Last change
on this file since 1333 was 821, checked in by Bruno Cornec, 19 years ago |
Addition of busybox 1.2.1 as a mindi-busybox new package
This should avoid delivering binary files in mindi not built there (Fedora and Debian are quite serious about that)
|
File size:
1.5 KB
|
Line | |
---|
1 | /* vi: set sw=4 ts=4: */
|
---|
2 | /*
|
---|
3 | * Utility routines.
|
---|
4 | *
|
---|
5 | * Copyright (C) Manuel Novoa III <mjn3@codepoet.org>
|
---|
6 | * and Vladimir Oleynik <dzo@simtreas.ru>
|
---|
7 | *
|
---|
8 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
---|
9 | */
|
---|
10 |
|
---|
11 | #include <stdio.h>
|
---|
12 | #include <limits.h>
|
---|
13 | #include <ctype.h>
|
---|
14 | #include "libbb.h"
|
---|
15 |
|
---|
16 | #define WANT_HEX_ESCAPES 1
|
---|
17 |
|
---|
18 | /* Usual "this only works for ascii compatible encodings" disclaimer. */
|
---|
19 | #undef _tolower
|
---|
20 | #define _tolower(X) ((X)|((char) 0x20))
|
---|
21 |
|
---|
22 | char bb_process_escape_sequence(const char **ptr)
|
---|
23 | {
|
---|
24 | static const char charmap[] = {
|
---|
25 | 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', 0,
|
---|
26 | '\a', '\b', '\f', '\n', '\r', '\t', '\v', '\\', '\\' };
|
---|
27 |
|
---|
28 | const char *p;
|
---|
29 | const char *q;
|
---|
30 | unsigned int num_digits;
|
---|
31 | unsigned int r;
|
---|
32 | unsigned int n;
|
---|
33 | unsigned int d;
|
---|
34 | unsigned int base;
|
---|
35 |
|
---|
36 | num_digits = n = 0;
|
---|
37 | base = 8;
|
---|
38 | q = *ptr;
|
---|
39 |
|
---|
40 | #ifdef WANT_HEX_ESCAPES
|
---|
41 | if (*q == 'x') {
|
---|
42 | ++q;
|
---|
43 | base = 16;
|
---|
44 | ++num_digits;
|
---|
45 | }
|
---|
46 | #endif
|
---|
47 |
|
---|
48 | do {
|
---|
49 | d = (unsigned int)(*q - '0');
|
---|
50 | #ifdef WANT_HEX_ESCAPES
|
---|
51 | if (d >= 10) {
|
---|
52 | d = ((unsigned int)(_tolower(*q) - 'a')) + 10;
|
---|
53 | }
|
---|
54 | #endif
|
---|
55 |
|
---|
56 | if (d >= base) {
|
---|
57 | #ifdef WANT_HEX_ESCAPES
|
---|
58 | if ((base == 16) && (!--num_digits)) {
|
---|
59 | /* return '\\'; */
|
---|
60 | --q;
|
---|
61 | }
|
---|
62 | #endif
|
---|
63 | break;
|
---|
64 | }
|
---|
65 |
|
---|
66 | r = n * base + d;
|
---|
67 | if (r > UCHAR_MAX) {
|
---|
68 | break;
|
---|
69 | }
|
---|
70 |
|
---|
71 | n = r;
|
---|
72 | ++q;
|
---|
73 | } while (++num_digits < 3);
|
---|
74 |
|
---|
75 | if (num_digits == 0) { /* mnemonic escape sequence? */
|
---|
76 | p = charmap;
|
---|
77 | do {
|
---|
78 | if (*p == *q) {
|
---|
79 | q++;
|
---|
80 | break;
|
---|
81 | }
|
---|
82 | } while (*++p);
|
---|
83 | n = *(p+(sizeof(charmap)/2));
|
---|
84 | }
|
---|
85 |
|
---|
86 | *ptr = q;
|
---|
87 |
|
---|
88 | return (char) n;
|
---|
89 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.