#include #define BLKSIZ 512 #define SSZ sizeof(short) char ibuf[BLKSIZ]; int blksiz = BLKSIZ; int aflg = 0; int dflg = 0; int oflg = 0; int main(argc, argv) int argc; char *argv[]; { char *arg; char *ifnm; register FILE *in; int blkno, nblks, lstblk, eblksz; long size; if (argc < 3) { printf("\ndumpf {-a} {-d} {-o} \n"); exit(1); } argv++; argc--; for (;;) { arg = *argv; if (*arg++ != '-') break; argv++; argc--; switch (*arg) { case 'a': aflg++; break; case 'd': dflg++; break; case 'o': oflg++; break; default: printf("Bad flag: %c", *arg); exit(1); } } ifnm = *argv++; argc--; in = fopen(ifnm, "rb"); if (in == NULL) { printf("Error opening input file: '%s'\n", ifnm); exit(1); } arg = *argv++; argc--; blkno = atoi(arg); if (arg < 0) { printf("Bad block number: %\n", blkno); exit(1); } if (argc > 0) { printf("Unneeded extra arg '%s'", *argv); exit(1); } if (fseek(in, 0, SEEK_END) != 0) { printf("Size seek failed\n"); exit(1); } size = ftell(in); nblks = (size / BLKSIZ); eblksz = (size % BLKSIZ); if (eblksz == 0) eblksz = BLKSIZ; else nblks++; lstblk = (nblks - 1); if (blkno == lstblk) blksiz = eblksz; if (blkno > lstblk) { printf("Block number too large\n"); exit(1); } printf("\nBlock: %d %d %d\n", blkno, nblks, lstblk); printf("Size: %ld %d %d (%o) \n", size, eblksz, blksiz, blksiz); if (fseek(in, (blkno * BLKSIZ), SEEK_SET) != 0) { printf("Read seek failed\n"); exit(1); } if (fread(&ibuf[0], sizeof(char), blksiz, in) != blksiz) { printf("Read failed\n"); exit(1); } dumpblock(); printf("\n"); } dumpblock() { register short *loc; short rowsiz, wd; int wdloc, wdno; if (aflg) rowsiz = 4; else rowsiz = 8; loc = ((short *) &ibuf[0]); wdloc = 0; for (;;) { if (oflg) printf("\n%03d: ", wdloc); else printf("\n%03o: ", wdloc); for (wdno = 0; (wdno < rowsiz); wdno++) { if (aflg) { wd = *loc++; prchar(wd & 0377); prchar((wd >> 8) & 0377); } else printf(((dflg != 0) ? "%06hd " : "%06ho "), *loc++); wdloc += SSZ; if (wdloc >= blksiz) return; } } } prchar(c) char c; { int rlen = 0, i; if (c & 0200) { rlen = 2; printf("M-", (c + 0100)); } c &= 0177; if (c < 040) { printf("^%c", (c + 0100)); rlen += 2; } else if (c == ' ') { printf("' '"); rlen += 3; } else if (c == 0177) { printf("DEL"); rlen += 3; } else { printf("%c", c); rlen += 1; } for (i = rlen; (i < 6); i++) putchar(' '); }