sed: -e options were handled in reverse order. fix that.
This commit is contained in:
parent
b97c9842a5
commit
e2016e145b
@ -1084,6 +1084,29 @@ static void add_cmd_block(char *cmdstr)
|
|||||||
free(temp);
|
free(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void add_cmds_link(llist_t *opt_e)
|
||||||
|
{
|
||||||
|
if (!opt_e) return;
|
||||||
|
add_cmds_link(opt_e->link);
|
||||||
|
add_cmd_block(opt_e->data);
|
||||||
|
free(opt_e);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void add_files_link(llist_t *opt_f)
|
||||||
|
{
|
||||||
|
char *line;
|
||||||
|
FILE *cmdfile;
|
||||||
|
if (!opt_f) return;
|
||||||
|
add_files_link(opt_f->link);
|
||||||
|
cmdfile = xfopen(opt_f->data, "r");
|
||||||
|
while ((line = bb_get_chomped_line_from_file(cmdfile)) != NULL) {
|
||||||
|
add_cmd(line);
|
||||||
|
free(line);
|
||||||
|
}
|
||||||
|
xprint_and_close_file(cmdfile);
|
||||||
|
free(opt_f);
|
||||||
|
}
|
||||||
|
|
||||||
int sed_main(int argc, char **argv)
|
int sed_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
unsigned long opt;
|
unsigned long opt;
|
||||||
@ -1112,27 +1135,12 @@ int sed_main(int argc, char **argv)
|
|||||||
if (opt & 0x2) bbg.regex_type|=REG_EXTENDED; // -r
|
if (opt & 0x2) bbg.regex_type|=REG_EXTENDED; // -r
|
||||||
if (opt & 0x4) bbg.be_quiet++; // -n
|
if (opt & 0x4) bbg.be_quiet++; // -n
|
||||||
if (opt & 0x8) { // -e
|
if (opt & 0x8) { // -e
|
||||||
while (opt_e) {
|
/* getopt_ulflags reverses order of arguments, handle it */
|
||||||
llist_t *cur = opt_e;
|
add_cmds_link(opt_e);
|
||||||
add_cmd_block(cur->data);
|
|
||||||
opt_e = cur->link;
|
|
||||||
free(cur);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (opt & 0x10) { // -f
|
if (opt & 0x10) { // -f
|
||||||
while (opt_f) {
|
/* getopt_ulflags reverses order of arguments, handle it */
|
||||||
llist_t *cur = opt_f;
|
add_files_link(opt_f);
|
||||||
FILE *cmdfile;
|
|
||||||
char *line;
|
|
||||||
cmdfile = xfopen(cur->data, "r");
|
|
||||||
while ((line = bb_get_chomped_line_from_file(cmdfile)) != NULL) {
|
|
||||||
add_cmd(line);
|
|
||||||
free(line);
|
|
||||||
}
|
|
||||||
xprint_and_close_file(cmdfile);
|
|
||||||
opt_f = cur->link;
|
|
||||||
free(cur);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* if we didn't get a pattern from -e or -f, use argv[optind] */
|
/* if we didn't get a pattern from -e or -f, use argv[optind] */
|
||||||
if(!(opt & 0x18)) {
|
if(!(opt & 0x18)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user