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