aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2003-03-28 08:36:52 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2003-03-28 08:36:52 +0000
commit595a6a419933eb08a05102e15c594d6d303b9e6f (patch)
treecbaa5775d1ef2956ad99dc87dfc744119221d116
parentccd43a83014d77cda09b5af82de9996bcd1fa333 (diff)
downloadbusybox-595a6a419933eb08a05102e15c594d6d303b9e6f.tar.gz
sed 't' branching command
-rw-r--r--editors/sed.c24
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)
cmdstr += parse_file_cmd(sed_cmd, cmdstr);
}
/* handle branch commands */
- else if (strchr(":b", sed_cmd->cmd)) {
+ else if (strchr(":bt", sed_cmd->cmd)) {
int length;
cmdstr += strspn(cmdstr, " ");
@@ -724,6 +724,7 @@ static void process_file(FILE *file)
do {
char *next_line;
sed_cmd_t *sed_cmd;
+ int substituted = 0;
/* Read one line in advance so we can act on the last line, the '$' address */
next_line = bb_get_chomped_line_from_file(file);
@@ -793,20 +794,16 @@ static void process_file(FILE *file)
*/
/* we print the line once, unless we were told to be quiet */
- if (!be_quiet) {
- altered |= do_subst_command(sed_cmd, &line);
- if (altered && ((sed_cmd->linear == NULL) || (sed_cmd->linear->cmd != 's'))) {
- puts(line);
- }
+ substituted = do_subst_command(sed_cmd, &line);
+ altered |= substituted;
+ if (!be_quiet && altered && ((sed_cmd->linear == NULL) || (sed_cmd->linear->cmd != 's'))) {
+ puts(line);
}
/* we also print the line if we were given the 'p' flag
* (this is quite possibly the second printing) */
- if (sed_cmd->sub_p) {
- altered |= do_subst_command(sed_cmd, &line);
- if (altered) {
- puts(line);
- }
+ if ((sed_cmd->sub_p) && altered) {
+ puts(line);
}
break;
case 'a':
@@ -867,6 +864,11 @@ static void process_file(FILE *file)
case 'b':
sed_cmd = branch_to(sed_cmd->label);
break;
+ case 't':
+ if (substituted) {
+ sed_cmd = branch_to(sed_cmd->label);
+ }
+ break;
// case ':':
// break;
}