Annotation of 41BSD/cmd/troff/n2.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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