diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-10-23 21:06:06 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-10-23 21:06:06 +0200 |
commit | 53600591311a129717abd2e3bcaa302622a6ce67 (patch) | |
tree | 4b0d08ed429d4b73a9739339e74d84a8a72fe25e /libbb | |
parent | 6a0d7490ea6ad97aeafb9da04acab13bd3c38e4d (diff) | |
download | busybox-w32-53600591311a129717abd2e3bcaa302622a6ce67.tar.gz busybox-w32-53600591311a129717abd2e3bcaa302622a6ce67.tar.bz2 busybox-w32-53600591311a129717abd2e3bcaa302622a6ce67.zip |
libbb: introduce and use strcpy_and_process_escape_sequences
function old new delta
strcpy_and_process_escape_sequences - 50 +50
bb_process_escape_sequence 148 138 -10
printf_main 789 776 -13
getty_main 1897 1831 -66
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/3 up/down: 50/-89) Total: -39 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/parse_config.c | 14 | ||||
-rw-r--r-- | libbb/process_escape_sequence.c | 44 |
2 files changed, 31 insertions, 27 deletions
diff --git a/libbb/parse_config.c b/libbb/parse_config.c index 3fff9f212..9dbfaf5d7 100644 --- a/libbb/parse_config.c +++ b/libbb/parse_config.c | |||
@@ -187,19 +187,7 @@ again: | |||
187 | 187 | ||
188 | #if 0 /* unused so far */ | 188 | #if 0 /* unused so far */ |
189 | if (flags & PARSE_ESCAPE) { | 189 | if (flags & PARSE_ESCAPE) { |
190 | const char *from; | 190 | strcpy_and_process_escape_sequences(tokens[t], tokens[t]); |
191 | char *to; | ||
192 | |||
193 | from = to = tokens[t]; | ||
194 | while (*from) { | ||
195 | if (*from == '\\') { | ||
196 | from++; | ||
197 | *to++ = bb_process_escape_sequence(&from); | ||
198 | } else { | ||
199 | *to++ = *from++; | ||
200 | } | ||
201 | } | ||
202 | *to = '\0'; | ||
203 | } | 191 | } |
204 | #endif | 192 | #endif |
205 | /* Skip possible delimiters */ | 193 | /* Skip possible delimiters */ |
diff --git a/libbb/process_escape_sequence.c b/libbb/process_escape_sequence.c index 82cbe10dc..dd6e076b0 100644 --- a/libbb/process_escape_sequence.c +++ b/libbb/process_escape_sequence.c | |||
@@ -31,14 +31,13 @@ char FAST_FUNC bb_process_escape_sequence(const char **ptr) | |||
31 | unsigned num_digits; | 31 | unsigned num_digits; |
32 | unsigned r; | 32 | unsigned r; |
33 | unsigned n; | 33 | unsigned n; |
34 | unsigned d; | ||
35 | unsigned base; | 34 | unsigned base; |
36 | 35 | ||
37 | num_digits = n = 0; | 36 | num_digits = n = 0; |
38 | base = 8; | 37 | base = 8; |
39 | q = *ptr; | 38 | q = *ptr; |
40 | 39 | ||
41 | #ifdef WANT_HEX_ESCAPES | 40 | #if WANT_HEX_ESCAPES |
42 | if (*q == 'x') { | 41 | if (*q == 'x') { |
43 | ++q; | 42 | ++q; |
44 | base = 16; | 43 | base = 16; |
@@ -50,20 +49,21 @@ char FAST_FUNC bb_process_escape_sequence(const char **ptr) | |||
50 | * \02 works, \2 does not (prints \ and 2). | 49 | * \02 works, \2 does not (prints \ and 2). |
51 | * We treat \2 as a valid octal escape sequence. */ | 50 | * We treat \2 as a valid octal escape sequence. */ |
52 | do { | 51 | do { |
53 | d = (unsigned char)(*q) - '0'; | 52 | #if !WANT_HEX_ESCAPES |
54 | #ifdef WANT_HEX_ESCAPES | 53 | unsigned d = (unsigned char)(*q) - '0'; |
55 | if (d >= 10) { | 54 | #else |
56 | d = (unsigned char)(_tolower(*q)) - 'a' + 10; | 55 | unsigned d = (unsigned char)_tolower(*q) - '0'; |
57 | } | 56 | if (d >= 10) |
57 | d += ('0' - 'a' + 10); | ||
58 | #endif | 58 | #endif |
59 | |||
60 | if (d >= base) { | 59 | if (d >= base) { |
61 | #ifdef WANT_HEX_ESCAPES | 60 | if (WANT_HEX_ESCAPES && base == 16) { |
62 | if ((base == 16) && (!--num_digits)) { | 61 | --num_digits; |
63 | /* return '\\'; */ | 62 | if (num_digits == 0) { |
64 | --q; | 63 | /* \x<bad_char> */ |
64 | --q; /* go back to x */ | ||
65 | } | ||
65 | } | 66 | } |
66 | #endif | ||
67 | break; | 67 | break; |
68 | } | 68 | } |
69 | 69 | ||
@@ -85,7 +85,9 @@ char FAST_FUNC bb_process_escape_sequence(const char **ptr) | |||
85 | } | 85 | } |
86 | } while (*++p); | 86 | } while (*++p); |
87 | /* p points to found escape char or NUL, | 87 | /* p points to found escape char or NUL, |
88 | * advance it and find what it translates to */ | 88 | * advance it and find what it translates to. |
89 | * Note that unrecognized sequence \z returns '\' | ||
90 | * and leaves ptr pointing to z. */ | ||
89 | p += sizeof(charmap) / 2; | 91 | p += sizeof(charmap) / 2; |
90 | n = *p; | 92 | n = *p; |
91 | } | 93 | } |
@@ -94,3 +96,17 @@ char FAST_FUNC bb_process_escape_sequence(const char **ptr) | |||
94 | 96 | ||
95 | return (char) n; | 97 | return (char) n; |
96 | } | 98 | } |
99 | |||
100 | char* FAST_FUNC strcpy_and_process_escape_sequences(char *dst, const char *src) | ||
101 | { | ||
102 | while (1) { | ||
103 | char c, c1; | ||
104 | c = c1 = *src++; | ||
105 | if (c1 == '\\') | ||
106 | c1 = bb_process_escape_sequence(&src); | ||
107 | *dst = c1; | ||
108 | if (c == '\0') | ||
109 | return dst; | ||
110 | dst++; | ||
111 | } | ||
112 | } | ||