diff options
author | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-04-09 22:48:12 +0000 |
---|---|---|
committer | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-04-09 22:48:12 +0000 |
commit | 88ea4d5576ceec648bff7f9bbf919fd3ecdff67b (patch) | |
tree | ef367ee8a9096884fb40debdc9e10af8583f9d5f /libbb/process_escape_sequence.c | |
parent | ada3b10c6a1ad210d6bf4078859792562636f27e (diff) | |
download | busybox-w32-88ea4d5576ceec648bff7f9bbf919fd3ecdff67b.tar.gz busybox-w32-88ea4d5576ceec648bff7f9bbf919fd3ecdff67b.tar.bz2 busybox-w32-88ea4d5576ceec648bff7f9bbf919fd3ecdff67b.zip |
Apply Vladimir's latest cleanup patch.
-Erik
git-svn-id: svn://busybox.net/trunk/busybox@2288 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb/process_escape_sequence.c')
-rw-r--r-- | libbb/process_escape_sequence.c | 73 |
1 files changed, 35 insertions, 38 deletions
diff --git a/libbb/process_escape_sequence.c b/libbb/process_escape_sequence.c index ad2be94ee..67b0490ce 100644 --- a/libbb/process_escape_sequence.c +++ b/libbb/process_escape_sequence.c | |||
@@ -2,9 +2,8 @@ | |||
2 | /* | 2 | /* |
3 | * Utility routines. | 3 | * Utility routines. |
4 | * | 4 | * |
5 | * Copyright (C) tons of folks. Tracking down who wrote what | 5 | * Copyright (C) Manuel Nova III <mnovoa3@bellsouth.net> |
6 | * isn't something I'm going to worry about... If you wrote something | 6 | * and Vladimir Oleynik <vodz@usa.net> |
7 | * here, please feel free to acknowledge your work. | ||
8 | * | 7 | * |
9 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
@@ -20,9 +19,7 @@ | |||
20 | * along with this program; if not, write to the Free Software | 19 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
22 | * | 21 | * |
23 | * Based in part on code from sash, Copyright (c) 1999 by David I. Bell | 22 | * |
24 | * Permission has been granted to redistribute this code under the GPL. | ||
25 | * | ||
26 | */ | 23 | */ |
27 | 24 | ||
28 | #include <stdio.h> | 25 | #include <stdio.h> |
@@ -31,45 +28,45 @@ | |||
31 | 28 | ||
32 | 29 | ||
33 | 30 | ||
34 | char process_escape_sequence(char **ptr) | 31 | char process_escape_sequence(const char **ptr) |
35 | { | 32 | { |
36 | static const char charmap[] = { | 33 | static const char charmap[] = { |
37 | 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', 0, | 34 | 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', 0, |
38 | '\a', '\b', '\f', '\n', '\r', '\t', '\v', '\\', '\\' }; | 35 | '\a', '\b', '\f', '\n', '\r', '\t', '\v', '\\', '\\' }; |
39 | |||
40 | const char *p; | ||
41 | char *q; | ||
42 | int num_digits; | ||
43 | unsigned int n; | ||
44 | 36 | ||
45 | n = 0; | 37 | const char *p; |
46 | q = *ptr; | 38 | const char *q; |
39 | int num_digits; | ||
40 | unsigned int n; | ||
41 | |||
42 | n = 0; | ||
43 | q = *ptr; | ||
47 | 44 | ||
48 | for ( num_digits = 0 ; num_digits < 3 ; ++num_digits) { | 45 | for ( num_digits = 0 ; num_digits < 3 ; ++num_digits) { |
49 | if ((*q < '0') || (*q > '7')) { /* not a digit? */ | 46 | if ((*q < '0') || (*q > '7')) { /* not a digit? */ |
50 | break; | 47 | break; |
51 | } | 48 | } |
52 | n = n * 8 + (*q++ - '0'); | 49 | n = n * 8 + (*q++ - '0'); |
53 | } | 50 | } |
54 | 51 | ||
55 | if (num_digits == 0) { /* mnemonic escape sequence? */ | 52 | if (num_digits == 0) { /* mnemonic escape sequence? */ |
56 | for (p=charmap ; *p ; p++) { | 53 | for (p=charmap ; *p ; p++) { |
57 | if (*p == *q) { | 54 | if (*p == *q) { |
58 | q++; | 55 | q++; |
59 | break; | 56 | break; |
60 | } | 57 | } |
61 | } | 58 | } |
62 | n = *(p+(sizeof(charmap)/2)); | 59 | n = *(p+(sizeof(charmap)/2)); |
63 | } | 60 | } |
64 | 61 | ||
65 | /* doesn't hurt to fall through to here from mnemonic case */ | 62 | /* doesn't hurt to fall through to here from mnemonic case */ |
66 | if (n > UCHAR_MAX) { /* is octal code too big for a char? */ | 63 | if (n > UCHAR_MAX) { /* is octal code too big for a char? */ |
67 | n /= 8; /* adjust value and */ | 64 | n /= 8; /* adjust value and */ |
68 | --q; /* back up one char */ | 65 | --q; /* back up one char */ |
69 | } | 66 | } |
70 | 67 | ||
71 | *ptr = q; | 68 | *ptr = q; |
72 | return (char) n; | 69 | return (char) n; |
73 | } | 70 | } |
74 | 71 | ||
75 | 72 | ||