1 /* $MirOS: src/usr.bin/oldroff/tbl/tv.c,v 1.3 2008/11/08 23:04:54 tg Exp $ */
2 
3 /*-
4  * Copyright (c) 1979, 1980, 1981, 1986, 1988, 1990, 1991, 1992
5  *     The Regents of the University of California.
6  * Copyright (C) Caldera International Inc.  2001-2002.
7  * Copyright (c) 2003, 2004
8  *	Thorsten "mirabilos" Glaser <tg@mirbsd.org>
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms,
12  * with or without modification, are permitted provided
13  * that the following conditions are met:
14  *
15  * Redistributions of source code and documentation must retain
16  * the above copyright notice, this list of conditions and the
17  * following disclaimer.  Redistributions in binary form must
18  * reproduce the above copyright notice, this list of conditions
19  * and the following disclaimer in the documentation and/or other
20  * materials provided with the distribution.
21  *
22  * All advertising materials mentioning features or use of this
23  * software must display the following acknowledgement:
24  *   This product includes software developed or owned by
25  *   Caldera International, Inc.
26  *
27  * Neither the name of Caldera International, Inc. nor the names
28  * of other contributors may be used to endorse or promote products
29  * derived from this software without specific prior written permission.
30  *
31  * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
32  * INTERNATIONAL, INC. AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
33  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35  * ARE DISCLAIMED.  IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
36  * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
37  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
39  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
40  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
41  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
42  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43  */
44 
45 /* tv.c: draw vertical lines */
46 
47 # include "t..c"
48 __SCCSID("@(#)tv.c	4.4 (Berkeley) 4/18/91");
49 __RCSID("$MirOS: src/usr.bin/oldroff/tbl/tv.c,v 1.3 2008/11/08 23:04:54 tg Exp $");
50 
drawvert(start,end,c,lwid)51 drawvert(start,end, c, lwid)
52 {
53 char *exb=0, *ext=0;
54 int tp=0, sl, ln, pos, epb, ept, vm;
55 end++;
56 vm='v';
57 /* note: nr 35 has value of 1m outside of linesize */
58 while (instead[end]) end++;
59 for(ln=0; ln<lwid; ln++)
60 	{
61 	epb=ept=0;
62 	pos = 2*ln-lwid+1;
63 	if (pos!=tp) fprintf(tabout, "\\h'%dp'", pos-tp);
64 	tp = pos;
65 	if (end<nlin)
66 		{
67 		if (fullbot[end]|| (!instead[end] && allh(end)))
68 			epb=2;
69 		else
70 		switch (midbar(end,c))
71 			{
72 			case '-':
73 			exb = "1v-.5m"; break;
74 			case '=':
75 			exb = "1v-.5m";
76 			epb = 1; break;
77 			}
78 		}
79 	if (lwid>1)
80 	switch(interh(end, c))
81 		{
82 		case THRU: epb -= 1; break;
83 		case RIGHT: epb += (ln==0 ? 1 : -1); break;
84 		case LEFT: epb += (ln==1 ? 1 : -1); break;
85 		}
86 	if (lwid==1)
87 	switch(interh(end,c))
88 		{
89 		case THRU: epb -= 1; break;
90 		case RIGHT: case LEFT: epb += 1; break;
91 		}
92 	if (start>0)
93 		{
94 		sl = start-1;
95 		while (sl>=0 && instead[sl]) sl--;
96 		if (sl>=0 && (fullbot[sl] || allh(sl)))
97 			ept=0;
98 		else
99 		if (sl>=0)
100 		switch(midbar(sl,c))
101 			{
102 			case '-':
103 			ext = ".5m"; break;
104 			case '=':
105 			ext= ".5m"; ept = -1; break;
106 			default:
107 				vm = 'm'; break;
108 			}
109 		else
110 			ept = -4;
111 		}
112 	else if (start==0 && allh(0))
113 		{
114 		ept=0;
115 		vm = 'm';
116 		}
117 	if (lwid>1)
118 		switch(interh(start,c))
119 			{
120 			case THRU: ept += 1; break;
121 			case LEFT: ept += (ln==0 ? 1 : -1); break;
122 			case RIGHT: ept += (ln==1 ? 1 : -1); break;
123 			}
124 	else if (lwid==1)
125 		switch(interh(start,c))
126 			{
127 			case THRU: ept += 1; break;
128 			case LEFT: case RIGHT: ept -= 1; break;
129 			}
130 	if (exb)
131 		fprintf(tabout, "\\v'%s'", exb);
132 	if (epb)
133 		fprintf(tabout, "\\v'%dp'", epb);
134 	fprintf(tabout, "\\s\\n(%d",LSIZE);
135 	if (linsize)
136 		fprintf(tabout, "\\v'-\\n(%dp/6u'", LSIZE);
137 	fprintf(tabout, "\\h'-\\n(#~u'"); /* adjustment for T450 nroff boxes */
138 	fprintf(tabout, "\\L'|\\n(#%cu-%s", linestop[start]+'a'-1, vm=='v'? "1v" : "\\n(35u");
139 	if (ext)
140 		fprintf(tabout, "-(%s)",ext);
141 	if (exb)
142 		fprintf(tabout, "-(%s)", exb);
143 	pos = ept-epb;
144 	if (pos)
145 		fprintf(tabout, "%s%dp", pos>=0? "+" : "", pos);
146 	/* the string #d is either "nl" or ".d" depending
147 	   on diversions; on GCOS not the same */
148 	fprintf(tabout, "'\\s0\\v'\\n(\\*(#du-\\n(#%cu+%s", linestop[start]+'a'-1,vm=='v' ? "1v" : "\\n(35u");
149 	if (ext)
150 		fprintf(tabout, "+%s",ext);
151 	if (ept)
152 		fprintf(tabout, "%s%dp", (-ept)>0 ? "+" : "", (-ept));
153 	fprintf(tabout, "'");
154 	if (linsize)
155 		fprintf(tabout, "\\v'\\n(%dp/6u'", LSIZE);
156 	}
157 }
158 
159 
midbar(i,c)160 midbar(i,c)
161 {
162 int k;
163 k = midbcol(i,c);
164 if (k==0 && c>0)
165 	k = midbcol(i, c-1);
166 return(k);
167 }
midbcol(i,c)168 midbcol(i,c)
169 {
170 int ct;
171 while ( (ct=ctype(i,c)) == 's')
172 	c--;
173 if (ct=='-' || ct == '=')
174 	return(ct);
175 if (ct=barent(table[i][c].col))
176 	return(ct);
177 return(0);
178 }
179 
barent(s)180 barent(s)
181 	char *s;
182 {
183 if (s==0) return (1);
184 if (!point(s)) return(1);
185 if (s[0]== '\\') s++;
186 if (s[1]!= 0)
187 	return(0);
188 switch(s[0])
189 	{
190 	case '_':
191 		return('-');
192 	case '=':
193 		return('=');
194 	}
195 return(0);
196 }
197