Annotation of researchv10no/cmd/troff/Old/catversion/gt.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *     gt - converts troff -g output to troff -t
        !             3:  */
        !             4: 
        !             5: #define N 65
        !             6: char obuf[512];
        !             7: char ibuf[512];
        !             8: char *ibufp ibuf;
        !             9: char *eibufp ibuf;
        !            10: char *obufp obuf;
        !            11: int id;
        !            12: int stop 100;
        !            13: int first 1;
        !            14: int pn 0;
        !            15: int skip 0;
        !            16: int xxx;
        !            17: 
        !            18: main(argc,argv)
        !            19: int argc;
        !            20: char **argv;
        !            21: {
        !            22:        register i, j;
        !            23: 
        !            24:        while((--argc > 0) && ((++argv)[0][0]=='-')){
        !            25:                switch(argv[0][1]){
        !            26:                        case 's':
        !            27:                                stop = atoi(&argv[0][2]);
        !            28:                                continue;
        !            29:                        case 'k':
        !            30:                                skip = atoi(&argv[0][2]);
        !            31:                                skip++;
        !            32:                                continue;
        !            33:                        case 'o':
        !            34:                                getpn(&argv[0][2]);
        !            35:                                continue;
        !            36:                        default:
        !            37:                                continue;
        !            38:                }
        !            39:        }
        !            40:        if(argc){
        !            41:                if((id=open(argv[0],0)) < 0){
        !            42:                        printf("Cannot open: %s\n",argv[0]);
        !            43:                        exit(1);
        !            44:                }
        !            45:        }
        !            46:        while(1){
        !            47:                oput(i=igetc());
        !            48:                if(i == 0100){ /*init*/
        !            49:                        if(pn++ > stop){
        !            50:                                pn = 1;
        !            51:                                trailer();
        !            52:                        }
        !            53:                        if(skip){
        !            54:                                skip--;
        !            55:                                if(!skip)oput(0100);
        !            56:                        }
        !            57:                        if((i=igetc()) != 0111){  /*stop*/
        !            58:                                oput(i);
        !            59:                                continue;
        !            60:                        }else{
        !            61:                                switch(i=igetc()){
        !            62:                                        case 'f':
        !            63:                                                for(j=8; j>0; j--)igetc();
        !            64:                                                if(first && !skip){
        !            65:                                                        first = 0;
        !            66:                                                        oput(0140);
        !            67:                                                }
        !            68:                                                continue;
        !            69:                                        case 0:
        !            70:                                                trailer();
        !            71:                                                ex();
        !            72:                                        default:
        !            73:                                                oput(i);
        !            74:                                                continue;
        !            75:                                }
        !            76:                        }
        !            77:                }
        !            78:        }
        !            79: }
        !            80: trailer(){
        !            81:        register j;
        !            82: 
        !            83:        for(j=N; j>0; j--)oput(0140);
        !            84:        oput(0111);
        !            85:        for(j=8; j>0; j--)oput(0101);
        !            86: }
        !            87: ex(){
        !            88:        oflush();
        !            89:        exit(0);
        !            90: }
        !            91: igetc(){
        !            92:        register i;
        !            93: 
        !            94:        if(ibufp >= eibufp){
        !            95:                if((i=read(id,ibuf,512)) <= 0)ex();
        !            96:                eibufp = ibuf + i;
        !            97:                ibufp = ibuf;
        !            98:        }
        !            99:        return((*ibufp++) & 0377);
        !           100: }
        !           101: oput(i)
        !           102: char i;
        !           103: {
        !           104:        if(skip)return;
        !           105:        *obufp++ = i;
        !           106:        if(obufp >= &obuf[512])oflush();
        !           107: }
        !           108: oflush(){
        !           109: 
        !           110:        if(obufp > obuf)
        !           111:                write(1,obuf,obufp-obuf);
        !           112:        obufp = obuf;
        !           113: }
        !           114: getpn(){}

unix.superglobalmegacorp.com

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