Annotation of 43BSDTahoe/new/xns/compiler/main.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.