1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1997-1999 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
27*7c478bd9Sstevel@tonic-gate 
28*7c478bd9Sstevel@tonic-gate #include <stdio.h>
29*7c478bd9Sstevel@tonic-gate #include <string.h>
30*7c478bd9Sstevel@tonic-gate #include <ctype.h>
31*7c478bd9Sstevel@tonic-gate #include "xlator.h"
32*7c478bd9Sstevel@tonic-gate #include "util.h"
33*7c478bd9Sstevel@tonic-gate #include "bucket.h"
34*7c478bd9Sstevel@tonic-gate #include "errlog.h"
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate /* Types: */
37*7c478bd9Sstevel@tonic-gate #define	TRUE	1
38*7c478bd9Sstevel@tonic-gate #define	FALSE	0
39*7c478bd9Sstevel@tonic-gate #define	MAXLINE 1024
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate typedef enum {
43*7c478bd9Sstevel@tonic-gate 	PARENT, UNCLE
44*7c478bd9Sstevel@tonic-gate } RELATION;
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate /* Statics: */
48*7c478bd9Sstevel@tonic-gate /* The parser is a dfa, driven by the following: */
49*7c478bd9Sstevel@tonic-gate static FILE *Fp;
50*7c478bd9Sstevel@tonic-gate static const char *Filename;
51*7c478bd9Sstevel@tonic-gate static char Previous[MAXLINE];
52*7c478bd9Sstevel@tonic-gate static char LeftMostChild[MAXLINE];
53*7c478bd9Sstevel@tonic-gate static int Selected = FALSE;
54*7c478bd9Sstevel@tonic-gate static int Line;
55*7c478bd9Sstevel@tonic-gate static int Errors;
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate /* The grammar is: */
59*7c478bd9Sstevel@tonic-gate static int arch(void);
60*7c478bd9Sstevel@tonic-gate static int comment(void);
61*7c478bd9Sstevel@tonic-gate static int arch_name(void);
62*7c478bd9Sstevel@tonic-gate static int set_list(void);
63*7c478bd9Sstevel@tonic-gate static int set(void);
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate /* The supporting code is: */
66*7c478bd9Sstevel@tonic-gate static int accept_token(char *);
67*7c478bd9Sstevel@tonic-gate static void skip_to(char *);
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate /* And the tokenizer is: */
70*7c478bd9Sstevel@tonic-gate static char *tokenize(char *);
71*7c478bd9Sstevel@tonic-gate static char *currtok(void);
72*7c478bd9Sstevel@tonic-gate static char *nexttok(void);
73*7c478bd9Sstevel@tonic-gate static char *skipb(char *);
74*7c478bd9Sstevel@tonic-gate static char *skipover(char *);
75*7c478bd9Sstevel@tonic-gate static char *CurrTok = NULL;
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate static int set_parents(void);
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate static table_t *Vers;
80*7c478bd9Sstevel@tonic-gate static table_t *Varch;
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate static void init_tables(void);
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate static void add_valid_arch(char *);
85*7c478bd9Sstevel@tonic-gate static void add_valid_version(char *vers_name);
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate #define	in_specials(c)  ((c) == '{' || (c) == '}' || (c) == '+' || \
89*7c478bd9Sstevel@tonic-gate 	(c) == '-' || (c) == ';' || (c) == ':' || (c) == ',' || \
90*7c478bd9Sstevel@tonic-gate 	(c) == '[' || (c) == ']')
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate #define	eq(s1, s2)	(strcmp((s1), (s2)) == 0)
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate 
95*7c478bd9Sstevel@tonic-gate /*
96*7c478bd9Sstevel@tonic-gate  * parse_versions -- parse the file whose name is passed, return
97*7c478bd9Sstevel@tonic-gate  *	the number of (fatal) errors encountered. Currently only
98*7c478bd9Sstevel@tonic-gate  *	knows about reading set files and writing vers files.
99*7c478bd9Sstevel@tonic-gate  */
100*7c478bd9Sstevel@tonic-gate int
parse_versions(const char * fileName)101*7c478bd9Sstevel@tonic-gate parse_versions(const char *fileName)
102*7c478bd9Sstevel@tonic-gate {
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate 	/* Prime the set-file parser dfa: */
105*7c478bd9Sstevel@tonic-gate 	assert(fileName != NULL, "passed null filename to parse_versions");
106*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "parse_versions(%s) {", fileName);
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate 	if ((Fp = fopen(fileName, "r")) == NULL) {
110*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "Cannot open version file \"%s\"\n",
111*7c478bd9Sstevel@tonic-gate 		    fileName);
112*7c478bd9Sstevel@tonic-gate 		errlog(END, "} /* parse_versions */");
113*7c478bd9Sstevel@tonic-gate 		return (1);
114*7c478bd9Sstevel@tonic-gate 	}
115*7c478bd9Sstevel@tonic-gate 	Filename = fileName;
116*7c478bd9Sstevel@tonic-gate 	Line = 0;
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate 	errlog(VERBOSE, "reading set file %s looking for architecture %s",
119*7c478bd9Sstevel@tonic-gate 	    Filename, TargetArchStr);
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate 	/* Run the dfa. */
122*7c478bd9Sstevel@tonic-gate 	while (arch())
123*7c478bd9Sstevel@tonic-gate 		continue;
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate 	(void) fclose(Fp);
126*7c478bd9Sstevel@tonic-gate 	/* print_all_buckets(); */
127*7c478bd9Sstevel@tonic-gate 	errlog(END, "} /* parse_versions */");
128*7c478bd9Sstevel@tonic-gate 	return (Errors);
129*7c478bd9Sstevel@tonic-gate }
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate /*
133*7c478bd9Sstevel@tonic-gate  * The parser. This implements the grammar:
134*7c478bd9Sstevel@tonic-gate  *    setfile::= (arch())+ <EOF>
135*7c478bd9Sstevel@tonic-gate  *             | <EOF>
136*7c478bd9Sstevel@tonic-gate  *    arch::= <ARCHITECTURE> "{" (set_list())* "}"
137*7c478bd9Sstevel@tonic-gate  *    set_list::= (set())+ ";"
138*7c478bd9Sstevel@tonic-gate  *    set::= <IDENTIFIER> ["[" "WEAK" "]"] ":" "{" (ancestors) "}" ";"
139*7c478bd9Sstevel@tonic-gate  *    ancestors::= <IDENTIFIER> | <ancestors> "," <IDENTIFIER>
140*7c478bd9Sstevel@tonic-gate  *    where <ARCHITECTURE> and <IDENTIFIER> are tokens.
141*7c478bd9Sstevel@tonic-gate  */
142*7c478bd9Sstevel@tonic-gate static int
arch(void)143*7c478bd9Sstevel@tonic-gate arch(void)
144*7c478bd9Sstevel@tonic-gate {
145*7c478bd9Sstevel@tonic-gate 	int olderrors;
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "arch() {");
148*7c478bd9Sstevel@tonic-gate 	if (comment()) {
149*7c478bd9Sstevel@tonic-gate 		errlog(END, "} /* arch */");
150*7c478bd9Sstevel@tonic-gate 		return (TRUE);
151*7c478bd9Sstevel@tonic-gate 	}
152*7c478bd9Sstevel@tonic-gate 	if (arch_name() == FALSE) {
153*7c478bd9Sstevel@tonic-gate 		errlog(END, "} /* arch */");
154*7c478bd9Sstevel@tonic-gate 		return (FALSE);
155*7c478bd9Sstevel@tonic-gate 	}
156*7c478bd9Sstevel@tonic-gate 	if (accept_token("{") == FALSE) {
157*7c478bd9Sstevel@tonic-gate 		errlog(END, "} /* arch */");
158*7c478bd9Sstevel@tonic-gate 		return (FALSE);
159*7c478bd9Sstevel@tonic-gate 	}
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate 	olderrors = Errors;
162*7c478bd9Sstevel@tonic-gate 	if (set_list() == FALSE) {
163*7c478bd9Sstevel@tonic-gate 		if (olderrors != Errors) {
164*7c478bd9Sstevel@tonic-gate 			errlog(END, "} /* arch */");
165*7c478bd9Sstevel@tonic-gate 			return (FALSE);
166*7c478bd9Sstevel@tonic-gate 		}
167*7c478bd9Sstevel@tonic-gate 	}
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate 	errlog(END, "} /* arch */");
170*7c478bd9Sstevel@tonic-gate 	return (TRUE);
171*7c478bd9Sstevel@tonic-gate }
172*7c478bd9Sstevel@tonic-gate 
173*7c478bd9Sstevel@tonic-gate static int
comment(void)174*7c478bd9Sstevel@tonic-gate comment(void)
175*7c478bd9Sstevel@tonic-gate {
176*7c478bd9Sstevel@tonic-gate 	char *token = currtok();
177*7c478bd9Sstevel@tonic-gate 
178*7c478bd9Sstevel@tonic-gate 	if (token == NULL || *token != '#') {
179*7c478bd9Sstevel@tonic-gate 		return (FALSE);
180*7c478bd9Sstevel@tonic-gate 	} else {
181*7c478bd9Sstevel@tonic-gate 		/* Swallow token. */
182*7c478bd9Sstevel@tonic-gate 		token =  nexttok();
183*7c478bd9Sstevel@tonic-gate 		return (TRUE);
184*7c478bd9Sstevel@tonic-gate 	}
185*7c478bd9Sstevel@tonic-gate }
186*7c478bd9Sstevel@tonic-gate 
187*7c478bd9Sstevel@tonic-gate static int
arch_name(void)188*7c478bd9Sstevel@tonic-gate arch_name(void)
189*7c478bd9Sstevel@tonic-gate {
190*7c478bd9Sstevel@tonic-gate 	char *token = currtok();
191*7c478bd9Sstevel@tonic-gate 
192*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "arch_name() {");
193*7c478bd9Sstevel@tonic-gate 	errlog(VERBOSE, "token = '%s';",
194*7c478bd9Sstevel@tonic-gate 		token ? token : "<NULL>");
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate 	if (token == NULL) {
197*7c478bd9Sstevel@tonic-gate 		errlog(END, "} /* arch_name */");
198*7c478bd9Sstevel@tonic-gate 		return (FALSE);
199*7c478bd9Sstevel@tonic-gate 
200*7c478bd9Sstevel@tonic-gate 	} else if (in_specials(*token)) {
201*7c478bd9Sstevel@tonic-gate 		/* It's not an architecture */
202*7c478bd9Sstevel@tonic-gate 		Selected = FALSE;
203*7c478bd9Sstevel@tonic-gate 
204*7c478bd9Sstevel@tonic-gate 		/* Report a syntax error: TBD */
205*7c478bd9Sstevel@tonic-gate 		errlog(INPUT | ERROR, "found special char. %c "
206*7c478bd9Sstevel@tonic-gate 		    "while looking for an architecture name",
207*7c478bd9Sstevel@tonic-gate 		    *token);
208*7c478bd9Sstevel@tonic-gate 
209*7c478bd9Sstevel@tonic-gate 		skip_to("}");	/* The follower set for arch_name. */
210*7c478bd9Sstevel@tonic-gate 		errlog(END, "} /* arch name */");
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate 		Errors++;
213*7c478bd9Sstevel@tonic-gate 		return (FALSE);
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate 	} else if (!eq(token, TargetArchStr)) {
216*7c478bd9Sstevel@tonic-gate 		/* It's an architecture ... */
217*7c478bd9Sstevel@tonic-gate 		errlog(VERBOSE, "Begin unselected architecture: %s", token);
218*7c478bd9Sstevel@tonic-gate 		add_valid_arch(token);
219*7c478bd9Sstevel@tonic-gate 		(void) nexttok();
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate 		/* ... but the the wrong one. */
222*7c478bd9Sstevel@tonic-gate 		Selected = FALSE;
223*7c478bd9Sstevel@tonic-gate 		errlog(END, "} /* arch name */");
224*7c478bd9Sstevel@tonic-gate 		return (TRUE);
225*7c478bd9Sstevel@tonic-gate 	} else {
226*7c478bd9Sstevel@tonic-gate 		/* Found the right architecture. */
227*7c478bd9Sstevel@tonic-gate 		errlog(VERBOSE, "Begin selected architecture: %s", token);
228*7c478bd9Sstevel@tonic-gate 		add_valid_arch(token);
229*7c478bd9Sstevel@tonic-gate 		(void) nexttok();
230*7c478bd9Sstevel@tonic-gate 		Selected = TRUE;
231*7c478bd9Sstevel@tonic-gate 		errlog(END, "} /* arch name */");
232*7c478bd9Sstevel@tonic-gate 		return (TRUE);
233*7c478bd9Sstevel@tonic-gate 	}
234*7c478bd9Sstevel@tonic-gate }
235*7c478bd9Sstevel@tonic-gate 
236*7c478bd9Sstevel@tonic-gate 
237*7c478bd9Sstevel@tonic-gate static int
set_list(void)238*7c478bd9Sstevel@tonic-gate set_list(void)
239*7c478bd9Sstevel@tonic-gate {
240*7c478bd9Sstevel@tonic-gate 	int olderrors;
241*7c478bd9Sstevel@tonic-gate 	char *token = currtok();
242*7c478bd9Sstevel@tonic-gate 
243*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "set_list() {");
244*7c478bd9Sstevel@tonic-gate 	errlog(VERBOSE, "token = '%s'",
245*7c478bd9Sstevel@tonic-gate 	    (token) ? token : "<NULL>");
246*7c478bd9Sstevel@tonic-gate 	if (set() == FALSE) {
247*7c478bd9Sstevel@tonic-gate 		errlog(END, "} /* set_list */");
248*7c478bd9Sstevel@tonic-gate 		return (FALSE);
249*7c478bd9Sstevel@tonic-gate 	}
250*7c478bd9Sstevel@tonic-gate 
251*7c478bd9Sstevel@tonic-gate 	olderrors = Errors;
252*7c478bd9Sstevel@tonic-gate 	while (set()) {
253*7c478bd9Sstevel@tonic-gate 		continue;
254*7c478bd9Sstevel@tonic-gate 	}
255*7c478bd9Sstevel@tonic-gate 	if (olderrors != Errors) {
256*7c478bd9Sstevel@tonic-gate 		errlog(END, "} /* set_list */");
257*7c478bd9Sstevel@tonic-gate 		return (FALSE);
258*7c478bd9Sstevel@tonic-gate 	}
259*7c478bd9Sstevel@tonic-gate 
260*7c478bd9Sstevel@tonic-gate 	errlog(END, "} /* set_list */");
261*7c478bd9Sstevel@tonic-gate 	return (TRUE);
262*7c478bd9Sstevel@tonic-gate }
263*7c478bd9Sstevel@tonic-gate 
264*7c478bd9Sstevel@tonic-gate 
265*7c478bd9Sstevel@tonic-gate static int
set(void)266*7c478bd9Sstevel@tonic-gate set(void)
267*7c478bd9Sstevel@tonic-gate {
268*7c478bd9Sstevel@tonic-gate 	char *token = currtok();
269*7c478bd9Sstevel@tonic-gate 	int has_parent = 0;
270*7c478bd9Sstevel@tonic-gate 
271*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "set() {");
272*7c478bd9Sstevel@tonic-gate 	errlog(VERBOSE, "token = '%s'",
273*7c478bd9Sstevel@tonic-gate 	    (token) ? token : "<NULL>");
274*7c478bd9Sstevel@tonic-gate 
275*7c478bd9Sstevel@tonic-gate 	if (in_specials(*token)) {
276*7c478bd9Sstevel@tonic-gate 		errlog(INPUT|ERROR, "unexpected token \"%s\" found. "
277*7c478bd9Sstevel@tonic-gate 		    "Version name expected", token);
278*7c478bd9Sstevel@tonic-gate 		Errors++;
279*7c478bd9Sstevel@tonic-gate 		errlog(END, "} /* set */");
280*7c478bd9Sstevel@tonic-gate 		return (FALSE);
281*7c478bd9Sstevel@tonic-gate 	}
282*7c478bd9Sstevel@tonic-gate 
283*7c478bd9Sstevel@tonic-gate 	errlog(VERBOSE, "Begin Version: %s", token);
284*7c478bd9Sstevel@tonic-gate 	*Previous = '\0';
285*7c478bd9Sstevel@tonic-gate 	if (Selected) {
286*7c478bd9Sstevel@tonic-gate 		if (add_parent(token, Previous, 0) == FALSE) {
287*7c478bd9Sstevel@tonic-gate 			errlog(INPUT | ERROR, "unable to add a parent version "
288*7c478bd9Sstevel@tonic-gate 			    "from the set file");
289*7c478bd9Sstevel@tonic-gate 			Errors++;
290*7c478bd9Sstevel@tonic-gate 			errlog(END, "} /* set */");
291*7c478bd9Sstevel@tonic-gate 			return (FALSE);
292*7c478bd9Sstevel@tonic-gate 		}
293*7c478bd9Sstevel@tonic-gate 	}
294*7c478bd9Sstevel@tonic-gate 
295*7c478bd9Sstevel@tonic-gate 	add_valid_version(token);
296*7c478bd9Sstevel@tonic-gate 	(void) strncpy(LeftMostChild, token, MAXLINE);
297*7c478bd9Sstevel@tonic-gate 	LeftMostChild[MAXLINE-1] = '\0';
298*7c478bd9Sstevel@tonic-gate 	(void) strncpy(Previous, token, MAXLINE);
299*7c478bd9Sstevel@tonic-gate 	Previous[MAXLINE-1] = '\0';
300*7c478bd9Sstevel@tonic-gate 
301*7c478bd9Sstevel@tonic-gate 	token = nexttok();
302*7c478bd9Sstevel@tonic-gate 
303*7c478bd9Sstevel@tonic-gate 	switch (*token) {
304*7c478bd9Sstevel@tonic-gate 		case ':':
305*7c478bd9Sstevel@tonic-gate 			errlog(VERBOSE, "token ':' found");
306*7c478bd9Sstevel@tonic-gate 			(void) accept_token(":");
307*7c478bd9Sstevel@tonic-gate 			if (set_parents() == FALSE) {
308*7c478bd9Sstevel@tonic-gate 				errlog(END, "} /* set */");
309*7c478bd9Sstevel@tonic-gate 				return (FALSE);
310*7c478bd9Sstevel@tonic-gate 			}
311*7c478bd9Sstevel@tonic-gate 			if (accept_token(";") == FALSE) {
312*7c478bd9Sstevel@tonic-gate 				errlog(END, "} /* set */");
313*7c478bd9Sstevel@tonic-gate 				return (FALSE);
314*7c478bd9Sstevel@tonic-gate 			}
315*7c478bd9Sstevel@tonic-gate 			errlog(VERBOSE, "End Version");
316*7c478bd9Sstevel@tonic-gate 			break;
317*7c478bd9Sstevel@tonic-gate 
318*7c478bd9Sstevel@tonic-gate 		case ';':
319*7c478bd9Sstevel@tonic-gate 			errlog(VERBOSE, "token ';' found");
320*7c478bd9Sstevel@tonic-gate 			(void) accept_token(";");
321*7c478bd9Sstevel@tonic-gate 			errlog(VERBOSE, "End version ':'");
322*7c478bd9Sstevel@tonic-gate 			break;
323*7c478bd9Sstevel@tonic-gate 
324*7c478bd9Sstevel@tonic-gate 		case '[':
325*7c478bd9Sstevel@tonic-gate 			(void) accept_token("[");
326*7c478bd9Sstevel@tonic-gate 			if (accept_token("WEAK") == FALSE) {
327*7c478bd9Sstevel@tonic-gate 				errlog(END, "} /* set */");
328*7c478bd9Sstevel@tonic-gate 				return (FALSE);
329*7c478bd9Sstevel@tonic-gate 			}
330*7c478bd9Sstevel@tonic-gate 			if (accept_token("]") == FALSE) {
331*7c478bd9Sstevel@tonic-gate 				errlog(END, "} /* set */");
332*7c478bd9Sstevel@tonic-gate 				return (FALSE);
333*7c478bd9Sstevel@tonic-gate 			}
334*7c478bd9Sstevel@tonic-gate 			token = currtok();
335*7c478bd9Sstevel@tonic-gate 			if (eq(token, ":")) {
336*7c478bd9Sstevel@tonic-gate 				(void) accept_token(":");
337*7c478bd9Sstevel@tonic-gate 				has_parent = 1;
338*7c478bd9Sstevel@tonic-gate 			} else if (eq(token, ";")) {
339*7c478bd9Sstevel@tonic-gate 				(void) accept_token(";");
340*7c478bd9Sstevel@tonic-gate 			} else {
341*7c478bd9Sstevel@tonic-gate 				errlog(ERROR|INPUT,
342*7c478bd9Sstevel@tonic-gate 				    "Unexpected token \"%s\" found. ':'"
343*7c478bd9Sstevel@tonic-gate 				    "or ';' expected.", token);
344*7c478bd9Sstevel@tonic-gate 				Errors++;
345*7c478bd9Sstevel@tonic-gate 				errlog(END, "} /* set */");
346*7c478bd9Sstevel@tonic-gate 				return (FALSE);
347*7c478bd9Sstevel@tonic-gate 			}
348*7c478bd9Sstevel@tonic-gate 			errlog(VERBOSE, "WEAK version detected\n");
349*7c478bd9Sstevel@tonic-gate 			if (Selected)
350*7c478bd9Sstevel@tonic-gate 				set_weak(LeftMostChild, TRUE);
351*7c478bd9Sstevel@tonic-gate 
352*7c478bd9Sstevel@tonic-gate 			if (has_parent) {
353*7c478bd9Sstevel@tonic-gate 				if (set_parents() == FALSE) {
354*7c478bd9Sstevel@tonic-gate 					errlog(END, "} /* set */");
355*7c478bd9Sstevel@tonic-gate 					return (FALSE);
356*7c478bd9Sstevel@tonic-gate 				}
357*7c478bd9Sstevel@tonic-gate 				if (accept_token(";") == FALSE) {
358*7c478bd9Sstevel@tonic-gate 					errlog(END, "} /* set */");
359*7c478bd9Sstevel@tonic-gate 					return (FALSE);
360*7c478bd9Sstevel@tonic-gate 				}
361*7c478bd9Sstevel@tonic-gate 			}
362*7c478bd9Sstevel@tonic-gate 			errlog(VERBOSE, "End Version");
363*7c478bd9Sstevel@tonic-gate 			break;
364*7c478bd9Sstevel@tonic-gate 		default:
365*7c478bd9Sstevel@tonic-gate 			/* CSTYLED */
366*7c478bd9Sstevel@tonic-gate 			errlog(ERROR|INPUT,
367*7c478bd9Sstevel@tonic-gate 			    "Unexpected token \"%s\" found. ';' expected.",
368*7c478bd9Sstevel@tonic-gate 			    token);
369*7c478bd9Sstevel@tonic-gate 			Errors++;
370*7c478bd9Sstevel@tonic-gate 			errlog(END, "} /* set */");
371*7c478bd9Sstevel@tonic-gate 			return (FALSE);
372*7c478bd9Sstevel@tonic-gate 	}
373*7c478bd9Sstevel@tonic-gate 
374*7c478bd9Sstevel@tonic-gate 	token = currtok();
375*7c478bd9Sstevel@tonic-gate 	if (eq(token, "}")) {
376*7c478bd9Sstevel@tonic-gate 		(void) accept_token("}");
377*7c478bd9Sstevel@tonic-gate 		errlog(VERBOSE, "End architecture");
378*7c478bd9Sstevel@tonic-gate 		errlog(END, "} /* set */");
379*7c478bd9Sstevel@tonic-gate 		return (FALSE);
380*7c478bd9Sstevel@tonic-gate 	}
381*7c478bd9Sstevel@tonic-gate 
382*7c478bd9Sstevel@tonic-gate 	errlog(END, "} /* set */");
383*7c478bd9Sstevel@tonic-gate 	return (TRUE);
384*7c478bd9Sstevel@tonic-gate }
385*7c478bd9Sstevel@tonic-gate 
386*7c478bd9Sstevel@tonic-gate static int
set_parents(void)387*7c478bd9Sstevel@tonic-gate set_parents(void)
388*7c478bd9Sstevel@tonic-gate {
389*7c478bd9Sstevel@tonic-gate 	char *token = currtok();
390*7c478bd9Sstevel@tonic-gate 	int uncle;
391*7c478bd9Sstevel@tonic-gate 
392*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "set_parents() {");
393*7c478bd9Sstevel@tonic-gate 	errlog(VERBOSE, "token = '%s'",
394*7c478bd9Sstevel@tonic-gate 	    (token) ? token : "<NULL>");
395*7c478bd9Sstevel@tonic-gate 
396*7c478bd9Sstevel@tonic-gate 	if (accept_token("{") == FALSE) {
397*7c478bd9Sstevel@tonic-gate 		errlog(INPUT|ERROR, "set_parents(): Unexpected token: %s\n",
398*7c478bd9Sstevel@tonic-gate 		    token);
399*7c478bd9Sstevel@tonic-gate 		Errors++;
400*7c478bd9Sstevel@tonic-gate 		errlog(END, "} /* set_parents */");
401*7c478bd9Sstevel@tonic-gate 		return (FALSE);
402*7c478bd9Sstevel@tonic-gate 	}
403*7c478bd9Sstevel@tonic-gate 
404*7c478bd9Sstevel@tonic-gate 	token = currtok();
405*7c478bd9Sstevel@tonic-gate 
406*7c478bd9Sstevel@tonic-gate 	if (in_specials(*token)) {
407*7c478bd9Sstevel@tonic-gate 		errlog(INPUT|ERROR, "set_parents(): Unexpected token: %c "
408*7c478bd9Sstevel@tonic-gate 		    "found. Version token expected", *token);
409*7c478bd9Sstevel@tonic-gate 		Errors++;
410*7c478bd9Sstevel@tonic-gate 		errlog(END, "} /* set_parents */");
411*7c478bd9Sstevel@tonic-gate 		return (FALSE);
412*7c478bd9Sstevel@tonic-gate 	}
413*7c478bd9Sstevel@tonic-gate 
414*7c478bd9Sstevel@tonic-gate 	uncle = 0;
415*7c478bd9Sstevel@tonic-gate 	while (token && *token != '}') {
416*7c478bd9Sstevel@tonic-gate 		errlog(VERBOSE, "Begin parent list: %s\n", token);
417*7c478bd9Sstevel@tonic-gate 		if (Selected) {
418*7c478bd9Sstevel@tonic-gate 			if (uncle)
419*7c478bd9Sstevel@tonic-gate 				(void) add_uncle(token, LeftMostChild, 0);
420*7c478bd9Sstevel@tonic-gate 			else
421*7c478bd9Sstevel@tonic-gate 				(void) add_parent(token, Previous, 0);
422*7c478bd9Sstevel@tonic-gate 		}
423*7c478bd9Sstevel@tonic-gate 		(void) strncpy(Previous, token, MAXLINE);
424*7c478bd9Sstevel@tonic-gate 		add_valid_version(token);
425*7c478bd9Sstevel@tonic-gate 		Previous[MAXLINE-1] = '\0';
426*7c478bd9Sstevel@tonic-gate 
427*7c478bd9Sstevel@tonic-gate 		token = nexttok();
428*7c478bd9Sstevel@tonic-gate 
429*7c478bd9Sstevel@tonic-gate 		if (*token == ',') {
430*7c478bd9Sstevel@tonic-gate 			token = nexttok();
431*7c478bd9Sstevel@tonic-gate 			/* following identifiers are all uncles */
432*7c478bd9Sstevel@tonic-gate 			uncle = 1;
433*7c478bd9Sstevel@tonic-gate 			continue;
434*7c478bd9Sstevel@tonic-gate 		}
435*7c478bd9Sstevel@tonic-gate 
436*7c478bd9Sstevel@tonic-gate 		if (*token == '}') {
437*7c478bd9Sstevel@tonic-gate 			if (accept_token("}") == FALSE) {
438*7c478bd9Sstevel@tonic-gate 				errlog(END, "} /* set_parents */");
439*7c478bd9Sstevel@tonic-gate 				return (FALSE);
440*7c478bd9Sstevel@tonic-gate 			}
441*7c478bd9Sstevel@tonic-gate 			errlog(VERBOSE, "set_parent: End of parent list");
442*7c478bd9Sstevel@tonic-gate 			errlog(END, "} /* set_parents */");
443*7c478bd9Sstevel@tonic-gate 			return (TRUE);
444*7c478bd9Sstevel@tonic-gate 		}
445*7c478bd9Sstevel@tonic-gate 
446*7c478bd9Sstevel@tonic-gate 		errlog(INPUT|ERROR,
447*7c478bd9Sstevel@tonic-gate 		    "set_parents(): Unexpected token \"%s\" "
448*7c478bd9Sstevel@tonic-gate 		    "found. ',' or '}' were expected", token);
449*7c478bd9Sstevel@tonic-gate 		Errors++;
450*7c478bd9Sstevel@tonic-gate 		errlog(END, "} /* set_parents */");
451*7c478bd9Sstevel@tonic-gate 		return (FALSE);
452*7c478bd9Sstevel@tonic-gate 	}
453*7c478bd9Sstevel@tonic-gate 	errlog(END, "} /* set_parents */");
454*7c478bd9Sstevel@tonic-gate 	return (TRUE);
455*7c478bd9Sstevel@tonic-gate }
456*7c478bd9Sstevel@tonic-gate 
457*7c478bd9Sstevel@tonic-gate 
458*7c478bd9Sstevel@tonic-gate /*
459*7c478bd9Sstevel@tonic-gate  * parser support routines
460*7c478bd9Sstevel@tonic-gate  */
461*7c478bd9Sstevel@tonic-gate 
462*7c478bd9Sstevel@tonic-gate 
463*7c478bd9Sstevel@tonic-gate /*
464*7c478bd9Sstevel@tonic-gate  * accept_token -- get a specified token or complain loudly.
465*7c478bd9Sstevel@tonic-gate  */
466*7c478bd9Sstevel@tonic-gate static int
accept_token(char * expected)467*7c478bd9Sstevel@tonic-gate accept_token(char *expected)
468*7c478bd9Sstevel@tonic-gate {
469*7c478bd9Sstevel@tonic-gate 	char *token = currtok();
470*7c478bd9Sstevel@tonic-gate 
471*7c478bd9Sstevel@tonic-gate 	assert(expected != NULL, "null token passed to accept_token");
472*7c478bd9Sstevel@tonic-gate 	errlog(OTHER | TRACING, "accept_token, at %s expecting %s",
473*7c478bd9Sstevel@tonic-gate 		(token) ? token : "<NULL>", expected);
474*7c478bd9Sstevel@tonic-gate 
475*7c478bd9Sstevel@tonic-gate 	if (token == NULL) {
476*7c478bd9Sstevel@tonic-gate 		/* We're at EOF */
477*7c478bd9Sstevel@tonic-gate 		return (TRUE);
478*7c478bd9Sstevel@tonic-gate 	}
479*7c478bd9Sstevel@tonic-gate 	if (eq(token, expected)) {
480*7c478bd9Sstevel@tonic-gate 		(void) nexttok();
481*7c478bd9Sstevel@tonic-gate 		return (TRUE);
482*7c478bd9Sstevel@tonic-gate 	} else {
483*7c478bd9Sstevel@tonic-gate 		errlog(INPUT | ERROR,
484*7c478bd9Sstevel@tonic-gate 			"accept_token, found %s while looking for %s",
485*7c478bd9Sstevel@tonic-gate 			(token) ? token : "<NULL>", expected);
486*7c478bd9Sstevel@tonic-gate 		++Errors;
487*7c478bd9Sstevel@tonic-gate 		return (FALSE);
488*7c478bd9Sstevel@tonic-gate 	}
489*7c478bd9Sstevel@tonic-gate }
490*7c478bd9Sstevel@tonic-gate 
491*7c478bd9Sstevel@tonic-gate static void
skip_to(char * target)492*7c478bd9Sstevel@tonic-gate skip_to(char *target)
493*7c478bd9Sstevel@tonic-gate {
494*7c478bd9Sstevel@tonic-gate 	char *token = currtok();
495*7c478bd9Sstevel@tonic-gate 
496*7c478bd9Sstevel@tonic-gate 	assert(target != NULL, "null target passed to skip_to");
497*7c478bd9Sstevel@tonic-gate 	while (token && !eq(token, target)) {
498*7c478bd9Sstevel@tonic-gate 		errlog(VERBOSE, "skipping over %s",
499*7c478bd9Sstevel@tonic-gate 			(token) ? token : "<NULL>");
500*7c478bd9Sstevel@tonic-gate 		token = nexttok();
501*7c478bd9Sstevel@tonic-gate 	}
502*7c478bd9Sstevel@tonic-gate }
503*7c478bd9Sstevel@tonic-gate 
504*7c478bd9Sstevel@tonic-gate 
505*7c478bd9Sstevel@tonic-gate /*
506*7c478bd9Sstevel@tonic-gate  * tokenizer -- below the grammar lives this, like a troll
507*7c478bd9Sstevel@tonic-gate  *	under a bridge.
508*7c478bd9Sstevel@tonic-gate  */
509*7c478bd9Sstevel@tonic-gate 
510*7c478bd9Sstevel@tonic-gate 
511*7c478bd9Sstevel@tonic-gate /*
512*7c478bd9Sstevel@tonic-gate  * skipb -- skip over blanks (whitespace, actually), stopping
513*7c478bd9Sstevel@tonic-gate  *      on first non-blank.
514*7c478bd9Sstevel@tonic-gate  */
515*7c478bd9Sstevel@tonic-gate static char *
skipb(char * p)516*7c478bd9Sstevel@tonic-gate skipb(char *p)
517*7c478bd9Sstevel@tonic-gate {
518*7c478bd9Sstevel@tonic-gate 
519*7c478bd9Sstevel@tonic-gate 	while (*p && isspace(*p))
520*7c478bd9Sstevel@tonic-gate 		++p;
521*7c478bd9Sstevel@tonic-gate 	return (p);
522*7c478bd9Sstevel@tonic-gate }
523*7c478bd9Sstevel@tonic-gate 
524*7c478bd9Sstevel@tonic-gate /*
525*7c478bd9Sstevel@tonic-gate  * skipover -- skip over non-separators (alnum, . and _, actually),
526*7c478bd9Sstevel@tonic-gate  *      stopping on first separator.
527*7c478bd9Sstevel@tonic-gate  */
528*7c478bd9Sstevel@tonic-gate static char *
skipover(char * p)529*7c478bd9Sstevel@tonic-gate skipover(char *p)
530*7c478bd9Sstevel@tonic-gate {
531*7c478bd9Sstevel@tonic-gate 
532*7c478bd9Sstevel@tonic-gate 	while (*p && (isalnum(*p) || (*p == '_' || *p == '.')))
533*7c478bd9Sstevel@tonic-gate 		++p;
534*7c478bd9Sstevel@tonic-gate 	return (p);
535*7c478bd9Sstevel@tonic-gate }
536*7c478bd9Sstevel@tonic-gate 
537*7c478bd9Sstevel@tonic-gate 
538*7c478bd9Sstevel@tonic-gate /*
539*7c478bd9Sstevel@tonic-gate  * currtok/nexttok -- get the current/next token
540*7c478bd9Sstevel@tonic-gate  */
541*7c478bd9Sstevel@tonic-gate static char *
currtok(void)542*7c478bd9Sstevel@tonic-gate currtok(void)
543*7c478bd9Sstevel@tonic-gate {
544*7c478bd9Sstevel@tonic-gate 
545*7c478bd9Sstevel@tonic-gate 	if (CurrTok == NULL) {
546*7c478bd9Sstevel@tonic-gate 		(void) nexttok();
547*7c478bd9Sstevel@tonic-gate 	}
548*7c478bd9Sstevel@tonic-gate 	return (CurrTok);
549*7c478bd9Sstevel@tonic-gate }
550*7c478bd9Sstevel@tonic-gate 
551*7c478bd9Sstevel@tonic-gate static char *
nexttok(void)552*7c478bd9Sstevel@tonic-gate nexttok(void)
553*7c478bd9Sstevel@tonic-gate {
554*7c478bd9Sstevel@tonic-gate 	static char line[MAXLINE];
555*7c478bd9Sstevel@tonic-gate 	char *p;
556*7c478bd9Sstevel@tonic-gate 
557*7c478bd9Sstevel@tonic-gate 	if ((p = tokenize(NULL)) == NULL) {
558*7c478bd9Sstevel@tonic-gate 		/* We're at an end of line. */
559*7c478bd9Sstevel@tonic-gate 		do {
560*7c478bd9Sstevel@tonic-gate 			if (fgets(line, sizeof (line), Fp) == NULL) {
561*7c478bd9Sstevel@tonic-gate 				/* Which is also end of file. */
562*7c478bd9Sstevel@tonic-gate 				CurrTok = NULL;
563*7c478bd9Sstevel@tonic-gate 				return (NULL);
564*7c478bd9Sstevel@tonic-gate 			}
565*7c478bd9Sstevel@tonic-gate 			++Line;
566*7c478bd9Sstevel@tonic-gate 			seterrline(Line, Filename, "", line);
567*7c478bd9Sstevel@tonic-gate 		} while ((p = tokenize(line)) == NULL);
568*7c478bd9Sstevel@tonic-gate 	}
569*7c478bd9Sstevel@tonic-gate 	CurrTok = p;
570*7c478bd9Sstevel@tonic-gate 	return (p);
571*7c478bd9Sstevel@tonic-gate }
572*7c478bd9Sstevel@tonic-gate 
573*7c478bd9Sstevel@tonic-gate 
574*7c478bd9Sstevel@tonic-gate 
575*7c478bd9Sstevel@tonic-gate /*
576*7c478bd9Sstevel@tonic-gate  * tokenize -- a version of the standard strtok with specific behavior.
577*7c478bd9Sstevel@tonic-gate  */
578*7c478bd9Sstevel@tonic-gate static char *
tokenize(char * line)579*7c478bd9Sstevel@tonic-gate tokenize(char *line)
580*7c478bd9Sstevel@tonic-gate {
581*7c478bd9Sstevel@tonic-gate 	static char *p = NULL;
582*7c478bd9Sstevel@tonic-gate 	static char saved = 0;
583*7c478bd9Sstevel@tonic-gate 	char *q;
584*7c478bd9Sstevel@tonic-gate 
585*7c478bd9Sstevel@tonic-gate 	if (line == NULL && p == NULL) {
586*7c478bd9Sstevel@tonic-gate 		/* It's the very first time */
587*7c478bd9Sstevel@tonic-gate 		return (NULL);
588*7c478bd9Sstevel@tonic-gate 	} else if (line != NULL) {
589*7c478bd9Sstevel@tonic-gate 		/* Initialize with a new line */
590*7c478bd9Sstevel@tonic-gate 		q = skipb(line);
591*7c478bd9Sstevel@tonic-gate 	} else {
592*7c478bd9Sstevel@tonic-gate 		/* Restore previous line. */
593*7c478bd9Sstevel@tonic-gate 		*p = saved;
594*7c478bd9Sstevel@tonic-gate 		q = skipb(p);
595*7c478bd9Sstevel@tonic-gate 	}
596*7c478bd9Sstevel@tonic-gate 	/* q is at the beginning of a token or at EOL, p is irrelevant. */
597*7c478bd9Sstevel@tonic-gate 
598*7c478bd9Sstevel@tonic-gate 	if (*q == '\0') {
599*7c478bd9Sstevel@tonic-gate 		/* It's at EOL. */
600*7c478bd9Sstevel@tonic-gate 		p = q;
601*7c478bd9Sstevel@tonic-gate 	} else if (in_specials(*q)) {
602*7c478bd9Sstevel@tonic-gate 		/* We have a special-character token. */
603*7c478bd9Sstevel@tonic-gate 		p = q + 1;
604*7c478bd9Sstevel@tonic-gate 	} else if (*q == '#') {
605*7c478bd9Sstevel@tonic-gate 		/* The whole rest of the line is a comment token. */
606*7c478bd9Sstevel@tonic-gate 		return (NULL);
607*7c478bd9Sstevel@tonic-gate 	} else {
608*7c478bd9Sstevel@tonic-gate 		/* We have a word token. */
609*7c478bd9Sstevel@tonic-gate 		p = skipover(q);
610*7c478bd9Sstevel@tonic-gate 	}
611*7c478bd9Sstevel@tonic-gate 	saved = *p;
612*7c478bd9Sstevel@tonic-gate 	*p = '\0';
613*7c478bd9Sstevel@tonic-gate 
614*7c478bd9Sstevel@tonic-gate 	if (p == q) {
615*7c478bd9Sstevel@tonic-gate 		/* End of line */
616*7c478bd9Sstevel@tonic-gate 		return (NULL);
617*7c478bd9Sstevel@tonic-gate 	} else {
618*7c478bd9Sstevel@tonic-gate 		return (q);
619*7c478bd9Sstevel@tonic-gate 	}
620*7c478bd9Sstevel@tonic-gate }
621*7c478bd9Sstevel@tonic-gate 
622*7c478bd9Sstevel@tonic-gate 
623*7c478bd9Sstevel@tonic-gate /*
624*7c478bd9Sstevel@tonic-gate  * valid_version -- see if a version string was mentioned in the set file.
625*7c478bd9Sstevel@tonic-gate  */
626*7c478bd9Sstevel@tonic-gate int
valid_version(const char * vers_name)627*7c478bd9Sstevel@tonic-gate valid_version(const char *vers_name)
628*7c478bd9Sstevel@tonic-gate {
629*7c478bd9Sstevel@tonic-gate 
630*7c478bd9Sstevel@tonic-gate 	if (Vers == NULL) {
631*7c478bd9Sstevel@tonic-gate 		init_tables();
632*7c478bd9Sstevel@tonic-gate 	}
633*7c478bd9Sstevel@tonic-gate 	return (in_stringtable(Vers, vers_name));
634*7c478bd9Sstevel@tonic-gate }
635*7c478bd9Sstevel@tonic-gate 
636*7c478bd9Sstevel@tonic-gate /*
637*7c478bd9Sstevel@tonic-gate  * valid_arch -- see if the arch was mentioned in the set file.
638*7c478bd9Sstevel@tonic-gate  */
639*7c478bd9Sstevel@tonic-gate int
valid_arch(const char * arch_name)640*7c478bd9Sstevel@tonic-gate valid_arch(const char *arch_name)
641*7c478bd9Sstevel@tonic-gate {
642*7c478bd9Sstevel@tonic-gate 
643*7c478bd9Sstevel@tonic-gate 	if (Vers == NULL) {
644*7c478bd9Sstevel@tonic-gate 		init_tables();
645*7c478bd9Sstevel@tonic-gate 	}
646*7c478bd9Sstevel@tonic-gate 	return (in_stringtable(Varch, arch_name));
647*7c478bd9Sstevel@tonic-gate }
648*7c478bd9Sstevel@tonic-gate 
649*7c478bd9Sstevel@tonic-gate /*
650*7c478bd9Sstevel@tonic-gate  * add_valid_version and _arch -- add a name to the table.
651*7c478bd9Sstevel@tonic-gate  */
652*7c478bd9Sstevel@tonic-gate static void
add_valid_version(char * vers_name)653*7c478bd9Sstevel@tonic-gate add_valid_version(char *vers_name)
654*7c478bd9Sstevel@tonic-gate {
655*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "add_valid_version(\"%s\") {", vers_name);
656*7c478bd9Sstevel@tonic-gate 	if (Vers == NULL) {
657*7c478bd9Sstevel@tonic-gate 		init_tables();
658*7c478bd9Sstevel@tonic-gate 	}
659*7c478bd9Sstevel@tonic-gate 	Vers = add_to_stringtable(Vers, vers_name);
660*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
661*7c478bd9Sstevel@tonic-gate }
662*7c478bd9Sstevel@tonic-gate 
663*7c478bd9Sstevel@tonic-gate static void
add_valid_arch(char * arch_name)664*7c478bd9Sstevel@tonic-gate add_valid_arch(char *arch_name)
665*7c478bd9Sstevel@tonic-gate {
666*7c478bd9Sstevel@tonic-gate 
667*7c478bd9Sstevel@tonic-gate 	errlog(BEGIN, "add_valid_arch(\"%s\") {", arch_name);
668*7c478bd9Sstevel@tonic-gate 	if (Vers == NULL) {
669*7c478bd9Sstevel@tonic-gate 		init_tables();
670*7c478bd9Sstevel@tonic-gate 	}
671*7c478bd9Sstevel@tonic-gate 	Varch = add_to_stringtable(Varch, arch_name);
672*7c478bd9Sstevel@tonic-gate 	errlog(END, "}");
673*7c478bd9Sstevel@tonic-gate }
674*7c478bd9Sstevel@tonic-gate 
675*7c478bd9Sstevel@tonic-gate /*
676*7c478bd9Sstevel@tonic-gate  * init_tables -- creat them when first used.
677*7c478bd9Sstevel@tonic-gate  */
678*7c478bd9Sstevel@tonic-gate static void
init_tables(void)679*7c478bd9Sstevel@tonic-gate init_tables(void)
680*7c478bd9Sstevel@tonic-gate {
681*7c478bd9Sstevel@tonic-gate 	Vers = create_stringtable(TABLE_INITIAL);
682*7c478bd9Sstevel@tonic-gate 	Varch = create_stringtable(TABLE_INITIAL);
683*7c478bd9Sstevel@tonic-gate }
684