|
|
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: #ifndef NOFP ! 158: f = ((float)leadtot / (float)(144 * 12)); ! 159: if(f > FEET){ ! 160: printf("Only %3.0f feet maximum per request. Sorry.\n",FEET); ! 161: exit(1); ! 162: } ! 163: #endif ! 164: continue; ! 165: } ! 166: if((i & 0360) == 0120){ /*size change*/ ! 167: i &= 017; ! 168: for(j = 0; i != (stab[j] & 017); j++); ! 169: osize = size; ! 170: size = stab[j]; ! 171: if(!lflg){ ! 172: printf("Size %d",rtab[j]); ! 173: if(!(osize & DBL) && (size & DBL))printf(", double\n"); ! 174: else if((osize & DBL) && !(size & DBL))printf(", single\n"); ! 175: else printf("\n"); ! 176: } ! 177: continue; ! 178: } ! 179: if(i & 0300)continue; ! 180: i = (i & 077) | mcase; ! 181: if(railmag != 03)k = asctab[i]; ! 182: else k = spectab[i]; ! 183: if(!lflg)printf("%s\n",k); ! 184: continue; ! 185: } ! 186: ex(); ! 187: } ! 188: ex(){ ! 189: #ifndef NOFP ! 190: double f1; ! 191: f1 = ((leadtot * 3)/432.0)/12.0; ! 192: printf("Total bytes %ld, lead %d, feet %4.2f\n",bytetot,leadtot,f1); ! 193: if(stop != 1 || init != 2){ ! 194: printf("Error - wrong # init %d, # stop %d\n",init,stop); ! 195: exit(1); ! 196: } ! 197: #endif ! 198: exit(0); ! 199: } ! 200: getc(){ ! 201: register i; ! 202: ! 203: if(ibufp >= eibufp){ ! 204: if((i=read(fid,ibuf,BUFSIZ)) <= 0)ex(); ! 205: eibufp = ibuf + i; ! 206: ibufp = ibuf; ! 207: bytetot += i; ! 208: } ! 209: return(*ibufp++ & 0377); ! 210: } ! 211: char *asctab[128] = { ! 212: 0, /*blank*/ ! 213: "h", /*h*/ ! 214: "t", /*t*/ ! 215: "n", /*n*/ ! 216: "m", /*m*/ ! 217: "l", /*l*/ ! 218: "i", /*i*/ ! 219: "z", /*z*/ ! 220: "s", /*s*/ ! 221: "d", /*d*/ ! 222: "b", /*b*/ ! 223: "x", /*x*/ ! 224: "f", /*f*/ ! 225: "j", /*j*/ ! 226: "u", /*u*/ ! 227: "k", /*k*/ ! 228: 0, /*blank*/ ! 229: "p", /*p*/ ! 230: "-", /*_ 3/4 em dash*/ ! 231: ";", /*;*/ ! 232: 0, /*blank*/ ! 233: "a", /*a*/ ! 234: "_", /*rule*/ ! 235: "c", /*c*/ ! 236: "`", /*` open*/ ! 237: "e", /*e*/ ! 238: "'", /*' close*/ ! 239: "o", /*o*/ ! 240: 0, /*1/4*/ ! 241: "r", /*r*/ ! 242: 0, /*1/2*/ ! 243: "v", /*v*/ ! 244: "-", /*- hyphen*/ ! 245: "w", /*w*/ ! 246: "q", /*q*/ ! 247: "/", /*/*/ ! 248: ".", /*.*/ ! 249: "g", /*g*/ ! 250: 0, /*3/4*/ ! 251: ",", /*,*/ ! 252: "&", /*&*/ ! 253: "y", /*y*/ ! 254: 0, /*blank*/ ! 255: "%", /*%*/ ! 256: 0, /*blank*/ ! 257: "Q", /*Q*/ ! 258: "T", /*T*/ ! 259: "O", /*O*/ ! 260: "H", /*H*/ ! 261: "N", /*N*/ ! 262: "M", /*M*/ ! 263: "L", /*L*/ ! 264: "R", /*R*/ ! 265: "G", /*G*/ ! 266: "I", /*I*/ ! 267: "P", /*P*/ ! 268: "C", /*C*/ ! 269: "V", /*V*/ ! 270: "E", /*E*/ ! 271: "Z", /*Z*/ ! 272: "D", /*D*/ ! 273: "B", /*B*/ ! 274: "S", /*S*/ ! 275: "Y", /*Y*/ ! 276: 0, /*blank*/ ! 277: "F", /*F*/ ! 278: "X", /*X*/ ! 279: "A", /*A*/ ! 280: "W", /*W*/ ! 281: "J", /*J*/ ! 282: "U", /*U*/ ! 283: "K", /*K*/ ! 284: "0", /*0*/ ! 285: "1", /*1*/ ! 286: "2", /*2*/ ! 287: "3", /*3*/ ! 288: "4", /*4*/ ! 289: "5", /*5*/ ! 290: "6", /*6*/ ! 291: "7", /*7*/ ! 292: "8", /*8*/ ! 293: "9", /*9*/ ! 294: "*", /***/ ! 295: "-", /*minus*/ ! 296: 0, /*fi*/ ! 297: 0, /*fl*/ ! 298: 0, /*ff*/ ! 299: 0, /*cent mark*/ ! 300: 0, /*ffl*/ ! 301: 0, /* ffi */ ! 302: "(", /*(*/ ! 303: ")", /*)*/ ! 304: "[", /*[*/ ! 305: "]", /*]*/ ! 306: 0, /*degree*/ ! 307: 0, /*dagger*/ ! 308: "=", /*=*/ ! 309: 0, /*registered*/ ! 310: ":", /*:*/ ! 311: "+", /*+*/ ! 312: 0, /*blank*/ ! 313: "!", /*!*/ ! 314: 0, /*bullet*/ ! 315: "?", /*?*/ ! 316: "'", /*foot mark*/ ! 317: "|", /*|*/ ! 318: 0, /*blank*/ ! 319: 0, /*copyright*/ ! 320: 0, /*square*/ ! 321: "$" }; /*$*/ ! 322: ! 323: char *spectab[128] = { ! 324: 0, /*blank*/ ! 325: 0, /*psi*/ ! 326: 0, /*theta*/ ! 327: 0, /*nu*/ ! 328: 0, /*mu*/ ! 329: 0, /*lambda*/ ! 330: 0, /*iota*/ ! 331: 0, /*zeta*/ ! 332: 0, /*sigma*/ ! 333: 0, /*delta*/ ! 334: 0, /*beta*/ ! 335: 0, /*xi*/ ! 336: 0, /*eta*/ ! 337: 0, /*phi*/ ! 338: "u", /*upsilon*/ ! 339: 0, /*kappa*/ ! 340: 0, /*blank*/ ! 341: 0, /*pi*/ ! 342: "@", /*at sign @*/ ! 343: 0, /*down arrow*/ ! 344: 0, /*blank*/ ! 345: 0, /*alpha*/ ! 346: "|", /*or*/ ! 347: 0, /*chi*/ ! 348: "\"", /*"*/ ! 349: 0, /*epsilon*/ ! 350: "=", /*equals*/ ! 351: "o", /*omicron*/ ! 352: 0, /*left arrow*/ ! 353: 0, /*rho*/ ! 354: 0, /*up arrow*/ ! 355: 0, /*tau*/ ! 356: "_", /*underrule*/ ! 357: "\\", /*\*/ ! 358: 0, /*Psi*/ ! 359: 0, /*bell system sign*/ ! 360: 0, /*infinity*/ ! 361: 0, /*gamma*/ ! 362: 0, /*improper superset*/ ! 363: 0, /*proportional to*/ ! 364: 0, /*right hand*/ ! 365: 0, /*omega*/ ! 366: 0, /*blank*/ ! 367: 0, /*gradient*/ ! 368: 0, /*blank*/ ! 369: 0, /*Phi*/ ! 370: 0, /*Theta*/ ! 371: 0, /*Omega*/ ! 372: 0, /*cup (union)*/ ! 373: 0, /*root en*/ ! 374: 0, /*terminal sigma*/ ! 375: 0, /*Lambda*/ ! 376: "-", /*some horizontal line*/ ! 377: 0, /*Gamma*/ ! 378: 0, /*integral sign*/ ! 379: 0, /*Pi*/ ! 380: 0, /*subset of*/ ! 381: 0, /*superset of*/ ! 382: 0, /*approximates*/ ! 383: 0, /*partial derivative*/ ! 384: 0, /*Delta*/ ! 385: 0, /*square root*/ ! 386: 0, /*Sigma*/ ! 387: 0, /*approx =*/ ! 388: 0, /*blank*/ ! 389: ">", /*>*/ ! 390: 0, /*Xi*/ ! 391: "<", /*<*/ ! 392: "/", /*slash (longer)*/ ! 393: 0, /*cap (intersection)*/ ! 394: "Y", /*Upsilon*/ ! 395: 0, /*not*/ ! 396: "|", /*right ceiling (rt of ")*/ ! 397: "|", /*left top (of big curly)*/ ! 398: "|", /*bold vertical*/ ! 399: "|", /*left center of big curly bracket*/ ! 400: "|", /*left bottom*/ ! 401: "|", /*right top*/ ! 402: "|", /*right center of big curly bracket*/ ! 403: "|", /*right bot*/ ! 404: "|", /*right floor (rb of ")*/ ! 405: "|", /*left floor (left bot of big sq bract)*/ ! 406: "|", /*left ceiling (lt of ")*/ ! 407: "x", /*multiply*/ ! 408: 0, /*divide*/ ! 409: 0, /*plus-minus*/ ! 410: 0, /*<=*/ ! 411: 0, /*>=*/ ! 412: 0, /*identically equal*/ ! 413: 0, /*not equal*/ ! 414: "{", /*{*/ ! 415: "}", /*}*/ ! 416: "'", /*' acute accent*/ ! 417: "`", /*` grave accent*/ ! 418: "^", /*^*/ ! 419: "#", /*sharp*/ ! 420: 0, /*left hand*/ ! 421: 0, /*member of*/ ! 422: "~", /*~*/ ! 423: 0, /*empty set*/ ! 424: 0, /*blank*/ ! 425: 0, /*dbl dagger*/ ! 426: "|", /*box rule*/ ! 427: "*", /*telephone asterisk?*/ ! 428: 0, /*improper subset*/ ! 429: 0, /*circle*/ ! 430: 0, /*blank*/ ! 431: "+", /*eqn plus sign*/ ! 432: 0, /*right arrow*/ ! 433: 0 }; /*section mark*/
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.