mirror of
https://github.com/sheumann/hush.git
synced 2024-12-23 05:29:58 +00:00
sed 't' branching command
This commit is contained in:
parent
ccd43a8301
commit
595a6a4199
@ -406,7 +406,7 @@ static char *parse_cmd_str(sed_cmd_t * const sed_cmd, char *cmdstr)
|
|||||||
cmdstr += parse_file_cmd(sed_cmd, cmdstr);
|
cmdstr += parse_file_cmd(sed_cmd, cmdstr);
|
||||||
}
|
}
|
||||||
/* handle branch commands */
|
/* handle branch commands */
|
||||||
else if (strchr(":b", sed_cmd->cmd)) {
|
else if (strchr(":bt", sed_cmd->cmd)) {
|
||||||
int length;
|
int length;
|
||||||
|
|
||||||
cmdstr += strspn(cmdstr, " ");
|
cmdstr += strspn(cmdstr, " ");
|
||||||
@ -724,6 +724,7 @@ static void process_file(FILE *file)
|
|||||||
do {
|
do {
|
||||||
char *next_line;
|
char *next_line;
|
||||||
sed_cmd_t *sed_cmd;
|
sed_cmd_t *sed_cmd;
|
||||||
|
int substituted = 0;
|
||||||
|
|
||||||
/* Read one line in advance so we can act on the last line, the '$' address */
|
/* Read one line in advance so we can act on the last line, the '$' address */
|
||||||
next_line = bb_get_chomped_line_from_file(file);
|
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 */
|
/* we print the line once, unless we were told to be quiet */
|
||||||
if (!be_quiet) {
|
substituted = do_subst_command(sed_cmd, &line);
|
||||||
altered |= do_subst_command(sed_cmd, &line);
|
altered |= substituted;
|
||||||
if (altered && ((sed_cmd->linear == NULL) || (sed_cmd->linear->cmd != 's'))) {
|
if (!be_quiet && altered && ((sed_cmd->linear == NULL) || (sed_cmd->linear->cmd != 's'))) {
|
||||||
puts(line);
|
puts(line);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we also print the line if we were given the 'p' flag
|
/* we also print the line if we were given the 'p' flag
|
||||||
* (this is quite possibly the second printing) */
|
* (this is quite possibly the second printing) */
|
||||||
if (sed_cmd->sub_p) {
|
if ((sed_cmd->sub_p) && altered) {
|
||||||
altered |= do_subst_command(sed_cmd, &line);
|
puts(line);
|
||||||
if (altered) {
|
|
||||||
puts(line);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
@ -867,6 +864,11 @@ static void process_file(FILE *file)
|
|||||||
case 'b':
|
case 'b':
|
||||||
sed_cmd = branch_to(sed_cmd->label);
|
sed_cmd = branch_to(sed_cmd->label);
|
||||||
break;
|
break;
|
||||||
|
case 't':
|
||||||
|
if (substituted) {
|
||||||
|
sed_cmd = branch_to(sed_cmd->label);
|
||||||
|
}
|
||||||
|
break;
|
||||||
// case ':':
|
// case ':':
|
||||||
// break;
|
// break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user