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