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