xref: /titanic_52/usr/src/cmd/tbl/t6.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 /*
117c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
127c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
137c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
147c478bd9Sstevel@tonic-gate  */
157c478bd9Sstevel@tonic-gate 
16*b5514887Smuffin #pragma ident	"%Z%%M%	%I%	%E% SMI"
177c478bd9Sstevel@tonic-gate 
187c478bd9Sstevel@tonic-gate  /* t6.c: compute tab stops */
197c478bd9Sstevel@tonic-gate # define tx(a) (a>(char *)0 && a<(char *)128)
207c478bd9Sstevel@tonic-gate # include "t..c"
21*b5514887Smuffin 
22*b5514887Smuffin void	wide(char *, char *, char *);
23*b5514887Smuffin 
24*b5514887Smuffin void
25*b5514887Smuffin maktab(void)
267c478bd9Sstevel@tonic-gate {
277c478bd9Sstevel@tonic-gate # define FN(i,c) font[stynum[i]][c]
287c478bd9Sstevel@tonic-gate # define SZ(i,c) csize[stynum[i]][c]
297c478bd9Sstevel@tonic-gate /* define the tab stops of the table */
307c478bd9Sstevel@tonic-gate int icol, ilin, tsep, k, ik, vforml, il, text;
317c478bd9Sstevel@tonic-gate int doubled[MAXCOL], acase[MAXCOL];
327c478bd9Sstevel@tonic-gate char *s;
337c478bd9Sstevel@tonic-gate for(icol=0; icol <ncol; icol++)
347c478bd9Sstevel@tonic-gate 	{
357c478bd9Sstevel@tonic-gate 	doubled[icol] = acase[icol] = 0;
367c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr %d 0\n", icol+CRIGHT);
377c478bd9Sstevel@tonic-gate    for(text=0; text<2; text++)
387c478bd9Sstevel@tonic-gate 	{
397c478bd9Sstevel@tonic-gate 	if (text)
407c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".%02d\n.rm %02d\n", icol+80, icol+80);
417c478bd9Sstevel@tonic-gate 	for(ilin=0; ilin<nlin; ilin++)
427c478bd9Sstevel@tonic-gate 		{
437c478bd9Sstevel@tonic-gate 		if (instead[ilin]|| fullbot[ilin]) continue;
447c478bd9Sstevel@tonic-gate 		vforml=ilin;
457c478bd9Sstevel@tonic-gate 		for(il=prev(ilin); il>=0 && vspen(table[il][icol].col); il=prev(il))
467c478bd9Sstevel@tonic-gate 			vforml=il;
477c478bd9Sstevel@tonic-gate 		if (fspan(vforml,icol)) continue;
487c478bd9Sstevel@tonic-gate 		if (filler(table[ilin][icol].col)) continue;
497c478bd9Sstevel@tonic-gate 		switch(ctype(vforml,icol))
507c478bd9Sstevel@tonic-gate 			{
517c478bd9Sstevel@tonic-gate 			case 'a':
527c478bd9Sstevel@tonic-gate 				acase[icol]=1;
537c478bd9Sstevel@tonic-gate 				s = table[ilin][icol].col;
547c478bd9Sstevel@tonic-gate 				if (s>(char *)0 && s<(char *)128 && text)
557c478bd9Sstevel@tonic-gate 					{
567c478bd9Sstevel@tonic-gate 					if (doubled[icol]==0)
577c478bd9Sstevel@tonic-gate 						fprintf(tabout, ".nr %d 0\n.nr %d 0\n",S1,S2);
587c478bd9Sstevel@tonic-gate 					doubled[icol]=1;
597c478bd9Sstevel@tonic-gate 					fprintf(tabout, ".if \\n(%c->\\n(%d .nr %d \\n(%c-\n",s,S2,S2,s);
607c478bd9Sstevel@tonic-gate 					}
617c478bd9Sstevel@tonic-gate 			case 'n':
627c478bd9Sstevel@tonic-gate 				if (table[ilin][icol].rcol!=0)
637c478bd9Sstevel@tonic-gate 					{
647c478bd9Sstevel@tonic-gate 					if (doubled[icol]==0 && text==0)
657c478bd9Sstevel@tonic-gate 						fprintf(tabout, ".nr %d 0\n.nr %d 0\n", S1, S2);
667c478bd9Sstevel@tonic-gate 					doubled[icol]=1;
677c478bd9Sstevel@tonic-gate 					if (real(s=table[ilin][icol].col) && !vspen(s))
687c478bd9Sstevel@tonic-gate 						{
697c478bd9Sstevel@tonic-gate 						if (tx(s) != text) continue;
707c478bd9Sstevel@tonic-gate 						fprintf(tabout, ".nr %d ", TMP);
717c478bd9Sstevel@tonic-gate 						wide(s, FN(vforml,icol), SZ(vforml,icol)); fprintf(tabout, "\n");
727c478bd9Sstevel@tonic-gate 						fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n", S1, TMP, S1, TMP);
737c478bd9Sstevel@tonic-gate 						}
747c478bd9Sstevel@tonic-gate 					if (text==0 && real(s=table[ilin][icol].rcol) && !vspen(s) && !barent(s))
757c478bd9Sstevel@tonic-gate 						{
767c478bd9Sstevel@tonic-gate 						fprintf(tabout, ".nr %d \\w%c%s%c\n",TMP, F1, s, F1);
777c478bd9Sstevel@tonic-gate 						fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n",S2,TMP,S2,TMP);
787c478bd9Sstevel@tonic-gate 						}
797c478bd9Sstevel@tonic-gate 					continue;
807c478bd9Sstevel@tonic-gate 					}
817c478bd9Sstevel@tonic-gate 			case 'r':
827c478bd9Sstevel@tonic-gate 			case 'c':
837c478bd9Sstevel@tonic-gate 			case 'l':
847c478bd9Sstevel@tonic-gate 				if (real(s=table[ilin][icol].col) && !vspen(s))
857c478bd9Sstevel@tonic-gate 					{
867c478bd9Sstevel@tonic-gate 					if (tx(s) != text) continue;
877c478bd9Sstevel@tonic-gate 					fprintf(tabout, ".nr %d ", TMP);
887c478bd9Sstevel@tonic-gate 					wide(s, FN(vforml,icol), SZ(vforml,icol)); fprintf(tabout, "\n");
897c478bd9Sstevel@tonic-gate 					fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n", icol+CRIGHT, TMP, icol+CRIGHT, TMP);
907c478bd9Sstevel@tonic-gate 					}
917c478bd9Sstevel@tonic-gate 			}
927c478bd9Sstevel@tonic-gate 		}
937c478bd9Sstevel@tonic-gate 		}
947c478bd9Sstevel@tonic-gate 	if (acase[icol])
957c478bd9Sstevel@tonic-gate 		{
967c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".if \\n(%d>=\\n(%d .nr %d \\n(%du+2n\n",S2,icol+CRIGHT,icol+CRIGHT,S2);
977c478bd9Sstevel@tonic-gate 		}
987c478bd9Sstevel@tonic-gate 	if (doubled[icol])
997c478bd9Sstevel@tonic-gate 		{
1007c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".nr %d \\n(%d\n", icol+CMID, S1);
1017c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".nr %d \\n(%d+\\n(%d\n",TMP,icol+CMID,S2);
1027c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".if \\n(%d>\\n(%d .nr %d \\n(%d\n",TMP,icol+CRIGHT,icol+CRIGHT,TMP);
1037c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d +(\\n(%d-\\n(%d)/2\n",TMP,icol+CRIGHT,icol+CMID,icol+CRIGHT,TMP);
1047c478bd9Sstevel@tonic-gate 		}
1057c478bd9Sstevel@tonic-gate 	if (cll[icol][0])
1067c478bd9Sstevel@tonic-gate 		{
1077c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".nr %d %sn\n", TMP, cll[icol]);
1087c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n",icol+CRIGHT, TMP, icol+CRIGHT, TMP);
1097c478bd9Sstevel@tonic-gate 		}
1107c478bd9Sstevel@tonic-gate 	for(ilin=0; ilin<nlin; ilin++)
1117c478bd9Sstevel@tonic-gate 	if (k=lspan(ilin, icol))
1127c478bd9Sstevel@tonic-gate 		{
1137c478bd9Sstevel@tonic-gate 		s=table[ilin][icol-k].col;
1147c478bd9Sstevel@tonic-gate 		if (!real(s) || barent(s) || vspen(s) ) continue;
1157c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".nr %d ", TMP);
1167c478bd9Sstevel@tonic-gate 		wide(table[ilin][icol-k].col, FN(ilin,icol-k), SZ(ilin,icol-k));
1177c478bd9Sstevel@tonic-gate 		for(ik=k; ik>=0; ik--)
1187c478bd9Sstevel@tonic-gate 			{
1197c478bd9Sstevel@tonic-gate 			fprintf(tabout, "-\\n(%d",CRIGHT+icol-ik);
1207c478bd9Sstevel@tonic-gate 			if (!expflg && ik>0) fprintf(tabout, "-%dn", sep[icol-ik]);
1217c478bd9Sstevel@tonic-gate 			}
1227c478bd9Sstevel@tonic-gate 		fprintf(tabout, "\n");
1237c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".if \\n(%d>0 .nr %d \\n(%d/%d\n", TMP, TMP, TMP, k);
1247c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".if \\n(%d<0 .nr %d 0\n", TMP, TMP);
1257c478bd9Sstevel@tonic-gate 		for(ik=0; ik<k; ik++)
1267c478bd9Sstevel@tonic-gate 			{
1277c478bd9Sstevel@tonic-gate 			if (doubled[icol-k+ik])
1287c478bd9Sstevel@tonic-gate 				fprintf(tabout, ".nr %d +\\n(%d/2\n", icol-k+ik+CMID, TMP);
1297c478bd9Sstevel@tonic-gate 			fprintf(tabout, ".nr %d +\\n(%d\n", icol-k+ik+CRIGHT, TMP);
1307c478bd9Sstevel@tonic-gate 			}
1317c478bd9Sstevel@tonic-gate 		}
1327c478bd9Sstevel@tonic-gate 	}
1337c478bd9Sstevel@tonic-gate if (textflg) untext();
1347c478bd9Sstevel@tonic-gate /* if even requested, make all columns widest width */
1357c478bd9Sstevel@tonic-gate # define TMP1 S1
1367c478bd9Sstevel@tonic-gate # define TMP2 S2
1377c478bd9Sstevel@tonic-gate if (evenflg)
1387c478bd9Sstevel@tonic-gate 	{
1397c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr %d 0\n", TMP);
1407c478bd9Sstevel@tonic-gate 	for(icol=0; icol<ncol; icol++)
1417c478bd9Sstevel@tonic-gate 		{
1427c478bd9Sstevel@tonic-gate 		if (evenup[icol]==0) continue;
1437c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".if \\n(%d>\\n(%d .nr %d \\n(%d\n",
1447c478bd9Sstevel@tonic-gate 		icol+CRIGHT, TMP, TMP, icol+CRIGHT);
1457c478bd9Sstevel@tonic-gate 		}
1467c478bd9Sstevel@tonic-gate 	for(icol=0; icol<ncol; icol++)
1477c478bd9Sstevel@tonic-gate 		{
1487c478bd9Sstevel@tonic-gate 		if (evenup[icol]==0)
1497c478bd9Sstevel@tonic-gate 			/* if column not evened just retain old interval */
1507c478bd9Sstevel@tonic-gate 			continue;
1517c478bd9Sstevel@tonic-gate 		if (doubled[icol])
1527c478bd9Sstevel@tonic-gate 			fprintf(tabout, ".nr %d (100*\\n(%d/\\n(%d)*\\n(%d/100\n",
1537c478bd9Sstevel@tonic-gate 				icol+CMID, icol+CMID, icol+CRIGHT, TMP);
1547c478bd9Sstevel@tonic-gate 				/* that nonsense with the 100's and parens tries
1557c478bd9Sstevel@tonic-gate 				   to avoid overflow while proportionally shifting
1567c478bd9Sstevel@tonic-gate 				   the middle of the number */
1577c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".nr %d \\n(%d\n", icol+CRIGHT, TMP);
1587c478bd9Sstevel@tonic-gate 		}
1597c478bd9Sstevel@tonic-gate 	}
1607c478bd9Sstevel@tonic-gate /* now adjust for total table width */
1617c478bd9Sstevel@tonic-gate for(tsep=icol=0; icol<ncol; icol++)
1627c478bd9Sstevel@tonic-gate 	tsep+= sep[icol];
1637c478bd9Sstevel@tonic-gate if (expflg)
1647c478bd9Sstevel@tonic-gate 	{
1657c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr %d 0", TMP);
1667c478bd9Sstevel@tonic-gate 	for(icol=0; icol<ncol; icol++)
1677c478bd9Sstevel@tonic-gate 		fprintf(tabout, "+\\n(%d", icol+CRIGHT);
1687c478bd9Sstevel@tonic-gate 	fprintf(tabout, "\n");
1697c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr %d \\n(.l-\\n(.i-\\n(%d\n", TMP, TMP);
1707c478bd9Sstevel@tonic-gate 	if (boxflg || dboxflg || allflg)
1717c478bd9Sstevel@tonic-gate 		tsep += 1;
1727c478bd9Sstevel@tonic-gate 	else
1737c478bd9Sstevel@tonic-gate 		tsep -= sep[ncol-1];
1747c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr %d \\n(%d/%d\n", TMP, TMP,  tsep);
1757c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".if \\n(%d<1n .nr %d 1n\n", TMP, TMP);
1767c478bd9Sstevel@tonic-gate 	}
1777c478bd9Sstevel@tonic-gate else
1787c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr %d 1n\n", TMP);
1797c478bd9Sstevel@tonic-gate fprintf(tabout, ".nr %d 0\n",CRIGHT-1);
1807c478bd9Sstevel@tonic-gate tsep= (boxflg || allflg || dboxflg || left1flg) ? 1 : 0;
1817c478bd9Sstevel@tonic-gate for(icol=0; icol<ncol; icol++)
1827c478bd9Sstevel@tonic-gate 	{
1837c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr %d \\n(%d+(%d*\\n(%d)\n",icol+CLEFT, icol+CRIGHT-1, tsep, TMP);
1847c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr %d +\\n(%d\n",icol+CRIGHT, icol+CLEFT);
1857c478bd9Sstevel@tonic-gate 	if (doubled[icol])
1867c478bd9Sstevel@tonic-gate 		{
1877c478bd9Sstevel@tonic-gate 		/* the next line is last-ditch effort to avoid zero field width */
1887c478bd9Sstevel@tonic-gate 		/*fprintf(tabout, ".if \\n(%d=0 .nr %d 1\n",icol+CMID, icol+CMID);*/
1897c478bd9Sstevel@tonic-gate 		fprintf(tabout, ".nr %d +\\n(%d\n", icol+CMID, icol+CLEFT);
1907c478bd9Sstevel@tonic-gate 	/*  fprintf(tabout, ".if n .if \\n(%d%%24>0 .nr %d +12u\n",icol+CMID, icol+CMID); */
1917c478bd9Sstevel@tonic-gate 		}
1927c478bd9Sstevel@tonic-gate 	tsep=sep[icol];
1937c478bd9Sstevel@tonic-gate 	}
1947c478bd9Sstevel@tonic-gate if (rightl)
1957c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr %d (\\n(%d+\\n(%d)/2\n",ncol+CRIGHT-1, ncol+CLEFT-1, ncol+CRIGHT-2);
1967c478bd9Sstevel@tonic-gate fprintf(tabout, ".nr TW \\n(%d\n", ncol+CRIGHT-1);
1977c478bd9Sstevel@tonic-gate if (boxflg || allflg || dboxflg)
1987c478bd9Sstevel@tonic-gate 	fprintf(tabout, ".nr TW +%d*\\n(%d\n", sep[ncol-1], TMP);
1997c478bd9Sstevel@tonic-gate fprintf(tabout,
2007c478bd9Sstevel@tonic-gate  ".if t .if \\n(TW>\\n(.li .tm Table at line %d file %s is too wide - \\n(TW units\n", iline-1, ifile);
2017c478bd9Sstevel@tonic-gate return;
2027c478bd9Sstevel@tonic-gate }
203*b5514887Smuffin 
204*b5514887Smuffin void
205*b5514887Smuffin wide(char *s, char *fn, char *size)
2067c478bd9Sstevel@tonic-gate {
2077c478bd9Sstevel@tonic-gate if (point(s))
2087c478bd9Sstevel@tonic-gate 	{
2097c478bd9Sstevel@tonic-gate 	fprintf(tabout, "\\w%c", F1);
2107c478bd9Sstevel@tonic-gate 	if (*fn>0) putfont(fn);
2117c478bd9Sstevel@tonic-gate 	if (*size) putsize(size);
2127c478bd9Sstevel@tonic-gate 	fprintf(tabout, "%s", s);
2137c478bd9Sstevel@tonic-gate 	if (*fn>0) putfont("P");
2147c478bd9Sstevel@tonic-gate 	if (*size) putsize("0");
2157c478bd9Sstevel@tonic-gate 	fprintf(tabout, "%c",F1);
2167c478bd9Sstevel@tonic-gate 	}
2177c478bd9Sstevel@tonic-gate else
2187c478bd9Sstevel@tonic-gate 	fprintf(tabout, "\\n(%c-", s);
2197c478bd9Sstevel@tonic-gate }
220*b5514887Smuffin 
221*b5514887Smuffin int
222*b5514887Smuffin filler(char *s)
2237c478bd9Sstevel@tonic-gate {
2247c478bd9Sstevel@tonic-gate return (point(s) && s[0]=='\\' && s[1] == 'R');
2257c478bd9Sstevel@tonic-gate }
226