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