xref: /titanic_51/usr/src/cmd/tbl/tu.c (revision b55148877d473978f0b46d593fd6213fa526fcc5)
1*b5514887Smuffin /*
2*b5514887Smuffin  * Copyright 1990 Sun Microsystems, Inc.  All rights reserved.
3*b5514887Smuffin  * Use is subject to license terms.
4*b5514887Smuffin  */
5*b5514887Smuffin 
67c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
77c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
117c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
127c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
137c478bd9Sstevel@tonic-gate  */
147c478bd9Sstevel@tonic-gate 
15*b5514887Smuffin #pragma ident	"%Z%%M%	%I%	%E% SMI"
167c478bd9Sstevel@tonic-gate 
177c478bd9Sstevel@tonic-gate  /* tu.c: draws horizontal lines */
187c478bd9Sstevel@tonic-gate # include "t..c"
19*b5514887Smuffin 
20*b5514887Smuffin void	drawline(int, int, int, int, int, int);
21*b5514887Smuffin 
22*b5514887Smuffin void
23*b5514887Smuffin makeline(int i, int c, int lintype)
247c478bd9Sstevel@tonic-gate {
257c478bd9Sstevel@tonic-gate int cr, type, shortl;
267c478bd9Sstevel@tonic-gate type = thish(i,c);
277c478bd9Sstevel@tonic-gate if (type==0) return;
287c478bd9Sstevel@tonic-gate cr=c;
297c478bd9Sstevel@tonic-gate shortl = (table[i][c].col[0]=='\\');
307c478bd9Sstevel@tonic-gate if (c>0 && !shortl && thish(i,c-1) == type)return;
317c478bd9Sstevel@tonic-gate if (shortl==0)
327c478bd9Sstevel@tonic-gate 	for(cr=c; cr < ncol && (ctype(i,cr)=='s'||type==thish(i,cr)); cr++);
337c478bd9Sstevel@tonic-gate else
347c478bd9Sstevel@tonic-gate 	for(cr=c+1; cr<ncol && ctype(i,cr)=='s'; cr++);
357c478bd9Sstevel@tonic-gate drawline(i, c, cr-1, lintype, 0, shortl);
367c478bd9Sstevel@tonic-gate }
37*b5514887Smuffin 
38*b5514887Smuffin void
39*b5514887Smuffin fullwide(int i, int lintype)
407c478bd9Sstevel@tonic-gate {
417c478bd9Sstevel@tonic-gate int cr, cl;
427c478bd9Sstevel@tonic-gate if (!pr1403)
437c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr %d \\n(.v\n.vs \\n(.vu-\\n(.sp\n", SVS);
447c478bd9Sstevel@tonic-gate cr= 0;
457c478bd9Sstevel@tonic-gate while (cr<ncol)
467c478bd9Sstevel@tonic-gate 	{
477c478bd9Sstevel@tonic-gate 	cl=cr;
487c478bd9Sstevel@tonic-gate 	while (i>0 && vspand(prev(i),cl,1))
497c478bd9Sstevel@tonic-gate 		cl++;
507c478bd9Sstevel@tonic-gate 	for(cr=cl; cr<ncol; cr++)
517c478bd9Sstevel@tonic-gate 		if (i>0 && vspand(prev(i),cr,1))
527c478bd9Sstevel@tonic-gate 			break;
537c478bd9Sstevel@tonic-gate 	if (cl<ncol)
547c478bd9Sstevel@tonic-gate 	drawline(i,cl,(cr<ncol?cr-1:cr),lintype,1,0);
557c478bd9Sstevel@tonic-gate 	}
567c478bd9Sstevel@tonic-gate fprintf(tabout, "\n");
577c478bd9Sstevel@tonic-gate if (!pr1403)
587c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".vs \\n(%du\n", SVS);
597c478bd9Sstevel@tonic-gate }
607c478bd9Sstevel@tonic-gate 
61*b5514887Smuffin void
62*b5514887Smuffin drawline(int i, int cl, int cr, int lintype, int noheight, int shortl)
637c478bd9Sstevel@tonic-gate {
647c478bd9Sstevel@tonic-gate 	char *exhr, *exhl, *lnch;
657c478bd9Sstevel@tonic-gate 	int lcount, ln, linpos, oldpos, nodata;
667c478bd9Sstevel@tonic-gate lcount=0;
677c478bd9Sstevel@tonic-gate exhr=exhl= "";
687c478bd9Sstevel@tonic-gate switch(lintype)
697c478bd9Sstevel@tonic-gate 	{
707c478bd9Sstevel@tonic-gate 	case '-': lcount=1;break;
717c478bd9Sstevel@tonic-gate 	case '=': lcount = pr1403? 1 : 2; break;
727c478bd9Sstevel@tonic-gate 	case SHORTLINE: lcount=1; break;
737c478bd9Sstevel@tonic-gate 	}
747c478bd9Sstevel@tonic-gate if (lcount<=0) return;
757c478bd9Sstevel@tonic-gate nodata = cr-cl>=ncol || noheight || allh(i);
767c478bd9Sstevel@tonic-gate 	if (!nodata)
777c478bd9Sstevel@tonic-gate 		fprintf(tabout, "\\v'-.5m'");
787c478bd9Sstevel@tonic-gate for(ln=oldpos=0; ln<lcount; ln++)
797c478bd9Sstevel@tonic-gate 	{
807c478bd9Sstevel@tonic-gate 	linpos = 2*ln - lcount +1;
817c478bd9Sstevel@tonic-gate 	if (linpos != oldpos)
827c478bd9Sstevel@tonic-gate 		fprintf(tabout, "\\v'%dp'", linpos-oldpos);
837c478bd9Sstevel@tonic-gate 	oldpos=linpos;
847c478bd9Sstevel@tonic-gate 	if (shortl==0)
857c478bd9Sstevel@tonic-gate 	{
867c478bd9Sstevel@tonic-gate 	tohcol(cl);
877c478bd9Sstevel@tonic-gate 	if (lcount>1)
887c478bd9Sstevel@tonic-gate 		{
897c478bd9Sstevel@tonic-gate 		switch(interv(i,cl))
907c478bd9Sstevel@tonic-gate 			{
917c478bd9Sstevel@tonic-gate 			case TOP: exhl = ln==0 ? "1p" : "-1p"; break;
927c478bd9Sstevel@tonic-gate 			case BOT: exhl = ln==1 ? "1p" : "-1p"; break;
937c478bd9Sstevel@tonic-gate 			case THRU: exhl = "1p"; break;
947c478bd9Sstevel@tonic-gate 			}
957c478bd9Sstevel@tonic-gate 		if (exhl[0])
967c478bd9Sstevel@tonic-gate 		fprintf(tabout, "\\h'%s'", exhl);
977c478bd9Sstevel@tonic-gate 		}
987c478bd9Sstevel@tonic-gate 	else if (lcount==1)
997c478bd9Sstevel@tonic-gate 		{
1007c478bd9Sstevel@tonic-gate 		switch(interv(i,cl))
1017c478bd9Sstevel@tonic-gate 			{
1027c478bd9Sstevel@tonic-gate 			case TOP: case BOT: exhl = "-1p"; break;
1037c478bd9Sstevel@tonic-gate 			case THRU: exhl = "1p"; break;
1047c478bd9Sstevel@tonic-gate 			}
1057c478bd9Sstevel@tonic-gate 		if (exhl[0])
1067c478bd9Sstevel@tonic-gate 		fprintf(tabout, "\\h'%s'", exhl);
1077c478bd9Sstevel@tonic-gate 		}
1087c478bd9Sstevel@tonic-gate 	if (lcount>1)
1097c478bd9Sstevel@tonic-gate 		{
1107c478bd9Sstevel@tonic-gate 		switch(interv(i,cr+1))
1117c478bd9Sstevel@tonic-gate 			{
1127c478bd9Sstevel@tonic-gate 			case TOP: exhr = ln==0 ? "-1p" : "+1p"; break;
1137c478bd9Sstevel@tonic-gate 			case BOT: exhr = ln==1 ? "-1p" : "+1p"; break;
1147c478bd9Sstevel@tonic-gate 			case THRU: exhr = "-1p"; break;
1157c478bd9Sstevel@tonic-gate 			}
1167c478bd9Sstevel@tonic-gate 		}
1177c478bd9Sstevel@tonic-gate 	else if (lcount==1)
1187c478bd9Sstevel@tonic-gate 		{
1197c478bd9Sstevel@tonic-gate 		switch(interv(i,cr+1))
1207c478bd9Sstevel@tonic-gate 			{
1217c478bd9Sstevel@tonic-gate 			case TOP: case BOT: exhr = "+1p"; break;
1227c478bd9Sstevel@tonic-gate 			case THRU: exhr = "-1p"; break;
1237c478bd9Sstevel@tonic-gate 			}
1247c478bd9Sstevel@tonic-gate 		}
1257c478bd9Sstevel@tonic-gate 	}
1267c478bd9Sstevel@tonic-gate 	else
1277c478bd9Sstevel@tonic-gate 		fprintf(tabout, "\\h'|\\n(%du'", cl+CLEFT);
1287c478bd9Sstevel@tonic-gate 	fprintf(tabout, "\\s\\n(%d",LSIZE);
1297c478bd9Sstevel@tonic-gate 	if (linsize)
1307c478bd9Sstevel@tonic-gate 		fprintf(tabout, "\\v'-\\n(%dp/6u'", LSIZE);
1317c478bd9Sstevel@tonic-gate 	if (shortl)
1327c478bd9Sstevel@tonic-gate 		fprintf(tabout, "\\l'|\\n(%du'", cr+CRIGHT);
1337c478bd9Sstevel@tonic-gate 	else
1347c478bd9Sstevel@tonic-gate 	{
1357c478bd9Sstevel@tonic-gate 	lnch = "\\(ul";
1367c478bd9Sstevel@tonic-gate 	if (pr1403)
1377c478bd9Sstevel@tonic-gate 		lnch = lintype==2 ? "=" : "\\(ru";
1387c478bd9Sstevel@tonic-gate 	if (cr+1>=ncol)
1397c478bd9Sstevel@tonic-gate 		fprintf(tabout, "\\l'|\\n(TWu%s%s'", exhr,lnch);
1407c478bd9Sstevel@tonic-gate 	else
1417c478bd9Sstevel@tonic-gate 		fprintf(tabout, "\\l'(|\\n(%du+|\\n(%du)/2u%s%s'", cr+CRIGHT,
1427c478bd9Sstevel@tonic-gate 			cr+1+CLEFT, exhr, lnch);
1437c478bd9Sstevel@tonic-gate 	}
1447c478bd9Sstevel@tonic-gate 	if (linsize)
1457c478bd9Sstevel@tonic-gate 		fprintf(tabout, "\\v'\\n(%dp/6u'", LSIZE);
1467c478bd9Sstevel@tonic-gate 	fprintf(tabout, "\\s0");
1477c478bd9Sstevel@tonic-gate 	}
1487c478bd9Sstevel@tonic-gate if (oldpos!=0)
1497c478bd9Sstevel@tonic-gate 	fprintf(tabout, "\\v'%dp'", -oldpos);
1507c478bd9Sstevel@tonic-gate if (!nodata)
1517c478bd9Sstevel@tonic-gate 	fprintf(tabout, "\\v'+.5m'");
1527c478bd9Sstevel@tonic-gate }
153*b5514887Smuffin 
154*b5514887Smuffin void
155*b5514887Smuffin getstop(void)
1567c478bd9Sstevel@tonic-gate {
1577c478bd9Sstevel@tonic-gate int i,c,k,junk, stopp;
1587c478bd9Sstevel@tonic-gate stopp=1;
1597c478bd9Sstevel@tonic-gate for(i=0; i<MAXLIN; i++)
1607c478bd9Sstevel@tonic-gate 	linestop[i]=0;
1617c478bd9Sstevel@tonic-gate for(i=0; i<nlin; i++)
1627c478bd9Sstevel@tonic-gate 	for(c=0; c<ncol; c++)
1637c478bd9Sstevel@tonic-gate 		{
1647c478bd9Sstevel@tonic-gate 		k = left(i,c,&junk);
1657c478bd9Sstevel@tonic-gate 		if (k>=0 && linestop[k]==0)
1667c478bd9Sstevel@tonic-gate 			linestop[k]= ++stopp;
1677c478bd9Sstevel@tonic-gate 		}
1687c478bd9Sstevel@tonic-gate if (boxflg || allflg || dboxflg)
1697c478bd9Sstevel@tonic-gate 	linestop[0]=1;
1707c478bd9Sstevel@tonic-gate }
171*b5514887Smuffin 
172*b5514887Smuffin int
173*b5514887Smuffin left(int i, int c, int *lwidp)
1747c478bd9Sstevel@tonic-gate {
1757c478bd9Sstevel@tonic-gate int kind, li, lj;
1767c478bd9Sstevel@tonic-gate 	/* returns -1 if no line to left */
1777c478bd9Sstevel@tonic-gate 	/* returns number of line where it starts */
1787c478bd9Sstevel@tonic-gate 	/* stores into lwid the kind of line */
1797c478bd9Sstevel@tonic-gate *lwidp=0;
1807c478bd9Sstevel@tonic-gate kind = lefdata(i,c);
1817c478bd9Sstevel@tonic-gate if (kind==0) return(-1);
1827c478bd9Sstevel@tonic-gate if (i+1<nlin)
1837c478bd9Sstevel@tonic-gate if (lefdata(next(i),c)== kind) return(-1);
1847c478bd9Sstevel@tonic-gate while (i>=0 && lefdata(i,c)==kind)
1857c478bd9Sstevel@tonic-gate 	i=prev(li=i);
1867c478bd9Sstevel@tonic-gate if (prev(li)== -1) li=0;
1877c478bd9Sstevel@tonic-gate *lwidp=kind;
1887c478bd9Sstevel@tonic-gate for(lj= i+1; lj<li; lj++)
1897c478bd9Sstevel@tonic-gate 	if (instead[lj] && strcmp(instead[lj], ".TH")==0)
1907c478bd9Sstevel@tonic-gate 		return(li);
1917c478bd9Sstevel@tonic-gate for(i= i+1; i<li; i++)
1927c478bd9Sstevel@tonic-gate 	if (fullbot[i])
1937c478bd9Sstevel@tonic-gate 		li=i;
1947c478bd9Sstevel@tonic-gate return(li);
1957c478bd9Sstevel@tonic-gate }
196*b5514887Smuffin 
197*b5514887Smuffin int
198*b5514887Smuffin lefdata(int i, int c)
1997c478bd9Sstevel@tonic-gate {
2007c478bd9Sstevel@tonic-gate int ck;
2017c478bd9Sstevel@tonic-gate if (i>=nlin) i=nlin-1;
2027c478bd9Sstevel@tonic-gate if (ctype(i,c) == 's')
2037c478bd9Sstevel@tonic-gate 	{
2047c478bd9Sstevel@tonic-gate 	for(ck=c; ctype(i,ck)=='s'; ck--);
2057c478bd9Sstevel@tonic-gate 	if (thish(i,ck)==0)
2067c478bd9Sstevel@tonic-gate 		return(0);
2077c478bd9Sstevel@tonic-gate 	}
2087c478bd9Sstevel@tonic-gate i =stynum[i];
2097c478bd9Sstevel@tonic-gate i = lefline[i][c];
2107c478bd9Sstevel@tonic-gate if (i>0) return(i);
2117c478bd9Sstevel@tonic-gate if (dboxflg && c==0) return(2);
2127c478bd9Sstevel@tonic-gate if (allflg)return(1);
2137c478bd9Sstevel@tonic-gate if (boxflg && c==0) return(1);
2147c478bd9Sstevel@tonic-gate return(0);
2157c478bd9Sstevel@tonic-gate }
216*b5514887Smuffin 
217*b5514887Smuffin int
218*b5514887Smuffin next(int i)
2197c478bd9Sstevel@tonic-gate {
2207c478bd9Sstevel@tonic-gate while (i+1 <nlin)
2217c478bd9Sstevel@tonic-gate 	{
2227c478bd9Sstevel@tonic-gate 	i++;
2237c478bd9Sstevel@tonic-gate 	if (!fullbot[i] && !instead[i]) break;
2247c478bd9Sstevel@tonic-gate 	}
2257c478bd9Sstevel@tonic-gate return(i);
2267c478bd9Sstevel@tonic-gate }
227*b5514887Smuffin 
228*b5514887Smuffin int
229*b5514887Smuffin prev(int i)
2307c478bd9Sstevel@tonic-gate {
2317c478bd9Sstevel@tonic-gate while (--i >=0  && (fullbot[i] || instead[i]))
2327c478bd9Sstevel@tonic-gate 	;
2337c478bd9Sstevel@tonic-gate return(i);
2347c478bd9Sstevel@tonic-gate }
235