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
48 /* bash requires leading 0 in octal escapes:
49 * \02 works, \2 does not (prints \ and 2).
50 * We treat \2 as a valid octal escape sequence. */
52 d = (unsigned char)(*q) - '0';
53 #ifdef WANT_HEX_ESCAPES
55 d = (unsigned char)(_tolower(*q)) - 'a' + 10;
60 #ifdef WANT_HEX_ESCAPES
61 if ((base == 16) && (!--num_digits)) {
76 } while (++num_digits < 3);
78 if (num_digits == 0) { /* mnemonic escape sequence? */
86 /* p points to found escape char or NUL,
87 * advance it and find what it translates to */
88 p += sizeof(charmap) / 2;