BSD 4_4 release
[unix-history] / usr / src / old / tbl / tu.c
CommitLineData
94bed826 1/*-
ad787160
C
2 * This module is believed to contain source code proprietary to AT&T.
3 * Use and redistribution is subject to the Berkeley Software License
4 * Agreement and your Software Agreement with AT&T (Western Electric).
94bed826
KB
5 */
6
476fcd16 7#ifndef lint
ad787160 8static char sccsid[] = "@(#)tu.c 4.4 (Berkeley) 4/18/91";
94bed826 9#endif /* not lint */
550f4efd
BS
10
11 /* tu.c: draws horizontal lines */
12# include "t..c"
13makeline(i,c,lintype)
14{
15int cr, type, shortl;
16type = thish(i,c);
17if (type==0) return;
18cr=c;
19shortl = (table[i][c].col[0]=='\\');
20if (c>0 && !shortl && thish(i,c-1) == type)return;
21if (shortl==0)
22 for(cr=c; cr < ncol && (ctype(i,cr)=='s'||type==thish(i,cr)); cr++);
23else
24 for(cr=c+1; cr<ncol && ctype(i,cr)=='s'; cr++);
25drawline(i, c, cr-1, lintype, 0, shortl);
26}
27fullwide(i, lintype)
28{
29int cr, cl;
30if (!pr1403)
31 fprintf(tabout, ".nr %d \\n(.v\n.vs \\n(.vu-\\n(.sp\n", SVS);
32cr= 0;
33while (cr<ncol)
34 {
35 cl=cr;
36 while (i>0 && vspand(prev(i),cl,1))
37 cl++;
38 for(cr=cl; cr<ncol; cr++)
39 if (i>0 && vspand(prev(i),cr,1))
40 break;
41 if (cl<ncol)
42 drawline(i,cl,(cr<ncol?cr-1:cr),lintype,1,0);
43 }
44fprintf(tabout, "\n");
45if (!pr1403)
46 fprintf(tabout, ".vs \\n(%du\n", SVS);
47}
48
49drawline(i, cl, cr, lintype, noheight, shortl)
50{
bdbc9c90
KB
51 char *exhr, *exhl, *lnch;
52 int lcount, ln, linpos, oldpos, nodata;
550f4efd
BS
53lcount=0;
54exhr=exhl= "";
55switch(lintype)
56 {
57 case '-': lcount=1;break;
58 case '=': lcount = pr1403? 1 : 2; break;
59 case SHORTLINE: lcount=1; break;
60 }
61if (lcount<=0) return;
62nodata = cr-cl>=ncol || noheight || allh(i);
63 if (!nodata)
64 fprintf(tabout, "\\v'-.5m'");
65for(ln=oldpos=0; ln<lcount; ln++)
66 {
67 linpos = 2*ln - lcount +1;
68 if (linpos != oldpos)
69 fprintf(tabout, "\\v'%dp'", linpos-oldpos);
70 oldpos=linpos;
71 if (shortl==0)
72 {
73 tohcol(cl);
74 if (lcount>1)
75 {
76 switch(interv(i,cl))
77 {
78 case TOP: exhl = ln==0 ? "1p" : "-1p"; break;
79 case BOT: exhl = ln==1 ? "1p" : "-1p"; break;
80 case THRU: exhl = "1p"; break;
81 }
82 if (exhl[0])
83 fprintf(tabout, "\\h'%s'", exhl);
84 }
85 else if (lcount==1)
86 {
87 switch(interv(i,cl))
88 {
89 case TOP: case BOT: exhl = "-1p"; break;
90 case THRU: exhl = "1p"; break;
91 }
92 if (exhl[0])
93 fprintf(tabout, "\\h'%s'", exhl);
94 }
95 if (lcount>1)
96 {
97 switch(interv(i,cr+1))
98 {
99 case TOP: exhr = ln==0 ? "-1p" : "+1p"; break;
100 case BOT: exhr = ln==1 ? "-1p" : "+1p"; break;
101 case THRU: exhr = "-1p"; break;
102 }
103 }
104 else if (lcount==1)
105 {
106 switch(interv(i,cr+1))
107 {
108 case TOP: case BOT: exhr = "+1p"; break;
109 case THRU: exhr = "-1p"; break;
110 }
111 }
112 }
113 else
114 fprintf(tabout, "\\h'|\\n(%du'", cl+CLEFT);
115 fprintf(tabout, "\\s\\n(%d",LSIZE);
116 if (linsize)
117 fprintf(tabout, "\\v'-\\n(%dp/6u'", LSIZE);
118 if (shortl)
119 fprintf(tabout, "\\l'|\\n(%du'", cr+CRIGHT);
120 else
121 {
122 lnch = "\\(ul";
123 if (pr1403)
124 lnch = lintype==2 ? "=" : "\\(ru";
125 if (cr+1>=ncol)
126 fprintf(tabout, "\\l'|\\n(TWu%s%s'", exhr,lnch);
127 else
128 fprintf(tabout, "\\l'(|\\n(%du+|\\n(%du)/2u%s%s'", cr+CRIGHT,
129 cr+1+CLEFT, exhr, lnch);
130 }
131 if (linsize)
132 fprintf(tabout, "\\v'\\n(%dp/6u'", LSIZE);
133 fprintf(tabout, "\\s0");
134 }
135if (oldpos!=0)
136 fprintf(tabout, "\\v'%dp'", -oldpos);
137if (!nodata)
138 fprintf(tabout, "\\v'+.5m'");
139}
140getstop()
141{
142int i,c,k,junk, stopp;
143stopp=1;
144for(i=0; i<MAXLIN; i++)
145 linestop[i]=0;
146for(i=0; i<nlin; i++)
147 for(c=0; c<ncol; c++)
148 {
149 k = left(i,c,&junk);
150 if (k>=0 && linestop[k]==0)
151 linestop[k]= ++stopp;
152 }
153if (boxflg || allflg || dboxflg)
154 linestop[0]=1;
155}
156left(i,c, lwidp)
157 int *lwidp;
158{
159int kind, li, lj;
160 /* returns -1 if no line to left */
161 /* returns number of line where it starts */
162 /* stores into lwid the kind of line */
163*lwidp=0;
164kind = lefdata(i,c);
165if (kind==0) return(-1);
166if (i+1<nlin)
167if (lefdata(next(i),c)== kind) return(-1);
168while (i>=0 && lefdata(i,c)==kind)
169 i=prev(li=i);
170if (prev(li)== -1) li=0;
171*lwidp=kind;
172for(lj= i+1; lj<li; lj++)
173 if (instead[lj] && strcmp(instead[lj], ".TH")==0)
174 return(li);
175for(i= i+1; i<li; i++)
176 if (fullbot[i])
177 li=i;
178return(li);
179}
180lefdata(i,c)
181{
182int ck;
183if (i>=nlin) i=nlin-1;
184if (ctype(i,c) == 's')
185 {
186 for(ck=c; ctype(i,ck)=='s'; ck--);
187 if (thish(i,ck)==0)
188 return(0);
189 }
190i =stynum[i];
191i = lefline[i][c];
192if (i>0) return(i);
193if (dboxflg && c==0) return(2);
194if (allflg)return(1);
195if (boxflg && c==0) return(1);
196return(0);
197}
198next(i)
199{
200while (i+1 <nlin)
201 {
202 i++;
203 if (!fullbot[i] && !instead[i]) break;
204 }
205return(i);
206}
207prev(i)
208{
209while (--i >=0 && (fullbot[i] || instead[i]))
210 ;
211return(i);
212}