diff options
author | Eric Andersen <andersen@codepoet.org> | 2004-07-26 12:06:19 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2004-07-26 12:06:19 +0000 |
commit | 53f5c0d5bf9c03e68531f89e05872f6cc0d88962 (patch) | |
tree | 160e9fdda67c1391b1f9344b1b722b40e418ef1b | |
parent | ac594257c34c12a2ca1b8e766c5f575ed2b05f5a (diff) | |
download | busybox-53f5c0d5bf9c03e68531f89e05872f6cc0d88962.tar.gz |
Allow hex escape sequences
-rw-r--r-- | libbb/process_escape_sequence.c | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/libbb/process_escape_sequence.c b/libbb/process_escape_sequence.c index e6b5fc995..f5ac500fa 100644 --- a/libbb/process_escape_sequence.c +++ b/libbb/process_escape_sequence.c @@ -22,42 +22,35 @@ * */ -#include <string.h> #include <stdio.h> #include <limits.h> -#include <ctype.h> #include "libbb.h" -#define isodigit(c) ((c) >= '0' && (c) <= '7') -#define hextobin(c) ((c)>='a'&&(c)<='f' ? (c)-'a'+10 : (c)>='A'&&(c)<='F' ? (c)-'A'+10 : (c)-'0') -#define octtobin(c) ((c) - '0') char bb_process_escape_sequence(const char **ptr) { - const char *p, *q; - unsigned int num_digits, r, n, hexescape; static const char charmap[] = { 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', 0, '\a', '\b', '\f', '\n', '\r', '\t', '\v', '\\', '\\' }; - n = r = hexescape = num_digits = 0; - q = *ptr; + const char *p; + const char *q; + unsigned int num_digits; + unsigned int r; + unsigned int n; - if (*q == 'x') { - hexescape++; - ++q; - } + n = 0; + q = *ptr; + num_digits = 0; do { - if (hexescape && isxdigit(*q)) { - r = n * 16 + hextobin(*q); - } else if (isodigit(*q)) { - r = n * 8 + octtobin(*q); - } - if (r <= UCHAR_MAX) { - n = r; - ++q; - if (++num_digits < 3) { - continue; + if (((unsigned int)(*q - '0')) <= 7) { + r = n * 8 + (*q - '0'); + if (r <= UCHAR_MAX) { + n = r; + ++q; + if (++num_digits < 3) { + continue; + } } } break; |