aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-04-12 21:20:25 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-04-12 21:20:25 +0000
commit945bd3dee89da895216dbc3113cc9cfb3f71c454 (patch)
tree3e922e9f73643d414cce7bd61dd7d8c2e39de045
parent3211adc184c8d48d91c1fb59cdba4d17e2b84b1d (diff)
downloadbusybox-w32-945bd3dee89da895216dbc3113cc9cfb3f71c454.tar.gz
busybox-w32-945bd3dee89da895216dbc3113cc9cfb3f71c454.tar.bz2
busybox-w32-945bd3dee89da895216dbc3113cc9cfb3f71c454.zip
sed: fix escaped newlines in -f; fix multiple -f and -e
(broke when getopt32 was fixed to not reverse the list)
-rw-r--r--editors/sed.c50
1 files changed, 18 insertions, 32 deletions
diff --git a/editors/sed.c b/editors/sed.c
index e4d753d72..4dd533177 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -482,15 +482,15 @@ static void add_cmd(const char *cmdstr)
482 if (G.add_cmd_line) { 482 if (G.add_cmd_line) {
483 char *tp = xasprintf("%s\n%s", G.add_cmd_line, cmdstr); 483 char *tp = xasprintf("%s\n%s", G.add_cmd_line, cmdstr);
484 free(G.add_cmd_line); 484 free(G.add_cmd_line);
485 G.add_cmd_line = tp; 485 cmdstr = G.add_cmd_line = tp;
486 } 486 }
487 487
488 /* If this line ends with backslash, request next line. */ 488 /* If this line ends with backslash, request next line. */
489 temp = strlen(cmdstr); 489 temp = strlen(cmdstr);
490 if (temp && cmdstr[temp-1] == '\\') { 490 if (temp && cmdstr[--temp] == '\\') {
491 if (!G.add_cmd_line) 491 if (!G.add_cmd_line)
492 G.add_cmd_line = xstrdup(cmdstr); 492 G.add_cmd_line = xstrdup(cmdstr);
493 G.add_cmd_line[temp-1] = 0; 493 G.add_cmd_line[temp] = '\0';
494 return; 494 return;
495 } 495 }
496 496
@@ -1210,29 +1210,6 @@ static void add_cmd_block(char *cmdstr)
1210 free(sv); 1210 free(sv);
1211} 1211}
1212 1212
1213static void add_cmds_link(llist_t *opt_e)
1214{
1215 if (!opt_e) return;
1216 add_cmds_link(opt_e->link);
1217 add_cmd_block(opt_e->data);
1218 free(opt_e);
1219}
1220
1221static void add_files_link(llist_t *opt_f)
1222{
1223 char *line;
1224 FILE *cmdfile;
1225 if (!opt_f) return;
1226 add_files_link(opt_f->link);
1227 cmdfile = xfopen(opt_f->data, "r");
1228 while ((line = xmalloc_getline(cmdfile)) != NULL) {
1229 add_cmd(line);
1230 free(line);
1231 }
1232 xprint_and_close_file(cmdfile);
1233 free(opt_f);
1234}
1235
1236void BUG_sed_globals_too_big(void); 1213void BUG_sed_globals_too_big(void);
1237 1214
1238int sed_main(int argc, char **argv); 1215int sed_main(int argc, char **argv);
@@ -1272,13 +1249,22 @@ int sed_main(int argc, char **argv)
1272 } 1249 }
1273 if (opt & 0x2) G.regex_type |= REG_EXTENDED; // -r 1250 if (opt & 0x2) G.regex_type |= REG_EXTENDED; // -r
1274 //if (opt & 0x4) G.be_quiet++; // -n 1251 //if (opt & 0x4) G.be_quiet++; // -n
1275 if (opt & 0x8) { // -e 1252 while (opt_e) { // -e
1276 /* getopt32 reverses order of arguments, handle it */ 1253 add_cmd_block(opt_e->data);
1277 add_cmds_link(opt_e); 1254 opt_e = opt_e->link;
1255 /* we leak opt_e here... */
1278 } 1256 }
1279 if (opt & 0x10) { // -f 1257 while (opt_f) { // -f
1280 /* getopt32 reverses order of arguments, handle it */ 1258 char *line;
1281 add_files_link(opt_f); 1259 FILE *cmdfile;
1260 cmdfile = xfopen(opt_f->data, "r");
1261 while ((line = xmalloc_getline(cmdfile)) != NULL) {
1262 add_cmd(line);
1263 free(line);
1264 }
1265 fclose(cmdfile);
1266 opt_f = opt_f->link;
1267 /* we leak opt_f here... */
1282 } 1268 }
1283 /* if we didn't get a pattern from -e or -f, use argv[0] */ 1269 /* if we didn't get a pattern from -e or -f, use argv[0] */
1284 if (!(opt & 0x18)) { 1270 if (!(opt & 0x18)) {