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