#include /* nm - hacked to run under Windoze JNC 28/Mar/2014 */ FILE *fi; int cflg; int nflg; int uflg; int rflg = 1; int gflg; int pflg; int sflg; int tflg; int hflg; int pass = 0; struct nl { char name[8]; short int typ; short unsigned val; } *anlp, *nlp; short int buf[8]; main(argc, argv) char **argv; { int n, i, j; int compare(); // printf("%d '%s' '%s'\n", argc, argv[0], argv[1]); // fflush(stdout); if (--argc > 0 && *argv[1] == '-') { argv++; while (*++*argv) switch (**argv) { case 'n': nflg++; continue; case 'c': cflg++; continue; case 'g': gflg++; continue; case 'h': hflg++; continue; case 'u': uflg++; continue; case 'r': rflg = -1; continue; case 's': sflg++; continue; case 't': tflg++; continue; case 'p': pflg++; continue; default: continue; } argc--; } argv++; // printf("file: '%s'\n", *argv);fflush(stdout); if (argc==0) fi = fopen("a.out", "rb"); else fi = fopen(*argv, "rb"); if(fi <= 0) { printf("cannot open input %s\n", ((argc == 0) ? "a.out" : *argv)); exit(); } fread(&buf[0], sizeof(char), 020, fi); // printf("header read\n");fflush(stdout); if (hflg) { printf("header typ: %o txt: %o data: %o bss: %o ", buf[0], buf[1], buf[2], buf[3]); printf("symsiz: %o reloc: %o\n", buf[4], buf[7]); fflush(stdout); } if(buf[0]!=0407 && buf[0]!=0410 && buf[0]!=0411) { printf("bad format\n"); exit(); } fseek(fi, ((long) buf[1]), SEEK_CUR); /* text */ fseek(fi, ((long) buf[2]), SEEK_CUR); /* data */ if(buf[7] != 1) { fseek(fi, ((long) buf[1]), SEEK_CUR); fseek(fi, ((long) buf[2]), SEEK_CUR); /* reloc */ } n = (buf[4] / 12); if(n == 0) { printf("no name list\n"); exit(); } anlp = ((struct nl *) malloc(12*n)); fread(anlp, sizeof(char), n*12, fi); if (pflg==0) qsort(anlp, n, 12, compare); prloop: nlp = anlp; for(i=0; ityp&040)==0) goto out; if(cflg) { if(nlp->name[0] != '_') goto out; for(j=0; j<7; j++) nlp->name[j] = nlp->name[j+1]; nlp->name[7] = '\0'; } j = nlp->typ&037; if(j > 4) j = 1; if(j==0 && nlp->val) j = 5; if(uflg && j!=0) goto out; if(!uflg) { if (sflg && (pass != tflg) && (j != 2)) goto out; if (sflg && (pass == tflg) && (j == 2)) goto out; if(j==0) printf(" "); else printo(nlp->val); printf("%c ", (nlp->typ&040? "UATDBC":"uatdbc")[j]); } printf("%.8s\n", nlp); out: nlp++; } if (sflg && (pass++ == 0)) goto prloop; fflush(stdout); } compare(p1, p2) struct nl *p1, *p2; { int a, i; a = 0; if(nflg) { if(p1->val > p2->val) { a = 1; goto out; } if(p1->val < p2->val) { a = -1; goto out; } } for(i=0; i<8; i++) if(p1->name[i] != p2->name[i]) { if(p1->name[i] > p2->name[i]) a = 1; else a = -1; goto out; } out: return(a*rflg); } printo(v) { if (v < 0) v &= 0177777; printf("%06o", v); }