1 /* vi: set sw=4 ts=4: */
5 * Copyright (C) Manuel Novoa III <mjn3@codepoet.org>
6 * and Vladimir Oleynik <dzo@simtreas.ru>
8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
13 #define WANT_HEX_ESCAPES 1
15 /* Usual "this only works for ascii compatible encodings" disclaimer. */
17 #define _tolower(X) ((X)|((char) 0x20))
19 char FAST_FUNC bb_process_escape_sequence(const char **ptr)
21 /* bash builtin "echo -e '\ec'" interprets \e as ESC,
22 * but coreutils "/bin/echo -e '\ec'" does not.
23 * manpages tend to support coreutils way. */
24 static const char charmap[] ALIGN1 = {
25 'a', 'b', /*'e',*/ 'f', 'n', 'r', 't', 'v', '\\', 0,
26 '\a', '\b', /*27,*/ '\f', '\n', '\r', '\t', '\v', '\\', '\\' };
40 #ifdef WANT_HEX_ESCAPES
49 d = (unsigned char)(*q) - '0';
50 #ifdef WANT_HEX_ESCAPES
52 d = (unsigned char)(_tolower(*q)) - 'a' + 10;
57 #ifdef WANT_HEX_ESCAPES
58 if ((base == 16) && (!--num_digits)) {
73 } while (++num_digits < 3);
75 if (num_digits == 0) { /* mnemonic escape sequence? */
83 n = *(p + (sizeof(charmap)/2));