xref: /onnv-gate/usr/src/cmd/tbl/t4.c (revision 381:1a7f0e46092a)
10Sstevel@tonic-gate /*
2*381Smuffin  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
30Sstevel@tonic-gate  * Use is subject to license terms.
40Sstevel@tonic-gate  */
50Sstevel@tonic-gate 
60Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
70Sstevel@tonic-gate /*	  All Rights Reserved  	*/
80Sstevel@tonic-gate 
90Sstevel@tonic-gate 
100Sstevel@tonic-gate /*
110Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
120Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
130Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
140Sstevel@tonic-gate  */
150Sstevel@tonic-gate 
160Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
170Sstevel@tonic-gate 
180Sstevel@tonic-gate  /* t4.c: read table specification */
190Sstevel@tonic-gate # include "t..c"
200Sstevel@tonic-gate int oncol;
21*381Smuffin 
22*381Smuffin void	readspec(void);
23*381Smuffin 
24*381Smuffin void
getspec(void)25*381Smuffin getspec(void)
260Sstevel@tonic-gate {
270Sstevel@tonic-gate int icol, i;
280Sstevel@tonic-gate for(icol=0; icol<MAXCOL; icol++)
290Sstevel@tonic-gate 	{
300Sstevel@tonic-gate 	sep[icol]= -1;
310Sstevel@tonic-gate 	evenup[icol]=0;
320Sstevel@tonic-gate 	cll[icol][0]=0;
330Sstevel@tonic-gate 	for(i=0; i<MAXHEAD; i++)
340Sstevel@tonic-gate 		{
350Sstevel@tonic-gate 		csize[i][icol][0]=0;
360Sstevel@tonic-gate 		vsize[i][icol][0]=0;
370Sstevel@tonic-gate 		font[i][icol][0] = lefline[i][icol] = 0;
380Sstevel@tonic-gate 		ctop[i][icol]=0;
390Sstevel@tonic-gate 		style[i][icol]= 'l';
400Sstevel@tonic-gate 		}
410Sstevel@tonic-gate 	}
420Sstevel@tonic-gate nclin=ncol=0;
430Sstevel@tonic-gate oncol =0;
440Sstevel@tonic-gate left1flg=rightl=0;
450Sstevel@tonic-gate readspec();
460Sstevel@tonic-gate fprintf(tabout, ".rm");
470Sstevel@tonic-gate for(i=0; i<ncol; i++)
480Sstevel@tonic-gate 	fprintf(tabout, " %02d", 80+i);
490Sstevel@tonic-gate fprintf(tabout, "\n");
500Sstevel@tonic-gate }
51*381Smuffin 
52*381Smuffin void
readspec(void)53*381Smuffin readspec(void)
540Sstevel@tonic-gate {
550Sstevel@tonic-gate int icol, c, sawchar, stopc, i;
560Sstevel@tonic-gate char sn[10], *snp, *temp;
570Sstevel@tonic-gate sawchar=icol=0;
580Sstevel@tonic-gate while (c=get1char())
590Sstevel@tonic-gate 	{
600Sstevel@tonic-gate 	switch(c)
610Sstevel@tonic-gate 		{
620Sstevel@tonic-gate 		default:
630Sstevel@tonic-gate 			if (c != tab)
640Sstevel@tonic-gate 			error(gettext("bad table specification character"));
650Sstevel@tonic-gate 		case ' ': /* note this is also case tab */
660Sstevel@tonic-gate 			continue;
670Sstevel@tonic-gate 		case '\n':
680Sstevel@tonic-gate 			if(sawchar==0) continue;
690Sstevel@tonic-gate 		case ',':
700Sstevel@tonic-gate 		case '.': /* end of table specification */
710Sstevel@tonic-gate 			ncol = max(ncol, icol);
720Sstevel@tonic-gate 			if (lefline[nclin][ncol]>0) {ncol++; rightl++;};
730Sstevel@tonic-gate 			if(sawchar)
740Sstevel@tonic-gate 				nclin++;
750Sstevel@tonic-gate 			if (nclin>=MAXHEAD)
760Sstevel@tonic-gate 				error(gettext("too many lines in specification"));
770Sstevel@tonic-gate 			icol=0;
780Sstevel@tonic-gate 			if (ncol==0 || nclin==0)
790Sstevel@tonic-gate 				error(gettext("no specification"));
800Sstevel@tonic-gate 			if (c== '.')
810Sstevel@tonic-gate 				{
820Sstevel@tonic-gate 				while ((c=get1char()) && c != '\n')
830Sstevel@tonic-gate 					if (c != ' ' && c != '\t')
840Sstevel@tonic-gate 						error(gettext("dot not last character on format line"));
850Sstevel@tonic-gate 				/* fix up sep - default is 3 except at edge */
860Sstevel@tonic-gate 				for(icol=0; icol<ncol; icol++)
870Sstevel@tonic-gate 					if (sep[icol]<0)
880Sstevel@tonic-gate 						sep[icol] =  icol+1<ncol ? 3 : 1;
890Sstevel@tonic-gate 				if (oncol == 0)
900Sstevel@tonic-gate 					oncol = ncol;
910Sstevel@tonic-gate 				else if (oncol +2 <ncol)
920Sstevel@tonic-gate 					error(gettext("tried to widen table in T&, not allowed"));
930Sstevel@tonic-gate 				return;
940Sstevel@tonic-gate 				}
950Sstevel@tonic-gate 			sawchar=0;
960Sstevel@tonic-gate 			continue;
970Sstevel@tonic-gate 		case 'C': case 'S': case 'R': case 'N': case 'L':  case 'A':
980Sstevel@tonic-gate 			c += ('a'-'A');
990Sstevel@tonic-gate 		case '_': if (c=='_') c= '-';
1000Sstevel@tonic-gate 		case '=': case '-':
1010Sstevel@tonic-gate 		case '^':
1020Sstevel@tonic-gate 		case 'c': case 's': case 'n': case 'r': case 'l':  case 'a':
1030Sstevel@tonic-gate 			style[nclin][icol]=c;
1040Sstevel@tonic-gate 			if (c== 's' && icol<=0)
1050Sstevel@tonic-gate 				error(gettext("first column can not be S-type"));
1060Sstevel@tonic-gate 			if (c=='s' && style[nclin][icol-1] == 'a')
1070Sstevel@tonic-gate 				{
1080Sstevel@tonic-gate 				fprintf(tabout, ".tm warning: can't span a-type cols, changed to l\n");
1090Sstevel@tonic-gate 				style[nclin][icol-1] = 'l';
1100Sstevel@tonic-gate 				}
1110Sstevel@tonic-gate 			if (c=='s' && style[nclin][icol-1] == 'n')
1120Sstevel@tonic-gate 				{
1130Sstevel@tonic-gate 				fprintf(tabout, ".tm warning: can't span n-type cols, changed to c\n");
1140Sstevel@tonic-gate 				style[nclin][icol-1] = 'c';
1150Sstevel@tonic-gate 				}
1160Sstevel@tonic-gate 			icol++;
1170Sstevel@tonic-gate 			if (c=='^' && nclin<=0)
1180Sstevel@tonic-gate 				error(gettext("first row can not contain vertical span"));
1190Sstevel@tonic-gate 			if (icol>=MAXCOL)
1200Sstevel@tonic-gate 				error(gettext("too many columns in table"));
1210Sstevel@tonic-gate 			sawchar=1;
1220Sstevel@tonic-gate 			continue;
1230Sstevel@tonic-gate 		case 'b': case 'i':
1240Sstevel@tonic-gate 			c += 'A'-'a';
1250Sstevel@tonic-gate 			/* FALLTHRU */
1260Sstevel@tonic-gate 		case 'B': case 'I':
1270Sstevel@tonic-gate 			if (sawchar == 0)
1280Sstevel@tonic-gate 				continue;
1290Sstevel@tonic-gate 			if (icol==0) continue;
1300Sstevel@tonic-gate 			snp=font[nclin][icol-1];
1310Sstevel@tonic-gate 			snp[0]= (c=='I' ? '2' : '3');
1320Sstevel@tonic-gate 			snp[1]=0;
1330Sstevel@tonic-gate 			continue;
1340Sstevel@tonic-gate 		case 't': case 'T':
1350Sstevel@tonic-gate 			if (sawchar == 0) {
1360Sstevel@tonic-gate 				continue;
1370Sstevel@tonic-gate 			}
1380Sstevel@tonic-gate 			if (icol>0)
1390Sstevel@tonic-gate 			ctop[nclin][icol-1] = 1;
1400Sstevel@tonic-gate 			continue;
1410Sstevel@tonic-gate 		case 'd': case 'D':
1420Sstevel@tonic-gate 			if (sawchar == 0)
1430Sstevel@tonic-gate 				continue;
1440Sstevel@tonic-gate 			if (icol>0)
1450Sstevel@tonic-gate 			ctop[nclin][icol-1] = -1;
1460Sstevel@tonic-gate 			continue;
1470Sstevel@tonic-gate 		case 'f': case 'F':
1480Sstevel@tonic-gate 			if (sawchar == 0)
1490Sstevel@tonic-gate 				continue;
1500Sstevel@tonic-gate 			if (icol==0) continue;
1510Sstevel@tonic-gate 			snp=font[nclin][icol-1];
1520Sstevel@tonic-gate 			snp[0]=snp[1]=stopc=0;
1530Sstevel@tonic-gate 			for(i=0; i<2; i++)
1540Sstevel@tonic-gate 				{
1550Sstevel@tonic-gate 				c = get1char();
1560Sstevel@tonic-gate 				if (i==0 && c=='(')
1570Sstevel@tonic-gate 					{
1580Sstevel@tonic-gate 					stopc=')';
1590Sstevel@tonic-gate 					c = get1char();
1600Sstevel@tonic-gate 					}
1610Sstevel@tonic-gate 				if (c==0) break;
1620Sstevel@tonic-gate 				if (c==stopc) {stopc=0; break;}
1630Sstevel@tonic-gate 				if (stopc==0)  if (c==' ' || c== tab ) break;
1640Sstevel@tonic-gate 				if (c=='\n'){un1getc(c); break;}
1650Sstevel@tonic-gate 				snp[i] = c;
1660Sstevel@tonic-gate 				if (c>= '0' && c<= '9') break;
1670Sstevel@tonic-gate 				}
1680Sstevel@tonic-gate 			if (stopc) if (get1char()!=stopc)
1690Sstevel@tonic-gate 				error(gettext("Nonterminated font name"));
1700Sstevel@tonic-gate 			continue;
1710Sstevel@tonic-gate 		case 'P': case 'p':
1720Sstevel@tonic-gate 			if (sawchar == 0)
1730Sstevel@tonic-gate 				continue;
1740Sstevel@tonic-gate 			if (icol<=0) continue;
1750Sstevel@tonic-gate 			temp = snp = csize[nclin][icol-1];
1760Sstevel@tonic-gate 			while (c = get1char())
1770Sstevel@tonic-gate 				{
1780Sstevel@tonic-gate 				if (c== ' ' || c== tab || c=='\n') break;
1790Sstevel@tonic-gate 				if (c=='-' || c == '+')
1800Sstevel@tonic-gate 					if (snp>temp)
1810Sstevel@tonic-gate 						break;
1820Sstevel@tonic-gate 					else
1830Sstevel@tonic-gate 						*snp++=c;
1840Sstevel@tonic-gate 				else
1850Sstevel@tonic-gate 				if (digit(c))
1860Sstevel@tonic-gate 					*snp++ = c;
1870Sstevel@tonic-gate 				else break;
1880Sstevel@tonic-gate 				if (snp-temp>4)
1890Sstevel@tonic-gate 					error(gettext("point size too large"));
1900Sstevel@tonic-gate 				}
1910Sstevel@tonic-gate 			*snp = 0;
1920Sstevel@tonic-gate 			if (atoi(temp)>36)
1930Sstevel@tonic-gate 				error(gettext("point size unreasonable"));
1940Sstevel@tonic-gate 			un1getc (c);
1950Sstevel@tonic-gate 			continue;
1960Sstevel@tonic-gate 		case 'V': case 'v':
1970Sstevel@tonic-gate 			if (sawchar == 0)
1980Sstevel@tonic-gate 				continue;
1990Sstevel@tonic-gate 			if (icol<=0) continue;
2000Sstevel@tonic-gate 			temp = snp = vsize[nclin][icol-1];
2010Sstevel@tonic-gate 			while (c = get1char())
2020Sstevel@tonic-gate 				{
2030Sstevel@tonic-gate 				if (c== ' ' || c== tab || c=='\n') break;
2040Sstevel@tonic-gate 				if (c=='-' || c == '+')
2050Sstevel@tonic-gate 					if (snp>temp)
2060Sstevel@tonic-gate 						break;
2070Sstevel@tonic-gate 					else
2080Sstevel@tonic-gate 						*snp++=c;
2090Sstevel@tonic-gate 				else
2100Sstevel@tonic-gate 				if (digit(c))
2110Sstevel@tonic-gate 					*snp++ = c;
2120Sstevel@tonic-gate 				else break;
2130Sstevel@tonic-gate 				if (snp-temp>4)
2140Sstevel@tonic-gate 					error(
2150Sstevel@tonic-gate 					gettext("vertical spacing value too large")
2160Sstevel@tonic-gate 					);
2170Sstevel@tonic-gate 				}
2180Sstevel@tonic-gate 			*snp=0;
2190Sstevel@tonic-gate 			un1getc(c);
2200Sstevel@tonic-gate 			continue;
2210Sstevel@tonic-gate 		case 'w': case 'W':
2220Sstevel@tonic-gate 			if (sawchar == 0) {
2230Sstevel@tonic-gate 				/*
2240Sstevel@tonic-gate 				 * This should be an error case.
2250Sstevel@tonic-gate 				 * However, for the backward-compatibility,
2260Sstevel@tonic-gate 				 * treat as if 'c' was specified.
2270Sstevel@tonic-gate 				 */
2280Sstevel@tonic-gate 				style[nclin][icol] = 'c';
2290Sstevel@tonic-gate 				icol++;
2300Sstevel@tonic-gate 				if (icol >= MAXCOL) {
2310Sstevel@tonic-gate 					error(gettext(
2320Sstevel@tonic-gate 						  "too many columns in table"));
2330Sstevel@tonic-gate 				}
2340Sstevel@tonic-gate 				sawchar = 1;
2350Sstevel@tonic-gate 			}
2360Sstevel@tonic-gate 
2370Sstevel@tonic-gate 			snp = cll [icol-1];
2380Sstevel@tonic-gate 		/* Dale Smith didn't like this check
2390Sstevel@tonic-gate 		 * possible to have two text blocks
2400Sstevel@tonic-gate 		 *  of different widths now ....
2410Sstevel@tonic-gate 			if (*snp)
2420Sstevel@tonic-gate 				{
2430Sstevel@tonic-gate 				fprintf(tabout,
2440Sstevel@tonic-gate 				gettext("Ignored second width specification"));
2450Sstevel@tonic-gate 				continue;
2460Sstevel@tonic-gate 				}
2470Sstevel@tonic-gate 		* end commented out code ... */
2480Sstevel@tonic-gate 			stopc=0;
2490Sstevel@tonic-gate 			while (c = get1char())
2500Sstevel@tonic-gate 				{
2510Sstevel@tonic-gate 				if (snp==cll[icol-1] && c=='(')
2520Sstevel@tonic-gate 					{
2530Sstevel@tonic-gate 					stopc = ')';
2540Sstevel@tonic-gate 					continue;
2550Sstevel@tonic-gate 					}
2560Sstevel@tonic-gate 				if ( !stopc && (c>'9' || c< '0'))
2570Sstevel@tonic-gate 					break;
2580Sstevel@tonic-gate 				if (stopc && c== stopc)
2590Sstevel@tonic-gate 					break;
2600Sstevel@tonic-gate 				*snp++ =c;
2610Sstevel@tonic-gate 				}
2620Sstevel@tonic-gate 			*snp=0;
2630Sstevel@tonic-gate 			if (snp-cll[icol-1]>CLLEN)
2640Sstevel@tonic-gate 				error (gettext("column width too long"));
2650Sstevel@tonic-gate 			if (!stopc)
2660Sstevel@tonic-gate 				un1getc(c);
2670Sstevel@tonic-gate 			continue;
2680Sstevel@tonic-gate 		case 'e': case 'E':
2690Sstevel@tonic-gate 			if (sawchar == 0)
2700Sstevel@tonic-gate 				continue;
2710Sstevel@tonic-gate 			if (icol<1) continue;
2720Sstevel@tonic-gate 			evenup[icol-1]=1;
2730Sstevel@tonic-gate 			evenflg=1;
2740Sstevel@tonic-gate 			continue;
2750Sstevel@tonic-gate 		case '0': case '1': case '2': case '3': case '4':
2760Sstevel@tonic-gate 		case '5': case '6': case '7': case '8': case '9':
2770Sstevel@tonic-gate 			sn[0] = c;
2780Sstevel@tonic-gate 			snp=sn+1;
2790Sstevel@tonic-gate 			while (digit(*snp++ = c = get1char()))
2800Sstevel@tonic-gate 				;
2810Sstevel@tonic-gate 			un1getc(c);
2820Sstevel@tonic-gate 			sep[icol-1] = max(sep[icol-1], numb(sn));
2830Sstevel@tonic-gate 			continue;
2840Sstevel@tonic-gate 		case '|':
2850Sstevel@tonic-gate 			lefline[nclin][icol]++;
2860Sstevel@tonic-gate 			if (icol==0) left1flg=1;
2870Sstevel@tonic-gate 			continue;
2880Sstevel@tonic-gate 		}
2890Sstevel@tonic-gate 	}
2900Sstevel@tonic-gate error(gettext("EOF reading table specification"));
2910Sstevel@tonic-gate }
292