diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-14 13:57:26 +1000 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-14 13:57:26 +1000 |
commit | 0c9d2455301ed633826e222aacd930126990913e (patch) | |
tree | 2353a480f55dfa41d9e6d2fa328af1b60dd3653e /findutils | |
parent | e8db4fe96b3a68b6f971d88084ef2fd2c8513e78 (diff) | |
parent | 9dc04124d5a3f0c9be249287817a964691e187b0 (diff) | |
download | busybox-w32-0c9d2455301ed633826e222aacd930126990913e.tar.gz busybox-w32-0c9d2455301ed633826e222aacd930126990913e.tar.bz2 busybox-w32-0c9d2455301ed633826e222aacd930126990913e.zip |
Merge branch 'origin/master' (early part)
Diffstat (limited to 'findutils')
-rw-r--r-- | findutils/Kbuild.src | 2 | ||||
-rw-r--r-- | findutils/find.c | 26 | ||||
-rw-r--r-- | findutils/grep.c | 12 | ||||
-rw-r--r-- | findutils/xargs.c | 2 |
4 files changed, 25 insertions, 17 deletions
diff --git a/findutils/Kbuild.src b/findutils/Kbuild.src index 771789ff5..6b4fb7470 100644 --- a/findutils/Kbuild.src +++ b/findutils/Kbuild.src | |||
@@ -2,7 +2,7 @@ | |||
2 | # | 2 | # |
3 | # Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org> | 3 | # Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org> |
4 | # | 4 | # |
5 | # Licensed under the GPL v2, see the file LICENSE in this tarball. | 5 | # Licensed under GPLv2, see file LICENSE in this source tree. |
6 | 6 | ||
7 | lib-y:= | 7 | lib-y:= |
8 | 8 | ||
diff --git a/findutils/find.c b/findutils/find.c index d4bcd6545..dd00f37ea 100644 --- a/findutils/find.c +++ b/findutils/find.c | |||
@@ -7,7 +7,7 @@ | |||
7 | * Reworked by David Douthitt <n9ubh@callsign.net> and | 7 | * Reworked by David Douthitt <n9ubh@callsign.net> and |
8 | * Matt Kraai <kraai@alumni.carnegiemellon.edu>. | 8 | * Matt Kraai <kraai@alumni.carnegiemellon.edu>. |
9 | * | 9 | * |
10 | * Licensed under the GPL version 2, see the file LICENSE in this tarball. | 10 | * Licensed under GPLv2, see file LICENSE in this source tree. |
11 | */ | 11 | */ |
12 | 12 | ||
13 | /* findutils-4.1.20: | 13 | /* findutils-4.1.20: |
@@ -748,13 +748,13 @@ static action*** parse_params(char **argv) | |||
748 | 748 | ||
749 | /* This is the only place in busybox where we use nested function. | 749 | /* This is the only place in busybox where we use nested function. |
750 | * So far more standard alternatives were bigger. */ | 750 | * So far more standard alternatives were bigger. */ |
751 | /* Suppress a warning "func without a prototype" */ | 751 | /* Auto decl suppresses "func without a prototype" warning: */ |
752 | auto action* alloc_action(int sizeof_struct, action_fp f); | 752 | auto action* alloc_action(int sizeof_struct, action_fp f); |
753 | action* alloc_action(int sizeof_struct, action_fp f) | 753 | action* alloc_action(int sizeof_struct, action_fp f) |
754 | { | 754 | { |
755 | action *ap; | 755 | action *ap; |
756 | appp[cur_group] = xrealloc(appp[cur_group], (cur_action+2) * sizeof(*appp)); | 756 | appp[cur_group] = xrealloc(appp[cur_group], (cur_action+2) * sizeof(*appp)); |
757 | appp[cur_group][cur_action++] = ap = xmalloc(sizeof_struct); | 757 | appp[cur_group][cur_action++] = ap = xzalloc(sizeof_struct); |
758 | appp[cur_group][cur_action] = NULL; | 758 | appp[cur_group][cur_action] = NULL; |
759 | ap->f = f; | 759 | ap->f = f; |
760 | IF_FEATURE_FIND_NOT( ap->invert = invert_flag; ) | 760 | IF_FEATURE_FIND_NOT( ap->invert = invert_flag; ) |
@@ -854,16 +854,20 @@ static action*** parse_params(char **argv) | |||
854 | IF_FEATURE_FIND_NOT( invert_flag = 0; ) | 854 | IF_FEATURE_FIND_NOT( invert_flag = 0; ) |
855 | ap = ALLOC_ACTION(exec); | 855 | ap = ALLOC_ACTION(exec); |
856 | ap->exec_argv = ++argv; /* first arg after -exec */ | 856 | ap->exec_argv = ++argv; /* first arg after -exec */ |
857 | ap->exec_argc = 0; | 857 | /*ap->exec_argc = 0; - ALLOC_ACTION did it */ |
858 | while (1) { | 858 | while (1) { |
859 | if (!*argv) /* did not see ';' or '+' until end */ | 859 | if (!*argv) /* did not see ';' or '+' until end */ |
860 | bb_error_msg_and_die(bb_msg_requires_arg, "-exec"); | 860 | bb_error_msg_and_die(bb_msg_requires_arg, "-exec"); |
861 | if (LONE_CHAR(argv[0], ';')) | 861 | // find -exec echo Foo ">{}<" ";" |
862 | // executes "echo Foo <filename>", | ||
863 | // find -exec echo Foo ">{}<" "+" | ||
864 | // executes "echo Foo <filename1> <filename2> <filename3>...". | ||
865 | // TODO (so far we treat "+" just like ";") | ||
866 | if ((argv[0][0] == ';' || argv[0][0] == '+') | ||
867 | && argv[0][1] == '\0' | ||
868 | ) { | ||
862 | break; | 869 | break; |
863 | //TODO: implement {} + (like xargs) | 870 | } |
864 | // See: | ||
865 | // find findutils/ -exec echo ">"{}"<" \; | ||
866 | // find findutils/ -exec echo ">"{}"<" + | ||
867 | argv++; | 871 | argv++; |
868 | ap->exec_argc++; | 872 | ap->exec_argc++; |
869 | } | 873 | } |
@@ -936,7 +940,7 @@ static action*** parse_params(char **argv) | |||
936 | ap = ALLOC_ACTION(perm); | 940 | ap = ALLOC_ACTION(perm); |
937 | ap->perm_char = arg1[0]; | 941 | ap->perm_char = arg1[0]; |
938 | arg1 = plus_minus_num(arg1); | 942 | arg1 = plus_minus_num(arg1); |
939 | ap->perm_mask = 0; | 943 | /*ap->perm_mask = 0; - ALLOC_ACTION did it */ |
940 | if (!bb_parse_mode(arg1, &ap->perm_mask)) | 944 | if (!bb_parse_mode(arg1, &ap->perm_mask)) |
941 | bb_error_msg_and_die("invalid mode '%s'", arg1); | 945 | bb_error_msg_and_die("invalid mode '%s'", arg1); |
942 | } | 946 | } |
@@ -1022,7 +1026,7 @@ static action*** parse_params(char **argv) | |||
1022 | else if (parm == PARM_context) { | 1026 | else if (parm == PARM_context) { |
1023 | action_context *ap; | 1027 | action_context *ap; |
1024 | ap = ALLOC_ACTION(context); | 1028 | ap = ALLOC_ACTION(context); |
1025 | ap->context = NULL; | 1029 | /*ap->context = NULL; - ALLOC_ACTION did it */ |
1026 | /* SELinux headers erroneously declare non-const parameter */ | 1030 | /* SELinux headers erroneously declare non-const parameter */ |
1027 | if (selinux_raw_to_trans_context((char*)arg1, &ap->context)) | 1031 | if (selinux_raw_to_trans_context((char*)arg1, &ap->context)) |
1028 | bb_simple_perror_msg(arg1); | 1032 | bb_simple_perror_msg(arg1); |
diff --git a/findutils/grep.c b/findutils/grep.c index 9eb5e5a1b..bf42753c5 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
@@ -5,7 +5,7 @@ | |||
5 | * Copyright (C) 1999,2000,2001 by Lineo, inc. and Mark Whitley | 5 | * Copyright (C) 1999,2000,2001 by Lineo, inc. and Mark Whitley |
6 | * Copyright (C) 1999,2000,2001 by Mark Whitley <markw@codepoet.org> | 6 | * Copyright (C) 1999,2000,2001 by Mark Whitley <markw@codepoet.org> |
7 | * | 7 | * |
8 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. | 8 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
9 | */ | 9 | */ |
10 | /* BB_AUDIT SUSv3 defects - unsupported option -x "match whole line only". */ | 10 | /* BB_AUDIT SUSv3 defects - unsupported option -x "match whole line only". */ |
11 | /* BB_AUDIT GNU defects - always acts as -a. */ | 11 | /* BB_AUDIT GNU defects - always acts as -a. */ |
@@ -469,15 +469,19 @@ static int grep_file(FILE *file) | |||
469 | if (found) | 469 | if (found) |
470 | print_line(gl->pattern, strlen(gl->pattern), linenum, ':'); | 470 | print_line(gl->pattern, strlen(gl->pattern), linenum, ':'); |
471 | } else while (1) { | 471 | } else while (1) { |
472 | unsigned start = gl->matched_range.rm_so; | ||
472 | unsigned end = gl->matched_range.rm_eo; | 473 | unsigned end = gl->matched_range.rm_eo; |
474 | unsigned len = end - start; | ||
473 | char old = line[end]; | 475 | char old = line[end]; |
474 | line[end] = '\0'; | 476 | line[end] = '\0'; |
475 | print_line(line + gl->matched_range.rm_so, | 477 | /* Empty match is not printed: try "echo test | grep -o ''" */ |
476 | end - gl->matched_range.rm_so, | 478 | if (len != 0) |
477 | linenum, ':'); | 479 | print_line(line + start, len, linenum, ':'); |
478 | if (old == '\0') | 480 | if (old == '\0') |
479 | break; | 481 | break; |
480 | line[end] = old; | 482 | line[end] = old; |
483 | if (len == 0) | ||
484 | end++; | ||
481 | #if !ENABLE_EXTRA_COMPAT | 485 | #if !ENABLE_EXTRA_COMPAT |
482 | if (regexec(&gl->compiled_regex, line + end, | 486 | if (regexec(&gl->compiled_regex, line + end, |
483 | 1, &gl->matched_range, REG_NOTBOL) != 0) | 487 | 1, &gl->matched_range, REG_NOTBOL) != 0) |
diff --git a/findutils/xargs.c b/findutils/xargs.c index 7b9f1fb73..d73fad9de 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c | |||
@@ -9,7 +9,7 @@ | |||
9 | * - Mike Rendell <michael@cs.mun.ca> | 9 | * - Mike Rendell <michael@cs.mun.ca> |
10 | * and David MacKenzie <djm@gnu.ai.mit.edu>. | 10 | * and David MacKenzie <djm@gnu.ai.mit.edu>. |
11 | * | 11 | * |
12 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. | 12 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
13 | * | 13 | * |
14 | * xargs is described in the Single Unix Specification v3 at | 14 | * xargs is described in the Single Unix Specification v3 at |
15 | * http://www.opengroup.org/onlinepubs/007904975/utilities/xargs.html | 15 | * http://www.opengroup.org/onlinepubs/007904975/utilities/xargs.html |