[BusyBox] [PATCH] sed 'T' command

Colin Watson cjwatson at debian.org
Tue Apr 12 17:41:34 UTC 2005


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.

Thanks,

-- 
Colin Watson                                       [cjwatson at debian.org]
-------------- next part --------------
Index: testsuite/sed/sed-branch-conditional-inverted
===================================================================
--- testsuite/sed/sed-branch-conditional-inverted	(revision 0)
+++ testsuite/sed/sed-branch-conditional-inverted	(revision 0)
@@ -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
Index: editors/sed.c
===================================================================
--- editors/sed.c	(revision 10080)
+++ editors/sed.c	(working copy)
@@ -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 @@
 		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,9 +1000,15 @@
 						break;
 					}
 
-					/* Test if substition worked, branch if so. */
+					/* Test if substitution worked, branch if so. */
 					case 't':
-						if (!substituted) break;
+					/* Test if substitution worked, branch if not. */
+					case 'T':
+						if (sed_cmd->cmd == 't') {
+							if (!substituted) break;
+						} else {
+							if (substituted) break;
+						}
 						substituted=0;
 							/* Fall through */
 					/* Branch to label */


More information about the busybox mailing list