xref: /onnv-gate/usr/src/cmd/tbl/t7.c (revision 381:1a7f0e46092a)
10Sstevel@tonic-gate /*
2*381Smuffin  * Copyright 1998 Sun Microsystems, Inc.  All rights reserved.
3*381Smuffin  * Use is subject to license terms.
40Sstevel@tonic-gate  */
50Sstevel@tonic-gate 
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  */
14*381Smuffin 
15*381Smuffin #pragma ident	"%Z%%M%	%I%	%E% SMI"
16*381Smuffin 
17*381Smuffin /* t7.c: control to write table entries */
180Sstevel@tonic-gate # include "t..c"
190Sstevel@tonic-gate # define realsplit ((ct=='a'||ct=='n') && table[ldata][c].rcol)
20*381Smuffin 
21*381Smuffin void	need(void);
22*381Smuffin void	deftail(void);
23*381Smuffin 
24*381Smuffin void
runout(void)25*381Smuffin runout(void)
260Sstevel@tonic-gate {
270Sstevel@tonic-gate int i;
280Sstevel@tonic-gate if (boxflg || allflg || dboxflg) need();
290Sstevel@tonic-gate if (ctrflg)
300Sstevel@tonic-gate 	{
310Sstevel@tonic-gate 	fprintf(tabout, ".nr #I \\n(.i\n");
320Sstevel@tonic-gate 	fprintf(tabout, ".in +(\\n(.lu-\\n(TWu-\\n(.iu)/2u\n");
330Sstevel@tonic-gate 	}
340Sstevel@tonic-gate fprintf(tabout, ".fc %c %c\n", F1, F2);
350Sstevel@tonic-gate fprintf(tabout, ".nr #T 0-1\n");
360Sstevel@tonic-gate deftail();
370Sstevel@tonic-gate for(i=0; i<nlin; i++)
380Sstevel@tonic-gate 	putline(i,i);
390Sstevel@tonic-gate if (leftover)
400Sstevel@tonic-gate 	yetmore();
410Sstevel@tonic-gate fprintf(tabout, ".fc\n");
420Sstevel@tonic-gate fprintf(tabout, ".nr T. 1\n");
430Sstevel@tonic-gate fprintf(tabout, ".T# 1\n");
440Sstevel@tonic-gate if (ctrflg)
450Sstevel@tonic-gate 	fprintf(tabout, ".in \\n(#Iu\n");
460Sstevel@tonic-gate }
47*381Smuffin 
48*381Smuffin void
runtabs(int lform,int ldata)49*381Smuffin runtabs(int lform, int ldata)
500Sstevel@tonic-gate {
510Sstevel@tonic-gate int c, ct, vforml, lf;
520Sstevel@tonic-gate fprintf(tabout, ".ta ");
530Sstevel@tonic-gate for(c=0; c<ncol; c++)
540Sstevel@tonic-gate 	{
550Sstevel@tonic-gate 	vforml=lform;
560Sstevel@tonic-gate 	for(lf=prev(lform); lf>=0 && vspen(table[lf][c].col); lf=prev(lf))
570Sstevel@tonic-gate 		vforml=lf;
580Sstevel@tonic-gate 	if (fspan(vforml,c))
590Sstevel@tonic-gate 		continue;
600Sstevel@tonic-gate 	switch(ct=ctype(vforml,c))
610Sstevel@tonic-gate 		{
620Sstevel@tonic-gate 		case 'n':
630Sstevel@tonic-gate 		case 'a':
640Sstevel@tonic-gate 			if (table[ldata][c].rcol)
650Sstevel@tonic-gate 			  if (lused[c]) /*Zero field width*/
660Sstevel@tonic-gate 				fprintf(tabout, "\\n(%du ",c+CMID);
670Sstevel@tonic-gate 		case 'c':
680Sstevel@tonic-gate 		case 'l':
690Sstevel@tonic-gate 		case 'r':
700Sstevel@tonic-gate 		    if (realsplit? rused[c]: (used[c]+lused[c]))
710Sstevel@tonic-gate 			fprintf(tabout, "\\n(%du ",c+CRIGHT);
720Sstevel@tonic-gate 			continue;
730Sstevel@tonic-gate 		case 's':
740Sstevel@tonic-gate 			if (lspan(lform, c))
750Sstevel@tonic-gate 				fprintf(tabout, "\\n(%du ", c+CRIGHT);
760Sstevel@tonic-gate 			continue;
770Sstevel@tonic-gate 		}
780Sstevel@tonic-gate 	}
790Sstevel@tonic-gate fprintf(tabout, "\n");
800Sstevel@tonic-gate }
81*381Smuffin 
82*381Smuffin int
ifline(char * s)83*381Smuffin ifline(char *s)
840Sstevel@tonic-gate {
850Sstevel@tonic-gate if (!point(s)) return(0);
860Sstevel@tonic-gate if (s[0] == '\\') s++;
870Sstevel@tonic-gate if (s[1] ) return(0);
880Sstevel@tonic-gate if (s[0] == '_') return('-');
890Sstevel@tonic-gate if (s[0] == '=') return('=');
900Sstevel@tonic-gate return(0);
910Sstevel@tonic-gate }
920Sstevel@tonic-gate 
93*381Smuffin void
need(void)94*381Smuffin need(void)
950Sstevel@tonic-gate {
960Sstevel@tonic-gate 	int texlin, horlin, i;
970Sstevel@tonic-gate 
980Sstevel@tonic-gate 	for(texlin = horlin = i = 0; i < nlin; i++) {
990Sstevel@tonic-gate 		if (allh(i))
1000Sstevel@tonic-gate 			horlin++;
1010Sstevel@tonic-gate 		else if (instead[i] != 0)
1020Sstevel@tonic-gate 			continue;
1030Sstevel@tonic-gate 		else
1040Sstevel@tonic-gate 			texlin++;
1050Sstevel@tonic-gate 	}
1060Sstevel@tonic-gate 	(void) fprintf(tabout, ".ne %dv+%dp\n", texlin, 2 * horlin);
1070Sstevel@tonic-gate 	/*
1080Sstevel@tonic-gate 	 * For nroff runs, we need to reserve space for the full height of the
1090Sstevel@tonic-gate 	 * horizontal rules.  If we don't reserve sufficient height, we'll have
1100Sstevel@tonic-gate 	 * problems trying to draw the vertical lines across the page boundary.
1110Sstevel@tonic-gate 	 */
1120Sstevel@tonic-gate 	(void) fprintf(tabout, ".if n .ne %dv\n", 2 * texlin + 2 * horlin + 2);
1130Sstevel@tonic-gate }
1140Sstevel@tonic-gate 
115*381Smuffin void
deftail(void)116*381Smuffin deftail(void)
1170Sstevel@tonic-gate {
1180Sstevel@tonic-gate int i, c, lf, lwid;
1190Sstevel@tonic-gate for(i=0; i<MAXHEAD; i++)
1200Sstevel@tonic-gate 	if (linestop[i])
1210Sstevel@tonic-gate 		fprintf(tabout, ".nr #%c 0-1\n", linestop[i]+'a'-1);
1220Sstevel@tonic-gate fprintf(tabout, ".nr #a 0-1\n");
1230Sstevel@tonic-gate fprintf(tabout, ".eo\n");
1240Sstevel@tonic-gate fprintf(tabout, ".de T#\n");
1250Sstevel@tonic-gate fprintf(tabout, ".ds #d .d\n");
1260Sstevel@tonic-gate fprintf(tabout, ".if \\(ts\\n(.z\\(ts\\(ts .ds #d nl\n");
1270Sstevel@tonic-gate 	fprintf(tabout, ".mk ##\n");
1280Sstevel@tonic-gate 	fprintf(tabout, ".nr ## -1v\n");
1290Sstevel@tonic-gate 	fprintf(tabout, ".ls 1\n");
1300Sstevel@tonic-gate 	for(i=0; i<MAXHEAD; i++)
1310Sstevel@tonic-gate 		if (linestop[i])
1320Sstevel@tonic-gate 			fprintf(tabout, ".if \\n(#T>=0 .nr #%c \\n(#T\n",linestop[i]+'a'-1);
1330Sstevel@tonic-gate if (boxflg || allflg || dboxflg) { /* bottom of table line */
1340Sstevel@tonic-gate 	if (!pr1403)
1350Sstevel@tonic-gate 		fprintf(tabout, ".if \\n(T. .vs \\n(.vu-\\n(.sp\n");
1360Sstevel@tonic-gate 	fprintf(tabout, ".if \\n(T. ");
1370Sstevel@tonic-gate 	drawline(nlin,0,ncol, dboxflg ? '=' : '-',1,0);
1380Sstevel@tonic-gate 	fprintf(tabout, "\n.if \\n(T. .vs\n");
1390Sstevel@tonic-gate 	/* T. is really an argument to a macro but because of
1400Sstevel@tonic-gate 		   eqn we don't dare pass it as an argument and reference by $1 */
1410Sstevel@tonic-gate }
1420Sstevel@tonic-gate 	for(c=0; c<ncol; c++)
1430Sstevel@tonic-gate 		{
1440Sstevel@tonic-gate 		if ((lf=left(nlin-1,c, &lwid))>=0)
1450Sstevel@tonic-gate 			{
1460Sstevel@tonic-gate 			fprintf(tabout, ".if \\n(#%c>=0 .sp -1\n",linestop[lf]+'a'-1);
1470Sstevel@tonic-gate 			fprintf(tabout, ".if \\n(#%c>=0 ", linestop[lf]+'a'-1);
1480Sstevel@tonic-gate 			tohcol(c);
1490Sstevel@tonic-gate 			drawvert(lf, nlin-1, c, lwid);
1500Sstevel@tonic-gate 			fprintf(tabout, "\\h'|\\n(TWu'\n");
1510Sstevel@tonic-gate 			}
1520Sstevel@tonic-gate 		}
1530Sstevel@tonic-gate 	if (boxflg || allflg || dboxflg) /* right hand line */
1540Sstevel@tonic-gate 		{
1550Sstevel@tonic-gate 		fprintf(tabout, ".if \\n(#a>=0 .sp -1\n");
1560Sstevel@tonic-gate 		fprintf(tabout, ".if \\n(#a>=0 \\h'|\\n(TWu'");
1570Sstevel@tonic-gate 		drawvert (0, nlin-1, ncol, dboxflg? 2 : 1);
1580Sstevel@tonic-gate 		fprintf(tabout, "\n");
1590Sstevel@tonic-gate 		}
1600Sstevel@tonic-gate fprintf(tabout, ".ls\n");
1610Sstevel@tonic-gate fprintf(tabout, "..\n");
1620Sstevel@tonic-gate fprintf(tabout, ".ec\n");
1630Sstevel@tonic-gate }
164