Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 3 | * Mini tr implementation for busybox |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 4 | * |
Rob Landley | cd54528 | 2006-06-30 16:35:40 +0000 | [diff] [blame] | 5 | ** Copyright (c) 1987,1997, Prentice Hall All rights reserved. |
| 6 | * |
| 7 | * The name of Prentice Hall may not be used to endorse or promote |
| 8 | * products derived from this software without specific prior |
| 9 | * written permission. |
| 10 | * |
Erik Andersen | 5afc864 | 2000-05-02 00:07:56 +0000 | [diff] [blame] | 11 | * Copyright (c) Michiel Huisjes |
| 12 | * |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 13 | * This version of tr is adapted from Minix tr and was modified |
Eric Andersen | cb81e64 | 2003-07-14 21:21:08 +0000 | [diff] [blame] | 14 | * by Erik Andersen <andersen@codepoet.org> to be used in busybox. |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 15 | * |
Rob Landley | cd54528 | 2006-06-30 16:35:40 +0000 | [diff] [blame] | 16 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 17 | */ |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 18 | /* http://www.opengroup.org/onlinepubs/009695399/utilities/tr.html |
| 19 | * TODO: xdigit, graph, print |
| 20 | */ |
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 21 | #include "busybox.h" |
Erik Andersen | 330fd2b | 2000-05-19 05:35:19 +0000 | [diff] [blame] | 22 | |
Eric Andersen | 22ecf04 | 2001-07-02 17:32:40 +0000 | [diff] [blame] | 23 | #define ASCII 0377 |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 24 | |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 25 | #define TR_OPT_complement (1<<0) |
| 26 | #define TR_OPT_delete (1<<1) |
| 27 | #define TR_OPT_squeeze_reps (1<<2) |
Mark Whitley | 8b7a0d8 | 2001-05-24 21:31:09 +0000 | [diff] [blame] | 28 | /* some "globals" shared across this file */ |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 29 | /* these last are pointers to static buffers declared in tr_main */ |
Rob Landley | ab58d5c | 2006-06-30 19:04:09 +0000 | [diff] [blame] | 30 | static char *poutput, *pvector, *pinvec, *poutvec; |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 31 | |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 32 | static void ATTRIBUTE_NORETURN convert(const smalluint flags) |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 33 | { |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 34 | size_t read_chars = 0, in_index = 0, out_index = 0, c, coded, last = -1; |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 35 | |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 36 | for (;;) { |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 37 | /* If we're out of input, flush output and read more input. */ |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 38 | if (in_index == read_chars) { |
Rob Landley | cd54528 | 2006-06-30 16:35:40 +0000 | [diff] [blame] | 39 | if (out_index) { |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 40 | xwrite(STDOUT_FILENO, (char *)poutput, out_index); |
Rob Landley | cd54528 | 2006-06-30 16:35:40 +0000 | [diff] [blame] | 41 | out_index = 0; |
| 42 | } |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 43 | if ((read_chars = read(STDIN_FILENO, bb_common_bufsiz1, BUFSIZ)) <= 0) { |
| 44 | if (write(STDOUT_FILENO, (char *)poutput, out_index) != out_index) |
| 45 | bb_perror_msg(bb_msg_write_error); |
| 46 | exit(EXIT_SUCCESS); |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 47 | } |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 48 | in_index = 0; |
| 49 | } |
Rob Landley | cd54528 | 2006-06-30 16:35:40 +0000 | [diff] [blame] | 50 | c = bb_common_bufsiz1[in_index++]; |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 51 | coded = pvector[c]; |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 52 | if ((flags & TR_OPT_delete) && pinvec[c]) |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 53 | continue; |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 54 | if ((flags & TR_OPT_squeeze_reps) && last == coded && |
| 55 | (pinvec[c] || poutvec[coded])) |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 56 | continue; |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 57 | poutput[out_index++] = last = coded; |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 58 | } |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 59 | /* NOTREACHED */ |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 62 | static void map(unsigned char *string1, unsigned int string1_len, |
| 63 | unsigned char *string2, unsigned int string2_len) |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 64 | { |
Rob Landley | ab58d5c | 2006-06-30 19:04:09 +0000 | [diff] [blame] | 65 | char last = '0'; |
Eric Andersen | 00143ba | 2000-07-13 16:40:41 +0000 | [diff] [blame] | 66 | unsigned int i, j; |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 67 | |
Eric Andersen | 00143ba | 2000-07-13 16:40:41 +0000 | [diff] [blame] | 68 | for (j = 0, i = 0; i < string1_len; i++) { |
| 69 | if (string2_len <= j) |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 70 | pvector[string1[i]] = last; |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 71 | else |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 72 | pvector[string1[i]] = last = string2[j++]; |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | |
Mark Whitley | 8b7a0d8 | 2001-05-24 21:31:09 +0000 | [diff] [blame] | 76 | /* supported constructs: |
| 77 | * Ranges, e.g., [0-9] ==> 0123456789 |
| 78 | * Escapes, e.g., \a ==> Control-G |
Rob Landley | f104814 | 2005-10-08 21:21:08 +0000 | [diff] [blame] | 79 | * Character classes, e.g. [:upper:] ==> A ... Z |
Mark Whitley | 8b7a0d8 | 2001-05-24 21:31:09 +0000 | [diff] [blame] | 80 | */ |
Rob Landley | ab58d5c | 2006-06-30 19:04:09 +0000 | [diff] [blame] | 81 | static unsigned int expand(const char *arg, char *buffer) |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 82 | { |
Rob Landley | ab58d5c | 2006-06-30 19:04:09 +0000 | [diff] [blame] | 83 | char *buffer_start = buffer; |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 84 | unsigned i; /* XXX: FIXME: use unsigned char? */ |
| 85 | unsigned char ac; |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 86 | #define CLO ":]" |
Denis Vlasenko | 240a1cf | 2007-04-08 16:07:02 +0000 | [diff] [blame] | 87 | static const char * const classes[] = { |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 88 | "alpha"CLO, "alnum"CLO, "digit"CLO, "lower"CLO, "upper"CLO, "space"CLO, |
| 89 | "blank"CLO, "punct"CLO, "cntrl"CLO, NULL |
| 90 | }; |
| 91 | #define CLASS_invalid 0 /* we increment the retval */ |
| 92 | #define CLASS_alpha 1 |
| 93 | #define CLASS_alnum 2 |
| 94 | #define CLASS_digit 3 |
| 95 | #define CLASS_lower 4 |
| 96 | #define CLASS_upper 5 |
| 97 | #define CLASS_space 6 |
| 98 | #define CLASS_blank 7 |
| 99 | #define CLASS_punct 8 |
| 100 | #define CLASS_cntrl 9 |
| 101 | //#define CLASS_xdigit 10 |
| 102 | //#define CLASS_graph 11 |
| 103 | //#define CLASS_print 12 |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 104 | while (*arg) { |
| 105 | if (*arg == '\\') { |
| 106 | arg++; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 107 | *buffer++ = bb_process_escape_sequence(&arg); |
Eric Andersen | 5a4a46a | 2001-07-09 21:32:29 +0000 | [diff] [blame] | 108 | } else if (*(arg+1) == '-') { |
| 109 | ac = *(arg+2); |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 110 | if (ac == 0) { |
Eric Andersen | 5a4a46a | 2001-07-09 21:32:29 +0000 | [diff] [blame] | 111 | *buffer++ = *arg++; |
| 112 | continue; |
| 113 | } |
| 114 | i = *arg; |
| 115 | while (i <= ac) |
| 116 | *buffer++ = i++; |
| 117 | arg += 3; /* Skip the assumed a-z */ |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 118 | } else if (*arg == '[') { |
| 119 | arg++; |
Rob Landley | 998dbee | 2006-04-19 22:22:06 +0000 | [diff] [blame] | 120 | i = *arg++; |
| 121 | if (ENABLE_FEATURE_TR_CLASSES && i == ':') { |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 122 | smalluint j; |
| 123 | { /* not really pretty.. */ |
| 124 | char *tmp = xstrndup(arg, 7); // warning: xdigit needs 8, not 7 |
| 125 | j = index_in_str_array(classes, tmp) + 1; |
| 126 | free(tmp); |
Rob Landley | f104814 | 2005-10-08 21:21:08 +0000 | [diff] [blame] | 127 | } |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 128 | if (j == CLASS_alnum || j == CLASS_digit) { |
Rob Landley | 998dbee | 2006-04-19 22:22:06 +0000 | [diff] [blame] | 129 | for (i = '0'; i <= '9'; i++) |
| 130 | *buffer++ = i; |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 131 | } |
| 132 | if (j == CLASS_alpha || j == CLASS_alnum || j == CLASS_upper) { |
Rob Landley | f104814 | 2005-10-08 21:21:08 +0000 | [diff] [blame] | 133 | for (i = 'A'; i <= 'Z'; i++) |
| 134 | *buffer++ = i; |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 135 | } |
| 136 | if (j == CLASS_alpha || j == CLASS_alnum || j == CLASS_lower) { |
Rob Landley | f104814 | 2005-10-08 21:21:08 +0000 | [diff] [blame] | 137 | for (i = 'a'; i <= 'z'; i++) |
| 138 | *buffer++ = i; |
Rob Landley | f104814 | 2005-10-08 21:21:08 +0000 | [diff] [blame] | 139 | } |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 140 | if (j == CLASS_space || j == CLASS_blank) { |
Rob Landley | 998dbee | 2006-04-19 22:22:06 +0000 | [diff] [blame] | 141 | *buffer++ = '\t'; |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 142 | if (j == CLASS_space) { |
| 143 | *buffer++ = '\n'; |
| 144 | *buffer++ = '\v'; |
| 145 | *buffer++ = '\f'; |
| 146 | *buffer++ = '\r'; |
| 147 | } |
Rob Landley | 998dbee | 2006-04-19 22:22:06 +0000 | [diff] [blame] | 148 | *buffer++ = ' '; |
| 149 | } |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 150 | if (j == CLASS_punct || j == CLASS_cntrl) { |
Rob Landley | f104814 | 2005-10-08 21:21:08 +0000 | [diff] [blame] | 151 | for (i = 0; i <= ASCII; i++) |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 152 | if ((j == CLASS_punct && |
| 153 | isprint(i) && (!isalnum(i)) && (!isspace(i))) || |
| 154 | (j == CLASS_cntrl && iscntrl(i))) |
Rob Landley | f104814 | 2005-10-08 21:21:08 +0000 | [diff] [blame] | 155 | *buffer++ = i; |
| 156 | } |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 157 | if (j == CLASS_invalid) { |
Rob Landley | 998dbee | 2006-04-19 22:22:06 +0000 | [diff] [blame] | 158 | *buffer++ = '['; |
| 159 | *buffer++ = ':'; |
Rob Landley | f104814 | 2005-10-08 21:21:08 +0000 | [diff] [blame] | 160 | continue; |
| 161 | } |
| 162 | break; |
| 163 | } |
Rob Landley | 998dbee | 2006-04-19 22:22:06 +0000 | [diff] [blame] | 164 | if (ENABLE_FEATURE_TR_EQUIV && i == '=') { |
Rob Landley | f104814 | 2005-10-08 21:21:08 +0000 | [diff] [blame] | 165 | *buffer++ = *arg; |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 166 | arg += 3; /* Skip the closing =] */ |
Rob Landley | f104814 | 2005-10-08 21:21:08 +0000 | [diff] [blame] | 167 | continue; |
| 168 | } |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 169 | if (*arg++ != '-') { |
| 170 | *buffer++ = '['; |
| 171 | arg -= 2; |
| 172 | continue; |
| 173 | } |
| 174 | ac = *arg++; |
| 175 | while (i <= ac) |
| 176 | *buffer++ = i++; |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 177 | arg++; /* Skip the assumed ']' */ |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 178 | } else |
| 179 | *buffer++ = *arg++; |
| 180 | } |
Eric Andersen | 00143ba | 2000-07-13 16:40:41 +0000 | [diff] [blame] | 181 | return (buffer - buffer_start); |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Rob Landley | ab58d5c | 2006-06-30 19:04:09 +0000 | [diff] [blame] | 184 | static int complement(char *buffer, int buffer_len) |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 185 | { |
"Robert P. J. Day" | 6822983 | 2006-07-01 13:08:46 +0000 | [diff] [blame] | 186 | short i, j, ix; |
Eric Andersen | fad04fd | 2000-07-14 06:49:52 +0000 | [diff] [blame] | 187 | char conv[ASCII + 2]; |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 188 | |
Eric Andersen | 1ca20a7 | 2001-03-21 07:34:27 +0000 | [diff] [blame] | 189 | ix = 0; |
Eric Andersen | 00143ba | 2000-07-13 16:40:41 +0000 | [diff] [blame] | 190 | for (i = 0; i <= ASCII; i++) { |
| 191 | for (j = 0; j < buffer_len; j++) |
| 192 | if (buffer[j] == i) |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 193 | break; |
Eric Andersen | 00143ba | 2000-07-13 16:40:41 +0000 | [diff] [blame] | 194 | if (j == buffer_len) |
Eric Andersen | 1ca20a7 | 2001-03-21 07:34:27 +0000 | [diff] [blame] | 195 | conv[ix++] = i & ASCII; |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 196 | } |
Eric Andersen | 1ca20a7 | 2001-03-21 07:34:27 +0000 | [diff] [blame] | 197 | memcpy(buffer, conv, ix); |
| 198 | return ix; |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Denis Vlasenko | 06af216 | 2007-02-03 17:28:39 +0000 | [diff] [blame] | 201 | int tr_main(int argc, char **argv); |
Rob Landley | dfba741 | 2006-03-06 20:47:33 +0000 | [diff] [blame] | 202 | int tr_main(int argc, char **argv) |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 203 | { |
"Robert P. J. Day" | 6822983 | 2006-07-01 13:08:46 +0000 | [diff] [blame] | 204 | unsigned char *ptr; |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 205 | int output_length = 0, input_length; |
Eric Andersen | f6aa13d | 2001-03-23 17:08:21 +0000 | [diff] [blame] | 206 | int idx = 1; |
Eric Andersen | fad04fd | 2000-07-14 06:49:52 +0000 | [diff] [blame] | 207 | int i; |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 208 | smalluint flags = 0; |
| 209 | RESERVE_CONFIG_UBUFFER(output, BUFSIZ); |
Rob Landley | 998f449 | 2006-04-10 16:40:47 +0000 | [diff] [blame] | 210 | RESERVE_CONFIG_BUFFER(vector, ASCII+1); |
Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 211 | RESERVE_CONFIG_BUFFER(invec, ASCII+1); |
| 212 | RESERVE_CONFIG_BUFFER(outvec, ASCII+1); |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 213 | |
| 214 | /* ... but make them available globally */ |
Rob Landley | ab58d5c | 2006-06-30 19:04:09 +0000 | [diff] [blame] | 215 | poutput = output; |
| 216 | pvector = vector; |
| 217 | pinvec = invec; |
| 218 | poutvec = outvec; |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 219 | |
Eric Andersen | f6aa13d | 2001-03-23 17:08:21 +0000 | [diff] [blame] | 220 | if (argc > 1 && argv[idx][0] == '-') { |
| 221 | for (ptr = (unsigned char *) &argv[idx][1]; *ptr; ptr++) { |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 222 | if (*ptr == 'c') |
| 223 | flags |= TR_OPT_complement; |
| 224 | else if (*ptr == 'd') |
| 225 | flags |= TR_OPT_delete; |
| 226 | else if (*ptr == 's') |
| 227 | flags |= TR_OPT_squeeze_reps; |
| 228 | else |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 229 | bb_show_usage(); |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 230 | } |
Eric Andersen | f6aa13d | 2001-03-23 17:08:21 +0000 | [diff] [blame] | 231 | idx++; |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 232 | } |
| 233 | for (i = 0; i <= ASCII; i++) { |
| 234 | vector[i] = i; |
| 235 | invec[i] = outvec[i] = FALSE; |
| 236 | } |
| 237 | |
Eric Andersen | f6aa13d | 2001-03-23 17:08:21 +0000 | [diff] [blame] | 238 | if (argv[idx] != NULL) { |
Rob Landley | cd54528 | 2006-06-30 16:35:40 +0000 | [diff] [blame] | 239 | input_length = expand(argv[idx++], bb_common_bufsiz1); |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 240 | if (flags & TR_OPT_complement) |
Rob Landley | cd54528 | 2006-06-30 16:35:40 +0000 | [diff] [blame] | 241 | input_length = complement(bb_common_bufsiz1, input_length); |
Eric Andersen | f6aa13d | 2001-03-23 17:08:21 +0000 | [diff] [blame] | 242 | if (argv[idx] != NULL) { |
| 243 | if (*argv[idx] == '\0') |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 244 | bb_error_msg_and_die("STRING2 cannot be empty"); |
Rob Landley | ab58d5c | 2006-06-30 19:04:09 +0000 | [diff] [blame] | 245 | output_length = expand(argv[idx], output); |
| 246 | map(bb_common_bufsiz1, input_length, output, output_length); |
Eric Andersen | a03d86c | 2000-07-10 16:38:50 +0000 | [diff] [blame] | 247 | } |
Eric Andersen | 00143ba | 2000-07-13 16:40:41 +0000 | [diff] [blame] | 248 | for (i = 0; i < input_length; i++) |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 249 | invec[(unsigned char)bb_common_bufsiz1[i]] = TRUE; |
Eric Andersen | 00143ba | 2000-07-13 16:40:41 +0000 | [diff] [blame] | 250 | for (i = 0; i < output_length; i++) |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 251 | outvec[output[i]] = TRUE; |
Erik Andersen | 8f8d6d5 | 2000-05-01 22:30:37 +0000 | [diff] [blame] | 252 | } |
Bernhard Reutner-Fischer | eceecea | 2007-03-30 14:43:27 +0000 | [diff] [blame] | 253 | convert(flags); |
| 254 | return EXIT_SUCCESS; |
Erik Andersen | fb002d0 | 2000-03-05 08:07:00 +0000 | [diff] [blame] | 255 | } |