document distributed with 4.2BSD
[unix-history] / usr / src / old / tbl / t7.c
CommitLineData
476fcd16
SL
1#ifndef lint
2static char sccsid[] = "@(#)t7.c 4.3 %G%";
3#endif
bf37f301
BS
4
5 /* t7.c: control to write table entries */
6# include "t..c"
7# define realsplit ((ct=='a'||ct=='n') && table[ldata][c].rcol)
8runout()
9{
10int i;
11if (boxflg || allflg || dboxflg) need();
12if (ctrflg)
13 {
14 fprintf(tabout, ".nr #I \\n(.i\n");
15 fprintf(tabout, ".in +(\\n(.lu-\\n(TWu-\\n(.iu)/2u\n");
16 }
17fprintf(tabout, ".fc %c %c\n", F1, F2);
18fprintf(tabout, ".nr #T 0-1\n");
19deftail();
20for(i=0; i<nlin; i++)
21 putline(i,i);
22if (leftover)
23 yetmore();
24fprintf(tabout, ".fc\n");
25fprintf(tabout, ".nr T. 1\n");
26fprintf(tabout, ".T# 1\n");
27if (ctrflg)
28 fprintf(tabout, ".in \\n(#Iu\n");
29}
30runtabs(lform, ldata)
31{
32int c, ct, vforml, lf;
33fprintf(tabout, ".ta ");
34for(c=0; c<ncol; c++)
35 {
36 vforml=lform;
37 for(lf=prev(lform); lf>=0 && vspen(table[lf][c].col); lf=prev(lf))
38 vforml=lf;
39 if (fspan(vforml,c))
40 continue;
41 switch(ct=ctype(vforml,c))
42 {
43 case 'n':
44 case 'a':
45 if (table[ldata][c].rcol)
46 if (lused[c]) /*Zero field width*/
47 fprintf(tabout, "\\n(%du ",c+CMID);
48 case 'c':
49 case 'l':
50 case 'r':
51 if (realsplit? rused[c]: (used[c]+lused[c]))
52 fprintf(tabout, "\\n(%du ",c+CRIGHT);
53 continue;
54 case 's':
55 if (lspan(lform, c))
56 fprintf(tabout, "\\n(%du ", c+CRIGHT);
57 continue;
58 }
59 }
60fprintf(tabout, "\n");
61}
62ifline(s)
63 char *s;
64{
31dcd0af 65if (!point(s)) return(0);
bf37f301
BS
66if (s[0] == '\\') s++;
67if (s[1] ) return(0);
68if (s[0] == '_') return('-');
69if (s[0] == '=') return('=');
70return(0);
71}
72need()
73{
74int texlin, horlin, i;
75for(texlin=horlin=i=0; i<nlin; i++)
76 {
77 if (fullbot[i]!=0)
78 horlin++;
79 else
80 if (instead[i]!=0)
81 continue;
82 else
83 texlin++;
84 }
85fprintf(tabout, ".ne %dv+%dp\n",texlin,2*horlin);
86}
87deftail()
88{
89int i, c, lf, lwid;
90for(i=0; i<MAXHEAD; i++)
91 if (linestop[i])
92 fprintf(tabout, ".nr #%c 0-1\n", linestop[i]+'a'-1);
93fprintf(tabout, ".nr #a 0-1\n");
94fprintf(tabout, ".eo\n");
95fprintf(tabout, ".de T#\n");
96fprintf(tabout, ".ds #d .d\n");
97fprintf(tabout, ".if \\(ts\\n(.z\\(ts\\(ts .ds #d nl\n");
98 fprintf(tabout, ".mk ##\n");
99 fprintf(tabout, ".nr ## -1v\n");
100 fprintf(tabout, ".ls 1\n");
101 for(i=0; i<MAXHEAD; i++)
102 if (linestop[i])
103 fprintf(tabout, ".if \\n(#T>=0 .nr #%c \\n(#T\n",linestop[i]+'a'-1);
104if (boxflg || allflg || dboxflg) /* bottom of table line */
105 if (fullbot[nlin-1]==0)
106 {
107 if (!pr1403)
108 fprintf(tabout, ".if \\n(T. .vs \\n(.vu-\\n(.sp\n");
109 fprintf(tabout, ".if \\n(T. ");
110 drawline(nlin,0,ncol, dboxflg ? '=' : '-',1,0);
111 fprintf(tabout, "\n.if \\n(T. .vs\n");
112 /* T. is really an argument to a macro but because of
113 eqn we don't dare pass it as an argument and reference by $1 */
114 }
115 for(c=0; c<ncol; c++)
116 {
117 if ((lf=left(nlin-1,c, &lwid))>=0)
118 {
119 fprintf(tabout, ".if \\n(#%c>=0 .sp -1\n",linestop[lf]+'a'-1);
120 fprintf(tabout, ".if \\n(#%c>=0 ", linestop[lf]+'a'-1);
121 tohcol(c);
122 drawvert(lf, nlin-1, c, lwid);
123 fprintf(tabout, "\\h'|\\n(TWu'\n");
124 }
125 }
126 if (boxflg || allflg || dboxflg) /* right hand line */
127 {
128 fprintf(tabout, ".if \\n(#a>=0 .sp -1\n");
129 fprintf(tabout, ".if \\n(#a>=0 \\h'|\\n(TWu'");
130 drawvert (0, nlin-1, ncol, dboxflg? 2 : 1);
131 fprintf(tabout, "\n");
132 }
133fprintf(tabout, ".ls\n");
134fprintf(tabout, "..\n");
135fprintf(tabout, ".ec\n");
136}