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