summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorVern Paxson <vern@ee.lbl.gov>1990-08-14 00:01:35 +0000
committerVern Paxson <vern@ee.lbl.gov>1990-08-14 00:01:35 +0000
commit43513ce78095f8ef020712f524a673b86ed4eca4 (patch)
treed9ab1e13133af750df9f80217d7bef3dfbdf8bac /misc.c
parenta68338983196b83c29f4779b7493a98e00499575 (diff)
fixed hexadecimal escapes; added is_hex_digit()
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c71
1 files changed, 58 insertions, 13 deletions
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':
+ { /* \<octal> */
+ sptr = 1;
- { /* \<octal> or \x<hex> */
- 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<hex> */
+ 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;