summaryrefslogtreecommitdiff
path: root/usr/src/cmd/tbl/tv.c
blob: 77fa9c5881214c0344b53eea0612ace4269021d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * Copyright 1990 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
/*	  All Rights Reserved  	*/

/*
 * Copyright (c) 1980 Regents of the University of California.
 * All rights reserved. The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 */
  
#pragma ident	"%Z%%M%	%I%	%E% SMI"

 /* tv.c: draw vertical lines */
# include "t..c"

void
drawvert(int start, int end, int c, int lwid)
{
char *exb=0, *ext=0;
int tp=0, sl, ln, pos, epb, ept, vm;
end++;
vm='v';
/* note: nr 35 has value of 1m outside of linesize */
while (instead[end]) end++;
for(ln=0; ln<lwid; ln++)
	{
	epb=ept=0;
	pos = 2*ln-lwid+1;
	if (pos!=tp) fprintf(tabout, "\\h'%dp'", pos-tp);
	tp = pos;
	if (end<nlin)
		{
		if (fullbot[end]|| (!instead[end] && allh(end)))
			epb=2;
		else
		switch (midbar(end,c))
			{
			case '-':
			exb = "1v-.5m"; break;
			case '=':
			exb = "1v-.5m";
			epb = 1; break;
			}
		}
	if (lwid>1)
	switch(interh(end, c))
		{
		case THRU: epb -= 1; break;
		case RIGHT: epb += (ln==0 ? 1 : -1); break;
		case LEFT: epb += (ln==1 ? 1 : -1); break;
		}
	if (lwid==1)
	switch(interh(end,c))
		{
		case THRU: epb -= 1; break;
		case RIGHT: case LEFT: epb += 1; break;
		}
	if (start>0)
		{
		sl = start-1;
		while (sl>=0 && instead[sl]) sl--;
		if (sl>=0 && (fullbot[sl] || allh(sl)))
			ept=0;
		else
		if (sl>=0)
		switch(midbar(sl,c))
			{
			case '-':
			ext = ".5m"; break;
			case '=':
			ext= ".5m"; ept = -1; break;
			default:
				vm = 'm'; break;
			}
		else
			ept = -4;
		}
	else if (start==0 && allh(0))
		{
		ept=0;
		vm = 'm';
		}
	if (lwid>1)
		switch(interh(start,c))
			{
			case THRU: ept += 1; break;
			case LEFT: ept += (ln==0 ? 1 : -1); break;
			case RIGHT: ept += (ln==1 ? 1 : -1); break;
			}
	else if (lwid==1)
		switch(interh(start,c))
			{
			case THRU: ept += 1; break;
			case LEFT: case RIGHT: ept -= 1; break;
			}
	if (exb)
		fprintf(tabout, "\\v'%s'", exb);
	if (epb)
		fprintf(tabout, "\\v'%dp'", epb);
	fprintf(tabout, "\\s\\n(%d",LSIZE);
	if (linsize)
		fprintf(tabout, "\\v'-\\n(%dp/6u'", LSIZE);
	fprintf(tabout, "\\h'-\\n(#~u'"); /* adjustment for T450 nroff boxes */
	fprintf(tabout, "\\L'|\\n(#%cu-%s", linestop[start]+'a'-1, vm=='v'? "1v" : "\\n(35u");
	if (ext)
		fprintf(tabout, "-(%s)",ext);
	if (exb)
		fprintf(tabout, "-(%s)", exb);
	pos = ept-epb;
	if (pos)
		fprintf(tabout, "%s%dp", pos>=0? "+" : "", pos);
	/* the string #d is either "nl" or ".d" depending
	   on diversions; on GCOS not the same */
	fprintf(tabout, "'\\s0\\v'\\n(\\*(#du-\\n(#%cu+%s", linestop[start]+'a'-1,vm=='v' ? "1v" : "\\n(35u");
	if (ext)
		fprintf(tabout, "+%s",ext);
	if (ept)
		fprintf(tabout, "%s%dp", (-ept)>0 ? "+" : "", (-ept));
	fprintf(tabout, "'");
	if (linsize)
		fprintf(tabout, "\\v'\\n(%dp/6u'", LSIZE);
	}
}

int
midbar(int i, int c)
{
int k;
k = midbcol(i,c);
if (k==0 && c>0)
	k = midbcol(i, c-1);
return(k);
}

int
midbcol(int i, int c)
{
int ct;
while ( (ct=ctype(i,c)) == 's')
	c--;
if (ct=='-' || ct == '=')
	return(ct);
if (ct=barent(table[i][c].col))
	return(ct);
return(0);
}

int
barent(char *s)
{
if (s==0) return (1);
if (!point(s)) return(1);
if (s[0]== '\\') s++;
if (s[1]!= 0)
	return(0);
switch(s[0])
	{
	case '_':
		return('-');
	case '=':
		return('=');
	}
return(0);
}