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