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