svn commit: trunk/busybox: editors testsuite
vda at busybox.net
vda at busybox.net
Tue Nov 13 16:48:11 UTC 2007
Author: vda
Date: 2007-11-13 08:48:10 -0800 (Tue, 13 Nov 2007)
New Revision: 20414
Log:
sed: support GNU-like '\t' escape in substitutions
Modified:
trunk/busybox/editors/sed.c
trunk/busybox/testsuite/README
trunk/busybox/testsuite/sed.tests
Changeset:
Modified: trunk/busybox/editors/sed.c
===================================================================
--- trunk/busybox/editors/sed.c 2007-11-13 10:00:59 UTC (rev 20413)
+++ trunk/busybox/editors/sed.c 2007-11-13 16:48:10 UTC (rev 20414)
@@ -173,7 +173,7 @@
if (G.outname) unlink(G.outname);
}
-/* strdup, replacing "\n" with '\n', and "\delimiter" with 'delimiter' */
+/* strcpy, replacing "\from" with 'to'. If to is NUL, replacing "\any" with 'any' */
static void parse_escapes(char *dest, const char *string, int len, char from, char to)
{
@@ -188,9 +188,10 @@
}
*dest++ = string[i++];
}
+ /* TODO: is it safe wrt a string with trailing '\\' ? */
*dest++ = string[i++];
}
- *dest = 0;
+ *dest = '\0';
}
static char *copy_parsing_escapes(const char *string, int len)
@@ -198,6 +199,8 @@
char *dest = xmalloc(len + 1);
parse_escapes(dest, string, len, 'n', '\n');
+ /* GNU sed also recognizes \t */
+ parse_escapes(dest, dest, strlen(dest), 't', '\t');
return dest;
}
@@ -205,7 +208,7 @@
/*
* index_of_next_unescaped_regexp_delim - walks left to right through a string
* beginning at a specified index and returns the index of the next regular
- * expression delimiter (typically a forward * slash ('/')) not preceded by
+ * expression delimiter (typically a forward slash ('/')) not preceded by
* a backslash ('\'). A negative delimiter disables square bracket checking.
*/
static int index_of_next_unescaped_regexp_delim(int delimiter, const char *str)
@@ -425,7 +428,8 @@
break;
}
sed_cmd->string = xstrdup(cmdstr);
- parse_escapes(sed_cmd->string, sed_cmd->string, strlen(cmdstr), 0, 0);
+ /* "\anychar" -> "anychar" */
+ parse_escapes(sed_cmd->string, sed_cmd->string, strlen(cmdstr), '\0', '\0');
cmdstr += strlen(cmdstr);
/* handle file cmds: (r)ead */
} else if (strchr("rw", sed_cmd->cmd)) {
@@ -1337,7 +1341,7 @@
// FIXME: error check / message?
rename(G.outname, argv[i]);
free(G.outname);
- G.outname = 0;
+ G.outname = NULL;
}
if (G.input_file_count > G.current_input_file)
process_files();
Modified: trunk/busybox/testsuite/README
===================================================================
--- trunk/busybox/testsuite/README 2007-11-13 10:00:59 UTC (rev 20413)
+++ trunk/busybox/testsuite/README 2007-11-13 16:48:10 UTC (rev 20414)
@@ -4,8 +4,10 @@
To run the test suite, change to this directory and run "./runtest". It will
run all of the test cases, and list those with unexpected outcomes. Adding the
-v option will cause it to show expected outcomes as well. To only run the test
-cases for particular applets, specify them as parameters to runtest.
+cases for particular applets:
+./runtest <applet1> <applet2>...
+
The test cases for an applet reside in the subdirectory of the applet name. The
name of the test case should be the assertion that is tested. The test case
should be a shell fragment that returns successfully if the test case passes,
Modified: trunk/busybox/testsuite/sed.tests
===================================================================
--- trunk/busybox/testsuite/sed.tests 2007-11-13 10:00:59 UTC (rev 20413)
+++ trunk/busybox/testsuite/sed.tests 2007-11-13 16:48:10 UTC (rev 20414)
@@ -57,6 +57,7 @@
testing "sed s chains" "sed -e s/foo/bar/ -e s/bar/baz/" "baz\n" "" "foo\n"
testing "sed s chains2" "sed -e s/foo/bar/ -e s/baz/nee/" "bar\n" "" "foo\n"
testing "sed s [delimiter]" "sed -e 's@[@]@@'" "onetwo" "" "one at two"
+testing "sed s with \\t (GNU ext)" "sed 's/\t/ /'" "one two" "" "one\ttwo"
# branch
testing "sed b (branch)" "sed -e 'b one;p;: one'" "foo\n" "" "foo\n"
More information about the busybox-cvs
mailing list