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

unix.superglobalmegacorp.com

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