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