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