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