package/busybox: update to busybox-1.7.1, include upstream patches
[openwrt/svn-archive/archive.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 diff -urpN busybox-1.17.1/testsuite/sed.tests busybox-1.17.1-sed/testsuite/sed.tests
46 --- busybox-1.17.1/testsuite/sed.tests 2010-07-06 04:25:54.000000000 +0200
47 +++ busybox-1.17.1-sed/testsuite/sed.tests 2010-08-01 04:19:26.000000000 +0200
48 @@ -270,11 +270,16 @@ testing "sed a cmd ended by double backs
49 | two \\
50 '
51
52 -# fisrt three lines are deleted; 4th line is matched and printed by "2,3" and by "4" ranges
53 +# first three lines are deleted; 4th line is matched and printed by "2,3" and by "4" ranges
54 testing "sed with N skipping lines past ranges on next cmds" \
55 "sed -n '1{N;N;d};1p;2,3p;3p;4p'" \
56 "4\n4\n" "" "1\n2\n3\n4\n"
57
58 +testing "sed -i with address modifies all files, not only first" \
59 + "cp input input2; sed -i -e '1s/foo/bar/' input input2 && cat input input2; rm input2" \
60 + "bar\nbar\n" "foo\n" ""
61 +
62 +
63 # testing "description" "arguments" "result" "infile" "stdin"
64
65 exit $FAILCOUNT