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