source: trunk/package/busybox/patches/000-upstream-sed.patch @ 22665

Last change on this file since 22665 was 22665, checked in by nico, 6 years ago

package/busybox: add missing bits from 1.17.1 update (mostly config stuff), rename upstream patches so they're applied first

File size: 2.0 KB
  • editors/sed.c

    a b  
    6161#include "libbb.h" 
    6262#include "xregex.h" 
    6363 
     64enum { 
     65        OPT_in_place = 1 << 0, 
     66}; 
     67 
    6468/* Each sed command turns into one of these structures. */ 
    6569typedef struct sed_cmd_s { 
    6670        /* Ordered by alignment requirements: currently 36 bytes on x86 */ 
    static void process_files(void) 
    938942 
    939943                if (matched) { 
    940944                        /* once matched, "n,xxx" range is dead, disabling it */ 
    941                         if (sed_cmd->beg_line > 0) 
     945                        if (sed_cmd->beg_line > 0 
     946                         && !(option_mask32 & OPT_in_place) /* but not for -i */ 
     947                        ) { 
    942948                                sed_cmd->beg_line = -2; 
     949                        } 
    943950                        sed_cmd->in_match = !( 
    944951                                /* has the ending line come, or is this a single address command? */ 
    945952                                (sed_cmd->end_line ? 
    static void add_cmd_block(char *cmdstr) 
    12701277int sed_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 
    12711278int sed_main(int argc UNUSED_PARAM, char **argv) 
    12721279{ 
    1273         enum { 
    1274                 OPT_in_place = 1 << 0, 
    1275         }; 
    12761280        unsigned opt; 
    12771281        llist_t *opt_e, *opt_f; 
    12781282        int status = EXIT_SUCCESS; 
    int sed_main(int argc UNUSED_PARAM, char 
    12921296        opt_e = opt_f = NULL; 
    12931297        opt_complementary = "e::f::" /* can occur multiple times */ 
    12941298                            "nn"; /* count -n */ 
     1299        /* -i must be first, to match OPT_in_place definition */ 
    12951300        opt = getopt32(argv, "irne:f:", &opt_e, &opt_f, 
    12961301                            &G.be_quiet); /* counter for -n */ 
    12971302        //argc -= optind; 
  • testsuite/sed.tests

    a b testing "sed a cmd ended by double backs 
    270270        | two \\ 
    271271' 
    272272 
    273 # fisrt three lines are deleted; 4th line is matched and printed by "2,3" and by "4" ranges 
     273# first three lines are deleted; 4th line is matched and printed by "2,3" and by "4" ranges 
    274274testing "sed with N skipping lines past ranges on next cmds" \ 
    275275        "sed -n '1{N;N;d};1p;2,3p;3p;4p'" \ 
    276276        "4\n4\n" "" "1\n2\n3\n4\n" 
    277277 
     278testing "sed -i with address modifies all files, not only first" \ 
     279        "cp input input2; sed -i -e '1s/foo/bar/' input input2 && cat input input2; rm input2" \ 
     280        "bar\nbar\n" "foo\n" "" 
     281 
     282 
    278283# testing "description" "arguments" "result" "infile" "stdin" 
    279284 
    280285exit $FAILCOUNT 
Note: See TracBrowser for help on using the repository browser.