diff options
author | Rob Landley <rob@landley.net> | 2005-05-18 06:34:37 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2005-05-18 06:34:37 +0000 |
commit | 93850a56b2257ca5d0b2bbea82348622d83011b8 (patch) | |
tree | 7fd0b5bfa26882183b865198485c08aa11d9feac | |
parent | 5797c7f0ef93f3efd0ba6634640f9591716214e3 (diff) | |
download | busybox-w32-93850a56b2257ca5d0b2bbea82348622d83011b8.tar.gz busybox-w32-93850a56b2257ca5d0b2bbea82348622d83011b8.tar.bz2 busybox-w32-93850a56b2257ca5d0b2bbea82348622d83011b8.zip |
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.
-rw-r--r-- | editors/sed.c | 16 | ||||
-rwxr-xr-x | testsuite/sed/sed-branch-conditional-inverted | 14 |
2 files changed, 24 insertions, 6 deletions
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 @@ | |||
57 | - grouped commands: {cmd1;cmd2} | 57 | - grouped commands: {cmd1;cmd2} |
58 | - transliteration (y/source-chars/dest-chars/) | 58 | - transliteration (y/source-chars/dest-chars/) |
59 | - pattern space hold space storing / swapping (g, h, x) | 59 | - pattern space hold space storing / swapping (g, h, x) |
60 | - labels / branching (: label, b, t) | 60 | - labels / branching (: label, b, t, T) |
61 | 61 | ||
62 | (Note: Specifying an address (range) to match is *optional*; commands | 62 | (Note: Specifying an address (range) to match is *optional*; commands |
63 | default to the whole pattern space if no specific address match was | 63 | default to the whole pattern space if no specific address match was |
@@ -65,7 +65,7 @@ | |||
65 | 65 | ||
66 | Unsupported features: | 66 | Unsupported features: |
67 | 67 | ||
68 | - GNU extensions | 68 | - most GNU extensions |
69 | - and more. | 69 | - and more. |
70 | 70 | ||
71 | Todo: | 71 | Todo: |
@@ -440,7 +440,7 @@ static char *parse_cmd_args(sed_cmd_t *sed_cmd, char *cmdstr) | |||
440 | if(sed_cmd->cmd=='w') | 440 | if(sed_cmd->cmd=='w') |
441 | sed_cmd->file=bb_xfopen(sed_cmd->string,"w"); | 441 | sed_cmd->file=bb_xfopen(sed_cmd->string,"w"); |
442 | /* handle branch commands */ | 442 | /* handle branch commands */ |
443 | } else if (strchr(":bt", sed_cmd->cmd)) { | 443 | } else if (strchr(":btT", sed_cmd->cmd)) { |
444 | int length; | 444 | int length; |
445 | 445 | ||
446 | while(isspace(*cmdstr)) cmdstr++; | 446 | while(isspace(*cmdstr)) cmdstr++; |
@@ -1000,11 +1000,15 @@ restart: | |||
1000 | break; | 1000 | break; |
1001 | } | 1001 | } |
1002 | 1002 | ||
1003 | /* Test if substition worked, branch if so. */ | 1003 | /* Test/branch if substitution occurred */ |
1004 | case 't': | 1004 | case 't': |
1005 | if (!substituted) break; | 1005 | if(!substituted) break; |
1006 | substituted=0; | 1006 | substituted=0; |
1007 | /* Fall through */ | 1007 | /* Fall through */ |
1008 | /* Test/branch if substitution didn't occur */ | ||
1009 | case 'T': | ||
1010 | if (substituted) break; | ||
1011 | /* Fall through */ | ||
1008 | /* Branch to label */ | 1012 | /* Branch to label */ |
1009 | case 'b': | 1013 | case 'b': |
1010 | if (!sed_cmd->string) goto discard_commands; | 1014 | 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 @@ | |||
1 | busybox sed 's/a/1/;T notone;p;: notone;p'>output <<EOF | ||
2 | a | ||
3 | b | ||
4 | c | ||
5 | EOF | ||
6 | cmp -s output - <<EOF | ||
7 | 1 | ||
8 | 1 | ||
9 | 1 | ||
10 | b | ||
11 | b | ||
12 | c | ||
13 | c | ||
14 | EOF | ||