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