Annotation of researchv10no/cmd/tbl/tbl.cpio, revision 1.1.1.1

1.1       root        1: 0707070035051115131006640000030000040000011503200474064415100000500000003372t..c/* t..c : external declarations */
                      2: 
                      3: # include "stdio.h"
                      4: # include "ctype.h"
                      5: 
                      6: # define MAXLIN 250
                      7: # define MAXHEAD 44
                      8: # define MAXCOL 30
                      9:  /* Do NOT make MAXCOL bigger with adjusting nregs[] in tr.c */
                     10: # define MAXCHS 2000
                     11: #define MAXLINLEN 300
                     12: # define MAXRPT 100
                     13: # define CLLEN 10
                     14: # define SHORTLINE 4
                     15: extern int nlin, ncol, iline, nclin, nslin;
                     16: 
                     17: extern int (*style)[MAXHEAD];
                     18: extern char (*font)[MAXHEAD][2];
                     19: extern char (*csize)[MAXHEAD][4];
                     20: extern char (*vsize)[MAXHEAD][4];
                     21: extern char (*cll)[CLLEN];
                     22: extern int (*flags)[MAXHEAD];
                     23: # define ZEROW 001
                     24: # define HALFUP 002
                     25: # define CTOP 004
                     26: # define CDOWN 010
                     27: extern int stynum[];
                     28: extern int qcol;
                     29: extern int *doubled, *acase, *topat;
                     30: extern int F1, F2;
                     31: extern int (*lefline)[MAXHEAD];
                     32: extern int fullbot[];
                     33: extern char *instead[];
                     34: extern int expflg;
                     35: extern int ctrflg;
                     36: extern int evenflg;
                     37: extern int *evenup;
                     38: extern int boxflg;
                     39: extern int dboxflg;
                     40: extern int linsize;
                     41: extern int tab;
                     42: extern int pr1403;
                     43: extern int linsize, delim1, delim2;
                     44: extern int allflg;
                     45: extern int textflg;
                     46: extern int left1flg;
                     47: extern int rightl;
                     48: struct colstr {char *col, *rcol;};
                     49: extern struct colstr *table[];
                     50: extern char *cspace, *cstore;
                     51: extern char *exstore, *exlim, *exspace;
                     52: extern int *sep;
                     53: extern int *used, *lused, *rused;
                     54: extern int linestop[];
                     55: extern int leftover;
                     56: extern char *last, *ifile;
                     57: extern int texname;
                     58: extern int texct, texmax;
                     59: extern char texstr[];
                     60: extern int linstart;
                     61: 
                     62: 
                     63: extern FILE *tabin, *tabout;
                     64: # define CRIGHT 2
                     65: # define CLEFT 0
                     66: # define CMID 1
                     67: # define S1 31
                     68: # define S2 32
                     69: # define S3 33
                     70: # define TMP 38
                     71: #define S9 39
                     72: # define SF 35
                     73: # define SL 34
                     74: # define LSIZE 33
                     75: # define SIND 37
                     76: # define SVS 36
                     77: /* this refers to the relative position of lines */
                     78: # define LEFT 1
                     79: # define RIGHT 2
                     80: # define THRU 3
                     81: # define TOP 1
                     82: # define BOT 2
                     83: 0707070035051115121006640000030000040000010245650265271262100000500000001755t0.c /* t0.c: storage allocation */
                     84: #
                     85: # include "t..c"
                     86: int expflg = 0;
                     87: int ctrflg = 0;
                     88: int boxflg = 0;
                     89: int dboxflg = 0;
                     90: int tab = '\t';
                     91: int linsize;
                     92: int pr1403;
                     93: int delim1, delim2;
                     94: int evenflg;
                     95: int *evenup;
                     96: int F1 = 0;
                     97: int F2 = 0;
                     98: int allflg = 0;
                     99: int leftover = 0;
                    100: int textflg = 0;
                    101: int left1flg = 0;
                    102: int rightl = 0;
                    103: char *cstore, *cspace;
                    104: char *last;
                    105: struct colstr *table[MAXLIN];
                    106: int stynum[MAXLIN+1];
                    107: int fullbot[MAXLIN];
                    108: char *instead[MAXLIN];
                    109: int linestop[MAXLIN];
                    110: int (*style)[MAXHEAD];
                    111: char (*font)[MAXHEAD][2];
                    112: char (*csize)[MAXHEAD][4];
                    113: char (*vsize)[MAXHEAD][4];
                    114: int (*lefline)[MAXHEAD];
                    115: char (*cll)[CLLEN];
                    116: int (*flags)[MAXHEAD];
                    117: int qcol;
                    118: int *doubled, *acase, *topat;
                    119: int nslin, nclin;
                    120: int *sep;
                    121: int *used, *lused, *rused;
                    122: int nlin, ncol;
                    123: int iline = 1;
                    124: char *ifile = "Input";
                    125: int texname = 'a';
                    126: int texct = 0;
                    127: char texstr[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYXZ0123456789";
                    128: int linstart;
                    129: char *exstore, *exlim, *exspace;
                    130: FILE *tabin  /*= stdin */;
                    131: FILE *tabout  /* = stdout */;
                    132: 0707070035051115001006640000510000040000011516610474064427500000500000003744t1.c /* t1.c: main control and input switching */
                    133: #
                    134: # include "t..c"
                    135: #include <signal.h>
                    136: # ifdef gcos
                    137: /* required by GCOS because file is passed to "tbl" by troff preprocessor */
                    138: # define _f1 _f
                    139: extern FILE *_f[];
                    140: # endif
                    141: 
                    142: # ifdef unix
                    143: # define MACROS "/usr/lib/tmac.s"
                    144: # define PYMACS "/usr/lib/tmac.m"
                    145: # endif
                    146: 
                    147: # ifdef gcos
                    148: # define MACROS "cc/troff/smac"
                    149: # define PYMACS "cc/troff/mmac"
                    150: # endif
                    151: 
                    152: # define ever (;;)
                    153: 
                    154: main(argc,argv)
                    155:        char *argv[];
                    156: {
                    157: # ifdef unix
                    158: int badsig();
                    159: signal(SIGPIPE, badsig);
                    160: # endif
                    161: # ifdef gcos
                    162: if(!intss()) tabout = fopen("qq", "w"); /* default media code is type 5 */
                    163: # endif
                    164: exit(tbl(argc,argv));
                    165: }
                    166: 
                    167: 
                    168: tbl(argc,argv)
                    169:        char *argv[];
                    170: {
                    171: char line[5120];
                    172: /*int x;*/
                    173: /*x=malloc((char *)0); uncomment when allocation breaks*/
                    174: /* required by GCOS because "stdout" is set by troff preprocessor */
                    175: tabin=stdin; tabout=stdout;
                    176: setinp(argc,argv);
                    177: while (gets1(line, sizeof(line)))
                    178:        {
                    179:        fprintf(tabout, "%s\n",line);
                    180:        if (prefix(".TS", line))
                    181:                tableput();
                    182:        }
                    183: fclose(tabin);
                    184: return(0);
                    185: }
                    186: int sargc;
                    187: char **sargv;
                    188: setinp(argc,argv)
                    189:        char **argv;
                    190: {
                    191:        sargc = argc;
                    192:        sargv = argv;
                    193:        sargc--; sargv++;
                    194:        if (sargc>0)
                    195:                swapin();
                    196: }
                    197: swapin()
                    198: {
                    199:        char *name;
                    200:        while (sargc>0 && **sargv=='-')
                    201:                {
                    202:                if (match("-ms", *sargv))
                    203:                        {
                    204:                        *sargv = MACROS;
                    205:                        break;
                    206:                        }
                    207:                if (match("-mm", *sargv))
                    208:                        {
                    209:                        *sargv = PYMACS;
                    210:                        break;
                    211:                        }
                    212:                if (match("-TX", *sargv))
                    213:                        pr1403=1;
                    214:                if (match("-", *sargv))
                    215:                        break;
                    216:                sargc--; sargv++;
                    217:                }
                    218:        if (sargc<=0) return(0);
                    219: # ifdef unix
                    220: /* file closing is done by GCOS troff preprocessor */
                    221:        if (tabin!=stdin) fclose(tabin);
                    222: # endif
                    223:        if (match(*sargv, "-")){
                    224:                tabin=stdin;
                    225:                name = "-";
                    226:        }
                    227:        else{
                    228:                tabin = fopen(ifile= *sargv, "r");
                    229:                name = ifile;
                    230:        }
                    231:        iline=1;
                    232: # ifdef unix
                    233: /* file names are all put into f. by the GCOS troff preprocessor */
                    234:        fprintf(tabout, ".ds f. %s\n",ifile);
                    235:        fprintf(tabout, ".lf %d %s\n",iline, name);
                    236: # endif
                    237:        if (tabin==NULL)
                    238:                error("Can't open file");
                    239:        sargc--;
                    240:        sargv++;
                    241:        return(1);
                    242: }
                    243: # ifdef unix
                    244: badsig()
                    245: {
                    246: signal(SIGPIPE, 1);
                    247:  exit(0);
                    248: }
                    249: # endif
                    250: 0707070035051115101006640000030000040000010245670373132574500000500000000420t2.c /* t2.c:  subroutine sequencing for one table */
                    251: # include "t..c"
                    252: tableput()
                    253: {
                    254: saveline();
                    255: savefill();
                    256: ifdivert();
                    257: cleanfc();
                    258: getcomm();
                    259: getspec();
                    260: gettbl();
                    261: getstop();
                    262: checkuse();
                    263: choochar();
                    264: maktab();
                    265: runout();
                    266: release();
                    267: rstofill();
                    268: endoff();
                    269: freearr();
                    270: restline();
                    271: }
                    272: 0707070035051112121006640000030000040000011516630474064445400000500000003265t3.c /* t3.c: interpret commands affecting whole table */
                    273: # include "t..c"
                    274: struct optstr {char *optnam; int *optadd;} options [] = {
                    275:        "expand", &expflg,
                    276:        "EXPAND", &expflg,
                    277:        "center", &ctrflg,
                    278:        "CENTER", &ctrflg,
                    279:        "box", &boxflg,
                    280:        "BOX", &boxflg,
                    281:        "allbox", &allflg,
                    282:        "ALLBOX", &allflg,
                    283:        "doublebox", &dboxflg,
                    284:        "DOUBLEBOX", &dboxflg,
                    285:        "frame", &boxflg,
                    286:        "FRAME", &boxflg,
                    287:        "doubleframe", &dboxflg,
                    288:        "DOUBLEFRAME", &dboxflg,
                    289:        "tab", &tab,
                    290:        "TAB", &tab,
                    291:        "linesize", &linsize,
                    292:        "LINESIZE", &linsize,
                    293:        "delim", &delim1,
                    294:        "DELIM", &delim1,
                    295:        0,0};
                    296: getcomm()
                    297: {
                    298: char line[200], *cp, nb[25], *t;
                    299: struct optstr *lp;
                    300: int c, ci, found;
                    301: for(lp= options; lp->optnam; lp++)
                    302:        *(lp->optadd) = 0;
                    303: texname = texstr[texct=0];
                    304: tab = '\t';
                    305: printf(".nr %d \\n(.s\n", LSIZE);
                    306: gets1(line, sizeof(line));
                    307: /* see if this is a command line */
                    308: if (strchr(line,';') == NULL)
                    309:        {
                    310:        backrest(line);
                    311:        return;
                    312:        }
                    313: for(cp=line; (c = *cp) != ';'; cp++)
                    314:        {
                    315:        if (!letter(c)) continue;
                    316:        found=0;
                    317:        for(lp= options; lp->optadd; lp++)
                    318:                {
                    319:                if (prefix(lp->optnam, cp))
                    320:                        {
                    321:                        *(lp->optadd) = 1;
                    322:                        cp += strlen(lp->optnam);
                    323:                        if (letter(*cp))
                    324:                                error("Misspelled global option");
                    325:                        while (*cp==' ')cp++;
                    326:                        t=nb;
                    327:                        if ( *cp == '(')
                    328:                                while ((ci= *++cp) != ')')
                    329:                                        *t++ = ci;
                    330:                        else cp--;
                    331:                        *t++ = 0; *t=0;
                    332:                        if (lp->optadd == &tab)
                    333:                                {
                    334:                                if (nb[0])
                    335:                                        *(lp->optadd) = nb[0];
                    336:                                }
                    337:                        if (lp->optadd == &linsize)
                    338:                                printf(".nr %d %s\n", LSIZE, nb);
                    339:                        if (lp->optadd == &delim1)
                    340:                                {
                    341:                                delim1 = nb[0];
                    342:                                delim2 = nb[1];
                    343:                                }
                    344:                        found=1;
                    345:                        break;
                    346:                        }
                    347:                }
                    348:        if (!found)
                    349:                error("Illegal option");
                    350:        }
                    351: cp++;
                    352: backrest(cp);
                    353: return;
                    354: }
                    355: backrest(cp)
                    356:        char *cp;
                    357: {
                    358: char *s;
                    359: for(s=cp; *s; s++);
                    360: un1getc('\n');
                    361: while (s>cp)
                    362:        un1getc(*--s);
                    363: return;
                    364: }
                    365: 0707070035050264701006640000510000010000011371440455733744100000500000017000t4.c /* t4.c: read table specification */
                    366: # include "t..c"
                    367: int oncol;
                    368: getspec()
                    369: {
                    370: int icol, i;
                    371: qcol = findcol()+1;/* must allow one extra for line at right */
                    372: garray(qcol);
                    373: sep[-1]= -1;
                    374: for(icol=0; icol<qcol; icol++)
                    375:        {
                    376:        sep[icol]= -1;
                    377:        evenup[icol]=0;
                    378:        cll[icol][0]=0;
                    379:        for(i=0; i<MAXHEAD; i++)
                    380:                {
                    381:                csize[icol][i][0]=0;
                    382:                vsize[icol][i][0]=0;
                    383:                font[icol][i][0] = lefline[icol][i] = 0;
                    384:                flags[icol][i]=0;
                    385:                style[icol][i]= 'l';
                    386:                }
                    387:        }
                    388: for(i=0;i<MAXHEAD;i++)
                    389:        lefline[qcol][i]=0;     /* fixes sample55 looping */
                    390: nclin=ncol=0;
                    391: oncol =0;
                    392: left1flg=rightl=0;
                    393: readspec();
                    394: fprintf(tabout, ".rm");
                    395: for(i=0; i<ncol; i++)
                    396:        fprintf(tabout, " %2s", reg(i, CRIGHT));
                    397: fprintf(tabout, "\n");
                    398: }
                    399: readspec()
                    400: {
                    401: int icol, c, sawchar, stopc, i;
                    402: char sn[10], *snp, *temp;
                    403: sawchar=icol=0;
                    404: while (c=get1char())
                    405:        {
                    406:        switch(c)
                    407:                {
                    408:                default:
                    409:                        if (c != tab)
                    410:                        error("bad table specification character");
                    411:                case ' ': /* note this is also case tab */
                    412:                        continue;
                    413:                case '\n':
                    414:                        if(sawchar==0) continue;
                    415:                case ',':
                    416:                case '.': /* end of table specification */
                    417:                        ncol = max(ncol, icol);
                    418:                        if (lefline[ncol][nclin]>0) {ncol++; rightl++;};
                    419:                        if(sawchar)
                    420:                                nclin++;
                    421:                        if (nclin>=MAXHEAD)
                    422:                                error("too many lines in specification");
                    423:                        icol=0;
                    424:                        if (ncol==0 || nclin==0)
                    425:                                error("no specification");
                    426:                        if (c== '.')
                    427:                                {
                    428:                                while ((c=get1char()) && c != '\n')
                    429:                                        if (c != ' ' && c != '\t')
                    430:                                                error("dot not last character on format line");
                    431:                                /* fix up sep - default is 3 except at edge */
                    432:                                for(icol=0; icol<ncol; icol++)
                    433:                                        if (sep[icol]<0)
                    434:                                                sep[icol] =  icol+1<ncol ? 3 : 2;
                    435:                                if (oncol == 0)
                    436:                                        oncol = ncol;
                    437:                                else if (oncol +2 <ncol)
                    438:                                        error("tried to widen table in T&, not allowed");
                    439:                                return;
                    440:                                }
                    441:                        sawchar=0;
                    442:                        continue;
                    443:                case 'C': case 'S': case 'R': case 'N': case 'L':  case 'A':
                    444:                        c += ('a'-'A');
                    445:                case '_': if (c=='_') c= '-';
                    446:                case '=': case '-':
                    447:                case '^':
                    448:                case 'c': case 's': case 'n': case 'r': case 'l':  case 'a':
                    449:                        style[icol][nclin]=c;
                    450:                        if (c== 's' && icol<=0)
                    451:                                error("first column can not be S-type");
                    452:                        if (c=='s' && style[icol-1][nclin] == 'a')
                    453:                                {
                    454:                                fprintf(tabout, ".tm warning: can't span a-type cols, changed to l\n");
                    455:                                style[icol-1][nclin] = 'l';
                    456:                                }
                    457:                        if (c=='s' && style[icol-1][nclin] == 'n')
                    458:                                {
                    459:                                fprintf(tabout, ".tm warning: can't span n-type cols, changed to c\n");
                    460:                                style[icol-1][nclin] = 'c';
                    461:                                }
                    462:                        icol++;
                    463:                        if (c=='^' && nclin<=0)
                    464:                                error("first row can not contain vertical span");
                    465:                        if (icol>qcol)
                    466:                                error("too many columns in table");
                    467:                        sawchar=1;
                    468:                        continue;
                    469:                case 'b': case 'i': 
                    470:                        c += 'A'-'a';
                    471:                case 'B': case 'I':
                    472:                        if (icol==0) continue;
                    473:                        snp=font[icol-1][nclin];
                    474:                        snp[0]= (c=='I' ? '2' : '3');
                    475:                        snp[1]=0;
                    476:                        continue;
                    477:                case 't': case 'T':
                    478:                        if (icol>0)
                    479:                        flags[icol-1][nclin] |= CTOP;
                    480:                        continue;
                    481:                case 'd': case 'D':
                    482:                        if (icol>0)
                    483:                        flags[icol-1][nclin] |= CDOWN;
                    484:                        continue;
                    485:                case 'f': case 'F':
                    486:                        if (icol==0) continue;
                    487:                        snp=font[icol-1][nclin];
                    488:                        snp[0]=snp[1]=stopc=0;
                    489:                        for(i=0; i<2; i++)
                    490:                                {
                    491:                                c = get1char();
                    492:                                if (i==0 && c=='(')
                    493:                                        {
                    494:                                        stopc=')';
                    495:                                        c = get1char();
                    496:                                        }
                    497:                                if (c==0) break;
                    498:                                if (c==stopc) {stopc=0; break;}
                    499:                                if (stopc==0)  if (c==' ' || c== tab ) break;
                    500:                                if (c=='\n' || c == '|'){un1getc(c); break;}
                    501:                                snp[i] = c;
                    502:                                if (c>= '0' && c<= '9') break;
                    503:                                }
                    504:                        if (stopc) if (get1char()!=stopc)
                    505:                                error("Nonterminated font name");
                    506:                        continue;
                    507:                case 'P': case 'p':
                    508:                        if (icol<=0) continue;
                    509:                        temp = snp = csize[icol-1][nclin];
                    510:                        while (c = get1char())
                    511:                                {
                    512:                                if (c== ' ' || c== tab || c=='\n') break;
                    513:                                if (c=='-' || c == '+')
                    514:                                        if (snp>temp)
                    515:                                                break;
                    516:                                        else
                    517:                                                *snp++=c;
                    518:                                else
                    519:                                if (digit(c))
                    520:                                        *snp++ = c;
                    521:                                else break;
                    522:                                if (snp-temp>4)
                    523:                                        error("point size too large");
                    524:                                }
                    525:                        *snp = 0;
                    526:                        if (atoi(temp)>36)
                    527:                                error("point size unreasonable");
                    528:                        un1getc (c);
                    529:                        continue;
                    530:                case 'V': case 'v':
                    531:                        if (icol<=0) continue;
                    532:                        temp = snp = vsize[icol-1][nclin];
                    533:                        while (c = get1char())
                    534:                                {
                    535:                                if (c== ' ' || c== tab || c=='\n') break;
                    536:                                if (c=='-' || c == '+')
                    537:                                        if (snp>temp)
                    538:                                                break;
                    539:                                        else
                    540:                                                *snp++=c;
                    541:                                else
                    542:                                if (digit(c))
                    543:                                        *snp++ = c;
                    544:                                else break;
                    545:                                if (snp-temp>4)
                    546:                                        error("vertical spacing value too large");
                    547:                                }
                    548:                        *snp=0;
                    549:                        un1getc(c);
                    550:                        continue;
                    551:                case 'w': case 'W':
                    552:                        snp = cll [icol-1];
                    553:                /* Dale Smith didn't like this check - possible to have two text blocks
                    554:                   of different widths now ....
                    555:                        if (*snp)
                    556:                                {
                    557:                                fprintf(tabout, "Ignored second width specification");
                    558:                                continue;
                    559:                                }
                    560:                /* end commented out code ... */
                    561:                        stopc=0;
                    562:                        while (c = get1char())
                    563:                                {
                    564:                                if (snp==cll[icol-1] && c=='(')
                    565:                                        {
                    566:                                        stopc = ')';
                    567:                                        continue;
                    568:                                        }
                    569:                                if ( !stopc && (c>'9' || c< '0'))
                    570:                                        break;
                    571:                                if (stopc && c== stopc)
                    572:                                        break;
                    573:                                *snp++ =c;
                    574:                                }
                    575:                        *snp=0;
                    576:                        if (snp-cll[icol-1]>CLLEN)
                    577:                                error ("column width too long");
                    578:                        if (!stopc)
                    579:                                un1getc(c);
                    580:                        continue;
                    581:                case 'e': case 'E':
                    582:                        if (icol<1) continue;
                    583:                        evenup[icol-1]=1;
                    584:                        evenflg=1;
                    585:                        continue;
                    586:                case 'z': case 'Z': /* zero width-ignre width this item */
                    587:                        if (icol<1) continue;
                    588:                        flags[icol-1][nclin] |= ZEROW;
                    589:                        continue;
                    590:                case 'u': case 'U': /* half line up */
                    591:                        if (icol<1) continue;
                    592:                        flags[icol-1][nclin] |= HALFUP;
                    593:                        continue;
                    594:                case '0': case '1': case '2': case '3': case '4':
                    595:                case '5': case '6': case '7': case '8': case '9': 
                    596:                        sn[0] = c;
                    597:                        snp=sn+1;
                    598:                        while (digit(*snp++ = c = get1char()))
                    599:                                ;
                    600:                        un1getc(c);
                    601:                        sep[icol-1] = max(sep[icol-1], numb(sn));
                    602:                        continue;
                    603:                case '|':
                    604:                        lefline[icol][nclin]++;
                    605:                        if (icol==0) left1flg=1;
                    606:                        continue;
                    607:                }
                    608:        }
                    609: error("EOF reading table specification");
                    610: }
                    611: findcol()
                    612: {
                    613: # define FLNLIM 200
                    614: /* this counts the number of columns and then puts the line back*/
                    615: char *s, line[FLNLIM+2], *p;
                    616: int c, n=0, inpar=0;
                    617: while ((c=get1char())!=EOF && c == ' ')
                    618:        ;
                    619: if (c!='\n')
                    620:        un1getc(c);
                    621: for(s=line; *s = c = get1char(); s++)
                    622:        {
                    623:        if (c==')') inpar=0;
                    624:        if (inpar) continue;
                    625:        if (c=='\n' || c == EOF || c == '.' || c==',')
                    626:                break;
                    627:        else if (c=='(')
                    628:                inpar=1;
                    629:        else
                    630:                if (s>=line+FLNLIM)
                    631:                        error("too long spec line");
                    632:        }
                    633: for(p=line; p<s; p++)
                    634:        switch (c= *p)
                    635:                {
                    636:                case 'l': case 'r': case 'c': case 'n': case 'a': case 's': 
                    637:                case 'L': case 'R': case 'C': case 'N': case 'A': case 'S': 
                    638:                case '-': case '=': case '_':
                    639:                        n++;
                    640:                }
                    641: while (p>=line)
                    642:        un1getc(*p--);
                    643: return(n);
                    644: }
                    645: garray(qcol)
                    646: {
                    647: char * getcore();
                    648: style =  (int (*)[]) getcore(MAXHEAD*qcol, sizeof(int));
                    649: evenup = (int *) getcore(qcol, sizeof(int));
                    650: lefline = (int (*)[]) getcore(MAXHEAD*(qcol+1), sizeof (int)); /*+1 for sample55 loop - others may need it too*/
                    651: font = (char (*)[][2]) getcore(MAXHEAD*qcol, 2);
                    652: csize = (char (*)[MAXHEAD][4]) getcore(MAXHEAD*qcol, 4);
                    653: vsize = (char (*)[MAXHEAD][4]) getcore(MAXHEAD*qcol, 4);
                    654: flags =  (int (*)[]) getcore(MAXHEAD*qcol, sizeof(int));
                    655: cll = (char (*)[])getcore(qcol, CLLEN);
                    656: sep = (int *) getcore(qcol+1, sizeof(int));
                    657: sep++; /* sep[-1] must be legal */
                    658: used = (int *) getcore(qcol+1, sizeof(int));
                    659: lused = (int *) getcore(qcol+1, sizeof(int));
                    660: rused = (int *) getcore(qcol+1, sizeof(int));
                    661: doubled = (int *) getcore(qcol+1, sizeof(int));
                    662: acase = (int *) getcore(qcol+1, sizeof(int));
                    663: topat = (int *) getcore(qcol+1, sizeof(int));
                    664: }
                    665: char *
                    666: getcore(a,b)
                    667: {
                    668: char *x, *calloc();
                    669: x = calloc(a,b);
                    670: if (x==0) 
                    671:        error("Couldn't get memory");
                    672: return(x);
                    673: }
                    674: freearr()
                    675: {
                    676: cfree(style);
                    677: cfree(evenup);
                    678: cfree(lefline);
                    679: cfree(flags);
                    680: cfree(font);
                    681: cfree(csize);
                    682: cfree(vsize);
                    683: cfree(cll);
                    684: cfree(--sep);  /* netnews says this should be --sep because incremented earlier! */
                    685: cfree(used);
                    686: cfree(lused);
                    687: cfree(rused);
                    688: cfree(doubled);
                    689: cfree(acase);
                    690: cfree(topat);
                    691: }
                    692: 0707070035051112061006640000510000040000010207410474064464000000500000006556t5.c /* t5.c: read data for table */
                    693: # include "t..c"
                    694: gettbl()
                    695: {
                    696: extern char *chspace();
                    697: extern char *maknew();
                    698: int icol, ch;
                    699: cstore=cspace= chspace();
                    700: textflg=0;
                    701: for (nlin=nslin=0; gets1(cstore, MAXCHS - (cstore-cspace)); nlin++)
                    702:        {
                    703:        stynum[nlin]=nslin;
                    704:        if (prefix(".TE", cstore))
                    705:                {
                    706:                leftover=0;
                    707:                break;
                    708:                }
                    709:        if (prefix(".TC", cstore) || prefix(".T&", cstore))
                    710:                {
                    711:                readspec();
                    712:                nslin++;
                    713:                }
                    714:        if (nlin>=MAXLIN)
                    715:                {
                    716:                leftover=(int)cstore;
                    717:                break;
                    718:                }
                    719:        fullbot[nlin]=0;
                    720:        if (cstore[0] == '.' && !isdigit(cstore[1]))
                    721:                {
                    722:                instead[nlin] = cstore;
                    723:                while (*cstore++);
                    724:                continue;
                    725:                }
                    726:        else instead[nlin] = 0;
                    727:        if (nodata(nlin))
                    728:                {
                    729:                if (ch = oneh(nlin))
                    730:                        fullbot[nlin]= ch;
                    731:                table[nlin] = (struct colstr *) alocv((ncol+2)*sizeof(table[0][0]));
                    732:                for(icol=0;icol<ncol;icol++){
                    733:                        table[nlin][icol].rcol = "";
                    734:                        table[nlin][icol].col = "";
                    735:                }
                    736:                nlin++;
                    737:                nslin++;
                    738:                fullbot[nlin] = 0;
                    739:                instead[nlin] = (char *) 0;
                    740:                }
                    741:        table[nlin] = (struct colstr *) alocv((ncol+2)*sizeof(table[0][0]));
                    742:        if (cstore[1]==0)
                    743:        switch(cstore[0])
                    744:                {
                    745:                case '_': fullbot[nlin]= '-'; continue;
                    746:                case '=': fullbot[nlin]= '='; continue;
                    747:                }
                    748:        stynum[nlin] = nslin;
                    749:        nslin = min(nslin+1, nclin-1);
                    750:        for (icol = 0; icol <ncol; icol++)
                    751:                {
                    752:                table[nlin][icol].col = cstore;
                    753:                table[nlin][icol].rcol=0;
                    754:                ch=1;
                    755:                if (match(cstore, "T{")){ /* text follows */
                    756:                        table[nlin][icol].col =
                    757:                                (char *)gettext(cstore, nlin, icol,
                    758:                                        font[icol][stynum[nlin]],
                    759:                                        csize[icol][stynum[nlin]]);
                    760:                }
                    761:                else
                    762:                        {
                    763:                        for(; (ch= *cstore) != '\0' && ch != tab; cstore++)
                    764:                                        ;
                    765:                        *cstore++ = '\0';
                    766:                        switch(ctype(nlin,icol)) /* numerical or alpha, subcol */
                    767:                                {
                    768:                                case 'n':
                    769:                                        table[nlin][icol].rcol = maknew(table[nlin][icol].col);
                    770:                                        break;
                    771:                                case 'a':
                    772:                                        table[nlin][icol].rcol = table[nlin][icol].col;
                    773:                                        table[nlin][icol].col = "";
                    774:                                        break;
                    775:                                }
                    776:                        }
                    777:                while (ctype(nlin,icol+1)== 's') /* spanning */
                    778:                        table[nlin][++icol].col = "";
                    779:                if (ch == '\0') break;
                    780:                }
                    781:        while (++icol <ncol+2)
                    782:                {
                    783:                table[nlin][icol].col = "";
                    784:                table [nlin][icol].rcol=0;
                    785:                }
                    786:        while (*cstore != '\0')
                    787:                 cstore++;
                    788:        if (cstore-cspace + MAXLINLEN > MAXCHS)
                    789:                cstore = cspace = chspace();
                    790:        }
                    791: last = cstore;
                    792: permute();
                    793: if (textflg) untext();
                    794: return;
                    795: }
                    796: nodata(il)
                    797: {
                    798: int c;
                    799: for (c=0; c<ncol;c++)
                    800:        {
                    801:        switch(ctype(il,c))
                    802:                {
                    803:                case 'c': case 'n': case 'r': case 'l': case 's': case 'a':
                    804:                        return(0);
                    805:                }
                    806:        }
                    807: return(1);
                    808: }
                    809: oneh(lin)
                    810: {
                    811: int k, icol;
                    812: k = ctype(lin,0);
                    813: for(icol=1; icol<ncol; icol++)
                    814:        {
                    815:        if (k != ctype(lin,icol))
                    816:                return(0);
                    817:        }
                    818: return(k);
                    819: }
                    820: # define SPAN "\\^"
                    821: permute()
                    822: {
                    823: int irow, jcol, is;
                    824: char *start, *strig;
                    825: for(jcol=0; jcol<ncol; jcol++)
                    826:        {
                    827:        for(irow=1; irow<nlin; irow++)
                    828:                {
                    829:                if (vspand(irow,jcol,0))
                    830:                        {
                    831:                        is = prev(irow);
                    832:                        if (is<0)
                    833:                                error("Vertical spanning in first row not allowed");
                    834:                        start = table[is][jcol].col;
                    835:                        strig = table[is][jcol].rcol;
                    836:                        while (irow<nlin &&vspand(irow,jcol,0))
                    837:                                irow++;
                    838:                        table[--irow][jcol].col = start;
                    839:                        table[irow][jcol].rcol = strig;
                    840:                        while (is<irow)
                    841:                                {
                    842:                                table[is][jcol].rcol =0;
                    843:                                table[is][jcol].col= SPAN;
                    844:                                is = next(is);
                    845:                                }
                    846:                        }
                    847:                }
                    848:        }
                    849: }
                    850: vspand(ir,ij,ifform)
                    851: {
                    852: if (ir<0) return(0);
                    853: if (ir>=nlin)return(0);
                    854: if (instead[ir]) return(0);
                    855: if (ifform==0 && ctype(ir,ij)=='^') return(1);
                    856: if (table[ir][ij].rcol!=0) return(0);
                    857: if (fullbot[ir]) return(0);
                    858: return(vspen(table[ir][ij].col));
                    859: }
                    860: vspen(s)
                    861:        char *s;
                    862: {
                    863: if (s==0) return(0);
                    864: if (!point(s)) return(0);
                    865: return(match(s, SPAN));
                    866: }
                    867: 0707070035051112041006640000030000040000010245600265271264300000500000014652t6.c /* t6.c: compute tab stops */
                    868: # define tx(a) (a>0 && a<128)
                    869: # include "t..c"
                    870: maktab()
                    871: {
                    872: # define FN(i,c) font[c][stynum[i]]
                    873: # define SZ(i,c) csize[c][stynum[i]]
                    874: /* define the tab stops of the table */
                    875: int icol, ilin, tsep, k, ik, vforml, il, text;
                    876: char *s;
                    877: for(icol=0; icol <ncol; icol++)
                    878:        {
                    879:        doubled[icol] = acase[icol] = 0;
                    880:        fprintf(tabout, ".nr %2s 0\n", reg(icol,CRIGHT));
                    881:    for(text=0; text<2; text++)
                    882:        {
                    883:        if (text)
                    884:                fprintf(tabout, ".%2s\n.rm %2s\n", reg(icol, CRIGHT), reg(icol, CRIGHT));
                    885:        for(ilin=0; ilin<nlin; ilin++)
                    886:                {
                    887:                if (instead[ilin]|| fullbot[ilin]) continue;
                    888:                vforml=ilin;
                    889:                for(il=prev(ilin); il>=0 && vspen(table[il][icol].col); il=prev(il))
                    890:                        vforml=il;
                    891:                if (fspan(vforml,icol)) continue;
                    892:                if (filler(table[ilin][icol].col)) continue;
                    893:                if ((flags[icol][stynum[ilin]] & ZEROW) != 0) continue;
                    894:                switch(ctype(vforml,icol))
                    895:                        {
                    896:                        case 'a':
                    897:                                acase[icol]=1;
                    898:                                s = table[ilin][icol].col;
                    899:                                if ((int)s>0 && (int)s<128 && text)
                    900:                                        {
                    901:                                        if (doubled[icol]==0)
                    902:                                                fprintf(tabout, ".nr %d 0\n.nr %d 0\n",S1,S2);
                    903:                                        doubled[icol]=1;
                    904:                                        fprintf(tabout, ".if \\n(%c->\\n(%d .nr %d \\n(%c-\n",s,S2,S2,s);
                    905:                                        }
                    906:                        case 'n':
                    907:                                if (table[ilin][icol].rcol!=0)
                    908:                                        {
                    909:                                        if (doubled[icol]==0 && text==0)
                    910:                                                fprintf(tabout, ".nr %d 0\n.nr %d 0\n", S1, S2);
                    911:                                        doubled[icol]=1;
                    912:                                        if (real(s=table[ilin][icol].col) && !vspen(s))
                    913:                                                {
                    914:                                                if (tx((int)s) != text) continue;
                    915:                                                fprintf(tabout, ".nr %d ", TMP);
                    916:                                                wide(s, FN(vforml,icol), SZ(vforml,icol)); fprintf(tabout, "\n");
                    917:                                                fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n", S1, TMP, S1, TMP);
                    918:                                                }
                    919:                                        if (text==0 && real(s=table[ilin][icol].rcol) && !vspen(s) && !barent(s))
                    920:                                                {
                    921:                                                fprintf(tabout, ".nr %d \\w%c%s%c\n",TMP, F1, s, F1);
                    922:                                                fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n",S2,TMP,S2,TMP);
                    923:                                                }
                    924:                                        continue;
                    925:                                        }
                    926:                        case 'r':
                    927:                        case 'c':
                    928:                        case 'l':
                    929:                                if (real(s=table[ilin][icol].col) && !vspen(s))
                    930:                                        {
                    931:                                        if (tx((int)s) != text) continue;
                    932:                                        fprintf(tabout, ".nr %d ", TMP);
                    933:                                        wide(s, FN(vforml,icol), SZ(vforml,icol)); fprintf(tabout, "\n");
                    934:                                        fprintf(tabout, ".if \\n(%2s<\\n(%d .nr %2s \\n(%d\n", reg(icol,CRIGHT), TMP, reg(icol,CRIGHT), TMP);
                    935:                                        }
                    936:                        }
                    937:                }
                    938:                }
                    939:        if (acase[icol])
                    940:                {
                    941:                fprintf(tabout, ".if \\n(%d>=\\n(%2s .nr %2s \\n(%du+2n\n",S2,reg(icol,CRIGHT),reg(icol,CRIGHT),S2);
                    942:                }
                    943:        if (doubled[icol])
                    944:                {
                    945:                fprintf(tabout, ".nr %2s \\n(%d\n", reg(icol,CMID), S1);
                    946:                fprintf(tabout, ".nr %d \\n(%2s+\\n(%d\n",TMP,reg(icol,CMID),S2);
                    947:                fprintf(tabout, ".if \\n(%d>\\n(%2s .nr %2s \\n(%d\n",TMP,reg(icol,CRIGHT),reg(icol,CRIGHT),TMP);
                    948:                fprintf(tabout, ".if \\n(%d<\\n(%2s .nr %2s +(\\n(%2s-\\n(%d)/2\n",TMP,reg(icol,CRIGHT),reg(icol,CMID),reg(icol,CRIGHT),TMP);
                    949:                }
                    950:        if (cll[icol][0])
                    951:                {
                    952:                fprintf(tabout, ".nr %d %sn\n", TMP, cll[icol]);
                    953:                fprintf(tabout, ".if \\n(%2s<\\n(%d .nr %2s \\n(%d\n",reg(icol,CRIGHT), TMP, reg(icol,CRIGHT), TMP);
                    954:                }
                    955:        for(ilin=0; ilin<nlin; ilin++)
                    956:        if (k=lspan(ilin, icol))
                    957:                {
                    958:                s=table[ilin][icol-k].col;
                    959:                if (!real(s) || barent(s) || vspen(s) ) continue;
                    960:                fprintf(tabout, ".nr %d ", TMP);
                    961:                wide(table[ilin][icol-k].col, FN(ilin,icol-k), SZ(ilin,icol-k));
                    962:                for(ik=k; ik>=0; ik--)
                    963:                        {
                    964:                        fprintf(tabout, "-\\n(%2s",reg(icol-ik,CRIGHT));
                    965:                        if (!expflg && ik>0) fprintf(tabout, "-%dn", sep[icol-ik]);
                    966:                        }
                    967:                fprintf(tabout, "\n");
                    968:                fprintf(tabout, ".if \\n(%d>0 .nr %d \\n(%d/%d\n", TMP, TMP, TMP, k);
                    969:                fprintf(tabout, ".if \\n(%d<0 .nr %d 0\n", TMP, TMP);
                    970:                for(ik=1; ik<=k; ik++)
                    971:                        {
                    972:                        if (doubled[icol-k+ik])
                    973:                                fprintf(tabout, ".nr %2s +\\n(%d/2\n", reg(icol-k+ik,CMID), TMP);
                    974:                        fprintf(tabout, ".nr %2s +\\n(%d\n", reg(icol-k+ik,CRIGHT), TMP);
                    975:                        }
                    976:                }
                    977:        }
                    978: if (textflg) untext();
                    979: /* if even requested, make all columns widest width */
                    980: # define TMP1 S1
                    981: # define TMP2 S2
                    982: if (evenflg)
                    983:        {
                    984:        fprintf(tabout, ".nr %d 0\n", TMP);
                    985:        for(icol=0; icol<ncol; icol++)
                    986:                {
                    987:                if (evenup[icol]==0) continue;
                    988:                fprintf(tabout, ".if \\n(%2s>\\n(%d .nr %d \\n(%2s\n",
                    989:                reg(icol,CRIGHT), TMP, TMP, reg(icol,CRIGHT));
                    990:                }
                    991:        for(icol=0; icol<ncol; icol++)
                    992:                {
                    993:                if (evenup[icol]==0)
                    994:                        /* if column not evened just retain old interval */
                    995:                        continue;
                    996:                if (doubled[icol])
                    997:                        fprintf(tabout, ".nr %2s (100*\\n(%2s/\\n(%2s)*\\n(%d/100\n",
                    998:                                reg(icol,CMID), reg(icol,CMID), reg(icol,CRIGHT), TMP);
                    999:                                /* that nonsense with the 100's and parens tries
                   1000:                                   to avoid overflow while proportionally shifting
                   1001:                                   the middle of the number */
                   1002:                fprintf(tabout, ".nr %2s \\n(%d\n", reg(icol,CRIGHT), TMP);
                   1003:                }
                   1004:        }
                   1005: /* now adjust for total table width */
                   1006: for(tsep=icol=0; icol<ncol; icol++)
                   1007:        tsep+= sep[icol];
                   1008: if (expflg)
                   1009:        {
                   1010:        fprintf(tabout, ".nr %d 0", TMP);
                   1011:        for(icol=0; icol<ncol; icol++)
                   1012:                fprintf(tabout, "+\\n(%2s", reg(icol,CRIGHT));
                   1013:        fprintf(tabout, "\n");
                   1014:        fprintf(tabout, ".nr %d \\n(.l-\\n(%d\n", TMP, TMP);
                   1015:        if (boxflg || dboxflg || allflg)
                   1016:                /* tsep += 1; */ ;
                   1017:        else
                   1018:                tsep -= sep[ncol-1];
                   1019:        fprintf(tabout, ".nr %d \\n(%d/%d\n", TMP, TMP,  tsep);
                   1020:        fprintf(tabout, ".if \\n(%d<0 .nr %d 0\n", TMP, TMP);
                   1021:        }
                   1022: else
                   1023:        fprintf(tabout, ".nr %d 1n\n", TMP);
                   1024: fprintf(tabout, ".nr %2s 0\n",reg(-1, CRIGHT));
                   1025: tsep= (boxflg || allflg || dboxflg || left1flg) ? 2 : 0;
                   1026: if (sep[-1] >= 0) tsep = sep[-1];
                   1027: for(icol=0; icol<ncol; icol++)
                   1028:        {
                   1029:        fprintf(tabout, ".nr %2s \\n(%2s+((%d*\\n(%d)/2)\n",reg(icol,CLEFT), reg(icol-1,CRIGHT), tsep, TMP);
                   1030:        fprintf(tabout, ".nr %2s +\\n(%2s\n",reg(icol,CRIGHT), reg(icol,CLEFT));
                   1031:        if (doubled[icol])
                   1032:                {
                   1033:                /* the next line is last-ditch effort to avoid zero field width */
                   1034:                /*fprintf(tabout, ".if \\n(%2s=0 .nr %2s 1\n",reg(icol,CMID), reg(icol,CMID));*/
                   1035:                fprintf(tabout, ".nr %2s +\\n(%2s\n", reg(icol,CMID), reg(icol,CLEFT));
                   1036:        /*  fprintf(tabout, ".if n .if \\n(%s%%24>0 .nr %s +12u\n",reg(icol,CMID), reg(icol,CMID)); */
                   1037:                }
                   1038:        tsep=sep[icol]*2;
                   1039:        }
                   1040: if (rightl)
                   1041:        fprintf(tabout, ".nr %s (\\n(%s+\\n(%s)/2\n",reg(ncol-1, CRIGHT), reg(ncol-1,CLEFT), reg(ncol-2,CRIGHT));
                   1042: fprintf(tabout, ".nr TW \\n(%2s\n", reg(ncol-1, CRIGHT));
                   1043: tsep = sep[ncol-1];
                   1044: if (boxflg || allflg || dboxflg)
                   1045:        fprintf(tabout, ".nr TW +((%d*\\n(%d)/2)\n", tsep, TMP);
                   1046: fprintf(tabout,
                   1047:  ".if t .if (\\n(TW+\\n(.o)>7.65i .tm Table at line %d file %s is too wide - \\n(TW units\n", iline-1, ifile);
                   1048: return;
                   1049: }
                   1050: wide(s, fn, size)
                   1051:        char *s, *size, *fn;
                   1052: {
                   1053: if (point(s))
                   1054:        {
                   1055:        fprintf(tabout, "\\w%c", F1);
                   1056:        if (*fn>0) putfont(fn);
                   1057:        if (*size) putsize(size);
                   1058:        fprintf(tabout, "%s", s);
                   1059:        if (*fn>0) putfont("P");
                   1060:        if (*size) putsize("0");
                   1061:        fprintf(tabout, "%c",F1);
                   1062:        }
                   1063: else
                   1064:        fprintf(tabout, "\\n(%c-", s);
                   1065: }
                   1066: filler(s)
                   1067:        char *s;
                   1068: {
                   1069: return (point(s) && s[0]=='\\' && s[1] == 'R');
                   1070: }
                   1071: 0707070035051115071006640000030000040000010245700265271264300000500000006174t7.c /* t7.c: control to write table entries */
                   1072: # include "t..c"
                   1073: # define realsplit ((ct=='a'||ct=='n') && table[ldata][c].rcol)
                   1074: runout()
                   1075: {
                   1076: int i;
                   1077: if (boxflg || allflg || dboxflg) need();
                   1078: if (ctrflg)
                   1079:        {
                   1080:        fprintf(tabout, ".nr #I \\n(.i\n");
                   1081:        fprintf(tabout, ".in +(\\n(.lu-\\n(TWu-\\n(.iu)/2u\n");
                   1082:        }
                   1083: fprintf(tabout, ".fc %c %c\n", F1, F2);
                   1084: fprintf(tabout, ".nr #T 0-1\n");
                   1085: deftail();
                   1086: for(i=0; i<nlin; i++)
                   1087:        putline(i,i);
                   1088: if (leftover)
                   1089:        yetmore();
                   1090: fprintf(tabout, ".fc\n");
                   1091: fprintf(tabout, ".nr T. 1\n");
                   1092: fprintf(tabout, ".T# 1\n");
                   1093: if (ctrflg)
                   1094:        fprintf(tabout, ".in \\n(#Iu\n");
                   1095: }
                   1096: runtabs(lform, ldata)
                   1097: {
                   1098: int c, ct, vforml, lf;
                   1099: fprintf(tabout, ".ta ");
                   1100: for(c=0; c<ncol; c++)
                   1101:        {
                   1102:        vforml=lform;
                   1103:        for(lf=prev(lform); lf>=0 && vspen(table[lf][c].col); lf=prev(lf))
                   1104:                vforml=lf;
                   1105:        if (fspan(vforml,c))
                   1106:                continue;
                   1107:        switch(ct=ctype(vforml,c))
                   1108:                {
                   1109:                case 'n':
                   1110:                case 'a':
                   1111:                        if (table[ldata][c].rcol)
                   1112:                          if (lused[c]) /*Zero field width*/
                   1113:                                fprintf(tabout, "\\n(%2su ",reg(c,CMID));
                   1114:                case 'c':
                   1115:                case 'l':
                   1116:                case 'r':
                   1117:                    if (realsplit? rused[c]: (used[c]+lused[c]))
                   1118:                        fprintf(tabout, "\\n(%2su ",reg(c,CRIGHT));
                   1119:                        continue;
                   1120:                case 's':
                   1121:                        if (lspan(lform, c))
                   1122:                                fprintf(tabout, "\\n(%2su ", reg(c,CRIGHT));
                   1123:                        continue;
                   1124:                }
                   1125:        }
                   1126: fprintf(tabout, "\n");
                   1127: }
                   1128: ifline(s)
                   1129:        char *s;
                   1130: {
                   1131: if (!point(s)) return(0);
                   1132: if (s[0] == '\\') s++;
                   1133: if (s[1] ) return(0);
                   1134: if (s[0] == '_') return('-');
                   1135: if (s[0] == '=') return('=');
                   1136: return(0);
                   1137: }
                   1138: need()
                   1139: {
                   1140: int texlin, horlin, i;
                   1141: for(texlin=horlin=i=0; i<nlin; i++)
                   1142:        {
                   1143:        if (fullbot[i]!=0)
                   1144:                horlin++;
                   1145:        else
                   1146:        if (instead[i]!=0)
                   1147:                continue;
                   1148:        else
                   1149:                texlin++;
                   1150:        }
                   1151: fprintf(tabout, ".ne %dv+%dp\n",texlin,2*horlin);
                   1152: }
                   1153: deftail()
                   1154: {
                   1155: int i, c, lf, lwid;
                   1156: for(i=0; i<MAXHEAD; i++)
                   1157:        if (linestop[i])
                   1158:                fprintf(tabout, ".nr #%c 0-1\n", linestop[i]+'a'-1);
                   1159: fprintf(tabout, ".nr #a 0-1\n");
                   1160: fprintf(tabout, ".eo\n");
                   1161: fprintf(tabout, ".de T#\n");
                   1162: fprintf(tabout, ".nr 35 1m\n");
                   1163: fprintf(tabout, ".ds #d .d\n");
                   1164: fprintf(tabout, ".if \\(ts\\n(.z\\(ts\\(ts .ds #d nl\n");
                   1165:        fprintf(tabout, ".mk ##\n");
                   1166:        fprintf(tabout, ".nr ## -1v\n");
                   1167:        fprintf(tabout, ".ls 1\n");
                   1168:        for(i=0; i<MAXHEAD; i++)
                   1169:                if (linestop[i])
                   1170:                        fprintf(tabout, ".if \\n(#T>=0 .nr #%c \\n(#T\n",linestop[i]+'a'-1);
                   1171: if (boxflg || allflg || dboxflg) /* bottom of table line */
                   1172:        if (fullbot[nlin-1]==0)
                   1173:                {
                   1174:                if (!pr1403)
                   1175:                        fprintf(tabout, ".if \\n(T. .vs \\n(.vu-\\n(.sp\n");
                   1176:                fprintf(tabout, ".if \\n(T. ");
                   1177:                drawline(nlin,0,ncol, dboxflg ? '=' : '-',1,0);
                   1178:                fprintf(tabout, "\n.if \\n(T. .vs\n");
                   1179:                /* T. is really an argument to a macro but because of 
                   1180:                   eqn we don't dare pass it as an argument and reference by $1 */
                   1181:                }
                   1182:        for(c=0; c<ncol; c++)
                   1183:                {
                   1184:                if ((lf=left(nlin-1,c, &lwid))>=0)
                   1185:                        {
                   1186:                        fprintf(tabout, ".if \\n(#%c>=0 .sp -1\n",linestop[lf]+'a'-1);
                   1187:                        fprintf(tabout, ".if \\n(#%c>=0 ", linestop[lf]+'a'-1);
                   1188:                        tohcol(c);
                   1189:                        drawvert(lf, nlin-1, c, lwid);
                   1190:                        fprintf(tabout, "\\h'|\\n(TWu'\n");
                   1191:                        }
                   1192:                }
                   1193:        if (boxflg || allflg || dboxflg) /* right hand line */
                   1194:                {
                   1195:                fprintf(tabout, ".if \\n(#a>=0 .sp -1\n");
                   1196:                fprintf(tabout, ".if \\n(#a>=0 \\h'|\\n(TWu'");
                   1197:                drawvert (0, nlin-1, ncol, dboxflg? 2 : 1);
                   1198:                fprintf(tabout, "\n");
                   1199:                }
                   1200: fprintf(tabout, ".ls\n");
                   1201: fprintf(tabout, "..\n");
                   1202: fprintf(tabout, ".ec\n");
                   1203: }
                   1204: 0707070035051115061006660000030000040000010245710406576507100000500000017553t8.c /* t8.c: write out one line of output table */
                   1205: # include "t..c"
                   1206: # define realsplit ((ct=='a'||ct=='n') && table[nl][c].rcol)
                   1207: int watchout;
                   1208: int once;
                   1209: putline(i, nl)
                   1210:        /* i is line number for deciding format */
                   1211:        /* nl is line number for finding data   usually identical */
                   1212: {
                   1213: int c, lf, ct, form, lwid, vspf, ip, cmidx, exvspen, vforml;
                   1214: int vct, chfont, uphalf;
                   1215: char *s, *size, *fn;
                   1216: cmidx=watchout=vspf=exvspen=0;
                   1217: if (i==0) once=0;
                   1218: if (i==0 && ( allflg || boxflg || dboxflg))
                   1219:        fullwide(0,   dboxflg? '=' : '-');
                   1220: if (instead[nl]==0 && fullbot[nl] ==0)
                   1221: for(c=0; c<ncol; c++)
                   1222:        {
                   1223:        s = table[nl][c].col;
                   1224:        if (s==0) continue;
                   1225:        if (vspen(s))
                   1226:                {
                   1227:                for(ip=nl; ip<nlin; ip=next(ip))
                   1228:                        if (!vspen(s=table[ip][c].col)) break;
                   1229:                if ((int)s>0 && (int)s<128)
                   1230:                fprintf(tabout, ".ne \\n(%c|u+\\n(.Vu\n",s);
                   1231:                continue;
                   1232:                }
                   1233:        if (point(s)) continue;
                   1234:        fprintf(tabout, ".ne \\n(%c|u+\\n(.Vu\n",s);
                   1235:        watchout=1;
                   1236:        }
                   1237: if (linestop[nl])
                   1238:        fprintf(tabout, ".mk #%c\n", linestop[nl]+'a'-1);
                   1239: lf = prev(nl);
                   1240: if (instead[nl])
                   1241:        {
                   1242:        puts(instead[nl]);
                   1243:        return;
                   1244:        }
                   1245: if (fullbot[nl])
                   1246:        {
                   1247:        switch (ct=fullbot[nl])
                   1248:                {
                   1249:                case '=':
                   1250:                case '-':
                   1251:                        fullwide(nl,ct);
                   1252:                }
                   1253:        return;
                   1254:        }
                   1255: for(c=0; c<ncol; c++)
                   1256:        {
                   1257:        if (instead[nl]==0 && fullbot[nl]==0)
                   1258:        if (vspen(table[nl][c].col)) vspf=1;
                   1259:        if (lf>=0)
                   1260:                if (vspen(table[lf][c].col)) vspf=1;
                   1261:        }
                   1262: if (vspf)
                   1263:        {
                   1264:        fprintf(tabout, ".nr #^ \\n(\\*(#du\n");
                   1265:        fprintf(tabout, ".nr #- \\n(#^\n"); /* current line position relative to bottom */
                   1266:        }
                   1267: vspf=0;
                   1268: chfont=0;
                   1269: for(c=0; c<ncol; c++)
                   1270:        {
                   1271:        s = table[nl][c].col;
                   1272:        if (s==0) continue;
                   1273:        chfont |= (int)(font[c][stynum[nl]]);
                   1274:        if (point(s) ) continue;
                   1275:        lf=prev(nl);
                   1276:        if (lf>=0 && vspen(table[lf][c].col))
                   1277:                fprintf(tabout, ".if (\\n(%c|+\\n(^%c-1v)>\\n(#- .nr #- +(\\n(%c|+\\n(^%c-\\n(#--1v)\n",s,'a'+c,s,'a'+c);
                   1278:        else
                   1279:                fprintf(tabout, ".if (\\n(%c|+\\n(#^-1v)>\\n(#- .nr #- +(\\n(%c|+\\n(#^-\\n(#--1v)\n",s,s);
                   1280:        }
                   1281: if (allflg && once>0 )
                   1282:        fullwide(i,'-');
                   1283: once=1;
                   1284: runtabs(i, nl);
                   1285: if (allh(i) && !pr1403)
                   1286:        {
                   1287:        fprintf(tabout, ".nr %d \\n(.v\n", SVS);
                   1288:        fprintf(tabout, ".vs \\n(.vu-\\n(.sp\n");
                   1289:        fprintf(tabout, ".nr 35 \\n(.vu\n");
                   1290:        }
                   1291: else
                   1292:        fprintf(tabout, ".nr 35 1m\n");
                   1293: if (chfont)
                   1294:        fprintf(tabout, ".nr %2d \\n(.f\n", S1);
                   1295: fprintf(tabout, "\\&");
                   1296: vct = 0;
                   1297: for(c=0; c<ncol; c++)
                   1298:        {
                   1299:        uphalf=0;
                   1300:        if (watchout==0 && i+1<nlin && (lf=left(i,c, &lwid))>=0)
                   1301:                {
                   1302:                tohcol(c);
                   1303:                drawvert(lf, i, c, lwid);
                   1304:                vct += 2;
                   1305:                }
                   1306:        if (rightl && c+1==ncol) continue;
                   1307:        vforml=i;
                   1308:        for(lf=prev(nl); lf>=0 && vspen(table[lf][c].col); lf=prev(lf))
                   1309:                vforml= lf;
                   1310:        form= ctype(vforml,c);
                   1311:        if (form != 's')
                   1312:                {
                   1313:                ct = reg(c,CLEFT);
                   1314:                if (form=='a') ct = reg(c,CMID);
                   1315:                if (form=='n' && table[nl][c].rcol && lused[c]==0) ct= reg(c,CMID);
                   1316:                fprintf(tabout, "\\h'|\\n(%2su'", ct);
                   1317:                }
                   1318:        s= table[nl][c].col;
                   1319:        fn = font[c][stynum[vforml]];
                   1320:        size = csize[c][stynum[vforml]];
                   1321:        if (*size==0)size=0;
                   1322:        if ((flags[c][stynum[nl]] & HALFUP)!=0 && pr1403 == 0)
                   1323:                uphalf=1;
                   1324:        switch(ct=ctype(vforml, c))
                   1325:                {
                   1326:                case 'n':
                   1327:                case 'a':
                   1328:                        if (table[nl][c].rcol)
                   1329:                                {
                   1330:                           if (lused[c]) /*Zero field width*/
                   1331:                                {
                   1332:                                ip = prev(nl);
                   1333:                                if (ip>=0)
                   1334:                                if (vspen(table[ip][c].col))
                   1335:                                        {
                   1336:                                        if (exvspen==0)
                   1337:                                                {
                   1338:                                                fprintf(tabout, "\\v'-(\\n(\\*(#du-\\n(^%cu", c+'a');
                   1339:                                                if (cmidx)
                   1340:                                                        fprintf(tabout, "-((\\n(#-u-\\n(^%cu)/2u)", c+'a');
                   1341:                                                vct++;
                   1342:                                                if (pr1403) /* must round to whole lines */
                   1343:                                                        fprintf(tabout, "/1v*1v");
                   1344:                                                fprintf(tabout, "'");
                   1345:                                                exvspen=1;
                   1346:                                                }
                   1347:                                        }
                   1348:                                fprintf(tabout, "%c%c",F1,F2);
                   1349:                                if (uphalf) fprintf(tabout, "\\u");
                   1350:                                puttext(s,fn,size);
                   1351:                                if (uphalf) fprintf(tabout, "\\d");
                   1352:                                fprintf(tabout, "%c",F1);
                   1353:                                }
                   1354:                                s= table[nl][c].rcol;
                   1355:                                form=1;
                   1356:                                break;
                   1357:                                }
                   1358:                case 'c':
                   1359:                        form=3; break;
                   1360:                case 'r':
                   1361:                        form=2; break;
                   1362:                case 'l':
                   1363:                        form=1; break;
                   1364:                case '-':
                   1365:                case '=':
                   1366:                        if (real(table[nl][c].col))
                   1367:                                fprintf(stderr,"%s: line %d: Data ignored on table line %d\n", ifile, iline-1, i+1);
                   1368:                        makeline(i,c,ct);
                   1369:                        continue;
                   1370:                default:
                   1371:                        continue;
                   1372:                }
                   1373:        if (realsplit ? rused[c]: used[c]) /*Zero field width*/
                   1374:                {
                   1375:                /* form: 1 left, 2 right, 3 center adjust */
                   1376:                if (ifline(s))
                   1377:                        {
                   1378:                        makeline(i,c,ifline(s));
                   1379:                        continue;
                   1380:                        }
                   1381:                if (filler(s))
                   1382:                        {
                   1383:                        fprintf(tabout, "\\l'|\\n(%2su\\&%s'", reg(c,CRIGHT), s+2);
                   1384:                        continue;
                   1385:                        }
                   1386:                ip = prev(nl);
                   1387:                cmidx = (flags[c][stynum[nl]] & (CTOP|CDOWN))==0;
                   1388:                if (ip>=0)
                   1389:                if (vspen(table[ip][c].col))
                   1390:                        {
                   1391:                        if (exvspen==0)
                   1392:                                {
                   1393:                                fprintf(tabout, "\\v'-(\\n(\\*(#du-\\n(^%cu", c+'a');
                   1394:                                if (cmidx)
                   1395:                                        fprintf(tabout, "-((\\n(#-u-\\n(^%cu)/2u)", c+'a');
                   1396:                                vct++;
                   1397:                                if (pr1403) /* round to whole lines */
                   1398:                                        fprintf(tabout, "/1v*1v");
                   1399:                                fprintf(tabout, "'");
                   1400:                                }
                   1401:                        }
                   1402:                fprintf(tabout, "%c", F1);
                   1403:                if (form!= 1)
                   1404:                        fprintf(tabout, "%c", F2);
                   1405:                if (vspen(s))
                   1406:                        vspf=1;
                   1407:                else
                   1408:                {
                   1409:                if (uphalf) fprintf(tabout, "\\u");
                   1410:                puttext(s, fn, size);
                   1411:                if (uphalf) fprintf(tabout, "\\d");
                   1412:                }
                   1413:                if (form !=2)
                   1414:                        fprintf(tabout, "%c", F2);
                   1415:                fprintf(tabout, "%c", F1);
                   1416:                }
                   1417:        ip = prev(nl);
                   1418:        if (ip>=0)
                   1419:        if (vspen(table[ip][c].col))
                   1420:                {
                   1421:                exvspen = (c+1 < ncol) && vspen(table[ip][c+1].col) &&
                   1422:                        (topat[c] == topat[c+1]) &&
                   1423:                        (cmidx == (flags[c+1] [stynum[nl]]&(CTOP|CDOWN)==0)) && (left(i,c+1,&lwid)<0);
                   1424:                if (exvspen==0)
                   1425:                        {
                   1426:                        fprintf(tabout, "\\v'(\\n(\\*(#du-\\n(^%cu", c+'a');
                   1427:                        if (cmidx)
                   1428:                                fprintf(tabout, "-((\\n(#-u-\\n(^%cu)/2u)", c+'a');
                   1429:                        vct++;
                   1430:                        if (pr1403) /* round to whole lines */
                   1431:                                fprintf(tabout, "/1v*1v");
                   1432:                        fprintf(tabout, "'");
                   1433:                        }
                   1434:                }
                   1435:        else
                   1436:                exvspen=0;
                   1437:        /* if lines need to be split for gcos here is the place for a backslash */
                   1438:        if (vct > 7 && c < ncol)
                   1439:                {
                   1440:                fprintf(tabout, "\n.sp-1\n\\&");
                   1441:                vct=0;
                   1442:                }
                   1443:        }
                   1444: fprintf(tabout, "\n");
                   1445: if (allh(i) && !pr1403) fprintf(tabout, ".vs \\n(%du\n", SVS);
                   1446: if (watchout)
                   1447:        funnies(i,nl);
                   1448: if (vspf)
                   1449:        {
                   1450:        for(c=0; c<ncol; c++)
                   1451:                if (vspen(table[nl][c].col) && (nl==0 || (lf=prev(nl))<0 || !vspen(table[lf][c].col)))
                   1452:                        {
                   1453:                        fprintf(tabout, ".nr ^%c \\n(#^u\n", 'a'+c);
                   1454:                        topat[c]=nl;
                   1455:                        }
                   1456:        }
                   1457: }
                   1458: puttext(s,fn, size)
                   1459:        char *s, *size, *fn;
                   1460: {
                   1461: if (point(s))
                   1462:        {
                   1463:        putfont(fn);
                   1464:        putsize(size);
                   1465:        fprintf(tabout, "%s",s);
                   1466:        if (*fn>0) fprintf(tabout, "\\f\\n(%2d", S1);
                   1467:        if (size!=0) putsize("0");
                   1468:        }
                   1469: }
                   1470: funnies( stl, lin)
                   1471: {
                   1472: /* write out funny diverted things */
                   1473: int c, s, pl, lwid, dv, lf, ct;
                   1474: char *fn;
                   1475: fprintf(tabout, ".mk ##\n"); /* rmember current vertical position */
                   1476: fprintf(tabout, ".nr %d \\n(##\n", S1); /* bottom position */
                   1477: for(c=0; c<ncol; c++)
                   1478:        {
                   1479:        s = (int)table[lin][c].col;
                   1480:        if (point(s)) continue;
                   1481:        if (s==0) continue;
                   1482:        fprintf(tabout, ".sp |\\n(##u-1v\n");
                   1483:        fprintf(tabout, ".nr %d ", SIND);
                   1484:        for(pl=stl; pl>=0 && !isalpha(ct=ctype(pl,c)); pl=prev(pl))
                   1485:                ;
                   1486:        switch (ct)
                   1487:                {
                   1488:                case 'n':
                   1489:                case 'c':
                   1490:                        fprintf(tabout, "(\\n(%2su+\\n(%2su-\\n(%c-u)/2u\n",reg(c,CLEFT),reg(c-1+ctspan(lin,c),CRIGHT), s);
                   1491:                        break;
                   1492:                case 'l':
                   1493:                        fprintf(tabout, "\\n(%2su\n",reg(c,CLEFT));
                   1494:                        break;
                   1495:                case 'a':
                   1496:                        fprintf(tabout, "\\n(%2su\n",reg(c,CMID));
                   1497:                        break;
                   1498:                case 'r':
                   1499:                        fprintf(tabout, "\\n(%2su-\\n(%c-u\n", reg(c,CRIGHT), s);
                   1500:                        break;
                   1501:                }
                   1502:        fprintf(tabout, ".in +\\n(%du\n", SIND);
                   1503:        fn=font[c][stynum[stl]];
                   1504:        putfont(fn);
                   1505:        pl = prev(stl);
                   1506:        if (stl>0 && pl>=0 && vspen(table[pl][c].col))
                   1507:                {
                   1508:                fprintf(tabout, ".sp |\\n(^%cu\n", 'a'+c);
                   1509:                if ((flags[c][stynum[stl]]&(CTOP|CDOWN))==0)
                   1510:                        {
                   1511:                        fprintf(tabout, ".nr %d \\n(#-u-\\n(^%c-\\n(%c|+1v\n",TMP, 'a'+c, s);
                   1512:                        fprintf(tabout, ".if \\n(%d>0 .sp \\n(%du/2u", TMP, TMP);
                   1513:                        if (pr1403) /* round */
                   1514:                                fprintf(tabout, "/1v*1v");
                   1515:                        fprintf(tabout, "\n");
                   1516:                        }
                   1517:                }
                   1518:        fprintf(tabout, ".%c+\n",s);
                   1519:        fprintf(tabout, ".in -\\n(%du\n", SIND);
                   1520:        if (*fn>0) putfont("P");
                   1521:        fprintf(tabout, ".mk %d\n", S2);
                   1522:        fprintf(tabout, ".if \\n(%d>\\n(%d .nr %d \\n(%d\n", S2, S1, S1, S2);
                   1523:        }
                   1524: fprintf(tabout, ".sp |\\n(%du\n", S1);
                   1525: for(c=dv=0; c<ncol; c++)
                   1526:        {
                   1527:        if (stl+1< nlin && (lf=left(stl,c,&lwid))>=0)
                   1528:                {
                   1529:                if (dv++ == 0)
                   1530:                        fprintf(tabout, ".sp -1\n");
                   1531:                tohcol(c);
                   1532:                dv++;
                   1533:                drawvert(lf, stl, c, lwid);
                   1534:                }
                   1535:        }
                   1536: if (dv)
                   1537:        fprintf(tabout,"\n");
                   1538: }
                   1539: putfont(fn)
                   1540:        char *fn;
                   1541: {
                   1542: if (fn && *fn)
                   1543:        fprintf(tabout,  fn[1] ? "\\f(%.2s" : "\\f%.2s",  fn);
                   1544: }
                   1545: putsize(s)
                   1546:        char *s;
                   1547: {
                   1548: if (s && *s)
                   1549:        fprintf(tabout, "\\s%s",s);
                   1550: }
                   1551: 0707070035051115051006640000030000040000010207610474064475300000500000002656t9.c /* t9.c: write lines for tables over 200 lines */
                   1552: # include "t..c"
                   1553: static useln;
                   1554: extern char *maknew();
                   1555: yetmore()
                   1556: {
                   1557: for(useln=0; useln<MAXLIN && table[useln]==0; useln++);
                   1558: if (useln>=MAXLIN)
                   1559:        error("Wierd.  No data in table.");
                   1560: table[0]=table[useln];
                   1561: for(useln=nlin-1; useln>=0 && (fullbot[useln] || instead[useln]); useln--);
                   1562: if (useln<0)
                   1563:        error("Wierd.  No real lines in table.");
                   1564: domore(leftover);
                   1565: while (gets1(cstore=cspace, MAXCHS) && domore(cstore))
                   1566:        ;
                   1567: last =cstore;
                   1568: return;
                   1569: }
                   1570: domore(dataln)
                   1571:        char *dataln;
                   1572: {
                   1573:        int icol, ch;
                   1574: if (prefix(".TE", dataln))
                   1575:        return(0);
                   1576: if (dataln[0] == '.' && !isdigit(dataln[1]))
                   1577:        {
                   1578:        puts(dataln);
                   1579:        return(1);
                   1580:        }
                   1581: fullbot[0]=0;
                   1582: instead[0]=(char *)0;
                   1583: if (dataln[1]==0)
                   1584: switch(dataln[0])
                   1585:        {
                   1586:        case '_': fullbot[0]= '-'; putline(useln,0);  return(1);
                   1587:        case '=': fullbot[0]= '='; putline(useln, 0); return(1);
                   1588:        }
                   1589: for (icol = 0; icol <ncol; icol++)
                   1590:        {
                   1591:        table[0][icol].col = dataln;
                   1592:        table[0][icol].rcol=0;
                   1593:        for(; (ch= *dataln) != '\0' && ch != tab; dataln++)
                   1594:                        ;
                   1595:        *dataln++ = '\0';
                   1596:        switch(ctype(useln,icol))
                   1597:                {
                   1598:                case 'n':
                   1599:                        table[0][icol].rcol = maknew(table[0][icol].col);
                   1600:                        break;
                   1601:                case 'a':
                   1602:                        table[0][icol].rcol = table[0][icol].col;
                   1603:                        table[0][icol].col= "";
                   1604:                        break;
                   1605:                }
                   1606:        while (ctype(useln,icol+1)== 's') /* spanning */
                   1607:                table[0][++icol].col = "";
                   1608:        if (ch == '\0') break;
                   1609:        }
                   1610: while (++icol <ncol)
                   1611:        table[0][icol].col = "";
                   1612: putline(useln,0);
                   1613: exstore=exspace; /* reuse space for numerical items */
                   1614: return(1);
                   1615: }
                   1616: 0707070035051115041006640000030000040000010207630474064504300000500000003071tb.c /* tb.c: check which entries exist, also storage allocation */
                   1617: # include "t..c"
                   1618: checkuse()
                   1619: {
                   1620: int i,c, k;
                   1621: for(c=0; c<ncol; c++)
                   1622:        {
                   1623:        used[c]=lused[c]=rused[c]=0;
                   1624:        for(i=0; i<nlin; i++)
                   1625:                {
                   1626:                if (instead[i] || fullbot[i]) continue;
                   1627:                k = ctype(i,c);
                   1628:                if (k== '-' || k == '=') continue;
                   1629:                if ((k=='n'||k=='a'))
                   1630:                        {
                   1631:                        rused[c]|= real(table[i][c].rcol);
                   1632:                        if( !real(table[i][c].rcol))
                   1633:                        used[c] |= real(table[i][c].col);
                   1634:                        if (table[i][c].rcol)
                   1635:                        lused[c] |= real(table[i][c].col);
                   1636:                        }
                   1637:                else
                   1638:                        used[c] |= real(table[i][c].col);
                   1639:                }
                   1640:        }
                   1641: }
                   1642: real(s)
                   1643:        char *s;
                   1644: {
                   1645: if (s==0) return(0);
                   1646: if (!point(s)) return(1);
                   1647: if (*s==0) return(0);
                   1648: return(1);
                   1649: }
                   1650: int spcount = 0;
                   1651: extern char * calloc();
                   1652: # define MAXVEC 20
                   1653: char *spvecs[MAXVEC];
                   1654: char *chspace()
                   1655: {
                   1656: char *pp;
                   1657: if (spvecs[spcount])
                   1658:        return(spvecs[spcount++]);
                   1659: if (spcount>=MAXVEC)
                   1660:        error("Too many characters in table");
                   1661: spvecs[spcount++]= pp = calloc(MAXCHS+MAXLINLEN,1);
                   1662: if (pp== (char *)-1 || pp == (char *)0)
                   1663:        error("no space for characters");
                   1664: return(pp);
                   1665: }
                   1666: # define MAXPC 50
                   1667: char *thisvec;
                   1668: int tpcount = -1;
                   1669: char *tpvecs[MAXPC];
                   1670: int *alocv(n)
                   1671: int n;
                   1672: {
                   1673: int *tp, *q;
                   1674: if (tpcount<0 || thisvec+n > tpvecs[tpcount]+MAXCHS)
                   1675:        {
                   1676:        tpcount++;
                   1677:        if (tpvecs[tpcount]==0)
                   1678:                {
                   1679:                tpvecs[tpcount] = calloc(MAXCHS,1);
                   1680:                }
                   1681:        thisvec = tpvecs[tpcount];
                   1682:        if (thisvec == (char *)0)
                   1683:                error("no space for vectors");
                   1684:        }
                   1685: tp=(int *)thisvec;
                   1686: thisvec+=n;
                   1687: for(q=tp; q<(int *)thisvec; q++)
                   1688:        *q=0;
                   1689: return(tp);
                   1690: }
                   1691: release()
                   1692: {
                   1693: /* give back unwanted space in some vectors */
                   1694: /* this should call free; it does not because
                   1695: alloc() is so buggy */
                   1696: spcount=0;
                   1697: tpcount= -1;
                   1698: exstore=0;
                   1699: }
                   1700: 0707070035051115031006640000030000040000010245750265271264600000500000002130tc.c /* tc.c: find character not in table to delimit fields */
                   1701: # include "t..c"
                   1702: choochar()
                   1703: {
                   1704: /* choose funny characters to delimit fields */
                   1705: int had[128], ilin,icol, k;
                   1706: char *s;
                   1707: for(icol=0; icol<128; icol++)
                   1708:        had[icol]=0;
                   1709: F1 = F2 = 0;
                   1710: for(ilin=0;ilin<nlin;ilin++)
                   1711:        {
                   1712:        if (instead[ilin]) continue;
                   1713:        if (fullbot[ilin]) continue;
                   1714:        for(icol=0; icol<ncol; icol++)
                   1715:                {
                   1716:                k = ctype(ilin, icol);
                   1717:                if (k==0 || k == '-' || k == '=')
                   1718:                        continue;
                   1719:                s = table[ilin][icol].col;
                   1720:                if (point(s))
                   1721:                while (*s)
                   1722:                        had[*s++]=1;
                   1723:                s=table[ilin][icol].rcol;
                   1724:                if (point(s))
                   1725:                while (*s)
                   1726:                        had[*s++]=1;
                   1727:                }
                   1728:        }
                   1729: /* choose first funny character */
                   1730: for(
                   1731:        s="\002\003\005\006\007!%&#/?,:;<=>@`^~_{}+-*ABCDEFGHIJKMNOPQRSTUVWXYZabcdefgjkoqrstwxyz";
                   1732:                *s; s++)
                   1733:        {
                   1734:        if (had[*s]==0)
                   1735:                {
                   1736:                F1= *s;
                   1737:                had[F1]=1;
                   1738:                break;
                   1739:                }
                   1740:        }
                   1741: /* choose second funny character */
                   1742: for(
                   1743:        s="\002\003\005\006\007:_~^`@;,<=>#%&!/?{}+-*ABCDEFGHIJKMNOPQRSTUVWXZabcdefgjkoqrstuwxyz";
                   1744:                *s; s++)
                   1745:        {
                   1746:        if (had[*s]==0)
                   1747:                {
                   1748:                F2= *s;
                   1749:                break;
                   1750:                }
                   1751:        }
                   1752: if (F1==0 || F2==0)
                   1753:        error("couldn't find characters to use for delimiters");
                   1754: return;
                   1755: }
                   1756: point(s)
                   1757: {
                   1758: return(s>= 128 || s<0);
                   1759: }
                   1760: 0707070035051115021006640000030000040000011516550474434145100000500000002144te.c /* te.c: error message control, input line count */
                   1761: # include "t..c"
                   1762: error(s)
                   1763:        char *s;
                   1764: {
                   1765: fprintf(stderr, "\n%s: line %d: %s\n", ifile, iline, s);
                   1766: # ifdef unix
                   1767: fprintf(stderr, "tbl quits\n");
                   1768: exit(1);
                   1769: # endif
                   1770: # ifdef gcos
                   1771: fprintf(stderr, "run terminated due to error condition detected by tbl preprocessor\n");
                   1772: exit(0);
                   1773: # endif
                   1774: }
                   1775: char *gets1(s, size)
                   1776:        char *s;
                   1777:        int size;
                   1778: {
                   1779: char *p, *ns;
                   1780: int nbl = 0;
                   1781: iline++;
                   1782: ns = s;
                   1783: p=fgets(s,size,tabin);
                   1784: while (p==0)
                   1785:        {
                   1786:        if (swapin()==0)
                   1787:                return(0);
                   1788:        p = fgets(s,size,tabin);
                   1789:        }
                   1790: 
                   1791: while (*s) s++;
                   1792: s--;
                   1793: if (*s == '\n') *s-- =0;
                   1794: else error("input buffer too small");
                   1795: for(nbl=0; *s == '\\' && s>p; s--)
                   1796:        nbl++;
                   1797: if (linstart && nbl % 2) /* fold escaped nl if in table */
                   1798:        gets1(s+1, size - (s-ns));
                   1799: 
                   1800: return(p);
                   1801: }
                   1802: # define BACKMAX 500
                   1803: char backup[BACKMAX];
                   1804: char *backp = backup;
                   1805: un1getc(c)
                   1806: {
                   1807: if (c=='\n')
                   1808:        iline--;
                   1809: *backp++ = c;
                   1810: if (backp >= backup+BACKMAX)
                   1811:        error("too much backup");
                   1812: }
                   1813: get1char()
                   1814: {
                   1815: int c;
                   1816: if (backp>backup)
                   1817:        c = *--backp;
                   1818: else
                   1819:        c=getc(tabin);
                   1820: if (c== EOF) /* EOF */
                   1821:        {
                   1822:        if (swapin() ==0)
                   1823:                error("unexpected EOF");
                   1824:        c = getc(tabin);
                   1825:        }
                   1826: if (c== '\n')
                   1827:        iline++;
                   1828: return(c);
                   1829: }
                   1830: 0707070035051115011006640000030000040000010245770446267321300000500000002207tf.c /* tf.c: save and restore fill mode around table */
                   1831: # include "t..c"
                   1832: savefill()
                   1833: {
                   1834: /* remembers various things: fill mode, vs, ps in mac 35 (SF) */
                   1835: fprintf(tabout, ".de %d\n",SF);
                   1836: fprintf(tabout, ".ps \\n(.s\n");
                   1837: fprintf(tabout, ".vs \\n(.vu\n");
                   1838: fprintf(tabout, ".in \\n(.iu\n");
                   1839: fprintf(tabout, ".if \\n(.u .fi\n");
                   1840: fprintf(tabout, ".if \\n(.j .ad\n");
                   1841: fprintf(tabout, ".if \\n(.j=0 .na\n");
                   1842: fprintf(tabout, "..\n");
                   1843: fprintf(tabout, ".nf\n");
                   1844: /* set obx offset if useful */
                   1845: fprintf(tabout, ".nr #~ 0\n");
                   1846: fprintf(tabout, ".if \\n(.T .if n .nr #~ 0.6n\n");
                   1847: }
                   1848: rstofill()
                   1849: {
                   1850: fprintf(tabout, ".%d\n",SF);
                   1851: }
                   1852: endoff()
                   1853: {
                   1854: int i;
                   1855:        for(i=0; i<MAXHEAD; i++)
                   1856:                if (linestop[i])
                   1857:                        fprintf(tabout, ".nr #%c 0\n", linestop[i]+'a'-1);
                   1858:        for(i=0; i<texct; i++)
                   1859:                fprintf(tabout, ".rm %c+\n",texstr[i]);
                   1860: fprintf(tabout, "%s\n", last);
                   1861: }
                   1862: ifdivert()
                   1863: {
                   1864: fprintf(tabout, ".ds #d .d\n");
                   1865: fprintf(tabout, ".if \\(ts\\n(.z\\(ts\\(ts .ds #d nl\n");
                   1866: }
                   1867: saveline()
                   1868: {
                   1869: fprintf(tabout, ".if \\n+(b.=1 .nr d. \\n(.c-\\n(c.-1\n");
                   1870: linstart=iline;
                   1871: }
                   1872: restline()
                   1873: {
                   1874: fprintf(tabout,".if \\n-(b.=0 .nr c. \\n(.c-\\n(d.-%d\n", iline-linstart);
                   1875: linstart = 0;
                   1876: }
                   1877: cleanfc()
                   1878: {
                   1879: fprintf(tabout, ".fc\n");
                   1880: }
                   1881: 0707070035051113651006640000510000040000010247370474434102600000500000003570tg.c /* tg.c: process included text blocks */
                   1882: # include "t..c"
                   1883: gettext(sp, ilin,icol, fn, sz)
                   1884:        char *sp, *fn, *sz;
                   1885: {
                   1886: /* get a section of text */
                   1887: char line[4096];
                   1888: int oname;
                   1889: char *vs;
                   1890: if (texname==0) error("Too many text block diversions");
                   1891: if (textflg==0)
                   1892:        {
                   1893:        fprintf(tabout, ".nr %d \\n(.lu\n", SL); /* remember old line length */
                   1894:        textflg=1;
                   1895:        }
                   1896: fprintf(tabout, ".eo\n");
                   1897: fprintf(tabout, ".am %s\n", reg(icol,CRIGHT));
                   1898: fprintf(tabout, ".br\n");
                   1899: fprintf(tabout, ".di %c+\n", texname);
                   1900: rstofill();
                   1901: if (fn && *fn) fprintf(tabout, ".nr %d \\n(.f\n.ft %s\n", S1, fn);
                   1902: fprintf(tabout, ".ft \\n(.f\n"); /* protect font */
                   1903: vs = vsize[icol][stynum[ilin]];
                   1904: if ((sz && *sz) || (vs && *vs))
                   1905:        {
                   1906:        fprintf(tabout, ".nr %d \\n(.v\n", S9);
                   1907:        if (vs==0 || *vs==0) vs= "\\n(.s+2";
                   1908:        if (sz && *sz)
                   1909:                fprintf(tabout, ".ps %s\n",sz);
                   1910:        fprintf(tabout, ".vs %s\n",vs);
                   1911:        fprintf(tabout, ".if \\n(%du>\\n(.vu .sp \\n(%du-\\n(.vu\n", S9,S9);
                   1912:        }
                   1913: if (cll[icol][0])
                   1914:        fprintf(tabout, ".ll %sn\n", cll[icol]);
                   1915: else
                   1916:        fprintf(tabout, ".ll \\n(%du*%du/%du\n",SL,ctspan(ilin,icol),ncol+1);
                   1917: fprintf(tabout,".if \\n(.l<\\n(%2s .ll \\n(%2su\n", reg(icol,CRIGHT), reg(icol,CRIGHT));
                   1918: if (ctype(ilin,icol)=='a')
                   1919:        fprintf(tabout, ".ll -2n\n");
                   1920: fprintf(tabout, ".in 0\n");
                   1921: while (gets1(line, sizeof(line)))
                   1922:        {
                   1923:        if (line[0]=='T' && line[1]=='}' && line[2]== tab) break;
                   1924:        if (match("T}", line)) break;
                   1925:        fprintf(tabout, "%s\n", line);
                   1926:        }
                   1927: if (fn && *fn) fprintf(tabout, ".ft \\n(%d\n", S1);
                   1928: if (sz && *sz) fprintf(tabout, ".br\n.ps\n.vs\n");
                   1929: fprintf(tabout, ".br\n");
                   1930: fprintf(tabout, ".di\n");
                   1931: fprintf(tabout, ".nr %c| \\n(dn\n", texname);
                   1932: fprintf(tabout, ".nr %c- \\n(dl\n", texname);
                   1933: fprintf(tabout, "..\n");
                   1934: fprintf(tabout, ".ec \\\n");
                   1935: /* copy remainder of line */
                   1936: if (line[2])
                   1937:        tcopy (sp, line+3);
                   1938: else
                   1939:        *sp=0;
                   1940: oname=texname;
                   1941: texname = texstr[++texct];
                   1942: return(oname);
                   1943: }
                   1944: untext()
                   1945: {
                   1946: rstofill();
                   1947: fprintf(tabout, ".nf\n");
                   1948: fprintf(tabout, ".ll \\n(%du\n", SL);
                   1949: }
                   1950: 0707070035051114771006640000030000040000010246010265271266600000500000002004ti.c /* ti.c: classify line intersections */
                   1951: # include "t..c"
                   1952: /* determine local environment for intersections */
                   1953: interv(i,c)
                   1954: {
                   1955: int ku, kl;
                   1956: if (c>=ncol || c == 0)
                   1957:        {
                   1958:        if (dboxflg)
                   1959:                {
                   1960:                if (i==0) return(BOT);
                   1961:                if (i>=nlin) return(TOP);
                   1962:                return(THRU);
                   1963:                }
                   1964:        if (c>=ncol)
                   1965:                return(0);
                   1966:        }
                   1967: ku = i>0 ? lefdata(i-1,c) : 0;
                   1968: if (i+1 >= nlin && allh(i))
                   1969:        kl=0;
                   1970: else
                   1971: kl = lefdata(allh(i) ? i+1 : i, c);
                   1972: if (ku==2 && kl==2) return(THRU);
                   1973: if (ku ==2) return(TOP);
                   1974: if (kl==BOT) return(2);
                   1975: return(0);
                   1976: }
                   1977: interh(i,c)
                   1978: {
                   1979: int kl, kr;
                   1980: if (fullbot[i]== '=' || (dboxflg && (i==0 || i>= nlin-1)))
                   1981:        {
                   1982:        if (c==ncol)
                   1983:                return(LEFT);
                   1984:        if (c==0)
                   1985:                return(RIGHT);
                   1986:        return(THRU);
                   1987:        }
                   1988: if (i>=nlin) return(0);
                   1989: kl = c>0 ? thish (i,c-1) : 0;
                   1990: if (kl<=1 && i>0 && allh(up1(i)))
                   1991:        kl = c>0 ? thish(up1(i),c-1) : 0;
                   1992: kr = thish(i,c);
                   1993: if (kr<=1 && i>0 && allh(up1(i)))
                   1994:        kr = c>0 ? thish(up1(i), c) : 0;
                   1995: if (kl== '=' && kr ==  '=') return(THRU);
                   1996: if (kl== '=') return(LEFT);
                   1997: if (kr== '=') return(RIGHT);
                   1998: return(0);
                   1999: }
                   2000: up1(i)
                   2001: {
                   2002: i--;
                   2003: while (instead[i] && i>0) i--;
                   2004: return(i);
                   2005: }
                   2006: 0707070035051114761006640000030000040000010246020265271266600000500000002123tm.c /* tm.c: split numerical fields */
                   2007: # include "t..c"
                   2008: char *maknew(str)
                   2009:        char *str;
                   2010: {
                   2011:        /* make two numerical fields */
                   2012:        extern char *chspace();
                   2013:        int dpoint, c;
                   2014:        char *p, *q, *ba;
                   2015:        p = str;
                   2016:        for (ba= 0; c = *str; str++)
                   2017:                if (c == '\\' && *(str+1)== '&')
                   2018:                        ba=str;
                   2019:        str=p;
                   2020:        if (ba==0)
                   2021:                {
                   2022:                for (dpoint=0; *str; str++)
                   2023:                        {
                   2024:                        if (*str=='.' && !ineqn(str,p) &&
                   2025:                                (str>p && digit(*(str-1)) ||
                   2026:                                digit(*(str+1))))
                   2027:                                        dpoint=(int)str;
                   2028:                        }
                   2029:                if (dpoint==0)
                   2030:                        for(; str>p; str--)
                   2031:                        {
                   2032:                        if (digit( * (str-1) ) && !ineqn(str, p))
                   2033:                                break;
                   2034:                        }
                   2035:                if (!dpoint && p==str) /* not numerical, don't split */
                   2036:                        return(0);
                   2037:                if (dpoint) str=(char *)dpoint;
                   2038:                }
                   2039:        else
                   2040:                str = ba;
                   2041:        p =str;
                   2042:        if (exstore ==0 || exstore >exlim)
                   2043:                {
                   2044:                exstore = exspace = chspace();
                   2045:                exlim= exstore+MAXCHS;
                   2046:                }
                   2047:        q = exstore;
                   2048:        while (*exstore++ = *str++);
                   2049:        *p = 0;
                   2050:        return(q);
                   2051:        }
                   2052: ineqn (s, p)
                   2053:        char *s, *p;
                   2054: {
                   2055: /* true if s is in a eqn within p */
                   2056: int ineq = 0, c;
                   2057: while (c = *p)
                   2058:        {
                   2059:        if (s == p)
                   2060:                return(ineq);
                   2061:        p++;
                   2062:        if ((ineq == 0) && (c == delim1))
                   2063:                ineq = 1;
                   2064:        else
                   2065:        if ((ineq == 1) && (c == delim2))
                   2066:                ineq = 0;
                   2067:        }
                   2068: return(0);
                   2069: }
                   2070: 0707070035051114751006640000030000040000010246030265271266700000500000001554tr.c# include "t..c"
                   2071:  /* tr.c: number register allocation */
                   2072: char * nregs[] ={
                   2073:        /* this array must have at least 3*qcol entries
                   2074:           or illegal register names will result */
                   2075:        "40","41","42","43","44","45","46","47","48","49",
                   2076:        "50","51","52","53","54","55","56","57","58","59",
                   2077:        "60","61","62","63","64","65","66","67","68","69",
                   2078:        "70","71","72","73","74","75","76","77","78","79",
                   2079:        "80","81","82","83","84","85","86","87","88","89",
                   2080:        "90","91","92","93","94","95","96","97","4q","4r",
                   2081:        "4s","4t","4u","4v","4w","4x","4y","4z","4;","4.",
                   2082:        "4a","4b","4c","4d","4e","4f","4g","4h","4i","4j",
                   2083:        "4k","4l","4m","4n","4o","4p","5a","5b","5c","5d",
                   2084:        "5e","5f","5g","5h","5i","5j","5k","5l","5m","5n",
                   2085:        "5o","5p","5q","5r","5s","5t","5u","5v","5w","5x",
                   2086:        0};
                   2087: char *
                   2088: reg(col, place)
                   2089: {
                   2090: if(sizeof(nregs) < 2*3*qcol)
                   2091:        error("Too many columns for registers");
                   2092: return (nregs[qcol*place+col]);
                   2093: }
                   2094: 0707070035051114741006640000030000040000010246040265271266700000500000001243ts.c /* ts.c: minor string processing subroutines */
                   2095: match (s1, s2)
                   2096:        char *s1, *s2;
                   2097: {
                   2098:        while (*s1 == *s2)
                   2099:                if (*s1++ == '\0')
                   2100:                        return(1);
                   2101:                else
                   2102:                        s2++;
                   2103:        return(0);
                   2104: }
                   2105: prefix(small, big)
                   2106:        char *small, *big;
                   2107: {
                   2108: int c;
                   2109: while ((c= *small++) == *big++)
                   2110:        if (c==0) return(1);
                   2111: return(c==0);
                   2112: }
                   2113: letter (ch)
                   2114:        {
                   2115:        if (ch >= 'a' && ch <= 'z')
                   2116:                return(1);
                   2117:        if (ch >= 'A' && ch <= 'Z')
                   2118:                return(1);
                   2119:        return(0);
                   2120:        }
                   2121: numb(str)
                   2122:        char *str;
                   2123:        {
                   2124:        /* convert to integer */
                   2125:        int k;
                   2126:        for (k=0; *str >= '0' && *str <= '9'; str++)
                   2127:                k = k*10 + *str - '0';
                   2128:        return(k);
                   2129:        }
                   2130: digit(x)
                   2131:        {
                   2132:        return(x>= '0' && x<= '9');
                   2133:        }
                   2134: max(a,b)
                   2135: {
                   2136: return( a>b ? a : b);
                   2137: }
                   2138: tcopy (s,t)
                   2139:        char *s, *t;
                   2140: {
                   2141:        while (*s++ = *t++);
                   2142: }
                   2143: 0707070035051114731006640000030000040000010246050265271267000000500000002651tt.c /* tt.c: subroutines for drawing horizontal lines */
                   2144: # include "t..c"
                   2145: ctype(il, ic)
                   2146: {
                   2147: if (instead[il])
                   2148:        return(0);
                   2149: if (fullbot[il])
                   2150:        return(0);
                   2151: il = stynum[il];
                   2152: return(style[ic][il]);
                   2153: }
                   2154: min(a,b)
                   2155: {
                   2156: return(a<b ? a : b);
                   2157: }
                   2158: fspan(i,c)
                   2159: {
                   2160: c++;
                   2161: return(c<ncol && ctype(i,c)=='s');
                   2162: }
                   2163: lspan(i,c)
                   2164: {
                   2165: int k;
                   2166: if (ctype(i,c) != 's') return(0);
                   2167: c++;
                   2168: if (c < ncol && ctype(i,c)== 's') 
                   2169:        return(0);
                   2170: for(k=0; ctype(i,--c) == 's'; k++);
                   2171: return(k);
                   2172: }
                   2173: ctspan(i,c)
                   2174: {
                   2175: int k;
                   2176: c++;
                   2177: for(k=1; c<ncol && ctype(i,c)=='s'; k++)
                   2178:        c++;
                   2179: return(k);
                   2180: }
                   2181: tohcol(ic)
                   2182: {
                   2183:                        if (ic==0)
                   2184:                                fprintf(tabout, "\\h'|0'");
                   2185:                        else
                   2186:                                fprintf(tabout, "\\h'(|\\n(%2su+|\\n(%2su)/2u'", reg(ic,CLEFT), reg(ic-1,CRIGHT));
                   2187: }
                   2188: allh(i)
                   2189: {
                   2190: /* return true if every element in line i is horizontal */
                   2191: /* also at least one must be horizontl */
                   2192: int c, one, k;
                   2193: if (fullbot[i]) return(1);
                   2194: if (i>=nlin) return(dboxflg||boxflg);
                   2195: for(one=c=0; c<ncol; c++)
                   2196:        {
                   2197:        k = thish(i,c);
                   2198:        if (k==0) return(0);
                   2199:        if (k==1) continue;
                   2200:        one=1;
                   2201:        }
                   2202: return(one);
                   2203: }
                   2204: thish(i,c)
                   2205: {
                   2206:        int t;
                   2207:        char *s;
                   2208:        struct colstr *pc;
                   2209:        if (c<0)return(0);
                   2210:        if (i<0) return(0);
                   2211:        t = ctype(i,c);
                   2212:        if (t=='_' || t == '-')
                   2213:                return('-');
                   2214:        if (t=='=')return('=');
                   2215:        if (t=='^') return(1);
                   2216:        if (fullbot[i] )
                   2217:                return(fullbot[i]);
                   2218:        if (t=='s') return(thish(i,c-1));
                   2219:        if (t==0) return(1);
                   2220:        pc = &table[i][c];
                   2221:        s = (t=='a' ? pc->rcol : pc->col);
                   2222:        if (s==0 || (point(s) && *s==0))
                   2223:                return(1);
                   2224:        if (vspen(s)) return(1);
                   2225:        if (t=barent( s))
                   2226:                return(t);
                   2227:        return(0);
                   2228: }
                   2229: 0707070035051114721006640000030000040000010246060265271267000000500000010000tu.c /* tu.c: draws horizontal lines */
                   2230: # include "t..c"
                   2231: makeline(i,c,lintype)
                   2232: {
                   2233: int cr, type, shortl;
                   2234: type = thish(i,c);
                   2235: if (type==0) return;
                   2236: cr=c;
                   2237: shortl = (table[i][c].col[0]=='\\');
                   2238: if (c>0 && !shortl && thish(i,c-1) == type)return;
                   2239: if (shortl==0)
                   2240:        for(cr=c; cr < ncol && (ctype(i,cr)=='s'||type==thish(i,cr)); cr++);
                   2241: else
                   2242:        for(cr=c+1; cr<ncol && ctype(i,cr)=='s'; cr++);
                   2243: drawline(i, c, cr-1, lintype, 0, shortl);
                   2244: }
                   2245: fullwide(i, lintype)
                   2246: {
                   2247: int cr, cl;
                   2248: if (!pr1403)
                   2249:        fprintf(tabout, ".nr %d \\n(.v\n.vs \\n(.vu-\\n(.sp\n", SVS);
                   2250: cr= 0;
                   2251: while (cr<ncol)
                   2252:        {
                   2253:        cl=cr;
                   2254:        while (i>0 && vspand(prev(i),cl,1))
                   2255:                cl++;
                   2256:        for(cr=cl; cr<ncol; cr++)
                   2257:                if (i>0 && vspand(prev(i),cr,1))
                   2258:                        break;
                   2259:        if (cl<ncol)
                   2260:        drawline(i,cl,(cr<ncol?cr-1:cr),lintype,1,0);
                   2261:        }
                   2262: fprintf(tabout, "\n");
                   2263: if (!pr1403)
                   2264:        fprintf(tabout, ".vs \\n(%du\n", SVS);
                   2265: }
                   2266: 
                   2267: drawline(i, cl, cr, lintype, noheight, shortl)
                   2268: {
                   2269:        char *exhr, *exhl, *lnch;
                   2270:        int lcount, ln, linpos, oldpos, nodata;
                   2271: lcount=0;
                   2272: exhr=exhl= "";
                   2273: switch(lintype)
                   2274:        {
                   2275:        case '-': lcount=1;break;
                   2276:        case '=': lcount = pr1403? 1 : 2; break;
                   2277:        case SHORTLINE: lcount=1; break;
                   2278:        }
                   2279: if (lcount<=0) return;
                   2280: nodata = cr-cl>=ncol || noheight || allh(i);
                   2281:        if (!nodata)
                   2282:                fprintf(tabout, "\\v'-.5m'");
                   2283: for(ln=oldpos=0; ln<lcount; ln++)
                   2284:        {
                   2285:        linpos = 2*ln - lcount +1;
                   2286:        if (linpos != oldpos)
                   2287:                fprintf(tabout, "\\v'%dp'", linpos-oldpos);
                   2288:        oldpos=linpos;
                   2289:        if (shortl==0)
                   2290:        {
                   2291:        tohcol(cl);
                   2292:        if (lcount>1)
                   2293:                {
                   2294:                switch(interv(i,cl))
                   2295:                        {
                   2296:                        case TOP: exhl = ln==0 ? "1p" : "-1p"; break;
                   2297:                        case BOT: exhl = ln==1 ? "1p" : "-1p"; break;
                   2298:                        case THRU: exhl = "1p"; break;
                   2299:                        }
                   2300:                if (exhl[0])
                   2301:                fprintf(tabout, "\\h'%s'", exhl);
                   2302:                }
                   2303:        else if (lcount==1)
                   2304:                {
                   2305:                switch(interv(i,cl))
                   2306:                        {
                   2307:                        case TOP: case BOT: exhl = "-1p"; break;
                   2308:                        case THRU: exhl = "1p"; break;
                   2309:                        }
                   2310:                if (exhl[0])
                   2311:                fprintf(tabout, "\\h'%s'", exhl);
                   2312:                }
                   2313:        if (lcount>1)
                   2314:                {
                   2315:                switch(interv(i,cr+1))
                   2316:                        {
                   2317:                        case TOP: exhr = ln==0 ? "-1p" : "+1p"; break;
                   2318:                        case BOT: exhr = ln==1 ? "-1p" : "+1p"; break;
                   2319:                        case THRU: exhr = "-1p"; break;
                   2320:                        }
                   2321:                }
                   2322:        else if (lcount==1)
                   2323:                {
                   2324:                switch(interv(i,cr+1))
                   2325:                        {
                   2326:                        case TOP: case BOT: exhr = "+1p"; break;
                   2327:                        case THRU: exhr = "-1p"; break;
                   2328:                        }
                   2329:                }
                   2330:        }
                   2331:        else
                   2332:                fprintf(tabout, "\\h'|\\n(%2su'", reg(cl,CLEFT));
                   2333:        fprintf(tabout, "\\s\\n(%d",LSIZE);
                   2334:        if (linsize)
                   2335:                fprintf(tabout, "\\v'-\\n(%dp/6u'", LSIZE);
                   2336:        if (shortl)
                   2337:                fprintf(tabout, "\\l'|\\n(%2su'", reg(cr,CRIGHT));
                   2338:        else
                   2339:        {
                   2340:        lnch = "\\(ul";
                   2341:        if (pr1403)
                   2342:                lnch = lintype==2 ? "=" : "\\(ru";
                   2343:        if (cr+1>=ncol)
                   2344:                fprintf(tabout, "\\l'|\\n(TWu%s%s'", exhr,lnch);
                   2345:        else
                   2346:                fprintf(tabout, "\\l'(|\\n(%2su+|\\n(%2su)/2u%s%s'", reg(cr,CRIGHT),
                   2347:                        reg(cr+1,CLEFT), exhr, lnch);
                   2348:        }
                   2349:        if (linsize)
                   2350:                fprintf(tabout, "\\v'\\n(%dp/6u'", LSIZE);
                   2351:        fprintf(tabout, "\\s0");
                   2352:        }
                   2353: if (oldpos!=0)
                   2354:        fprintf(tabout, "\\v'%dp'", -oldpos);
                   2355: if (!nodata)
                   2356:        fprintf(tabout, "\\v'+.5m'");
                   2357: }
                   2358: getstop()
                   2359: {
                   2360: int i,c,k,junk, stopp;
                   2361: stopp=1;
                   2362: for(i=0; i<MAXLIN; i++)
                   2363:        linestop[i]=0;
                   2364: for(i=0; i<nlin; i++)
                   2365:        for(c=0; c<ncol; c++)
                   2366:                {
                   2367:                k = left(i,c,&junk);
                   2368:                if (k>=0 && linestop[k]==0)
                   2369:                        linestop[k]= ++stopp;
                   2370:                }
                   2371: if (boxflg || allflg || dboxflg)
                   2372:        linestop[0]=1;
                   2373: }
                   2374: left(i,c, lwidp)
                   2375:        int *lwidp;
                   2376: {
                   2377: int kind, li, lj;
                   2378:        /* returns -1 if no line to left */
                   2379:        /* returns number of line where it starts */
                   2380:        /* stores into lwid the kind of line */
                   2381: *lwidp=0;
                   2382: if (i<0) return(-1);
                   2383: kind = lefdata(i,c);
                   2384: if (kind==0) return(-1);
                   2385: if (i+1<nlin)
                   2386: if (lefdata(next(i),c)== kind) return(-1);
                   2387: while (i>=0 && lefdata(i,c)==kind)
                   2388:        i=prev(li=i);
                   2389: if (prev(li)== -1) li=0;
                   2390: *lwidp=kind;
                   2391: for(lj= i+1; lj<li; lj++)
                   2392:        if (instead[lj] && strcmp(instead[lj], ".TH")==0)
                   2393:                return(li);
                   2394: for(i= i+1; i<li; i++)
                   2395:        if (fullbot[i])
                   2396:                li=i;
                   2397: return(li);
                   2398: }
                   2399: lefdata(i,c)
                   2400: {
                   2401: int ck;
                   2402: if (i>=nlin) i=nlin-1;
                   2403: if (ctype(i,c) == 's')
                   2404:        {
                   2405:        for(ck=c; ctype(i,ck)=='s'; ck--);
                   2406:        if (thish(i,ck)==0)
                   2407:                return(0);
                   2408:        }
                   2409: i =stynum[i];
                   2410: i = lefline[c][i];
                   2411: if (i>0) return(i);
                   2412: if (dboxflg && c==0) return(2);
                   2413: if (allflg)return(1);
                   2414: if (boxflg && c==0) return(1);
                   2415: return(0);
                   2416: }
                   2417: next(i)
                   2418: {
                   2419: while (i+1 <nlin)
                   2420:        {
                   2421:        i++;
                   2422:        if (!fullbot[i] && !instead[i]) break;
                   2423:        }
                   2424: return(i);
                   2425: }
                   2426: prev(i)
                   2427: {
                   2428: while (--i >=0  && (fullbot[i] || instead[i]))
                   2429:        ;
                   2430: return(i);
                   2431: }
                   2432: 0707070035051114711006640000030000040000010246070265271267100000500000005512tv.c /* tv.c: draw vertical lines */
                   2433: # include "t..c"
                   2434: drawvert(start,end, c, lwid)
                   2435: {
                   2436: char *exb=0, *ext=0;
                   2437: int tp=0, sl, ln, pos, epb, ept, vm;
                   2438: end++;
                   2439: vm='v';
                   2440: /* note: nr 35 has value of 1m outside of linesize */
                   2441: while (instead[end]) end++;
                   2442: for(ln=0; ln<lwid; ln++)
                   2443:        {
                   2444:        epb=ept=0;
                   2445:        pos = 2*ln-lwid+1;
                   2446:        if (pos!=tp) fprintf(tabout, "\\h'%dp'", pos-tp);
                   2447:        tp = pos;
                   2448:        if (end<nlin)
                   2449:                {
                   2450:                if (fullbot[end]|| (!instead[end] && allh(end)))
                   2451:                        epb=2;
                   2452:                else
                   2453:                switch (midbar(end,c))
                   2454:                        {
                   2455:                        case '-':
                   2456:                        exb = "1v-.5m"; break;
                   2457:                        case '=':
                   2458:                        exb = "1v-.5m";
                   2459:                        epb = 1; break;
                   2460:                        }
                   2461:                }
                   2462:        if (lwid>1)
                   2463:        switch(interh(end, c))
                   2464:                {
                   2465:                case THRU: epb -= 1; break;
                   2466:                case RIGHT: epb += (ln==0 ? 1 : -1); break;
                   2467:                case LEFT: epb += (ln==1 ? 1 : -1); break;
                   2468:                }
                   2469:        if (lwid==1)
                   2470:        switch(interh(end,c))
                   2471:                {
                   2472:                case THRU: epb -= 1; break;
                   2473:                case RIGHT: case LEFT: epb += 1; break;
                   2474:                }
                   2475:        if (start>0)
                   2476:                {
                   2477:                sl = start-1;
                   2478:                while (sl>=0 && instead[sl]) sl--;
                   2479:                if (sl>=0 && (fullbot[sl] || allh(sl)))
                   2480:                        ept=0;
                   2481:                else
                   2482:                if (sl>=0)
                   2483:                switch(midbar(sl,c))
                   2484:                        {
                   2485:                        case '-':
                   2486:                        ext = ".5m"; break;
                   2487:                        case '=':
                   2488:                        ext= ".5m"; ept = -1; break;
                   2489:                        default:
                   2490:                                vm = 'm'; break;
                   2491:                        }
                   2492:                else
                   2493:                        ept = -4;
                   2494:                }
                   2495:        else if (start==0 && allh(0))
                   2496:                {
                   2497:                ept=0;
                   2498:                vm = 'm';
                   2499:                }
                   2500:        if (lwid>1)
                   2501:                switch(interh(start,c))
                   2502:                        {
                   2503:                        case THRU: ept += 1; break;
                   2504:                        case LEFT: ept += (ln==0 ? 1 : -1); break;
                   2505:                        case RIGHT: ept += (ln==1 ? 1 : -1); break;
                   2506:                        }
                   2507:        else if (lwid==1)
                   2508:                switch(interh(start,c))
                   2509:                        {
                   2510:                        case THRU: ept += 1; break;
                   2511:                        case LEFT: case RIGHT: ept -= 1; break;
                   2512:                        }
                   2513:        if (exb)
                   2514:                fprintf(tabout, "\\v'%s'", exb);
                   2515:        if (epb)
                   2516:                fprintf(tabout, "\\v'%dp'", epb);
                   2517:        fprintf(tabout, "\\s\\n(%d",LSIZE);
                   2518:        if (linsize)
                   2519:                fprintf(tabout, "\\v'-\\n(%dp/6u'", LSIZE);
                   2520:        fprintf(tabout, "\\h'-\\n(#~u'"); /* adjustment for T450 nroff boxes */
                   2521:        fprintf(tabout, "\\L'|\\n(#%cu-%s", linestop[start]+'a'-1, vm=='v'? "1v" : "\\n(35u");
                   2522:        if (ext)
                   2523:                fprintf(tabout, "-(%s)",ext);
                   2524:        if (exb)
                   2525:                fprintf(tabout, "-(%s)", exb);
                   2526:        pos = ept-epb;
                   2527:        if (pos)
                   2528:                fprintf(tabout, "%s%dp", pos>=0? "+" : "", pos);
                   2529:        /* the string #d is either "nl" or ".d" depending
                   2530:           on diversions; on GCOS not the same */
                   2531:        fprintf(tabout, "'\\s0\\v'\\n(\\*(#du-\\n(#%cu+%s", linestop[start]+'a'-1,vm=='v' ? "1v" : "\\n(35u");
                   2532:        if (ext)
                   2533:                fprintf(tabout, "+%s",ext);
                   2534:        if (ept)
                   2535:                fprintf(tabout, "%s%dp", (-ept)>0 ? "+" : "", (-ept));
                   2536:        fprintf(tabout, "'");
                   2537:        if (linsize)
                   2538:                fprintf(tabout, "\\v'\\n(%dp/6u'", LSIZE);
                   2539:        }
                   2540: }
                   2541: 
                   2542: 
                   2543: midbar(i,c)
                   2544: {
                   2545: int k;
                   2546: k = midbcol(i,c);
                   2547: if (k==0 && c>0)
                   2548:        k = midbcol(i, c-1);
                   2549: return(k);
                   2550: }
                   2551: midbcol(i,c)
                   2552: {
                   2553: int ct;
                   2554: while ( (ct=ctype(i,c)) == 's')
                   2555:        c--;
                   2556: if (ct=='-' || ct == '=')
                   2557:        return(ct);
                   2558: if (ct=barent(table[i][c].col))
                   2559:        return(ct);
                   2560: return(0);
                   2561: }
                   2562: 
                   2563: barent(s)
                   2564:        char *s;
                   2565: {
                   2566: if (s==0) return (1);
                   2567: if (!point(s)) return(0);
                   2568: if (s[0]== '\\') s++;
                   2569: if (s[1]!= 0)
                   2570:        return(0);
                   2571: switch(s[0])
                   2572:        {
                   2573:        case '_':
                   2574:                return('-');
                   2575:        case '=':
                   2576:                return('=');
                   2577:        }
                   2578: return(0);
                   2579: }
                   2580: 0707070035051114711006640000030000040000010246070265271267100001300000000000TRAILER!!!0);
                   2581: }
                   2582: 
                   2583: barent(s)
                   2584:        char *s;
                   2585: {
                   2586: if (s==0) return (1);
                   2587: if (!point(s)) return(0);
                   2588: if (s[0]== '\\') s++;
                   2589: if (s[1]!= 0)
                   2590:        return(0);
                   2591: switch(s[0])
                   2592:        {
                   2593:        case '_':
                   2594:                return('-');
                   2595:        case '=':
                   2596:                return('=');
                   2597:        }
                   2598: return(0);
                   2599: }
                   2600: 0707070

unix.superglobalmegacorp.com

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