blob: 2fa9de53bbfcc30b7b04135f7d22bf590983795f [file] [log] [blame]
rsc5cedca12004-05-15 23:24:00 +00001/* t7.c: control to write table entries */
2# include "t.h"
3# define realsplit ((ct=='a'||ct=='n') && table[ldata][c].rcol)
4
5void
6runout(void)
7{
8 int i;
9
10 if (boxflg || allflg || dboxflg)
11 need();
12 if (ctrflg) {
wkj8a3cbc12004-05-17 02:23:43 +000013 Bprint(&tabout, ".nr #I \\n(.i\n");
14 Bprint(&tabout, ".in +(\\n(.lu-\\n(TWu-\\n(.iu)/2u\n");
rsc5cedca12004-05-15 23:24:00 +000015 }
wkj8a3cbc12004-05-17 02:23:43 +000016 Bprint(&tabout, ".fc %c %c\n", F1, F2);
17 Bprint(&tabout, ".nr #T 0-1\n");
rsc5cedca12004-05-15 23:24:00 +000018 deftail();
19 for (i = 0; i < nlin; i++)
20 putline(i, i);
21 if (leftover)
22 yetmore();
wkj8a3cbc12004-05-17 02:23:43 +000023 Bprint(&tabout, ".fc\n");
24 Bprint(&tabout, ".nr T. 1\n");
25 Bprint(&tabout, ".T# 1\n");
rsc5cedca12004-05-15 23:24:00 +000026 if (ctrflg)
wkj8a3cbc12004-05-17 02:23:43 +000027 Bprint(&tabout, ".in \\n(#Iu\n");
rsc5cedca12004-05-15 23:24:00 +000028}
29
30
31void
32runtabs(int lform, int ldata)
33{
34 int c, ct, vforml, lf;
35
wkj8a3cbc12004-05-17 02:23:43 +000036 Bprint(&tabout, ".ta ");
rsc5cedca12004-05-15 23:24:00 +000037 for (c = 0; c < ncol; c++) {
38 vforml = lform;
39 for (lf = prev(lform); lf >= 0 && vspen(table[lf][c].col); lf = prev(lf))
40 vforml = lf;
41 if (fspan(vforml, c))
42 continue;
43 switch (ct = ctype(vforml, c)) {
44 case 'n':
45 case 'a':
46 if (table[ldata][c].rcol)
47 if (lused[c]) /*Zero field width*/
wkj8a3cbc12004-05-17 02:23:43 +000048 Bprint(&tabout, "\\n(%2su ", reg(c, CMID));
rsc5cedca12004-05-15 23:24:00 +000049 case 'c':
50 case 'l':
51 case 'r':
52 if (realsplit ? rused[c] : (used[c] + lused[c]))
wkj8a3cbc12004-05-17 02:23:43 +000053 Bprint(&tabout, "\\n(%2su ", reg(c, CRIGHT));
rsc5cedca12004-05-15 23:24:00 +000054 continue;
55 case 's':
56 if (lspan(lform, c))
wkj8a3cbc12004-05-17 02:23:43 +000057 Bprint(&tabout, "\\n(%2su ", reg(c, CRIGHT));
rsc5cedca12004-05-15 23:24:00 +000058 continue;
59 }
60 }
wkj8a3cbc12004-05-17 02:23:43 +000061 Bprint(&tabout, "\n");
rsc5cedca12004-05-15 23:24:00 +000062}
63
64
65int
66ifline(char *s)
67{
68 if (!point(s))
69 return(0);
70 if (s[0] == '\\')
71 s++;
72 if (s[1] )
73 return(0);
74 if (s[0] == '_')
75 return('-');
76 if (s[0] == '=')
77 return('=');
78 return(0);
79}
80
81
82void
83need(void)
84{
85 int texlin, horlin, i;
86
87 for (texlin = horlin = i = 0; i < nlin; i++) {
88 if (fullbot[i] != 0)
89 horlin++;
90 else if (instead[i] != 0)
91 continue;
92 else
93 texlin++;
94 }
wkj8a3cbc12004-05-17 02:23:43 +000095 Bprint(&tabout, ".ne %dv+%dp\n", texlin, 2 * horlin);
rsc5cedca12004-05-15 23:24:00 +000096}
97
98
99void
100deftail(void)
101{
102 int i, c, lf, lwid;
103
104 for (i = 0; i < MAXHEAD; i++)
105 if (linestop[i])
wkj8a3cbc12004-05-17 02:23:43 +0000106 Bprint(&tabout, ".nr #%c 0-1\n", linestop[i] + 'a' - 1);
107 Bprint(&tabout, ".nr #a 0-1\n");
108 Bprint(&tabout, ".eo\n");
109 Bprint(&tabout, ".de T#\n");
110 Bprint(&tabout, ".nr 35 1m\n");
111 Bprint(&tabout, ".ds #d .d\n");
112 Bprint(&tabout, ".if \\(ts\\n(.z\\(ts\\(ts .ds #d nl\n");
113 Bprint(&tabout, ".mk ##\n");
114 Bprint(&tabout, ".nr ## -1v\n");
115 Bprint(&tabout, ".ls 1\n");
rsc5cedca12004-05-15 23:24:00 +0000116 for (i = 0; i < MAXHEAD; i++)
117 if (linestop[i])
wkj8a3cbc12004-05-17 02:23:43 +0000118 Bprint(&tabout, ".if \\n(#T>=0 .nr #%c \\n(#T\n",
rsc5cedca12004-05-15 23:24:00 +0000119 linestop[i] + 'a' - 1);
120 if (boxflg || allflg || dboxflg) /* bottom of table line */
121 if (fullbot[nlin-1] == 0) {
122 if (!pr1403)
wkj8a3cbc12004-05-17 02:23:43 +0000123 Bprint(&tabout, ".if \\n(T. .vs \\n(.vu-\\n(.sp\n");
124 Bprint(&tabout, ".if \\n(T. ");
rsc5cedca12004-05-15 23:24:00 +0000125 drawline(nlin, 0, ncol, dboxflg ? '=' : '-', 1, 0);
wkj8a3cbc12004-05-17 02:23:43 +0000126 Bprint(&tabout, "\n.if \\n(T. .vs\n");
rsc5cedca12004-05-15 23:24:00 +0000127 /* T. is really an argument to a macro but because of
128 eqn we don't dare pass it as an argument and reference by $1 */
129 }
130 for (c = 0; c < ncol; c++) {
131 if ((lf = left(nlin - 1, c, &lwid)) >= 0) {
wkj8a3cbc12004-05-17 02:23:43 +0000132 Bprint(&tabout, ".if \\n(#%c>=0 .sp -1\n", linestop[lf] + 'a' - 1);
133 Bprint(&tabout, ".if \\n(#%c>=0 ", linestop[lf] + 'a' - 1);
rsc5cedca12004-05-15 23:24:00 +0000134 tohcol(c);
135 drawvert(lf, nlin - 1, c, lwid);
wkj8a3cbc12004-05-17 02:23:43 +0000136 Bprint(&tabout, "\\h'|\\n(TWu'\n");
rsc5cedca12004-05-15 23:24:00 +0000137 }
138 }
139 if (boxflg || allflg || dboxflg) /* right hand line */ {
wkj8a3cbc12004-05-17 02:23:43 +0000140 Bprint(&tabout, ".if \\n(#a>=0 .sp -1\n");
141 Bprint(&tabout, ".if \\n(#a>=0 \\h'|\\n(TWu'");
rsc5cedca12004-05-15 23:24:00 +0000142 drawvert (0, nlin - 1, ncol, dboxflg ? 2 : 1);
wkj8a3cbc12004-05-17 02:23:43 +0000143 Bprint(&tabout, "\n");
rsc5cedca12004-05-15 23:24:00 +0000144 }
wkj8a3cbc12004-05-17 02:23:43 +0000145 Bprint(&tabout, ".ls\n");
146 Bprint(&tabout, "..\n");
147 Bprint(&tabout, ".ec\n");
rsc5cedca12004-05-15 23:24:00 +0000148}
149
150