aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMimi Li <felloak@gmail.com>2012-07-24 13:20:12 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2012-07-24 13:20:12 +0200
commit37a79c092edcc8691686a4d4b609d2c034ccd840 (patch)
tree9a13c482df69283ad4e3898c052ff04361c13b90
parentdbed6c4b46f3c8dc74d50e4cf35b1cb8b8c4ff2d (diff)
downloadbusybox-w32-37a79c092edcc8691686a4d4b609d2c034ccd840.tar.gz
busybox-w32-37a79c092edcc8691686a4d4b609d2c034ccd840.tar.bz2
busybox-w32-37a79c092edcc8691686a4d4b609d2c034ccd840.zip
sed: allow 'w' cmd to use two address form
function old new delta add_cmd 1101 1094 -7 Signed-off-by: Mimi Li <felloak@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/sed.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/editors/sed.c b/editors/sed.c
index 42d8e17c6..070af611a 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -53,7 +53,9 @@
53 * Todo: 53 * Todo:
54 * - Create a wrapper around regex to make libc's regex conform with sed 54 * - Create a wrapper around regex to make libc's regex conform with sed
55 * 55 *
56 * Reference http://www.opengroup.org/onlinepubs/007904975/utilities/sed.html 56 * Reference
57 * http://www.opengroup.org/onlinepubs/007904975/utilities/sed.html
58 * http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html
57 */ 59 */
58 60
59//usage:#define sed_trivial_usage 61//usage:#define sed_trivial_usage
@@ -492,8 +494,10 @@ static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr)
492 } 494 }
493 /* handle edit cmds: (a)ppend, (i)nsert, and (c)hange */ 495 /* handle edit cmds: (a)ppend, (i)nsert, and (c)hange */
494 else if (idx <= IDX_c) { /* a,i,c */ 496 else if (idx <= IDX_c) { /* a,i,c */
495 if ((sed_cmd->end_line || sed_cmd->end_match) && sed_cmd->cmd != 'c') 497 if (idx < IDX_c) { /* a,i */
496 bb_error_msg_and_die("only a beginning address can be specified for edit commands"); 498 if (sed_cmd->end_line || sed_cmd->end_match)
499 bb_error_msg_and_die("command '%c' uses only one address", sed_cmd->cmd);
500 }
497 for (;;) { 501 for (;;) {
498 if (*cmdstr == '\n' || *cmdstr == '\\') { 502 if (*cmdstr == '\n' || *cmdstr == '\\') {
499 cmdstr++; 503 cmdstr++;
@@ -510,8 +514,10 @@ static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr)
510 } 514 }
511 /* handle file cmds: (r)ead */ 515 /* handle file cmds: (r)ead */
512 else if (idx <= IDX_w) { /* r,w */ 516 else if (idx <= IDX_w) { /* r,w */
513 if (sed_cmd->end_line || sed_cmd->end_match) 517 if (idx < IDX_w) { /* r */
514 bb_error_msg_and_die("command only uses one address"); 518 if (sed_cmd->end_line || sed_cmd->end_match)
519 bb_error_msg_and_die("command '%c' uses only one address", sed_cmd->cmd);
520 }
515 cmdstr += parse_file_cmd(/*sed_cmd,*/ cmdstr, &sed_cmd->string); 521 cmdstr += parse_file_cmd(/*sed_cmd,*/ cmdstr, &sed_cmd->string);
516 if (sed_cmd->cmd == 'w') { 522 if (sed_cmd->cmd == 'w') {
517 sed_cmd->sw_file = xfopen_for_write(sed_cmd->string); 523 sed_cmd->sw_file = xfopen_for_write(sed_cmd->string);