1: #ifndef lint
   2: static char RCSid[] = "$Header: main.c,v 2.0 85/11/21 07:21:40 jqj Exp $";
   3: #endif
   4: 
   5: /* $Log:	main.c,v $
   6:  * Revision 2.0  85/11/21  07:21:40  jqj
   7:  * 4.3BSD standard release
   8:  *
   9:  * Revision 1.5  85/05/23  06:19:55  jqj
  10:  * *** empty log message ***
  11:  *
  12:  * Revision 1.5  85/05/23  06:19:55  jqj
  13:  * Public Beta-test version, released 24 May 1985
  14:  *
  15:  * Revision 1.4  85/03/26  06:10:07  jqj
  16:  * Revised public alpha-test version, released 26 March 1985
  17:  *
  18:  * Revision 1.3  85/03/11  16:39:42  jqj
  19:  * Public alpha-test version, released 11 March 1985
  20:  *
  21:  * Revision 1.2  85/02/21  11:05:24  jqj
  22:  * alpha test version
  23:  *
  24:  * Revision 1.1  85/02/15  13:55:31  jqj
  25:  * Initial revision
  26:  *
  27:  */
  28: 
  29: #include "compiler.h"
  30: #include <errno.h>
  31: #include <signal.h>
  32: 
  33: char *input_file;
  34: static char header_file[MAXSTR];
  35: FILE *header;
  36: static char *header1_file[MAXSTR];
  37: FILE *header1;
  38: static char support_file1[MAXSTR];
  39: FILE *support1;
  40: static char support_file2[MAXSTR];
  41: FILE *support2;
  42: static char client_file[MAXSTR];
  43: FILE *client;
  44: static char server_file[MAXSTR];
  45: FILE *server;
  46: 
  47: list Procedures, Errors;
  48: int recursive_flag, errs;
  49: 
  50: struct type *Boolean_type, *Cardinal_type, *LongCardinal_type,
  51:     *Integer_type, *LongInteger_type, *String_type,
  52:     *Unspecified_type, *LongUnspecified_type, *NilRecord_type,
  53:     *StreamEnum_type;
  54: 
  55: #ifdef DEBUG
  56: int DebugFlag = 0;
  57: #endif
  58: 
  59: 
  60: interrupt()
  61: {
  62:     errs = 1;
  63:     goodbye();
  64: }
  65: 
  66: main(argc,argv)
  67:     int argc;
  68:     char **argv;
  69: {
  70:     if (argc != 2) {
  71:         fprintf(stderr, "Usage: %s input_file\n",argv[0]);
  72:         exit(1);
  73:     }
  74:     input_file = argv[1];
  75:     if (freopen(input_file, "r",stdin) == NULL) {
  76:         perror(input_file); exit(1);
  77:     }
  78:     tempname(header_file);
  79:     tempname(header1_file);
  80:     tempname(client_file);
  81:     tempname(server_file);
  82:     tempname(support_file1);
  83:     tempname(support_file2);
  84:     if ((header = fopen(header_file,"w")) == NULL) {
  85:         perror(header_file);
  86:         goodbye();
  87:     }
  88:     if ((header1 = fopen(header1_file,"w")) == NULL) {
  89:         perror(header1_file);
  90:         goodbye();
  91:     }
  92:     if ((client = fopen(client_file,"w")) == NULL) {
  93:         perror(client_file);
  94:         goodbye();
  95:     }
  96:     if ((server = fopen(server_file,"w")) == NULL) {
  97:         perror(server_file);
  98:         goodbye();
  99:     }
 100:     if ((support1 = fopen(support_file1,"w")) == NULL) {
 101:         perror(support_file1);
 102:         goodbye();
 103:     }
 104:     if ((support2 = fopen(support_file2,"w")) == NULL) {
 105:         perror(support_file2);
 106:         goodbye();
 107:     }
 108:     setup_predefs();
 109:     (void) yyparse();
 110:     (void) fclose(header1);
 111:     (void) fclose(header);
 112:     (void) fclose(client);
 113:     (void) fclose(server);
 114:     if (errs == 0) {
 115:         register int c;
 116: 
 117:         freopen(support_file2, "r", support2);
 118:         while ((c = getc(support2)) != EOF)
 119:             (void) putc(c, support1);
 120:         (void) fclose(support1);
 121:         (void) fclose(support2);
 122:         (void) unlink(support_file2);
 123:         changename(support_file1, "_support.c");
 124:         if (Procedures != NIL) {
 125:             changename(client_file, "_client.c");
 126:             changename(server_file, "_server.c");
 127:         } else {
 128:             (void) unlink(client_file);
 129:             (void) unlink(server_file);
 130:         }
 131:         changename(header_file, ".h");
 132:         changename(header1_file, "_defs.h");
 133:     }
 134:     goodbye();
 135: 
 136: }
 137: 
 138: 
 139: goodbye()
 140: {
 141:     if(errs) {
 142:         (void) unlink(header_file);
 143:         (void) unlink(header1_file);
 144:         (void) unlink(client_file);
 145:         (void) unlink(server_file);
 146:         (void) unlink(support_file1);
 147:         (void) unlink(support_file2);
 148:     }
 149:     exit(errs);
 150: }
 151: 
 152: /*
 153:  * Rename the source file to be <CurrentProgram><CurrentVersion><suffix> .
 154:  */
 155: changename(source, suffix)
 156:     char *source, *suffix;
 157: {
 158:     char newname[MAXSTR];
 159: 
 160:     (void) sprintf(newname, "%s%d%s",
 161:             CurrentProgram, CurrentVersion, suffix);
 162:     if (rename(source, newname) == -1)
 163:         perror(newname);
 164: }
 165: 
 166: /* VARARGS1 */
 167: error(level, s, args)
 168:     enum severity level;
 169:     char *s;
 170: {
 171:     extern int yylineno;
 172: 
 173:     fprintf(stderr, "%s: %d: ", input_file, yylineno);
 174:     if (level == WARNING)
 175:         fprintf(stderr, "Warning: ");
 176:     _doprnt(s, &args, stderr);
 177:     (void) putc('\n', stderr);
 178:     if (level == ERROR)
 179:         errs++;
 180:     if (level == FATAL)
 181:         goodbye();
 182: }
 183: 
 184: yyerror(s)
 185:     char *s;
 186: {
 187:     error(ERROR, s);
 188: }
 189: 
 190: tempname(bclient)
 191:     char *bclient;
 192: {
 193:     static int n = 0;
 194: 
 195:     sprintf(bclient, "tmp%d.%d", n, getpid());
 196:     n++;
 197: }
 198: 
 199: struct type *
 200: predefine_enum_type(name,elements)
 201:     char *name;
 202:     char **elements;
 203: {
 204:     struct object *symbol;
 205:     list dlist;
 206:     struct type *resulttype;
 207:     char *id, *value;
 208: 
 209:     dlist = NIL;
 210:     for ( ; *elements != (char*)NULL; elements += 2) {
 211:         id = *elements;
 212:         value = *(elements+1);
 213:         if (check_def(id, (char*)NULL))
 214:           error(FATAL,"in predefine_enum_type, %s already declared",
 215:             id);
 216:         symbol = make_symbol(id, (char*)NULL);
 217:         define_enumeration_symbol(symbol, value);
 218:         dlist = cons(cons((list) symbol, (list) value),
 219:                  dlist);
 220:     }
 221:     resulttype = enumeration_type(dlist);
 222:     resulttype->type_name = name;
 223:     resulttype->type_xsize = 1;
 224:     return(resulttype);
 225: }
 226: 
 227: #define PREDEFINE(xtype, xname, nwords, constr) { \
 228:     xtype = make_type(constr); \
 229:     xtype->type_name = xname; \
 230:     xtype->type_xsize = nwords; \
 231: }
 232: 
 233: /*
 234:  * This mess is needed because C doesn't handle initialization of unions.
 235:  * Note that all of these must correspond to declarations, plus sizeof_,
 236:  * externalize_, and internalize_ functions, in courier.h
 237:  */
 238: setup_predefs()
 239: {
 240:     static char *streamvals[] = {"nextSegment","0","lastSegment","1",
 241:                      (char*)0};
 242: #ifndef lint
 243:     PREDEFINE(Boolean_type, "Boolean", 1, C_BOOLEAN);
 244:     PREDEFINE(Cardinal_type, "Cardinal", 1, C_NUMERIC);
 245:     PREDEFINE(LongCardinal_type, "LongCardinal", 2, C_NUMERIC);
 246:     PREDEFINE(Integer_type, "Integer", 1, C_NUMERIC);
 247:     PREDEFINE(LongInteger_type, "LongInteger", 2, C_NUMERIC);
 248:     PREDEFINE(String_type, "String", -1, C_STRING);
 249:     PREDEFINE(Unspecified_type, "Unspecified", 1, C_NUMERIC);
 250:     PREDEFINE(LongUnspecified_type, "LongUnspecified", 2, C_NUMERIC);
 251:     PREDEFINE(NilRecord_type, "NilRecord", 0, C_RECORD);
 252:     StreamEnum_type = predefine_enum_type("StreamEnumerator", streamvals);
 253: #endif
 254: }

Defined functions

changename defined in line 155; used 5 times
goodbye defined in line 139; used 9 times
interrupt defined in line 60; never used
main defined in line 66; never used
predefine_enum_type defined in line 199; used 1 times
setup_predefs defined in line 238; used 1 times
tempname defined in line 190; used 6 times
yyerror defined in line 184; never used

Defined variables

Boolean_type defined in line 50; used 3 times
DebugFlag defined in line 56; never used
Errors defined in line 47; used 4 times
Integer_type defined in line 51; used 3 times
Procedures defined in line 47; used 4 times
RCSid defined in line 2; never used
String_type defined in line 51; used 3 times
client_file defined in line 42; used 6 times
errs defined in line 48; used 5 times
header1_file defined in line 36; used 5 times
header_file defined in line 34; used 5 times
input_file defined in line 33; used 8 times
server_file defined in line 44; used 6 times
support_file1 defined in line 38; used 5 times
support_file2 defined in line 40; used 6 times

Defined macros

PREDEFINE defined in line 227; used 9 times
Last modified: 1986-03-13
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1987
Valid CSS Valid XHTML 1.0 Strict