aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-06-15 10:18:01 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-06-15 10:18:01 +0200
commit237aecedabb05abb199018c1e08b645b594bbff9 (patch)
tree6d3fc373517dff3d7f84d73aacb91b0032573203
parentf7e929e795c433014f76e4be808776e6dc968cbc (diff)
downloadbusybox-w32-237aecedabb05abb199018c1e08b645b594bbff9.tar.gz
busybox-w32-237aecedabb05abb199018c1e08b645b594bbff9.tar.bz2
busybox-w32-237aecedabb05abb199018c1e08b645b594bbff9.zip
xargs: another code shrink
function old new delta process0_stdin 117 103 -14 process_stdin 336 314 -22 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--findutils/xargs.c50
1 files changed, 20 insertions, 30 deletions
diff --git a/findutils/xargs.c b/findutils/xargs.c
index d9f8a3b18..8caaff91c 100644
--- a/findutils/xargs.c
+++ b/findutils/xargs.c
@@ -18,7 +18,7 @@
18 */ 18 */
19 19
20//kbuild:lib-$(CONFIG_XARGS) += xargs.o 20//kbuild:lib-$(CONFIG_XARGS) += xargs.o
21//config: 21
22//config:config XARGS 22//config:config XARGS
23//config: bool "xargs" 23//config: bool "xargs"
24//config: default y 24//config: default y
@@ -161,13 +161,12 @@ static char* FAST_FUNC process_stdin(int n_max_chars, int n_max_arg, char *buf)
161#define QUOTE 1 161#define QUOTE 1
162#define BACKSLASH 2 162#define BACKSLASH 2
163#define SPACE 4 163#define SPACE 4
164 char *s; /* start of the word */ 164 char q = '\0'; /* quote char */
165 char *p; /* pointer to end of the word */
166 char q = '\0'; /* quote char */
167 char state = NORM; 165 char state = NORM;
166 char *s = buf; /* start of the word */
167 char *p = s + strlen(buf); /* end of the word */
168 168
169 s = buf; 169 buf += n_max_chars; /* past buffer's end */
170 p = s + strlen(buf);
171 170
172 /* "goto ret" is used instead of "break" to make control flow 171 /* "goto ret" is used instead of "break" to make control flow
173 * more obvious: */ 172 * more obvious: */
@@ -224,17 +223,14 @@ static char* FAST_FUNC process_stdin(int n_max_chars, int n_max_arg, char *buf)
224 } 223 }
225 store_param(s); 224 store_param(s);
226 dbg_msg("args[]:'%s'", s); 225 dbg_msg("args[]:'%s'", s);
227 n_max_chars -= (p - s);
228 /* if (n_max_chars < 0) impossible */
229 s = p; 226 s = p;
230 n_max_arg--; 227 n_max_arg--;
231 if (n_max_arg == 0 || n_max_chars == 0) { 228 if (n_max_arg == 0) {
232 goto ret; 229 goto ret;
233 } 230 }
234 state = NORM; 231 state = NORM;
235 } else /* state != SPACE */ 232 }
236 if (p - s >= n_max_chars) { 233 if (p == buf) {
237 dbg_msg("s:'%s' p-s:%d n_max_chars:%d", s, (int)(p-s), n_max_chars);
238 goto ret; 234 goto ret;
239 } 235 }
240 } 236 }
@@ -248,11 +244,10 @@ static char* FAST_FUNC process_stdin(int n_max_chars, int n_max_arg, char *buf)
248/* The variant does not support single quotes, double quotes or backslash */ 244/* The variant does not support single quotes, double quotes or backslash */
249static char* FAST_FUNC process_stdin(int n_max_chars, int n_max_arg, char *buf) 245static char* FAST_FUNC process_stdin(int n_max_chars, int n_max_arg, char *buf)
250{ 246{
251 char *s; /* start of the word */ 247 char *s = buf; /* start of the word */
252 char *p; /* pointer to end of the word */ 248 char *p = s + strlen(buf); /* end of the word */
253 249
254 s = buf; 250 buf += n_max_chars; /* past buffer's end */
255 p = s + strlen(buf);
256 251
257 while (1) { 252 while (1) {
258 int c = getchar(); 253 int c = getchar();
@@ -278,15 +273,13 @@ static char* FAST_FUNC process_stdin(int n_max_chars, int n_max_arg, char *buf)
278 } 273 }
279 store_param(s); 274 store_param(s);
280 dbg_msg("args[]:'%s'", s); 275 dbg_msg("args[]:'%s'", s);
281 n_max_chars -= (p - s);
282 /* if (n_max_chars < 0) impossible */
283 s = p; 276 s = p;
284 n_max_arg--; 277 n_max_arg--;
285 if (n_max_arg == 0 || n_max_chars == 0) { 278 if (n_max_arg == 0) {
286 goto ret; 279 goto ret;
287 } 280 }
288 } else /* c != EOF */ 281 }
289 if (p - s >= n_max_chars) { 282 if (p == buf) {
290 goto ret; 283 goto ret;
291 } 284 }
292 } 285 }
@@ -301,11 +294,10 @@ static char* FAST_FUNC process_stdin(int n_max_chars, int n_max_arg, char *buf)
301#if ENABLE_FEATURE_XARGS_SUPPORT_ZERO_TERM 294#if ENABLE_FEATURE_XARGS_SUPPORT_ZERO_TERM
302static char* FAST_FUNC process0_stdin(int n_max_chars, int n_max_arg, char *buf) 295static char* FAST_FUNC process0_stdin(int n_max_chars, int n_max_arg, char *buf)
303{ 296{
304 char *s; /* start of the word */ 297 char *s = buf; /* start of the word */
305 char *p; /* pointer to end of the word */ 298 char *p = s + strlen(buf); /* end of the word */
306 299
307 s = buf; 300 buf += n_max_chars; /* past buffer's end */
308 p = s + strlen(buf);
309 301
310 while (1) { 302 while (1) {
311 int c = getchar(); 303 int c = getchar();
@@ -319,15 +311,13 @@ static char* FAST_FUNC process0_stdin(int n_max_chars, int n_max_arg, char *buf)
319 /* A full word is loaded */ 311 /* A full word is loaded */
320 store_param(s); 312 store_param(s);
321 dbg_msg("args[]:'%s'", s); 313 dbg_msg("args[]:'%s'", s);
322 n_max_chars -= (p - s);
323 /* if (n_max_chars < 0) impossible */
324 s = p; 314 s = p;
325 n_max_arg--; 315 n_max_arg--;
326 if (n_max_arg == 0 || n_max_chars == 0) { 316 if (n_max_arg == 0) {
327 goto ret; 317 goto ret;
328 } 318 }
329 } else /* c != '\0' */ 319 }
330 if (p - s >= n_max_chars) { 320 if (p == buf) {
331 goto ret; 321 goto ret;
332 } 322 }
333 } 323 }