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