5 * The contents of this file are subject to the terms of the
6 * Common Development and Distribution License, Version 1.0 only
7 * (the "License"). You may not use this file except in compliance
10 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 * or http://www.opensolaris.org/os/licensing.
12 * See the License for the specific language governing permissions
13 * and limitations under the License.
15 * When distributing Covered Code, include this CDDL HEADER in each
16 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 * If applicable, add the following below this CDDL HEADER, with the
18 * fields enclosed by brackets "[]" replaced with your own identifying
19 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
42 static itm_data_t *hexadecimal_data(int, char *);
43 static itm_data_t *name_data(int, char *);
44 static void filename_lineno(void);
45 static int at_name_to_token(char *);
54 HEXADECIMAL (("0x"|"0X")([0-9A-Fa-f])+)
55 ITMNAME (([^% \t\n\r])+"%"([^% \t\n\r])+)
56 ATNAME "@"([0-9A-Za-z_]+)
57 NAME ([A-Za-z_][A-Za-z0-9_]*)
58 MAPTYPE_NAME (automatic|dense|index|hash|binary)
65 ^"#"[ \t]*{DECIMAL}[ \t]*"\"".*"\"".*"\n" {
70 if (NULL == cmd_opt.preprocess) {
73 "preprocess may be required\n"));
78 yylval.num = strtoul(yytext, (char **)NULL, 10);
82 {OCTAL} { yylval.num = strtoul(yytext, (char **)NULL, 8);
86 {HEXADECIMAL} { yylval.data = hexadecimal_data(yyleng - 2, yytext + 2);
90 {ITMNAME} { yylval.data = str_to_data(yyleng, yytext);
94 {ATNAME} { return at_name_to_token(yytext);
97 {MAPTYPE_NAME} { yylval.num = at_name_to_token(yytext);
98 yylval.data = name_data(yyleng, yytext);
99 return (MAPTYPE_NAME);
103 {NAME} { yylval.num = at_name_to_token(yytext);
104 if (0 != yylval.num) {
107 yylval.data = name_data(yyleng, yytext);
120 "," {return (COMMA);}
121 ":" {return (COLON);}
122 "..." {return (ELLIPSES);}
125 "=" {return (ASSIGN);}
127 "&&" {return (LAND);}
140 "-" {return (MINUS);}
148 gettext("Unrecognized token '%1$c' \n"),
149 cmd_opt.my_name, yytext[0]);
156 * lexinit - starts the Lexical Analyzer off in the right start condition
164 /* does this really need to be here? */
177 gettext("%1$s: file(%2$s) line(%3$d) last token(%4$s)\n"),
178 s, itm_input_file, yylineno, yytext);
180 exit(ITMC_STATUS_BT);
189 * NOT: This table must be sorted alphabetically.
191 static at_name_token_t at_table[] = {
192 "@automatic", MAPTYPE_AUTO,
193 "@binary", MAPTYPE_BINARY,
195 "@condition", CONDITION,
196 "@default", ITM_DEFAULT,
197 "@dense", MAPTYPE_DENSE,
198 "@direction", DIRECTION,
202 "@escapeseq", ESCAPESEQ,
204 "@hash", MAPTYPE_HASH,
205 "@identical", ITM_IDENTICAL,
208 "@index", MAPTYPE_INDEX,
211 "@inputsize", ITM_INSIZE,
214 "@no_change_copy", ITM_IDENTICAL,
216 "@operation", OPERATION,
219 "@output_byte_length", RESULTLEN,
220 "@outputsize", ITM_OUTSIZE,
221 "@printchr", PRINTCHR,
223 "@printint", PRINTINT,
225 "@resultlen", RESULTLEN,
228 "automatic", MAPTYPE_AUTO,
230 "binary", MAPTYPE_BINARY,
232 "condition", CONDITION,
233 "default", ITM_DEFAULT,
234 "dense", MAPTYPE_DENSE,
235 "direction", DIRECTION,
239 "escapeseq", ESCAPESEQ,
241 "hash", MAPTYPE_HASH,
243 "index", MAPTYPE_INDEX,
246 "inputsize", ITM_INSIZE,
249 "no_change_copy", ITM_IDENTICAL,
251 "operation", OPERATION,
253 "output_byte_length", RESULTLEN,
254 "outputsize", ITM_OUTSIZE,
255 "printchr", PRINTCHR,
257 "printint", PRINTINT,
264 at_name_to_token(char *s)
271 TRACE_MESSAGE('l', ("at_name_to_token: %s", s));
272 for (low = 0, high = (sizeof (at_table) /
273 sizeof (at_name_token_t));
274 low < high; /* NOP */) {
275 mid = (low + high) / 2;
276 result = strcmp(s, at_table[mid].name);
279 } else if (0 < result) {
281 } else { /* 0 == result */
282 TRACE_MESSAGE('l', (" %d\n", at_table[mid].token));
283 return (at_table[mid].token);
286 TRACE_MESSAGE('l', (" - not found\n"));
291 hexadecimal_data(int seqsize, char *seq)
301 /* size is assured to be multiple of 2 */
302 assert(seqsize != 0);
305 if (size > MAXSEQUENCE) {
307 gettext(" specified sequence must be less than %$1d\n"),
311 binary = malloc_vital(size);
313 if (seqsize % 2 != 0) {
315 if (('0' <= low) && (low <= '9')) {
317 } else if (('a' <= low) && (low <= 'f')) {
318 val = (low - 'a' + 10);
319 } else if (('A' <= low) && (low <= 'F')) {
320 val = (low - 'A' + 10);
326 for (/* NOP */; i < size; i++, j += 2) {
328 low = *(seq + j + 1);
329 if (('0' <= high) && (high <= '9')) {
330 val = ((high - '0') << 4);
331 } else if (('a' <= high) && (high <= 'f')) {
332 val = ((high - 'a' + 10) << 4);
333 } else if (('A' <= high) && (high <= 'F')) {
334 val = ((high - 'A' + 10) << 4);
336 if (('0' <= low) && (low <= '9')) {
338 } else if (('a' <= low) && (low <= 'f')) {
339 val |= (low - 'a' + 10);
340 } else if (('A' <= low) && (low <= 'F')) {
341 val |= (low - 'A' + 10);
346 data = malloc_vital(sizeof (itm_data_t));
349 if (size <= sizeof (data->place)) {
350 (void) memmove(&(data->place), binary, size);
353 data->place.itm_ptr = (itm_place2_t)binary;
360 name_data(int size, char *seq)
365 if (size > MAXNAMELENGTH) {
366 itm_error(gettext("the length(%d) exceed limitation(%d)"),
367 size, MAXNAMELENGTH);
368 exit(ITMC_STATUS_BT2);
370 data = malloc_vital(sizeof (itm_data_t));
373 if (size <= sizeof (data->place)) {
374 (void) memmove(&(data->place), seq, size);
376 data->place.itm_ptr = (itm_place2_t)malloc_vital(size);
377 (void) memmove((char *)(data->place.itm_ptr), seq, size);
384 filename_lineno(void)
387 static char restr[] =
388 "^#[ \t]*\\([0-9]\\{1,\\}\\)[ \t]*\"\\(.*\\)\".*";
390 extern char *braslist[];
391 extern char *braelist[];
392 static char *filename;
397 re = compile(restr, NULL, NULL);
400 gettext("REGEXP compile error\n"));
401 exit(ITMC_STATUS_BT);
404 match = step(yytext, re);
406 lineno = atoi(braslist[0]);
408 len = braelist[1] - braslist[1];
409 filename = malloc_vital(len + 1);
410 (void) memcpy(filename, braslist[1], len);
411 *(filename + len) = '\0';
412 itm_input_file = filename;