1*381Smuffin /*
2*381Smuffin * Copyright 1990 Sun Microsystems, Inc. All rights reserved.
3*381Smuffin * Use is subject to license terms.
4*381Smuffin */
5*381Smuffin
60Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
70Sstevel@tonic-gate /* All Rights Reserved */
80Sstevel@tonic-gate
90Sstevel@tonic-gate /*
100Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California.
110Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement
120Sstevel@tonic-gate * specifies the terms and conditions for redistribution.
130Sstevel@tonic-gate */
140Sstevel@tonic-gate
15*381Smuffin #pragma ident "%Z%%M% %I% %E% SMI"
160Sstevel@tonic-gate
170Sstevel@tonic-gate /* tu.c: draws horizontal lines */
180Sstevel@tonic-gate # include "t..c"
19*381Smuffin
20*381Smuffin void drawline(int, int, int, int, int, int);
21*381Smuffin
22*381Smuffin void
makeline(int i,int c,int lintype)23*381Smuffin makeline(int i, int c, int lintype)
240Sstevel@tonic-gate {
250Sstevel@tonic-gate int cr, type, shortl;
260Sstevel@tonic-gate type = thish(i,c);
270Sstevel@tonic-gate if (type==0) return;
280Sstevel@tonic-gate cr=c;
290Sstevel@tonic-gate shortl = (table[i][c].col[0]=='\\');
300Sstevel@tonic-gate if (c>0 && !shortl && thish(i,c-1) == type)return;
310Sstevel@tonic-gate if (shortl==0)
320Sstevel@tonic-gate for(cr=c; cr < ncol && (ctype(i,cr)=='s'||type==thish(i,cr)); cr++);
330Sstevel@tonic-gate else
340Sstevel@tonic-gate for(cr=c+1; cr<ncol && ctype(i,cr)=='s'; cr++);
350Sstevel@tonic-gate drawline(i, c, cr-1, lintype, 0, shortl);
360Sstevel@tonic-gate }
37*381Smuffin
38*381Smuffin void
fullwide(int i,int lintype)39*381Smuffin fullwide(int i, int lintype)
400Sstevel@tonic-gate {
410Sstevel@tonic-gate int cr, cl;
420Sstevel@tonic-gate if (!pr1403)
430Sstevel@tonic-gate fprintf(tabout, ".nr %d \\n(.v\n.vs \\n(.vu-\\n(.sp\n", SVS);
440Sstevel@tonic-gate cr= 0;
450Sstevel@tonic-gate while (cr<ncol)
460Sstevel@tonic-gate {
470Sstevel@tonic-gate cl=cr;
480Sstevel@tonic-gate while (i>0 && vspand(prev(i),cl,1))
490Sstevel@tonic-gate cl++;
500Sstevel@tonic-gate for(cr=cl; cr<ncol; cr++)
510Sstevel@tonic-gate if (i>0 && vspand(prev(i),cr,1))
520Sstevel@tonic-gate break;
530Sstevel@tonic-gate if (cl<ncol)
540Sstevel@tonic-gate drawline(i,cl,(cr<ncol?cr-1:cr),lintype,1,0);
550Sstevel@tonic-gate }
560Sstevel@tonic-gate fprintf(tabout, "\n");
570Sstevel@tonic-gate if (!pr1403)
580Sstevel@tonic-gate fprintf(tabout, ".vs \\n(%du\n", SVS);
590Sstevel@tonic-gate }
600Sstevel@tonic-gate
61*381Smuffin void
drawline(int i,int cl,int cr,int lintype,int noheight,int shortl)62*381Smuffin drawline(int i, int cl, int cr, int lintype, int noheight, int shortl)
630Sstevel@tonic-gate {
640Sstevel@tonic-gate char *exhr, *exhl, *lnch;
650Sstevel@tonic-gate int lcount, ln, linpos, oldpos, nodata;
660Sstevel@tonic-gate lcount=0;
670Sstevel@tonic-gate exhr=exhl= "";
680Sstevel@tonic-gate switch(lintype)
690Sstevel@tonic-gate {
700Sstevel@tonic-gate case '-': lcount=1;break;
710Sstevel@tonic-gate case '=': lcount = pr1403? 1 : 2; break;
720Sstevel@tonic-gate case SHORTLINE: lcount=1; break;
730Sstevel@tonic-gate }
740Sstevel@tonic-gate if (lcount<=0) return;
750Sstevel@tonic-gate nodata = cr-cl>=ncol || noheight || allh(i);
760Sstevel@tonic-gate if (!nodata)
770Sstevel@tonic-gate fprintf(tabout, "\\v'-.5m'");
780Sstevel@tonic-gate for(ln=oldpos=0; ln<lcount; ln++)
790Sstevel@tonic-gate {
800Sstevel@tonic-gate linpos = 2*ln - lcount +1;
810Sstevel@tonic-gate if (linpos != oldpos)
820Sstevel@tonic-gate fprintf(tabout, "\\v'%dp'", linpos-oldpos);
830Sstevel@tonic-gate oldpos=linpos;
840Sstevel@tonic-gate if (shortl==0)
850Sstevel@tonic-gate {
860Sstevel@tonic-gate tohcol(cl);
870Sstevel@tonic-gate if (lcount>1)
880Sstevel@tonic-gate {
890Sstevel@tonic-gate switch(interv(i,cl))
900Sstevel@tonic-gate {
910Sstevel@tonic-gate case TOP: exhl = ln==0 ? "1p" : "-1p"; break;
920Sstevel@tonic-gate case BOT: exhl = ln==1 ? "1p" : "-1p"; break;
930Sstevel@tonic-gate case THRU: exhl = "1p"; break;
940Sstevel@tonic-gate }
950Sstevel@tonic-gate if (exhl[0])
960Sstevel@tonic-gate fprintf(tabout, "\\h'%s'", exhl);
970Sstevel@tonic-gate }
980Sstevel@tonic-gate else if (lcount==1)
990Sstevel@tonic-gate {
1000Sstevel@tonic-gate switch(interv(i,cl))
1010Sstevel@tonic-gate {
1020Sstevel@tonic-gate case TOP: case BOT: exhl = "-1p"; break;
1030Sstevel@tonic-gate case THRU: exhl = "1p"; break;
1040Sstevel@tonic-gate }
1050Sstevel@tonic-gate if (exhl[0])
1060Sstevel@tonic-gate fprintf(tabout, "\\h'%s'", exhl);
1070Sstevel@tonic-gate }
1080Sstevel@tonic-gate if (lcount>1)
1090Sstevel@tonic-gate {
1100Sstevel@tonic-gate switch(interv(i,cr+1))
1110Sstevel@tonic-gate {
1120Sstevel@tonic-gate case TOP: exhr = ln==0 ? "-1p" : "+1p"; break;
1130Sstevel@tonic-gate case BOT: exhr = ln==1 ? "-1p" : "+1p"; break;
1140Sstevel@tonic-gate case THRU: exhr = "-1p"; break;
1150Sstevel@tonic-gate }
1160Sstevel@tonic-gate }
1170Sstevel@tonic-gate else if (lcount==1)
1180Sstevel@tonic-gate {
1190Sstevel@tonic-gate switch(interv(i,cr+1))
1200Sstevel@tonic-gate {
1210Sstevel@tonic-gate case TOP: case BOT: exhr = "+1p"; break;
1220Sstevel@tonic-gate case THRU: exhr = "-1p"; break;
1230Sstevel@tonic-gate }
1240Sstevel@tonic-gate }
1250Sstevel@tonic-gate }
1260Sstevel@tonic-gate else
1270Sstevel@tonic-gate fprintf(tabout, "\\h'|\\n(%du'", cl+CLEFT);
1280Sstevel@tonic-gate fprintf(tabout, "\\s\\n(%d",LSIZE);
1290Sstevel@tonic-gate if (linsize)
1300Sstevel@tonic-gate fprintf(tabout, "\\v'-\\n(%dp/6u'", LSIZE);
1310Sstevel@tonic-gate if (shortl)
1320Sstevel@tonic-gate fprintf(tabout, "\\l'|\\n(%du'", cr+CRIGHT);
1330Sstevel@tonic-gate else
1340Sstevel@tonic-gate {
1350Sstevel@tonic-gate lnch = "\\(ul";
1360Sstevel@tonic-gate if (pr1403)
1370Sstevel@tonic-gate lnch = lintype==2 ? "=" : "\\(ru";
1380Sstevel@tonic-gate if (cr+1>=ncol)
1390Sstevel@tonic-gate fprintf(tabout, "\\l'|\\n(TWu%s%s'", exhr,lnch);
1400Sstevel@tonic-gate else
1410Sstevel@tonic-gate fprintf(tabout, "\\l'(|\\n(%du+|\\n(%du)/2u%s%s'", cr+CRIGHT,
1420Sstevel@tonic-gate cr+1+CLEFT, exhr, lnch);
1430Sstevel@tonic-gate }
1440Sstevel@tonic-gate if (linsize)
1450Sstevel@tonic-gate fprintf(tabout, "\\v'\\n(%dp/6u'", LSIZE);
1460Sstevel@tonic-gate fprintf(tabout, "\\s0");
1470Sstevel@tonic-gate }
1480Sstevel@tonic-gate if (oldpos!=0)
1490Sstevel@tonic-gate fprintf(tabout, "\\v'%dp'", -oldpos);
1500Sstevel@tonic-gate if (!nodata)
1510Sstevel@tonic-gate fprintf(tabout, "\\v'+.5m'");
1520Sstevel@tonic-gate }
153*381Smuffin
154*381Smuffin void
getstop(void)155*381Smuffin getstop(void)
1560Sstevel@tonic-gate {
1570Sstevel@tonic-gate int i,c,k,junk, stopp;
1580Sstevel@tonic-gate stopp=1;
1590Sstevel@tonic-gate for(i=0; i<MAXLIN; i++)
1600Sstevel@tonic-gate linestop[i]=0;
1610Sstevel@tonic-gate for(i=0; i<nlin; i++)
1620Sstevel@tonic-gate for(c=0; c<ncol; c++)
1630Sstevel@tonic-gate {
1640Sstevel@tonic-gate k = left(i,c,&junk);
1650Sstevel@tonic-gate if (k>=0 && linestop[k]==0)
1660Sstevel@tonic-gate linestop[k]= ++stopp;
1670Sstevel@tonic-gate }
1680Sstevel@tonic-gate if (boxflg || allflg || dboxflg)
1690Sstevel@tonic-gate linestop[0]=1;
1700Sstevel@tonic-gate }
171*381Smuffin
172*381Smuffin int
left(int i,int c,int * lwidp)173*381Smuffin left(int i, int c, int *lwidp)
1740Sstevel@tonic-gate {
1750Sstevel@tonic-gate int kind, li, lj;
1760Sstevel@tonic-gate /* returns -1 if no line to left */
1770Sstevel@tonic-gate /* returns number of line where it starts */
1780Sstevel@tonic-gate /* stores into lwid the kind of line */
1790Sstevel@tonic-gate *lwidp=0;
1800Sstevel@tonic-gate kind = lefdata(i,c);
1810Sstevel@tonic-gate if (kind==0) return(-1);
1820Sstevel@tonic-gate if (i+1<nlin)
1830Sstevel@tonic-gate if (lefdata(next(i),c)== kind) return(-1);
1840Sstevel@tonic-gate while (i>=0 && lefdata(i,c)==kind)
1850Sstevel@tonic-gate i=prev(li=i);
1860Sstevel@tonic-gate if (prev(li)== -1) li=0;
1870Sstevel@tonic-gate *lwidp=kind;
1880Sstevel@tonic-gate for(lj= i+1; lj<li; lj++)
1890Sstevel@tonic-gate if (instead[lj] && strcmp(instead[lj], ".TH")==0)
1900Sstevel@tonic-gate return(li);
1910Sstevel@tonic-gate for(i= i+1; i<li; i++)
1920Sstevel@tonic-gate if (fullbot[i])
1930Sstevel@tonic-gate li=i;
1940Sstevel@tonic-gate return(li);
1950Sstevel@tonic-gate }
196*381Smuffin
197*381Smuffin int
lefdata(int i,int c)198*381Smuffin lefdata(int i, int c)
1990Sstevel@tonic-gate {
2000Sstevel@tonic-gate int ck;
2010Sstevel@tonic-gate if (i>=nlin) i=nlin-1;
2020Sstevel@tonic-gate if (ctype(i,c) == 's')
2030Sstevel@tonic-gate {
2040Sstevel@tonic-gate for(ck=c; ctype(i,ck)=='s'; ck--);
2050Sstevel@tonic-gate if (thish(i,ck)==0)
2060Sstevel@tonic-gate return(0);
2070Sstevel@tonic-gate }
2080Sstevel@tonic-gate i =stynum[i];
2090Sstevel@tonic-gate i = lefline[i][c];
2100Sstevel@tonic-gate if (i>0) return(i);
2110Sstevel@tonic-gate if (dboxflg && c==0) return(2);
2120Sstevel@tonic-gate if (allflg)return(1);
2130Sstevel@tonic-gate if (boxflg && c==0) return(1);
2140Sstevel@tonic-gate return(0);
2150Sstevel@tonic-gate }
216*381Smuffin
217*381Smuffin int
next(int i)218*381Smuffin next(int i)
2190Sstevel@tonic-gate {
2200Sstevel@tonic-gate while (i+1 <nlin)
2210Sstevel@tonic-gate {
2220Sstevel@tonic-gate i++;
2230Sstevel@tonic-gate if (!fullbot[i] && !instead[i]) break;
2240Sstevel@tonic-gate }
2250Sstevel@tonic-gate return(i);
2260Sstevel@tonic-gate }
227*381Smuffin
228*381Smuffin int
prev(int i)229*381Smuffin prev(int i)
2300Sstevel@tonic-gate {
2310Sstevel@tonic-gate while (--i >=0 && (fullbot[i] || instead[i]))
2320Sstevel@tonic-gate ;
2330Sstevel@tonic-gate return(i);
2340Sstevel@tonic-gate }
235