1: #ifndef lint
   2: static  char    sccs_id []  = "@(#)od.c	2.2	12/6/80";
   3: #endif
   4: /*
   5:  * od -- octal (also hex, decimal, radix 40, and character) dump
   6:  */
   7: 
   8: #include <stdio.h>
   9: 
  10: unsigned short  word[8];
  11: unsigned short  lastword[8];
  12: int conv;
  13: int base =  010;
  14: int max;
  15: long    addr;
  16: 
  17: main(argc, argv)
  18: char **argv;
  19: {
  20:     register char *p;
  21:     register n, f, same;
  22: 
  23: 
  24:     argv++;
  25:     f = 0;
  26:     if(argc > 1) {
  27:         p = *argv;
  28:         if(*p == '-') {
  29:             while(*p != '\0') {
  30:                 switch(*p++) {
  31:                 case 'o':
  32:                     conv |= 001;
  33:                     f = 6;
  34:                     break;
  35:                 case 'd':
  36:                     conv |= 002;
  37:                     f = 5;
  38:                     break;
  39:                 case 'x':
  40:                 case 'h':
  41:                     conv |= 010;
  42:                     f = 4;
  43:                     break;
  44:                 case 'c':
  45:                     conv |= 020;
  46:                     f = 7;
  47:                     break;
  48:                 case 'b':
  49:                     conv |= 040;
  50:                     f = 7;
  51:                     break;
  52:                 case 'r':
  53:                     conv |= 0100;
  54:                     f = 3;
  55:                     break;
  56:                 }
  57:                 if(f > max)
  58:                     max = f;
  59:             }
  60:             argc--;
  61:             argv++;
  62:         }
  63:     }
  64:     if(!conv) {
  65:         max = 6;
  66:         conv = 1;
  67:     }
  68:     if(argc > 1)
  69:     if(**argv != '+') {
  70:         if (freopen(*argv, "r", stdin) == NULL) {
  71:             printf("cannot open %s\n", *argv);
  72:             exit(1);
  73:         }
  74:         argv++;
  75:         argc--;
  76:     }
  77:     if(argc > 1)
  78:         offset(*argv);
  79: 
  80:     same = -1;
  81:     for ( ; (n = fread((char *)word, 1, sizeof(word), stdin)) > 0; addr += n) {
  82:         if (same>=0) {
  83:             for (f=0; f<8; f++)
  84:                 if (lastword[f] != word[f])
  85:                     goto notsame;
  86:             if (same==0) {
  87:                 printf("*\n");
  88:                 same = 1;
  89:             }
  90:             continue;
  91:         }
  92:     notsame:
  93:         line(addr, word, (n+sizeof(word[0])-1)/sizeof(word[0]));
  94:         same = 0;
  95:         for (f=0; f<8; f++)
  96:             lastword[f] = word[f];
  97:         for (f=0; f<8; f++)
  98:             word[f] = 0;
  99:     }
 100:     putn(addr, base, 7);
 101:     putchar('\n');
 102: }
 103: 
 104: line(a, w, n)
 105: long a;
 106: unsigned short *w;
 107: {
 108:     register i, f, c;
 109: 
 110:     f = 1;
 111:     for(c=1; c; c<<=1) {
 112:         if((c&conv) == 0)
 113:             continue;
 114:         if(f) {
 115:             putn(a, base, 7);
 116:             putchar(' ');
 117:             f = 0;
 118:         } else
 119:             putchar('\t');
 120:         for (i=0; i<n; i++) {
 121:             putx(w[i], c);
 122:             putchar(i==n-1? '\n': ' ');
 123:         }
 124:     }
 125: }
 126: 
 127: putx(n, c)
 128: unsigned n;
 129: {
 130: 
 131:     switch(c) {
 132:     case 001:
 133:         pre(6);
 134:         putn((long)n, 8, 6);
 135:         break;
 136:     case 002:
 137:         pre(5);
 138:         putn((long)n, 10, 5);
 139:         break;
 140:     case 010:
 141:         pre(4);
 142:         putn((long)n, 16, 4);
 143:         break;
 144:     case 020:
 145:         pre(7);
 146:         {
 147:             unsigned short sn = n;
 148:             cput(*(char *)&sn);
 149:             putchar(' ');
 150:             cput(*((char *)&sn + 1));
 151:             break;
 152:         }
 153:     case 040:
 154:         pre(7);
 155:         {
 156:             unsigned short sn = n;
 157:             putn((long)(*(char *)&sn)&0377, 8, 3);
 158:             putchar(' ');
 159:             putn((long)(*((char *)&sn + 1))&0377, 8, 3);
 160:             break;
 161:         }
 162:     case 0100:
 163:         pre(3);
 164:         {
 165:             char s[4];
 166:             rad50(s, n);
 167:             printf(s);
 168:             break;
 169:         }
 170:     }
 171: }
 172: 
 173: cput(c)
 174: {
 175:     c &= 0377;
 176:     if(c>037 && c<0177) {
 177:         printf("  ");
 178:         putchar(c);
 179:         return;
 180:     }
 181:     switch(c) {
 182:     case '\0':
 183:         printf(" \\0");
 184:         break;
 185:     case '\b':
 186:         printf(" \\b");
 187:         break;
 188:     case '\f':
 189:         printf(" \\f");
 190:         break;
 191:     case '\n':
 192:         printf(" \\n");
 193:         break;
 194:     case '\r':
 195:         printf(" \\r");
 196:         break;
 197:     case '\t':
 198:         printf(" \\t");
 199:         break;
 200:     default:
 201:         putn((long)c, 8, 3);
 202:     }
 203: }
 204: 
 205: putn(n, b, c)
 206: long n;
 207: {
 208:     register d;
 209: 
 210:     if(!c)
 211:         return;
 212:     putn(n/b, b, c-1);
 213:     d = n%b;
 214:     if (d > 9)
 215:         putchar(d-10+'a');
 216:     else
 217:         putchar(d+'0');
 218: }
 219: 
 220: pre(n)
 221: {
 222:     int i;
 223: 
 224:     for(i=n; i<max; i++)
 225:         putchar(' ');
 226: }
 227: 
 228: offset(s)
 229: register char *s;
 230: {
 231:     register char *p;
 232:     long a;
 233:     register int d;
 234: 
 235:     if (*s=='+')
 236:         s++;
 237:     if (*s=='x') {
 238:         s++;
 239:         base = 16;
 240:     } else if (*s=='0' && s[1]=='x') {
 241:         s += 2;
 242:         base = 16;
 243:     } else if (*s == '0')
 244:         base = 8;
 245:     p = s;
 246:     while(*p) {
 247:         if (*p++=='.')
 248:             base = 10;
 249:     }
 250:     for (a=0; *s; s++) {
 251:         d = *s;
 252:         if(d>='0' && d<='9')
 253:             a = a*base + d - '0';
 254:         else if (d>='a' && d<='f' && base==16)
 255:             a = a*base + d + 10 - 'a';
 256:         else
 257:             break;
 258:     }
 259:     if (*s == '.')
 260:         s++;
 261:     if(*s=='b' || *s=='B')
 262:         a *= 512;
 263:     fseek(stdin, a, 0);
 264:     addr = a;
 265: }
 266: 
 267: char r50[] = {
 268:     ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
 269:     'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
 270:     'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
 271:     'x', 'y', 'z', '$', '.', '|', '0', '1',
 272:     '2', '3', '4', '5', '6', '7', '8', '9'
 273: };
 274: 
 275: 
 276: rad50(s, n)
 277: register char *s;
 278: register unsigned n;
 279: {
 280:     s[2] = r50[n % 40]; n /= 40;
 281:     s[1] = r50[n % 40]; n /= 40;
 282:     s[0] = r50[n % 40];
 283:     s[3] =  0;
 284: }

Defined functions

cput defined in line 173; used 2 times
line defined in line 104; used 1 times
  • in line 93
main defined in line 17; never used
offset defined in line 228; used 1 times
  • in line 78
pre defined in line 220; used 6 times
putn defined in line 205; used 9 times
putx defined in line 127; used 1 times
rad50 defined in line 276; used 1 times

Defined variables

addr defined in line 15; used 4 times
base defined in line 13; used 9 times
conv defined in line 12; used 9 times
lastword defined in line 11; used 2 times
max defined in line 14; used 4 times
r50 defined in line 267; used 3 times
sccs_id defined in line 2; never used
word defined in line 10; used 8 times
Last modified: 1983-06-04
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 762
Valid CSS Valid XHTML 1.0 Strict