xref: /titanic_51/usr/src/cmd/tbl/tu.c (revision 5aefb6555731130ca4fd295960123d71f2d21fe8)
1 /*
2  * Copyright 1990 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  /* tu.c: draws horizontal lines */
18 # include "t..c"
19 
20 void	drawline(int, int, int, int, int, int);
21 
22 void
23 makeline(int i, int c, int lintype)
24 {
25 int cr, type, shortl;
26 type = thish(i,c);
27 if (type==0) return;
28 cr=c;
29 shortl = (table[i][c].col[0]=='\\');
30 if (c>0 && !shortl && thish(i,c-1) == type)return;
31 if (shortl==0)
32 	for(cr=c; cr < ncol && (ctype(i,cr)=='s'||type==thish(i,cr)); cr++);
33 else
34 	for(cr=c+1; cr<ncol && ctype(i,cr)=='s'; cr++);
35 drawline(i, c, cr-1, lintype, 0, shortl);
36 }
37 
38 void
39 fullwide(int i, int lintype)
40 {
41 int cr, cl;
42 if (!pr1403)
43 	fprintf(tabout, ".nr %d \\n(.v\n.vs \\n(.vu-\\n(.sp\n", SVS);
44 cr= 0;
45 while (cr<ncol)
46 	{
47 	cl=cr;
48 	while (i>0 && vspand(prev(i),cl,1))
49 		cl++;
50 	for(cr=cl; cr<ncol; cr++)
51 		if (i>0 && vspand(prev(i),cr,1))
52 			break;
53 	if (cl<ncol)
54 	drawline(i,cl,(cr<ncol?cr-1:cr),lintype,1,0);
55 	}
56 fprintf(tabout, "\n");
57 if (!pr1403)
58 	fprintf(tabout, ".vs \\n(%du\n", SVS);
59 }
60 
61 void
62 drawline(int i, int cl, int cr, int lintype, int noheight, int shortl)
63 {
64 	char *exhr, *exhl, *lnch;
65 	int lcount, ln, linpos, oldpos, nodata;
66 lcount=0;
67 exhr=exhl= "";
68 switch(lintype)
69 	{
70 	case '-': lcount=1;break;
71 	case '=': lcount = pr1403? 1 : 2; break;
72 	case SHORTLINE: lcount=1; break;
73 	}
74 if (lcount<=0) return;
75 nodata = cr-cl>=ncol || noheight || allh(i);
76 	if (!nodata)
77 		fprintf(tabout, "\\v'-.5m'");
78 for(ln=oldpos=0; ln<lcount; ln++)
79 	{
80 	linpos = 2*ln - lcount +1;
81 	if (linpos != oldpos)
82 		fprintf(tabout, "\\v'%dp'", linpos-oldpos);
83 	oldpos=linpos;
84 	if (shortl==0)
85 	{
86 	tohcol(cl);
87 	if (lcount>1)
88 		{
89 		switch(interv(i,cl))
90 			{
91 			case TOP: exhl = ln==0 ? "1p" : "-1p"; break;
92 			case BOT: exhl = ln==1 ? "1p" : "-1p"; break;
93 			case THRU: exhl = "1p"; break;
94 			}
95 		if (exhl[0])
96 		fprintf(tabout, "\\h'%s'", exhl);
97 		}
98 	else if (lcount==1)
99 		{
100 		switch(interv(i,cl))
101 			{
102 			case TOP: case BOT: exhl = "-1p"; break;
103 			case THRU: exhl = "1p"; break;
104 			}
105 		if (exhl[0])
106 		fprintf(tabout, "\\h'%s'", exhl);
107 		}
108 	if (lcount>1)
109 		{
110 		switch(interv(i,cr+1))
111 			{
112 			case TOP: exhr = ln==0 ? "-1p" : "+1p"; break;
113 			case BOT: exhr = ln==1 ? "-1p" : "+1p"; break;
114 			case THRU: exhr = "-1p"; break;
115 			}
116 		}
117 	else if (lcount==1)
118 		{
119 		switch(interv(i,cr+1))
120 			{
121 			case TOP: case BOT: exhr = "+1p"; break;
122 			case THRU: exhr = "-1p"; break;
123 			}
124 		}
125 	}
126 	else
127 		fprintf(tabout, "\\h'|\\n(%du'", cl+CLEFT);
128 	fprintf(tabout, "\\s\\n(%d",LSIZE);
129 	if (linsize)
130 		fprintf(tabout, "\\v'-\\n(%dp/6u'", LSIZE);
131 	if (shortl)
132 		fprintf(tabout, "\\l'|\\n(%du'", cr+CRIGHT);
133 	else
134 	{
135 	lnch = "\\(ul";
136 	if (pr1403)
137 		lnch = lintype==2 ? "=" : "\\(ru";
138 	if (cr+1>=ncol)
139 		fprintf(tabout, "\\l'|\\n(TWu%s%s'", exhr,lnch);
140 	else
141 		fprintf(tabout, "\\l'(|\\n(%du+|\\n(%du)/2u%s%s'", cr+CRIGHT,
142 			cr+1+CLEFT, exhr, lnch);
143 	}
144 	if (linsize)
145 		fprintf(tabout, "\\v'\\n(%dp/6u'", LSIZE);
146 	fprintf(tabout, "\\s0");
147 	}
148 if (oldpos!=0)
149 	fprintf(tabout, "\\v'%dp'", -oldpos);
150 if (!nodata)
151 	fprintf(tabout, "\\v'+.5m'");
152 }
153 
154 void
155 getstop(void)
156 {
157 int i,c,k,junk, stopp;
158 stopp=1;
159 for(i=0; i<MAXLIN; i++)
160 	linestop[i]=0;
161 for(i=0; i<nlin; i++)
162 	for(c=0; c<ncol; c++)
163 		{
164 		k = left(i,c,&junk);
165 		if (k>=0 && linestop[k]==0)
166 			linestop[k]= ++stopp;
167 		}
168 if (boxflg || allflg || dboxflg)
169 	linestop[0]=1;
170 }
171 
172 int
173 left(int i, int c, int *lwidp)
174 {
175 int kind, li, lj;
176 	/* returns -1 if no line to left */
177 	/* returns number of line where it starts */
178 	/* stores into lwid the kind of line */
179 *lwidp=0;
180 kind = lefdata(i,c);
181 if (kind==0) return(-1);
182 if (i+1<nlin)
183 if (lefdata(next(i),c)== kind) return(-1);
184 while (i>=0 && lefdata(i,c)==kind)
185 	i=prev(li=i);
186 if (prev(li)== -1) li=0;
187 *lwidp=kind;
188 for(lj= i+1; lj<li; lj++)
189 	if (instead[lj] && strcmp(instead[lj], ".TH")==0)
190 		return(li);
191 for(i= i+1; i<li; i++)
192 	if (fullbot[i])
193 		li=i;
194 return(li);
195 }
196 
197 int
198 lefdata(int i, int c)
199 {
200 int ck;
201 if (i>=nlin) i=nlin-1;
202 if (ctype(i,c) == 's')
203 	{
204 	for(ck=c; ctype(i,ck)=='s'; ck--);
205 	if (thish(i,ck)==0)
206 		return(0);
207 	}
208 i =stynum[i];
209 i = lefline[i][c];
210 if (i>0) return(i);
211 if (dboxflg && c==0) return(2);
212 if (allflg)return(1);
213 if (boxflg && c==0) return(1);
214 return(0);
215 }
216 
217 int
218 next(int i)
219 {
220 while (i+1 <nlin)
221 	{
222 	i++;
223 	if (!fullbot[i] && !instead[i]) break;
224 	}
225 return(i);
226 }
227 
228 int
229 prev(int i)
230 {
231 while (--i >=0  && (fullbot[i] || instead[i]))
232 	;
233 return(i);
234 }
235