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