diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2003-03-28 08:36:52 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2003-03-28 08:36:52 +0000 |
commit | 595a6a419933eb08a05102e15c594d6d303b9e6f (patch) | |
tree | cbaa5775d1ef2956ad99dc87dfc744119221d116 | |
parent | ccd43a83014d77cda09b5af82de9996bcd1fa333 (diff) | |
download | busybox-w32-595a6a419933eb08a05102e15c594d6d303b9e6f.tar.gz busybox-w32-595a6a419933eb08a05102e15c594d6d303b9e6f.tar.bz2 busybox-w32-595a6a419933eb08a05102e15c594d6d303b9e6f.zip |
sed 't' branching command
-rw-r--r-- | editors/sed.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/editors/sed.c b/editors/sed.c index d14b6f763..d1db5fa4f 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -406,7 +406,7 @@ static char *parse_cmd_str(sed_cmd_t * const sed_cmd, char *cmdstr) | |||
406 | cmdstr += parse_file_cmd(sed_cmd, cmdstr); | 406 | cmdstr += parse_file_cmd(sed_cmd, cmdstr); |
407 | } | 407 | } |
408 | /* handle branch commands */ | 408 | /* handle branch commands */ |
409 | else if (strchr(":b", sed_cmd->cmd)) { | 409 | else if (strchr(":bt", sed_cmd->cmd)) { |
410 | int length; | 410 | int length; |
411 | 411 | ||
412 | cmdstr += strspn(cmdstr, " "); | 412 | cmdstr += strspn(cmdstr, " "); |
@@ -724,6 +724,7 @@ static void process_file(FILE *file) | |||
724 | do { | 724 | do { |
725 | char *next_line; | 725 | char *next_line; |
726 | sed_cmd_t *sed_cmd; | 726 | sed_cmd_t *sed_cmd; |
727 | int substituted = 0; | ||
727 | 728 | ||
728 | /* Read one line in advance so we can act on the last line, the '$' address */ | 729 | /* Read one line in advance so we can act on the last line, the '$' address */ |
729 | next_line = bb_get_chomped_line_from_file(file); | 730 | next_line = bb_get_chomped_line_from_file(file); |
@@ -793,20 +794,16 @@ static void process_file(FILE *file) | |||
793 | */ | 794 | */ |
794 | 795 | ||
795 | /* we print the line once, unless we were told to be quiet */ | 796 | /* we print the line once, unless we were told to be quiet */ |
796 | if (!be_quiet) { | 797 | substituted = do_subst_command(sed_cmd, &line); |
797 | altered |= do_subst_command(sed_cmd, &line); | 798 | altered |= substituted; |
798 | if (altered && ((sed_cmd->linear == NULL) || (sed_cmd->linear->cmd != 's'))) { | 799 | if (!be_quiet && altered && ((sed_cmd->linear == NULL) || (sed_cmd->linear->cmd != 's'))) { |
799 | puts(line); | 800 | puts(line); |
800 | } | ||
801 | } | 801 | } |
802 | 802 | ||
803 | /* we also print the line if we were given the 'p' flag | 803 | /* we also print the line if we were given the 'p' flag |
804 | * (this is quite possibly the second printing) */ | 804 | * (this is quite possibly the second printing) */ |
805 | if (sed_cmd->sub_p) { | 805 | if ((sed_cmd->sub_p) && altered) { |
806 | altered |= do_subst_command(sed_cmd, &line); | 806 | puts(line); |
807 | if (altered) { | ||
808 | puts(line); | ||
809 | } | ||
810 | } | 807 | } |
811 | break; | 808 | break; |
812 | case 'a': | 809 | case 'a': |
@@ -867,6 +864,11 @@ static void process_file(FILE *file) | |||
867 | case 'b': | 864 | case 'b': |
868 | sed_cmd = branch_to(sed_cmd->label); | 865 | sed_cmd = branch_to(sed_cmd->label); |
869 | break; | 866 | break; |
867 | case 't': | ||
868 | if (substituted) { | ||
869 | sed_cmd = branch_to(sed_cmd->label); | ||
870 | } | ||
871 | break; | ||
870 | // case ':': | 872 | // case ':': |
871 | // break; | 873 | // break; |
872 | } | 874 | } |