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