1*7c478bd9Sstevel@tonic-gate %{
2*7c478bd9Sstevel@tonic-gate /*
3*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
4*7c478bd9Sstevel@tonic-gate  *
5*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
6*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
7*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
8*7c478bd9Sstevel@tonic-gate  * with the License.
9*7c478bd9Sstevel@tonic-gate  *
10*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
12*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
13*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
14*7c478bd9Sstevel@tonic-gate  *
15*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
16*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
18*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
19*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
20*7c478bd9Sstevel@tonic-gate  *
21*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
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 #include <assert.h>
28*7c478bd9Sstevel@tonic-gate #include <stdio.h>
29*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
30*7c478bd9Sstevel@tonic-gate #include <unistd.h>
31*7c478bd9Sstevel@tonic-gate #include <libintl.h>
32*7c478bd9Sstevel@tonic-gate #include <string.h>
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #include <regexpr.h>
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #include "iconv_tm.h"
37*7c478bd9Sstevel@tonic-gate #include "itmcomp.h"
38*7c478bd9Sstevel@tonic-gate #include "y.tab.h"
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate static itm_data_t	*hexadecimal_data(int, char *);
41*7c478bd9Sstevel@tonic-gate static itm_data_t	*name_data(int, char *);
42*7c478bd9Sstevel@tonic-gate static void		filename_lineno(void);
43*7c478bd9Sstevel@tonic-gate static int		at_name_to_token(char *);
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate %}
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate %start	norm comment
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate DECIMAL		([0-9]+)
51*7c478bd9Sstevel@tonic-gate OCTAL		(0[0-7][0-7]+)
52*7c478bd9Sstevel@tonic-gate HEXADECIMAL	(("0x"|"0X")([0-9A-Fa-f])+)
53*7c478bd9Sstevel@tonic-gate ITMNAME		(([^% \t\n\r])+"%"([^% \t\n\r])+)
54*7c478bd9Sstevel@tonic-gate ATNAME		"@"([0-9A-Za-z_]+)
55*7c478bd9Sstevel@tonic-gate NAME		([A-Za-z_][A-Za-z0-9_]*)
56*7c478bd9Sstevel@tonic-gate MAPTYPE_NAME	(automatic|dense|index|hash|binary)
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate %%
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate [ \t\n]+	;
61*7c478bd9Sstevel@tonic-gate "//".*"\n"	;
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate ^"#"[ \t]*{DECIMAL}[ \t]*"\"".*"\"".*"\n" {
64*7c478bd9Sstevel@tonic-gate 			filename_lineno();
65*7c478bd9Sstevel@tonic-gate 		}
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate ^"#".*"\n"	{
68*7c478bd9Sstevel@tonic-gate 			if (NULL == cmd_opt.preprocess) {
69*7c478bd9Sstevel@tonic-gate 				itm_error(
70*7c478bd9Sstevel@tonic-gate 				gettext("warning: "
71*7c478bd9Sstevel@tonic-gate 					"preprocess may be required\n"));
72*7c478bd9Sstevel@tonic-gate 			}
73*7c478bd9Sstevel@tonic-gate 		}
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate {DECIMAL}	{
76*7c478bd9Sstevel@tonic-gate 			yylval.num = strtoul(yytext, (char **)NULL, 10);
77*7c478bd9Sstevel@tonic-gate 			return (DECIMAL);
78*7c478bd9Sstevel@tonic-gate 		}
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate {OCTAL}		{	yylval.num = strtoul(yytext, (char **)NULL, 8);
81*7c478bd9Sstevel@tonic-gate 			return (DECIMAL);
82*7c478bd9Sstevel@tonic-gate 		}
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate {HEXADECIMAL}	{	yylval.data = hexadecimal_data(yyleng - 2, yytext + 2);
85*7c478bd9Sstevel@tonic-gate 			return (HEXADECIMAL);
86*7c478bd9Sstevel@tonic-gate 		}
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate {ITMNAME}	{	yylval.data = str_to_data(yyleng, yytext);
89*7c478bd9Sstevel@tonic-gate 			return (ITMNAME);
90*7c478bd9Sstevel@tonic-gate 		}
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate {ATNAME}	{	return at_name_to_token(yytext);
93*7c478bd9Sstevel@tonic-gate 		}
94*7c478bd9Sstevel@tonic-gate 
95*7c478bd9Sstevel@tonic-gate {MAPTYPE_NAME}	{	yylval.num = at_name_to_token(yytext);
96*7c478bd9Sstevel@tonic-gate 			yylval.data = name_data(yyleng, yytext);
97*7c478bd9Sstevel@tonic-gate 			return (MAPTYPE_NAME);
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate 		}
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate {NAME}		{	yylval.num = at_name_to_token(yytext);
102*7c478bd9Sstevel@tonic-gate 			if (0 != yylval.num) {
103*7c478bd9Sstevel@tonic-gate 				return (yylval.num);
104*7c478bd9Sstevel@tonic-gate 			} else {
105*7c478bd9Sstevel@tonic-gate 				yylval.data = name_data(yyleng, yytext);
106*7c478bd9Sstevel@tonic-gate 				return (NAME);
107*7c478bd9Sstevel@tonic-gate 			}
108*7c478bd9Sstevel@tonic-gate 		}
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate "{"		{return (CBO);}
112*7c478bd9Sstevel@tonic-gate "}"		{return (CBC);}
113*7c478bd9Sstevel@tonic-gate "["		{return (SBO);}
114*7c478bd9Sstevel@tonic-gate "]"		{return (SBC);}
115*7c478bd9Sstevel@tonic-gate "("		{return (PO);}
116*7c478bd9Sstevel@tonic-gate ")"		{return (PC);}
117*7c478bd9Sstevel@tonic-gate ";"		{return (SC);}
118*7c478bd9Sstevel@tonic-gate ","		{return (COMMA);}
119*7c478bd9Sstevel@tonic-gate ":"		{return (COLON);}
120*7c478bd9Sstevel@tonic-gate "..."		{return (ELLIPSES);}
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate 
123*7c478bd9Sstevel@tonic-gate "="		{return (ASSIGN);}
124*7c478bd9Sstevel@tonic-gate "||"		{return (LOR);}
125*7c478bd9Sstevel@tonic-gate "&&"		{return (LAND);}
126*7c478bd9Sstevel@tonic-gate "|"		{return (OR);}
127*7c478bd9Sstevel@tonic-gate "^"		{return (XOR);}
128*7c478bd9Sstevel@tonic-gate "&"		{return (AND);}
129*7c478bd9Sstevel@tonic-gate "=="		{return (EQ);}
130*7c478bd9Sstevel@tonic-gate "!="		{return (NE);}
131*7c478bd9Sstevel@tonic-gate "<"		{return (LT);}
132*7c478bd9Sstevel@tonic-gate "<="		{return (LE);}
133*7c478bd9Sstevel@tonic-gate ">"		{return (GT);}
134*7c478bd9Sstevel@tonic-gate ">="		{return (GE);}
135*7c478bd9Sstevel@tonic-gate "<<"		{return (SHL);}
136*7c478bd9Sstevel@tonic-gate ">>"		{return (SHR);}
137*7c478bd9Sstevel@tonic-gate "+"		{return (PLUS);}
138*7c478bd9Sstevel@tonic-gate "-"		{return (MINUS);}
139*7c478bd9Sstevel@tonic-gate "*"		{return (MUL);}
140*7c478bd9Sstevel@tonic-gate "/"		{return (DIV);}
141*7c478bd9Sstevel@tonic-gate "%"		{return (MOD);}
142*7c478bd9Sstevel@tonic-gate "!"		{return (NOT);}
143*7c478bd9Sstevel@tonic-gate "~"		{return (NEG);}
144*7c478bd9Sstevel@tonic-gate 
145*7c478bd9Sstevel@tonic-gate .		{	itm_error(
146*7c478bd9Sstevel@tonic-gate 				gettext("Unrecognized token '%1$c' \n"),
147*7c478bd9Sstevel@tonic-gate 				cmd_opt.my_name, yytext[0]);
148*7c478bd9Sstevel@tonic-gate 			return (0);
149*7c478bd9Sstevel@tonic-gate 		}
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate %%
152*7c478bd9Sstevel@tonic-gate 
153*7c478bd9Sstevel@tonic-gate /*
154*7c478bd9Sstevel@tonic-gate  * lexinit - starts the Lexical Analyzer off in the right start condition
155*7c478bd9Sstevel@tonic-gate  */
156*7c478bd9Sstevel@tonic-gate void
157*7c478bd9Sstevel@tonic-gate lexinit()
158*7c478bd9Sstevel@tonic-gate {
159*7c478bd9Sstevel@tonic-gate 	BEGIN norm;
160*7c478bd9Sstevel@tonic-gate }
161*7c478bd9Sstevel@tonic-gate 
162*7c478bd9Sstevel@tonic-gate /* does this really need to be here? */
163*7c478bd9Sstevel@tonic-gate int
yywrap()164*7c478bd9Sstevel@tonic-gate yywrap()
165*7c478bd9Sstevel@tonic-gate {
166*7c478bd9Sstevel@tonic-gate 	return (1);
167*7c478bd9Sstevel@tonic-gate }
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate void
yyerror(char * s)170*7c478bd9Sstevel@tonic-gate yyerror(char *s)
171*7c478bd9Sstevel@tonic-gate {
172*7c478bd9Sstevel@tonic-gate 	extern int	yylineno;
173*7c478bd9Sstevel@tonic-gate 
174*7c478bd9Sstevel@tonic-gate 	itm_error(
175*7c478bd9Sstevel@tonic-gate 		gettext("%1$s: file(%2$s) line(%3$d) last token(%4$s)\n"),
176*7c478bd9Sstevel@tonic-gate 		s, itm_input_file, yylineno, yytext);
177*7c478bd9Sstevel@tonic-gate 
178*7c478bd9Sstevel@tonic-gate 	exit(ITMC_STATUS_BT);
179*7c478bd9Sstevel@tonic-gate }
180*7c478bd9Sstevel@tonic-gate 
181*7c478bd9Sstevel@tonic-gate typedef struct {
182*7c478bd9Sstevel@tonic-gate 	char	*name;
183*7c478bd9Sstevel@tonic-gate 	int	token;
184*7c478bd9Sstevel@tonic-gate } at_name_token_t;
185*7c478bd9Sstevel@tonic-gate 
186*7c478bd9Sstevel@tonic-gate /*
187*7c478bd9Sstevel@tonic-gate  * NOT: This table must be sorted alphabetically.
188*7c478bd9Sstevel@tonic-gate  */
189*7c478bd9Sstevel@tonic-gate static at_name_token_t at_table[] = {
190*7c478bd9Sstevel@tonic-gate 	"@automatic",	MAPTYPE_AUTO,
191*7c478bd9Sstevel@tonic-gate 	"@binary",	MAPTYPE_BINARY,
192*7c478bd9Sstevel@tonic-gate 	"@between",	BETWEEN,
193*7c478bd9Sstevel@tonic-gate 	"@condition",	CONDITION,
194*7c478bd9Sstevel@tonic-gate 	"@default",	ITM_DEFAULT,
195*7c478bd9Sstevel@tonic-gate 	"@dense",	MAPTYPE_DENSE,
196*7c478bd9Sstevel@tonic-gate 	"@direction",	DIRECTION,
197*7c478bd9Sstevel@tonic-gate 	"@discard",	DISCARD,
198*7c478bd9Sstevel@tonic-gate 	"@else",	ITM_ELSE,
199*7c478bd9Sstevel@tonic-gate 	"@error",	ERROR,
200*7c478bd9Sstevel@tonic-gate 	"@escapeseq",	ESCAPESEQ,
201*7c478bd9Sstevel@tonic-gate 	"@false",	ITM_FALSE,
202*7c478bd9Sstevel@tonic-gate 	"@hash",	MAPTYPE_HASH,
203*7c478bd9Sstevel@tonic-gate 	"@identical",	ITM_IDENTICAL,
204*7c478bd9Sstevel@tonic-gate 	"@if",		ITM_IF,
205*7c478bd9Sstevel@tonic-gate 	"@in",		ITM_IN,
206*7c478bd9Sstevel@tonic-gate 	"@index",	MAPTYPE_INDEX,
207*7c478bd9Sstevel@tonic-gate 	"@init",	ITM_INIT,
208*7c478bd9Sstevel@tonic-gate 	"@input",	ITM_IN,
209*7c478bd9Sstevel@tonic-gate 	"@inputsize",	ITM_INSIZE,
210*7c478bd9Sstevel@tonic-gate 	"@map",		MAP,
211*7c478bd9Sstevel@tonic-gate 	"@maptype",	MAPTYPE,
212*7c478bd9Sstevel@tonic-gate 	"@no_change_copy",	ITM_IDENTICAL,
213*7c478bd9Sstevel@tonic-gate 	"@nop",		NOP,
214*7c478bd9Sstevel@tonic-gate 	"@operation",	OPERATION,
215*7c478bd9Sstevel@tonic-gate 	"@out",		ITM_OUT,
216*7c478bd9Sstevel@tonic-gate 	"@output",	ITM_OUT,
217*7c478bd9Sstevel@tonic-gate 	"@output_byte_length",	RESULTLEN,
218*7c478bd9Sstevel@tonic-gate 	"@outputsize",	ITM_OUTSIZE,
219*7c478bd9Sstevel@tonic-gate 	"@printchr",	PRINTCHR,
220*7c478bd9Sstevel@tonic-gate 	"@printhd",	PRINTHD,
221*7c478bd9Sstevel@tonic-gate 	"@printint",	PRINTINT,
222*7c478bd9Sstevel@tonic-gate 	"@reset",	RESET,
223*7c478bd9Sstevel@tonic-gate 	"@resultlen",	RESULTLEN,
224*7c478bd9Sstevel@tonic-gate 	"@return",	RETURN,
225*7c478bd9Sstevel@tonic-gate 	"@true",	ITM_TRUE,
226*7c478bd9Sstevel@tonic-gate 	"automatic",	MAPTYPE_AUTO,
227*7c478bd9Sstevel@tonic-gate 	"between",	BETWEEN,
228*7c478bd9Sstevel@tonic-gate 	"binary",	MAPTYPE_BINARY,
229*7c478bd9Sstevel@tonic-gate 	"break",	BREAK,
230*7c478bd9Sstevel@tonic-gate 	"condition",	CONDITION,
231*7c478bd9Sstevel@tonic-gate 	"default",	ITM_DEFAULT,
232*7c478bd9Sstevel@tonic-gate 	"dense",	MAPTYPE_DENSE,
233*7c478bd9Sstevel@tonic-gate 	"direction",	DIRECTION,
234*7c478bd9Sstevel@tonic-gate 	"discard",	DISCARD,
235*7c478bd9Sstevel@tonic-gate 	"else",		ITM_ELSE,
236*7c478bd9Sstevel@tonic-gate 	"error",	ERROR,
237*7c478bd9Sstevel@tonic-gate 	"escapeseq",	ESCAPESEQ,
238*7c478bd9Sstevel@tonic-gate 	"false",	ITM_FALSE,
239*7c478bd9Sstevel@tonic-gate 	"hash",		MAPTYPE_HASH,
240*7c478bd9Sstevel@tonic-gate 	"if",		ITM_IF,
241*7c478bd9Sstevel@tonic-gate 	"index",	MAPTYPE_INDEX,
242*7c478bd9Sstevel@tonic-gate 	"init",		ITM_INIT,
243*7c478bd9Sstevel@tonic-gate 	"input",	ITM_IN,
244*7c478bd9Sstevel@tonic-gate 	"inputsize",	ITM_INSIZE,
245*7c478bd9Sstevel@tonic-gate 	"map",		MAP,
246*7c478bd9Sstevel@tonic-gate 	"maptype",	MAPTYPE,
247*7c478bd9Sstevel@tonic-gate 	"no_change_copy",	ITM_IDENTICAL,
248*7c478bd9Sstevel@tonic-gate 	"nop",		NOP,
249*7c478bd9Sstevel@tonic-gate 	"operation",	OPERATION,
250*7c478bd9Sstevel@tonic-gate 	"output",	ITM_OUT,
251*7c478bd9Sstevel@tonic-gate 	"output_byte_length",	RESULTLEN,
252*7c478bd9Sstevel@tonic-gate 	"outputsize",	ITM_OUTSIZE,
253*7c478bd9Sstevel@tonic-gate 	"printchr",	PRINTCHR,
254*7c478bd9Sstevel@tonic-gate 	"printhd",	PRINTHD,
255*7c478bd9Sstevel@tonic-gate 	"printint",	PRINTINT,
256*7c478bd9Sstevel@tonic-gate 	"reset",	RESET,
257*7c478bd9Sstevel@tonic-gate 	"return",	RETURN,
258*7c478bd9Sstevel@tonic-gate 	"true",		ITM_TRUE,
259*7c478bd9Sstevel@tonic-gate };
260*7c478bd9Sstevel@tonic-gate 
261*7c478bd9Sstevel@tonic-gate int
at_name_to_token(char * s)262*7c478bd9Sstevel@tonic-gate at_name_to_token(char *s)
263*7c478bd9Sstevel@tonic-gate {
264*7c478bd9Sstevel@tonic-gate 	int	high;
265*7c478bd9Sstevel@tonic-gate 	int	mid;
266*7c478bd9Sstevel@tonic-gate 	int	low;
267*7c478bd9Sstevel@tonic-gate 	int	result;
268*7c478bd9Sstevel@tonic-gate 
269*7c478bd9Sstevel@tonic-gate 	TRACE_MESSAGE('l', ("at_name_to_token: %s", s));
270*7c478bd9Sstevel@tonic-gate 	for (low = 0, high = (sizeof (at_table) /
271*7c478bd9Sstevel@tonic-gate 				sizeof (at_name_token_t));
272*7c478bd9Sstevel@tonic-gate 	    low < high; /* NOP */) {
273*7c478bd9Sstevel@tonic-gate 		mid = (low + high) / 2;
274*7c478bd9Sstevel@tonic-gate 		result = strcmp(s, at_table[mid].name);
275*7c478bd9Sstevel@tonic-gate 		if (result < 0) {
276*7c478bd9Sstevel@tonic-gate 			high = mid;
277*7c478bd9Sstevel@tonic-gate 		} else if (0 < result) {
278*7c478bd9Sstevel@tonic-gate 			low = mid + 1;
279*7c478bd9Sstevel@tonic-gate 		} else { /* 0 == result */
280*7c478bd9Sstevel@tonic-gate 			TRACE_MESSAGE('l', (" %d\n", at_table[mid].token));
281*7c478bd9Sstevel@tonic-gate 			return (at_table[mid].token);
282*7c478bd9Sstevel@tonic-gate 		}
283*7c478bd9Sstevel@tonic-gate 	}
284*7c478bd9Sstevel@tonic-gate 	TRACE_MESSAGE('l', (" - not found\n"));
285*7c478bd9Sstevel@tonic-gate 	return (0);
286*7c478bd9Sstevel@tonic-gate }
287*7c478bd9Sstevel@tonic-gate 
288*7c478bd9Sstevel@tonic-gate static itm_data_t *
hexadecimal_data(int seqsize,char * seq)289*7c478bd9Sstevel@tonic-gate hexadecimal_data(int seqsize, char *seq)
290*7c478bd9Sstevel@tonic-gate {
291*7c478bd9Sstevel@tonic-gate 	itm_data_t	*data;
292*7c478bd9Sstevel@tonic-gate 	char		*binary;
293*7c478bd9Sstevel@tonic-gate 	int		i, j;
294*7c478bd9Sstevel@tonic-gate 	int		val;
295*7c478bd9Sstevel@tonic-gate 	int		high;
296*7c478bd9Sstevel@tonic-gate 	int		low;
297*7c478bd9Sstevel@tonic-gate 	int		size;
298*7c478bd9Sstevel@tonic-gate 
299*7c478bd9Sstevel@tonic-gate 	/* size is assured to be multiple of 2 */
300*7c478bd9Sstevel@tonic-gate 	assert(seqsize != 0);
301*7c478bd9Sstevel@tonic-gate 	size = seqsize + 1;
302*7c478bd9Sstevel@tonic-gate 	size /= 2;
303*7c478bd9Sstevel@tonic-gate 	if (size > MAXSEQUENCE) {
304*7c478bd9Sstevel@tonic-gate 		itm_error(
305*7c478bd9Sstevel@tonic-gate 		gettext(" specified sequence must be less than %$1d\n"),
306*7c478bd9Sstevel@tonic-gate 		MAXSEQUENCE);
307*7c478bd9Sstevel@tonic-gate 		return (NULL);
308*7c478bd9Sstevel@tonic-gate 	}
309*7c478bd9Sstevel@tonic-gate 	binary = malloc_vital(size);
310*7c478bd9Sstevel@tonic-gate 	i = j = 0;
311*7c478bd9Sstevel@tonic-gate 	if (seqsize % 2 != 0) {
312*7c478bd9Sstevel@tonic-gate 		low =  *(seq);
313*7c478bd9Sstevel@tonic-gate 		if (('0' <= low) && (low <= '9')) {
314*7c478bd9Sstevel@tonic-gate 			val = (low - '0');
315*7c478bd9Sstevel@tonic-gate 		} else if (('a' <= low) && (low <= 'f')) {
316*7c478bd9Sstevel@tonic-gate 			val = (low - 'a' + 10);
317*7c478bd9Sstevel@tonic-gate 		} else if (('A' <= low) && (low <= 'F')) {
318*7c478bd9Sstevel@tonic-gate 			val = (low - 'A' + 10);
319*7c478bd9Sstevel@tonic-gate 		}
320*7c478bd9Sstevel@tonic-gate 		*(binary + i) = val;
321*7c478bd9Sstevel@tonic-gate 		i++;
322*7c478bd9Sstevel@tonic-gate 		j++;
323*7c478bd9Sstevel@tonic-gate 	}
324*7c478bd9Sstevel@tonic-gate 	for (/* NOP */; i < size; i++, j += 2) {
325*7c478bd9Sstevel@tonic-gate 		high = *(seq + j);
326*7c478bd9Sstevel@tonic-gate 		low =  *(seq + j + 1);
327*7c478bd9Sstevel@tonic-gate 		if (('0' <= high) && (high <= '9')) {
328*7c478bd9Sstevel@tonic-gate 			val = ((high - '0') << 4);
329*7c478bd9Sstevel@tonic-gate 		} else if (('a' <= high) && (high <= 'f')) {
330*7c478bd9Sstevel@tonic-gate 			val = ((high - 'a' + 10) << 4);
331*7c478bd9Sstevel@tonic-gate 		} else if (('A' <= high) && (high <= 'F')) {
332*7c478bd9Sstevel@tonic-gate 			val = ((high - 'A' + 10) << 4);
333*7c478bd9Sstevel@tonic-gate 		}
334*7c478bd9Sstevel@tonic-gate 		if (('0' <= low) && (low <= '9')) {
335*7c478bd9Sstevel@tonic-gate 			val |= (low - '0');
336*7c478bd9Sstevel@tonic-gate 		} else if (('a' <= low) && (low <= 'f')) {
337*7c478bd9Sstevel@tonic-gate 			val |= (low - 'a' + 10);
338*7c478bd9Sstevel@tonic-gate 		} else if (('A' <= low) && (low <= 'F')) {
339*7c478bd9Sstevel@tonic-gate 			val |= (low - 'A' + 10);
340*7c478bd9Sstevel@tonic-gate 		}
341*7c478bd9Sstevel@tonic-gate 		*(binary + i) = val;
342*7c478bd9Sstevel@tonic-gate 	}
343*7c478bd9Sstevel@tonic-gate 
344*7c478bd9Sstevel@tonic-gate 	data = malloc_vital(sizeof (itm_data_t));
345*7c478bd9Sstevel@tonic-gate 
346*7c478bd9Sstevel@tonic-gate 	data->size = size;
347*7c478bd9Sstevel@tonic-gate 	if (size <= sizeof (data->place)) {
348*7c478bd9Sstevel@tonic-gate 		(void) memmove(&(data->place), binary, size);
349*7c478bd9Sstevel@tonic-gate 		free(binary);
350*7c478bd9Sstevel@tonic-gate 	} else {
351*7c478bd9Sstevel@tonic-gate 		data->place.itm_ptr = (itm_place2_t)binary;
352*7c478bd9Sstevel@tonic-gate 	}
353*7c478bd9Sstevel@tonic-gate 
354*7c478bd9Sstevel@tonic-gate 	return (data);
355*7c478bd9Sstevel@tonic-gate }
356*7c478bd9Sstevel@tonic-gate 
357*7c478bd9Sstevel@tonic-gate static itm_data_t *
name_data(int size,char * seq)358*7c478bd9Sstevel@tonic-gate name_data(int size, char *seq)
359*7c478bd9Sstevel@tonic-gate {
360*7c478bd9Sstevel@tonic-gate 	itm_data_t *data;
361*7c478bd9Sstevel@tonic-gate 
362*7c478bd9Sstevel@tonic-gate 
363*7c478bd9Sstevel@tonic-gate 	if (size > MAXNAMELENGTH) {
364*7c478bd9Sstevel@tonic-gate 		itm_error(gettext("the length(%d) exceed limitation(%d)"),
365*7c478bd9Sstevel@tonic-gate 		size, MAXNAMELENGTH);
366*7c478bd9Sstevel@tonic-gate 		exit(ITMC_STATUS_BT2);
367*7c478bd9Sstevel@tonic-gate 	}
368*7c478bd9Sstevel@tonic-gate 	data = malloc_vital(sizeof (itm_data_t));
369*7c478bd9Sstevel@tonic-gate 
370*7c478bd9Sstevel@tonic-gate 	data->size = size;
371*7c478bd9Sstevel@tonic-gate 	if (size <= sizeof (data->place)) {
372*7c478bd9Sstevel@tonic-gate 		(void) memmove(&(data->place), seq, size);
373*7c478bd9Sstevel@tonic-gate 	} else {
374*7c478bd9Sstevel@tonic-gate 		data->place.itm_ptr = (itm_place2_t)malloc_vital(size);
375*7c478bd9Sstevel@tonic-gate 		(void) memmove((char *)(data->place.itm_ptr), seq, size);
376*7c478bd9Sstevel@tonic-gate 	}
377*7c478bd9Sstevel@tonic-gate 
378*7c478bd9Sstevel@tonic-gate 	return (data);
379*7c478bd9Sstevel@tonic-gate }
380*7c478bd9Sstevel@tonic-gate 
381*7c478bd9Sstevel@tonic-gate static void
filename_lineno(void)382*7c478bd9Sstevel@tonic-gate filename_lineno(void)
383*7c478bd9Sstevel@tonic-gate {
384*7c478bd9Sstevel@tonic-gate 	static char	*re;
385*7c478bd9Sstevel@tonic-gate 	static char	restr[] =
386*7c478bd9Sstevel@tonic-gate 			"^#[ \t]*\\([0-9]\\{1,\\}\\)[ \t]*\"\\(.*\\)\".*";
387*7c478bd9Sstevel@tonic-gate 	int		match;
388*7c478bd9Sstevel@tonic-gate 	extern char	*braslist[];
389*7c478bd9Sstevel@tonic-gate 	extern char	*braelist[];
390*7c478bd9Sstevel@tonic-gate 	static char	*filename;
391*7c478bd9Sstevel@tonic-gate 	int		len;
392*7c478bd9Sstevel@tonic-gate 	int		lineno;
393*7c478bd9Sstevel@tonic-gate 
394*7c478bd9Sstevel@tonic-gate 	if (NULL == re) {
395*7c478bd9Sstevel@tonic-gate 		re = compile(restr, NULL, NULL);
396*7c478bd9Sstevel@tonic-gate 		if (NULL == re) {
397*7c478bd9Sstevel@tonic-gate 			itm_error(
398*7c478bd9Sstevel@tonic-gate 				gettext("REGEXP compile error\n"));
399*7c478bd9Sstevel@tonic-gate 			exit(ITMC_STATUS_BT);
400*7c478bd9Sstevel@tonic-gate 		}
401*7c478bd9Sstevel@tonic-gate 	}
402*7c478bd9Sstevel@tonic-gate 	match = step(yytext, re);
403*7c478bd9Sstevel@tonic-gate 	if (0 != match) {
404*7c478bd9Sstevel@tonic-gate 		lineno = atoi(braslist[0]);
405*7c478bd9Sstevel@tonic-gate 		free(filename);
406*7c478bd9Sstevel@tonic-gate 		len = braelist[1] - braslist[1];
407*7c478bd9Sstevel@tonic-gate 		filename = malloc_vital(len + 1);
408*7c478bd9Sstevel@tonic-gate 		(void) memcpy(filename, braslist[1], len);
409*7c478bd9Sstevel@tonic-gate 		*(filename + len) = '\0';
410*7c478bd9Sstevel@tonic-gate 		itm_input_file = filename;
411*7c478bd9Sstevel@tonic-gate 		yylineno = lineno;
412*7c478bd9Sstevel@tonic-gate 	}
413*7c478bd9Sstevel@tonic-gate }
414