xref: /illumos-gate/usr/src/cmd/tbl/t7.c (revision 55fea89d)
17c478bd9Sstevel@tonic-gate /*
2b5514887Smuffin  * Copyright 1998 Sun Microsystems, Inc.  All rights reserved.
3b5514887Smuffin  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
5*55fea89dSDan Cross 
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  */
14b5514887Smuffin 
15b5514887Smuffin /* t7.c: control to write table entries */
167c478bd9Sstevel@tonic-gate # include "t..c"
177c478bd9Sstevel@tonic-gate # define realsplit ((ct=='a'||ct=='n') && table[ldata][c].rcol)
18b5514887Smuffin 
19b5514887Smuffin void	need(void);
20b5514887Smuffin void	deftail(void);
21b5514887Smuffin 
22b5514887Smuffin void
runout(void)23b5514887Smuffin runout(void)
247c478bd9Sstevel@tonic-gate {
257c478bd9Sstevel@tonic-gate int i;
267c478bd9Sstevel@tonic-gate if (boxflg || allflg || dboxflg) need();
277c478bd9Sstevel@tonic-gate if (ctrflg)
287c478bd9Sstevel@tonic-gate 	{
297c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr #I \\n(.i\n");
307c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".in +(\\n(.lu-\\n(TWu-\\n(.iu)/2u\n");
317c478bd9Sstevel@tonic-gate 	}
327c478bd9Sstevel@tonic-gate fprintf(tabout, ".fc %c %c\n", F1, F2);
337c478bd9Sstevel@tonic-gate fprintf(tabout, ".nr #T 0-1\n");
347c478bd9Sstevel@tonic-gate deftail();
357c478bd9Sstevel@tonic-gate for(i=0; i<nlin; i++)
367c478bd9Sstevel@tonic-gate 	putline(i,i);
377c478bd9Sstevel@tonic-gate if (leftover)
387c478bd9Sstevel@tonic-gate 	yetmore();
397c478bd9Sstevel@tonic-gate fprintf(tabout, ".fc\n");
407c478bd9Sstevel@tonic-gate fprintf(tabout, ".nr T. 1\n");
417c478bd9Sstevel@tonic-gate fprintf(tabout, ".T# 1\n");
427c478bd9Sstevel@tonic-gate if (ctrflg)
437c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".in \\n(#Iu\n");
447c478bd9Sstevel@tonic-gate }
45b5514887Smuffin 
46b5514887Smuffin void
runtabs(int lform,int ldata)47b5514887Smuffin runtabs(int lform, int ldata)
487c478bd9Sstevel@tonic-gate {
497c478bd9Sstevel@tonic-gate int c, ct, vforml, lf;
507c478bd9Sstevel@tonic-gate fprintf(tabout, ".ta ");
517c478bd9Sstevel@tonic-gate for(c=0; c<ncol; c++)
527c478bd9Sstevel@tonic-gate 	{
537c478bd9Sstevel@tonic-gate 	vforml=lform;
547c478bd9Sstevel@tonic-gate 	for(lf=prev(lform); lf>=0 && vspen(table[lf][c].col); lf=prev(lf))
557c478bd9Sstevel@tonic-gate 		vforml=lf;
567c478bd9Sstevel@tonic-gate 	if (fspan(vforml,c))
577c478bd9Sstevel@tonic-gate 		continue;
587c478bd9Sstevel@tonic-gate 	switch(ct=ctype(vforml,c))
597c478bd9Sstevel@tonic-gate 		{
607c478bd9Sstevel@tonic-gate 		case 'n':
617c478bd9Sstevel@tonic-gate 		case 'a':
627c478bd9Sstevel@tonic-gate 			if (table[ldata][c].rcol)
637c478bd9Sstevel@tonic-gate 			  if (lused[c]) /*Zero field width*/
647c478bd9Sstevel@tonic-gate 				fprintf(tabout, "\\n(%du ",c+CMID);
659807e130SToomas Soome 			/* FALLTHROUGH */
667c478bd9Sstevel@tonic-gate 		case 'c':
677c478bd9Sstevel@tonic-gate 		case 'l':
687c478bd9Sstevel@tonic-gate 		case 'r':
69f55f1fcbSToomas Soome 			if (realsplit? rused[c]: (used[c]+lused[c]))
70f55f1fcbSToomas Soome 				fprintf(tabout, "\\n(%du ",c+CRIGHT);
717c478bd9Sstevel@tonic-gate 			continue;
727c478bd9Sstevel@tonic-gate 		case 's':
737c478bd9Sstevel@tonic-gate 			if (lspan(lform, c))
747c478bd9Sstevel@tonic-gate 				fprintf(tabout, "\\n(%du ", c+CRIGHT);
757c478bd9Sstevel@tonic-gate 			continue;
767c478bd9Sstevel@tonic-gate 		}
777c478bd9Sstevel@tonic-gate 	}
787c478bd9Sstevel@tonic-gate fprintf(tabout, "\n");
797c478bd9Sstevel@tonic-gate }
80b5514887Smuffin 
81b5514887Smuffin int
ifline(char * s)82b5514887Smuffin ifline(char *s)
837c478bd9Sstevel@tonic-gate {
847c478bd9Sstevel@tonic-gate if (!point(s)) return(0);
857c478bd9Sstevel@tonic-gate if (s[0] == '\\') s++;
867c478bd9Sstevel@tonic-gate if (s[1] ) return(0);
877c478bd9Sstevel@tonic-gate if (s[0] == '_') return('-');
887c478bd9Sstevel@tonic-gate if (s[0] == '=') return('=');
897c478bd9Sstevel@tonic-gate return(0);
907c478bd9Sstevel@tonic-gate }
917c478bd9Sstevel@tonic-gate 
92b5514887Smuffin void
need(void)93b5514887Smuffin need(void)
947c478bd9Sstevel@tonic-gate {
957c478bd9Sstevel@tonic-gate 	int texlin, horlin, i;
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	for(texlin = horlin = i = 0; i < nlin; i++) {
987c478bd9Sstevel@tonic-gate 		if (allh(i))
997c478bd9Sstevel@tonic-gate 			horlin++;
1007c478bd9Sstevel@tonic-gate 		else if (instead[i] != 0)
1017c478bd9Sstevel@tonic-gate 			continue;
1027c478bd9Sstevel@tonic-gate 		else
1037c478bd9Sstevel@tonic-gate 			texlin++;
1047c478bd9Sstevel@tonic-gate 	}
1057c478bd9Sstevel@tonic-gate 	(void) fprintf(tabout, ".ne %dv+%dp\n", texlin, 2 * horlin);
1067c478bd9Sstevel@tonic-gate 	/*
1077c478bd9Sstevel@tonic-gate 	 * For nroff runs, we need to reserve space for the full height of the
1087c478bd9Sstevel@tonic-gate 	 * horizontal rules.  If we don't reserve sufficient height, we'll have
1097c478bd9Sstevel@tonic-gate 	 * problems trying to draw the vertical lines across the page boundary.
1107c478bd9Sstevel@tonic-gate 	 */
1117c478bd9Sstevel@tonic-gate 	(void) fprintf(tabout, ".if n .ne %dv\n", 2 * texlin + 2 * horlin + 2);
1127c478bd9Sstevel@tonic-gate }
1137c478bd9Sstevel@tonic-gate 
114b5514887Smuffin void
deftail(void)115b5514887Smuffin deftail(void)
1167c478bd9Sstevel@tonic-gate {
1177c478bd9Sstevel@tonic-gate int i, c, lf, lwid;
1187c478bd9Sstevel@tonic-gate for(i=0; i<MAXHEAD; i++)
1197c478bd9Sstevel@tonic-gate 	if (linestop[i])
1207c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".nr #%c 0-1\n", linestop[i]+'a'-1);
1217c478bd9Sstevel@tonic-gate fprintf(tabout, ".nr #a 0-1\n");
1227c478bd9Sstevel@tonic-gate fprintf(tabout, ".eo\n");
1237c478bd9Sstevel@tonic-gate fprintf(tabout, ".de T#\n");
1247c478bd9Sstevel@tonic-gate fprintf(tabout, ".ds #d .d\n");
1257c478bd9Sstevel@tonic-gate fprintf(tabout, ".if \\(ts\\n(.z\\(ts\\(ts .ds #d nl\n");
1267c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".mk ##\n");
1277c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr ## -1v\n");
1287c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".ls 1\n");
1297c478bd9Sstevel@tonic-gate 	for(i=0; i<MAXHEAD; i++)
1307c478bd9Sstevel@tonic-gate 		if (linestop[i])
1317c478bd9Sstevel@tonic-gate 			fprintf(tabout, ".if \\n(#T>=0 .nr #%c \\n(#T\n",linestop[i]+'a'-1);
1327c478bd9Sstevel@tonic-gate if (boxflg || allflg || dboxflg) { /* bottom of table line */
1337c478bd9Sstevel@tonic-gate 	if (!pr1403)
1347c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".if \\n(T. .vs \\n(.vu-\\n(.sp\n");
1357c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".if \\n(T. ");
1367c478bd9Sstevel@tonic-gate 	drawline(nlin,0,ncol, dboxflg ? '=' : '-',1,0);
1377c478bd9Sstevel@tonic-gate 	fprintf(tabout, "\n.if \\n(T. .vs\n");
138*55fea89dSDan Cross 	/* T. is really an argument to a macro but because of
1397c478bd9Sstevel@tonic-gate 		   eqn we don't dare pass it as an argument and reference by $1 */
1407c478bd9Sstevel@tonic-gate }
1417c478bd9Sstevel@tonic-gate 	for(c=0; c<ncol; c++)
1427c478bd9Sstevel@tonic-gate 		{
1437c478bd9Sstevel@tonic-gate 		if ((lf=left(nlin-1,c, &lwid))>=0)
1447c478bd9Sstevel@tonic-gate 			{
1457c478bd9Sstevel@tonic-gate 			fprintf(tabout, ".if \\n(#%c>=0 .sp -1\n",linestop[lf]+'a'-1);
1467c478bd9Sstevel@tonic-gate 			fprintf(tabout, ".if \\n(#%c>=0 ", linestop[lf]+'a'-1);
1477c478bd9Sstevel@tonic-gate 			tohcol(c);
1487c478bd9Sstevel@tonic-gate 			drawvert(lf, nlin-1, c, lwid);
1497c478bd9Sstevel@tonic-gate 			fprintf(tabout, "\\h'|\\n(TWu'\n");
1507c478bd9Sstevel@tonic-gate 			}
1517c478bd9Sstevel@tonic-gate 		}
1527c478bd9Sstevel@tonic-gate 	if (boxflg || allflg || dboxflg) /* right hand line */
1537c478bd9Sstevel@tonic-gate 		{
1547c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".if \\n(#a>=0 .sp -1\n");
1557c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".if \\n(#a>=0 \\h'|\\n(TWu'");
1567c478bd9Sstevel@tonic-gate 		drawvert (0, nlin-1, ncol, dboxflg? 2 : 1);
1577c478bd9Sstevel@tonic-gate 		fprintf(tabout, "\n");
1587c478bd9Sstevel@tonic-gate 		}
1597c478bd9Sstevel@tonic-gate fprintf(tabout, ".ls\n");
1607c478bd9Sstevel@tonic-gate fprintf(tabout, "..\n");
1617c478bd9Sstevel@tonic-gate fprintf(tabout, ".ec\n");
1627c478bd9Sstevel@tonic-gate }
163