home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / src / cmd / tbl / t6.c < prev    next >
Encoding:
C/C++ Source or Header  |  1979-01-10  |  6.1 KB  |  203 lines

  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[stynum[i]][c]
  7. # define SZ(i,c) csize[stynum[i]][c]
  8. /* define the tab stops of the table */
  9. int icol, ilin, tsep, k, ik, vforml, il, text;
  10. int doubled[MAXCOL], acase[MAXCOL];
  11. char *s;
  12. for(icol=0; icol <ncol; icol++)
  13.     {
  14.     doubled[icol] = acase[icol] = 0;
  15.     fprintf(tabout, ".nr %d 0\n", icol+CRIGHT);
  16.    for(text=0; text<2; text++)
  17.     {
  18.     if (text)
  19.         fprintf(tabout, ".%02d\n.rm %02d\n", icol+80, icol+80);
  20.     for(ilin=0; ilin<nlin; ilin++)
  21.         {
  22.         if (instead[ilin]|| fullbot[ilin]) continue;
  23.         vforml=ilin;
  24.         for(il=prev(ilin); il>=0 && vspen(table[il][icol].col); il=prev(il))
  25.             vforml=il;
  26.         if (fspan(vforml,icol)) continue;
  27.         if (filler(table[ilin][icol].col)) continue;
  28.         switch(ctype(vforml,icol))
  29.             {
  30.             case 'a':
  31.                 acase[icol]=1;
  32.                 s = table[ilin][icol].col;
  33.                 if (s>0 && 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(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(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(%d<\\n(%d .nr %d \\n(%d\n", icol+CRIGHT, TMP, icol+CRIGHT, TMP);
  69.                     }
  70.             }
  71.         }
  72.         }
  73.     if (acase[icol])
  74.         {
  75.         fprintf(tabout, ".if \\n(%d>=\\n(%d .nr %d \\n(%du+2n\n",S2,icol+CRIGHT,icol+CRIGHT,S2);
  76.         }
  77.     if (doubled[icol])
  78.         {
  79.         fprintf(tabout, ".nr %d \\n(%d\n", icol+CMID, S1);
  80.         fprintf(tabout, ".nr %d \\n(%d+\\n(%d\n",TMP,icol+CMID,S2);
  81.         fprintf(tabout, ".if \\n(%d>\\n(%d .nr %d \\n(%d\n",TMP,icol+CRIGHT,icol+CRIGHT,TMP);
  82.         fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d +(\\n(%d-\\n(%d)/2\n",TMP,icol+CRIGHT,icol+CMID,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(%d<\\n(%d .nr %d \\n(%d\n",icol+CRIGHT, TMP, 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(%d",CRIGHT+icol-ik);
  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 %d +\\n(%d/2\n", icol-k+ik+CMID, TMP);
  108.             fprintf(tabout, ".nr %d +\\n(%d\n", 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(%d>\\n(%d .nr %d \\n(%d\n",
  123.         icol+CRIGHT, TMP, TMP, 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 %d (100*\\n(%d/\\n(%d)*\\n(%d/100\n",
  132.                 icol+CMID, icol+CMID, 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 %d \\n(%d\n", 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(%d", 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 %d 0\n",CRIGHT-1);
  159. tsep= (boxflg || allflg || dboxflg || left1flg) ? 1 : 0;
  160. for(icol=0; icol<ncol; icol++)
  161.     {
  162.     fprintf(tabout, ".nr %d \\n(%d+(%d*\\n(%d)\n",icol+CLEFT, icol+CRIGHT-1, tsep, TMP);
  163.     fprintf(tabout, ".nr %d +\\n(%d\n",icol+CRIGHT, icol+CLEFT);
  164.     if (doubled[icol])
  165.         {
  166.         /* the next line is last-ditch effort to avoid zero field width */
  167.         /*fprintf(tabout, ".if \\n(%d=0 .nr %d 1\n",icol+CMID, icol+CMID);*/
  168.         fprintf(tabout, ".nr %d +\\n(%d\n", icol+CMID, icol+CLEFT);
  169.     /*  fprintf(tabout, ".if n .if \\n(%d%%24>0 .nr %d +12u\n",icol+CMID, icol+CMID); */
  170.         }
  171.     tsep=sep[icol];
  172.     }
  173. if (rightl)
  174.     fprintf(tabout, ".nr %d (\\n(%d+\\n(%d)/2\n",ncol+CRIGHT-1, ncol+CLEFT-1, ncol+CRIGHT-2);
  175. fprintf(tabout, ".nr TW \\n(%d\n", ncol+CRIGHT-1);
  176. if (boxflg || allflg || dboxflg)
  177.     fprintf(tabout, ".nr TW +%d*\\n(%d\n", sep[ncol-1], TMP);
  178. fprintf(tabout,
  179.  ".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);
  180. return;
  181. }
  182. wide(s, fn, size)
  183.     char *s, *size, *fn;
  184. {
  185. if (point(s))
  186.     {
  187.     fprintf(tabout, "\\w%c", F1);
  188.     if (*fn>0) putfont(fn);
  189.     if (*size) putsize(size);
  190.     fprintf(tabout, "%s", s);
  191.     if (*fn>0) putfont("P");
  192.     if (*size) putsize("0");
  193.     fprintf(tabout, "%c",F1);
  194.     }
  195. else
  196.     fprintf(tabout, "\\n(%c-", s);
  197. }
  198. filler(s)
  199.     char *s;
  200. {
  201. return (point(s) && s[0]=='\\' && s[1] == 'R');
  202. }
  203.