From: Vern Paxson Date: Tue, 14 Aug 1990 00:01:35 +0000 (+0000) Subject: fixed hexadecimal escapes; added is_hex_digit() X-Git-Tag: flex-2-5-5b~477 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=43513ce78095f8ef020712f524a673b86ed4eca4;p=flex fixed hexadecimal escapes; added is_hex_digit() --- diff --git a/misc.c b/misc.c index 2a05d6b..0071470 100644 --- a/misc.c +++ b/misc.c @@ -477,6 +477,38 @@ Char str[]; } +/* is_hex_digit - returns true if a character is a valid hex digit, false + * otherwise + * + * synopsis: + * int true_or_false, is_hex_digit(); + * int ch; + * val = is_hex_digit( ch ); + */ + +int is_hex_digit( ch ) +int ch; + + { + if ( isdigit( ch ) ) + return ( 1 ); + + switch ( clower( ch ) ) + { + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + return ( 1 ); + + default: + return ( 0 ); + } + } + + /* line_directive_out - spit out a "# line" statement */ void line_directive_out( output_file_name ) @@ -584,6 +616,9 @@ Char myesc( array ) Char array[]; { + Char c, esc_char; + register int sptr; + switch ( array[1] ) { case 'a': return ( '\a' ); @@ -594,9 +629,6 @@ Char array[]; case 't': return ( '\t' ); case 'v': return ( '\v' ); - case 'x': - /* fall through */ - case '0': case '1': case '2': @@ -607,15 +639,31 @@ Char array[]; case '7': case '8': case '9': + { /* \ */ + sptr = 1; - { /* \ or \x */ - Char c, esc_char; - register int sptr = 1; - - if ( array[1] == 'x' ) + while ( isascii( array[sptr] ) && isdigit( array[sptr] ) ) + /* don't increment inside loop control because if + * isdigit() is a macro it might expand into multiple + * increments ... + */ ++sptr; - while ( isascii( array[sptr] ) && isdigit( array[sptr] ) ) + c = array[sptr]; + array[sptr] = '\0'; + + esc_char = otoi( array + 1 ); + + array[sptr] = c; + + return ( esc_char ); + } + + case 'x': + { /* \x */ + int sptr = 2; + + while ( isascii( array[sptr] ) && is_hex_digit( array[sptr] ) ) /* don't increment inside loop control because if * isdigit() is a macro it will expand it to two * increments ... @@ -625,10 +673,7 @@ Char array[]; c = array[sptr]; array[sptr] = '\0'; - if ( array[1] == 'x' ) - esc_char = htoi( array + 2 ); - else - esc_char = otoi( array + 1 ); + esc_char = htoi( array + 2 ); array[sptr] = c;