Annotation of coherent/d/bin/cc/c/coh/sizomf.c, revision 1.1

1.1     ! root        1: #include       <stdio.h>
        !             2: 
        !             3: #ifdef vax
        !             4: #include       <ssdef.h>
        !             5: #include       <stsdef.h>
        !             6: #define        NNAME   500
        !             7: #define        NSEG    500
        !             8: #define        NBREC   10000
        !             9: #define        SRMODE  "r"
        !            10: #define        OK      (STS$M_INHIB_MSG|SS$_NORMAL)
        !            11: #define        BAD     (STS$M_INHIB_MSG|SS$_ABORT)
        !            12: #else
        !            13: #define        NNAME   250
        !            14: #define        NSEG    250
        !            15: #define        NBREC   5000
        !            16: #define        SRMODE  "rb"
        !            17: #define        OK      0
        !            18: #define        BAD     1
        !            19: #endif
        !            20: 
        !            21: #define        LNAMES  0x96
        !            22: #define        SEGDEF  0x98
        !            23: #define        MODEND  0x8A
        !            24: 
        !            25: typedef        struct  SEG     {
        !            26:        int     s_index;                /* Index into LNAMES */
        !            27:        long    s_size;                 /* Size */
        !            28: }      SEG;
        !            29: 
        !            30: typedef        struct  REC     {
        !            31:        int     r_type;                 /* Type code */
        !            32:        int     r_length;               /* Length of data (no checksum) */
        !            33:        char    r_data[NBREC];          /* Data */
        !            34: }      REC;
        !            35: 
        !            36: REC    rec;                            /* OMF record */
        !            37: char   *name[NNAME];                   /* Names, indexed by LNAMES index */
        !            38: int    nname;                          /* Highest name index */
        !            39: SEG    seg[NSEG];                      /* Segments */
        !            40: int    nseg;                           /* Highest segment index */
        !            41: FILE   *ifp;                           /* Input file */
        !            42: 
        !            43: extern char *malloc();
        !            44: 
        !            45: main(argc, argv)
        !            46: char   *argv[];
        !            47: {
        !            48:        register char   *np;
        !            49:        register SEG    *sp;
        !            50:        register long   total;
        !            51: 
        !            52:        if (argc < 2)
        !            53:                fatal(NULL, "Usage: size file\n");
        !            54:        if ((ifp=fopen(argv[1], SRMODE)) == NULL)
        !            55:                fatal(argv[1], "cannot open input file");
        !            56:        while (getrec()!=0 && rec.r_type!=MODEND) {
        !            57:                if (rec.r_type == LNAMES)
        !            58:                        lnames();
        !            59:                else if (rec.r_type == SEGDEF)
        !            60:                        segdef();
        !            61:        }
        !            62:        total = 0;
        !            63:        for (sp = &seg[0]; sp < &seg[nseg]; ++sp) {
        !            64:                printf("\t0x%04lx\t", sp->s_size);
        !            65:                if (sp->s_index>nname || (np=name[sp->s_index-1])==NULL)
        !            66:                        np = "[Bonzo]";
        !            67:                printf("%s\n", np);
        !            68:                total += sp->s_size;
        !            69:        }
        !            70:        if (nseg > 1) {
        !            71:                printf("\t0x%04lx\tTotal (hex)\n", total);
        !            72:                printf("\t%6ld\tTotal (decimal)\n", total);
        !            73:        }
        !            74:        exit(OK);
        !            75: }
        !            76: 
        !            77: fatal(fn, msg)
        !            78: char   *fn;
        !            79: char   *msg;
        !            80: {
        !            81:        fprintf(stderr, "size: ");
        !            82:        if (fn != NULL)
        !            83:                fprintf(stderr, "%s: ", fn);
        !            84:        fprintf(stderr, "%s\n", msg);
        !            85:        exit(BAD);
        !            86: }
        !            87: 
        !            88: getrec()
        !            89: {
        !            90:        register int    b1;
        !            91:        register int    b2;
        !            92:        register int    i;
        !            93:        register int    nbytes;
        !            94:        register int    checksum;
        !            95: 
        !            96:        if ((rec.r_type=getc(ifp)) == EOF)
        !            97:                return (0);
        !            98:        checksum = rec.r_type;
        !            99:        if ((b1=getc(ifp))==EOF || (b2=getc(ifp))==EOF)
        !           100:                fatal(NULL, "eof in length");
        !           101:        checksum += b1;
        !           102:        checksum += b2;
        !           103:        nbytes = (b2<<8) | b1;
        !           104:        if (nbytes >= NBREC)
        !           105:                fatal("omf item too long");
        !           106:        rec.r_length = nbytes-1;
        !           107:        for (i=0; i<nbytes; ++i) {
        !           108:                if ((b1=getc(ifp)) == EOF)
        !           109:                        fatal(NULL, "eof in data");
        !           110:                rec.r_data[i] = b1;
        !           111:                checksum += b1;
        !           112:        }
        !           113:        if ((checksum&0xFF) != 0)
        !           114:                fatal(NULL, "checksum error");
        !           115:        return (1);
        !           116: }
        !           117: 
        !           118: lnames()
        !           119: {
        !           120:        register char   *namep;
        !           121:        register int    length;
        !           122:        register int    index;
        !           123: 
        !           124:        index = 0;
        !           125:        while (index < rec.r_length) {
        !           126:                if (nname >= NNAME)
        !           127:                        fatal(NULL, "too many LNAMES items");
        !           128:                length = rec.r_data[index++];
        !           129:                if ((namep=malloc(length+1)) == NULL)
        !           130:                        fatal(NULL, "out of space for LNAMES strings");
        !           131:                name[nname++] = namep;
        !           132:                while (length--)
        !           133:                        *namep++ = rec.r_data[index++];
        !           134:                *namep = 0;
        !           135:        }
        !           136: }
        !           137: 
        !           138: segdef()
        !           139: {
        !           140:        register int    acbp;
        !           141:        register int    index;
        !           142:        register int    segindex;
        !           143:        register long   segsize;
        !           144: 
        !           145:        if (nseg >= NSEG)
        !           146:                fatal(NULL, "too many SEGDEF items");
        !           147:        index = 0;
        !           148:        acbp = rec.r_data[index++];
        !           149:        if ((acbp&0xE0)==0 || (acbp&0xE0)==0xA0)        /* Has FRAME */
        !           150:                index += 3;
        !           151:        if ((acbp&0xE0) == 0xC0)                        /* LTL */
        !           152:                index += 5;
        !           153:        if ((acbp&0x02) != 0)                           /* "Big" */
        !           154:                segsize = 65536L;
        !           155:        else
        !           156:                segsize = (unsigned)((rec.r_data[index+0]&0xFF)
        !           157:                          | ((rec.r_data[index+1]&0xFF) << 8));
        !           158:        index += 2;
        !           159:        segindex = rec.r_data[index++]&0xFF;
        !           160:        if ((segindex&0x80) != 0) {
        !           161:                segindex  = (segindex&0x7F) << 8;
        !           162:                segindex |= rec.r_data[index++]&0xFF;
        !           163:        }
        !           164:        seg[nseg].s_index = segindex;
        !           165:        seg[nseg].s_size  = segsize;
        !           166:        ++nseg;
        !           167: }

unix.superglobalmegacorp.com

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