Annotation of researchv10no/cmd/troff/Old/t10.c, revision 1.1

1.1     ! root        1: #include "tdef.h"
        !             2: extern
        !             3: #include "d.h"
        !             4: extern
        !             5: #include "v.h"
        !             6: /*
        !             7: troff10.c
        !             8: 
        !             9: CAT interface
        !            10: */
        !            11: 
        !            12: #include <sgtty.h>
        !            13: #include "ext.h"
        !            14: int    vpos     = 0;   /* absolute vertical position on page */
        !            15: int    hpos     = 0;   /* ditto horizontal */
        !            16: 
        !            17: #define        T_IESC  16
        !            18: 
        !            19: short  *chtab;
        !            20: char   *chname;
        !            21: char   *fontab[NFONT+1];
        !            22: char   *kerntab[NFONT+1];
        !            23: char   *fitab[NFONT+1];
        !            24: 
        !            25: int    Inch;
        !            26: int    Hor;
        !            27: int    Vert;
        !            28: int    Unitwidth;
        !            29: int    nfonts;
        !            30: int    nsizes;
        !            31: int    nchtab;
        !            32: 
        !            33: /* these characters are used as various signals or values
        !            34: /* in miscellaneous places.
        !            35: /* values are set in specnames in t10.c
        !            36: */
        !            37: 
        !            38: int    c_hyphen;
        !            39: int    c_emdash;
        !            40: int    c_rule;
        !            41: int    c_minus;
        !            42: int    c_narsp;
        !            43: int    c_hnarsp;
        !            44: int    c_fi;
        !            45: int    c_fl;
        !            46: int    c_ff;
        !            47: int    c_ffi;
        !            48: int    c_ffl;
        !            49: int    c_acute;
        !            50: int    c_grave;
        !            51: int    c_under;
        !            52: int    c_rooten;
        !            53: int    c_boxrule;
        !            54: int    c_lefthand;
        !            55: 
        !            56: #include "dev.h"
        !            57: struct dev dev;
        !            58: struct font *fontbase[NFONT+1];
        !            59: 
        !            60: 
        !            61: ptinit()
        !            62: {
        !            63:        int     i, fin, nw;
        !            64:        char    *setbrk(), *filebase, *p;
        !            65: 
        !            66:        /* open table for device,
        !            67:        /* read in resolution, size info, font info, etc.
        !            68:        /* and set params
        !            69:        */
        !            70:        strcat(termtab, "/dev");
        !            71:        strcat(termtab, devname);
        !            72:        strcat(termtab, "/DESC.out");   /* makes "..../devXXX/DESC.out" */
        !            73:        if ((fin = open(termtab, 0)) < 0) {
        !            74:                fprintf(stderr, "troff: can't open tables for %s\n", termtab);
        !            75:                done3(1);
        !            76:        }
        !            77:        read(fin, &dev, sizeof(struct dev ));
        !            78:        Inch = dev.res;
        !            79:        Hor = dev.hor;
        !            80:        Vert = dev.vert;
        !            81:        Unitwidth = dev.unitwidth;
        !            82:        nfonts = dev.nfonts;
        !            83:        nsizes = dev.nsizes;
        !            84:        nchtab = dev.nchtab;
        !            85:        filebase = setbrk(dev.filesize + 2*EXTRAFONT);  /* enough room for whole file */
        !            86:        read(fin, filebase, dev.filesize);      /* all at once */
        !            87:        pstab = (short *) filebase;
        !            88:        chtab = pstab + nsizes + 1;
        !            89:        chname = (char *) (chtab + dev.nchtab);
        !            90:        p = chname + dev.lchname;
        !            91:        for (i = 1; i <= nfonts; i++) {
        !            92:                fontbase[i] = (struct font *) p;
        !            93:                nw = *p & BMASK;        /* 1st thing is width count */
        !            94:                fontlab[i] = PAIR(fontbase[i]->namefont[0], fontbase[i]->namefont[1]);
        !            95:                /* for now, still 2 char names */
        !            96:                if (smnt == 0 && fontbase[i]->specfont == 1)
        !            97:                        smnt = i;       /* first special font */
        !            98:                p += sizeof(struct font);       /* that's what's on the beginning */
        !            99:                fontab[i] = p;
        !           100:                kerntab[i] = p + nw;
        !           101:                fitab[i] = p + 3 * nw;  /* skip width, kern, code */
        !           102:                p += 3 * nw + dev.nchtab + 128 - 32;
        !           103:        }
        !           104:        fontbase[0] = (struct font *) p;        /* the last shall be first */
        !           105:        fontbase[0]->nwfont = EXTRAFONT - dev.nchtab - (128-32) - sizeof (struct font);
        !           106:        fontab[0] = p + sizeof (struct font);
        !           107:        close(fin);
        !           108:        /* there are a lot of things that used to be constant
        !           109:        /* that now require code to be executed.
        !           110:        */
        !           111:        sps = SPS;
        !           112:        ics = ICS;
        !           113:        for (i = 0; i < 16; i++)
        !           114:                tabtab[i] = DTAB * (i + 1);
        !           115:        pl = 11 * INCH;
        !           116:        po = PO;
        !           117:        spacesz = SS;
        !           118:        lss = lss1 = VS;
        !           119:        ll = ll1 = lt = lt1 = LL;
        !           120:        specnames();    /* install names like "hyphen", etc. */
        !           121:        if (ascii)
        !           122:                return;
        !           123:        fprintf(ptid, "x T %s\n", devname);
        !           124:        fprintf(ptid, "x res %d %d %d\n", Inch, Hor, Vert);
        !           125:        fprintf(ptid, "x init\n");      /* do initialization for particular device */
        !           126:        for (i = 1; i <= nfonts; i++)
        !           127:                fprintf(ptid, "x font %d %s\n", i, fontbase[i]->namefont);
        !           128:   /*
        !           129:        fprintf(ptid, "x xxx fonts=%d sizes=%d unit=%d\n", nfonts, nsizes, Unitwidth);
        !           130:        fprintf(ptid, "x xxx nchtab=%d lchname=%d nfitab=%d\n",
        !           131:                dev.nchtab, dev.lchname, dev.nchtab+128-32);
        !           132:        fprintf(ptid, "x xxx sizes:\nx xxx ");
        !           133:        for (i = 0; i < nsizes; i++)
        !           134:                fprintf(ptid, " %d", pstab[i]);
        !           135:        fprintf(ptid, "\nx xxx chars:\nx xxx ");
        !           136:        for (i = 0; i < dev.nchtab; i++)
        !           137:                fprintf(ptid, " %s", &chname[chtab[i]]);
        !           138:        fprintf(ptid, "\nx xxx\n");
        !           139:   */
        !           140: }
        !           141: 
        !           142: specnames()
        !           143: {
        !           144:        static struct {
        !           145:                int     *n;
        !           146:                char    *v;
        !           147:        } spnames[] = {
        !           148:                &c_hyphen, "hy",
        !           149:                &c_emdash, "em",
        !           150:                &c_rule, "ru",
        !           151:                &c_minus, "\\-",
        !           152:                &c_narsp, "\\|",
        !           153:                &c_hnarsp, "\\^",
        !           154:                &c_fi, "fi",
        !           155:                &c_fl, "fl",
        !           156:                &c_ff, "ff",
        !           157:                &c_ffi, "Fi",
        !           158:                &c_ffl, "Fl",
        !           159:                &c_acute, "aa",
        !           160:                &c_grave, "ga",
        !           161:                &c_under, "ul",
        !           162:                &c_rooten, "rn",
        !           163:                &c_boxrule, "br",
        !           164:                &c_lefthand, "lh",
        !           165:                0, 0
        !           166:        };
        !           167:        int     i;
        !           168: 
        !           169:        for (i = 0; spnames[i].n; i++)
        !           170:                *spnames[i].n = findch(spnames[i].v);
        !           171: }
        !           172: 
        !           173: findch(s)      /* find char s in chname */
        !           174: register char  *s;
        !           175: {
        !           176:        register int    i;
        !           177: 
        !           178:        for (i = 0; i < nchtab; i++)
        !           179:                if (strcmp(s, &chname[chtab[i]]) == 0)
        !           180:                        return(i + 128);
        !           181:        return(0);
        !           182: }
        !           183: 
        !           184: ptout(i)
        !           185: tchar  i;
        !           186: {
        !           187:        register dv, ik;
        !           188:        register tchar  *k;
        !           189:        int     temp, a, b;
        !           190: 
        !           191:        if (cbits(i) != '\n') {
        !           192:                *olinep++ = i;
        !           193:                return;
        !           194:        }
        !           195:        if (olinep == oline) {
        !           196:                lead += lss;
        !           197:                return;
        !           198:        }
        !           199: 
        !           200:        hpos = po;      /* ??? */
        !           201:        esc = 0;        /* ??? */
        !           202:        ptesc();        /* the problem is to get back to the left end of the line */
        !           203:        dv = 0;
        !           204:        for (k = oline; k < olinep; k++) {
        !           205:                if (ismot(*k) && isvmot(*k)) {
        !           206:                        temp = absmot(*k);
        !           207:                        if (isnmot(*k))
        !           208:                                temp = -temp;
        !           209:                        dv += temp;
        !           210:                }
        !           211:        }
        !           212:        if (dv) {
        !           213:                vflag++;
        !           214:                *olinep++ = makem(-dv);
        !           215:                vflag = 0;
        !           216:        }
        !           217: 
        !           218:        b = dip->blss + lss;
        !           219:        lead += dip->blss + lss;
        !           220:        dip->blss = 0;
        !           221:        for (k = oline; k < olinep; )
        !           222:                k += ptout0(k); /* now passing a pointer! */
        !           223:        olinep = oline;
        !           224:        lead += dip->alss;
        !           225:        a = dip->alss;
        !           226:        dip->alss = 0;
        !           227:        /*
        !           228:        fprintf(ptid, "x xxx end of line: hpos=%d, vpos=%d\n", hpos, vpos);
        !           229: */
        !           230:        fprintf(ptid, "n%d %d\n", b, a);        /* be nice to chuck */
        !           231: }
        !           232: 
        !           233: ptout0(pi)
        !           234: tchar  *pi;
        !           235: {
        !           236:        register short j, k, w;
        !           237:        short   z, dx, dy, dx2, dy2, n;
        !           238:        tchar   i;
        !           239:        int outsize;    /* size of object being printed */
        !           240: 
        !           241:        outsize = 1;    /* default */
        !           242:        i = *pi;
        !           243:        k = cbits(i);
        !           244:        if (ismot(i)) {
        !           245:                j = absmot(i);
        !           246:                if (isnmot(i))
        !           247:                        j = -j;
        !           248:                if (isvmot(i))
        !           249:                        lead += j;
        !           250:                else 
        !           251:                        esc += j;
        !           252:                return(outsize);
        !           253:        }
        !           254:        if (k == CHARHT) {
        !           255:                fprintf(ptid, "x H %d\n", sbits(i));
        !           256:                return(outsize);
        !           257:        }
        !           258:        if (k == SLANT) {
        !           259:                fprintf(ptid, "x S %d\n", sfbits(i)-180);
        !           260:                return(outsize);
        !           261:        }
        !           262:        if (k == WORDSP) {
        !           263:                oput('w');
        !           264:                return(outsize);
        !           265:        }
        !           266:        if (k == FONTPOS) {
        !           267:                char temp[3];
        !           268:                n = i >> 16;
        !           269:                temp[0] = n & BMASK;
        !           270:                temp[1] = n >> BYTE;
        !           271:                temp[2] = 0;
        !           272:                ptfpcmd(0, temp, 0);
        !           273:                return(outsize);
        !           274:        }
        !           275:        xbitf = 2;
        !           276:        if (sfbits(i) == oldbits) {
        !           277:                xfont = pfont;
        !           278:                xpts = ppts;
        !           279:                xbitf = 0;
        !           280:        } else 
        !           281:                xbits(i);
        !           282:        if (k < 040 && k != DRAWFCN)
        !           283:                return(outsize);
        !           284:        w = getcw(k - 32);
        !           285:        j = z = 0;
        !           286:        if (k != DRAWFCN) {
        !           287:                if (cs) {
        !           288:                        if (bd)
        !           289:                                w += (bd - 1) * HOR;
        !           290:                        j = (cs - w) / 2;
        !           291:                        w = cs - j;
        !           292:                        if (bd)
        !           293:                                w -= (bd - 1) * HOR;
        !           294:                }
        !           295:                if (iszbit(i)) {
        !           296:                        if (cs)
        !           297:                                w = -j; 
        !           298:                        else 
        !           299:                                w = 0;
        !           300:                        z = 1;
        !           301:                }
        !           302:        }
        !           303:        esc += j;
        !           304:        if (xfont != mfont)
        !           305:                ptfont();
        !           306:        if (xpts != mpts)
        !           307:                ptps();
        !           308:        if (lead)
        !           309:                ptlead();
        !           310:        /* put out the real character here */
        !           311:        if (k == DRAWFCN) {
        !           312:                if (esc)
        !           313:                        ptesc();
        !           314:                dx = absmot(pi[3]);
        !           315:                if (isnmot(pi[3]))
        !           316:                        dx = -dx;
        !           317:                dy = absmot(pi[4]);
        !           318:                if (isnmot(pi[4]))
        !           319:                        dy = -dy;
        !           320:                switch (cbits(pi[1])) {
        !           321:                case DRAWCIRCLE:        /* circle */
        !           322:                        fprintf(ptid, "D%c %d\n", DRAWCIRCLE, dx);      /* dx is diameter */
        !           323:                        w = 0;
        !           324:                        hpos += dx;
        !           325:                        break;
        !           326:                case DRAWELLIPSE:
        !           327:                        fprintf(ptid, "D%c %d %d\n", DRAWELLIPSE, dx, dy);
        !           328:                        w = 0;
        !           329:                        hpos += dx;
        !           330:                        break;
        !           331:                case DRAWLINE:  /* line */
        !           332:                        k = cbits(pi[2]);
        !           333:                        fprintf(ptid, "D%c %d %d ", DRAWLINE, dx, dy);
        !           334:                        if (k < 128)
        !           335:                                fprintf(ptid, "%c\n", k);
        !           336:                        else
        !           337:                                fprintf(ptid, "%s\n", &chname[chtab[k - 128]]);
        !           338:                        w = 0;
        !           339:                        hpos += dx;
        !           340:                        vpos += dy;
        !           341:                        break;
        !           342:                case DRAWARC:   /* arc */
        !           343:                        dx2 = absmot(pi[5]);
        !           344:                        if (isnmot(pi[5]))
        !           345:                                dx2 = -dx2;
        !           346:                        dy2 = absmot(pi[6]);
        !           347:                        if (isnmot(pi[6]))
        !           348:                                dy2 = -dy2;
        !           349:                        fprintf(ptid, "D%c %d %d %d %d\n", DRAWARC,
        !           350:                                dx, dy, dx2, dy2);
        !           351:                        w = 0;
        !           352:                        hpos += dx + dx2;
        !           353:                        vpos += dy + dy2;
        !           354:                        break;
        !           355:                case DRAWWIG:   /* wiggly line */
        !           356:                        fprintf(ptid, "D%c %d %d", DRAWWIG, dx, dy);
        !           357:                        w = 0;
        !           358:                        hpos += dx;
        !           359:                        vpos += dy;
        !           360:                        for (n = 5; cbits(pi[n]) != '.'; n += 2) {
        !           361:                                dx = absmot(pi[n]);
        !           362:                                if (isnmot(pi[n]))
        !           363:                                        dx = -dx;
        !           364:                                dy = absmot(pi[n+1]);
        !           365:                                if (isnmot(pi[n+1]))
        !           366:                                        dy = -dy;
        !           367:                                fprintf(ptid, " %d %d", dx, dy);
        !           368:                                hpos += dx;
        !           369:                                vpos += dy;
        !           370:                        }
        !           371:                        fprintf(ptid, "\n");
        !           372:                        break;
        !           373:                }
        !           374:                for (n = 3; cbits(pi[n]) != '.'; n++)
        !           375:                        ;
        !           376:                outsize = n + 1;
        !           377:        } else if (k < 128) {
        !           378:                /* try to go faster and compress output */
        !           379:                /* by printing nnc for small positive motion followed by c */
        !           380:                /* kludgery; have to make sure set all the vars too */
        !           381:                if (esc > 0 && esc < 100) {
        !           382:                        oput(esc / 10 + '0');
        !           383:                        oput(esc % 10 + '0');
        !           384:                        oput(k);
        !           385:                        hpos += esc;
        !           386:                        esc = 0;
        !           387:                } else {
        !           388:                        if (esc)
        !           389:                                ptesc();
        !           390:                        fprintf(ptid, "c%c\n", k);
        !           391:                }
        !           392:        } else {
        !           393:                if (esc)
        !           394:                        ptesc();
        !           395:                fprintf(ptid, "C%s\n", &chname[chtab[k - 128]]);
        !           396:        }
        !           397:        if (bd) {
        !           398:                bd -= HOR;
        !           399:                if (esc += bd)
        !           400:                        ptesc();
        !           401:                if (k < 128) {
        !           402:                        fprintf(ptid, "c%c\n", k);
        !           403:                } else
        !           404:                        fprintf(ptid, "C%s\n", &chname[chtab[k - 128]]);
        !           405:                if (z)
        !           406:                        esc -= bd;
        !           407:        }
        !           408:        esc += w;
        !           409:        return(outsize);
        !           410: }
        !           411: 
        !           412: ptps()
        !           413: {
        !           414:        register i, j, k;
        !           415: 
        !           416:        i = xpts;
        !           417:        for (j = 0; i > (k = pstab[j]); j++)
        !           418:                if (!k) {
        !           419:                        k = pstab[--j];
        !           420:                        break;
        !           421:                }
        !           422:        fprintf(ptid, "s%d\n", k);      /* really should put out string rep of size */
        !           423:        mpts = i;
        !           424: }
        !           425: 
        !           426: ptfont()
        !           427: {
        !           428:        mfont = xfont;
        !           429:        fprintf(ptid, "f%d\n", xfont);
        !           430: }
        !           431: 
        !           432: ptfpcmd(f, s, d)
        !           433: int    f;
        !           434: char   *s, *d;
        !           435: {
        !           436:        if (ascii)
        !           437:                return;
        !           438:        fprintf(ptid, "x font %d %s %s\n", f, s, d==0 ? "" : d);
        !           439:        ptfont();       /* make sure that it gets noticed */
        !           440: }
        !           441: 
        !           442: ptlead()
        !           443: {
        !           444:        vpos += lead;
        !           445:        if (!ascii)
        !           446:                fprintf(ptid, "V%d\n", vpos);
        !           447:        lead = 0;
        !           448: }
        !           449: 
        !           450: ptesc()
        !           451: {
        !           452:        hpos += esc;
        !           453:        if (esc > 0)
        !           454:                fprintf(ptid, "h%d", esc);
        !           455:        else
        !           456:                fprintf(ptid, "H%d\n", hpos);
        !           457:        esc = 0;
        !           458: }
        !           459: 
        !           460: newpage(n)     /* called at end of each output page (we hope) */
        !           461: {
        !           462:        ptlead();
        !           463:        vpos = 0;
        !           464:        if (ascii)
        !           465:                return;
        !           466:        flusho();
        !           467:        fprintf(ptid, "p%d\n", n);      /* new page */
        !           468:        ptps();
        !           469:        ptfont();
        !           470: }
        !           471: 
        !           472: pttrailer()
        !           473: {
        !           474:        fprintf(ptid, "x trailer\n");
        !           475: }
        !           476: 
        !           477: ptstop()
        !           478: {
        !           479:        fprintf(ptid, "x stop\n");
        !           480: }
        !           481: 
        !           482: dostop()
        !           483: {
        !           484:        if (ascii)
        !           485:                return;
        !           486:        ptlead();
        !           487:        vpos = 0;
        !           488:        /*      fprintf(ptid, "x xxx end of page\n");*/
        !           489:        if (!nofeed)
        !           490:                pttrailer();
        !           491:        ptlead();
        !           492:        fprintf(ptid, "x pause\n");
        !           493:        flusho();
        !           494:        mpts = mfont = 0;
        !           495:        paper = 0;
        !           496:        esc = T_IESC;   /* this is a dreg */
        !           497:        ptesc();
        !           498:        esc = po;
        !           499:        hpos = vpos = 0;        /* probably in wrong place */
        !           500: }

unix.superglobalmegacorp.com

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