xref: /titanic_44/usr/src/cmd/tbl/t3.c (revision 02e56f3f1bfc8d9977bafb8cb5202f576dcded27)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
16 
17  /* t3.c: interpret commands affecting whole table */
18 # include "t..c"
19 #include <string.h>
20 
21 struct optstr {char *optnam; int *optadd;} options [] = {
22 	"expand", &expflg,
23 	"EXPAND", &expflg,
24 	"center", &ctrflg,
25 	"CENTER", &ctrflg,
26 	"box", &boxflg,
27 	"BOX", &boxflg,
28 	"allbox", &allflg,
29 	"ALLBOX", &allflg,
30 	"doublebox", &dboxflg,
31 	"DOUBLEBOX", &dboxflg,
32 	"frame", &boxflg,
33 	"FRAME", &boxflg,
34 	"doubleframe", &dboxflg,
35 	"DOUBLEFRAME", &dboxflg,
36 	"tab", &tab,
37 	"TAB", &tab,
38 	"linesize", &linsize,
39 	"LINESIZE", &linsize,
40 	"delim", &delim1,
41 	"DELIM", &delim1,
42 	0,0};
43 
44 void	backrest(char *);
45 
46 void
47 getcomm(void)
48 {
49 char line[200], *cp, nb[25], *t;
50 struct optstr *lp;
51 int c, ci, found;
52 for(lp= options; lp->optnam; lp++)
53 	*(lp->optadd) = 0;
54 texname = texstr[texct=0];
55 tab = '\t';
56 printf(".nr %d \\n(.s\n", LSIZE);
57 gets1(line, sizeof line);
58 /* see if this is a command line */
59 if (strchr(line,';') == NULL)
60 	{
61 	backrest(line);
62 	return;
63 	}
64 for(cp=line; (c = *cp) != ';'; cp++)
65 	{
66 	if (!letter(c)) continue;
67 	found=0;
68 	for(lp= options; lp->optadd; lp++)
69 		{
70 		if (prefix(lp->optnam, cp))
71 			{
72 			*(lp->optadd) = 1;
73 			cp += strlen(lp->optnam);
74 			if (letter(*cp))
75 				error(gettext("Misspelled global option"));
76 			while (*cp==' ')cp++;
77 			t=nb;
78 			if ( *cp == '(')
79 				while ((ci= *++cp) != ')')
80 					*t++ = ci;
81 			else cp--;
82 			*t++ = 0; *t=0;
83 			if (lp->optadd == &tab)
84 				{
85 				if (nb[0])
86 					*(lp->optadd) = nb[0];
87 				}
88 			if (lp->optadd == &linsize)
89 				printf(".nr %d %s\n", LSIZE, nb);
90 			if (lp->optadd == &delim1)
91 				{
92 				delim1 = nb[0];
93 				delim2 = nb[1];
94 				}
95 			found=1;
96 			break;
97 			}
98 		}
99 	if (!found)
100 		error(gettext("Illegal option"));
101 	}
102 cp++;
103 backrest(cp);
104 return;
105 }
106 
107 void
108 backrest(char *cp)
109 {
110 char *s;
111 for(s=cp; *s; s++);
112 un1getc('\n');
113 while (s>cp)
114 	un1getc(*--s);
115 return;
116 }
117