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