aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorRichard Genoud <richard.genoud@gmail.com>2015-10-26 10:10:28 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2015-10-26 17:18:07 +0100
commitd683c5c2f1493c2b0856a5f8751508836b0988d5 (patch)
treeb9ba390323f272c76f7a316223a25c6b1760797e /coreutils
parent028524317d8d0011ed38e86e507a06738a5b5a97 (diff)
downloadbusybox-w32-d683c5c2f1493c2b0856a5f8751508836b0988d5.tar.gz
busybox-w32-d683c5c2f1493c2b0856a5f8751508836b0988d5.tar.bz2
busybox-w32-d683c5c2f1493c2b0856a5f8751508836b0988d5.zip
tr: support octal ranges
now, we can do printf "a\tb\tcdef\n" | ./busybox tr -d "\1-\14b-e" af and bonus, we save some bytes. function old new delta expand 718 699 -19 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-19) Total: -19 bytes Signed-off-by: Richard Genoud <richard.genoud@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/tr.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/coreutils/tr.c b/coreutils/tr.c
index e67948a36..2f49d5a86 100644
--- a/coreutils/tr.c
+++ b/coreutils/tr.c
@@ -91,7 +91,6 @@ static void map(char *pvector,
91 * Character classes, e.g. [:upper:] ==> A...Z 91 * Character classes, e.g. [:upper:] ==> A...Z
92 * Equiv classess, e.g. [=A=] ==> A (hmmmmmmm?) 92 * Equiv classess, e.g. [=A=] ==> A (hmmmmmmm?)
93 * not supported: 93 * not supported:
94 * \ooo-\ooo - octal ranges
95 * [x*N] - repeat char x N times 94 * [x*N] - repeat char x N times
96 * [x*] - repeat char x until it fills STRING2: 95 * [x*] - repeat char x until it fills STRING2:
97 * # echo qwe123 | /usr/bin/tr 123456789 '[d]' 96 * # echo qwe123 | /usr/bin/tr 123456789 '[d]'
@@ -99,7 +98,7 @@ static void map(char *pvector,
99 * # echo qwe123 | /usr/bin/tr 123456789 '[d*]' 98 * # echo qwe123 | /usr/bin/tr 123456789 '[d*]'
100 * qweddd 99 * qweddd
101 */ 100 */
102static unsigned expand(const char *arg, char **buffer_p) 101static unsigned expand(char *arg, char **buffer_p)
103{ 102{
104 char *buffer = *buffer_p; 103 char *buffer = *buffer_p;
105 unsigned pos = 0; 104 unsigned pos = 0;
@@ -113,9 +112,17 @@ static unsigned expand(const char *arg, char **buffer_p)
113 *buffer_p = buffer = xrealloc(buffer, size); 112 *buffer_p = buffer = xrealloc(buffer, size);
114 } 113 }
115 if (*arg == '\\') { 114 if (*arg == '\\') {
115 const char *z;
116 arg++; 116 arg++;
117 buffer[pos++] = bb_process_escape_sequence(&arg); 117 z = arg;
118 continue; 118 ac = bb_process_escape_sequence(&z);
119 arg = (char *)z;
120 arg--;
121 *arg = ac;
122 /*
123 * fall through, there may be a range.
124 * If not, current char will be treated anyway.
125 */
119 } 126 }
120 if (arg[1] == '-') { /* "0-9..." */ 127 if (arg[1] == '-') { /* "0-9..." */
121 ac = arg[2]; 128 ac = arg[2];
@@ -124,9 +131,15 @@ static unsigned expand(const char *arg, char **buffer_p)
124 continue; /* next iter will copy '-' and stop */ 131 continue; /* next iter will copy '-' and stop */
125 } 132 }
126 i = (unsigned char) *arg; 133 i = (unsigned char) *arg;
134 arg += 3; /* skip 0-9 or 0-\ */
135 if (ac == '\\') {
136 const char *z;
137 z = arg;
138 ac = bb_process_escape_sequence(&z);
139 arg = (char *)z;
140 }
127 while (i <= ac) /* ok: i is unsigned _int_ */ 141 while (i <= ac) /* ok: i is unsigned _int_ */
128 buffer[pos++] = i++; 142 buffer[pos++] = i++;
129 arg += 3; /* skip 0-9 */
130 continue; 143 continue;
131 } 144 }
132 if ((ENABLE_FEATURE_TR_CLASSES || ENABLE_FEATURE_TR_EQUIV) 145 if ((ENABLE_FEATURE_TR_CLASSES || ENABLE_FEATURE_TR_EQUIV)