[BusyBox-cvs] busybox/editors sed.c,1.162,1.163
Rob Landley
landley at busybox.net
Thu Apr 1 09:23:32 UTC 2004
Update of /var/cvs/busybox/editors
In directory nail:/tmp/cvs-serv8067/busybox/editors
Modified Files:
sed.c
Log Message:
The last patch broke:
sed -i "/^boo/a fred" ipsec.conf
Which works in gnu sed. (And is _supposed_ to strip all the whitespace before
"fred".)
It also broke:
sed -i -e "/^boo/a \\" -e " fred" ipsec.conf
I.E. there can legally be spaces between the a and the backslash at the end of
the line.
And strangely enough, gnu sed accepts the following syntax as well:
sed -i "/^boo/a \\ fred" ipsec.conf
Which is a way of having the significant whitespace at the start of the line,
all on one line. (But notice that the whitespace BEFORE the slash is still
stripped, as is the slash itself. And notice that the naieve placement of
"\n" there doesn't work, it puts an n at the start of the appended line. The
double slashing is for shell escapes because you could escape the quote, you
see. It's turned into a single backslash. But \n there is _not_ turned into
a newline by the shell. So there.)
This makes all three syntaxes work in my tests. I should probably start
writing better documentation at some point. I posted my current sedtests.py
file to the list, which needs a lot more tests added as well...
Index: sed.c
===================================================================
RCS file: /var/cvs/busybox/editors/sed.c,v
retrieving revision 1.162
retrieving revision 1.163
diff -u -d -r1.162 -r1.163
--- a/sed.c 31 Mar 2004 11:42:40 -0000 1.162
+++ b/sed.c 1 Apr 2004 09:23:30 -0000 1.163
@@ -6,6 +6,7 @@
* Copyright (C) 1999,2000,2001 by Mark Whitley <markw at codepoet.org>
* Copyright (C) 2002 Matt Kraai
* Copyright (C) 2003 by Glenn McGrath <bug1 at optushome.com.au>
+ * Copyright (C) 2003,2004 by Rob Landley <rob at landley.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -410,9 +411,13 @@
if ((sed_cmd->end_line || sed_cmd->end_match) && sed_cmd->cmd != 'c')
bb_error_msg_and_die
("only a beginning address can be specified for edit commands");
- if (*cmdstr != '\n') /* should not happen */
- bb_error_msg_and_die("A/I/C backslash not followed by NL?");
- cmdstr++; /* skip over the NL following the backslash */
+ for(;;) {
+ if(*cmdstr=='\n' || *cmdstr=='\\') {
+ cmdstr++;
+ break;
+ } else if(isspace(*cmdstr)) cmdstr++;
+ else break;
+ }
sed_cmd->string = bb_xstrdup(cmdstr);
parse_escapes(sed_cmd->string,sed_cmd->string,strlen(cmdstr),0,0);
cmdstr += strlen(cmdstr);
More information about the busybox-cvs
mailing list