xref: /titanic_52/usr/src/cmd/tbl/t4.c (revision b55148877d473978f0b46d593fd6213fa526fcc5)
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 /*
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 
167c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
177c478bd9Sstevel@tonic-gate 
187c478bd9Sstevel@tonic-gate  /* t4.c: read table specification */
197c478bd9Sstevel@tonic-gate # include "t..c"
207c478bd9Sstevel@tonic-gate int oncol;
21*b5514887Smuffin 
22*b5514887Smuffin void	readspec(void);
23*b5514887Smuffin 
24*b5514887Smuffin void
25*b5514887Smuffin getspec(void)
267c478bd9Sstevel@tonic-gate {
277c478bd9Sstevel@tonic-gate int icol, i;
287c478bd9Sstevel@tonic-gate for(icol=0; icol<MAXCOL; icol++)
297c478bd9Sstevel@tonic-gate 	{
307c478bd9Sstevel@tonic-gate 	sep[icol]= -1;
317c478bd9Sstevel@tonic-gate 	evenup[icol]=0;
327c478bd9Sstevel@tonic-gate 	cll[icol][0]=0;
337c478bd9Sstevel@tonic-gate 	for(i=0; i<MAXHEAD; i++)
347c478bd9Sstevel@tonic-gate 		{
357c478bd9Sstevel@tonic-gate 		csize[i][icol][0]=0;
367c478bd9Sstevel@tonic-gate 		vsize[i][icol][0]=0;
377c478bd9Sstevel@tonic-gate 		font[i][icol][0] = lefline[i][icol] = 0;
387c478bd9Sstevel@tonic-gate 		ctop[i][icol]=0;
397c478bd9Sstevel@tonic-gate 		style[i][icol]= 'l';
407c478bd9Sstevel@tonic-gate 		}
417c478bd9Sstevel@tonic-gate 	}
427c478bd9Sstevel@tonic-gate nclin=ncol=0;
437c478bd9Sstevel@tonic-gate oncol =0;
447c478bd9Sstevel@tonic-gate left1flg=rightl=0;
457c478bd9Sstevel@tonic-gate readspec();
467c478bd9Sstevel@tonic-gate fprintf(tabout, ".rm");
477c478bd9Sstevel@tonic-gate for(i=0; i<ncol; i++)
487c478bd9Sstevel@tonic-gate 	fprintf(tabout, " %02d", 80+i);
497c478bd9Sstevel@tonic-gate fprintf(tabout, "\n");
507c478bd9Sstevel@tonic-gate }
51*b5514887Smuffin 
52*b5514887Smuffin void
53*b5514887Smuffin readspec(void)
547c478bd9Sstevel@tonic-gate {
557c478bd9Sstevel@tonic-gate int icol, c, sawchar, stopc, i;
567c478bd9Sstevel@tonic-gate char sn[10], *snp, *temp;
577c478bd9Sstevel@tonic-gate sawchar=icol=0;
587c478bd9Sstevel@tonic-gate while (c=get1char())
597c478bd9Sstevel@tonic-gate 	{
607c478bd9Sstevel@tonic-gate 	switch(c)
617c478bd9Sstevel@tonic-gate 		{
627c478bd9Sstevel@tonic-gate 		default:
637c478bd9Sstevel@tonic-gate 			if (c != tab)
647c478bd9Sstevel@tonic-gate 			error(gettext("bad table specification character"));
657c478bd9Sstevel@tonic-gate 		case ' ': /* note this is also case tab */
667c478bd9Sstevel@tonic-gate 			continue;
677c478bd9Sstevel@tonic-gate 		case '\n':
687c478bd9Sstevel@tonic-gate 			if(sawchar==0) continue;
697c478bd9Sstevel@tonic-gate 		case ',':
707c478bd9Sstevel@tonic-gate 		case '.': /* end of table specification */
717c478bd9Sstevel@tonic-gate 			ncol = max(ncol, icol);
727c478bd9Sstevel@tonic-gate 			if (lefline[nclin][ncol]>0) {ncol++; rightl++;};
737c478bd9Sstevel@tonic-gate 			if(sawchar)
747c478bd9Sstevel@tonic-gate 				nclin++;
757c478bd9Sstevel@tonic-gate 			if (nclin>=MAXHEAD)
767c478bd9Sstevel@tonic-gate 				error(gettext("too many lines in specification"));
777c478bd9Sstevel@tonic-gate 			icol=0;
787c478bd9Sstevel@tonic-gate 			if (ncol==0 || nclin==0)
797c478bd9Sstevel@tonic-gate 				error(gettext("no specification"));
807c478bd9Sstevel@tonic-gate 			if (c== '.')
817c478bd9Sstevel@tonic-gate 				{
827c478bd9Sstevel@tonic-gate 				while ((c=get1char()) && c != '\n')
837c478bd9Sstevel@tonic-gate 					if (c != ' ' && c != '\t')
847c478bd9Sstevel@tonic-gate 						error(gettext("dot not last character on format line"));
857c478bd9Sstevel@tonic-gate 				/* fix up sep - default is 3 except at edge */
867c478bd9Sstevel@tonic-gate 				for(icol=0; icol<ncol; icol++)
877c478bd9Sstevel@tonic-gate 					if (sep[icol]<0)
887c478bd9Sstevel@tonic-gate 						sep[icol] =  icol+1<ncol ? 3 : 1;
897c478bd9Sstevel@tonic-gate 				if (oncol == 0)
907c478bd9Sstevel@tonic-gate 					oncol = ncol;
917c478bd9Sstevel@tonic-gate 				else if (oncol +2 <ncol)
927c478bd9Sstevel@tonic-gate 					error(gettext("tried to widen table in T&, not allowed"));
937c478bd9Sstevel@tonic-gate 				return;
947c478bd9Sstevel@tonic-gate 				}
957c478bd9Sstevel@tonic-gate 			sawchar=0;
967c478bd9Sstevel@tonic-gate 			continue;
977c478bd9Sstevel@tonic-gate 		case 'C': case 'S': case 'R': case 'N': case 'L':  case 'A':
987c478bd9Sstevel@tonic-gate 			c += ('a'-'A');
997c478bd9Sstevel@tonic-gate 		case '_': if (c=='_') c= '-';
1007c478bd9Sstevel@tonic-gate 		case '=': case '-':
1017c478bd9Sstevel@tonic-gate 		case '^':
1027c478bd9Sstevel@tonic-gate 		case 'c': case 's': case 'n': case 'r': case 'l':  case 'a':
1037c478bd9Sstevel@tonic-gate 			style[nclin][icol]=c;
1047c478bd9Sstevel@tonic-gate 			if (c== 's' && icol<=0)
1057c478bd9Sstevel@tonic-gate 				error(gettext("first column can not be S-type"));
1067c478bd9Sstevel@tonic-gate 			if (c=='s' && style[nclin][icol-1] == 'a')
1077c478bd9Sstevel@tonic-gate 				{
1087c478bd9Sstevel@tonic-gate 				fprintf(tabout, ".tm warning: can't span a-type cols, changed to l\n");
1097c478bd9Sstevel@tonic-gate 				style[nclin][icol-1] = 'l';
1107c478bd9Sstevel@tonic-gate 				}
1117c478bd9Sstevel@tonic-gate 			if (c=='s' && style[nclin][icol-1] == 'n')
1127c478bd9Sstevel@tonic-gate 				{
1137c478bd9Sstevel@tonic-gate 				fprintf(tabout, ".tm warning: can't span n-type cols, changed to c\n");
1147c478bd9Sstevel@tonic-gate 				style[nclin][icol-1] = 'c';
1157c478bd9Sstevel@tonic-gate 				}
1167c478bd9Sstevel@tonic-gate 			icol++;
1177c478bd9Sstevel@tonic-gate 			if (c=='^' && nclin<=0)
1187c478bd9Sstevel@tonic-gate 				error(gettext("first row can not contain vertical span"));
1197c478bd9Sstevel@tonic-gate 			if (icol>=MAXCOL)
1207c478bd9Sstevel@tonic-gate 				error(gettext("too many columns in table"));
1217c478bd9Sstevel@tonic-gate 			sawchar=1;
1227c478bd9Sstevel@tonic-gate 			continue;
1237c478bd9Sstevel@tonic-gate 		case 'b': case 'i':
1247c478bd9Sstevel@tonic-gate 			c += 'A'-'a';
1257c478bd9Sstevel@tonic-gate 			/* FALLTHRU */
1267c478bd9Sstevel@tonic-gate 		case 'B': case 'I':
1277c478bd9Sstevel@tonic-gate 			if (sawchar == 0)
1287c478bd9Sstevel@tonic-gate 				continue;
1297c478bd9Sstevel@tonic-gate 			if (icol==0) continue;
1307c478bd9Sstevel@tonic-gate 			snp=font[nclin][icol-1];
1317c478bd9Sstevel@tonic-gate 			snp[0]= (c=='I' ? '2' : '3');
1327c478bd9Sstevel@tonic-gate 			snp[1]=0;
1337c478bd9Sstevel@tonic-gate 			continue;
1347c478bd9Sstevel@tonic-gate 		case 't': case 'T':
1357c478bd9Sstevel@tonic-gate 			if (sawchar == 0) {
1367c478bd9Sstevel@tonic-gate 				continue;
1377c478bd9Sstevel@tonic-gate 			}
1387c478bd9Sstevel@tonic-gate 			if (icol>0)
1397c478bd9Sstevel@tonic-gate 			ctop[nclin][icol-1] = 1;
1407c478bd9Sstevel@tonic-gate 			continue;
1417c478bd9Sstevel@tonic-gate 		case 'd': case 'D':
1427c478bd9Sstevel@tonic-gate 			if (sawchar == 0)
1437c478bd9Sstevel@tonic-gate 				continue;
1447c478bd9Sstevel@tonic-gate 			if (icol>0)
1457c478bd9Sstevel@tonic-gate 			ctop[nclin][icol-1] = -1;
1467c478bd9Sstevel@tonic-gate 			continue;
1477c478bd9Sstevel@tonic-gate 		case 'f': case 'F':
1487c478bd9Sstevel@tonic-gate 			if (sawchar == 0)
1497c478bd9Sstevel@tonic-gate 				continue;
1507c478bd9Sstevel@tonic-gate 			if (icol==0) continue;
1517c478bd9Sstevel@tonic-gate 			snp=font[nclin][icol-1];
1527c478bd9Sstevel@tonic-gate 			snp[0]=snp[1]=stopc=0;
1537c478bd9Sstevel@tonic-gate 			for(i=0; i<2; i++)
1547c478bd9Sstevel@tonic-gate 				{
1557c478bd9Sstevel@tonic-gate 				c = get1char();
1567c478bd9Sstevel@tonic-gate 				if (i==0 && c=='(')
1577c478bd9Sstevel@tonic-gate 					{
1587c478bd9Sstevel@tonic-gate 					stopc=')';
1597c478bd9Sstevel@tonic-gate 					c = get1char();
1607c478bd9Sstevel@tonic-gate 					}
1617c478bd9Sstevel@tonic-gate 				if (c==0) break;
1627c478bd9Sstevel@tonic-gate 				if (c==stopc) {stopc=0; break;}
1637c478bd9Sstevel@tonic-gate 				if (stopc==0)  if (c==' ' || c== tab ) break;
1647c478bd9Sstevel@tonic-gate 				if (c=='\n'){un1getc(c); break;}
1657c478bd9Sstevel@tonic-gate 				snp[i] = c;
1667c478bd9Sstevel@tonic-gate 				if (c>= '0' && c<= '9') break;
1677c478bd9Sstevel@tonic-gate 				}
1687c478bd9Sstevel@tonic-gate 			if (stopc) if (get1char()!=stopc)
1697c478bd9Sstevel@tonic-gate 				error(gettext("Nonterminated font name"));
1707c478bd9Sstevel@tonic-gate 			continue;
1717c478bd9Sstevel@tonic-gate 		case 'P': case 'p':
1727c478bd9Sstevel@tonic-gate 			if (sawchar == 0)
1737c478bd9Sstevel@tonic-gate 				continue;
1747c478bd9Sstevel@tonic-gate 			if (icol<=0) continue;
1757c478bd9Sstevel@tonic-gate 			temp = snp = csize[nclin][icol-1];
1767c478bd9Sstevel@tonic-gate 			while (c = get1char())
1777c478bd9Sstevel@tonic-gate 				{
1787c478bd9Sstevel@tonic-gate 				if (c== ' ' || c== tab || c=='\n') break;
1797c478bd9Sstevel@tonic-gate 				if (c=='-' || c == '+')
1807c478bd9Sstevel@tonic-gate 					if (snp>temp)
1817c478bd9Sstevel@tonic-gate 						break;
1827c478bd9Sstevel@tonic-gate 					else
1837c478bd9Sstevel@tonic-gate 						*snp++=c;
1847c478bd9Sstevel@tonic-gate 				else
1857c478bd9Sstevel@tonic-gate 				if (digit(c))
1867c478bd9Sstevel@tonic-gate 					*snp++ = c;
1877c478bd9Sstevel@tonic-gate 				else break;
1887c478bd9Sstevel@tonic-gate 				if (snp-temp>4)
1897c478bd9Sstevel@tonic-gate 					error(gettext("point size too large"));
1907c478bd9Sstevel@tonic-gate 				}
1917c478bd9Sstevel@tonic-gate 			*snp = 0;
1927c478bd9Sstevel@tonic-gate 			if (atoi(temp)>36)
1937c478bd9Sstevel@tonic-gate 				error(gettext("point size unreasonable"));
1947c478bd9Sstevel@tonic-gate 			un1getc (c);
1957c478bd9Sstevel@tonic-gate 			continue;
1967c478bd9Sstevel@tonic-gate 		case 'V': case 'v':
1977c478bd9Sstevel@tonic-gate 			if (sawchar == 0)
1987c478bd9Sstevel@tonic-gate 				continue;
1997c478bd9Sstevel@tonic-gate 			if (icol<=0) continue;
2007c478bd9Sstevel@tonic-gate 			temp = snp = vsize[nclin][icol-1];
2017c478bd9Sstevel@tonic-gate 			while (c = get1char())
2027c478bd9Sstevel@tonic-gate 				{
2037c478bd9Sstevel@tonic-gate 				if (c== ' ' || c== tab || c=='\n') break;
2047c478bd9Sstevel@tonic-gate 				if (c=='-' || c == '+')
2057c478bd9Sstevel@tonic-gate 					if (snp>temp)
2067c478bd9Sstevel@tonic-gate 						break;
2077c478bd9Sstevel@tonic-gate 					else
2087c478bd9Sstevel@tonic-gate 						*snp++=c;
2097c478bd9Sstevel@tonic-gate 				else
2107c478bd9Sstevel@tonic-gate 				if (digit(c))
2117c478bd9Sstevel@tonic-gate 					*snp++ = c;
2127c478bd9Sstevel@tonic-gate 				else break;
2137c478bd9Sstevel@tonic-gate 				if (snp-temp>4)
2147c478bd9Sstevel@tonic-gate 					error(
2157c478bd9Sstevel@tonic-gate 					gettext("vertical spacing value too large")
2167c478bd9Sstevel@tonic-gate 					);
2177c478bd9Sstevel@tonic-gate 				}
2187c478bd9Sstevel@tonic-gate 			*snp=0;
2197c478bd9Sstevel@tonic-gate 			un1getc(c);
2207c478bd9Sstevel@tonic-gate 			continue;
2217c478bd9Sstevel@tonic-gate 		case 'w': case 'W':
2227c478bd9Sstevel@tonic-gate 			if (sawchar == 0) {
2237c478bd9Sstevel@tonic-gate 				/*
2247c478bd9Sstevel@tonic-gate 				 * This should be an error case.
2257c478bd9Sstevel@tonic-gate 				 * However, for the backward-compatibility,
2267c478bd9Sstevel@tonic-gate 				 * treat as if 'c' was specified.
2277c478bd9Sstevel@tonic-gate 				 */
2287c478bd9Sstevel@tonic-gate 				style[nclin][icol] = 'c';
2297c478bd9Sstevel@tonic-gate 				icol++;
2307c478bd9Sstevel@tonic-gate 				if (icol >= MAXCOL) {
2317c478bd9Sstevel@tonic-gate 					error(gettext(
2327c478bd9Sstevel@tonic-gate 						  "too many columns in table"));
2337c478bd9Sstevel@tonic-gate 				}
2347c478bd9Sstevel@tonic-gate 				sawchar = 1;
2357c478bd9Sstevel@tonic-gate 			}
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate 			snp = cll [icol-1];
2387c478bd9Sstevel@tonic-gate 		/* Dale Smith didn't like this check
2397c478bd9Sstevel@tonic-gate 		 * possible to have two text blocks
2407c478bd9Sstevel@tonic-gate 		 *  of different widths now ....
2417c478bd9Sstevel@tonic-gate 			if (*snp)
2427c478bd9Sstevel@tonic-gate 				{
2437c478bd9Sstevel@tonic-gate 				fprintf(tabout,
2447c478bd9Sstevel@tonic-gate 				gettext("Ignored second width specification"));
2457c478bd9Sstevel@tonic-gate 				continue;
2467c478bd9Sstevel@tonic-gate 				}
2477c478bd9Sstevel@tonic-gate 		* end commented out code ... */
2487c478bd9Sstevel@tonic-gate 			stopc=0;
2497c478bd9Sstevel@tonic-gate 			while (c = get1char())
2507c478bd9Sstevel@tonic-gate 				{
2517c478bd9Sstevel@tonic-gate 				if (snp==cll[icol-1] && c=='(')
2527c478bd9Sstevel@tonic-gate 					{
2537c478bd9Sstevel@tonic-gate 					stopc = ')';
2547c478bd9Sstevel@tonic-gate 					continue;
2557c478bd9Sstevel@tonic-gate 					}
2567c478bd9Sstevel@tonic-gate 				if ( !stopc && (c>'9' || c< '0'))
2577c478bd9Sstevel@tonic-gate 					break;
2587c478bd9Sstevel@tonic-gate 				if (stopc && c== stopc)
2597c478bd9Sstevel@tonic-gate 					break;
2607c478bd9Sstevel@tonic-gate 				*snp++ =c;
2617c478bd9Sstevel@tonic-gate 				}
2627c478bd9Sstevel@tonic-gate 			*snp=0;
2637c478bd9Sstevel@tonic-gate 			if (snp-cll[icol-1]>CLLEN)
2647c478bd9Sstevel@tonic-gate 				error (gettext("column width too long"));
2657c478bd9Sstevel@tonic-gate 			if (!stopc)
2667c478bd9Sstevel@tonic-gate 				un1getc(c);
2677c478bd9Sstevel@tonic-gate 			continue;
2687c478bd9Sstevel@tonic-gate 		case 'e': case 'E':
2697c478bd9Sstevel@tonic-gate 			if (sawchar == 0)
2707c478bd9Sstevel@tonic-gate 				continue;
2717c478bd9Sstevel@tonic-gate 			if (icol<1) continue;
2727c478bd9Sstevel@tonic-gate 			evenup[icol-1]=1;
2737c478bd9Sstevel@tonic-gate 			evenflg=1;
2747c478bd9Sstevel@tonic-gate 			continue;
2757c478bd9Sstevel@tonic-gate 		case '0': case '1': case '2': case '3': case '4':
2767c478bd9Sstevel@tonic-gate 		case '5': case '6': case '7': case '8': case '9':
2777c478bd9Sstevel@tonic-gate 			sn[0] = c;
2787c478bd9Sstevel@tonic-gate 			snp=sn+1;
2797c478bd9Sstevel@tonic-gate 			while (digit(*snp++ = c = get1char()))
2807c478bd9Sstevel@tonic-gate 				;
2817c478bd9Sstevel@tonic-gate 			un1getc(c);
2827c478bd9Sstevel@tonic-gate 			sep[icol-1] = max(sep[icol-1], numb(sn));
2837c478bd9Sstevel@tonic-gate 			continue;
2847c478bd9Sstevel@tonic-gate 		case '|':
2857c478bd9Sstevel@tonic-gate 			lefline[nclin][icol]++;
2867c478bd9Sstevel@tonic-gate 			if (icol==0) left1flg=1;
2877c478bd9Sstevel@tonic-gate 			continue;
2887c478bd9Sstevel@tonic-gate 		}
2897c478bd9Sstevel@tonic-gate 	}
2907c478bd9Sstevel@tonic-gate error(gettext("EOF reading table specification"));
2917c478bd9Sstevel@tonic-gate }
292