[BusyBox-cvs] busybox/editors Config.in,1.6,1.7 sed.c,1.148,1.149
Glenn McGrath
bug1 at busybox.net
Tue Sep 16 05:25:44 UTC 2003
Update of /var/cvs/busybox/editors
In directory winder:/tmp/cvs-serv1286/editors
Modified Files:
Config.in sed.c
Log Message:
Configuration option to define wether to follows GNU sed's behaviour
or the posix standard.
Put the cleanup code back the way it was.
Index: Config.in
===================================================================
RCS file: /var/cvs/busybox/editors/Config.in,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- Config.in 22 Jul 2003 09:59:28 -0000 1.6
+++ Config.in 16 Sep 2003 05:25:40 -0000 1.7
@@ -42,6 +42,19 @@
It works by translating '\n' to "\n" and back.
It may introduce unexpected results if you use "\n" in your text.
+config CONFIG_FEATURE_SED_GNU_COMPATABILITY
+ bool " Behave consistent with GNU sed"
+ default y
+ depends on CONFIG_SED
+ help
+ Where GNU sed doesnt follow the posix standard, do as GNU sed does.
+ Current difference are in
+ - N command with odd number of lines (see GNU sed info page)
+ - Blanks before substitution flags eg.
+ GNU sed interprets 's/a/b/ g' as 's/a/b/g'
+ Standard says 's/a/b/ g' should be 's/a/b/;g'
+ - GNU sed allows blanks between a '!' and the function.
+
config CONFIG_VI
bool "vi"
default n
Index: sed.c
===================================================================
RCS file: /var/cvs/busybox/editors/sed.c,v
retrieving revision 1.148
retrieving revision 1.149
diff -u -d -r1.148 -r1.149
--- sed.c 16 Sep 2003 01:46:34 -0000 1.148
+++ sed.c 16 Sep 2003 05:25:40 -0000 1.149
@@ -45,9 +45,11 @@
- GNU extensions
- and more.
- Bugs:
-
- - lots
+ Todo:
+
+ - Create a wrapper around regex to make libc's regex conform with sed
+ - Fix bugs
+
Reference http://www.opengroup.org/onlinepubs/007904975/utilities/sed.html
*/
@@ -298,7 +300,15 @@
}
/* process the flags */
- while (substr[++idx]) {
+#ifndef CONFIG_FEATURE_SED_GNU_COMPATABILITY
+ idx++;
+#else
+ /* GNU sed allows blanks before the flag, this can lead to an incosistent
+ * interpretation of 's/a/b/ g' as being either 's/a/b/g' or 's/a/b/;g'.
+ * which results in very different behaviour.
+ */
+ while (substr[++idx])
+#endif
switch (substr[idx]) {
case 'g':
if (match[0] != '^') {
@@ -312,16 +322,20 @@
case 'p':
sed_cmd->sub_p = 1;
break;
+#ifdef CONFIG_FEATURE_SED_GNU_COMPATABILITY
default:
/* any whitespace or semicolon trailing after a s/// is ok */
if (strchr(semicolon_whitespace, substr[idx]))
goto out;
- /* else */
bb_error_msg_and_die("bad option in substitution expression");
+#endif
}
- }
- out:
+#ifndef CONFIG_FEATURE_SED_GNU_COMPATABILITY
+ idx++;
+#else
+out:
+#endif
/* compile the match string into a regex */
if (*match != '\0') {
/* If match is empty, we use last regex used at runtime */
@@ -556,15 +570,12 @@
sed_cmd->invert = 1;
cmdstr++;
-#ifdef SED_FEATURE_STRICT_CHECKING
+#ifdef CONFIG_FEATURE_SED_GNU_COMPATABILITY
/* According to the spec
* It is unspecified whether <blank>s can follow a '!' character,
* and conforming applications shall not follow a '!' character
* with <blank>s.
*/
- if (isblank(cmdstr[idx]) {
- bb_error_msg_and_die("blank follows '!'");}
-#else
/* skip whitespace before the command */
while (isspace(*cmdstr)) {
cmdstr++;
@@ -931,7 +942,6 @@
}
/* we also print the line if we were given the 'p' flag
* (this is quite possibly the second printing) */
-// if ((sed_cmd->sub_p) && (!altered || substituted)) {
if ((sed_cmd->sub_p) && (altered || substituted)) {
puts(pattern_space);
}
@@ -1007,20 +1017,25 @@
}
break;
case 'N': /* Append the next line to the current line */
- if (next_line) {
- pattern_space =
- realloc(pattern_space,
- strlen(pattern_space) + strlen(next_line) + 2);
- strcat(pattern_space, "\n");
- strcat(pattern_space, next_line);
- next_line = bb_get_chomped_line_from_file(file);
- linenum++;
- } else {
+ if (next_line == NULL) {
/* Jump to end of script and exist */
deleted = 1;
free(next_line);
+#ifdef CONFIG_FEATURE_SED_GNU_COMPATABILITY
+ /* GNU sed will add the newline character
+ * The GNU sed info page labels this as a bug that wont be fixed
+ */
+ next_line = calloc(1,1);
+#else
next_line = NULL;
+ break;
+#endif
}
+ pattern_space = realloc(pattern_space, strlen(pattern_space) + strlen(next_line) + 2);
+ strcat(pattern_space, "\n");
+ strcat(pattern_space, next_line);
+ next_line = bb_get_chomped_line_from_file(file);
+ linenum++;
break;
case 't':
if (substituted)
@@ -1164,13 +1179,11 @@
{
int opt, status = EXIT_SUCCESS;
-#if 0 /* This doesnt seem to be working */
#ifdef CONFIG_FEATURE_CLEAN_UP
/* destroy command strings on exit */
if (atexit(destroy_cmd_strs) == -1)
bb_perror_msg_and_die("atexit");
#endif
-#endif
/* do normal option parsing */
while ((opt = getopt(argc, argv, "ne:f:")) > 0) {
@@ -1223,8 +1236,5 @@
}
}
-#ifdef CONFIG_FEATURE_CLEAN_UP
- destroy_cmd_strs();
-#endif
return status;
}
More information about the busybox-cvs
mailing list