Annotation of 43BSDReno/usr.bin/roff/nroff/n10.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char sccsid[] = "@(#)n10.c      4.5 5/11/89";
                      3: #endif lint
                      4: 
                      5: #include "tdef.h"
                      6: #include <sgtty.h>
                      7: extern
                      8: #include "d.h"
                      9: extern
                     10: #include "v.h"
                     11: extern
                     12: #include "tw.h"
                     13: #include "pathnames.h"
                     14: /*
                     15: nroff10.c
                     16: 
                     17: Device interfaces
                     18: */
                     19: 
                     20: extern int lss;
                     21: extern char obuf[];
                     22: extern char *obufp;
                     23: extern int xfont;
                     24: extern int esc;
                     25: extern int lead;
                     26: extern int oline[];
                     27: extern int *olinep;
                     28: extern int ulfont;
                     29: extern int esct;
                     30: extern int sps;
                     31: extern int ics;
                     32: extern int ttysave;
                     33: extern struct sgttyb ttys;
                     34: extern char termtab[];
                     35: extern int ptid;
                     36: extern int waitf;
                     37: extern int pipeflg;
                     38: extern int eqflg;
                     39: extern int hflg;
                     40: extern int tabtab[];
                     41: extern int ascii;
                     42: extern int xxx;
                     43: int dtab;
                     44: int bdmode;
                     45: int plotmode;
                     46: 
                     47: ptinit(){
                     48:        register i, j;
                     49:        register char **p;
                     50:        char *q;
                     51:        int x[8];
                     52:        extern char *setbrk();
                     53: 
                     54:        if(((i=open(termtab,0)) < 0) && (i=open(_PATH_TERM,0)) < 0){
                     55:                prstr("Cannot open ");
                     56:                prstr(termtab);
                     57:                prstr("\n");
                     58:                exit(-1);
                     59:        }
                     60:        read(i,(char *)x,8*sizeof(int));
                     61:        /* Calc size of table, not counting zzz */
                     62:        j = ((int) &t.zzz - (int) &t.bset);
                     63:        read(i, (char *)&t.bset, j);
                     64:        x[2] -= j;
                     65:        q = setbrk(x[2]);
                     66:        lseek(i,(long)t.twinit+8*sizeof(int),0);
                     67:        i = read(i,q,x[2]);
                     68:        j = q - t.twinit;
                     69:        for(p = &t.twinit; p < &t.zzz; p++){
                     70:                if(*p)*p += j;else *p = "";
                     71:        }
                     72:        sps = EM;
                     73:        ics = EM*2;
                     74:        dtab = 8 * t.Em;
                     75:        for(i=0; i<16; i++)tabtab[i] = dtab * (i+1);
                     76:        if(eqflg)t.Adj = t.Hor;
                     77: }
                     78: twdone(){
                     79:        obufp = obuf;
                     80:        oputs(t.twrest);
                     81:        flusho();
                     82:        if(pipeflg){
                     83:                close(ptid);
                     84:                wait(&waitf);
                     85:        }
                     86:        if(ttysave != -1) {
                     87:                ttys.sg_flags = ttysave;
                     88:                stty(1, &ttys);
                     89:        }
                     90: }
                     91: ptout(i)
                     92: int i;
                     93: {
                     94:        *olinep++ = i;
                     95:        if(olinep >= &oline[LNSIZE])olinep--;
                     96:        if((i&CMASK) != '\n')return;
                     97:        olinep--;
                     98:        lead += dip->blss + lss - t.Newline;
                     99:        dip->blss = 0;
                    100:        esct = esc = 0;
                    101:        if(olinep>oline){
                    102:                move();
                    103:                ptout1();
                    104:                oputs(t.twnl);
                    105:        }else{
                    106:                lead += t.Newline;
                    107:                move();
                    108:        }
                    109:        lead += dip->alss;
                    110:        dip->alss = 0;
                    111:        olinep = oline;
                    112: }
                    113: ptout1()
                    114: {
                    115:        register i, k;
                    116:        register char *codep;
                    117:        extern char *plot();
                    118:        int *q, w, j, phyw;
                    119: 
                    120:        for(q=oline; q<olinep; q++){
                    121:        if((i = *q) & MOT){
                    122:                j = i & ~MOTV;
                    123:                if(i & NMOT)j = -j;
                    124:                if(i & VMOT)lead += j;
                    125:                else esc += j;
                    126:                continue;
                    127:        }
                    128:        if((k = (i & CMASK)) <= 040){
                    129:                switch(k){
                    130:                        case ' ': /*space*/
                    131:                                esc += t.Char;
                    132:                                break;
                    133:                }
                    134:                continue;
                    135:        }
                    136:        codep = t.codetab[k-32];
                    137:        w = t.Char * (*codep++ & 0177);
                    138:        phyw = w;
                    139:        if(i&ZBIT)w = 0;
                    140:        if(*codep && (esc || lead))move();
                    141:        esct += w;
                    142:        if(i&074000)xfont = (i>>9) & 03;
                    143:        if(*t.bdon & 0377){
                    144:                if(!bdmode && (xfont == 2)){
                    145:                        oputs(t.bdon);
                    146:                        bdmode++;
                    147:                }
                    148:                if(bdmode && (xfont != 2)){
                    149:                        oputs(t.bdoff);
                    150:                        bdmode = 0;
                    151:                }
                    152:        }
                    153: 
                    154:        if(xfont == ulfont){
                    155:                for(k=w/t.Char;k>0;k--)oput('_');
                    156:                for(k=w/t.Char;k>0;k--)oput('\b');
                    157:        }
                    158:        while(*codep != 0){
                    159:                if(*codep & 0200){
                    160:                        codep = plot(codep);
                    161:                        oputs(t.plotoff);
                    162:                        oput(' ');
                    163:                }else{
                    164:                        if(plotmode)oputs(t.plotoff);
                    165:                        /*
                    166:                         * simulate bold font as overstrike if no t.bdon
                    167:                         */
                    168:                        if (xfont == 2 && !(*t.bdon & 0377)) {
                    169:                                oput(*codep);
                    170:                                oput('\b');
                    171:                        }
                    172:                        *obufp++ = *codep++;
                    173:                        if(obufp == (obuf + OBUFSZ + ascii - 1))flusho();
                    174: /*                     oput(*codep++);*/
                    175:                }
                    176:        }
                    177:        if(!w)for(k=phyw/t.Char;k>0;k--)oput('\b');
                    178:        }
                    179: }
                    180: char *plot(x)
                    181: char *x;
                    182: {
                    183:        register int i;
                    184:        register char *j, *k;
                    185: 
                    186:        if(!plotmode)oputs(t.ploton);
                    187:        k = x;
                    188:        if((*k & 0377) == 0200)k++;
                    189:        for(; *k; k++){
                    190:                if(*k & 0200){
                    191:                        if(*k & 0100){
                    192:                                if(*k & 040)j = t.up; else j = t.down;
                    193:                        }else{
                    194:                                if(*k & 040)j = t.left; else j = t.right;
                    195:                        }
                    196:                        if(!(i = *k & 037))return(++k);
                    197:                        while(i--)oputs(j);
                    198:                }else oput(*k);
                    199:        }
                    200:        return(k);
                    201: }
                    202: move(){
                    203:        register k;
                    204:        register char *i, *j;
                    205:        char *p, *q;
                    206:        int iesct, dt;
                    207: 
                    208:        iesct = esct;
                    209:        if(esct += esc)i = "\0"; else i = "\n\0";
                    210:        j = t.hlf;
                    211:        p = t.right;
                    212:        q = t.down;
                    213:        if(lead){
                    214:                if(lead < 0){
                    215:                        lead = -lead;
                    216:                        i = t.flr;
                    217:                /*      if(!esct)i = t.flr; else i = "\0";*/
                    218:                        j = t.hlr;
                    219:                        q = t.up;
                    220:                }
                    221:                if(*i & 0377){
                    222:                        k = lead/t.Newline;
                    223:                        lead = lead%t.Newline;
                    224:                        while(k--)oputs(i);
                    225:                }
                    226:                if(*j & 0377){
                    227:                        k = lead/t.Halfline;
                    228:                        lead = lead%t.Halfline;
                    229:                        while(k--)oputs(j);
                    230:                }
                    231:                else { /* no half-line forward, not at line begining */
                    232:                        k = lead/t.Newline;
                    233:                        lead = lead%t.Newline;
                    234:                        if (k>0) esc=esct;
                    235:                        i = "\n";
                    236:                        while (k--) oputs(i);
                    237:                }
                    238:        }
                    239:        if(esc){
                    240:                if(esc < 0){
                    241:                        esc = -esc;
                    242:                        j = "\b";
                    243:                        p = t.left;
                    244:                }else{
                    245:                        j = " ";
                    246:                        if(hflg)while((dt = dtab - (iesct%dtab)) <= esc){
                    247:                                if(dt%t.Em || dt==t.Em)break;
                    248:                                oput(TAB);
                    249:                                esc -= dt;
                    250:                                iesct += dt;
                    251:                        }
                    252:                }
                    253:                k = esc/t.Em;
                    254:                esc = esc%t.Em;
                    255:                while(k--)oputs(j);
                    256:        }
                    257:        if((*t.ploton & 0377) && (esc || lead)){
                    258:                if(!plotmode)oputs(t.ploton);
                    259:                esc /= t.Hor;
                    260:                lead /= t.Vert;
                    261:                while(esc--)oputs(p);
                    262:                while(lead--)oputs(q);
                    263:                oputs(t.plotoff);
                    264:        }
                    265:        esc = lead = 0;
                    266: }
                    267: ptlead(){move();}
                    268: dostop(){
                    269:        char junk;
                    270: 
                    271:        flusho();
                    272:        read(2,&junk,1);
                    273: }

unix.superglobalmegacorp.com

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