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