diff options
author | Eric Andersen <andersen@codepoet.org> | 2004-07-26 15:28:47 +0400 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2004-07-26 15:28:47 +0400 |
commit | 380919905cd689f0d295abb4f10468b3144a83ce (patch) | |
tree | 4c0a6c5d276d73dfec8efb47b4bf6471ef566203 /libbb | |
parent | 4f807a84c5d936c931cd93c9e98d087305295a1c (diff) |
Allow hex escape sequences
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/process_escape_sequence.c | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/libbb/process_escape_sequence.c b/libbb/process_escape_sequence.c index f5ac500fa..e6b5fc995 100644 --- a/libbb/process_escape_sequence.c +++ b/libbb/process_escape_sequence.c @@ -22,35 +22,42 @@ * */ +#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', '\\', '\\' }; - const char *p; - const char *q; - unsigned int num_digits; - unsigned int r; - unsigned int n; - - n = 0; + n = r = hexescape = num_digits = 0; q = *ptr; - num_digits = 0; + if (*q == 'x') { + hexescape++; + ++q; + } + do { - if (((unsigned int)(*q - '0')) <= 7) { - r = n * 8 + (*q - '0'); - if (r <= UCHAR_MAX) { - n = r; - ++q; - if (++num_digits < 3) { - continue; - } + 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; } } break; |