Commit | Line | Data |
---|---|---|
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 | 8 | static 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" | |
13 | makeline(i,c,lintype) | |
14 | { | |
15 | int cr, type, shortl; | |
16 | type = thish(i,c); | |
17 | if (type==0) return; | |
18 | cr=c; | |
19 | shortl = (table[i][c].col[0]=='\\'); | |
20 | if (c>0 && !shortl && thish(i,c-1) == type)return; | |
21 | if (shortl==0) | |
22 | for(cr=c; cr < ncol && (ctype(i,cr)=='s'||type==thish(i,cr)); cr++); | |
23 | else | |
24 | for(cr=c+1; cr<ncol && ctype(i,cr)=='s'; cr++); | |
25 | drawline(i, c, cr-1, lintype, 0, shortl); | |
26 | } | |
27 | fullwide(i, lintype) | |
28 | { | |
29 | int cr, cl; | |
30 | if (!pr1403) | |
31 | fprintf(tabout, ".nr %d \\n(.v\n.vs \\n(.vu-\\n(.sp\n", SVS); | |
32 | cr= 0; | |
33 | while (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 | } | |
44 | fprintf(tabout, "\n"); | |
45 | if (!pr1403) | |
46 | fprintf(tabout, ".vs \\n(%du\n", SVS); | |
47 | } | |
48 | ||
49 | drawline(i, cl, cr, lintype, noheight, shortl) | |
50 | { | |
bdbc9c90 KB |
51 | char *exhr, *exhl, *lnch; |
52 | int lcount, ln, linpos, oldpos, nodata; | |
550f4efd BS |
53 | lcount=0; |
54 | exhr=exhl= ""; | |
55 | switch(lintype) | |
56 | { | |
57 | case '-': lcount=1;break; | |
58 | case '=': lcount = pr1403? 1 : 2; break; | |
59 | case SHORTLINE: lcount=1; break; | |
60 | } | |
61 | if (lcount<=0) return; | |
62 | nodata = cr-cl>=ncol || noheight || allh(i); | |
63 | if (!nodata) | |
64 | fprintf(tabout, "\\v'-.5m'"); | |
65 | for(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 | } | |
135 | if (oldpos!=0) | |
136 | fprintf(tabout, "\\v'%dp'", -oldpos); | |
137 | if (!nodata) | |
138 | fprintf(tabout, "\\v'+.5m'"); | |
139 | } | |
140 | getstop() | |
141 | { | |
142 | int i,c,k,junk, stopp; | |
143 | stopp=1; | |
144 | for(i=0; i<MAXLIN; i++) | |
145 | linestop[i]=0; | |
146 | for(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 | } | |
153 | if (boxflg || allflg || dboxflg) | |
154 | linestop[0]=1; | |
155 | } | |
156 | left(i,c, lwidp) | |
157 | int *lwidp; | |
158 | { | |
159 | int 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; | |
164 | kind = lefdata(i,c); | |
165 | if (kind==0) return(-1); | |
166 | if (i+1<nlin) | |
167 | if (lefdata(next(i),c)== kind) return(-1); | |
168 | while (i>=0 && lefdata(i,c)==kind) | |
169 | i=prev(li=i); | |
170 | if (prev(li)== -1) li=0; | |
171 | *lwidp=kind; | |
172 | for(lj= i+1; lj<li; lj++) | |
173 | if (instead[lj] && strcmp(instead[lj], ".TH")==0) | |
174 | return(li); | |
175 | for(i= i+1; i<li; i++) | |
176 | if (fullbot[i]) | |
177 | li=i; | |
178 | return(li); | |
179 | } | |
180 | lefdata(i,c) | |
181 | { | |
182 | int ck; | |
183 | if (i>=nlin) i=nlin-1; | |
184 | if (ctype(i,c) == 's') | |
185 | { | |
186 | for(ck=c; ctype(i,ck)=='s'; ck--); | |
187 | if (thish(i,ck)==0) | |
188 | return(0); | |
189 | } | |
190 | i =stynum[i]; | |
191 | i = lefline[i][c]; | |
192 | if (i>0) return(i); | |
193 | if (dboxflg && c==0) return(2); | |
194 | if (allflg)return(1); | |
195 | if (boxflg && c==0) return(1); | |
196 | return(0); | |
197 | } | |
198 | next(i) | |
199 | { | |
200 | while (i+1 <nlin) | |
201 | { | |
202 | i++; | |
203 | if (!fullbot[i] && !instead[i]) break; | |
204 | } | |
205 | return(i); | |
206 | } | |
207 | prev(i) | |
208 | { | |
209 | while (--i >=0 && (fullbot[i] || instead[i])) | |
210 | ; | |
211 | return(i); | |
212 | } |