Annotation of coherent/b/bin/size.c, revision 1.1.1.1

1.1       root        1: #include <misc.h>
                      2: #include <canon.h>
                      3: #include <n.out.h>
                      4: #include <coff.h>
                      5: #include <setjmp.h>
                      6: #include <errno.h>
                      7: #include <dir.h>
                      8: #include <arcoff.h>
                      9: #include <ar.h>
                     10: 
                     11: #define xread(x, m) if(1 != fread(&x, sizeof(x), 1, ifp)) fatal(rmsg, m);
                     12: 
                     13: static char rmsg[] = "Error reading %s";
                     14: static FILE *ifp;
                     15: static jmp_buf env;
                     16: static char namesw;
                     17: static char cfile[100];
                     18: 
                     19: static int errors = 0;         /* keep track of errors from fatal() */
                     20: 
                     21: /*
                     22:  * Put message and longjmp to next file.
                     23:  */
                     24: void
                     25: fatal(s)
                     26: char *s;
                     27: {
                     28:        fprintf(stderr, "size: %s: %r\n", cfile, &s);
                     29:        ++errors;
                     30:        longjmp(env, 1);
                     31: }
                     32: 
                     33: /*
                     34:  * Print members of archive.
                     35:  */
                     36: archive(filen, at)
                     37: char *filen;
                     38: long at;
                     39: {
                     40:        long arhend;
                     41:        struct ar_hdr coff_arh;
                     42:        struct old_ar_hdr arh;
                     43:        char *strchr();
                     44:        char *p;
                     45: 
                     46:        namesw = 0;
                     47:        for (arhend = at + SARMAG; ; ) {
                     48:                fseek(ifp, arhend, 0);
                     49:                if (1 != fread(&coff_arh, sizeof(coff_arh), 1, ifp))
                     50:                        break;
                     51:                memset(&arh, '\0', sizeof(arh));
                     52:                memcpy(arh.ar_name, coff_arh.ar_name, DIRSIZ);
                     53:                if (NULL != (p = strchr(arh.ar_name, '/')))
                     54:                        *p = '\0';
                     55: 
                     56:                sscanf(coff_arh.ar_date, "%ld %d %d %o %ld",
                     57:                        &arh.ar_date, &arh.ar_uid,
                     58:                        &arh.ar_gid, &arh.ar_mode, &arh.ar_size);
                     59: 
                     60:                arhend += sizeof(coff_arh);
                     61:                if (arh.ar_name[0]) {
                     62:                        sprintf(cfile, "%s(%s): ", filen, arh.ar_name);
                     63:                        printf("%s", cfile);
                     64:                        printSize(arh.ar_name, arhend);
                     65:                }
                     66:                arhend += arh.ar_size;
                     67:                if (arhend & 1)
                     68:                        arhend++;               
                     69:        }
                     70:        namesw = 1;
                     71: }
                     72: 
                     73: /*
                     74:  * Process old n.out files.
                     75:  */
                     76: old_nout(filen, at)
                     77: char *filen;
                     78: long at;
                     79: {
                     80:        struct ldheader ldh;
                     81:        register i;
                     82:        long total;
                     83: 
                     84:        if (namesw)
                     85:                printf("%s: ", filen);
                     86: 
                     87:        fseek(ifp, at, 0);
                     88:        xread(ldh, "n.out header");
                     89:        for (total = i = 0; i < L_DEBUG; i++) {
                     90:                cansize(ldh.l_ssize[i]);
                     91:                if (i)
                     92:                        putchar('+');
                     93:                printf("%ld", ldh.l_ssize[i]);
                     94:                total += ldh.l_ssize[i];
                     95:        }
                     96:        printf(" %ld (%lx)\n", total, total);
                     97: }
                     98: 
                     99: /*
                    100:  * Process old ar files.
                    101:  */
                    102: old_ar(filen, at)
                    103: char *filen;
                    104: long at;
                    105: {
                    106:        long arhend;
                    107:        struct old_ar_hdr arh;
                    108: 
                    109:        namesw = 0;
                    110:        for (arhend = at + sizeof(short); ; ) {
                    111:                fseek(ifp, arhend, 0);
                    112:                if (1 != fread(&arh, sizeof(arh), 1, ifp))
                    113:                        break;
                    114:                arhend += sizeof(arh);
                    115:                arh.ar_date = 0;        /* terminate name */
                    116:                if (strcmp(arh.ar_name, HDRNAME)) {
                    117:                        sprintf(cfile, "%s(%s): ", filen, arh.ar_name);
                    118:                        printf("%s", cfile);
                    119:                        printSize(arh.ar_name, arhend);
                    120:                }
                    121:                cansize(arh.ar_size);
                    122:                arhend += arh.ar_size;
                    123:        }
                    124: }
                    125: 
                    126: /*
                    127:  * Print size of coff file or call friends.
                    128:  */
                    129: printSize(filen, at)
                    130: char *filen;
                    131: long at;
                    132: {
                    133:        FILEHDR fh;
                    134:        long total;
                    135:        int i;
                    136: 
                    137:        xread(fh, "file header");
                    138:        if (fh.f_magic != C_386_MAGIC) {
                    139:                if (!memcmp(ARMAG, &fh, SARMAG))
                    140:                        return (archive(filen, at));
                    141: 
                    142:                /* Check old file types */
                    143:                canshort(fh.f_magic);
                    144:                if (fh.f_magic == OLD_ARMAG)
                    145:                        return (old_ar(filen, at));
                    146:                if (fh.f_magic == L_MAGIC)
                    147:                        return (old_nout(filen, at));
                    148:                fatal("Unknown filetype 0x%x", fh.f_magic);
                    149:        }
                    150: 
                    151:        if (namesw)
                    152:                printf("%s: ", filen);
                    153: 
                    154:        fseek(ifp, at + sizeof(FILEHDR) + fh.f_opthdr, 0);
                    155:        for (total = i = 0; i < fh.f_nscns; i++) {
                    156:                SCNHDR sh;
                    157: 
                    158:                xread(sh, "section");
                    159:                if (i)
                    160:                        putchar('+');
                    161:                printf("%ld", sh.s_size);
                    162:                total += sh.s_size;
                    163:        }
                    164:        printf(" %ld (%lx)\n", total, total);
                    165: }
                    166: 
                    167: main(argc, argv)
                    168: char *argv[];
                    169: {
                    170:        char *filen;
                    171:        int i;
                    172: 
                    173:        for (i = 1; i < argc; i++) {
                    174:                /* fatal() longjmp()s here for next file */
                    175:                if (setjmp(env)) {
                    176:                        if (NULL != ifp) {
                    177:                                fclose(ifp);
                    178:                                ifp = NULL;
                    179:                        }
                    180:                        continue;
                    181:                }
                    182:                strcpy(cfile, filen = argv[i]);
                    183:                ifp = xopen(filen, "rb");
                    184: 
                    185:                namesw = argc > 2;
                    186: 
                    187:                printSize(filen, 0L);
                    188: 
                    189:                fclose(ifp);
                    190:                ifp = NULL;
                    191:        }
                    192:        exit(errors);
                    193: }
                    194: 

unix.superglobalmegacorp.com

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