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