Annotation of coherent/b/bin/as/main.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Initialize the assembler
        !             3:  */
        !             4: #include <asm.h>
        !             5: 
        !             6: #ifdef COHERENT
        !             7: #define SLASH '/'
        !             8: #else
        !             9: #define SLASH '\\'
        !            10: #endif
        !            11: 
        !            12: #if 0
        !            13:        /* This is used only to get the Syntax error message into the docs. */
        !            14: 
        !            15:        yyerror("Syntax error");
        !            16:        /* The syntax of this statement makes no sense to the parser.
        !            17:         * This can be a variety of problems. */
        !            18: #endif
        !            19: 
        !            20: static char swChars[] = "VwQXaxfpbgnlo:?E:D:"; /* list for getargs */
        !            21: static int savArgc;
        !            22: static char **savArgv;
        !            23: static char dodefsw;   /* -D or -E used */
        !            24: 
        !            25: /*
        !            26:  * Do -E and -D definitions. 
        !            27:  * -Dx=y is the same as x .define y
        !            28:  * -Ea=5 is the same as a .equ 5
        !            29:  * This is called every pass.
        !            30:  */
        !            31: void
        !            32: dodefs()
        !            33: {
        !            34:        register char *p, c;
        !            35: 
        !            36:        if (!dodefsw)   /* no -D or -E to process */
        !            37:                return;
        !            38: 
        !            39:        optix = 1;      /* reset getargs */
        !            40:        while (EOF != (c = getargs(savArgc, savArgv, swChars))) {
        !            41:                switch(c) {
        !            42:                case 'D':
        !            43:                case 'E':
        !            44:                        if (NULL == (p = strchr(optarg, '=')) || p == optarg)
        !            45:                                fatal("Invalid option on -%c switch", c);
        !            46:                                /* The syntax of -D and -E switches is
        !            47:                                 * -Dname=string
        !            48:                                 * -Ename=number */
        !            49:                        *p++ = '\0';
        !            50:                        if ('D' == c) {
        !            51:                                defCt++;
        !            52:                                defMac(gcpy(optarg, 0),
        !            53:                                       gcpy(p, offset(parm, str)),
        !            54:                                       MACSTR);
        !            55:                        }
        !            56:                        else
        !            57:                                symLookUp(gcpy(optarg, 0), S_XSYM, atol(p), 0);
        !            58:                        *--p = '=';
        !            59:                default:
        !            60:                        continue;
        !            61:                }
        !            62:        }
        !            63: }
        !            64: 
        !            65: /*
        !            66:  * Invalid usage message.
        !            67:  */
        !            68: void
        !            69: usage()
        !            70: {
        !            71:        fprintf(stderr, "usage: as [-wXxfpbgnlQ] [-o output] filename\n");
        !            72:        exit(1);
        !            73: }
        !            74: 
        !            75: /*
        !            76:  * process arguments and call yyparse.
        !            77:  */
        !            78: main(argc, argv)
        !            79: char **argv;
        !            80: {
        !            81:        register char *p, c;
        !            82:        char *fileName;
        !            83: 
        !            84:        errdev = stderr;        /* errors normally go to stderr */
        !            85: 
        !            86:        initStor();             /* init storage control */
        !            87:        segInit();              /* init segment data */
        !            88:        indPass();              /* init indefinite branch logic */
        !            89:        newLevel(NORMAL);       /* set base level for if else etc */
        !            90: 
        !            91:        _addargs("AS", &argc, &argv);
        !            92:        savArgv = argv;
        !            93:        savArgc = argc;
        !            94: 
        !            95:        fileName = NULL;
        !            96:        while (EOF != (c = getargs(argc, argv, swChars))) {
        !            97:                switch(c) {
        !            98:                case 0:
        !            99:                        if (NULL != fileName)   /* one time only */
        !           100:                                fatal("more than one file to process");
        !           101:                                /* The assembler will only process one file
        !           102:                                 * at a time. */
        !           103:                        fileName = optarg;
        !           104:                        break;
        !           105: 
        !           106:                case 'a':       /* align data objects */
        !           107:                        alignon = alignonX ^= 1;
        !           108:                        break;
        !           109: 
        !           110:                case 'n':       /* No fixes for chip errata */
        !           111:                        nswitch = nswitchX ^= 1; 
        !           112:                        break;
        !           113: 
        !           114:                case 'w':       /* No warning messages */
        !           115:                        wswitchX ^= 1;  
        !           116:                        break;
        !           117: 
        !           118:                case 'X':       /* don't output .L local symbols */
        !           119:                        Xswitch ^= 1;   
        !           120:                        break;
        !           121: 
        !           122:                case 'x':       /* no local symbols in object file */
        !           123:                        xswitch ^= 1;   
        !           124:                        break;
        !           125: 
        !           126:                case 'f':       /* reverse order of operands */
        !           127:                        fswitch = fswitchX ^= 1; 
        !           128:                        break;
        !           129: 
        !           130:                case 'p':       /* don't use % on register names */
        !           131:                        rswitch ^= 1;   
        !           132:                        break;
        !           133: 
        !           134:                case 'b':       /* reverse bracket sense */
        !           135:                        bswitch = bswitchX ^= 1; 
        !           136:                        break;
        !           137: 
        !           138:                case 'Q':       /* No messages at all */
        !           139:                        Qswitch ^= 1;
        !           140:                        break;
        !           141: 
        !           142:                case 'g':       /* treat unrefrenced symbols as globl */
        !           143:                        gswitch = 1;    
        !           144:                        break;
        !           145: 
        !           146:                case 'l':       /* print a listing */
        !           147:                        errdev = (lswitchX ^= 1) ? stdout : stderr;
        !           148:                        break;
        !           149: 
        !           150:                case 'o':
        !           151:                        outName = optarg;
        !           152:                        if ((NULL == (p = strrchr(outName, '.'))) ||
        !           153:                            strcmp(p, ".o"))
        !           154:                                fatal("Unlikely output file '%s'", outName);
        !           155:                        /* Output file-names should have \fB.o\fR suffixes.
        !           156:                         * Because this is generally a typographical error,
        !           157:                         * \fBas\fR aborts to
        !           158:                         * avoid overwriting an important file. */
        !           159:                        break;
        !           160: 
        !           161:                case 'D':       /* process in dodefs */
        !           162:                case 'E':
        !           163:                        dodefsw = 1;
        !           164:                case 'V':
        !           165:                        fprintf(stderr, "Mark Williams 80386 assembler\n");
        !           166:                        break;
        !           167: 
        !           168:                case '?':
        !           169:                default:
        !           170:                        usage();
        !           171:                }
        !           172:        }
        !           173: 
        !           174:        if (fileName == NULL)
        !           175:                fatal("no work");
        !           176:                /* There were no files listed on the command line. */
        !           177: 
        !           178:        symInit();              /* init symbol table */
        !           179: 
        !           180:        fileOpen(fileName);
        !           181:        title = scpy(fileName, 0);
        !           182: 
        !           183:        if(NULL == outName) {   /* develop output filename */
        !           184:                char *q;
        !           185:                int len;
        !           186: 
        !           187:                /* point p at input file name */
        !           188:                if (NULL != (q = strrchr(p = fileName, SLASH)))
        !           189:                        p = q + 1;
        !           190: 
        !           191:                outName = alloc((unsigned)(3 + (len = strlen(p))));
        !           192:                strcpy(outName, p);
        !           193: 
        !           194:                p = outName + len - 2;  /* right spot for .  */
        !           195:                if ('.' != *p)          /* if no . append .o */
        !           196:                        p += 2;
        !           197: 
        !           198:                strcpy(p, ".o");
        !           199:        }
        !           200: 
        !           201:        /* get ctime without \n */
        !           202:        {
        !           203:                long t;
        !           204: 
        !           205:                time(&t);
        !           206:                c = strlen(dTime = ctime(&t)) - 1;
        !           207:                dTime[c] = '\0';
        !           208:        }
        !           209: 
        !           210:        dodefs();
        !           211:        yyparse();
        !           212:        fatal("Unexpected return from parser"); /* TECH */
        !           213: }

unix.superglobalmegacorp.com

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