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