Annotation of researchv10no/cmd/troff/ancient.nroff/n2.c, revision 1.1

1.1     ! root        1: #include "tdef.hd"
        !             2: #ifdef unix
        !             3: #include <sgtty.h>
        !             4: #endif
        !             5: #include "strs.hd"
        !             6: #ifdef NROFF
        !             7: #include "tw.hd"
        !             8: extern struct ttable t;
        !             9: #endif
        !            10: #ifdef unix
        !            11: #include <setjmp.h>
        !            12: extern jmp_buf sjbuf;
        !            13: #endif
        !            14: 
        !            15: /*
        !            16: troff2.c
        !            17: 
        !            18: output, cleanup
        !            19: */
        !            20: 
        !            21: extern struct s *frame, *stk, *nxf;
        !            22: extern struct tmpfaddr ip;
        !            23: extern struct tmpfaddr offset;
        !            24: #ifndef INCORE
        !            25: extern struct envblock eblock;
        !            26: #else
        !            27: extern struct envblock eblock[NEV];
        !            28: extern int ev;
        !            29: #endif
        !            30: extern struct datablock dblock;
        !            31: extern struct d d[NDI], *dip;
        !            32: 
        !            33: extern char *enda;
        !            34: 
        !            35: 
        !            36: extern int ch_CMASK;
        !            37: extern char obuf[OBUFSZ];
        !            38: extern char *obufp;
        !            39: extern int dilev;
        !            40: extern int eschar;
        !            41: extern int tlss;
        !            42: extern int tflg;
        !            43: extern int ascii;
        !            44: extern int print;
        !            45: extern int waitf;
        !            46: extern char ptname[];
        !            47: extern filedes ptid;
        !            48: extern int em;
        !            49: extern int ds;
        !            50: extern int mflg;
        !            51: extern struct tmpfaddr woff;
        !            52: extern int nflush;
        !            53: extern int lgf;
        !            54: extern int app;
        !            55: extern int nfo;
        !            56: extern int donef;
        !            57: extern int nofeed;
        !            58: extern int trap;
        !            59: extern struct sgttyb ttys;
        !            60: extern int ttysave;
        !            61: extern int quiet;
        !            62: extern int ndone;
        !            63: extern int lead;
        !            64: extern int ralss;
        !            65: extern int gflag;
        !            66: extern char *unlkp;
        !            67: extern char newf[];
        !            68: extern int ejf;
        !            69: extern int no_out;
        !            70: extern int level;
        !            71: extern int stop;
        !            72: int toolate;
        !            73: int error;
        !            74: #ifndef NROFF
        !            75: extern int paper;
        !            76: extern int acctf;
        !            77: #else
        !            78: #ifndef SMALL
        !            79: extern int pipeflg;
        !            80: #endif
        !            81: #endif
        !            82: pchar(c)
        !            83: int c;
        !            84: {
        !            85:        register j;
        !            86: 
        !            87:        if(c & MOT){pchar1(c); return;}
        !            88:        switch(j = c & CMASK){
        !            89:                case 0:
        !            90:                case IMP:
        !            91:                case RIGHT:
        !            92:                case LEFT:
        !            93:                        return;
        !            94:                case HX:
        !            95:                        j = (tlss>>9) | ((c&~0777)>>3);
        !            96:                        if(c & 040000){
        !            97:                                j &= ~(040000>>3);
        !            98:                                if(j > dip->blss)dip->blss = j;
        !            99:                        }else{
        !           100:                                if(j > dip->alss)dip->alss = j;
        !           101:                                ralss = dip->alss;
        !           102:                        }
        !           103:                        tlss = 0;
        !           104:                        return;
        !           105:                case LX:
        !           106:                        tlss = c;
        !           107:                        return;
        !           108:                case PRESC:
        !           109:                        if (dilev == 0) j = eschar;
        !           110:                default:
        !           111:                        c = (trtab[j] & BMASK) | (c & ~CMASK);
        !           112:        }
        !           113:        pchar1(c);
        !           114: }
        !           115: pchar1(c)
        !           116: int c;
        !           117: {
        !           118:        register j, *k;
        !           119:        extern int chtab[];
        !           120: 
        !           121:        j = c & CMASK;
        !           122:        if (dilev > 0) {
        !           123:                wbf(c);
        !           124:                cptmpfaddr(dip->op,offset);
        !           125:                return;
        !           126:        }
        !           127:        if(!tflg && !print){
        !           128:                if(j == '\n')dip->alss = dip->blss = 0;
        !           129:                return;
        !           130:        }
        !           131:        if(no_out || (j == FILLER))return;
        !           132: #ifndef NROFF
        !           133:        if(ascii){
        !           134:                if(c & MOT){
        !           135:                        oput(' ');
        !           136:                        return;
        !           137:                }
        !           138:                if(j < 0177){
        !           139:                        oput(c);
        !           140:                        return;
        !           141:                }
        !           142:                switch(j){
        !           143:                        case 0200:
        !           144:                        case 0210:
        !           145:                                oput('-');
        !           146:                                break;
        !           147:                        case 0211:
        !           148:                                oputs("\146\151"/*fi*/);
        !           149:                                break;
        !           150:                        case 0212:
        !           151:                                oputs("\146\154"/*fl*/);
        !           152:                                break;
        !           153:                        case 0213:
        !           154:                                oputs("\146\146"/*ff*/);
        !           155:                                break;
        !           156:                        case 0214:
        !           157:                                oputs("\146\146\151"/*ffi*/);
        !           158:                                break;
        !           159:                        case 0215:
        !           160:                                oputs("\146\146\154"/*ffl*/);
        !           161:                                break;
        !           162:                        default:
        !           163:                                for(k=chtab; *++k != j; k++)
        !           164:                                        if(*k == 0)return;
        !           165:                                oput('\\');
        !           166:                                oput('(');
        !           167:                                oput(*--k & BMASK);
        !           168:                                oput(*k >> BYTE);
        !           169:                }
        !           170:        }else
        !           171: #endif
        !           172:        ptout(c);
        !           173: }
        !           174: oput(i)
        !           175: char i;
        !           176: {
        !           177:        *obufp++ = i;
        !           178:        if(obufp == (obuf + OBUFSZ + ascii - 1))flusho();
        !           179: }
        !           180: oputs(i)
        !           181: char *i;
        !           182: {
        !           183:        while(*i != 0)oput(*i++);
        !           184: }
        !           185: flusho(){
        !           186:        if(!ascii)*obufp++ = 0;
        !           187: #ifdef unix
        !           188:        if(!ptid){
        !           189:                while((ptid=open(ptname,1)) < 0){
        !           190:                        if(++waitf <=2)prstr("Waiting for Typesetter.\n");
        !           191:                        sleep(15);
        !           192:                }
        !           193:        }
        !           194: #endif
        !           195:        if(no_out == 0){
        !           196:                if (!toolate) {
        !           197:                        toolate++;
        !           198: #ifdef NROFF
        !           199: #ifdef unix
        !           200:                        if(t.bset || t.breset){
        !           201:                                if(ttysave == -1) {
        !           202:                                        gtty(1, &ttys);
        !           203:                                        ttysave = ttys.sg_flags;
        !           204:                                }
        !           205:                                ttys.sg_flags &= ~t.breset;
        !           206:                                ttys.sg_flags |= t.bset;
        !           207:                                stty(1, &ttys);
        !           208:                        }
        !           209: #endif
        !           210:                        {
        !           211:                        char *p = t.twinit;
        !           212:                        while (*p++)
        !           213:                                ;
        !           214: #ifdef unix
        !           215:                        write(ptid, t.twinit, p-t.twinit-1);
        !           216: #endif
        !           217: #ifdef tso
        !           218:                        fwrite(t.twinit,p-t.twinit-1,1,ptid);
        !           219: #endif
        !           220:                        }
        !           221: #endif
        !           222:                }
        !           223: #ifdef unix
        !           224:                toolate += write(ptid, obuf, obufp-obuf);
        !           225: #endif
        !           226: #ifdef tso
        !           227:                toolate += fwrite(obuf,obufp-obuf,1,ptid);
        !           228: #endif
        !           229:        }
        !           230:        obufp = obuf;
        !           231: }
        !           232: done(x) int x;{
        !           233:        register i;
        !           234: 
        !           235:        error |= x;
        !           236:        level = 0;
        !           237:        app = ds = lgf = 0;
        !           238:        if(i=em){
        !           239:                donef = -1;
        !           240:                em = 0;
        !           241: #ifdef unix
        !           242:                if(control(i,0))longjmp(sjbuf,1);
        !           243: #endif
        !           244: #ifdef tso
        !           245:                if (control(i,0)) reset(0);
        !           246: #endif
        !           247:        }
        !           248:        if(!nfo)done3(0);
        !           249:        mflg = 0;
        !           250:        dip = &d[dilev = 0];
        !           251:        if (woff.b) wbt(0);
        !           252:        if(pendw)getword(1);
        !           253:        pendnf = 0;
        !           254:        if(donef == 1)done1(0);
        !           255:        donef = 1;
        !           256:        ip.b = 0;
        !           257:        frame = stk;
        !           258: #ifndef INCORE
        !           259:        nxf = frame + 1;
        !           260: #else
        !           261:        nxf = (struct s *)malloc(sizeof(struct s));
        !           262: #endif
        !           263:        if(!ejf)tbreak();
        !           264:        nflush++;
        !           265:        eject((struct s *)0);
        !           266: #ifdef unix
        !           267:        longjmp(sjbuf,1);
        !           268: #endif
        !           269: #ifdef tso
        !           270:        reset(0);
        !           271: #endif
        !           272: }
        !           273: done1(x) int x; {
        !           274:        error |= x;
        !           275:        if(v_nl){
        !           276:                trap = 0;
        !           277:                eject((struct s *)0);
        !           278: #ifdef unix
        !           279:                longjmp(sjbuf,1);
        !           280: #endif
        !           281: #ifdef tso
        !           282:                reset(0);
        !           283: #endif
        !           284:        }
        !           285:        if(nofeed){
        !           286:                ptlead();
        !           287:                flusho();
        !           288:                done3(0);
        !           289:        }else{
        !           290:                if(!gflag)lead += TRAILER;
        !           291:                done2(0);
        !           292:        }
        !           293: }
        !           294: done2(x) int x; {
        !           295:        register i;
        !           296: 
        !           297:        ptlead();
        !           298: #ifndef NROFF
        !           299:        if(!ascii){
        !           300:                oput(T_INIT);
        !           301:                oput(T_STOP);
        !           302:                if(!gflag)for(i=8; i>0; i--)oput(T_PAD);
        !           303: #ifndef tso
        !           304:                if(stop && (ptid != 1)) prstr("Troff finished.\n");
        !           305: #endif
        !           306:        }
        !           307: #endif
        !           308:        flusho();
        !           309:        done3(x);
        !           310: }
        !           311: done3(x) int x;{
        !           312:        error |= x;
        !           313: #ifdef unix
        !           314:        signal(SIGINT, SIG_IGN);
        !           315:        signal(SIGTERM, SIG_IGN);
        !           316: #ifndef INCORE
        !           317:        unlink(unlkp);
        !           318: #endif
        !           319: #endif
        !           320: #ifdef NROFF
        !           321:        twdone();
        !           322: #endif
        !           323: #ifdef unix
        !           324:        if(quiet){
        !           325:                ttys.sg_flags |= ECHO;
        !           326:                stty(0, &ttys);
        !           327:        }
        !           328: #endif
        !           329:        if(ascii)mesg(1);
        !           330: #ifndef NROFF
        !           331: #ifndef SMALL
        !           332:        report();
        !           333: #endif
        !           334: #endif
        !           335:        exit(error);
        !           336: }
        !           337: edone(x) int x;{
        !           338:        frame = stk;
        !           339: #ifndef INCORE
        !           340:        nxf = frame + 1;
        !           341: #else
        !           342:        nxf = (struct s *)malloc(sizeof(struct s));
        !           343: #endif
        !           344:        ip.b = 0;
        !           345:        done(x);
        !           346: }
        !           347: 
        !           348: #ifndef NROFF
        !           349: #ifndef SMALL
        !           350: report(){
        !           351:        struct {int use; int uid;} a;
        !           352: 
        !           353:        if((ptid != 1) && paper ){
        !           354:                lseek(acctf,0L,2);
        !           355:                a.use = paper;
        !           356:                a.uid = getuid();
        !           357:                write(acctf,(char *)&a,sizeof(a));
        !           358:        }
        !           359: }
        !           360: #endif
        !           361: #endif
        !           362: #ifdef NROFF
        !           363: casepi(){
        !           364: #ifndef SMALL
        !           365:        register i;
        !           366:        int id[2];
        !           367: 
        !           368:        if(toolate || skip() || !getname() || (pipe(id) == -1) ||
        !           369:           ((i=fork()) == -1)){
        !           370:                prstr("Pipe not created.\n");
        !           371:                return;
        !           372:        }
        !           373:        ptid = id[1];
        !           374:        if(i>0){
        !           375:                close(id[0]);
        !           376:                toolate++;
        !           377:                pipeflg++;
        !           378:                return;
        !           379:        }
        !           380:        close(0);
        !           381:        dup(id[0]);
        !           382:        close(id[1]);
        !           383:        execl(newf,newf,0);
        !           384:        prstr("Cannot exec: ");
        !           385:        prstr(newf);
        !           386:        prstr("\n");
        !           387:        exit(-4);
        !           388: #endif
        !           389: }
        !           390: #endif

unix.superglobalmegacorp.com

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