xref: /onnv-gate/usr/src/cmd/tbl/tv.c (revision 381:1a7f0e46092a)
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  /* tv.c: draw vertical lines */
180Sstevel@tonic-gate # include "t..c"
19*381Smuffin 
20*381Smuffin void
drawvert(int start,int end,int c,int lwid)21*381Smuffin drawvert(int start, int end, int c, int lwid)
220Sstevel@tonic-gate {
230Sstevel@tonic-gate char *exb=0, *ext=0;
240Sstevel@tonic-gate int tp=0, sl, ln, pos, epb, ept, vm;
250Sstevel@tonic-gate end++;
260Sstevel@tonic-gate vm='v';
270Sstevel@tonic-gate /* note: nr 35 has value of 1m outside of linesize */
280Sstevel@tonic-gate while (instead[end]) end++;
290Sstevel@tonic-gate for(ln=0; ln<lwid; ln++)
300Sstevel@tonic-gate 	{
310Sstevel@tonic-gate 	epb=ept=0;
320Sstevel@tonic-gate 	pos = 2*ln-lwid+1;
330Sstevel@tonic-gate 	if (pos!=tp) fprintf(tabout, "\\h'%dp'", pos-tp);
340Sstevel@tonic-gate 	tp = pos;
350Sstevel@tonic-gate 	if (end<nlin)
360Sstevel@tonic-gate 		{
370Sstevel@tonic-gate 		if (fullbot[end]|| (!instead[end] && allh(end)))
380Sstevel@tonic-gate 			epb=2;
390Sstevel@tonic-gate 		else
400Sstevel@tonic-gate 		switch (midbar(end,c))
410Sstevel@tonic-gate 			{
420Sstevel@tonic-gate 			case '-':
430Sstevel@tonic-gate 			exb = "1v-.5m"; break;
440Sstevel@tonic-gate 			case '=':
450Sstevel@tonic-gate 			exb = "1v-.5m";
460Sstevel@tonic-gate 			epb = 1; break;
470Sstevel@tonic-gate 			}
480Sstevel@tonic-gate 		}
490Sstevel@tonic-gate 	if (lwid>1)
500Sstevel@tonic-gate 	switch(interh(end, c))
510Sstevel@tonic-gate 		{
520Sstevel@tonic-gate 		case THRU: epb -= 1; break;
530Sstevel@tonic-gate 		case RIGHT: epb += (ln==0 ? 1 : -1); break;
540Sstevel@tonic-gate 		case LEFT: epb += (ln==1 ? 1 : -1); break;
550Sstevel@tonic-gate 		}
560Sstevel@tonic-gate 	if (lwid==1)
570Sstevel@tonic-gate 	switch(interh(end,c))
580Sstevel@tonic-gate 		{
590Sstevel@tonic-gate 		case THRU: epb -= 1; break;
600Sstevel@tonic-gate 		case RIGHT: case LEFT: epb += 1; break;
610Sstevel@tonic-gate 		}
620Sstevel@tonic-gate 	if (start>0)
630Sstevel@tonic-gate 		{
640Sstevel@tonic-gate 		sl = start-1;
650Sstevel@tonic-gate 		while (sl>=0 && instead[sl]) sl--;
660Sstevel@tonic-gate 		if (sl>=0 && (fullbot[sl] || allh(sl)))
670Sstevel@tonic-gate 			ept=0;
680Sstevel@tonic-gate 		else
690Sstevel@tonic-gate 		if (sl>=0)
700Sstevel@tonic-gate 		switch(midbar(sl,c))
710Sstevel@tonic-gate 			{
720Sstevel@tonic-gate 			case '-':
730Sstevel@tonic-gate 			ext = ".5m"; break;
740Sstevel@tonic-gate 			case '=':
750Sstevel@tonic-gate 			ext= ".5m"; ept = -1; break;
760Sstevel@tonic-gate 			default:
770Sstevel@tonic-gate 				vm = 'm'; break;
780Sstevel@tonic-gate 			}
790Sstevel@tonic-gate 		else
800Sstevel@tonic-gate 			ept = -4;
810Sstevel@tonic-gate 		}
820Sstevel@tonic-gate 	else if (start==0 && allh(0))
830Sstevel@tonic-gate 		{
840Sstevel@tonic-gate 		ept=0;
850Sstevel@tonic-gate 		vm = 'm';
860Sstevel@tonic-gate 		}
870Sstevel@tonic-gate 	if (lwid>1)
880Sstevel@tonic-gate 		switch(interh(start,c))
890Sstevel@tonic-gate 			{
900Sstevel@tonic-gate 			case THRU: ept += 1; break;
910Sstevel@tonic-gate 			case LEFT: ept += (ln==0 ? 1 : -1); break;
920Sstevel@tonic-gate 			case RIGHT: ept += (ln==1 ? 1 : -1); break;
930Sstevel@tonic-gate 			}
940Sstevel@tonic-gate 	else if (lwid==1)
950Sstevel@tonic-gate 		switch(interh(start,c))
960Sstevel@tonic-gate 			{
970Sstevel@tonic-gate 			case THRU: ept += 1; break;
980Sstevel@tonic-gate 			case LEFT: case RIGHT: ept -= 1; break;
990Sstevel@tonic-gate 			}
1000Sstevel@tonic-gate 	if (exb)
1010Sstevel@tonic-gate 		fprintf(tabout, "\\v'%s'", exb);
1020Sstevel@tonic-gate 	if (epb)
1030Sstevel@tonic-gate 		fprintf(tabout, "\\v'%dp'", epb);
1040Sstevel@tonic-gate 	fprintf(tabout, "\\s\\n(%d",LSIZE);
1050Sstevel@tonic-gate 	if (linsize)
1060Sstevel@tonic-gate 		fprintf(tabout, "\\v'-\\n(%dp/6u'", LSIZE);
1070Sstevel@tonic-gate 	fprintf(tabout, "\\h'-\\n(#~u'"); /* adjustment for T450 nroff boxes */
1080Sstevel@tonic-gate 	fprintf(tabout, "\\L'|\\n(#%cu-%s", linestop[start]+'a'-1, vm=='v'? "1v" : "\\n(35u");
1090Sstevel@tonic-gate 	if (ext)
1100Sstevel@tonic-gate 		fprintf(tabout, "-(%s)",ext);
1110Sstevel@tonic-gate 	if (exb)
1120Sstevel@tonic-gate 		fprintf(tabout, "-(%s)", exb);
1130Sstevel@tonic-gate 	pos = ept-epb;
1140Sstevel@tonic-gate 	if (pos)
1150Sstevel@tonic-gate 		fprintf(tabout, "%s%dp", pos>=0? "+" : "", pos);
1160Sstevel@tonic-gate 	/* the string #d is either "nl" or ".d" depending
1170Sstevel@tonic-gate 	   on diversions; on GCOS not the same */
1180Sstevel@tonic-gate 	fprintf(tabout, "'\\s0\\v'\\n(\\*(#du-\\n(#%cu+%s", linestop[start]+'a'-1,vm=='v' ? "1v" : "\\n(35u");
1190Sstevel@tonic-gate 	if (ext)
1200Sstevel@tonic-gate 		fprintf(tabout, "+%s",ext);
1210Sstevel@tonic-gate 	if (ept)
1220Sstevel@tonic-gate 		fprintf(tabout, "%s%dp", (-ept)>0 ? "+" : "", (-ept));
1230Sstevel@tonic-gate 	fprintf(tabout, "'");
1240Sstevel@tonic-gate 	if (linsize)
1250Sstevel@tonic-gate 		fprintf(tabout, "\\v'\\n(%dp/6u'", LSIZE);
1260Sstevel@tonic-gate 	}
1270Sstevel@tonic-gate }
1280Sstevel@tonic-gate 
129*381Smuffin int
midbar(int i,int c)130*381Smuffin midbar(int i, int c)
1310Sstevel@tonic-gate {
1320Sstevel@tonic-gate int k;
1330Sstevel@tonic-gate k = midbcol(i,c);
1340Sstevel@tonic-gate if (k==0 && c>0)
1350Sstevel@tonic-gate 	k = midbcol(i, c-1);
1360Sstevel@tonic-gate return(k);
1370Sstevel@tonic-gate }
138*381Smuffin 
139*381Smuffin int
midbcol(int i,int c)140*381Smuffin midbcol(int i, int c)
1410Sstevel@tonic-gate {
1420Sstevel@tonic-gate int ct;
1430Sstevel@tonic-gate while ( (ct=ctype(i,c)) == 's')
1440Sstevel@tonic-gate 	c--;
1450Sstevel@tonic-gate if (ct=='-' || ct == '=')
1460Sstevel@tonic-gate 	return(ct);
1470Sstevel@tonic-gate if (ct=barent(table[i][c].col))
1480Sstevel@tonic-gate 	return(ct);
1490Sstevel@tonic-gate return(0);
1500Sstevel@tonic-gate }
1510Sstevel@tonic-gate 
152*381Smuffin int
barent(char * s)153*381Smuffin barent(char *s)
1540Sstevel@tonic-gate {
1550Sstevel@tonic-gate if (s==0) return (1);
1560Sstevel@tonic-gate if (!point(s)) return(1);
1570Sstevel@tonic-gate if (s[0]== '\\') s++;
1580Sstevel@tonic-gate if (s[1]!= 0)
1590Sstevel@tonic-gate 	return(0);
1600Sstevel@tonic-gate switch(s[0])
1610Sstevel@tonic-gate 	{
1620Sstevel@tonic-gate 	case '_':
1630Sstevel@tonic-gate 		return('-');
1640Sstevel@tonic-gate 	case '=':
1650Sstevel@tonic-gate 		return('=');
1660Sstevel@tonic-gate 	}
1670Sstevel@tonic-gate return(0);
1680Sstevel@tonic-gate }
169