Annotation of researchv10no/cmd/troff/ancient.nroff/n9.c, revision 1.1

1.1     ! root        1: #include "tdef.hd"
        !             2: #include "strs.hd"
        !             3: #ifdef NROFF
        !             4: #include "tw.hd"
        !             5: extern struct ttable t;
        !             6: #endif
        !             7: /*
        !             8: troff9.c
        !             9: 
        !            10: misc functions
        !            11: */
        !            12: 
        !            13: #ifndef INCORE
        !            14: extern struct envblock eblock;
        !            15: #else
        !            16: extern struct envblock eblock[NEV];
        !            17: extern int ev;
        !            18: #endif
        !            19: extern struct datablock dblock;
        !            20: 
        !            21: extern int rptbuf[];
        !            22: extern int *cstk[], cstkl;
        !            23: extern int ch_CMASK;
        !            24: extern long atoi0();
        !            25: extern int cbuf[];
        !            26: extern int ch;
        !            27: extern int dfact;
        !            28: extern int vflag;
        !            29: extern int fc;
        !            30: extern int padc;
        !            31: extern int nlflg;
        !            32: extern int tabch, ldrch;
        !            33: setline(){
        !            34:        register *i, length, c;
        !            35:        int w, cnt, delim, rem, temp;
        !            36: 
        !            37:        if((delim = getch()) & MOT)return;
        !            38:                else delim &= CMASK;
        !            39:        vflag = 0;
        !            40:        dfact = EM;
        !            41:        length = quant(atoi(),HOR);
        !            42:        dfact = 1;
        !            43:        if(!length){
        !            44:                eat(delim);
        !            45:                return;
        !            46:        }
        !            47: s0:
        !            48:        if ((c = getch()) && (ch_CMASK == delim)) {
        !            49:                ch = c;
        !            50:                c = 0204 | chbits;      }
        !            51:          else if (ch_CMASK == FILLER) goto s0;
        !            52:        w = width(c);
        !            53:        i = cbuf;
        !            54:        if(length < 0){
        !            55:                *i++ = makem(length);
        !            56:                length = -length;
        !            57:        }
        !            58:        if(!(cnt = length/w)){
        !            59:                *i++ = makem(-(temp = ((w-length)/2)));
        !            60:                *i++ = c;
        !            61:                *i++ = makem(-(w - length - temp));
        !            62:                goto s1;
        !            63:        }
        !            64:        if(rem = length%w){
        !            65:                switch(c & CMASK){
        !            66:                        case 0204: /*rule*/
        !            67:                        case 0224: /*underrule*/
        !            68:                        case 0276: /*root en*/
        !            69:                                *i++ = c | ZBIT;
        !            70:                        default:
        !            71:                                *i++ = makem(rem);
        !            72:                }
        !            73:        }
        !            74:        while (cnt--) *i++ = c;
        !            75: s1:
        !            76:        *i++ = 0;
        !            77:        eat(delim);
        !            78:        setcp(cbuf);
        !            79: }
        !            80: eat(c)
        !            81: int c;
        !            82: {
        !            83:        do getch();
        !            84:            while ((ch_CMASK != c) && (ch_CMASK != '\n'));
        !            85: }
        !            86: setov(){
        !            87:        register i, j, k;
        !            88:        int *p, delim, o[NOV], w[NOV];
        !            89: 
        !            90:        if((delim = getch()) & MOT)return;
        !            91:                else delim &= CMASK;
        !            92:        for (k=0; ((k<NOV) && (i = getch()) && (ch_CMASK != delim) &&
        !            93:                (ch_CMASK != '\n')); k++){
        !            94:                        o[k] = i;
        !            95:                        w[k] = width(i);
        !            96:        }
        !            97:        o[k] = w[k] = 0;
        !            98:        if(o[0])
        !            99:            do {
        !           100:                j = 0;
        !           101:                for(k=1; o[k] ; k++)
        !           102:                        if(w[k-1] < w[k]){
        !           103:                                j++;
        !           104:                                i = w[k];
        !           105:                                w[k] = w[k-1];
        !           106:                                w[k-1] = i;
        !           107:                                i = o[k];
        !           108:                                o[k] = o[k-1];
        !           109:                                o[k-1] = i;     }}
        !           110:            while (j);
        !           111:        else return;
        !           112:        p = cbuf;
        !           113:        for(k=0; o[k]; k++){
        !           114:                *p++ = o[k];
        !           115:                *p++ = makem(-((w[k]+w[k+1])/2));
        !           116:        }
        !           117:        *p++ = makem(w[0]/2);
        !           118:        *p = 0;
        !           119:        setcp(cbuf);
        !           120: }
        !           121: setbra(){
        !           122:        register i, *j;
        !           123:        int cnt, delim, dwn;
        !           124: 
        !           125:        if((delim = getch()) & MOT)return;
        !           126:                else delim &= CMASK;
        !           127:        j = cbuf + 1;
        !           128:        cnt = 0;
        !           129: #ifdef NROFF
        !           130:        dwn = (2*t.Halfline) | MOT | VMOT;
        !           131: #endif
        !           132: #ifndef NROFF
        !           133:        dwn = EM | MOT | VMOT;
        !           134: #endif
        !           135:        while ((i = getch()) && (ch_CMASK != delim) && (ch_CMASK != '\n') &&
        !           136:                (j <= (cbuf+NC-4))){
        !           137:                *j++ = i | ZBIT;
        !           138:                *j++ = dwn;
        !           139:                cnt++;
        !           140:        }
        !           141:        if(--cnt < 0)return;
        !           142:                else if (!cnt){
        !           143:                        ch = *(j-2);
        !           144:                        return;
        !           145:        }
        !           146:        *j = 0;
        !           147: #ifdef NROFF
        !           148:        *--j = *cbuf = (cnt*t.Halfline) | MOT | NMOT | VMOT;
        !           149: #endif
        !           150: #ifndef NROFF
        !           151:        *--j = *cbuf = (cnt*EM)/2 | MOT | NMOT | VMOT;
        !           152: #endif
        !           153:        *--j &= ~ZBIT;
        !           154:        setcp(cbuf);
        !           155: }
        !           156: setvline(){
        !           157:        register i, c, *k;
        !           158:        int cnt, neg, rem, ver, delim;
        !           159: 
        !           160:        if((delim = getch()) & MOT)return;
        !           161:                else delim &= CMASK;
        !           162:        dfact = lss;
        !           163:        vflag++;
        !           164:        i = quant(atoi(),VERT);
        !           165:        dfact = 1;
        !           166:        if(!i){
        !           167:                eat(delim);
        !           168:                vflag = 0;
        !           169:                return;
        !           170:        }
        !           171:        if ((c = getch()) && (ch_CMASK == delim)) {
        !           172:                c = 0337 | chbits;      /*default box rule*/
        !           173:        }else getch();
        !           174:        c |= ZBIT;
        !           175:        neg = 0;
        !           176:        if(i < 0){
        !           177:                i = -i;
        !           178:                neg = NMOT;
        !           179:        }
        !           180: #ifdef NROFF
        !           181:        ver = 2*t.Halfline;
        !           182: #endif
        !           183: #ifndef NROFF
        !           184:        ver = EM;
        !           185: #endif
        !           186:        cnt = i/ver;
        !           187:        rem = makem(i%ver) | neg;
        !           188:        ver = makem(ver) | neg;
        !           189:        k = cbuf;
        !           190:        if(!neg)*k++ = ver;
        !           191:        if(rem & ~MOTV){
        !           192:                *k++ = c;
        !           193:                *k++ = rem;
        !           194:        }
        !           195:        while((k < (cbuf+NC-3)) && cnt--){
        !           196:                *k++ = c;
        !           197:                *k++ = ver;
        !           198:        }
        !           199:        *(k-2) &= ~ZBIT;
        !           200:        if(!neg)k--;
        !           201:        *k = 0;
        !           202:        setcp(cbuf);
        !           203:        vflag = 0;
        !           204: }
        !           205: casefc(){
        !           206: 
        !           207:        fc = IMP;
        !           208:        padc = ' ';
        !           209:        if (skip() || (getch() & MOT) || (ch_CMASK == '\n')) return;
        !           210:        fc = ch_CMASK;
        !           211:        if(skip() || (ch & MOT) || ((ch &= CMASK) == fc))return;
        !           212:        padc = ch;
        !           213: }
        !           214: setfield(x)
        !           215: int x;
        !           216: {
        !           217:        register i, j, *fp;
        !           218:        int length, ws, npad, temp, type, rchar;
        !           219:        int **pp, *padptr[NPP];
        !           220:        static int fbuf[FBUFSZ];
        !           221:        int savfc, savtc, savlc;
        !           222: 
        !           223:        if(x == tabch) rchar = tabc | chbits;
        !           224:        else if(x ==  ldrch) rchar = dotc | chbits;
        !           225:        temp = npad = ws = 0;
        !           226:        savfc = fc; savtc = tabch; savlc = ldrch;
        !           227:        tabch = ldrch = fc = IMP;
        !           228:        for(j=0;1;j++){
        !           229:                if((tabtab[j] & TMASK)== 0){
        !           230:                        if(x==savfc)prstr("Zero field width.\n");
        !           231:                        j = 0;
        !           232:                        goto rtn;
        !           233:                }
        !           234:                if((length = ((tabtab[j] & TMASK) - v_hp)) > 0 )break;
        !           235:        }
        !           236:        type = tabtab[j] & (~TMASK);
        !           237:        fp = fbuf;
        !           238:        pp = padptr;
        !           239:       if(x == savfc){while(1){
        !           240:                if ((i = getch()) && (ch_CMASK == padc)) {
        !           241:                        npad++;
        !           242:                        *pp++ = fp;
        !           243:                        if(pp > (padptr + NPP - 1))break;
        !           244:                        goto s1;
        !           245:                }else if(ch_CMASK == savfc) break;
        !           246:                        else if(ch_CMASK == '\n'){
        !           247:                                temp = ch_CMASK;
        !           248:                                nlflg = 0;
        !           249:                                break;
        !           250:                        }
        !           251:                ws += width(i);
        !           252:        s1:
        !           253:                *fp++ = i;
        !           254:                if(fp > (fbuf + FBUFSZ -3))break;
        !           255:        }
        !           256:        if(!npad){
        !           257:                npad++;
        !           258:                *pp++ = fp;
        !           259:                *fp++ = 0;
        !           260:        }
        !           261:        *fp++ = temp;
        !           262:        *fp++ = 0;
        !           263:        temp = i = (j = length-ws)/npad;
        !           264:        i = (i/HOR)*HOR;
        !           265:        if((j -= i*npad) <0)j = -j;
        !           266:        i = makem(i);
        !           267:        if(temp <0)i |= NMOT;
        !           268:        for(;npad > 0; npad--){
        !           269:                *(*--pp) = i;
        !           270:                if(j){
        !           271:                        j -= HOR;
        !           272:                        (*(*pp)) += HOR;
        !           273:                }
        !           274:        }
        !           275:        setcp(fbuf);
        !           276:        j = 0;
        !           277:       }else if(type == 0){
        !           278:        /*plain tab or leader*/
        !           279:                if((j = width(rchar)) != 0)     {
        !           280:                        fp = rptbuf;
        !           281:                        i = ((length/j) > (RPTLEN-1)) ?
        !           282:                                RPTLEN - 1 : length / j;
        !           283:                        for (;i;i--)
        !           284:                                *fp++ = rchar;
        !           285:                        *fp = 0;
        !           286:                        setrp(rptbuf);  /* setup repeat string */
        !           287:                        length %= j;    }
        !           288:                if(length)j = length | MOT;
        !           289:                else j = getch0();
        !           290:       }else{
        !           291:        /*center tab*/
        !           292:        /*right tab*/
        !           293:                while ((i = getch()) && (ch_CMASK != savtc) &&
        !           294:                    (ch_CMASK != '\n') && (ch_CMASK != savlc)) {
        !           295:                        ws += width(i);
        !           296:                        *fp++ = i;
        !           297:                        if(fp > (fbuf +FBUFSZ - 3)) break;
        !           298:                }
        !           299:                *fp++ = i;
        !           300:                *fp++ = 0;
        !           301:                if(type == RTAB)length -= ws;
        !           302:                else length -= ws/2; /*CTAB*/
        !           303:                if(((j = width(rchar)) != 0) && (length > 0))   {
        !           304:                        fp = rptbuf;
        !           305:                        i = ((length/j) > (RPTLEN-1)) ?
        !           306:                                RPTLEN - 1 : length / j;
        !           307:                        for (;i;i--)
        !           308:                                *fp++ = rchar;
        !           309:                        *fp = 0;
        !           310:                        setrp(rptbuf);  /* setup repeat string */
        !           311:                        length %= j;    }
        !           312:                length = (length/HOR)*HOR;
        !           313:                j = makem(length);
        !           314:                setcp(fbuf);
        !           315:                nlflg = 0;
        !           316:        }
        !           317: rtn:
        !           318:        fc = savfc; tabch = savtc; ldrch = savlc;
        !           319:        return(j);
        !           320: }

unix.superglobalmegacorp.com

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