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