xref: /titanic_51/usr/src/cmd/geniconvtbl/itmcomp.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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) 1999 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <stdio.h>
30*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
31*7c478bd9Sstevel@tonic-gate #include <unistd.h>
32*7c478bd9Sstevel@tonic-gate #include <libgen.h>
33*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
34*7c478bd9Sstevel@tonic-gate #include <locale.h>
35*7c478bd9Sstevel@tonic-gate #include <string.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/wait.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
38*7c478bd9Sstevel@tonic-gate #include <stdarg.h>
39*7c478bd9Sstevel@tonic-gate #include <errno.h>
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate #include "itmcomp.h"
42*7c478bd9Sstevel@tonic-gate #include "maptype.h"
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
45*7c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN	"SYS_TEST"
46*7c478bd9Sstevel@tonic-gate #endif
47*7c478bd9Sstevel@tonic-gate #define	ITMSUFFIX	".bt"
48*7c478bd9Sstevel@tonic-gate #define	ME_DEFAULT	"geniconvtbl"
49*7c478bd9Sstevel@tonic-gate #define	CPP_PATH	"/usr/lib/cpp"
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate itmc_ref_t	*ref_first[ITMC_OBJ_LAST + 1];
52*7c478bd9Sstevel@tonic-gate itmc_ref_t	*ref_last[ITMC_OBJ_LAST + 1];
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate itmc_name_t	*name_first;
55*7c478bd9Sstevel@tonic-gate itmc_name_t	*name_last;
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate char		*itm_input_file;		/* referred in itm_comp.l */
58*7c478bd9Sstevel@tonic-gate char		*itm_output_file;
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate cmd_opt_t	cmd_opt;
61*7c478bd9Sstevel@tonic-gate itm_num_t	name_id;
62*7c478bd9Sstevel@tonic-gate itm_num_t	reg_id;
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate itmc_name_t	name_lookup_error;
65*7c478bd9Sstevel@tonic-gate int		error_deferred;
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate char *itm_name_type_name[] = {
68*7c478bd9Sstevel@tonic-gate 	"UNKNOWN",
69*7c478bd9Sstevel@tonic-gate 	"ITM",
70*7c478bd9Sstevel@tonic-gate 	"STRING",
71*7c478bd9Sstevel@tonic-gate 	"DIRECTION",
72*7c478bd9Sstevel@tonic-gate 	"CONDITION",
73*7c478bd9Sstevel@tonic-gate 	"MAP",
74*7c478bd9Sstevel@tonic-gate 	"OPERATION",
75*7c478bd9Sstevel@tonic-gate 	"EXPRESSION",
76*7c478bd9Sstevel@tonic-gate 	"DATA",
77*7c478bd9Sstevel@tonic-gate 	"NAME",
78*7c478bd9Sstevel@tonic-gate 	"RANGE",
79*7c478bd9Sstevel@tonic-gate 	"REGISTER",
80*7c478bd9Sstevel@tonic-gate };
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate static void	usage(int status);
84*7c478bd9Sstevel@tonic-gate static int	cpp_opt_append(char	*opt, char	*arg);
85*7c478bd9Sstevel@tonic-gate static void	cpp_opt_trunc(int num);
86*7c478bd9Sstevel@tonic-gate static int	parse_opts(int argc, char	**argv);
87*7c478bd9Sstevel@tonic-gate static char	*prog_path_expand(const char	*base_name);
88*7c478bd9Sstevel@tonic-gate static void	map_name_type_append(char	*optarg);
89*7c478bd9Sstevel@tonic-gate static char	*map_type_name_str(itmc_map_type_t);
90*7c478bd9Sstevel@tonic-gate static char	*strdup_vital(const char *);
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate #if defined(ENABLE_TRACE)
93*7c478bd9Sstevel@tonic-gate static void	trace_option(void);
94*7c478bd9Sstevel@tonic-gate #endif /* ENABLE_TRACE */
95*7c478bd9Sstevel@tonic-gate static FILE	*cpp_open(void);
96*7c478bd9Sstevel@tonic-gate static void	cpp_close(FILE		*fp);
97*7c478bd9Sstevel@tonic-gate static int	itm_compile(char	*file);
98*7c478bd9Sstevel@tonic-gate static void	wait_child(pid_t pid);
99*7c478bd9Sstevel@tonic-gate static int	fork_error(void);
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate int
105*7c478bd9Sstevel@tonic-gate main(int argc, char **argv)
106*7c478bd9Sstevel@tonic-gate {
107*7c478bd9Sstevel@tonic-gate 	char	**pp;
108*7c478bd9Sstevel@tonic-gate 	pid_t	pid;
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate 	(void) parse_opts(argc, argv);
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate #if defined(ENABLE_TRACE)
117*7c478bd9Sstevel@tonic-gate 	trace_option();
118*7c478bd9Sstevel@tonic-gate #endif /* ENABLE_TRACE */
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate 	if (NULL != cmd_opt.disassemble) {
121*7c478bd9Sstevel@tonic-gate 		disassemble(cmd_opt.disassemble);
122*7c478bd9Sstevel@tonic-gate 	} else if (NULL == cmd_opt.input_file) {
123*7c478bd9Sstevel@tonic-gate 		(void) itm_compile(NULL);
124*7c478bd9Sstevel@tonic-gate 	} else {
125*7c478bd9Sstevel@tonic-gate 		if (1 < cmd_opt.input_file_num) {
126*7c478bd9Sstevel@tonic-gate 			for (pp = cmd_opt.input_file; *pp; pp++) {
127*7c478bd9Sstevel@tonic-gate 				(void) printf("%s:\n", *pp);
128*7c478bd9Sstevel@tonic-gate 				pid = fork();
129*7c478bd9Sstevel@tonic-gate 				switch (pid) {
130*7c478bd9Sstevel@tonic-gate 				case 0:
131*7c478bd9Sstevel@tonic-gate 					exit(itm_compile(*pp));
132*7c478bd9Sstevel@tonic-gate 					break;
133*7c478bd9Sstevel@tonic-gate 				case -1:
134*7c478bd9Sstevel@tonic-gate 					(void) fork_error();
135*7c478bd9Sstevel@tonic-gate 					break;
136*7c478bd9Sstevel@tonic-gate 				default:
137*7c478bd9Sstevel@tonic-gate 					wait_child(pid);
138*7c478bd9Sstevel@tonic-gate 				}
139*7c478bd9Sstevel@tonic-gate 			}
140*7c478bd9Sstevel@tonic-gate 		} else {
141*7c478bd9Sstevel@tonic-gate 			(void) itm_compile(*(cmd_opt.input_file));
142*7c478bd9Sstevel@tonic-gate 		}
143*7c478bd9Sstevel@tonic-gate 	}
144*7c478bd9Sstevel@tonic-gate 
145*7c478bd9Sstevel@tonic-gate 	return (0);
146*7c478bd9Sstevel@tonic-gate }
147*7c478bd9Sstevel@tonic-gate 
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate static int
150*7c478bd9Sstevel@tonic-gate itm_compile(char *file)
151*7c478bd9Sstevel@tonic-gate {
152*7c478bd9Sstevel@tonic-gate 	char	*cmd_line;
153*7c478bd9Sstevel@tonic-gate 	char	*command;
154*7c478bd9Sstevel@tonic-gate 	char	*p;
155*7c478bd9Sstevel@tonic-gate 	size_t	length;
156*7c478bd9Sstevel@tonic-gate 	FILE	*fp;
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate 	extern int	yyparse();
159*7c478bd9Sstevel@tonic-gate 	extern FILE *yyin;
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate 	if (NULL == file) {
162*7c478bd9Sstevel@tonic-gate 		itm_input_file = gettext("*stdin*");
163*7c478bd9Sstevel@tonic-gate 	} else {
164*7c478bd9Sstevel@tonic-gate 		if (0 != access(file, R_OK)) {
165*7c478bd9Sstevel@tonic-gate 			int	e = errno;
166*7c478bd9Sstevel@tonic-gate 			itm_error(
167*7c478bd9Sstevel@tonic-gate 				gettext("%1$s: can not access %2$s: "),
168*7c478bd9Sstevel@tonic-gate 				cmd_opt.my_name, file);
169*7c478bd9Sstevel@tonic-gate 			errno = e;
170*7c478bd9Sstevel@tonic-gate 			PERROR(NULL);
171*7c478bd9Sstevel@tonic-gate 			exit(ITMC_STATUS_CMD2);
172*7c478bd9Sstevel@tonic-gate 		}
173*7c478bd9Sstevel@tonic-gate 		itm_input_file = file;
174*7c478bd9Sstevel@tonic-gate 	}
175*7c478bd9Sstevel@tonic-gate 
176*7c478bd9Sstevel@tonic-gate 	if ((NULL == cmd_opt.output_file) &&
177*7c478bd9Sstevel@tonic-gate 	    (0 == cmd_opt.no_output)) {
178*7c478bd9Sstevel@tonic-gate 		p = strrchr(file, '.');
179*7c478bd9Sstevel@tonic-gate 		if (NULL == p) {
180*7c478bd9Sstevel@tonic-gate 			length = strlen(file);
181*7c478bd9Sstevel@tonic-gate 		} else {
182*7c478bd9Sstevel@tonic-gate 			length = p - file;
183*7c478bd9Sstevel@tonic-gate 		}
184*7c478bd9Sstevel@tonic-gate 		itm_output_file = malloc_vital(length + 5);
185*7c478bd9Sstevel@tonic-gate 		(void) memcpy(itm_output_file, file, length);
186*7c478bd9Sstevel@tonic-gate 		(void) memcpy(itm_output_file + length, ITMSUFFIX, 5);
187*7c478bd9Sstevel@tonic-gate 	} else {
188*7c478bd9Sstevel@tonic-gate 		itm_output_file = cmd_opt.output_file;
189*7c478bd9Sstevel@tonic-gate 	}
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate 	if (0 != cmd_opt.preprocess) {
192*7c478bd9Sstevel@tonic-gate 		if (NULL == file) {
193*7c478bd9Sstevel@tonic-gate 			fp = cpp_open();
194*7c478bd9Sstevel@tonic-gate 			cmd_line = cmd_opt.preprocess;
195*7c478bd9Sstevel@tonic-gate 		} else {
196*7c478bd9Sstevel@tonic-gate 			(void) cpp_opt_append(file, NULL);
197*7c478bd9Sstevel@tonic-gate 			fp = cpp_open();
198*7c478bd9Sstevel@tonic-gate 			cpp_opt_trunc(1);
199*7c478bd9Sstevel@tonic-gate 		}
200*7c478bd9Sstevel@tonic-gate 		if (NULL == fp) {
201*7c478bd9Sstevel@tonic-gate 			p = strchr(cmd_line, ' ');
202*7c478bd9Sstevel@tonic-gate 			if (NULL == p) {
203*7c478bd9Sstevel@tonic-gate 				length = strlen(cmd_line);
204*7c478bd9Sstevel@tonic-gate 			} else {
205*7c478bd9Sstevel@tonic-gate 				length = (p - cmd_line);
206*7c478bd9Sstevel@tonic-gate 			}
207*7c478bd9Sstevel@tonic-gate 			command = malloc_vital((sizeof (char)) * (length + 1));
208*7c478bd9Sstevel@tonic-gate 			(void) memcpy(command, cmd_line, length);
209*7c478bd9Sstevel@tonic-gate 			*(command + length) = '\0';
210*7c478bd9Sstevel@tonic-gate 			PERROR(command);
211*7c478bd9Sstevel@tonic-gate 			itm_error(
212*7c478bd9Sstevel@tonic-gate 				gettext("%1$s: can not start %2$s on %3$s\n"),
213*7c478bd9Sstevel@tonic-gate 				cmd_opt.my_name, command, itm_input_file);
214*7c478bd9Sstevel@tonic-gate 			exit(ITMC_STATUS_SYS);
215*7c478bd9Sstevel@tonic-gate 		} else {
216*7c478bd9Sstevel@tonic-gate 			yyin = fp;
217*7c478bd9Sstevel@tonic-gate 		}
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate 		(void) yyparse();
220*7c478bd9Sstevel@tonic-gate 		if (NULL == cmd_opt.preprocess_specified) {
221*7c478bd9Sstevel@tonic-gate 			cpp_close(fp);
222*7c478bd9Sstevel@tonic-gate 		}
223*7c478bd9Sstevel@tonic-gate 	} else {
224*7c478bd9Sstevel@tonic-gate 		if ((NULL == file) || (0 != strcmp("-", file))) {
225*7c478bd9Sstevel@tonic-gate 			yyin = stdin;
226*7c478bd9Sstevel@tonic-gate 		} else {
227*7c478bd9Sstevel@tonic-gate 			yyin = fopen(file, "r");
228*7c478bd9Sstevel@tonic-gate 			if (NULL == yyin) {
229*7c478bd9Sstevel@tonic-gate 				itm_error(
230*7c478bd9Sstevel@tonic-gate 					gettext("%1$s: can not open %2$s\n"),
231*7c478bd9Sstevel@tonic-gate 					cmd_opt.my_name, itm_input_file);
232*7c478bd9Sstevel@tonic-gate 				exit(ITMC_STATUS_CMD2);
233*7c478bd9Sstevel@tonic-gate 			}
234*7c478bd9Sstevel@tonic-gate 		}
235*7c478bd9Sstevel@tonic-gate 		(void) yyparse();
236*7c478bd9Sstevel@tonic-gate 		if (stdin != yyin) {
237*7c478bd9Sstevel@tonic-gate 			(void) fclose(yyin);
238*7c478bd9Sstevel@tonic-gate 		}
239*7c478bd9Sstevel@tonic-gate 	}
240*7c478bd9Sstevel@tonic-gate 
241*7c478bd9Sstevel@tonic-gate 	return (ITMC_STATUS_SUCCESS);
242*7c478bd9Sstevel@tonic-gate }
243*7c478bd9Sstevel@tonic-gate 
244*7c478bd9Sstevel@tonic-gate 
245*7c478bd9Sstevel@tonic-gate 
246*7c478bd9Sstevel@tonic-gate 
247*7c478bd9Sstevel@tonic-gate static void
248*7c478bd9Sstevel@tonic-gate wait_child(pid_t pid)
249*7c478bd9Sstevel@tonic-gate {
250*7c478bd9Sstevel@tonic-gate 	int	stat_loc;
251*7c478bd9Sstevel@tonic-gate 	char *msgstr;
252*7c478bd9Sstevel@tonic-gate 
253*7c478bd9Sstevel@tonic-gate 	(void) waitpid(pid, &stat_loc, 0);
254*7c478bd9Sstevel@tonic-gate 	if (WTERMSIG(stat_loc)) {
255*7c478bd9Sstevel@tonic-gate 		if (WCOREDUMP(stat_loc)) {
256*7c478bd9Sstevel@tonic-gate 			msgstr = gettext("signal received: %s, core dumped\n");
257*7c478bd9Sstevel@tonic-gate 		} else {
258*7c478bd9Sstevel@tonic-gate 			msgstr = gettext("signal received: %s\n");
259*7c478bd9Sstevel@tonic-gate 		}
260*7c478bd9Sstevel@tonic-gate 		itm_error(msgstr, strsignal(WTERMSIG(stat_loc)));
261*7c478bd9Sstevel@tonic-gate 	}
262*7c478bd9Sstevel@tonic-gate }
263*7c478bd9Sstevel@tonic-gate 
264*7c478bd9Sstevel@tonic-gate 
265*7c478bd9Sstevel@tonic-gate static int
266*7c478bd9Sstevel@tonic-gate fork_error(void)
267*7c478bd9Sstevel@tonic-gate {
268*7c478bd9Sstevel@tonic-gate 	PERROR(gettext("fork"));
269*7c478bd9Sstevel@tonic-gate 	exit(ITMC_STATUS_SYS);
270*7c478bd9Sstevel@tonic-gate 	return (0); /* never return */
271*7c478bd9Sstevel@tonic-gate }
272*7c478bd9Sstevel@tonic-gate 
273*7c478bd9Sstevel@tonic-gate 
274*7c478bd9Sstevel@tonic-gate 
275*7c478bd9Sstevel@tonic-gate static int
276*7c478bd9Sstevel@tonic-gate parse_opts(int argc, char **argv)
277*7c478bd9Sstevel@tonic-gate {
278*7c478bd9Sstevel@tonic-gate 	int		c;
279*7c478bd9Sstevel@tonic-gate 	int		i;
280*7c478bd9Sstevel@tonic-gate 	char		*p;
281*7c478bd9Sstevel@tonic-gate 	int		error_num = 0;
282*7c478bd9Sstevel@tonic-gate 
283*7c478bd9Sstevel@tonic-gate #ifdef YYDEBUG
284*7c478bd9Sstevel@tonic-gate 	extern int	yydebug;
285*7c478bd9Sstevel@tonic-gate #endif /* YYDEBUG */
286*7c478bd9Sstevel@tonic-gate 
287*7c478bd9Sstevel@tonic-gate 	extern char	*optarg;
288*7c478bd9Sstevel@tonic-gate 	extern int	optind;
289*7c478bd9Sstevel@tonic-gate 
290*7c478bd9Sstevel@tonic-gate 
291*7c478bd9Sstevel@tonic-gate 	cmd_opt.my_name = basename(*(argv + 0));
292*7c478bd9Sstevel@tonic-gate 	if ('\0' == *(cmd_opt.my_name)) {
293*7c478bd9Sstevel@tonic-gate 		cmd_opt.my_name = ME_DEFAULT;
294*7c478bd9Sstevel@tonic-gate 	}
295*7c478bd9Sstevel@tonic-gate 
296*7c478bd9Sstevel@tonic-gate 	cmd_opt.preprocess_default = CPP_PATH;
297*7c478bd9Sstevel@tonic-gate 	cmd_opt.preprocess = cmd_opt.preprocess_default;
298*7c478bd9Sstevel@tonic-gate 	cmd_opt.strip = 1; /* stripped by default */
299*7c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "d:i:p:W:D:I:U:fnsM:lo:qX:h")) != EOF) {
300*7c478bd9Sstevel@tonic-gate 		switch (c) {
301*7c478bd9Sstevel@tonic-gate 		case 'd':
302*7c478bd9Sstevel@tonic-gate 			cmd_opt.disassemble = optarg;
303*7c478bd9Sstevel@tonic-gate 			break;
304*7c478bd9Sstevel@tonic-gate 		case 'i':
305*7c478bd9Sstevel@tonic-gate 			cmd_opt.interpreter = optarg;
306*7c478bd9Sstevel@tonic-gate 			break;
307*7c478bd9Sstevel@tonic-gate 		case 'p':
308*7c478bd9Sstevel@tonic-gate 			if (NULL != cmd_opt.preprocess_specified) {
309*7c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
310*7c478bd9Sstevel@tonic-gate 				gettext("multiple -p options are specified\n"));
311*7c478bd9Sstevel@tonic-gate 				error_num += 1;
312*7c478bd9Sstevel@tonic-gate 			}
313*7c478bd9Sstevel@tonic-gate 			cmd_opt.preprocess_specified =
314*7c478bd9Sstevel@tonic-gate 				prog_path_expand(optarg);
315*7c478bd9Sstevel@tonic-gate 			cmd_opt.preprocess = cmd_opt.preprocess_specified;
316*7c478bd9Sstevel@tonic-gate 			if (NULL == cmd_opt.preprocess) {
317*7c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
318*7c478bd9Sstevel@tonic-gate 				gettext("cannot find preprocessor \"%s\"\n"),
319*7c478bd9Sstevel@tonic-gate 					optarg);
320*7c478bd9Sstevel@tonic-gate 				error_num += 1;
321*7c478bd9Sstevel@tonic-gate 			}
322*7c478bd9Sstevel@tonic-gate 			(void) cpp_opt_append(NULL, NULL);
323*7c478bd9Sstevel@tonic-gate 			p = basename(optarg);
324*7c478bd9Sstevel@tonic-gate 			if (NULL == p) {
325*7c478bd9Sstevel@tonic-gate 				*(cmd_opt.cpp_opt + 0) = strdup_vital(optarg);
326*7c478bd9Sstevel@tonic-gate 			} else {
327*7c478bd9Sstevel@tonic-gate 				*(cmd_opt.cpp_opt + 0) = strdup_vital(p);
328*7c478bd9Sstevel@tonic-gate 			}
329*7c478bd9Sstevel@tonic-gate 			break;
330*7c478bd9Sstevel@tonic-gate 		case 'W':
331*7c478bd9Sstevel@tonic-gate 			if (cpp_opt_append(optarg, NULL)) {
332*7c478bd9Sstevel@tonic-gate 				error_num += 1;
333*7c478bd9Sstevel@tonic-gate 			}
334*7c478bd9Sstevel@tonic-gate 			break;
335*7c478bd9Sstevel@tonic-gate 		case 'I':
336*7c478bd9Sstevel@tonic-gate 			if (cpp_opt_append("-I", optarg)) {
337*7c478bd9Sstevel@tonic-gate 				error_num += 1;
338*7c478bd9Sstevel@tonic-gate 			}
339*7c478bd9Sstevel@tonic-gate 			break;
340*7c478bd9Sstevel@tonic-gate 		case 'D':
341*7c478bd9Sstevel@tonic-gate 			if (cpp_opt_append("-D", optarg)) {
342*7c478bd9Sstevel@tonic-gate 				error_num += 1;
343*7c478bd9Sstevel@tonic-gate 			}
344*7c478bd9Sstevel@tonic-gate 			break;
345*7c478bd9Sstevel@tonic-gate 		case 'U':
346*7c478bd9Sstevel@tonic-gate 			if (cpp_opt_append("-U", optarg)) {
347*7c478bd9Sstevel@tonic-gate 				error_num += 1;
348*7c478bd9Sstevel@tonic-gate 			}
349*7c478bd9Sstevel@tonic-gate 			break;
350*7c478bd9Sstevel@tonic-gate 		case 'f':
351*7c478bd9Sstevel@tonic-gate 			cmd_opt.force_overwrite = 1;
352*7c478bd9Sstevel@tonic-gate 			break;
353*7c478bd9Sstevel@tonic-gate 		case 'n':
354*7c478bd9Sstevel@tonic-gate 			cmd_opt.no_output = 1;
355*7c478bd9Sstevel@tonic-gate 			break;
356*7c478bd9Sstevel@tonic-gate 		case 'M':
357*7c478bd9Sstevel@tonic-gate 			map_name_type_append(optarg);
358*7c478bd9Sstevel@tonic-gate 			break;
359*7c478bd9Sstevel@tonic-gate 		case 'l':
360*7c478bd9Sstevel@tonic-gate 			cmd_opt.large_table = 1;
361*7c478bd9Sstevel@tonic-gate 			break;
362*7c478bd9Sstevel@tonic-gate 		case 'o':
363*7c478bd9Sstevel@tonic-gate 			cmd_opt.output_file = optarg;
364*7c478bd9Sstevel@tonic-gate 			break;
365*7c478bd9Sstevel@tonic-gate 		case 's':
366*7c478bd9Sstevel@tonic-gate 			cmd_opt.strip = 0;
367*7c478bd9Sstevel@tonic-gate 			break;
368*7c478bd9Sstevel@tonic-gate 		case 'q':
369*7c478bd9Sstevel@tonic-gate 			cmd_opt.quiet = 1;
370*7c478bd9Sstevel@tonic-gate 			break;
371*7c478bd9Sstevel@tonic-gate #if defined(ENABLE_TRACE)
372*7c478bd9Sstevel@tonic-gate 		case 'X':
373*7c478bd9Sstevel@tonic-gate 			cmd_opt.trace = malloc_vital((sizeof (char)) * 128);
374*7c478bd9Sstevel@tonic-gate 			(void) memset(cmd_opt.trace, 0, (sizeof (char)) * 128);
375*7c478bd9Sstevel@tonic-gate 			for (p = optarg; *p; p++) {
376*7c478bd9Sstevel@tonic-gate 				*(cmd_opt.trace + ((*p) & 0x007f)) = 1;
377*7c478bd9Sstevel@tonic-gate 			}
378*7c478bd9Sstevel@tonic-gate #ifdef YYDEBUG
379*7c478bd9Sstevel@tonic-gate 			if (TRACE('Y'))	yydebug = 1;
380*7c478bd9Sstevel@tonic-gate #endif /* YYDEBUG */
381*7c478bd9Sstevel@tonic-gate 			break;
382*7c478bd9Sstevel@tonic-gate #endif /* ENABLE_TRACE */
383*7c478bd9Sstevel@tonic-gate 		case 'h':
384*7c478bd9Sstevel@tonic-gate 			usage(ITMC_STATUS_SUCCESS);
385*7c478bd9Sstevel@tonic-gate 			break;
386*7c478bd9Sstevel@tonic-gate 		default:
387*7c478bd9Sstevel@tonic-gate 			usage(ITMC_STATUS_CMD);
388*7c478bd9Sstevel@tonic-gate 		}
389*7c478bd9Sstevel@tonic-gate 	}
390*7c478bd9Sstevel@tonic-gate 
391*7c478bd9Sstevel@tonic-gate 	if (optind < argc) {
392*7c478bd9Sstevel@tonic-gate 		cmd_opt.input_file_num = (argc - optind);
393*7c478bd9Sstevel@tonic-gate 		cmd_opt.input_file =
394*7c478bd9Sstevel@tonic-gate 			malloc_vital((sizeof (char *)) *
395*7c478bd9Sstevel@tonic-gate 					(argc - optind + 1));
396*7c478bd9Sstevel@tonic-gate 		*(cmd_opt.input_file + (argc - optind)) = NULL;
397*7c478bd9Sstevel@tonic-gate 	}
398*7c478bd9Sstevel@tonic-gate 
399*7c478bd9Sstevel@tonic-gate 	for (i = 0; optind < argc; optind++, i++) {
400*7c478bd9Sstevel@tonic-gate 		*(cmd_opt.input_file + i) = argv[optind];
401*7c478bd9Sstevel@tonic-gate 	}
402*7c478bd9Sstevel@tonic-gate 
403*7c478bd9Sstevel@tonic-gate 	/* check conflict */
404*7c478bd9Sstevel@tonic-gate 
405*7c478bd9Sstevel@tonic-gate 	if ((1 < cmd_opt.input_file_num) && (NULL != cmd_opt.output_file)) {
406*7c478bd9Sstevel@tonic-gate 		itm_error(gettext("use -o with single input file\n"));
407*7c478bd9Sstevel@tonic-gate 		error_num++;
408*7c478bd9Sstevel@tonic-gate 	}
409*7c478bd9Sstevel@tonic-gate 
410*7c478bd9Sstevel@tonic-gate 	if ((cmd_opt.input_file_num <= 0) &&
411*7c478bd9Sstevel@tonic-gate 	    (NULL == cmd_opt.output_file) &&
412*7c478bd9Sstevel@tonic-gate 	    (NULL == cmd_opt.disassemble) &&
413*7c478bd9Sstevel@tonic-gate 	    (0 == cmd_opt.no_output)) {
414*7c478bd9Sstevel@tonic-gate 		itm_error(gettext(
415*7c478bd9Sstevel@tonic-gate 			"output file is unnamed. "
416*7c478bd9Sstevel@tonic-gate 			"use -o to specify output file\n"));
417*7c478bd9Sstevel@tonic-gate 		error_num++;
418*7c478bd9Sstevel@tonic-gate 	}
419*7c478bd9Sstevel@tonic-gate 
420*7c478bd9Sstevel@tonic-gate 	if (cmd_opt.disassemble &&
421*7c478bd9Sstevel@tonic-gate 	    (cmd_opt.interpreter ||
422*7c478bd9Sstevel@tonic-gate 	    cmd_opt.cpp_opt ||
423*7c478bd9Sstevel@tonic-gate 	    cmd_opt.preprocess_specified ||
424*7c478bd9Sstevel@tonic-gate 	    cmd_opt.input_file ||
425*7c478bd9Sstevel@tonic-gate 	    cmd_opt.force_overwrite ||
426*7c478bd9Sstevel@tonic-gate 	    cmd_opt.no_output ||
427*7c478bd9Sstevel@tonic-gate 	    cmd_opt.map_name_type ||
428*7c478bd9Sstevel@tonic-gate 	    cmd_opt.large_table ||
429*7c478bd9Sstevel@tonic-gate 	    cmd_opt.output_file)) {
430*7c478bd9Sstevel@tonic-gate 		itm_error(
431*7c478bd9Sstevel@tonic-gate 			gettext("-d may not specified with other options\n"));
432*7c478bd9Sstevel@tonic-gate 		error_num++;
433*7c478bd9Sstevel@tonic-gate 	}
434*7c478bd9Sstevel@tonic-gate 
435*7c478bd9Sstevel@tonic-gate 	if (error_num) {
436*7c478bd9Sstevel@tonic-gate 		usage(ITMC_STATUS_CMD);
437*7c478bd9Sstevel@tonic-gate 	}
438*7c478bd9Sstevel@tonic-gate 
439*7c478bd9Sstevel@tonic-gate 	/*
440*7c478bd9Sstevel@tonic-gate 	 * do not move upward
441*7c478bd9Sstevel@tonic-gate 	 * may conflict with -d option
442*7c478bd9Sstevel@tonic-gate 	 */
443*7c478bd9Sstevel@tonic-gate 	if ((NULL == cmd_opt.preprocess_specified) &&
444*7c478bd9Sstevel@tonic-gate 	    (NULL != cmd_opt.preprocess_default)) {
445*7c478bd9Sstevel@tonic-gate 		(void) cpp_opt_append(NULL, NULL);
446*7c478bd9Sstevel@tonic-gate 		p = basename(cmd_opt.preprocess_default);
447*7c478bd9Sstevel@tonic-gate 		if (NULL == p) {
448*7c478bd9Sstevel@tonic-gate 			*(cmd_opt.cpp_opt + 0) =
449*7c478bd9Sstevel@tonic-gate 				strdup_vital(cmd_opt.preprocess_default);
450*7c478bd9Sstevel@tonic-gate 		} else {
451*7c478bd9Sstevel@tonic-gate 			*(cmd_opt.cpp_opt + 0) = strdup_vital(p);
452*7c478bd9Sstevel@tonic-gate 		}
453*7c478bd9Sstevel@tonic-gate 	}
454*7c478bd9Sstevel@tonic-gate 	return (0);
455*7c478bd9Sstevel@tonic-gate }
456*7c478bd9Sstevel@tonic-gate 
457*7c478bd9Sstevel@tonic-gate 
458*7c478bd9Sstevel@tonic-gate static FILE *
459*7c478bd9Sstevel@tonic-gate cpp_open(void)
460*7c478bd9Sstevel@tonic-gate {
461*7c478bd9Sstevel@tonic-gate 	pid_t	pid;
462*7c478bd9Sstevel@tonic-gate 	int	filedes[2];
463*7c478bd9Sstevel@tonic-gate 	int	i;
464*7c478bd9Sstevel@tonic-gate 
465*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < cmd_opt.cpp_opt_num; i++) {
466*7c478bd9Sstevel@tonic-gate 		TRACE_MESSAGE('C', ("%s\n", *(cmd_opt.cpp_opt + i)));
467*7c478bd9Sstevel@tonic-gate 	}
468*7c478bd9Sstevel@tonic-gate 
469*7c478bd9Sstevel@tonic-gate 	if (pipe(filedes)) {
470*7c478bd9Sstevel@tonic-gate 		PERROR(gettext("pipe"));
471*7c478bd9Sstevel@tonic-gate 		itm_error(gettext("failed to open pipe\n"));
472*7c478bd9Sstevel@tonic-gate 		exit(ITMC_STATUS_SYS);
473*7c478bd9Sstevel@tonic-gate 	}
474*7c478bd9Sstevel@tonic-gate 	pid = fork();
475*7c478bd9Sstevel@tonic-gate 	if (pid == 0) {	/* child */
476*7c478bd9Sstevel@tonic-gate 		(void) close(filedes[0]);
477*7c478bd9Sstevel@tonic-gate 		(void) close(1);
478*7c478bd9Sstevel@tonic-gate 		(void) dup2(filedes[1], 1);
479*7c478bd9Sstevel@tonic-gate 		(void) execv(cmd_opt.preprocess, cmd_opt.cpp_opt);
480*7c478bd9Sstevel@tonic-gate 		exit(0);
481*7c478bd9Sstevel@tonic-gate 	} else if (pid == (pid_t)(-1)) {	/* error */
482*7c478bd9Sstevel@tonic-gate 		return	(NULL);
483*7c478bd9Sstevel@tonic-gate 	} else {
484*7c478bd9Sstevel@tonic-gate 		(void) close(filedes[1]);
485*7c478bd9Sstevel@tonic-gate 		return (fdopen(filedes[0], "r"));
486*7c478bd9Sstevel@tonic-gate 	}
487*7c478bd9Sstevel@tonic-gate 	return	(NULL); /* NEVER */
488*7c478bd9Sstevel@tonic-gate }
489*7c478bd9Sstevel@tonic-gate 
490*7c478bd9Sstevel@tonic-gate 
491*7c478bd9Sstevel@tonic-gate static int
492*7c478bd9Sstevel@tonic-gate cpp_opt_append(char	*opt, char	*arg)
493*7c478bd9Sstevel@tonic-gate {
494*7c478bd9Sstevel@tonic-gate 	size_t	opt_len;
495*7c478bd9Sstevel@tonic-gate 	size_t	arg_len;
496*7c478bd9Sstevel@tonic-gate 	char	*new_opt;
497*7c478bd9Sstevel@tonic-gate 	char	**new_opt_list;
498*7c478bd9Sstevel@tonic-gate 
499*7c478bd9Sstevel@tonic-gate 	opt_len = ((NULL == opt) ? 0 : strlen(opt));
500*7c478bd9Sstevel@tonic-gate 	arg_len = ((NULL == arg) ? 0 : strlen(arg));
501*7c478bd9Sstevel@tonic-gate 	if (0 < (opt_len + arg_len)) {
502*7c478bd9Sstevel@tonic-gate 		new_opt = malloc_vital(opt_len + arg_len + 1);
503*7c478bd9Sstevel@tonic-gate 		if (NULL != opt) {
504*7c478bd9Sstevel@tonic-gate 			(void) memcpy(new_opt, opt, opt_len + 1);
505*7c478bd9Sstevel@tonic-gate 		}
506*7c478bd9Sstevel@tonic-gate 		if (NULL != arg) {
507*7c478bd9Sstevel@tonic-gate 			(void) memcpy(new_opt + opt_len, arg, arg_len + 1);
508*7c478bd9Sstevel@tonic-gate 		}
509*7c478bd9Sstevel@tonic-gate 	} else {
510*7c478bd9Sstevel@tonic-gate 		new_opt = NULL;
511*7c478bd9Sstevel@tonic-gate 	}
512*7c478bd9Sstevel@tonic-gate 
513*7c478bd9Sstevel@tonic-gate 	if (0 == cmd_opt.cpp_opt_reserved) {
514*7c478bd9Sstevel@tonic-gate 		cmd_opt.cpp_opt_reserved = 32;
515*7c478bd9Sstevel@tonic-gate 		cmd_opt.cpp_opt = malloc_vital((sizeof (char *)) * 32);
516*7c478bd9Sstevel@tonic-gate 		*(cmd_opt.cpp_opt + 0) = "cpp";
517*7c478bd9Sstevel@tonic-gate 		cmd_opt.cpp_opt_num = 1;
518*7c478bd9Sstevel@tonic-gate 	} else if ((cmd_opt.cpp_opt_reserved - 2) <= cmd_opt.cpp_opt_num) {
519*7c478bd9Sstevel@tonic-gate 		cmd_opt.cpp_opt_reserved += 32;
520*7c478bd9Sstevel@tonic-gate 		new_opt_list = malloc_vital((sizeof (char *)) *
521*7c478bd9Sstevel@tonic-gate 					    cmd_opt.cpp_opt_reserved);
522*7c478bd9Sstevel@tonic-gate 		(void) memcpy(new_opt_list, cmd_opt.cpp_opt,
523*7c478bd9Sstevel@tonic-gate 			(sizeof (char *)) * cmd_opt.cpp_opt_num);
524*7c478bd9Sstevel@tonic-gate 		(void) memset(new_opt_list + cmd_opt.cpp_opt_num, 0, 32);
525*7c478bd9Sstevel@tonic-gate 		free(cmd_opt.cpp_opt);
526*7c478bd9Sstevel@tonic-gate 		cmd_opt.cpp_opt = new_opt_list;
527*7c478bd9Sstevel@tonic-gate 	}
528*7c478bd9Sstevel@tonic-gate 	if (NULL != new_opt) {
529*7c478bd9Sstevel@tonic-gate 		*(cmd_opt.cpp_opt + cmd_opt.cpp_opt_num) = new_opt;
530*7c478bd9Sstevel@tonic-gate 		cmd_opt.cpp_opt_num += 1;
531*7c478bd9Sstevel@tonic-gate 	}
532*7c478bd9Sstevel@tonic-gate 	return (0);
533*7c478bd9Sstevel@tonic-gate }
534*7c478bd9Sstevel@tonic-gate 
535*7c478bd9Sstevel@tonic-gate 
536*7c478bd9Sstevel@tonic-gate static void
537*7c478bd9Sstevel@tonic-gate cpp_opt_trunc(int num)
538*7c478bd9Sstevel@tonic-gate {
539*7c478bd9Sstevel@tonic-gate 	if (cmd_opt.cpp_opt_num < num) {
540*7c478bd9Sstevel@tonic-gate 		num = cmd_opt.cpp_opt_num;
541*7c478bd9Sstevel@tonic-gate 	}
542*7c478bd9Sstevel@tonic-gate 	for (; 0 < num; --num) {
543*7c478bd9Sstevel@tonic-gate 		free(cmd_opt.cpp_opt + cmd_opt.cpp_opt_num);
544*7c478bd9Sstevel@tonic-gate 		--(cmd_opt.cpp_opt_num);
545*7c478bd9Sstevel@tonic-gate 	}
546*7c478bd9Sstevel@tonic-gate }
547*7c478bd9Sstevel@tonic-gate 
548*7c478bd9Sstevel@tonic-gate 
549*7c478bd9Sstevel@tonic-gate static void
550*7c478bd9Sstevel@tonic-gate cpp_close(FILE *fp)
551*7c478bd9Sstevel@tonic-gate {
552*7c478bd9Sstevel@tonic-gate 	(void) fclose(fp);
553*7c478bd9Sstevel@tonic-gate 	(void) wait_child(0);
554*7c478bd9Sstevel@tonic-gate }
555*7c478bd9Sstevel@tonic-gate 
556*7c478bd9Sstevel@tonic-gate 
557*7c478bd9Sstevel@tonic-gate 
558*7c478bd9Sstevel@tonic-gate 
559*7c478bd9Sstevel@tonic-gate static char *
560*7c478bd9Sstevel@tonic-gate prog_path_expand(const char *base_name)
561*7c478bd9Sstevel@tonic-gate {
562*7c478bd9Sstevel@tonic-gate 	size_t	base_len;
563*7c478bd9Sstevel@tonic-gate 	size_t	dir_len;
564*7c478bd9Sstevel@tonic-gate 	char	path[MAXPATHLEN];
565*7c478bd9Sstevel@tonic-gate 	char	*p;
566*7c478bd9Sstevel@tonic-gate 	char	*pe;
567*7c478bd9Sstevel@tonic-gate 
568*7c478bd9Sstevel@tonic-gate 	base_len = strlen(base_name);
569*7c478bd9Sstevel@tonic-gate 	path[0] = '\0';
570*7c478bd9Sstevel@tonic-gate 
571*7c478bd9Sstevel@tonic-gate 	if (NULL != strchr(base_name, '/')) {
572*7c478bd9Sstevel@tonic-gate 		if (0 == access(base_name, X_OK)) {
573*7c478bd9Sstevel@tonic-gate 			return (strdup_vital(base_name));
574*7c478bd9Sstevel@tonic-gate 		} else {
575*7c478bd9Sstevel@tonic-gate 			return (NULL);
576*7c478bd9Sstevel@tonic-gate 		}
577*7c478bd9Sstevel@tonic-gate 	}
578*7c478bd9Sstevel@tonic-gate 
579*7c478bd9Sstevel@tonic-gate 	for (p = getenv("PATH"); p; ) {
580*7c478bd9Sstevel@tonic-gate 		pe = strchr(p, ':');
581*7c478bd9Sstevel@tonic-gate 		dir_len = ((NULL == pe) ? strlen(p) : (pe - p));
582*7c478bd9Sstevel@tonic-gate 		(void) memcpy(path, p, dir_len);
583*7c478bd9Sstevel@tonic-gate 		if ((0 != dir_len) &&
584*7c478bd9Sstevel@tonic-gate 		    ('/' != path[dir_len - 1])) {
585*7c478bd9Sstevel@tonic-gate 			path[dir_len] = '/';
586*7c478bd9Sstevel@tonic-gate 			dir_len += 1;
587*7c478bd9Sstevel@tonic-gate 		}
588*7c478bd9Sstevel@tonic-gate 		if ((dir_len + base_len) < MAXPATHLEN) {
589*7c478bd9Sstevel@tonic-gate 			(void) memcpy(path + dir_len, base_name, base_len + 1);
590*7c478bd9Sstevel@tonic-gate 			if (0 == access(path, X_OK)) {
591*7c478bd9Sstevel@tonic-gate 				return (strdup_vital(path));
592*7c478bd9Sstevel@tonic-gate 			}
593*7c478bd9Sstevel@tonic-gate 		}
594*7c478bd9Sstevel@tonic-gate 		p = ((NULL == pe) ? NULL : (pe + 1));
595*7c478bd9Sstevel@tonic-gate 	}
596*7c478bd9Sstevel@tonic-gate 	return	(NULL);
597*7c478bd9Sstevel@tonic-gate }
598*7c478bd9Sstevel@tonic-gate 
599*7c478bd9Sstevel@tonic-gate 
600*7c478bd9Sstevel@tonic-gate static void
601*7c478bd9Sstevel@tonic-gate usage(int status)
602*7c478bd9Sstevel@tonic-gate {
603*7c478bd9Sstevel@tonic-gate 
604*7c478bd9Sstevel@tonic-gate 	if (ITMC_STATUS_SUCCESS == status) {
605*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stdout,
606*7c478bd9Sstevel@tonic-gate 		gettext("Usage: %1$s [-n] [-f] [-q]\n"
607*7c478bd9Sstevel@tonic-gate 		"	     [-p preprocessor] [-W argument]\n"
608*7c478bd9Sstevel@tonic-gate 		"	     [-Dname] [-Dname=def] [-Idirectory] [-Uname]\n"
609*7c478bd9Sstevel@tonic-gate 		"	     [file ...]\n	%2$s -h\n"),
610*7c478bd9Sstevel@tonic-gate 		cmd_opt.my_name, cmd_opt.my_name);
611*7c478bd9Sstevel@tonic-gate 	} else {
612*7c478bd9Sstevel@tonic-gate 		(void) itm_error(
613*7c478bd9Sstevel@tonic-gate 		gettext("Usage: %1$s [-n] [-f] [-q]\n"
614*7c478bd9Sstevel@tonic-gate 		"	     [-p preprocessor] [-W argument]\n"
615*7c478bd9Sstevel@tonic-gate 		"	     [-Dname] [-Dname=def] [-Idirectory] [-Uname]\n"
616*7c478bd9Sstevel@tonic-gate 		"	     [file ...]\n	%2$s -h\n"),
617*7c478bd9Sstevel@tonic-gate 		cmd_opt.my_name, cmd_opt.my_name);
618*7c478bd9Sstevel@tonic-gate 	}
619*7c478bd9Sstevel@tonic-gate 	exit(status);
620*7c478bd9Sstevel@tonic-gate }
621*7c478bd9Sstevel@tonic-gate 
622*7c478bd9Sstevel@tonic-gate 
623*7c478bd9Sstevel@tonic-gate static char *
624*7c478bd9Sstevel@tonic-gate map_type_name_str(itmc_map_type_t type)
625*7c478bd9Sstevel@tonic-gate {
626*7c478bd9Sstevel@tonic-gate 	int	i;
627*7c478bd9Sstevel@tonic-gate 	for (i = 0; NULL != map_type_name[i].name; i++) {
628*7c478bd9Sstevel@tonic-gate 		if (type == map_type_name[i].type) {
629*7c478bd9Sstevel@tonic-gate 			return (map_type_name[i].name);
630*7c478bd9Sstevel@tonic-gate 		}
631*7c478bd9Sstevel@tonic-gate 	}
632*7c478bd9Sstevel@tonic-gate 	return ("");
633*7c478bd9Sstevel@tonic-gate }
634*7c478bd9Sstevel@tonic-gate 
635*7c478bd9Sstevel@tonic-gate static void
636*7c478bd9Sstevel@tonic-gate map_name_type_append(char *optarg)
637*7c478bd9Sstevel@tonic-gate {
638*7c478bd9Sstevel@tonic-gate 	char			*oa;
639*7c478bd9Sstevel@tonic-gate 	char			*oa_save;
640*7c478bd9Sstevel@tonic-gate 	char			*name;
641*7c478bd9Sstevel@tonic-gate 	char			*p;
642*7c478bd9Sstevel@tonic-gate 	char			*phf;
643*7c478bd9Sstevel@tonic-gate 	int			hash_factor = 0;
644*7c478bd9Sstevel@tonic-gate 	itmc_map_type_t		type;
645*7c478bd9Sstevel@tonic-gate 	itmc_map_name_type_t	*m;
646*7c478bd9Sstevel@tonic-gate 	int			i;
647*7c478bd9Sstevel@tonic-gate 
648*7c478bd9Sstevel@tonic-gate 	oa = oa_save = strdup_vital(optarg);
649*7c478bd9Sstevel@tonic-gate 
650*7c478bd9Sstevel@tonic-gate 	while ((NULL != oa) && ('\0' != *oa)) {
651*7c478bd9Sstevel@tonic-gate 		name = oa;
652*7c478bd9Sstevel@tonic-gate 		oa = strchr(oa, ',');
653*7c478bd9Sstevel@tonic-gate 		if (NULL != oa) {
654*7c478bd9Sstevel@tonic-gate 			*(oa++) = '\0';
655*7c478bd9Sstevel@tonic-gate 		}
656*7c478bd9Sstevel@tonic-gate 		p = strchr(name, '=');
657*7c478bd9Sstevel@tonic-gate 		if (NULL == p) {
658*7c478bd9Sstevel@tonic-gate 			type = ITMC_MAP_AUTOMATIC;
659*7c478bd9Sstevel@tonic-gate 		} else {
660*7c478bd9Sstevel@tonic-gate 			*(p++) = '\0';
661*7c478bd9Sstevel@tonic-gate 			if ('\0' == *p) {
662*7c478bd9Sstevel@tonic-gate 				type = ITMC_MAP_AUTOMATIC;
663*7c478bd9Sstevel@tonic-gate 			} else {
664*7c478bd9Sstevel@tonic-gate 				phf = strchr(p, ':');
665*7c478bd9Sstevel@tonic-gate 				if (NULL != phf) {
666*7c478bd9Sstevel@tonic-gate 					*(phf++) = '\0';
667*7c478bd9Sstevel@tonic-gate 					hash_factor = atoi(phf);
668*7c478bd9Sstevel@tonic-gate 					if (hash_factor < 0) {
669*7c478bd9Sstevel@tonic-gate 						itm_error(
670*7c478bd9Sstevel@tonic-gate 						gettext(
671*7c478bd9Sstevel@tonic-gate 						"invalid hash factor is "
672*7c478bd9Sstevel@tonic-gate 						"specified: %s\n"),
673*7c478bd9Sstevel@tonic-gate 							phf);
674*7c478bd9Sstevel@tonic-gate 						hash_factor = 0;
675*7c478bd9Sstevel@tonic-gate 						error_deferred += 1;
676*7c478bd9Sstevel@tonic-gate 					}
677*7c478bd9Sstevel@tonic-gate 				}
678*7c478bd9Sstevel@tonic-gate 				for (i = 0;
679*7c478bd9Sstevel@tonic-gate 				    NULL != map_type_name[i].name; i++) {
680*7c478bd9Sstevel@tonic-gate 					if (0 ==
681*7c478bd9Sstevel@tonic-gate 					    strcmp(p, map_type_name[i].name)) {
682*7c478bd9Sstevel@tonic-gate 						type = map_type_name[i].type;
683*7c478bd9Sstevel@tonic-gate 						break;
684*7c478bd9Sstevel@tonic-gate 					}
685*7c478bd9Sstevel@tonic-gate 				}
686*7c478bd9Sstevel@tonic-gate 				if (NULL == map_type_name[i].name) {
687*7c478bd9Sstevel@tonic-gate 					itm_error(
688*7c478bd9Sstevel@tonic-gate 					gettext(
689*7c478bd9Sstevel@tonic-gate 					"unknown map type is specified: %s\n"),
690*7c478bd9Sstevel@tonic-gate 					p);
691*7c478bd9Sstevel@tonic-gate 					error_deferred += 1;
692*7c478bd9Sstevel@tonic-gate 					continue;
693*7c478bd9Sstevel@tonic-gate 				}
694*7c478bd9Sstevel@tonic-gate 			}
695*7c478bd9Sstevel@tonic-gate 		}
696*7c478bd9Sstevel@tonic-gate 		if (0 == strcmp(name, "default")) {
697*7c478bd9Sstevel@tonic-gate 			*name = '\0';
698*7c478bd9Sstevel@tonic-gate 		}
699*7c478bd9Sstevel@tonic-gate 		m = cmd_opt.map_name_type;
700*7c478bd9Sstevel@tonic-gate 		if (NULL == m) {
701*7c478bd9Sstevel@tonic-gate 			m = malloc_vital(sizeof (itmc_map_name_type_t));
702*7c478bd9Sstevel@tonic-gate 			m->name = strdup_vital(name);
703*7c478bd9Sstevel@tonic-gate 			m->type = type;
704*7c478bd9Sstevel@tonic-gate 			m->hash_factor = hash_factor;
705*7c478bd9Sstevel@tonic-gate 			m->next = NULL;
706*7c478bd9Sstevel@tonic-gate 			cmd_opt.map_name_type = m;
707*7c478bd9Sstevel@tonic-gate 			continue;
708*7c478bd9Sstevel@tonic-gate 		}
709*7c478bd9Sstevel@tonic-gate 		for (; ; m = m->next) {
710*7c478bd9Sstevel@tonic-gate 			if (0 == strcmp(name, m->name)) {
711*7c478bd9Sstevel@tonic-gate 				if (type == m->type) {
712*7c478bd9Sstevel@tonic-gate 					m = NULL;
713*7c478bd9Sstevel@tonic-gate 					break;
714*7c478bd9Sstevel@tonic-gate 				}
715*7c478bd9Sstevel@tonic-gate 				if ('\0' == *name) {
716*7c478bd9Sstevel@tonic-gate 					itm_error(
717*7c478bd9Sstevel@tonic-gate 					gettext(
718*7c478bd9Sstevel@tonic-gate 					"multiple default types are specified:"
719*7c478bd9Sstevel@tonic-gate 					" \"%1$s\" and \"%2$s\"\n"),
720*7c478bd9Sstevel@tonic-gate 						map_type_name_str(type),
721*7c478bd9Sstevel@tonic-gate 						map_type_name_str(m->type));
722*7c478bd9Sstevel@tonic-gate 				} else {
723*7c478bd9Sstevel@tonic-gate 					itm_error(
724*7c478bd9Sstevel@tonic-gate 					gettext("map \"%1$s\" is specified as "
725*7c478bd9Sstevel@tonic-gate 					"two types \"%2$s\" and \"%3$s\"\n"),
726*7c478bd9Sstevel@tonic-gate 					name,
727*7c478bd9Sstevel@tonic-gate 					map_type_name_str(type),
728*7c478bd9Sstevel@tonic-gate 					map_type_name_str(m->type));
729*7c478bd9Sstevel@tonic-gate 				}
730*7c478bd9Sstevel@tonic-gate 				error_deferred += 1;
731*7c478bd9Sstevel@tonic-gate 				m = NULL;
732*7c478bd9Sstevel@tonic-gate 				break;
733*7c478bd9Sstevel@tonic-gate 			}
734*7c478bd9Sstevel@tonic-gate 			if (NULL == m->next) {
735*7c478bd9Sstevel@tonic-gate 				break;
736*7c478bd9Sstevel@tonic-gate 			}
737*7c478bd9Sstevel@tonic-gate 		}
738*7c478bd9Sstevel@tonic-gate 		if (NULL != m) {
739*7c478bd9Sstevel@tonic-gate 			m->next = malloc_vital(sizeof (itmc_map_name_type_t));
740*7c478bd9Sstevel@tonic-gate 			m = m->next;
741*7c478bd9Sstevel@tonic-gate 			m->name = strdup_vital(name);
742*7c478bd9Sstevel@tonic-gate 			m->type = type;
743*7c478bd9Sstevel@tonic-gate 			m->hash_factor = hash_factor;
744*7c478bd9Sstevel@tonic-gate 			m->next = NULL;
745*7c478bd9Sstevel@tonic-gate 
746*7c478bd9Sstevel@tonic-gate 		}
747*7c478bd9Sstevel@tonic-gate 	}
748*7c478bd9Sstevel@tonic-gate 	free(oa_save);
749*7c478bd9Sstevel@tonic-gate }
750*7c478bd9Sstevel@tonic-gate 
751*7c478bd9Sstevel@tonic-gate 
752*7c478bd9Sstevel@tonic-gate 
753*7c478bd9Sstevel@tonic-gate void *
754*7c478bd9Sstevel@tonic-gate malloc_vital(size_t size)
755*7c478bd9Sstevel@tonic-gate {
756*7c478bd9Sstevel@tonic-gate 	void	*p;
757*7c478bd9Sstevel@tonic-gate 
758*7c478bd9Sstevel@tonic-gate 	TRACE_MESSAGE('M', ("malloc_vital: %d\n", size));
759*7c478bd9Sstevel@tonic-gate 
760*7c478bd9Sstevel@tonic-gate 	size = ITMROUNDUP(size);
761*7c478bd9Sstevel@tonic-gate 
762*7c478bd9Sstevel@tonic-gate 	p = (void*) malloc(size);
763*7c478bd9Sstevel@tonic-gate 	if (NULL == p) {
764*7c478bd9Sstevel@tonic-gate 		PERROR(gettext("malloc"));
765*7c478bd9Sstevel@tonic-gate 		exit(ITMC_STATUS_SYS);
766*7c478bd9Sstevel@tonic-gate 	}
767*7c478bd9Sstevel@tonic-gate 
768*7c478bd9Sstevel@tonic-gate 	(void) memset(p, 0, size);
769*7c478bd9Sstevel@tonic-gate 
770*7c478bd9Sstevel@tonic-gate 	return	(p);
771*7c478bd9Sstevel@tonic-gate }
772*7c478bd9Sstevel@tonic-gate 
773*7c478bd9Sstevel@tonic-gate 
774*7c478bd9Sstevel@tonic-gate static char *
775*7c478bd9Sstevel@tonic-gate strdup_vital(const char		*str)
776*7c478bd9Sstevel@tonic-gate {
777*7c478bd9Sstevel@tonic-gate 	char	*p;
778*7c478bd9Sstevel@tonic-gate 	size_t	len;
779*7c478bd9Sstevel@tonic-gate 
780*7c478bd9Sstevel@tonic-gate 	if (NULL == str) {
781*7c478bd9Sstevel@tonic-gate 		return	(NULL);
782*7c478bd9Sstevel@tonic-gate 	}
783*7c478bd9Sstevel@tonic-gate 
784*7c478bd9Sstevel@tonic-gate 	len = strlen(str) + 1;
785*7c478bd9Sstevel@tonic-gate 	p = malloc_vital(len);
786*7c478bd9Sstevel@tonic-gate 	(void) memcpy(p, str, len);
787*7c478bd9Sstevel@tonic-gate 	return	(p);
788*7c478bd9Sstevel@tonic-gate }
789*7c478bd9Sstevel@tonic-gate 
790*7c478bd9Sstevel@tonic-gate 
791*7c478bd9Sstevel@tonic-gate 
792*7c478bd9Sstevel@tonic-gate 
793*7c478bd9Sstevel@tonic-gate 
794*7c478bd9Sstevel@tonic-gate itm_data_t *
795*7c478bd9Sstevel@tonic-gate str_to_data(int size, char *seq)
796*7c478bd9Sstevel@tonic-gate {
797*7c478bd9Sstevel@tonic-gate 	itm_data_t *data;
798*7c478bd9Sstevel@tonic-gate 
799*7c478bd9Sstevel@tonic-gate 	data = malloc_vital(sizeof (itm_data_t));
800*7c478bd9Sstevel@tonic-gate 
801*7c478bd9Sstevel@tonic-gate 	data->size = size;
802*7c478bd9Sstevel@tonic-gate 	if (size <= sizeof (data->place)) {
803*7c478bd9Sstevel@tonic-gate 		(void) memmove(&(data->place), seq, size);
804*7c478bd9Sstevel@tonic-gate 	} else {
805*7c478bd9Sstevel@tonic-gate 		data->place.itm_ptr = (itm_place2_t)malloc_vital(size);
806*7c478bd9Sstevel@tonic-gate 		(void) memmove((char *)(data->place.itm_ptr), seq, size);
807*7c478bd9Sstevel@tonic-gate 	}
808*7c478bd9Sstevel@tonic-gate 
809*7c478bd9Sstevel@tonic-gate 	return	(data);
810*7c478bd9Sstevel@tonic-gate }
811*7c478bd9Sstevel@tonic-gate 
812*7c478bd9Sstevel@tonic-gate 
813*7c478bd9Sstevel@tonic-gate char *
814*7c478bd9Sstevel@tonic-gate name_to_str(itm_data_t *name)
815*7c478bd9Sstevel@tonic-gate {
816*7c478bd9Sstevel@tonic-gate 	static char	*ptr = NULL;
817*7c478bd9Sstevel@tonic-gate 	static size_t	len = 0;
818*7c478bd9Sstevel@tonic-gate 	size_t		req_len;
819*7c478bd9Sstevel@tonic-gate 	char		*p;
820*7c478bd9Sstevel@tonic-gate 
821*7c478bd9Sstevel@tonic-gate 	if (NULL == name) {
822*7c478bd9Sstevel@tonic-gate 		p = gettext("(no name)");
823*7c478bd9Sstevel@tonic-gate 		req_len = strlen(p) + 1;
824*7c478bd9Sstevel@tonic-gate 	} else {
825*7c478bd9Sstevel@tonic-gate 		req_len = name->size + 1;
826*7c478bd9Sstevel@tonic-gate 	}
827*7c478bd9Sstevel@tonic-gate 
828*7c478bd9Sstevel@tonic-gate 	if (len <= req_len) {
829*7c478bd9Sstevel@tonic-gate 		len += 512;
830*7c478bd9Sstevel@tonic-gate 		free(ptr);
831*7c478bd9Sstevel@tonic-gate 		ptr = malloc_vital(len);
832*7c478bd9Sstevel@tonic-gate 	}
833*7c478bd9Sstevel@tonic-gate 
834*7c478bd9Sstevel@tonic-gate 	if (NULL == name) {
835*7c478bd9Sstevel@tonic-gate 		(void) memcpy(ptr, p, req_len);
836*7c478bd9Sstevel@tonic-gate 		*(ptr + req_len) = '\0';
837*7c478bd9Sstevel@tonic-gate 	} else if (name->size <= (sizeof (name->place))) {
838*7c478bd9Sstevel@tonic-gate 		(void) memcpy(ptr, (char *)(&(name->place)), name->size);
839*7c478bd9Sstevel@tonic-gate 		*(ptr + name->size) = '\0';
840*7c478bd9Sstevel@tonic-gate 	} else {
841*7c478bd9Sstevel@tonic-gate 		(void) memcpy(ptr, (char *)(name->place.itm_ptr), name->size);
842*7c478bd9Sstevel@tonic-gate 		*(ptr + name->size) = '\0';
843*7c478bd9Sstevel@tonic-gate 	}
844*7c478bd9Sstevel@tonic-gate 
845*7c478bd9Sstevel@tonic-gate 	return	(ptr);
846*7c478bd9Sstevel@tonic-gate }
847*7c478bd9Sstevel@tonic-gate 
848*7c478bd9Sstevel@tonic-gate #define	ARGUMENTSMAX (8)
849*7c478bd9Sstevel@tonic-gate char *
850*7c478bd9Sstevel@tonic-gate data_to_hexadecimal(itm_data_t		*data)
851*7c478bd9Sstevel@tonic-gate {
852*7c478bd9Sstevel@tonic-gate 	static int index = 0;
853*7c478bd9Sstevel@tonic-gate 	static char	*ptr[ARGUMENTSMAX] = { NULL, NULL, NULL, NULL,
854*7c478bd9Sstevel@tonic-gate 						NULL, NULL, NULL, NULL};
855*7c478bd9Sstevel@tonic-gate 	static long	len[ARGUMENTSMAX] = { 0, 0, 0, 0, 0, 0, 0, 0};
856*7c478bd9Sstevel@tonic-gate 	char		*hdp;
857*7c478bd9Sstevel@tonic-gate 	char		*p;
858*7c478bd9Sstevel@tonic-gate 	long		i;
859*7c478bd9Sstevel@tonic-gate 	int		val;
860*7c478bd9Sstevel@tonic-gate 	size_t		req_len;
861*7c478bd9Sstevel@tonic-gate 
862*7c478bd9Sstevel@tonic-gate 	if (ARGUMENTSMAX <= index) index = 0;
863*7c478bd9Sstevel@tonic-gate 	req_len = (2 * data->size) + 1;
864*7c478bd9Sstevel@tonic-gate 	if (len[index] <= req_len) {
865*7c478bd9Sstevel@tonic-gate 		len[index] += 512;
866*7c478bd9Sstevel@tonic-gate 		free(ptr[index]);
867*7c478bd9Sstevel@tonic-gate 		ptr[index] = malloc_vital(len[index]);
868*7c478bd9Sstevel@tonic-gate 	}
869*7c478bd9Sstevel@tonic-gate 	hdp = ptr[index];
870*7c478bd9Sstevel@tonic-gate 
871*7c478bd9Sstevel@tonic-gate 	if (data->size <= (sizeof (itm_place_t))) {
872*7c478bd9Sstevel@tonic-gate 		p = (char *)&(data->place);
873*7c478bd9Sstevel@tonic-gate 	} else {
874*7c478bd9Sstevel@tonic-gate 		p = (char *)(data->place.itm_ptr);
875*7c478bd9Sstevel@tonic-gate 	}
876*7c478bd9Sstevel@tonic-gate 
877*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < data->size; i++, p++) {
878*7c478bd9Sstevel@tonic-gate 		val = ((*p & 0x00f0) >> 4);
879*7c478bd9Sstevel@tonic-gate 		if ((0 <= val) && (val <= 9)) {
880*7c478bd9Sstevel@tonic-gate 			*hdp = '0' + val;
881*7c478bd9Sstevel@tonic-gate 		} else {
882*7c478bd9Sstevel@tonic-gate 			*hdp = 'a' + val - 10;
883*7c478bd9Sstevel@tonic-gate 		}
884*7c478bd9Sstevel@tonic-gate 		hdp++;
885*7c478bd9Sstevel@tonic-gate 
886*7c478bd9Sstevel@tonic-gate 		val = (*p & 0x000f);
887*7c478bd9Sstevel@tonic-gate 		if ((0 <= val) && (val <= 9)) {
888*7c478bd9Sstevel@tonic-gate 			*hdp = '0' + val;
889*7c478bd9Sstevel@tonic-gate 		} else {
890*7c478bd9Sstevel@tonic-gate 			*hdp = 'a' + val - 10;
891*7c478bd9Sstevel@tonic-gate 		}
892*7c478bd9Sstevel@tonic-gate 		hdp++;
893*7c478bd9Sstevel@tonic-gate 	}
894*7c478bd9Sstevel@tonic-gate 	*hdp = '\0';
895*7c478bd9Sstevel@tonic-gate 	return (ptr[index++]);
896*7c478bd9Sstevel@tonic-gate }
897*7c478bd9Sstevel@tonic-gate 
898*7c478bd9Sstevel@tonic-gate 
899*7c478bd9Sstevel@tonic-gate 
900*7c478bd9Sstevel@tonic-gate 
901*7c478bd9Sstevel@tonic-gate 
902*7c478bd9Sstevel@tonic-gate void
903*7c478bd9Sstevel@tonic-gate itm_error(char *format, ...)
904*7c478bd9Sstevel@tonic-gate {
905*7c478bd9Sstevel@tonic-gate 	va_list		ap;
906*7c478bd9Sstevel@tonic-gate 	va_start(ap, format);
907*7c478bd9Sstevel@tonic-gate 
908*7c478bd9Sstevel@tonic-gate 	if (0 == cmd_opt.quiet) {
909*7c478bd9Sstevel@tonic-gate 		(void) vfprintf(stderr, format, ap);
910*7c478bd9Sstevel@tonic-gate 	}
911*7c478bd9Sstevel@tonic-gate 	va_end(ap);
912*7c478bd9Sstevel@tonic-gate }
913*7c478bd9Sstevel@tonic-gate 
914*7c478bd9Sstevel@tonic-gate #if defined(ENABLE_TRACE)
915*7c478bd9Sstevel@tonic-gate static void
916*7c478bd9Sstevel@tonic-gate trace_option(void)
917*7c478bd9Sstevel@tonic-gate {
918*7c478bd9Sstevel@tonic-gate 	char **pp;
919*7c478bd9Sstevel@tonic-gate 	int	i;
920*7c478bd9Sstevel@tonic-gate 
921*7c478bd9Sstevel@tonic-gate 	if (!(TRACE('o')))
922*7c478bd9Sstevel@tonic-gate 		return;
923*7c478bd9Sstevel@tonic-gate 
924*7c478bd9Sstevel@tonic-gate 	itm_error("my_name	   = %s\n", cmd_opt.my_name);
925*7c478bd9Sstevel@tonic-gate 	if (NULL == cmd_opt.input_file) {
926*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stdout, "input_file   = (stdin)\n");
927*7c478bd9Sstevel@tonic-gate 	} else {
928*7c478bd9Sstevel@tonic-gate 		for (pp = cmd_opt.input_file; *pp; pp++) {
929*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stdout, "input_file   = %s\n", *pp);
930*7c478bd9Sstevel@tonic-gate 		}
931*7c478bd9Sstevel@tonic-gate 	}
932*7c478bd9Sstevel@tonic-gate 	itm_error("output_file  = %s\n",
933*7c478bd9Sstevel@tonic-gate 		cmd_opt.output_file ? cmd_opt.output_file : "(stdout)");
934*7c478bd9Sstevel@tonic-gate 	itm_error("interpreter  = %s\n",
935*7c478bd9Sstevel@tonic-gate 		cmd_opt.interpreter ? cmd_opt.interpreter : "(default)");
936*7c478bd9Sstevel@tonic-gate 	if (cmd_opt.cpp_opt) {
937*7c478bd9Sstevel@tonic-gate 		itm_error("cpp_opt	   = %s\n", *(cmd_opt.cpp_opt));
938*7c478bd9Sstevel@tonic-gate 		for (i = 1; i < cmd_opt.cpp_opt_num; i++) {
939*7c478bd9Sstevel@tonic-gate 			itm_error("\t%s\n", *(cmd_opt.cpp_opt + i));
940*7c478bd9Sstevel@tonic-gate 		}
941*7c478bd9Sstevel@tonic-gate 	} else {
942*7c478bd9Sstevel@tonic-gate 		itm_error("cpp_opt	   = %s\n", "(none)");
943*7c478bd9Sstevel@tonic-gate 	}
944*7c478bd9Sstevel@tonic-gate 	itm_error("preprocess_default = %s\n",
945*7c478bd9Sstevel@tonic-gate 		cmd_opt.preprocess_default ? cmd_opt.preprocess_default :
946*7c478bd9Sstevel@tonic-gate 		"(no)");
947*7c478bd9Sstevel@tonic-gate 	itm_error("preprocess_specified = %s\n",
948*7c478bd9Sstevel@tonic-gate 		cmd_opt.preprocess_specified ? cmd_opt.preprocess_specified :
949*7c478bd9Sstevel@tonic-gate 		"(no)");
950*7c478bd9Sstevel@tonic-gate 	itm_error("preprocess   = %s\n",
951*7c478bd9Sstevel@tonic-gate 		cmd_opt.preprocess ? cmd_opt.preprocess : "(no)");
952*7c478bd9Sstevel@tonic-gate 	itm_error("disassemble  = %s\n",
953*7c478bd9Sstevel@tonic-gate 		cmd_opt.disassemble ? "yes" : "no");
954*7c478bd9Sstevel@tonic-gate 	itm_error("map type	   =");
955*7c478bd9Sstevel@tonic-gate 	if (NULL == cmd_opt.map_name_type) {
956*7c478bd9Sstevel@tonic-gate 		itm_error("\n");
957*7c478bd9Sstevel@tonic-gate 	} else {
958*7c478bd9Sstevel@tonic-gate 		itmc_map_name_type_t *m;
959*7c478bd9Sstevel@tonic-gate 		itm_error(" ");
960*7c478bd9Sstevel@tonic-gate 		m = cmd_opt.map_name_type;
961*7c478bd9Sstevel@tonic-gate 		itm_error("%s=%s",
962*7c478bd9Sstevel@tonic-gate 			(((NULL == m->name) || ('\0' == *(m->name))) ?
963*7c478bd9Sstevel@tonic-gate 				"default" : m->name),
964*7c478bd9Sstevel@tonic-gate 			map_type_name_str(m->type));
965*7c478bd9Sstevel@tonic-gate 		if (0 != m->hash_factor) {
966*7c478bd9Sstevel@tonic-gate 			itm_error(":%ld\n", m->hash_factor);
967*7c478bd9Sstevel@tonic-gate 		} else {
968*7c478bd9Sstevel@tonic-gate 			(void) fputc('\n', stderr);
969*7c478bd9Sstevel@tonic-gate 		}
970*7c478bd9Sstevel@tonic-gate 		for (m = m->next; NULL != m; m = m->next) {
971*7c478bd9Sstevel@tonic-gate 			itm_error("		%s=%s",
972*7c478bd9Sstevel@tonic-gate 				(((NULL == m->name) || ('\0' == *(m->name))) ?
973*7c478bd9Sstevel@tonic-gate 					"default" : m->name),
974*7c478bd9Sstevel@tonic-gate 				map_type_name_str(m->type));
975*7c478bd9Sstevel@tonic-gate 			if (0 != m->hash_factor) {
976*7c478bd9Sstevel@tonic-gate 				itm_error(":%ld\n", m->hash_factor);
977*7c478bd9Sstevel@tonic-gate 			} else {
978*7c478bd9Sstevel@tonic-gate 				(void) fputc('\n', stderr);
979*7c478bd9Sstevel@tonic-gate 			}
980*7c478bd9Sstevel@tonic-gate 		}
981*7c478bd9Sstevel@tonic-gate 	}
982*7c478bd9Sstevel@tonic-gate 	itm_error("large table  = %s\n",
983*7c478bd9Sstevel@tonic-gate 		cmd_opt.large_table ? "true" : "false");
984*7c478bd9Sstevel@tonic-gate 	itm_error("overwrite	   = %s\n",
985*7c478bd9Sstevel@tonic-gate 		cmd_opt.force_overwrite ? "true" : "false");
986*7c478bd9Sstevel@tonic-gate 	itm_error("strip	      = %s\n",
987*7c478bd9Sstevel@tonic-gate 		cmd_opt.strip ? "true" : "false");
988*7c478bd9Sstevel@tonic-gate 	itm_error("no_output	   = %s\n",
989*7c478bd9Sstevel@tonic-gate 		cmd_opt.no_output ? "true" : "false");
990*7c478bd9Sstevel@tonic-gate 	itm_error("trace	      = ");
991*7c478bd9Sstevel@tonic-gate 	if (NULL == cmd_opt.trace) {
992*7c478bd9Sstevel@tonic-gate 		itm_error("(no)\n");
993*7c478bd9Sstevel@tonic-gate 	} else {
994*7c478bd9Sstevel@tonic-gate 		for (i = 0x21; i < 0x7f; i++) {
995*7c478bd9Sstevel@tonic-gate 			if (TRACE(i)) {
996*7c478bd9Sstevel@tonic-gate 				(void) fputc(i, stderr);
997*7c478bd9Sstevel@tonic-gate 			}
998*7c478bd9Sstevel@tonic-gate 		}
999*7c478bd9Sstevel@tonic-gate 		(void) fputc('\n', stderr);
1000*7c478bd9Sstevel@tonic-gate 	}
1001*7c478bd9Sstevel@tonic-gate }
1002*7c478bd9Sstevel@tonic-gate #endif /* ENABLE_TRACE */
1003*7c478bd9Sstevel@tonic-gate 
1004*7c478bd9Sstevel@tonic-gate #if defined(ENABLE_TRACE)
1005*7c478bd9Sstevel@tonic-gate extern void
1006*7c478bd9Sstevel@tonic-gate trace_message(char *format, ...)
1007*7c478bd9Sstevel@tonic-gate {
1008*7c478bd9Sstevel@tonic-gate 	va_list	ap;
1009*7c478bd9Sstevel@tonic-gate 	va_start(ap, format);
1010*7c478bd9Sstevel@tonic-gate 
1011*7c478bd9Sstevel@tonic-gate 	(void) vfprintf(stderr, format, ap);
1012*7c478bd9Sstevel@tonic-gate 
1013*7c478bd9Sstevel@tonic-gate 	va_end(ap);
1014*7c478bd9Sstevel@tonic-gate }
1015*7c478bd9Sstevel@tonic-gate #endif /* ENABLE_TRACE */
1016