aboutsummaryrefslogtreecommitdiff
path: root/libbb/process_escape_sequence.c
diff options
context:
space:
mode:
authormjn3 <mjn3@69ca8d6d-28ef-0310-b511-8ec308f3f277>2003-03-19 09:13:01 +0000
committermjn3 <mjn3@69ca8d6d-28ef-0310-b511-8ec308f3f277>2003-03-19 09:13:01 +0000
commite901c15d890dbbdce4c086963cb1513653fc46b5 (patch)
treea318d0f03aa076c74b576ea45dc543a5669e8e91 /libbb/process_escape_sequence.c
parent40758c00616c3b2c85d83eb4afdeb04b1f65c9f1 (diff)
downloadbusybox-w32-e901c15d890dbbdce4c086963cb1513653fc46b5.tar.gz
busybox-w32-e901c15d890dbbdce4c086963cb1513653fc46b5.tar.bz2
busybox-w32-e901c15d890dbbdce4c086963cb1513653fc46b5.zip
Major coreutils update.
git-svn-id: svn://busybox.net/trunk/busybox@6751 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb/process_escape_sequence.c')
-rw-r--r--libbb/process_escape_sequence.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/libbb/process_escape_sequence.c b/libbb/process_escape_sequence.c
index 9a16f80ab..ef2717bdd 100644
--- a/libbb/process_escape_sequence.c
+++ b/libbb/process_escape_sequence.c
@@ -2,7 +2,7 @@
2/* 2/*
3 * Utility routines. 3 * Utility routines.
4 * 4 *
5 * Copyright (C) Manuel Nova III <mnovoa3@bellsouth.net> 5 * Copyright (C) Manuel Novoa III <mjn3@codepoet.org>
6 * and Vladimir Oleynik <dzo@simtreas.ru> 6 * and Vladimir Oleynik <dzo@simtreas.ru>
7 * 7 *
8 * 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
@@ -26,9 +26,7 @@
26#include <limits.h> 26#include <limits.h>
27#include "libbb.h" 27#include "libbb.h"
28 28
29 29char bb_process_escape_sequence(const char **ptr)
30
31char process_escape_sequence(const char **ptr)
32{ 30{
33 static const char charmap[] = { 31 static const char charmap[] = {
34 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', 0, 32 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', 0,
@@ -36,40 +34,43 @@ char process_escape_sequence(const char **ptr)
36 34
37 const char *p; 35 const char *p;
38 const char *q; 36 const char *q;
39 int num_digits; 37 unsigned int num_digits;
38 unsigned int r;
40 unsigned int n; 39 unsigned int n;
41 40
42 n = 0; 41 n = 0;
43 q = *ptr; 42 q = *ptr;
44 43
45 for ( num_digits = 0 ; num_digits < 3 ; ++num_digits) { 44 num_digits = 0;
46 if ((*q < '0') || (*q > '7')) { /* not a digit? */ 45 do {
47 break; 46 if (((unsigned int)(*q - '0')) <= 7) {
47 r = n * 8 + (*q - '0');
48 if (r <= UCHAR_MAX) {
49 n = r;
50 ++q;
51 if (++num_digits < 3) {
52 continue;
53 }
54 }
48 } 55 }
49 n = n * 8 + (*q++ - '0'); 56 break;
50 } 57 } while (1);
51 58
52 if (num_digits == 0) { /* mnemonic escape sequence? */ 59 if (num_digits == 0) { /* mnemonic escape sequence? */
53 for (p=charmap ; *p ; p++) { 60 p = charmap;
61 do {
54 if (*p == *q) { 62 if (*p == *q) {
55 q++; 63 q++;
56 break; 64 break;
57 } 65 }
58 } 66 } while (*++p);
59 n = *(p+(sizeof(charmap)/2)); 67 n = *(p+(sizeof(charmap)/2));
60 } 68 }
61 69
62 /* doesn't hurt to fall through to here from mnemonic case */
63 if (n > UCHAR_MAX) { /* is octal code too big for a char? */
64 n /= 8; /* adjust value and */
65 --q; /* back up one char */
66 }
67
68 *ptr = q; 70 *ptr = q;
69 return (char) n; 71 return (char) n;
70} 72}
71 73
72
73/* END CODE */ 74/* END CODE */
74/* 75/*
75Local Variables: 76Local Variables: