Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/libbb/process_escape_sequence.c

    r1765 r2725  
    66 * and Vladimir Oleynik <dzo@simtreas.ru>
    77 *
    8  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     8 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    99 */
    1010
     
    1717#define _tolower(X) ((X)|((char) 0x20))
    1818
    19 char bb_process_escape_sequence(const char **ptr)
     19char FAST_FUNC bb_process_escape_sequence(const char **ptr)
    2020{
    21     static const char charmap[] ALIGN1 = {
    22         'a',  'b',  'f',  'n',  'r',  't',  'v',  '\\', 0,
    23         '\a', '\b', '\f', '\n', '\r', '\t', '\v', '\\', '\\' };
    24 
    25     const char *p;
    2621    const char *q;
    27     unsigned int num_digits;
    28     unsigned int r;
    29     unsigned int n;
    30     unsigned int d;
    31     unsigned int base;
     22    unsigned num_digits;
     23    unsigned n;
     24    unsigned base;
    3225
    3326    num_digits = n = 0;
     
    3528    q = *ptr;
    3629
    37 #ifdef WANT_HEX_ESCAPES
    38     if (*q == 'x') {
     30    if (WANT_HEX_ESCAPES && *q == 'x') {
    3931        ++q;
    4032        base = 16;
    4133        ++num_digits;
    4234    }
     35
     36    /* bash requires leading 0 in octal escapes:
     37     * \02 works, \2 does not (prints \ and 2).
     38     * We treat \2 as a valid octal escape sequence. */
     39    do {
     40        unsigned r;
     41#if !WANT_HEX_ESCAPES
     42        unsigned d = (unsigned char)(*q) - '0';
     43#else
     44        unsigned d = (unsigned char)_tolower(*q) - '0';
     45        if (d >= 10)
     46            d += ('0' - 'a' + 10);
    4347#endif
    44 
    45     do {
    46         d = (unsigned char)(*q) - '0';
    47 #ifdef WANT_HEX_ESCAPES
    48         if (d >= 10) {
    49             d = (unsigned char)(_tolower(*q)) - 'a' + 10;
    50         }
    51 #endif
    52 
    5348        if (d >= base) {
    54 #ifdef WANT_HEX_ESCAPES
    55             if ((base == 16) && (!--num_digits)) {
    56 /*              return '\\'; */
    57                 --q;
     49            if (WANT_HEX_ESCAPES && base == 16) {
     50                --num_digits;
     51                if (num_digits == 0) {
     52                    /* \x<bad_char>: return '\',
     53                     * leave ptr pointing to x */
     54                    return '\\';
     55                }
    5856            }
    59 #endif
    6057            break;
    6158        }
     
    7067    } while (++num_digits < 3);
    7168
    72     if (num_digits == 0) {  /* mnemonic escape sequence? */
    73         p = charmap;
     69    if (num_digits == 0) {
     70        /* Not octal or hex escape sequence.
     71         * Is it one-letter one? */
     72
     73        /* bash builtin "echo -e '\ec'" interprets \e as ESC,
     74         * but coreutils "/bin/echo -e '\ec'" does not.
     75         * Manpages tend to support coreutils way.
     76         * Update: coreutils added support for \e on 28 Oct 2009. */
     77        static const char charmap[] ALIGN1 = {
     78            'a',  'b', 'e', 'f',  'n',  'r',  't',  'v',  '\\', '\0',
     79            '\a', '\b', 27, '\f', '\n', '\r', '\t', '\v', '\\', '\\',
     80        };
     81        const char *p = charmap;
    7482        do {
    7583            if (*p == *q) {
     
    7785                break;
    7886            }
    79         } while (*++p);
    80         n = *(p + (sizeof(charmap)/2));
     87        } while (*++p != '\0');
     88        /* p points to found escape char or NUL,
     89         * advance it and find what it translates to.
     90         * Note that \NUL and unrecognized sequence \z return '\'
     91         * and leave ptr pointing to NUL or z. */
     92        n = p[sizeof(charmap) / 2];
    8193    }
    8294
     
    8597    return (char) n;
    8698}
     99
     100char* 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}
Note: See TracChangeset for help on using the changeset viewer.