Annotation of researchv10no/cmd/troff/Old/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: 
                     14: /*
                     15: troff2.c
                     16: 
                     17: output, cleanup
                     18: */
                     19: 
                     20: #include "ext.h"
                     21: extern jmp_buf sjbuf;
                     22: int    toolate;
                     23: int    error;
                     24: 
                     25: pchar(i)
                     26: tchar i;
                     27: {
                     28:        int j;
                     29:        static int hx = 0;      /* records if have seen HX */
                     30: 
                     31:        if (hx) {
                     32:                hx = 0;
                     33:                j = absmot(i);
                     34:                if (isnmot(i)) {
                     35:                        if (j > dip->blss)
                     36:                                dip->blss = j;
                     37:                } else {
                     38:                        if (j > dip->alss)
                     39:                                dip->alss = j;
                     40:                        ralss = dip->alss;
                     41:                }
                     42:                return;
                     43:        }
                     44:        if (ismot(i)) {
                     45:                pchar1(i); 
                     46:                return;
                     47:        }
                     48:        switch (j = cbits(i)) {
                     49:        case 0:
                     50:        case IMP:
                     51:        case RIGHT:
                     52:        case LEFT:
                     53:                return;
                     54:        case HX:
                     55:                hx = 1;
                     56:                return;
                     57:        case PRESC:
                     58:                if (dip == &d[0])
                     59:                        j = eschar;     /* fall through */
                     60:        default:
                     61:                setcbits(i, trtab[j]);
                     62:        }
                     63:        pchar1(i);
                     64: }
                     65: 
                     66: 
                     67: pchar1(i)
                     68: tchar i;
                     69: {
                     70:        register j, *k;
                     71: 
                     72:        j = cbits(i);
                     73:        if (dip != &d[0]) {
                     74:                wbf(i);
                     75:                dip->op = offset;
                     76:                return;
                     77:        }
                     78:        if (!tflg && !print) {
                     79:                if (j == '\n')
                     80:                        dip->alss = dip->blss = 0;
                     81:                return;
                     82:        }
                     83:        if (no_out || j == FILLER)
                     84:                return;
                     85:        if (tflg) {     /* transparent mode, undiverted */
                     86:                fprintf(ptid, "%c", j);
                     87:                return;
                     88:        }
                     89: #ifndef NROFF
                     90:        if (ascii) {
                     91:                if (ismot(i)) {
                     92:                        oput(' ');
                     93:                        return;
                     94:                }
                     95:                if (j < 0177) {
                     96:                        oput(j);
                     97:                        return;
                     98:                }
                     99:                if (j == HYPHEN || j == MINUS)
                    100:                        oput('-');
                    101:                else if (j == LIG_FI)
                    102:                        oputs("fi");
                    103:                else if (j == LIG_FL)
                    104:                        oputs("fl");
                    105:                else if (j == LIG_FF)
                    106:                        oputs("ff");
                    107:                else if (j == LIG_FFI)
                    108:                        oputs("ffi");
                    109:                else if (j == LIG_FFL)
                    110:                        oputs("ffl");
                    111:                else if (j == NARSP || j == HNARSP || j == WORDSP)
                    112:                        ;       /* nothing at all */
                    113:                else {
                    114:                        oput('\\');
                    115:                        oput('(');
                    116:                        oput(chname[chtab[j-128]]);
                    117:                        oput(chname[chtab[j-128]+1]);
                    118:                }
                    119:        } else
                    120: #endif
                    121:                ptout(i);
                    122: }
                    123: 
                    124: 
                    125: oput(i)
                    126: char   i;
                    127: {
                    128:        *obufp++ = i;
                    129:        if (obufp >= &obuf[OBUFSZ])
                    130:                flusho();
                    131: }
                    132: 
                    133: 
                    134: oputs(i)
                    135: register char  *i;
                    136: {
                    137:        while (*i != 0)
                    138:                oput(*i++);
                    139: }
                    140: 
                    141: 
                    142: flusho()
                    143: {
                    144:        if (obufp == obuf)
                    145:                return;
                    146:        if (no_out == 0) {
                    147:                if (!toolate) {
                    148:                        toolate++;
                    149: #ifdef NROFF
                    150:                        if (t.bset || t.breset) {
                    151:                                if (ttysave == -1) {
                    152:                                        gtty(1, &ttys);
                    153:                                        ttysave = ttys.sg_flags;
                    154:                                }
                    155:                                ttys.sg_flags &= ~t.breset;
                    156:                                ttys.sg_flags |= t.bset;
                    157:                                stty(1, &ttys);
                    158:                        }
                    159:                         {
                    160:                                char    *p = t.twinit;
                    161:                                while (*p++)
                    162:                                        ;
                    163:                                write(ptid, t.twinit, p - t.twinit - 1);
                    164:                        }
                    165: #endif
                    166:                }
                    167:                toolate += write(ptid, obuf, obufp - obuf);
                    168:        }
                    169:        obufp = obuf;
                    170: }
                    171: 
                    172: 
                    173: done(x) 
                    174: int    x;
                    175: {
                    176:        register i;
                    177: 
                    178:        error |= x;
                    179:        level = 0;
                    180:        app = ds = lgf = 0;
                    181:        if (i = em) {
                    182:                donef = -1;
                    183:                em = 0;
                    184:                if (control(i, 0))
                    185:                        longjmp(sjbuf, 1);
                    186:        }
                    187:        if (!nfo)
                    188:                done3(0);
                    189:        mflg = 0;
                    190:        dip = &d[0];
                    191:        if (woff)
                    192:                wbt((tchar)0);
                    193:        if (pendw)
                    194:                getword(1);
                    195:        pendnf = 0;
                    196:        if (donef == 1)
                    197:                done1(0);
                    198:        donef = 1;
                    199:        ip = 0;
                    200:        frame = stk;
                    201:        nxf = frame + 1;
                    202:        if (!ejf)
                    203:                tbreak();
                    204:        nflush++;
                    205:        eject((struct s *)0);
                    206:        longjmp(sjbuf, 1);
                    207: }
                    208: 
                    209: 
                    210: done1(x) 
                    211: int    x; 
                    212: {
                    213:        error |= x;
                    214:        if (v.nl) {
                    215:                trap = 0;
                    216:                eject((struct s *)0);
                    217:                longjmp(sjbuf, 1);
                    218:        }
                    219:        if (nofeed) {
                    220:                ptlead();
                    221:                flusho();
                    222:                done3(0);
                    223:        } else {
                    224:                if (!gflag)
                    225:                        pttrailer();
                    226:                done2(0);
                    227:        }
                    228: }
                    229: 
                    230: 
                    231: done2(x) 
                    232: int    x; 
                    233: {
                    234:        ptlead();
                    235: #ifndef NROFF
                    236:        if (!ascii)
                    237:                ptstop();
                    238: #endif
                    239:        flusho();
                    240:        done3(x);
                    241: }
                    242: 
                    243: done3(x) 
                    244: int    x;
                    245: {
                    246:        error |= x;
                    247:        signal(SIGINT, SIG_IGN);
                    248:        signal(SIGTERM, SIG_IGN);
                    249:        unlink(unlkp);
                    250: #ifdef NROFF
                    251:        twdone();
                    252: #endif
                    253:        if (quiet) {
                    254:                ttys.sg_flags |= ECHO;
                    255:                stty(0, &ttys);
                    256:        }
                    257:        if (ascii)
                    258:                mesg(1);
                    259:        exit(error);
                    260: }
                    261: 
                    262: 
                    263: edone(x) 
                    264: int    x;
                    265: {
                    266:        frame = stk;
                    267:        nxf = frame + 1;
                    268:        ip = 0;
                    269:        done(x);
                    270: }
                    271: 
                    272: 
                    273: 
                    274: casepi()
                    275: {
                    276:        register i;
                    277:        int     id[2];
                    278: 
                    279:        if (toolate || skip() || !getname() || pipe(id) == -1 || (i = fork()) == -1) {
                    280:                fprintf(stderr, "Pipe not created.\n");
                    281:                return;
                    282:        }
                    283:        ptid = id[1];
                    284:        if (i > 0) {
                    285:                close(id[0]);
                    286:                toolate++;
                    287:                pipeflg++;
                    288:                return;
                    289:        }
                    290:        close(0);
                    291:        dup(id[0]);
                    292:        close(id[1]);
                    293:        execl(nextf, nextf, 0);
                    294:        fprintf(stderr, "Cannot exec %s\n", nextf);
                    295:        exit(-4);
                    296: }

unix.superglobalmegacorp.com

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