From: Rob Landley Date: Wed, 18 May 2005 06:34:37 +0000 (-0000) Subject: Patch from Colin Watson (mangled slightly by Rob Landley): X-Git-Tag: 1_1_0~969 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=93850a56b2257ca5d0b2bbea82348622d83011b8;p=oweals%2Fbusybox.git Patch from Colin Watson (mangled slightly by Rob Landley): This patch implements the 'T' command in sed. This is a GNU extension, but one of the udev hotplug scripts uses it, so I need it in busybox anyway. Includes a test; 'svn add testsuite/sed/sed-branch-conditional-inverted' after applying. --- diff --git a/editors/sed.c b/editors/sed.c index 1b6ed2b0f..a0a127e2b 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -57,7 +57,7 @@ - grouped commands: {cmd1;cmd2} - transliteration (y/source-chars/dest-chars/) - pattern space hold space storing / swapping (g, h, x) - - labels / branching (: label, b, t) + - labels / branching (: label, b, t, T) (Note: Specifying an address (range) to match is *optional*; commands default to the whole pattern space if no specific address match was @@ -65,7 +65,7 @@ Unsupported features: - - GNU extensions + - most GNU extensions - and more. Todo: @@ -440,7 +440,7 @@ static char *parse_cmd_args(sed_cmd_t *sed_cmd, char *cmdstr) if(sed_cmd->cmd=='w') sed_cmd->file=bb_xfopen(sed_cmd->string,"w"); /* handle branch commands */ - } else if (strchr(":bt", sed_cmd->cmd)) { + } else if (strchr(":btT", sed_cmd->cmd)) { int length; while(isspace(*cmdstr)) cmdstr++; @@ -1000,11 +1000,15 @@ restart: break; } - /* Test if substition worked, branch if so. */ + /* Test/branch if substitution occurred */ case 't': - if (!substituted) break; + if(!substituted) break; substituted=0; - /* Fall through */ + /* Fall through */ + /* Test/branch if substitution didn't occur */ + case 'T': + if (substituted) break; + /* Fall through */ /* Branch to label */ case 'b': if (!sed_cmd->string) goto discard_commands; diff --git a/testsuite/sed/sed-branch-conditional-inverted b/testsuite/sed/sed-branch-conditional-inverted new file mode 100755 index 000000000..f4df84b3e --- /dev/null +++ b/testsuite/sed/sed-branch-conditional-inverted @@ -0,0 +1,14 @@ +busybox sed 's/a/1/;T notone;p;: notone;p'>output <