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

1.1     ! root        1: #include "tdef.hd"
        !             2: #include "strs.hd"
        !             3: 
        !             4: /*
        !             5: troff6.c
        !             6: 
        !             7: width functions, sizes and fonts
        !             8: */
        !             9: 
        !            10: #ifndef INCORE
        !            11: extern struct envblock eblock;
        !            12: #else
        !            13: extern struct envblock eblock[NEV];
        !            14: extern int ev;
        !            15: #endif
        !            16: extern struct datablock dblock;
        !            17: 
        !            18: #ifdef ebcdic
        !            19: extern char *fname();
        !            20: #endif
        !            21: extern int *cstk[], cstkl;
        !            22: extern int tch[];
        !            23: extern int ch_CMASK;
        !            24: extern long atoi0();
        !            25: extern int eschar;
        !            26: extern int widthp;
        !            27: extern int xpts;
        !            28: extern int xfont;
        !            29: extern int code;
        !            30: extern int smnt;
        !            31: extern int setwdf;
        !            32: extern int cs;
        !            33: extern int ccs;
        !            34: extern int xbitf;
        !            35: extern int mfont;
        !            36: extern int mpts;
        !            37: extern int pfont;
        !            38: extern int ppts;
        !            39: extern int oldbits;
        !            40: extern int nonumb;
        !            41: extern int noscale;
        !            42: extern int nlflg;
        !            43: extern int nform;
        !            44: extern int dfact;
        !            45: extern int vflag;
        !            46: extern int lg;
        !            47: extern char fontfile[];
        !            48: extern int ffi;
        !            49: extern int bd;
        !            50: extern int level;
        !            51: extern int ch;
        !            52: extern int res;
        !            53: extern filedes ptid;
        !            54: extern char ftR[],ftI[],ftB[],ftS[];
        !            55: int trflg;
        !            56: char *fontab[] = {ftR, ftI, ftB, ftS};
        !            57: int fontlab[] = {'R','I','B','S',0};
        !            58: char pstab[] = {6,7,8,9,10,11,12,14,16,18,20,22,24,28,36,0};
        !            59: char psctab[] = {010,000,001,007,002,003,004,005,0211,006,
        !            60:                0212,0213,0214,0215,0216,0};
        !            61: int cstab[4], ccstab[4];
        !            62: int bdtab[4];
        !            63: int sbold = 0;
        !            64: int spsz = 0;
        !            65: struct fz {
        !            66:        char sign;
        !            67:        char size;
        !            68:        int fzinc;
        !            69:        } fz[4];
        !            70: width(c)
        !            71: int c;
        !            72: {
        !            73:        register i,j,k;
        !            74: 
        !            75:        j = c;
        !            76:        k = 0;
        !            77:        if(j & MOT){
        !            78:                if(j & VMOT)goto rtn;
        !            79:                k = j & ~MOTV;
        !            80:                if(j & NMOT)k = -k;
        !            81:                goto rtn;
        !            82:        }
        !            83:        if((i = (j & CMASK)) == 010){
        !            84:                k = -widthp;
        !            85:                goto rtn;
        !            86:        }
        !            87:        if(i == PRESC)i = eschar;
        !            88:        if((i == ohc) ||
        !            89:           (i >= 0370))goto rtn;
        !            90:        if((j>>BYTE) == oldbits){
        !            91:                xfont = pfont;
        !            92:                xpts = ppts;
        !            93:        }else xbits(j);
        !            94:        if(j & ZBIT)goto rtn;
        !            95:        if(!trflg)i = trtab[i] & BMASK;
        !            96:        if((i -= 32) < 0)goto rtn;
        !            97:        k = getcw(i);
        !            98:        if(bd)k += bd - 1;
        !            99:        if(cs)k = cs;
        !           100:        widthp = k;
        !           101: rtn:
        !           102:        xbitf = trflg = 0;
        !           103:        return(k);
        !           104: }
        !           105: getcw(i)
        !           106: int i;
        !           107: {
        !           108:        register j,k;
        !           109:        register char *p;
        !           110:        int x;
        !           111:        extern char codetab[];
        !           112: 
        !           113:        bd = 0;
        !           114:        if((code = codetab[i])  & 0200){
        !           115:                if(smnt){
        !           116:                        p = fontab[smnt-1];
        !           117:                        if(xfont == (sbold-1))bd = bdtab[smnt-1];
        !           118:                        goto g0;
        !           119:                }
        !           120:                code = 0;
        !           121:                k = 36;
        !           122:                goto g1;
        !           123:        }
        !           124:        p = fontab[xfont];
        !           125: g0:
        !           126:        if(!i)k = spacesz;
        !           127:        else k = *(p + i) & BMASK;
        !           128:        if(setwdf)v_ct |= ((k>>6) & 3);
        !           129: g1:
        !           130:        k = (j = (k&077)*(xpts&077))/6;
        !           131:        if((j%6) >= 3)k++;
        !           132:        if(cs = cstab[xfont]){
        !           133:                if(ccs = ccstab[xfont])x = ccs; else x = xpts;
        !           134:                cs = (j = (cs&077)*(x&077))/6;
        !           135:                if((j%6) >= 3)cs++;
        !           136:        }
        !           137:        if(!bd)bd = bdtab[xfont];
        !           138:        return(k);
        !           139: }
        !           140: xbits(i)
        !           141: int i;
        !           142: {
        !           143:        register j, k;
        !           144: 
        !           145:        j = i >> BYTE;
        !           146:        xfont = (j>>1) & 03;
        !           147:        if(k = (j>>3) & 017){
        !           148:                xpts = pstab[--k];
        !           149:                if(psctab[k] < 0)xpts |= DBL;
        !           150:                oldbits = j;
        !           151:                pfont = xfont;
        !           152:                ppts = xpts;
        !           153:                goto rtn;
        !           154:        }
        !           155:        switch(xbitf){
        !           156:                case 0:
        !           157:                        xfont = font;
        !           158:                        xpts = pts;
        !           159:                        break;
        !           160:                case 1:
        !           161:                        xfont = pfont;
        !           162:                        xpts = ppts;
        !           163:                        break;
        !           164:                case 2:
        !           165:                        xfont = mfont;
        !           166:                        xpts = mpts;
        !           167:        }
        !           168: rtn:
        !           169:        xbitf = 0;
        !           170: }
        !           171: setch(){
        !           172:        register i,*j,k;
        !           173:        extern int chtab[];
        !           174: 
        !           175:        if((i = getrq()) == 0)return(0);
        !           176:        for(j=chtab;*j != i;j++)if(*(j++) == 0)return(0);
        !           177:        k = *(++j) | chbits;
        !           178:        return(k);
        !           179: }
        !           180: find(i,j)
        !           181: int i,j[];
        !           182: {
        !           183:        register k;
        !           184: 
        !           185:        if(((k = i-'0') >= 1) && (k <= 4) && (k != smnt))return(--k);
        !           186:        for(k=0; j[k] != i; k++)if(j[k] == 0)return(-1);
        !           187:        return(k);
        !           188: }
        !           189: caseps(){
        !           190:        register i;
        !           191: 
        !           192:        if(skip())i = apts1;
        !           193:        else{
        !           194:                noscale++;
        !           195:                i = inumb(&apts);
        !           196:                noscale = 0;
        !           197:                if(nonumb)return;
        !           198:        }
        !           199:        casps1(i);
        !           200: }
        !           201: casps1(i)
        !           202: int i;
        !           203: {
        !           204:        if(i <= 0)return;
        !           205:        if(fz[font].size){
        !           206:                i = getfz(font, i);
        !           207:        }
        !           208:        apts1 = apts;
        !           209:        apts = i;
        !           210:        pts1 = pts;
        !           211:        pts = findps(i & 077);
        !           212:        mchbits();
        !           213: }
        !           214: findps(i)
        !           215: int i;
        !           216: {
        !           217:        register j, k;
        !           218: 
        !           219:        for(j=0; i > (k = pstab[j]);j++)if(!k){k=pstab[--j];break;}
        !           220:        if(psctab[j] < 0)k |= DBL;
        !           221:        return(k);
        !           222: }
        !           223: mchbits(){
        !           224:        register i, j, k;
        !           225: 
        !           226:        spbits = 0;
        !           227:        i = pts & 077;
        !           228:        for(j=0; i > (k = pstab[j]);j++)if(!k){k=pstab[--j];break;}
        !           229:        chbits = (((++j)<<2) | font) << (BYTE + 1);
        !           230:        sps = width(' ' | chbits);
        !           231:        if(font == (spsz-1)){
        !           232:                i = findps(getfz(smnt-1, apts + fz[font].fzinc));
        !           233:                for(j=0; i > (k = pstab[j]);j++)if(!k){k=pstab[--j];break;}
        !           234:                spbits = (((++j)<<2) | font) << (BYTE + 1);
        !           235:        }
        !           236: }
        !           237: getfz(x,y)
        !           238: int x, y;
        !           239: {
        !           240:        register i, j;
        !           241: 
        !           242:        i = fz[x].size;
        !           243:        j = fz[x].sign;
        !           244:        if(i || j){
        !           245:                if(j == '+')i += y;
        !           246:                else if(j == '-')i = y - i;
        !           247:        }
        !           248:        fz[x].fzinc = y - i;
        !           249:        return(i);
        !           250: }
        !           251: setps(){
        !           252:        register i,j;
        !           253: 
        !           254:        if((((i=getch() & CMASK) == '+')  || (i == '-')) &&
        !           255:          (((j=(ch = getch() & CMASK) - '0') >= 0) && (j <= 9))){
        !           256:                if(i == '-')j = -j;
        !           257:                ch = 0;
        !           258:                casps1(apts+j);
        !           259:                return;
        !           260:        }
        !           261:        if((i -= '0') == 0){
        !           262:                casps1(apts1);
        !           263:                return;
        !           264:        }
        !           265:        if((i > 0) && (i <= 9)){
        !           266:                if((i <= 3) &&
        !           267:                  ((j=(ch = getch() & CMASK) - '0') >= 0) && (j <= 9)){
        !           268:                        i = 10*i +j;
        !           269:                        ch = 0;
        !           270:                }
        !           271:                casps1(i);
        !           272:        }
        !           273: }
        !           274: caseft(){
        !           275:        skip();
        !           276:        setfont(1);
        !           277: }
        !           278: setfont(a)
        !           279: int a;
        !           280: {
        !           281:        register i,j;
        !           282: 
        !           283:        if(a)i = getrq();
        !           284:                else i = getsn();
        !           285:        if(!i || (i == 'P'))
        !           286:                j = font1;
        !           287:            else if ((i == 'S') || ((j = find(i,fontlab)) == -1)) return;
        !           288:        font1 = font;
        !           289:        font = j;
        !           290:        i = 0;
        !           291:        if(fz[font1].size){
        !           292:                i++;
        !           293:                casps1(apts + fz[font1].fzinc);
        !           294:        }else if(fz[font].size){
        !           295:                i++;
        !           296:                casps1(apts);
        !           297:        }
        !           298:        if(!i)mchbits();
        !           299: }
        !           300: setwd(){
        !           301:        register i, base, wid;
        !           302:        int delim, em, k;
        !           303:        int savlevel, savhp, savapts, savapts1, savfont, savfont1,
        !           304:                savpts, savpts1;
        !           305: 
        !           306:        base = v_st = v_sb = wid = v_ct = 0;
        !           307:        if((delim = getch() & CMASK) & MOT)return;
        !           308:        savhp = v_hp;
        !           309:        savlevel = level;
        !           310:        v_hp = level = 0;
        !           311:        savapts = apts;
        !           312:        savapts1 = apts1;
        !           313:        savfont = font;
        !           314:        savfont1 = font1;
        !           315:        savpts = pts;
        !           316:        savpts1 = pts1;
        !           317:        setwdf++;
        !           318:        while ((i = getch()) && (ch_CMASK != delim) && !nlflg) {
        !           319:                wid += width(i);
        !           320:                if(!(i & MOT)){
        !           321:                        em = (xpts & 077)*6;
        !           322:                }else if(i & VMOT){
        !           323:                        k = i & ~MOTV;
        !           324:                        if(i & NMOT)k = -k;
        !           325:                        base -= k;
        !           326:                        em = 0;
        !           327:                }else continue;
        !           328:                if(base < v_sb)v_sb = base;
        !           329:                if((k=base + em) > v_st)v_st = k;
        !           330:        }
        !           331:        nform = 0;
        !           332:        setn1(wid);
        !           333:        v_hp = savhp;
        !           334:        level = savlevel;
        !           335:        apts = savapts;
        !           336:        apts1 = savapts1;
        !           337:        font = savfont;
        !           338:        font1 = savfont1;
        !           339:        pts = savpts;
        !           340:        pts1 = savpts1;
        !           341:        mchbits();
        !           342:        setwdf = 0;
        !           343: }
        !           344: mot(){
        !           345:        register i, j;
        !           346: 
        !           347:        j = HOR;
        !           348:        getch(); /*eat delim*/
        !           349:        if(i = atoi()){
        !           350:                if(vflag)j = VERT;
        !           351:                i = makem(quant(i,j));
        !           352:        }
        !           353:        getch();
        !           354:        vflag = 0;
        !           355:        dfact = 1;
        !           356:        return(i);
        !           357: }
        !           358: sethl(k)
        !           359: int k;
        !           360: {
        !           361:        register i;
        !           362: 
        !           363:        i = 3 * (pts & 077);
        !           364:        if(k == 'u')i = -i;
        !           365:        else if(k == 'r')i = -2*i;
        !           366:        vflag++;
        !           367:        i = makem(i);
        !           368:        vflag = 0;
        !           369:        return(i);
        !           370: }
        !           371: makem(i)
        !           372: int i;
        !           373: {
        !           374:        register j;
        !           375: 
        !           376:        if((j = i) < 0)j = -j;
        !           377:        j = (j & ~MOTV) | MOT;
        !           378:        if(i < 0)j |= NMOT;
        !           379:        if(vflag)j |= VMOT;
        !           380:        return(j);
        !           381: }
        !           382: getlg(i)
        !           383: int i;
        !           384: {
        !           385:        register j, k;
        !           386: 
        !           387:        switch((j = getch0()) & CMASK){
        !           388:                case 'f':
        !           389:                        if(lg!=2){switch((k =getch0()) & CMASK){
        !           390:                                        case 'i':
        !           391:                                                j = 0214;
        !           392:                                                break;
        !           393:                                        case 'l':
        !           394:                                                j = 0215;
        !           395:                                                break;
        !           396:                                        default:
        !           397:                                                setch0(k);
        !           398:                                                j = 0213;
        !           399:                                }
        !           400:                        }else j = 0213;
        !           401:                        break;
        !           402:                case 'l':
        !           403:                        j = 0212;
        !           404:                        break;
        !           405:                case 'i':
        !           406:                        j = 0211;
        !           407:                        break;
        !           408:                default:
        !           409:                        setch0(j);
        !           410:                        j = i;
        !           411:        }
        !           412:        return((i & ~CMASK) | j);
        !           413: }
        !           414: caselg(){
        !           415: 
        !           416:        lg = 1;
        !           417:        if(skip())return;
        !           418:        lg = atoi();
        !           419: }
        !           420: casefp(){
        !           421:        register i, j;
        !           422:        int chr;
        !           423: 
        !           424:        skip();
        !           425:        if(((i = (getch() & CMASK) - '0' -1) < 0) || (i >3)) {
        !           426:                prstr("fp: bad font position\n");
        !           427:                return; }
        !           428:        if(skip() || !(j = getrq())){prstr("fp: no font name\n"); return;}
        !           429:        fontfile[ffi] = j & BMASK;
        !           430:        fontfile[ffi+1] = j>>BYTE;
        !           431: #ifdef tso
        !           432:        if (fontfile[ffi+1])    {
        !           433:                fontfile[ffi+2] = '.';  /* fudge file name (to ftxx.f) */
        !           434:                fontfile[ffi+3] = 'f';  }
        !           435:            else        {
        !           436:                fontfile[ffi+1] = '.';
        !           437:                fontfile[ffi+2] = 'f';  }
        !           438: #endif
        !           439:        getfont(i,0);           /* read in font table */
        !           440:        if(i == (smnt-1)){smnt = 0; sbold = 0; spsz = 0;}
        !           441:        if((fontlab[i] = j) == 'S')smnt = i + 1;
        !           442:        bdtab[i] = cstab[i] = ccstab[i] = 0;
        !           443:        fz[i].fzinc = fz[i].sign = fz[i].size = 0;
        !           444: #ifndef tso
        !           445:        if(ptid != 1){
        !           446: #endif
        !           447:                prstr("Mount font ");
        !           448:                aprstr(&fontfile[ffi]);
        !           449:                prstr(" on ");
        !           450:                chr = PAIR((i + '1'),0);
        !           451:                aprstr(&chr);
        !           452:                prstr("\n");
        !           453: #ifndef tso
        !           454:        }
        !           455: #endif
        !           456: }
        !           457: getfont(pos,new)
        !           458: int pos,new;
        !           459: {
        !           460:        register filedes k;
        !           461: 
        !           462: #ifdef unix
        !           463:        if((k = open(fontfile,0)) < 0){
        !           464: #endif
        !           465: #ifdef tso
        !           466:        if ((k = fopen(fname(fontfile),"r,BINARY"))==NULL) {
        !           467: #endif
        !           468:                if (!new) prstr("Non-existent font type");
        !           469:                    else  prstr("Unknown output device");
        !           470:        c0:
        !           471:                prstr("\n");
        !           472:                done(-1);
        !           473:        }
        !           474: #ifdef unix
        !           475:        if(read(k,fontab[pos],256-32) != 256-32){
        !           476: #endif
        !           477: #ifdef tso
        !           478:        if (fread((char *)fontab[pos],1,256-32,k) != 256-32) {
        !           479: #endif
        !           480:                prstr("Cannot read font file");
        !           481:                goto c0;
        !           482:        }
        !           483: #ifdef unix
        !           484:        close(k);
        !           485: #endif
        !           486: #ifdef tso
        !           487:        fclose(k);
        !           488: #endif
        !           489: }
        !           490: casecs(){
        !           491:        register i, j;
        !           492: 
        !           493:        noscale++;
        !           494:        skip();
        !           495:        if(!(i=getrq()) ||
        !           496:          ((i = find(i,fontlab)) < 0))goto rtn;
        !           497:        skip();
        !           498:        cstab[i] = atoi();
        !           499:        skip();
        !           500:        j = atoi();
        !           501:        if(!nonumb)ccstab[i] = findps(j);
        !           502: rtn:
        !           503:        noscale = 0;
        !           504: }
        !           505: casebd(){
        !           506:        register i, j, k;
        !           507: 
        !           508:        k = 0;
        !           509: bd0:
        !           510:        if(skip() || !(i = getrq()) ||
        !           511:          ((j = find(i,fontlab))  == -1)){
        !           512:                if(k)goto bd1;
        !           513:                else return;
        !           514:        }
        !           515:        if(j == (smnt-1)){
        !           516:                k = smnt;
        !           517:                goto bd0;
        !           518:        }
        !           519:        if(k){
        !           520:                sbold = j + 1;
        !           521:                j = k -1;
        !           522:        }
        !           523: bd1:
        !           524:        skip();
        !           525:        noscale++;
        !           526:        bdtab[j] = atoi();
        !           527:        noscale = 0;
        !           528: }
        !           529: casevs(){
        !           530:        register i;
        !           531: 
        !           532:        skip();
        !           533:        vflag++;
        !           534:        dfact = 6; /*default scaling is points!*/
        !           535:        res = VERT;
        !           536:        i = inumb(&lss);
        !           537:        if(nonumb)i = lss1;
        !           538:        if(i < VERT)i = VERT;
        !           539:        lss1 = lss;
        !           540:        lss = i;
        !           541: }
        !           542: casess(){
        !           543:        register i;
        !           544: 
        !           545:        noscale++;
        !           546:        skip();
        !           547:        if(i = atoi()){
        !           548:                spacesz = i& 0177;
        !           549:                sps = width(' ' | chbits);
        !           550:        }
        !           551:        noscale = 0;
        !           552: }
        !           553: xlss(){
        !           554:        register i, j;
        !           555: 
        !           556:        getch();
        !           557:        dfact = lss;
        !           558:        i = quant(atoi(),VERT);
        !           559:        dfact = 1;
        !           560:        getch();
        !           561:        if((j = i) < 0)j = -j;
        !           562:        setch0(((j & 03700)<<3) | HX);
        !           563:        if(i < 0) setch0(tch[0] | 040000);
        !           564:        return(((j & 077)<<9) | LX);
        !           565: }
        !           566: 
        !           567: casepi()       {}

unix.superglobalmegacorp.com

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