Annotation of researchv9/cmd/troff/n2.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * n2.c
                      3:  *
                      4:  * output, cleanup
                      5:  */
                      6: 
                      7: #include "tdef.h"
                      8: #include <ctype.h>
                      9: #include <signal.h>
                     10: #ifdef NROFF
                     11: #include "tw.h"
                     12: #endif
                     13: #include <setjmp.h>
                     14: #include "ext.h"
                     15: 
                     16: extern jmp_buf sjbuf;
                     17: int    toolate;
                     18: int    error;
                     19: extern int     nchtab;
                     20: 
                     21: pchar(i)
                     22:        register tchar i;
                     23: {
                     24:        register int j;
                     25:        static int hx = 0;      /* records if have seen HX */
                     26: 
                     27:        if (hx) {
                     28:                hx = 0;
                     29:                j = absmot(i);
                     30:                if (isnmot(i)) {
                     31:                        if (j > dip->blss)
                     32:                                dip->blss = j;
                     33:                } else {
                     34:                        if (j > dip->alss)
                     35:                                dip->alss = j;
                     36:                        ralss = dip->alss;
                     37:                }
                     38:                return;
                     39:        }
                     40:        if (ismot(i)) {
                     41:                pchar1(i); 
                     42:                return;
                     43:        }
                     44:        switch (j = cbits(i)) {
                     45:        case 0:
                     46:        case IMP:
                     47:        case RIGHT:
                     48:        case LEFT:
                     49:                return;
                     50:        case HX:
                     51:                hx = 1;
                     52:                return;
                     53:        case PRESC:
                     54:                if (dip == &d[0])
                     55:                        j = eschar;     /* fall through */
                     56:        default:
                     57:                setcbits(i, trtab[j]);
                     58:        }
                     59:        pchar1(i);
                     60: }
                     61: 
                     62: 
                     63: pchar1(i)
                     64:        register tchar i;
                     65: {
                     66:        register j;
                     67: 
                     68:        j = cbits(i);
                     69:        if (dip != &d[0]) {
                     70:                wbf(i);
                     71:                dip->op = offset;
                     72:                return;
                     73:        }
                     74:        if (!tflg && !print) {
                     75:                if (j == '\n')
                     76:                        dip->alss = dip->blss = 0;
                     77:                return;
                     78:        }
                     79:        if (no_out || j == FILLER)
                     80:                return;
                     81:        if (tflg) {     /* transparent mode, undiverted */
                     82:                fdprintf(ptid, "%c", j);
                     83:                return;
                     84:        }
                     85: #ifndef NROFF
                     86:        if (ascii)
                     87:                outascii(i);
                     88:        else
                     89: #endif
                     90:                ptout(i);
                     91: }
                     92: 
                     93: outascii(i)    /* print i in best-guess ascii */
                     94:        tchar i;
                     95: {
                     96:        int j = cbits(i);
                     97: 
                     98:        if (ismot(i)) {
                     99:                oput(' ');
                    100:                return;
                    101:        }
                    102:        if (j < 0177 && j >= ' ' || j == '\n') {
                    103:                oput(j);
                    104:                return;
                    105:        }
                    106:        if (j == DRAWFCN)
                    107:                oputs("\\D");
                    108:        else if (j == HYPHEN || j == MINUS)
                    109:                oput('-');
                    110:        else if (j == XON)
                    111:                oputs("\\X");
                    112:        else if (j == LIG_FI)
                    113:                oputs("fi");
                    114:        else if (j == LIG_FL)
                    115:                oputs("fl");
                    116:        else if (j == LIG_FF)
                    117:                oputs("ff");
                    118:        else if (j == LIG_FFI)
                    119:                oputs("ffi");
                    120:        else if (j == LIG_FFL)
                    121:                oputs("ffl");
                    122:        else if (j == WORDSP)
                    123:                ;       /* nothing at all */
                    124:        else if (j > 0177 && j < nchtab + 128-32) {
                    125:                oput('\\');
                    126:                oput('(');
                    127:                oput(chname[chtab[j-128]]);
                    128:                oput(chname[chtab[j-128]+1]);
                    129:        } else if (j >= nchtab + 128) {
                    130:                char buf[10];
                    131:                sprintf(buf, "N%d", j - (nchtab+128));
                    132:                oputs(buf);
                    133:        }
                    134: }
                    135: 
                    136: 
                    137: /*
                    138:  * now a macro
                    139: oput(i)
                    140:        register int    i;
                    141: {
                    142:        *obufp++ = i;
                    143:        if (obufp >= &obuf[OBUFSZ])
                    144:                flusho();
                    145: }
                    146: */
                    147: 
                    148: oputs(i)
                    149: register char  *i;
                    150: {
                    151:        while (*i != 0)
                    152:                oput(*i++);
                    153: }
                    154: 
                    155: 
                    156: flusho()
                    157: {
                    158:        if (obufp == obuf)
                    159:                return;
                    160:        if (no_out == 0) {
                    161:                if (!toolate) {
                    162:                        toolate++;
                    163: #ifdef NROFF
                    164:                        set_tty();
                    165:                        {
                    166:                                char    *p = t.twinit;
                    167:                                while (*p++)
                    168:                                        ;
                    169:                                if (p - t.twinit > 1)
                    170:                                        write(ptid, t.twinit, p - t.twinit - 1);
                    171:                        }
                    172: #endif
                    173:                }
                    174:                toolate += write(ptid, obuf, (int)(obufp - obuf));
                    175:        }
                    176:        obufp = obuf;
                    177: }
                    178: 
                    179: 
                    180: done(x) 
                    181: int    x;
                    182: {
                    183:        register i;
                    184: 
                    185:        error |= x;
                    186:        app = ds = lgf = 0;
                    187:        if (i = em) {
                    188:                donef = -1;
                    189:                em = 0;
                    190:                if (control(i, 0))
                    191:                        longjmp(sjbuf, 1);
                    192:        }
                    193:        if (!nfo)
                    194:                done3(0);
                    195:        mflg = 0;
                    196:        dip = &d[0];
                    197:        if (woff)
                    198:                wbt((tchar)0);
                    199:        if (pendw)
                    200:                getword(1);
                    201:        pendnf = 0;
                    202:        if (donef == 1)
                    203:                done1(0);
                    204:        donef = 1;
                    205:        ip = 0;
                    206:        frame = stk;
                    207:        nxf = frame + 1;
                    208:        if (!ejf)
                    209:                tbreak();
                    210:        nflush++;
                    211:        eject((struct s *)0);
                    212:        longjmp(sjbuf, 1);
                    213: }
                    214: 
                    215: 
                    216: done1(x) 
                    217: int    x; 
                    218: {
                    219:        error |= x;
                    220:        if (numtab[NL].val) {
                    221:                trap = 0;
                    222:                eject((struct s *)0);
                    223:                longjmp(sjbuf, 1);
                    224:        }
                    225:        if (nofeed) {
                    226:                ptlead();
                    227:                flusho();
                    228:                done3(0);
                    229:        } else {
                    230:                if (!gflag)
                    231:                        pttrailer();
                    232:                done2(0);
                    233:        }
                    234: }
                    235: 
                    236: 
                    237: done2(x) 
                    238: int    x; 
                    239: {
                    240:        ptlead();
                    241: #ifndef NROFF
                    242:        if (!ascii)
                    243:                ptstop();
                    244: #endif
                    245:        flusho();
                    246:        done3(x);
                    247: }
                    248: 
                    249: done3(x) 
                    250: int    x;
                    251: {
                    252:        error |= x;
                    253:        signal(SIGINT, SIG_IGN);
                    254:        signal(SIGTERM, SIG_IGN);
                    255:        unlink(unlkp);
                    256: #ifdef NROFF
                    257:        twdone();
                    258: #endif
                    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:                errprint("Pipe not created.");
                    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:        errprint("Cannot exec %s", 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.