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