Annotation of cci/d/entry/absaddr.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Take ast - generated list files, take a.sym, produce a
        !             3:  *  list file with updated PC's.
        !             4:  */
        !             5: #include <stdio.h>
        !             6: #define        TRUE 1
        !             7: #define        FALSE 0
        !             8: #define        NSYM 4000
        !             9: 
        !            10: struct symbol {
        !            11:        char    name[13];
        !            12:        long    value;
        !            13: }      symbol[NSYM];
        !            14: 
        !            15:        long    basevalue, knownstart;
        !            16:        char    lastsymbol[13];
        !            17:        char    line[200];
        !            18:        FILE    *asym, *source = stdin;
        !            19:        char *symfil = "a.sym";
        !            20: 
        !            21: main(argc, argv)
        !            22: int argc;
        !            23: char *argv[];
        !            24: {
        !            25:        long    eof, i;
        !            26: 
        !            27:        knownstart = FALSE;
        !            28:        if (argc > 3) {
        !            29:                printf("Usage : %s [listfile] [symbolsfile]\n", argv[0]);
        !            30:                exit(1);
        !            31:        }
        !            32:        if (argc >= 2) {
        !            33:                source = fopen(argv[1], "r");
        !            34:                if (source == NULL) {
        !            35:                        printf("Cannot open %s\n", argv[1]);
        !            36:                        exit(1);
        !            37:                }
        !            38:        }
        !            39:        if (argc == 3)
        !            40:                symfil = argv[2];
        !            41:        asym = fopen (symfil, "r");
        !            42:        if (asym == NULL) {
        !            43:                printf("Cannot open %s\n", symfil);
        !            44:                exit(1);
        !            45:        }
        !            46:        eof =  FALSE;
        !            47:        for (i=0; i < NSYM && !eof; i++) {
        !            48:                if (fgets(line, 80, asym)==NULL) eof = TRUE;
        !            49:                sscanf(line, "%s %x", symbol[i].name, &symbol[i].value);
        !            50:        }
        !            51: 
        !            52:        eof = FALSE;    /* source file now */
        !            53:        while (!eof) {
        !            54:                if (fgets(line,200, source)==NULL) eof =TRUE;
        !            55:                if (!knownstart) checkline();
        !            56:                if (knownstart) transform();
        !            57:                printf("%s", line);
        !            58:        }
        !            59: }
        !            60: 
        !            61: /*
        !            62:  * Check line for symbols and for start of text.
        !            63:  */
        !            64: checkline()
        !            65: {
        !            66:        long    i, j, place;
        !            67: 
        !            68:        i = place = 0;
        !            69:        while (line[i] != '_' && line[i] != '\0' && line[i] != '\n') i++;
        !            70:        if (line[i] == '_' && (i==0 || 
        !            71:                        line[i-1] == ' ' || line[i-1] == '\t')) {
        !            72:                for (j=0; j<13; j++) lastsymbol[j] = '\0';
        !            73:                while (line[i] != ':' && line[i] != '\0' 
        !            74:                        && line[i] != '\n' && place<13 ) 
        !            75:                        lastsymbol[place++] = line[i++];
        !            76:        }
        !            77:        if (!place)
        !            78:          if (line[3] == ' ' || line[15] == '*' || line[18] == ' ') return;
        !            79: /* 
        !            80:  * Found start of text
        !            81:  */
        !            82:        for (i=0; i< NSYM && !knownstart; i++) {
        !            83:                if (strncmp(symbol[i].name, lastsymbol, place)==0) {
        !            84:                        knownstart = TRUE;
        !            85:                        sscanf(&line[6] , "%x", &j);
        !            86:                        basevalue = symbol[i].value - j;
        !            87:                }
        !            88:        }
        !            89:        if (!knownstart) printf("Symbol %s not found ---\n", lastsymbol);
        !            90: }
        !            91: 
        !            92: /*
        !            93:  * Transform text lines
        !            94:  */
        !            95: transform()
        !            96: {
        !            97: 
        !            98:        long    i;
        !            99: 
        !           100:        if (line[3] == ' ' || line[15] == '*') return;
        !           101:        sscanf(&line[6] , "%x", &i);
        !           102:        i += basevalue;
        !           103:        sprintf(&line[6], "%08x", i); line[14] = ' ';
        !           104: }

unix.superglobalmegacorp.com

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