brcm47xx: do not read out cfe
[openwrt.git] / package / busybox / patches / 921-sed.patch
1 --- a/editors/sed.c
2 +++ b/editors/sed.c
3 @@ -61,6 +61,10 @@
4  #include "libbb.h"
5  #include "xregex.h"
6  
7 +enum {
8 +       OPT_in_place = 1 << 0,
9 +};
10 +
11  /* Each sed command turns into one of these structures. */
12  typedef struct sed_cmd_s {
13         /* Ordered by alignment requirements: currently 36 bytes on x86 */
14 @@ -938,8 +942,11 @@ static void process_files(void)
15  
16                 if (matched) {
17                         /* once matched, "n,xxx" range is dead, disabling it */
18 -                       if (sed_cmd->beg_line > 0)
19 +                       if (sed_cmd->beg_line > 0
20 +                        && !(option_mask32 & OPT_in_place) /* but not for -i */
21 +                       ) {
22                                 sed_cmd->beg_line = -2;
23 +                       }
24                         sed_cmd->in_match = !(
25                                 /* has the ending line come, or is this a single address command? */
26                                 (sed_cmd->end_line ?
27 @@ -1270,9 +1277,6 @@ static void add_cmd_block(char *cmdstr)
28  int sed_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
29  int sed_main(int argc UNUSED_PARAM, char **argv)
30  {
31 -       enum {
32 -               OPT_in_place = 1 << 0,
33 -       };
34         unsigned opt;
35         llist_t *opt_e, *opt_f;
36         int status = EXIT_SUCCESS;
37 @@ -1292,6 +1296,7 @@ int sed_main(int argc UNUSED_PARAM, char
38         opt_e = opt_f = NULL;
39         opt_complementary = "e::f::" /* can occur multiple times */
40                             "nn"; /* count -n */
41 +       /* -i must be first, to match OPT_in_place definition */
42         opt = getopt32(argv, "irne:f:", &opt_e, &opt_f,
43                             &G.be_quiet); /* counter for -n */
44         //argc -= optind;
45 --- a/testsuite/sed.tests
46 +++ b/testsuite/sed.tests
47 @@ -270,11 +270,16 @@ testing "sed a cmd ended by double backs
48         | two \\
49  '
50  
51 -# fisrt three lines are deleted; 4th line is matched and printed by "2,3" and by "4" ranges
52 +# first three lines are deleted; 4th line is matched and printed by "2,3" and by "4" ranges
53  testing "sed with N skipping lines past ranges on next cmds" \
54         "sed -n '1{N;N;d};1p;2,3p;3p;4p'" \
55         "4\n4\n" "" "1\n2\n3\n4\n"
56  
57 +testing "sed -i with address modifies all files, not only first" \
58 +       "cp input input2; sed -i -e '1s/foo/bar/' input input2 && cat input input2; rm input2" \
59 +       "bar\nbar\n" "foo\n" ""
60 +
61 +
62  # testing "description" "arguments" "result" "infile" "stdin"
63  
64  exit $FAILCOUNT