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