diff options
author | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2004-07-26 12:06:19 +0000 |
---|---|---|
committer | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2004-07-26 12:06:19 +0000 |
commit | 9e054bb9e199d73fe0d5e87a19261b902fb85460 (patch) | |
tree | 160e9fdda67c1391b1f9344b1b722b40e418ef1b | |
parent | 464221ab85fb7f23930fbad6106651122c11099e (diff) | |
download | busybox-w32-9e054bb9e199d73fe0d5e87a19261b902fb85460.tar.gz busybox-w32-9e054bb9e199d73fe0d5e87a19261b902fb85460.tar.bz2 busybox-w32-9e054bb9e199d73fe0d5e87a19261b902fb85460.zip |
Allow hex escape sequences
git-svn-id: svn://busybox.net/trunk/busybox@9022 69ca8d6d-28ef-0310-b511-8ec308f3f277
-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 @@ | |||
22 | * | 22 | * |
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include <string.h> | ||
26 | #include <stdio.h> | 25 | #include <stdio.h> |
27 | #include <limits.h> | 26 | #include <limits.h> |
28 | #include <ctype.h> | ||
29 | #include "libbb.h" | 27 | #include "libbb.h" |
30 | 28 | ||
31 | #define isodigit(c) ((c) >= '0' && (c) <= '7') | ||
32 | #define hextobin(c) ((c)>='a'&&(c)<='f' ? (c)-'a'+10 : (c)>='A'&&(c)<='F' ? (c)-'A'+10 : (c)-'0') | ||
33 | #define octtobin(c) ((c) - '0') | ||
34 | char bb_process_escape_sequence(const char **ptr) | 29 | char bb_process_escape_sequence(const char **ptr) |
35 | { | 30 | { |
36 | const char *p, *q; | ||
37 | unsigned int num_digits, r, n, hexescape; | ||
38 | static const char charmap[] = { | 31 | static const char charmap[] = { |
39 | 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', 0, | 32 | 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', 0, |
40 | '\a', '\b', '\f', '\n', '\r', '\t', '\v', '\\', '\\' }; | 33 | '\a', '\b', '\f', '\n', '\r', '\t', '\v', '\\', '\\' }; |
41 | 34 | ||
42 | n = r = hexescape = num_digits = 0; | 35 | const char *p; |
43 | q = *ptr; | 36 | const char *q; |
37 | unsigned int num_digits; | ||
38 | unsigned int r; | ||
39 | unsigned int n; | ||
44 | 40 | ||
45 | if (*q == 'x') { | 41 | n = 0; |
46 | hexescape++; | 42 | q = *ptr; |
47 | ++q; | ||
48 | } | ||
49 | 43 | ||
44 | num_digits = 0; | ||
50 | do { | 45 | do { |
51 | if (hexescape && isxdigit(*q)) { | 46 | if (((unsigned int)(*q - '0')) <= 7) { |
52 | r = n * 16 + hextobin(*q); | 47 | r = n * 8 + (*q - '0'); |
53 | } else if (isodigit(*q)) { | 48 | if (r <= UCHAR_MAX) { |
54 | r = n * 8 + octtobin(*q); | 49 | n = r; |
55 | } | 50 | ++q; |
56 | if (r <= UCHAR_MAX) { | 51 | if (++num_digits < 3) { |
57 | n = r; | 52 | continue; |
58 | ++q; | 53 | } |
59 | if (++num_digits < 3) { | ||
60 | continue; | ||
61 | } | 54 | } |
62 | } | 55 | } |
63 | break; | 56 | break; |