xref: /onnv-gate/usr/src/cmd/tbl/t7.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * Copyright (c) 1983-1998 by Sun Microsystems, Inc.
3*0Sstevel@tonic-gate  * All Rights Reserved.
4*0Sstevel@tonic-gate  */
5*0Sstevel@tonic-gate 
6*0Sstevel@tonic-gate #ident	"%Z%%M%	%I%	%E% SMI"
7*0Sstevel@tonic-gate 
8*0Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
9*0Sstevel@tonic-gate /*	  All Rights Reserved  	*/
10*0Sstevel@tonic-gate 
11*0Sstevel@tonic-gate 
12*0Sstevel@tonic-gate /*
13*0Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
14*0Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
15*0Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
16*0Sstevel@tonic-gate  */
17*0Sstevel@tonic-gate 
18*0Sstevel@tonic-gate  /* t7.c: control to write table entries */
19*0Sstevel@tonic-gate # include "t..c"
20*0Sstevel@tonic-gate # define realsplit ((ct=='a'||ct=='n') && table[ldata][c].rcol)
21*0Sstevel@tonic-gate runout()
22*0Sstevel@tonic-gate {
23*0Sstevel@tonic-gate int i;
24*0Sstevel@tonic-gate if (boxflg || allflg || dboxflg) need();
25*0Sstevel@tonic-gate if (ctrflg)
26*0Sstevel@tonic-gate 	{
27*0Sstevel@tonic-gate 	fprintf(tabout, ".nr #I \\n(.i\n");
28*0Sstevel@tonic-gate 	fprintf(tabout, ".in +(\\n(.lu-\\n(TWu-\\n(.iu)/2u\n");
29*0Sstevel@tonic-gate 	}
30*0Sstevel@tonic-gate fprintf(tabout, ".fc %c %c\n", F1, F2);
31*0Sstevel@tonic-gate fprintf(tabout, ".nr #T 0-1\n");
32*0Sstevel@tonic-gate deftail();
33*0Sstevel@tonic-gate for(i=0; i<nlin; i++)
34*0Sstevel@tonic-gate 	putline(i,i);
35*0Sstevel@tonic-gate if (leftover)
36*0Sstevel@tonic-gate 	yetmore();
37*0Sstevel@tonic-gate fprintf(tabout, ".fc\n");
38*0Sstevel@tonic-gate fprintf(tabout, ".nr T. 1\n");
39*0Sstevel@tonic-gate fprintf(tabout, ".T# 1\n");
40*0Sstevel@tonic-gate if (ctrflg)
41*0Sstevel@tonic-gate 	fprintf(tabout, ".in \\n(#Iu\n");
42*0Sstevel@tonic-gate }
43*0Sstevel@tonic-gate runtabs(lform, ldata)
44*0Sstevel@tonic-gate {
45*0Sstevel@tonic-gate int c, ct, vforml, lf;
46*0Sstevel@tonic-gate fprintf(tabout, ".ta ");
47*0Sstevel@tonic-gate for(c=0; c<ncol; c++)
48*0Sstevel@tonic-gate 	{
49*0Sstevel@tonic-gate 	vforml=lform;
50*0Sstevel@tonic-gate 	for(lf=prev(lform); lf>=0 && vspen(table[lf][c].col); lf=prev(lf))
51*0Sstevel@tonic-gate 		vforml=lf;
52*0Sstevel@tonic-gate 	if (fspan(vforml,c))
53*0Sstevel@tonic-gate 		continue;
54*0Sstevel@tonic-gate 	switch(ct=ctype(vforml,c))
55*0Sstevel@tonic-gate 		{
56*0Sstevel@tonic-gate 		case 'n':
57*0Sstevel@tonic-gate 		case 'a':
58*0Sstevel@tonic-gate 			if (table[ldata][c].rcol)
59*0Sstevel@tonic-gate 			  if (lused[c]) /*Zero field width*/
60*0Sstevel@tonic-gate 				fprintf(tabout, "\\n(%du ",c+CMID);
61*0Sstevel@tonic-gate 		case 'c':
62*0Sstevel@tonic-gate 		case 'l':
63*0Sstevel@tonic-gate 		case 'r':
64*0Sstevel@tonic-gate 		    if (realsplit? rused[c]: (used[c]+lused[c]))
65*0Sstevel@tonic-gate 			fprintf(tabout, "\\n(%du ",c+CRIGHT);
66*0Sstevel@tonic-gate 			continue;
67*0Sstevel@tonic-gate 		case 's':
68*0Sstevel@tonic-gate 			if (lspan(lform, c))
69*0Sstevel@tonic-gate 				fprintf(tabout, "\\n(%du ", c+CRIGHT);
70*0Sstevel@tonic-gate 			continue;
71*0Sstevel@tonic-gate 		}
72*0Sstevel@tonic-gate 	}
73*0Sstevel@tonic-gate fprintf(tabout, "\n");
74*0Sstevel@tonic-gate }
75*0Sstevel@tonic-gate ifline(s)
76*0Sstevel@tonic-gate 	char *s;
77*0Sstevel@tonic-gate {
78*0Sstevel@tonic-gate if (!point(s)) return(0);
79*0Sstevel@tonic-gate if (s[0] == '\\') s++;
80*0Sstevel@tonic-gate if (s[1] ) return(0);
81*0Sstevel@tonic-gate if (s[0] == '_') return('-');
82*0Sstevel@tonic-gate if (s[0] == '=') return('=');
83*0Sstevel@tonic-gate return(0);
84*0Sstevel@tonic-gate }
85*0Sstevel@tonic-gate 
86*0Sstevel@tonic-gate need()
87*0Sstevel@tonic-gate {
88*0Sstevel@tonic-gate 	int texlin, horlin, i;
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate 	for(texlin = horlin = i = 0; i < nlin; i++) {
91*0Sstevel@tonic-gate 		if (allh(i))
92*0Sstevel@tonic-gate 			horlin++;
93*0Sstevel@tonic-gate 		else if (instead[i] != 0)
94*0Sstevel@tonic-gate 			continue;
95*0Sstevel@tonic-gate 		else
96*0Sstevel@tonic-gate 			texlin++;
97*0Sstevel@tonic-gate 	}
98*0Sstevel@tonic-gate 	(void) fprintf(tabout, ".ne %dv+%dp\n", texlin, 2 * horlin);
99*0Sstevel@tonic-gate 	/*
100*0Sstevel@tonic-gate 	 * For nroff runs, we need to reserve space for the full height of the
101*0Sstevel@tonic-gate 	 * horizontal rules.  If we don't reserve sufficient height, we'll have
102*0Sstevel@tonic-gate 	 * problems trying to draw the vertical lines across the page boundary.
103*0Sstevel@tonic-gate 	 */
104*0Sstevel@tonic-gate 	(void) fprintf(tabout, ".if n .ne %dv\n", 2 * texlin + 2 * horlin + 2);
105*0Sstevel@tonic-gate }
106*0Sstevel@tonic-gate 
107*0Sstevel@tonic-gate deftail()
108*0Sstevel@tonic-gate {
109*0Sstevel@tonic-gate int i, c, lf, lwid;
110*0Sstevel@tonic-gate for(i=0; i<MAXHEAD; i++)
111*0Sstevel@tonic-gate 	if (linestop[i])
112*0Sstevel@tonic-gate 		fprintf(tabout, ".nr #%c 0-1\n", linestop[i]+'a'-1);
113*0Sstevel@tonic-gate fprintf(tabout, ".nr #a 0-1\n");
114*0Sstevel@tonic-gate fprintf(tabout, ".eo\n");
115*0Sstevel@tonic-gate fprintf(tabout, ".de T#\n");
116*0Sstevel@tonic-gate fprintf(tabout, ".ds #d .d\n");
117*0Sstevel@tonic-gate fprintf(tabout, ".if \\(ts\\n(.z\\(ts\\(ts .ds #d nl\n");
118*0Sstevel@tonic-gate 	fprintf(tabout, ".mk ##\n");
119*0Sstevel@tonic-gate 	fprintf(tabout, ".nr ## -1v\n");
120*0Sstevel@tonic-gate 	fprintf(tabout, ".ls 1\n");
121*0Sstevel@tonic-gate 	for(i=0; i<MAXHEAD; i++)
122*0Sstevel@tonic-gate 		if (linestop[i])
123*0Sstevel@tonic-gate 			fprintf(tabout, ".if \\n(#T>=0 .nr #%c \\n(#T\n",linestop[i]+'a'-1);
124*0Sstevel@tonic-gate if (boxflg || allflg || dboxflg) { /* bottom of table line */
125*0Sstevel@tonic-gate 	if (!pr1403)
126*0Sstevel@tonic-gate 		fprintf(tabout, ".if \\n(T. .vs \\n(.vu-\\n(.sp\n");
127*0Sstevel@tonic-gate 	fprintf(tabout, ".if \\n(T. ");
128*0Sstevel@tonic-gate 	drawline(nlin,0,ncol, dboxflg ? '=' : '-',1,0);
129*0Sstevel@tonic-gate 	fprintf(tabout, "\n.if \\n(T. .vs\n");
130*0Sstevel@tonic-gate 	/* T. is really an argument to a macro but because of
131*0Sstevel@tonic-gate 		   eqn we don't dare pass it as an argument and reference by $1 */
132*0Sstevel@tonic-gate }
133*0Sstevel@tonic-gate 	for(c=0; c<ncol; c++)
134*0Sstevel@tonic-gate 		{
135*0Sstevel@tonic-gate 		if ((lf=left(nlin-1,c, &lwid))>=0)
136*0Sstevel@tonic-gate 			{
137*0Sstevel@tonic-gate 			fprintf(tabout, ".if \\n(#%c>=0 .sp -1\n",linestop[lf]+'a'-1);
138*0Sstevel@tonic-gate 			fprintf(tabout, ".if \\n(#%c>=0 ", linestop[lf]+'a'-1);
139*0Sstevel@tonic-gate 			tohcol(c);
140*0Sstevel@tonic-gate 			drawvert(lf, nlin-1, c, lwid);
141*0Sstevel@tonic-gate 			fprintf(tabout, "\\h'|\\n(TWu'\n");
142*0Sstevel@tonic-gate 			}
143*0Sstevel@tonic-gate 		}
144*0Sstevel@tonic-gate 	if (boxflg || allflg || dboxflg) /* right hand line */
145*0Sstevel@tonic-gate 		{
146*0Sstevel@tonic-gate 		fprintf(tabout, ".if \\n(#a>=0 .sp -1\n");
147*0Sstevel@tonic-gate 		fprintf(tabout, ".if \\n(#a>=0 \\h'|\\n(TWu'");
148*0Sstevel@tonic-gate 		drawvert (0, nlin-1, ncol, dboxflg? 2 : 1);
149*0Sstevel@tonic-gate 		fprintf(tabout, "\n");
150*0Sstevel@tonic-gate 		}
151*0Sstevel@tonic-gate fprintf(tabout, ".ls\n");
152*0Sstevel@tonic-gate fprintf(tabout, "..\n");
153*0Sstevel@tonic-gate fprintf(tabout, ".ec\n");
154*0Sstevel@tonic-gate }
155