Annotation of researchv10no/cmd/tbl/t6.c, revision 1.1.1.1

1.1       root        1:  /* t6.c: compute tab stops */
                      2: # define tx(a) (a>0 && a<128)
                      3: # include "t..c"
                      4: maktab()
                      5: {
                      6: # define FN(i,c) font[c][stynum[i]]
                      7: # define SZ(i,c) csize[c][stynum[i]]
                      8: /* define the tab stops of the table */
                      9: int icol, ilin, tsep, k, ik, vforml, il, text;
                     10: char *s;
                     11: for(icol=0; icol <ncol; icol++)
                     12:        {
                     13:        doubled[icol] = acase[icol] = 0;
                     14:        fprintf(tabout, ".nr %2s 0\n", reg(icol,CRIGHT));
                     15:    for(text=0; text<2; text++)
                     16:        {
                     17:        if (text)
                     18:                fprintf(tabout, ".%2s\n.rm %2s\n", reg(icol, CRIGHT), reg(icol, CRIGHT));
                     19:        for(ilin=0; ilin<nlin; ilin++)
                     20:                {
                     21:                if (instead[ilin]|| fullbot[ilin]) continue;
                     22:                vforml=ilin;
                     23:                for(il=prev(ilin); il>=0 && vspen(table[il][icol].col); il=prev(il))
                     24:                        vforml=il;
                     25:                if (fspan(vforml,icol)) continue;
                     26:                if (filler(table[ilin][icol].col)) continue;
                     27:                if ((flags[icol][stynum[ilin]] & ZEROW) != 0) continue;
                     28:                switch(ctype(vforml,icol))
                     29:                        {
                     30:                        case 'a':
                     31:                                acase[icol]=1;
                     32:                                s = table[ilin][icol].col;
                     33:                                if ((int)s>0 && (int)s<128 && text)
                     34:                                        {
                     35:                                        if (doubled[icol]==0)
                     36:                                                fprintf(tabout, ".nr %d 0\n.nr %d 0\n",S1,S2);
                     37:                                        doubled[icol]=1;
                     38:                                        fprintf(tabout, ".if \\n(%c->\\n(%d .nr %d \\n(%c-\n",s,S2,S2,s);
                     39:                                        }
                     40:                        case 'n':
                     41:                                if (table[ilin][icol].rcol!=0)
                     42:                                        {
                     43:                                        if (doubled[icol]==0 && text==0)
                     44:                                                fprintf(tabout, ".nr %d 0\n.nr %d 0\n", S1, S2);
                     45:                                        doubled[icol]=1;
                     46:                                        if (real(s=table[ilin][icol].col) && !vspen(s))
                     47:                                                {
                     48:                                                if (tx((int)s) != text) continue;
                     49:                                                fprintf(tabout, ".nr %d ", TMP);
                     50:                                                wide(s, FN(vforml,icol), SZ(vforml,icol)); fprintf(tabout, "\n");
                     51:                                                fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n", S1, TMP, S1, TMP);
                     52:                                                }
                     53:                                        if (text==0 && real(s=table[ilin][icol].rcol) && !vspen(s) && !barent(s))
                     54:                                                {
                     55:                                                fprintf(tabout, ".nr %d \\w%c%s%c\n",TMP, F1, s, F1);
                     56:                                                fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n",S2,TMP,S2,TMP);
                     57:                                                }
                     58:                                        continue;
                     59:                                        }
                     60:                        case 'r':
                     61:                        case 'c':
                     62:                        case 'l':
                     63:                                if (real(s=table[ilin][icol].col) && !vspen(s))
                     64:                                        {
                     65:                                        if (tx((int)s) != text) continue;
                     66:                                        fprintf(tabout, ".nr %d ", TMP);
                     67:                                        wide(s, FN(vforml,icol), SZ(vforml,icol)); fprintf(tabout, "\n");
                     68:                                        fprintf(tabout, ".if \\n(%2s<\\n(%d .nr %2s \\n(%d\n", reg(icol,CRIGHT), TMP, reg(icol,CRIGHT), TMP);
                     69:                                        }
                     70:                        }
                     71:                }
                     72:                }
                     73:        if (acase[icol])
                     74:                {
                     75:                fprintf(tabout, ".if \\n(%d>=\\n(%2s .nr %2s \\n(%du+2n\n",S2,reg(icol,CRIGHT),reg(icol,CRIGHT),S2);
                     76:                }
                     77:        if (doubled[icol])
                     78:                {
                     79:                fprintf(tabout, ".nr %2s \\n(%d\n", reg(icol,CMID), S1);
                     80:                fprintf(tabout, ".nr %d \\n(%2s+\\n(%d\n",TMP,reg(icol,CMID),S2);
                     81:                fprintf(tabout, ".if \\n(%d>\\n(%2s .nr %2s \\n(%d\n",TMP,reg(icol,CRIGHT),reg(icol,CRIGHT),TMP);
                     82:                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);
                     83:                }
                     84:        if (cll[icol][0])
                     85:                {
                     86:                fprintf(tabout, ".nr %d %sn\n", TMP, cll[icol]);
                     87:                fprintf(tabout, ".if \\n(%2s<\\n(%d .nr %2s \\n(%d\n",reg(icol,CRIGHT), TMP, reg(icol,CRIGHT), TMP);
                     88:                }
                     89:        for(ilin=0; ilin<nlin; ilin++)
                     90:        if (k=lspan(ilin, icol))
                     91:                {
                     92:                s=table[ilin][icol-k].col;
                     93:                if (!real(s) || barent(s) || vspen(s) ) continue;
                     94:                fprintf(tabout, ".nr %d ", TMP);
                     95:                wide(table[ilin][icol-k].col, FN(ilin,icol-k), SZ(ilin,icol-k));
                     96:                for(ik=k; ik>=0; ik--)
                     97:                        {
                     98:                        fprintf(tabout, "-\\n(%2s",reg(icol-ik,CRIGHT));
                     99:                        if (!expflg && ik>0) fprintf(tabout, "-%dn", sep[icol-ik]);
                    100:                        }
                    101:                fprintf(tabout, "\n");
                    102:                fprintf(tabout, ".if \\n(%d>0 .nr %d \\n(%d/%d\n", TMP, TMP, TMP, k);
                    103:                fprintf(tabout, ".if \\n(%d<0 .nr %d 0\n", TMP, TMP);
                    104:                for(ik=1; ik<=k; ik++)
                    105:                        {
                    106:                        if (doubled[icol-k+ik])
                    107:                                fprintf(tabout, ".nr %2s +\\n(%d/2\n", reg(icol-k+ik,CMID), TMP);
                    108:                        fprintf(tabout, ".nr %2s +\\n(%d\n", reg(icol-k+ik,CRIGHT), TMP);
                    109:                        }
                    110:                }
                    111:        }
                    112: if (textflg) untext();
                    113: /* if even requested, make all columns widest width */
                    114: # define TMP1 S1
                    115: # define TMP2 S2
                    116: if (evenflg)
                    117:        {
                    118:        fprintf(tabout, ".nr %d 0\n", TMP);
                    119:        for(icol=0; icol<ncol; icol++)
                    120:                {
                    121:                if (evenup[icol]==0) continue;
                    122:                fprintf(tabout, ".if \\n(%2s>\\n(%d .nr %d \\n(%2s\n",
                    123:                reg(icol,CRIGHT), TMP, TMP, reg(icol,CRIGHT));
                    124:                }
                    125:        for(icol=0; icol<ncol; icol++)
                    126:                {
                    127:                if (evenup[icol]==0)
                    128:                        /* if column not evened just retain old interval */
                    129:                        continue;
                    130:                if (doubled[icol])
                    131:                        fprintf(tabout, ".nr %2s (100*\\n(%2s/\\n(%2s)*\\n(%d/100\n",
                    132:                                reg(icol,CMID), reg(icol,CMID), reg(icol,CRIGHT), TMP);
                    133:                                /* that nonsense with the 100's and parens tries
                    134:                                   to avoid overflow while proportionally shifting
                    135:                                   the middle of the number */
                    136:                fprintf(tabout, ".nr %2s \\n(%d\n", reg(icol,CRIGHT), TMP);
                    137:                }
                    138:        }
                    139: /* now adjust for total table width */
                    140: for(tsep=icol=0; icol<ncol; icol++)
                    141:        tsep+= sep[icol];
                    142: if (expflg)
                    143:        {
                    144:        fprintf(tabout, ".nr %d 0", TMP);
                    145:        for(icol=0; icol<ncol; icol++)
                    146:                fprintf(tabout, "+\\n(%2s", reg(icol,CRIGHT));
                    147:        fprintf(tabout, "\n");
                    148:        fprintf(tabout, ".nr %d \\n(.l-\\n(%d\n", TMP, TMP);
                    149:        if (boxflg || dboxflg || allflg)
                    150:                /* tsep += 1; */ ;
                    151:        else
                    152:                tsep -= sep[ncol-1];
                    153:        fprintf(tabout, ".nr %d \\n(%d/%d\n", TMP, TMP,  tsep);
                    154:        fprintf(tabout, ".if \\n(%d<0 .nr %d 0\n", TMP, TMP);
                    155:        }
                    156: else
                    157:        fprintf(tabout, ".nr %d 1n\n", TMP);
                    158: fprintf(tabout, ".nr %2s 0\n",reg(-1, CRIGHT));
                    159: tsep= (boxflg || allflg || dboxflg || left1flg) ? 2 : 0;
                    160: if (sep[-1] >= 0) tsep = sep[-1];
                    161: for(icol=0; icol<ncol; icol++)
                    162:        {
                    163:        fprintf(tabout, ".nr %2s \\n(%2s+((%d*\\n(%d)/2)\n",reg(icol,CLEFT), reg(icol-1,CRIGHT), tsep, TMP);
                    164:        fprintf(tabout, ".nr %2s +\\n(%2s\n",reg(icol,CRIGHT), reg(icol,CLEFT));
                    165:        if (doubled[icol])
                    166:                {
                    167:                /* the next line is last-ditch effort to avoid zero field width */
                    168:                /*fprintf(tabout, ".if \\n(%2s=0 .nr %2s 1\n",reg(icol,CMID), reg(icol,CMID));*/
                    169:                fprintf(tabout, ".nr %2s +\\n(%2s\n", reg(icol,CMID), reg(icol,CLEFT));
                    170:        /*  fprintf(tabout, ".if n .if \\n(%s%%24>0 .nr %s +12u\n",reg(icol,CMID), reg(icol,CMID)); */
                    171:                }
                    172:        tsep=sep[icol]*2;
                    173:        }
                    174: if (rightl)
                    175:        fprintf(tabout, ".nr %s (\\n(%s+\\n(%s)/2\n",reg(ncol-1, CRIGHT), reg(ncol-1,CLEFT), reg(ncol-2,CRIGHT));
                    176: fprintf(tabout, ".nr TW \\n(%2s\n", reg(ncol-1, CRIGHT));
                    177: tsep = sep[ncol-1];
                    178: if (boxflg || allflg || dboxflg)
                    179:        fprintf(tabout, ".nr TW +((%d*\\n(%d)/2)\n", tsep, TMP);
                    180: fprintf(tabout,
                    181:  ".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);
                    182: return;
                    183: }
                    184: wide(s, fn, size)
                    185:        char *s, *size, *fn;
                    186: {
                    187: if (point(s))
                    188:        {
                    189:        fprintf(tabout, "\\w%c", F1);
                    190:        if (*fn>0) putfont(fn);
                    191:        if (*size) putsize(size);
                    192:        fprintf(tabout, "%s", s);
                    193:        if (*fn>0) putfont("P");
                    194:        if (*size) putsize("0");
                    195:        fprintf(tabout, "%c",F1);
                    196:        }
                    197: else
                    198:        fprintf(tabout, "\\n(%c-", s);
                    199: }
                    200: filler(s)
                    201:        char *s;
                    202: {
                    203: return (point(s) && s[0]=='\\' && s[1] == 'R');
                    204: }

unix.superglobalmegacorp.com

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