xref: /titanic_53/usr/src/cmd/tbl/tv.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
2*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
3*7c478bd9Sstevel@tonic-gate 
4*7c478bd9Sstevel@tonic-gate 
5*7c478bd9Sstevel@tonic-gate /*
6*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
7*7c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
8*7c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
9*7c478bd9Sstevel@tonic-gate  */
10*7c478bd9Sstevel@tonic-gate 
11*7c478bd9Sstevel@tonic-gate /*
12*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
13*7c478bd9Sstevel@tonic-gate  * All Rights Reserved.
14*7c478bd9Sstevel@tonic-gate  */
15*7c478bd9Sstevel@tonic-gate 
16*7c478bd9Sstevel@tonic-gate #ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.1	*/
17*7c478bd9Sstevel@tonic-gate 
18*7c478bd9Sstevel@tonic-gate  /* tv.c: draw vertical lines */
19*7c478bd9Sstevel@tonic-gate # include "t..c"
20*7c478bd9Sstevel@tonic-gate drawvert(start,end, c, lwid)
21*7c478bd9Sstevel@tonic-gate {
22*7c478bd9Sstevel@tonic-gate char *exb=0, *ext=0;
23*7c478bd9Sstevel@tonic-gate int tp=0, sl, ln, pos, epb, ept, vm;
24*7c478bd9Sstevel@tonic-gate end++;
25*7c478bd9Sstevel@tonic-gate vm='v';
26*7c478bd9Sstevel@tonic-gate /* note: nr 35 has value of 1m outside of linesize */
27*7c478bd9Sstevel@tonic-gate while (instead[end]) end++;
28*7c478bd9Sstevel@tonic-gate for(ln=0; ln<lwid; ln++)
29*7c478bd9Sstevel@tonic-gate 	{
30*7c478bd9Sstevel@tonic-gate 	epb=ept=0;
31*7c478bd9Sstevel@tonic-gate 	pos = 2*ln-lwid+1;
32*7c478bd9Sstevel@tonic-gate 	if (pos!=tp) fprintf(tabout, "\\h'%dp'", pos-tp);
33*7c478bd9Sstevel@tonic-gate 	tp = pos;
34*7c478bd9Sstevel@tonic-gate 	if (end<nlin)
35*7c478bd9Sstevel@tonic-gate 		{
36*7c478bd9Sstevel@tonic-gate 		if (fullbot[end]|| (!instead[end] && allh(end)))
37*7c478bd9Sstevel@tonic-gate 			epb=2;
38*7c478bd9Sstevel@tonic-gate 		else
39*7c478bd9Sstevel@tonic-gate 		switch (midbar(end,c))
40*7c478bd9Sstevel@tonic-gate 			{
41*7c478bd9Sstevel@tonic-gate 			case '-':
42*7c478bd9Sstevel@tonic-gate 			exb = "1v-.5m"; break;
43*7c478bd9Sstevel@tonic-gate 			case '=':
44*7c478bd9Sstevel@tonic-gate 			exb = "1v-.5m";
45*7c478bd9Sstevel@tonic-gate 			epb = 1; break;
46*7c478bd9Sstevel@tonic-gate 			}
47*7c478bd9Sstevel@tonic-gate 		}
48*7c478bd9Sstevel@tonic-gate 	if (lwid>1)
49*7c478bd9Sstevel@tonic-gate 	switch(interh(end, c))
50*7c478bd9Sstevel@tonic-gate 		{
51*7c478bd9Sstevel@tonic-gate 		case THRU: epb -= 1; break;
52*7c478bd9Sstevel@tonic-gate 		case RIGHT: epb += (ln==0 ? 1 : -1); break;
53*7c478bd9Sstevel@tonic-gate 		case LEFT: epb += (ln==1 ? 1 : -1); break;
54*7c478bd9Sstevel@tonic-gate 		}
55*7c478bd9Sstevel@tonic-gate 	if (lwid==1)
56*7c478bd9Sstevel@tonic-gate 	switch(interh(end,c))
57*7c478bd9Sstevel@tonic-gate 		{
58*7c478bd9Sstevel@tonic-gate 		case THRU: epb -= 1; break;
59*7c478bd9Sstevel@tonic-gate 		case RIGHT: case LEFT: epb += 1; break;
60*7c478bd9Sstevel@tonic-gate 		}
61*7c478bd9Sstevel@tonic-gate 	if (start>0)
62*7c478bd9Sstevel@tonic-gate 		{
63*7c478bd9Sstevel@tonic-gate 		sl = start-1;
64*7c478bd9Sstevel@tonic-gate 		while (sl>=0 && instead[sl]) sl--;
65*7c478bd9Sstevel@tonic-gate 		if (sl>=0 && (fullbot[sl] || allh(sl)))
66*7c478bd9Sstevel@tonic-gate 			ept=0;
67*7c478bd9Sstevel@tonic-gate 		else
68*7c478bd9Sstevel@tonic-gate 		if (sl>=0)
69*7c478bd9Sstevel@tonic-gate 		switch(midbar(sl,c))
70*7c478bd9Sstevel@tonic-gate 			{
71*7c478bd9Sstevel@tonic-gate 			case '-':
72*7c478bd9Sstevel@tonic-gate 			ext = ".5m"; break;
73*7c478bd9Sstevel@tonic-gate 			case '=':
74*7c478bd9Sstevel@tonic-gate 			ext= ".5m"; ept = -1; break;
75*7c478bd9Sstevel@tonic-gate 			default:
76*7c478bd9Sstevel@tonic-gate 				vm = 'm'; break;
77*7c478bd9Sstevel@tonic-gate 			}
78*7c478bd9Sstevel@tonic-gate 		else
79*7c478bd9Sstevel@tonic-gate 			ept = -4;
80*7c478bd9Sstevel@tonic-gate 		}
81*7c478bd9Sstevel@tonic-gate 	else if (start==0 && allh(0))
82*7c478bd9Sstevel@tonic-gate 		{
83*7c478bd9Sstevel@tonic-gate 		ept=0;
84*7c478bd9Sstevel@tonic-gate 		vm = 'm';
85*7c478bd9Sstevel@tonic-gate 		}
86*7c478bd9Sstevel@tonic-gate 	if (lwid>1)
87*7c478bd9Sstevel@tonic-gate 		switch(interh(start,c))
88*7c478bd9Sstevel@tonic-gate 			{
89*7c478bd9Sstevel@tonic-gate 			case THRU: ept += 1; break;
90*7c478bd9Sstevel@tonic-gate 			case LEFT: ept += (ln==0 ? 1 : -1); break;
91*7c478bd9Sstevel@tonic-gate 			case RIGHT: ept += (ln==1 ? 1 : -1); break;
92*7c478bd9Sstevel@tonic-gate 			}
93*7c478bd9Sstevel@tonic-gate 	else if (lwid==1)
94*7c478bd9Sstevel@tonic-gate 		switch(interh(start,c))
95*7c478bd9Sstevel@tonic-gate 			{
96*7c478bd9Sstevel@tonic-gate 			case THRU: ept += 1; break;
97*7c478bd9Sstevel@tonic-gate 			case LEFT: case RIGHT: ept -= 1; break;
98*7c478bd9Sstevel@tonic-gate 			}
99*7c478bd9Sstevel@tonic-gate 	if (exb)
100*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, "\\v'%s'", exb);
101*7c478bd9Sstevel@tonic-gate 	if (epb)
102*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, "\\v'%dp'", epb);
103*7c478bd9Sstevel@tonic-gate 	fprintf(tabout, "\\s\\n(%d",LSIZE);
104*7c478bd9Sstevel@tonic-gate 	if (linsize)
105*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, "\\v'-\\n(%dp/6u'", LSIZE);
106*7c478bd9Sstevel@tonic-gate 	fprintf(tabout, "\\h'-\\n(#~u'"); /* adjustment for T450 nroff boxes */
107*7c478bd9Sstevel@tonic-gate 	fprintf(tabout, "\\L'|\\n(#%cu-%s", linestop[start]+'a'-1, vm=='v'? "1v" : "\\n(35u");
108*7c478bd9Sstevel@tonic-gate 	if (ext)
109*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, "-(%s)",ext);
110*7c478bd9Sstevel@tonic-gate 	if (exb)
111*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, "-(%s)", exb);
112*7c478bd9Sstevel@tonic-gate 	pos = ept-epb;
113*7c478bd9Sstevel@tonic-gate 	if (pos)
114*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, "%s%dp", pos>=0? "+" : "", pos);
115*7c478bd9Sstevel@tonic-gate 	/* the string #d is either "nl" or ".d" depending
116*7c478bd9Sstevel@tonic-gate 	   on diversions; on GCOS not the same */
117*7c478bd9Sstevel@tonic-gate 	fprintf(tabout, "'\\s0\\v'\\n(\\*(#du-\\n(#%cu+%s", linestop[start]+'a'-1,vm=='v' ? "1v" : "\\n(35u");
118*7c478bd9Sstevel@tonic-gate 	if (ext)
119*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, "+%s",ext);
120*7c478bd9Sstevel@tonic-gate 	if (ept)
121*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, "%s%dp", (-ept)>0 ? "+" : "", (-ept));
122*7c478bd9Sstevel@tonic-gate 	fprintf(tabout, "'");
123*7c478bd9Sstevel@tonic-gate 	if (linsize)
124*7c478bd9Sstevel@tonic-gate 		fprintf(tabout, "\\v'\\n(%dp/6u'", LSIZE);
125*7c478bd9Sstevel@tonic-gate 	}
126*7c478bd9Sstevel@tonic-gate }
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate midbar(i,c)
130*7c478bd9Sstevel@tonic-gate {
131*7c478bd9Sstevel@tonic-gate int k;
132*7c478bd9Sstevel@tonic-gate k = midbcol(i,c);
133*7c478bd9Sstevel@tonic-gate if (k==0 && c>0)
134*7c478bd9Sstevel@tonic-gate 	k = midbcol(i, c-1);
135*7c478bd9Sstevel@tonic-gate return(k);
136*7c478bd9Sstevel@tonic-gate }
137*7c478bd9Sstevel@tonic-gate midbcol(i,c)
138*7c478bd9Sstevel@tonic-gate {
139*7c478bd9Sstevel@tonic-gate int ct;
140*7c478bd9Sstevel@tonic-gate while ( (ct=ctype(i,c)) == 's')
141*7c478bd9Sstevel@tonic-gate 	c--;
142*7c478bd9Sstevel@tonic-gate if (ct=='-' || ct == '=')
143*7c478bd9Sstevel@tonic-gate 	return(ct);
144*7c478bd9Sstevel@tonic-gate if (ct=barent(table[i][c].col))
145*7c478bd9Sstevel@tonic-gate 	return(ct);
146*7c478bd9Sstevel@tonic-gate return(0);
147*7c478bd9Sstevel@tonic-gate }
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate barent(s)
150*7c478bd9Sstevel@tonic-gate 	char *s;
151*7c478bd9Sstevel@tonic-gate {
152*7c478bd9Sstevel@tonic-gate if (s==0) return (1);
153*7c478bd9Sstevel@tonic-gate if (!point(s)) return(1);
154*7c478bd9Sstevel@tonic-gate if (s[0]== '\\') s++;
155*7c478bd9Sstevel@tonic-gate if (s[1]!= 0)
156*7c478bd9Sstevel@tonic-gate 	return(0);
157*7c478bd9Sstevel@tonic-gate switch(s[0])
158*7c478bd9Sstevel@tonic-gate 	{
159*7c478bd9Sstevel@tonic-gate 	case '_':
160*7c478bd9Sstevel@tonic-gate 		return('-');
161*7c478bd9Sstevel@tonic-gate 	case '=':
162*7c478bd9Sstevel@tonic-gate 		return('=');
163*7c478bd9Sstevel@tonic-gate 	}
164*7c478bd9Sstevel@tonic-gate return(0);
165*7c478bd9Sstevel@tonic-gate }
166