aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-10-01 21:37:40 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-10-01 21:37:40 +0000
commite2016e145b499f257dff1011f1608490a49fdb7e (patch)
treeeee83cc32f3f50737939eef5a7fd0fc01e1cf111
parentb97c9842a521a54980b247ab8b920f057b128b2e (diff)
downloadbusybox-w32-e2016e145b499f257dff1011f1608490a49fdb7e.tar.gz
busybox-w32-e2016e145b499f257dff1011f1608490a49fdb7e.tar.bz2
busybox-w32-e2016e145b499f257dff1011f1608490a49fdb7e.zip
sed: -e options were handled in reverse order. fix that.
-rw-r--r--editors/sed.c46
1 files changed, 27 insertions, 19 deletions
diff --git a/editors/sed.c b/editors/sed.c
index 229a9feaa..54d08ee02 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -1084,6 +1084,29 @@ static void add_cmd_block(char *cmdstr)
1084 free(temp); 1084 free(temp);
1085} 1085}
1086 1086
1087static void add_cmds_link(llist_t *opt_e)
1088{
1089 if (!opt_e) return;
1090 add_cmds_link(opt_e->link);
1091 add_cmd_block(opt_e->data);
1092 free(opt_e);
1093}
1094
1095static void add_files_link(llist_t *opt_f)
1096{
1097 char *line;
1098 FILE *cmdfile;
1099 if (!opt_f) return;
1100 add_files_link(opt_f->link);
1101 cmdfile = xfopen(opt_f->data, "r");
1102 while ((line = bb_get_chomped_line_from_file(cmdfile)) != NULL) {
1103 add_cmd(line);
1104 free(line);
1105 }
1106 xprint_and_close_file(cmdfile);
1107 free(opt_f);
1108}
1109
1087int sed_main(int argc, char **argv) 1110int sed_main(int argc, char **argv)
1088{ 1111{
1089 unsigned long opt; 1112 unsigned long opt;
@@ -1112,27 +1135,12 @@ int sed_main(int argc, char **argv)
1112 if (opt & 0x2) bbg.regex_type|=REG_EXTENDED; // -r 1135 if (opt & 0x2) bbg.regex_type|=REG_EXTENDED; // -r
1113 if (opt & 0x4) bbg.be_quiet++; // -n 1136 if (opt & 0x4) bbg.be_quiet++; // -n
1114 if (opt & 0x8) { // -e 1137 if (opt & 0x8) { // -e
1115 while (opt_e) { 1138 /* getopt_ulflags reverses order of arguments, handle it */
1116 llist_t *cur = opt_e; 1139 add_cmds_link(opt_e);
1117 add_cmd_block(cur->data);
1118 opt_e = cur->link;
1119 free(cur);
1120 }
1121 } 1140 }
1122 if (opt & 0x10) { // -f 1141 if (opt & 0x10) { // -f
1123 while (opt_f) { 1142 /* getopt_ulflags reverses order of arguments, handle it */
1124 llist_t *cur = opt_f; 1143 add_files_link(opt_f);
1125 FILE *cmdfile;
1126 char *line;
1127 cmdfile = xfopen(cur->data, "r");
1128 while ((line = bb_get_chomped_line_from_file(cmdfile)) != NULL) {
1129 add_cmd(line);
1130 free(line);
1131 }
1132 xprint_and_close_file(cmdfile);
1133 opt_f = cur->link;
1134 free(cur);
1135 }
1136 } 1144 }
1137 /* if we didn't get a pattern from -e or -f, use argv[optind] */ 1145 /* if we didn't get a pattern from -e or -f, use argv[optind] */
1138 if(!(opt & 0x18)) { 1146 if(!(opt & 0x18)) {