xref: /onnv-gate/usr/src/cmd/tbl/t3.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
2*0Sstevel@tonic-gate /*	  All Rights Reserved  	*/
3*0Sstevel@tonic-gate 
4*0Sstevel@tonic-gate 
5*0Sstevel@tonic-gate /*
6*0Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
7*0Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
8*0Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
9*0Sstevel@tonic-gate  */
10*0Sstevel@tonic-gate 
11*0Sstevel@tonic-gate /*
12*0Sstevel@tonic-gate  * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
13*0Sstevel@tonic-gate  * All Rights Reserved.
14*0Sstevel@tonic-gate  */
15*0Sstevel@tonic-gate 
16*0Sstevel@tonic-gate #ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.1	*/
17*0Sstevel@tonic-gate 
18*0Sstevel@tonic-gate  /* t3.c: interpret commands affecting whole table */
19*0Sstevel@tonic-gate # include "t..c"
20*0Sstevel@tonic-gate struct optstr {char *optnam; int *optadd;} options [] = {
21*0Sstevel@tonic-gate 	"expand", &expflg,
22*0Sstevel@tonic-gate 	"EXPAND", &expflg,
23*0Sstevel@tonic-gate 	"center", &ctrflg,
24*0Sstevel@tonic-gate 	"CENTER", &ctrflg,
25*0Sstevel@tonic-gate 	"box", &boxflg,
26*0Sstevel@tonic-gate 	"BOX", &boxflg,
27*0Sstevel@tonic-gate 	"allbox", &allflg,
28*0Sstevel@tonic-gate 	"ALLBOX", &allflg,
29*0Sstevel@tonic-gate 	"doublebox", &dboxflg,
30*0Sstevel@tonic-gate 	"DOUBLEBOX", &dboxflg,
31*0Sstevel@tonic-gate 	"frame", &boxflg,
32*0Sstevel@tonic-gate 	"FRAME", &boxflg,
33*0Sstevel@tonic-gate 	"doubleframe", &dboxflg,
34*0Sstevel@tonic-gate 	"DOUBLEFRAME", &dboxflg,
35*0Sstevel@tonic-gate 	"tab", &tab,
36*0Sstevel@tonic-gate 	"TAB", &tab,
37*0Sstevel@tonic-gate 	"linesize", &linsize,
38*0Sstevel@tonic-gate 	"LINESIZE", &linsize,
39*0Sstevel@tonic-gate 	"delim", &delim1,
40*0Sstevel@tonic-gate 	"DELIM", &delim1,
41*0Sstevel@tonic-gate 	0,0};
42*0Sstevel@tonic-gate extern char *strchr();
43*0Sstevel@tonic-gate getcomm()
44*0Sstevel@tonic-gate {
45*0Sstevel@tonic-gate char line[200], *cp, nb[25], *t;
46*0Sstevel@tonic-gate struct optstr *lp;
47*0Sstevel@tonic-gate int c, ci, found;
48*0Sstevel@tonic-gate for(lp= options; lp->optnam; lp++)
49*0Sstevel@tonic-gate 	*(lp->optadd) = 0;
50*0Sstevel@tonic-gate texname = texstr[texct=0];
51*0Sstevel@tonic-gate tab = '\t';
52*0Sstevel@tonic-gate printf(".nr %d \\n(.s\n", LSIZE);
53*0Sstevel@tonic-gate gets1(line, sizeof line);
54*0Sstevel@tonic-gate /* see if this is a command line */
55*0Sstevel@tonic-gate if (strchr(line,';') == NULL)
56*0Sstevel@tonic-gate 	{
57*0Sstevel@tonic-gate 	backrest(line);
58*0Sstevel@tonic-gate 	return;
59*0Sstevel@tonic-gate 	}
60*0Sstevel@tonic-gate for(cp=line; (c = *cp) != ';'; cp++)
61*0Sstevel@tonic-gate 	{
62*0Sstevel@tonic-gate 	if (!letter(c)) continue;
63*0Sstevel@tonic-gate 	found=0;
64*0Sstevel@tonic-gate 	for(lp= options; lp->optadd; lp++)
65*0Sstevel@tonic-gate 		{
66*0Sstevel@tonic-gate 		if (prefix(lp->optnam, cp))
67*0Sstevel@tonic-gate 			{
68*0Sstevel@tonic-gate 			*(lp->optadd) = 1;
69*0Sstevel@tonic-gate 			cp += strlen(lp->optnam);
70*0Sstevel@tonic-gate 			if (letter(*cp))
71*0Sstevel@tonic-gate 				error(gettext("Misspelled global option"));
72*0Sstevel@tonic-gate 			while (*cp==' ')cp++;
73*0Sstevel@tonic-gate 			t=nb;
74*0Sstevel@tonic-gate 			if ( *cp == '(')
75*0Sstevel@tonic-gate 				while ((ci= *++cp) != ')')
76*0Sstevel@tonic-gate 					*t++ = ci;
77*0Sstevel@tonic-gate 			else cp--;
78*0Sstevel@tonic-gate 			*t++ = 0; *t=0;
79*0Sstevel@tonic-gate 			if (lp->optadd == &tab)
80*0Sstevel@tonic-gate 				{
81*0Sstevel@tonic-gate 				if (nb[0])
82*0Sstevel@tonic-gate 					*(lp->optadd) = nb[0];
83*0Sstevel@tonic-gate 				}
84*0Sstevel@tonic-gate 			if (lp->optadd == &linsize)
85*0Sstevel@tonic-gate 				printf(".nr %d %s\n", LSIZE, nb);
86*0Sstevel@tonic-gate 			if (lp->optadd == &delim1)
87*0Sstevel@tonic-gate 				{
88*0Sstevel@tonic-gate 				delim1 = nb[0];
89*0Sstevel@tonic-gate 				delim2 = nb[1];
90*0Sstevel@tonic-gate 				}
91*0Sstevel@tonic-gate 			found=1;
92*0Sstevel@tonic-gate 			break;
93*0Sstevel@tonic-gate 			}
94*0Sstevel@tonic-gate 		}
95*0Sstevel@tonic-gate 	if (!found)
96*0Sstevel@tonic-gate 		error(gettext("Illegal option"));
97*0Sstevel@tonic-gate 	}
98*0Sstevel@tonic-gate cp++;
99*0Sstevel@tonic-gate backrest(cp);
100*0Sstevel@tonic-gate return;
101*0Sstevel@tonic-gate }
102*0Sstevel@tonic-gate backrest(cp)
103*0Sstevel@tonic-gate 	char *cp;
104*0Sstevel@tonic-gate {
105*0Sstevel@tonic-gate char *s;
106*0Sstevel@tonic-gate for(s=cp; *s; s++);
107*0Sstevel@tonic-gate un1getc('\n');
108*0Sstevel@tonic-gate while (s>cp)
109*0Sstevel@tonic-gate 	un1getc(*--s);
110*0Sstevel@tonic-gate return;
111*0Sstevel@tonic-gate }
112