20 |
{ |
{ |
21 |
/* bash builtin "echo -e '\ec'" interprets \e as ESC, |
/* bash builtin "echo -e '\ec'" interprets \e as ESC, |
22 |
* but coreutils "/bin/echo -e '\ec'" does not. |
* but coreutils "/bin/echo -e '\ec'" does not. |
23 |
* manpages tend to support coreutils way. */ |
* manpages tend to support coreutils way. |
24 |
|
* Update: coreutils added support for \e on 28 Oct 2009. */ |
25 |
static const char charmap[] ALIGN1 = { |
static const char charmap[] ALIGN1 = { |
26 |
'a', 'b', /*'e',*/ 'f', 'n', 'r', 't', 'v', '\\', 0, |
'a', 'b', 'e', 'f', 'n', 'r', 't', 'v', '\\', 0, |
27 |
'\a', '\b', /*27,*/ '\f', '\n', '\r', '\t', '\v', '\\', '\\' }; |
'\a', '\b', 27, '\f', '\n', '\r', '\t', '\v', '\\', '\\' }; |
28 |
|
|
29 |
const char *p; |
const char *p; |
30 |
const char *q; |
const char *q; |
46 |
} |
} |
47 |
#endif |
#endif |
48 |
|
|
49 |
|
/* bash requires leading 0 in octal escapes: |
50 |
|
* \02 works, \2 does not (prints \ and 2). |
51 |
|
* We treat \2 as a valid octal escape sequence. */ |
52 |
do { |
do { |
53 |
d = (unsigned char)(*q) - '0'; |
d = (unsigned char)(*q) - '0'; |
54 |
#ifdef WANT_HEX_ESCAPES |
#ifdef WANT_HEX_ESCAPES |
84 |
break; |
break; |
85 |
} |
} |
86 |
} while (*++p); |
} while (*++p); |
87 |
n = *(p + (sizeof(charmap)/2)); |
/* p points to found escape char or NUL, |
88 |
|
* advance it and find what it translates to */ |
89 |
|
p += sizeof(charmap) / 2; |
90 |
|
n = *p; |
91 |
} |
} |
92 |
|
|
93 |
*ptr = q; |
*ptr = q; |