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 /* tv.c: draw vertical lines */
18# include "t..c"
19
20void
21drawvert(int start, int end, int c, int lwid)
22{
23char *exb=0, *ext=0;
24int tp=0, sl, ln, pos, epb, ept, vm;
25end++;
26vm='v';
27/* note: nr 35 has value of 1m outside of linesize */
28while (instead[end]) end++;
29for(ln=0; ln<lwid; ln++)
30	{
31	epb=ept=0;
32	pos = 2*ln-lwid+1;
33	if (pos!=tp) fprintf(tabout, "\\h'%dp'", pos-tp);
34	tp = pos;
35	if (end<nlin)
36		{
37		if (fullbot[end]|| (!instead[end] && allh(end)))
38			epb=2;
39		else
40		switch (midbar(end,c))
41			{
42			case '-':
43			exb = "1v-.5m"; break;
44			case '=':
45			exb = "1v-.5m";
46			epb = 1; break;
47			}
48		}
49	if (lwid>1)
50	switch(interh(end, c))
51		{
52		case THRU: epb -= 1; break;
53		case RIGHT: epb += (ln==0 ? 1 : -1); break;
54		case LEFT: epb += (ln==1 ? 1 : -1); break;
55		}
56	if (lwid==1)
57	switch(interh(end,c))
58		{
59		case THRU: epb -= 1; break;
60		case RIGHT: case LEFT: epb += 1; break;
61		}
62	if (start>0)
63		{
64		sl = start-1;
65		while (sl>=0 && instead[sl]) sl--;
66		if (sl>=0 && (fullbot[sl] || allh(sl)))
67			ept=0;
68		else
69		if (sl>=0)
70		switch(midbar(sl,c))
71			{
72			case '-':
73			ext = ".5m"; break;
74			case '=':
75			ext= ".5m"; ept = -1; break;
76			default:
77				vm = 'm'; break;
78			}
79		else
80			ept = -4;
81		}
82	else if (start==0 && allh(0))
83		{
84		ept=0;
85		vm = 'm';
86		}
87	if (lwid>1)
88		switch(interh(start,c))
89			{
90			case THRU: ept += 1; break;
91			case LEFT: ept += (ln==0 ? 1 : -1); break;
92			case RIGHT: ept += (ln==1 ? 1 : -1); break;
93			}
94	else if (lwid==1)
95		switch(interh(start,c))
96			{
97			case THRU: ept += 1; break;
98			case LEFT: case RIGHT: ept -= 1; break;
99			}
100	if (exb)
101		fprintf(tabout, "\\v'%s'", exb);
102	if (epb)
103		fprintf(tabout, "\\v'%dp'", epb);
104	fprintf(tabout, "\\s\\n(%d",LSIZE);
105	if (linsize)
106		fprintf(tabout, "\\v'-\\n(%dp/6u'", LSIZE);
107	fprintf(tabout, "\\h'-\\n(#~u'"); /* adjustment for T450 nroff boxes */
108	fprintf(tabout, "\\L'|\\n(#%cu-%s", linestop[start]+'a'-1, vm=='v'? "1v" : "\\n(35u");
109	if (ext)
110		fprintf(tabout, "-(%s)",ext);
111	if (exb)
112		fprintf(tabout, "-(%s)", exb);
113	pos = ept-epb;
114	if (pos)
115		fprintf(tabout, "%s%dp", pos>=0? "+" : "", pos);
116	/* the string #d is either "nl" or ".d" depending
117	   on diversions; on GCOS not the same */
118	fprintf(tabout, "'\\s0\\v'\\n(\\*(#du-\\n(#%cu+%s", linestop[start]+'a'-1,vm=='v' ? "1v" : "\\n(35u");
119	if (ext)
120		fprintf(tabout, "+%s",ext);
121	if (ept)
122		fprintf(tabout, "%s%dp", (-ept)>0 ? "+" : "", (-ept));
123	fprintf(tabout, "'");
124	if (linsize)
125		fprintf(tabout, "\\v'\\n(%dp/6u'", LSIZE);
126	}
127}
128
129int
130midbar(int i, int c)
131{
132int k;
133k = midbcol(i,c);
134if (k==0 && c>0)
135	k = midbcol(i, c-1);
136return(k);
137}
138
139int
140midbcol(int i, int c)
141{
142int ct;
143while ( (ct=ctype(i,c)) == 's')
144	c--;
145if (ct=='-' || ct == '=')
146	return(ct);
147if (ct=barent(table[i][c].col))
148	return(ct);
149return(0);
150}
151
152int
153barent(char *s)
154{
155if (s==0) return (1);
156if (!point(s)) return(1);
157if (s[0]== '\\') s++;
158if (s[1]!= 0)
159	return(0);
160switch(s[0])
161	{
162	case '_':
163		return('-');
164	case '=':
165		return('=');
166	}
167return(0);
168}
169