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.
This commit is contained in:
Rob Landley 2005-05-18 06:34:37 +00:00
parent 5797c7f0ef
commit 93850a56b2
2 changed files with 24 additions and 6 deletions

View File

@ -57,7 +57,7 @@
- grouped commands: {cmd1;cmd2} - grouped commands: {cmd1;cmd2}
- transliteration (y/source-chars/dest-chars/) - transliteration (y/source-chars/dest-chars/)
- pattern space hold space storing / swapping (g, h, x) - 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 (Note: Specifying an address (range) to match is *optional*; commands
default to the whole pattern space if no specific address match was default to the whole pattern space if no specific address match was
@ -65,7 +65,7 @@
Unsupported features: Unsupported features:
- GNU extensions - most GNU extensions
- and more. - and more.
Todo: Todo:
@ -440,7 +440,7 @@ static char *parse_cmd_args(sed_cmd_t *sed_cmd, char *cmdstr)
if(sed_cmd->cmd=='w') if(sed_cmd->cmd=='w')
sed_cmd->file=bb_xfopen(sed_cmd->string,"w"); sed_cmd->file=bb_xfopen(sed_cmd->string,"w");
/* handle branch commands */ /* handle branch commands */
} else if (strchr(":bt", sed_cmd->cmd)) { } else if (strchr(":btT", sed_cmd->cmd)) {
int length; int length;
while(isspace(*cmdstr)) cmdstr++; while(isspace(*cmdstr)) cmdstr++;
@ -1000,11 +1000,15 @@ restart:
break; break;
} }
/* Test if substition worked, branch if so. */ /* Test/branch if substitution occurred */
case 't': case 't':
if (!substituted) break; if(!substituted) break;
substituted=0; substituted=0;
/* Fall through */ /* Fall through */
/* Test/branch if substitution didn't occur */
case 'T':
if (substituted) break;
/* Fall through */
/* Branch to label */ /* Branch to label */
case 'b': case 'b':
if (!sed_cmd->string) goto discard_commands; if (!sed_cmd->string) goto discard_commands;

View File

@ -0,0 +1,14 @@
busybox sed 's/a/1/;T notone;p;: notone;p'>output <<EOF
a
b
c
EOF
cmp -s output - <<EOF
1
1
1
b
b
c
c
EOF