xref: /illumos-gate/usr/src/cmd/tbl/t5.c (revision 2a8bcb4e)
17c478bd9Sstevel@tonic-gate /*
2*b5514887Smuffin  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
37c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
57c478bd9Sstevel@tonic-gate 
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  */
147c478bd9Sstevel@tonic-gate 
157c478bd9Sstevel@tonic-gate  /* t5.c: read data for table */
167c478bd9Sstevel@tonic-gate # include "t..c"
17*b5514887Smuffin 
18*b5514887Smuffin void	permute(void);
19*b5514887Smuffin 
20*b5514887Smuffin void
gettbl(void)21*b5514887Smuffin gettbl(void)
227c478bd9Sstevel@tonic-gate {
237c478bd9Sstevel@tonic-gate int icol, ch;
247c478bd9Sstevel@tonic-gate cstore=cspace= chspace();
257c478bd9Sstevel@tonic-gate textflg=0;
267c478bd9Sstevel@tonic-gate for (nlin=nslin=0; gets1(cstore, MAXSTR); nlin++)
277c478bd9Sstevel@tonic-gate 	{
287c478bd9Sstevel@tonic-gate 	stynum[nlin]=nslin;
297c478bd9Sstevel@tonic-gate 	if (prefix(".TE", cstore))
307c478bd9Sstevel@tonic-gate 		{
317c478bd9Sstevel@tonic-gate 		leftover=0;
327c478bd9Sstevel@tonic-gate 		break;
337c478bd9Sstevel@tonic-gate 		}
347c478bd9Sstevel@tonic-gate 	if (prefix(".TC", cstore) || prefix(".T&", cstore))
357c478bd9Sstevel@tonic-gate 		{
367c478bd9Sstevel@tonic-gate 		readspec();
377c478bd9Sstevel@tonic-gate 		nslin++;
387c478bd9Sstevel@tonic-gate 		}
397c478bd9Sstevel@tonic-gate 	if (nlin>=MAXLIN)
407c478bd9Sstevel@tonic-gate 		{
417c478bd9Sstevel@tonic-gate 		leftover=cstore;
427c478bd9Sstevel@tonic-gate 		break;
437c478bd9Sstevel@tonic-gate 		}
447c478bd9Sstevel@tonic-gate 	fullbot[nlin]=0;
457c478bd9Sstevel@tonic-gate 	if (cstore[0] == '.' && !isdigit((unsigned char)cstore[1]))
467c478bd9Sstevel@tonic-gate 		{
477c478bd9Sstevel@tonic-gate 		instead[nlin] = cstore;
487c478bd9Sstevel@tonic-gate 		while (*cstore++);
497c478bd9Sstevel@tonic-gate 		continue;
507c478bd9Sstevel@tonic-gate 		}
517c478bd9Sstevel@tonic-gate 	else instead[nlin] = 0;
527c478bd9Sstevel@tonic-gate 	if (nodata(nlin))
537c478bd9Sstevel@tonic-gate 		{
547c478bd9Sstevel@tonic-gate 		if (ch = oneh(nlin))
557c478bd9Sstevel@tonic-gate 			fullbot[nlin]= ch;
567c478bd9Sstevel@tonic-gate 		nlin++;
577c478bd9Sstevel@tonic-gate 		nslin++;
587c478bd9Sstevel@tonic-gate 		instead[nlin]=(char *)0;
597c478bd9Sstevel@tonic-gate 		fullbot[nlin]=0;
607c478bd9Sstevel@tonic-gate 		}
617c478bd9Sstevel@tonic-gate 	table[nlin] = (struct colstr *) alocv((ncol+2)*sizeof(table[0][0]));
627c478bd9Sstevel@tonic-gate 	if (cstore[1]==0)
637c478bd9Sstevel@tonic-gate 	switch(cstore[0])
647c478bd9Sstevel@tonic-gate 		{
657c478bd9Sstevel@tonic-gate 		case '_': fullbot[nlin]= '-'; continue;
667c478bd9Sstevel@tonic-gate 		case '=': fullbot[nlin]= '='; continue;
677c478bd9Sstevel@tonic-gate 		}
687c478bd9Sstevel@tonic-gate 	stynum[nlin] = nslin;
697c478bd9Sstevel@tonic-gate 	nslin = min(nslin+1, nclin-1);
707c478bd9Sstevel@tonic-gate 	for (icol = 0; icol <ncol; icol++)
717c478bd9Sstevel@tonic-gate 		{
727c478bd9Sstevel@tonic-gate 		table[nlin][icol].col = cstore;
737c478bd9Sstevel@tonic-gate 		table[nlin][icol].rcol=0;
747c478bd9Sstevel@tonic-gate 		ch=1;
757c478bd9Sstevel@tonic-gate 		if (match(cstore, "T{")) /* text follows */
767c478bd9Sstevel@tonic-gate 			/* get_text was originally gettext and was renamed */
777c478bd9Sstevel@tonic-gate 			table[nlin][icol].col =
787c478bd9Sstevel@tonic-gate 				(char *)get_text(cstore, nlin, icol,
797c478bd9Sstevel@tonic-gate 					font[stynum[nlin]][icol],
807c478bd9Sstevel@tonic-gate 					csize[stynum[nlin]][icol]);
817c478bd9Sstevel@tonic-gate 		else
827c478bd9Sstevel@tonic-gate 			{
837c478bd9Sstevel@tonic-gate 			for(; (ch= *cstore) != '\0' && ch != tab; cstore++)
847c478bd9Sstevel@tonic-gate 					;
857c478bd9Sstevel@tonic-gate 			*cstore++ = '\0';
867c478bd9Sstevel@tonic-gate 			switch(ctype(nlin,icol)) /* numerical or alpha, subcol */
877c478bd9Sstevel@tonic-gate 				{
887c478bd9Sstevel@tonic-gate 				case 'n':
897c478bd9Sstevel@tonic-gate 					table[nlin][icol].rcol =
907c478bd9Sstevel@tonic-gate 					    (char *)maknew(table[nlin][icol].col);
917c478bd9Sstevel@tonic-gate 					break;
927c478bd9Sstevel@tonic-gate 				case 'a':
937c478bd9Sstevel@tonic-gate 					table[nlin][icol].rcol = table[nlin][icol].col;
947c478bd9Sstevel@tonic-gate 					table[nlin][icol].col = "";
957c478bd9Sstevel@tonic-gate 					break;
967c478bd9Sstevel@tonic-gate 				}
977c478bd9Sstevel@tonic-gate 			}
987c478bd9Sstevel@tonic-gate 		while (ctype(nlin,icol+1)== 's') /* spanning */
997c478bd9Sstevel@tonic-gate 			table[nlin][++icol].col = "";
1007c478bd9Sstevel@tonic-gate 		if (ch == '\0') break;
1017c478bd9Sstevel@tonic-gate 		}
1027c478bd9Sstevel@tonic-gate 	while (++icol <ncol+2)
1037c478bd9Sstevel@tonic-gate 		{
1047c478bd9Sstevel@tonic-gate 		table[nlin][icol].col = "";
1057c478bd9Sstevel@tonic-gate 		table [nlin][icol].rcol=0;
1067c478bd9Sstevel@tonic-gate 		}
1077c478bd9Sstevel@tonic-gate 	while (*cstore != '\0')
1087c478bd9Sstevel@tonic-gate 		 cstore++;
1097c478bd9Sstevel@tonic-gate 	if (cstore-cspace > MAXCHS)
1107c478bd9Sstevel@tonic-gate 		cstore = cspace = chspace();
1117c478bd9Sstevel@tonic-gate 	}
1127c478bd9Sstevel@tonic-gate last = cstore;
1137c478bd9Sstevel@tonic-gate permute();
1147c478bd9Sstevel@tonic-gate if (textflg) untext();
1157c478bd9Sstevel@tonic-gate return;
1167c478bd9Sstevel@tonic-gate }
117*b5514887Smuffin 
118*b5514887Smuffin int
nodata(int il)119*b5514887Smuffin nodata(int il)
1207c478bd9Sstevel@tonic-gate {
1217c478bd9Sstevel@tonic-gate int c;
1227c478bd9Sstevel@tonic-gate for (c=0; c<ncol;c++)
1237c478bd9Sstevel@tonic-gate 	{
1247c478bd9Sstevel@tonic-gate 	switch(ctype(il,c))
1257c478bd9Sstevel@tonic-gate 		{
1267c478bd9Sstevel@tonic-gate 		case 'c': case 'n': case 'r': case 'l': case 's': case 'a':
1277c478bd9Sstevel@tonic-gate 			return(0);
1287c478bd9Sstevel@tonic-gate 		}
1297c478bd9Sstevel@tonic-gate 	}
1307c478bd9Sstevel@tonic-gate return(1);
1317c478bd9Sstevel@tonic-gate }
132*b5514887Smuffin 
133*b5514887Smuffin int
oneh(int lin)134*b5514887Smuffin oneh(int lin)
1357c478bd9Sstevel@tonic-gate {
1367c478bd9Sstevel@tonic-gate int k, icol;
1377c478bd9Sstevel@tonic-gate k = ctype(lin,0);
1387c478bd9Sstevel@tonic-gate for(icol=1; icol<ncol; icol++)
1397c478bd9Sstevel@tonic-gate 	{
1407c478bd9Sstevel@tonic-gate 	if (k != ctype(lin,icol))
1417c478bd9Sstevel@tonic-gate 		return(0);
1427c478bd9Sstevel@tonic-gate 	}
1437c478bd9Sstevel@tonic-gate return(k);
1447c478bd9Sstevel@tonic-gate }
145*b5514887Smuffin 
1467c478bd9Sstevel@tonic-gate # define SPAN "\\^"
147*b5514887Smuffin 
148*b5514887Smuffin void
permute(void)149*b5514887Smuffin permute(void)
1507c478bd9Sstevel@tonic-gate {
1517c478bd9Sstevel@tonic-gate int irow, jcol, is;
1527c478bd9Sstevel@tonic-gate char *start, *strig;
1537c478bd9Sstevel@tonic-gate for(jcol=0; jcol<ncol; jcol++)
1547c478bd9Sstevel@tonic-gate 	{
1557c478bd9Sstevel@tonic-gate 	for(irow=1; irow<nlin; irow++)
1567c478bd9Sstevel@tonic-gate 		{
1577c478bd9Sstevel@tonic-gate 		if (vspand(irow,jcol,0))
1587c478bd9Sstevel@tonic-gate 			{
1597c478bd9Sstevel@tonic-gate 			is = prev(irow);
1607c478bd9Sstevel@tonic-gate 			if (is<0)
1617c478bd9Sstevel@tonic-gate 				error(gettext("Vertical spanning in first row not allowed"));
1627c478bd9Sstevel@tonic-gate 			start = table[is][jcol].col;
1637c478bd9Sstevel@tonic-gate 			strig = table[is][jcol].rcol;
1647c478bd9Sstevel@tonic-gate 			while (irow<nlin &&vspand(irow,jcol,0))
1657c478bd9Sstevel@tonic-gate 				irow++;
1667c478bd9Sstevel@tonic-gate 			table[--irow][jcol].col = start;
1677c478bd9Sstevel@tonic-gate 			table[irow][jcol].rcol = strig;
1687c478bd9Sstevel@tonic-gate 			while (is<irow)
1697c478bd9Sstevel@tonic-gate 				{
1707c478bd9Sstevel@tonic-gate 				table[is][jcol].rcol =0;
1717c478bd9Sstevel@tonic-gate 				table[is][jcol].col= SPAN;
1727c478bd9Sstevel@tonic-gate 				is = next(is);
1737c478bd9Sstevel@tonic-gate 				}
1747c478bd9Sstevel@tonic-gate 			}
1757c478bd9Sstevel@tonic-gate 		}
1767c478bd9Sstevel@tonic-gate 	}
1777c478bd9Sstevel@tonic-gate }
178*b5514887Smuffin 
179*b5514887Smuffin int
vspand(int ir,int ij,int ifform)180*b5514887Smuffin vspand(int ir, int ij, int ifform)
1817c478bd9Sstevel@tonic-gate {
1827c478bd9Sstevel@tonic-gate if (ir<0) return(0);
1837c478bd9Sstevel@tonic-gate if (ir>=nlin)return(0);
1847c478bd9Sstevel@tonic-gate if (instead[ir]) return(0);
1857c478bd9Sstevel@tonic-gate if (ifform==0 && ctype(ir,ij)=='^') return(1);
1867c478bd9Sstevel@tonic-gate if (table[ir]==0) return(0);
1877c478bd9Sstevel@tonic-gate if (table[ir][ij].rcol!=0) return(0);
1887c478bd9Sstevel@tonic-gate if (fullbot[ir]) return(0);
1897c478bd9Sstevel@tonic-gate return(vspen(table[ir][ij].col));
1907c478bd9Sstevel@tonic-gate }
191*b5514887Smuffin 
192*b5514887Smuffin int
vspen(char * s)193*b5514887Smuffin vspen(char *s)
1947c478bd9Sstevel@tonic-gate {
1957c478bd9Sstevel@tonic-gate if (s==0) return(0);
1967c478bd9Sstevel@tonic-gate if (!point(s)) return(0);
1977c478bd9Sstevel@tonic-gate return(match(s, SPAN));
1987c478bd9Sstevel@tonic-gate }
199