1: #ifndef lint 2: static char *sccsid = "@(#)pti.c 4.1 (Berkeley) 10/1/80"; 3: #endif 4: #define DBL 0200 5: /* 6: C version of pti 7: */ 8: 9: char *ap; 10: char ibuf[512]; 11: char *ibufp = ibuf; 12: char *eibufp = ibuf; 13: int fid; 14: int esc; 15: int escd; 16: int verd; 17: int esct; 18: int osize = 02; 19: int size = 02; 20: int leadtot; 21: int railmag; 22: int lead; 23: int mcase; 24: int stab[] = { 25: 010,0,01,07,02,03,04,05,0211,06,0212,0213,0214,0215,0216,0217}; 26: int rtab[] = { 27: 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 28, 36, 18}; 28: char *asctab[128]; 29: char *spectab[128]; 30: long offset; 31: int lflg; 32: 33: main(argc,argv) 34: int argc; 35: char **argv; 36: { 37: register i, j; 38: register char *k; 39: extern ex(); 40: 41: while((--argc > 0) && ((++argv)[0][0]=='-')){ 42: switch(argv[0][1]){ 43: case 'l': 44: lflg++; 45: continue; 46: default: 47: ap = &argv[0][1]; 48: while(((j = *ap++ - '0') >= 0) 49: && (j <= 9))offset = 8*offset +j; 50: continue; 51: } 52: } 53: if(argc){ 54: if((fid=open(argv[0], 0)) < 0){ 55: printf("Cannot open: %s\n",argv[0]); 56: exit(1); 57: } 58: } 59: lseek(fid,offset,0); 60: while((i = getc()) >= 0){ 61: if(i & 0200){ 62: if(!lflg)printf("%o ",i); 63: esc += (~i) & 0177; 64: continue; 65: } 66: if(esc){ 67: if(escd){ 68: if(!lflg)printf("< %d\n",esc); 69: esc = -esc; 70: } 71: else{ 72: if(!lflg)printf("> %d\n",esc); 73: } 74: esct += esc; 75: esc = 0; 76: } 77: if(!lflg)printf("%o ",i); 78: if(!i){ 79: if(!lflg)printf("\n"); 80: continue; 81: } 82: switch(i){ 83: case 0100: /*init*/ 84: escd = verd = mcase = railmag = 0; 85: if(!lflg)printf("Initialize\n"); 86: continue; 87: case 0101: /*lower rail*/ 88: railmag &= ~01; 89: if(!lflg)printf("Lower rail\n"); 90: continue; 91: case 0102: /*upper rail*/ 92: railmag |= 01; 93: if(!lflg)printf("Upper rail\n"); 94: continue; 95: case 0103: /*upper mag*/ 96: railmag |= 02; 97: if(!lflg)printf("Upper mag\n"); 98: continue; 99: case 0104: /*lower mag*/ 100: railmag &= ~02; 101: if(!lflg)printf("Lower mag\n"); 102: continue; 103: case 0105: /*lower case*/ 104: mcase = 0; 105: if(!lflg)printf("Lower case\n"); 106: continue; 107: case 0106: /*upper case*/ 108: mcase = 0100; 109: if(!lflg)printf("Upper case\n"); 110: continue; 111: case 0107: /*escape forward*/ 112: escd = 0; 113: if(!lflg)printf("> mode, %d\n",esct); 114: continue; 115: case 0110: /*escape backward*/ 116: escd = 1; 117: if(!lflg)printf("< mode, %d\n",esct); 118: continue; 119: case 0111: /*stop*/ 120: if(!lflg)printf("STOP\n"); 121: continue; 122: case 0112: /*lead forward*/ 123: verd = 0; 124: if(!lflg)printf("Lead forward, %d\n",leadtot); 125: continue; 126: case 0114: /*lead backward*/ 127: verd = 1; 128: if(!lflg)printf("Lead backward, %d\n",leadtot); 129: continue; 130: case 0115: /*undefined*/ 131: if(!lflg)printf("New page\n"); 132: continue; 133: case 0116: 134: lead = 64 * getc(); 135: goto leadin; 136: case 0117: 137: case 0113: 138: if(!lflg)printf("Undefined code\n"); 139: continue; 140: } 141: if((i & 0340) == 0140){ /*leading*/ 142: lead = (~i) & 037; 143: leadin: 144: if(!lflg)printf("Lead %d\n",lead); 145: if(verd)lead = -lead; 146: leadtot += lead; 147: continue; 148: } 149: if((i & 0360) == 0120){ /*size change*/ 150: i &= 017; 151: for(j = 0; i != (stab[j] & 017); j++); 152: osize = size; 153: size = stab[j]; 154: if(!lflg){ 155: printf("Size %d",rtab[j]); 156: if(!(osize & DBL) && (size & DBL))printf(", double\n"); 157: else if((osize & DBL) && !(size & DBL))printf(", single\n"); 158: else printf("\n"); 159: } 160: continue; 161: } 162: if(i & 0300)continue; 163: i = (i & 077) | mcase; 164: if(railmag != 03)k = asctab[i]; 165: else k = spectab[i]; 166: if(!lflg)printf("%s\n",k); 167: continue; 168: } 169: ex(); 170: } 171: ex(){ 172: printf("Total lead %d\n",leadtot); 173: exit(0); 174: } 175: getc(){ 176: register i; 177: 178: if(ibufp >= eibufp){ 179: if((i=read(fid,ibuf,512)) <= 0)ex(); 180: eibufp = ibuf + i; 181: ibufp = ibuf; 182: } 183: return(*ibufp++ & 0377); 184: } 185: char *asctab[128] = { 186: 0, /*blank*/ 187: "h", /*h*/ 188: "t", /*t*/ 189: "n", /*n*/ 190: "m", /*m*/ 191: "l", /*l*/ 192: "i", /*i*/ 193: "z", /*z*/ 194: "s", /*s*/ 195: "d", /*d*/ 196: "b", /*b*/ 197: "x", /*x*/ 198: "f", /*f*/ 199: "j", /*j*/ 200: "u", /*u*/ 201: "k", /*k*/ 202: 0, /*blank*/ 203: "p", /*p*/ 204: "-", /*_ 3/4 em dash*/ 205: ";", /*;*/ 206: 0, /*blank*/ 207: "a", /*a*/ 208: "_", /*rule*/ 209: "c", /*c*/ 210: "`", /*` open*/ 211: "e", /*e*/ 212: "'", /*' close*/ 213: "o", /*o*/ 214: 0, /*1/4*/ 215: "r", /*r*/ 216: 0, /*1/2*/ 217: "v", /*v*/ 218: "-", /*- hyphen*/ 219: "w", /*w*/ 220: "q", /*q*/ 221: "/", /*/*/ 222: ".", /*.*/ 223: "g", /*g*/ 224: 0, /*3/4*/ 225: ",", /*,*/ 226: "&", /*&*/ 227: "y", /*y*/ 228: 0, /*blank*/ 229: "%", /*%*/ 230: 0, /*blank*/ 231: "Q", /*Q*/ 232: "T", /*T*/ 233: "O", /*O*/ 234: "H", /*H*/ 235: "N", /*N*/ 236: "M", /*M*/ 237: "L", /*L*/ 238: "R", /*R*/ 239: "G", /*G*/ 240: "I", /*I*/ 241: "P", /*P*/ 242: "C", /*C*/ 243: "V", /*V*/ 244: "E", /*E*/ 245: "Z", /*Z*/ 246: "D", /*D*/ 247: "B", /*B*/ 248: "S", /*S*/ 249: "Y", /*Y*/ 250: 0, /*blank*/ 251: "F", /*F*/ 252: "X", /*X*/ 253: "A", /*A*/ 254: "W", /*W*/ 255: "J", /*J*/ 256: "U", /*U*/ 257: "K", /*K*/ 258: "0", /*0*/ 259: "1", /*1*/ 260: "2", /*2*/ 261: "3", /*3*/ 262: "4", /*4*/ 263: "5", /*5*/ 264: "6", /*6*/ 265: "7", /*7*/ 266: "8", /*8*/ 267: "9", /*9*/ 268: "*", /***/ 269: "-", /*minus*/ 270: 0, /*fi*/ 271: 0, /*fl*/ 272: 0, /*ff*/ 273: 0, /*cent mark*/ 274: 0, /*ffl*/ 275: 0, /* ffi */ 276: "(", /*(*/ 277: ")", /*)*/ 278: "[", /*[*/ 279: "]", /*]*/ 280: 0, /*degree*/ 281: 0, /*dagger*/ 282: "=", /*=*/ 283: 0, /*registered*/ 284: ":", /*:*/ 285: "+", /*+*/ 286: 0, /*blank*/ 287: "!", /*!*/ 288: 0, /*bullet*/ 289: "?", /*?*/ 290: "'", /*foot mark*/ 291: "|", /*|*/ 292: 0, /*blank*/ 293: 0, /*copyright*/ 294: 0, /*square*/ 295: "$" }; /*$*/ 296: 297: char *spectab[128] = { 298: 0, /*blank*/ 299: 0, /*psi*/ 300: 0, /*theta*/ 301: 0, /*nu*/ 302: 0, /*mu*/ 303: 0, /*lambda*/ 304: 0, /*iota*/ 305: 0, /*zeta*/ 306: 0, /*sigma*/ 307: 0, /*delta*/ 308: 0, /*beta*/ 309: 0, /*xi*/ 310: 0, /*eta*/ 311: 0, /*phi*/ 312: "u", /*upsilon*/ 313: 0, /*kappa*/ 314: 0, /*blank*/ 315: 0, /*pi*/ 316: "@", /*at sign @*/ 317: 0, /*down arrow*/ 318: 0, /*blank*/ 319: 0, /*alpha*/ 320: "|", /*or*/ 321: 0, /*chi*/ 322: "\"", /*"*/ 323: 0, /*epsilon*/ 324: "=", /*equals*/ 325: "o", /*omicron*/ 326: 0, /*left arrow*/ 327: 0, /*rho*/ 328: 0, /*up arrow*/ 329: 0, /*tau*/ 330: "_", /*underrule*/ 331: "\\", /*\*/ 332: 0, /*Psi*/ 333: 0, /*bell system sign*/ 334: 0, /*infinity*/ 335: 0, /*gamma*/ 336: 0, /*improper superset*/ 337: 0, /*proportional to*/ 338: 0, /*right hand*/ 339: 0, /*omega*/ 340: 0, /*blank*/ 341: 0, /*gradient*/ 342: 0, /*blank*/ 343: 0, /*Phi*/ 344: 0, /*Theta*/ 345: 0, /*Omega*/ 346: 0, /*cup (union)*/ 347: 0, /*root en*/ 348: 0, /*terminal sigma*/ 349: 0, /*Lambda*/ 350: "-", /*some horizontal line*/ 351: 0, /*Gamma*/ 352: 0, /*integral sign*/ 353: 0, /*Pi*/ 354: 0, /*subset of*/ 355: 0, /*superset of*/ 356: 0, /*approximates*/ 357: 0, /*partial derivative*/ 358: 0, /*Delta*/ 359: 0, /*square root*/ 360: 0, /*Sigma*/ 361: 0, /*approx =*/ 362: 0, /*blank*/ 363: ">", /*>*/ 364: 0, /*Xi*/ 365: "<", /*<*/ 366: "/", /*slash (longer)*/ 367: 0, /*cap (intersection)*/ 368: "Y", /*Upsilon*/ 369: 0, /*not*/ 370: "|", /*right ceiling (rt of ")*/ 371: "|", /*left top (of big curly)*/ 372: "|", /*bold vertical*/ 373: "|", /*left center of big curly bracket*/ 374: "|", /*left bottom*/ 375: "|", /*right top*/ 376: "|", /*right center of big curly bracket*/ 377: "|", /*right bot*/ 378: "|", /*right floor (rb of ")*/ 379: "|", /*left floor (left bot of big sq bract)*/ 380: "|", /*left ceiling (lt of ")*/ 381: "x", /*multiply*/ 382: 0, /*divide*/ 383: 0, /*plus-minus*/ 384: 0, /*<=*/ 385: 0, /*>=*/ 386: 0, /*identically equal*/ 387: 0, /*not equal*/ 388: "{", /*{*/ 389: "}", /*}*/ 390: "'", /*' acute accent*/ 391: "`", /*` grave accent*/ 392: "^", /*^*/ 393: "#", /*sharp*/ 394: 0, /*left hand*/ 395: 0, /*member of*/ 396: "~", /*~*/ 397: 0, /*empty set*/ 398: 0, /*blank*/ 399: 0, /*dbl dagger*/ 400: "|", /*box rule*/ 401: "*", /*telephone asterisk?*/ 402: 0, /*improper subset*/ 403: 0, /*circle*/ 404: 0, /*blank*/ 405: "+", /*eqn plus sign*/ 406: 0, /*right arrow*/ 407: 0 }; /*section mark*/