Annotation of 43BSD/old/berknet/chktroff.c, revision 1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.