[BusyBox] Re: [patch] Simplify the heck out of the sed newline hack.

Glenn McGrath bug1 at optushome.com.au
Thu Sep 25 13:34:10 UTC 2003


On Thu, 25 Sep 2003 04:55:29 -0500
Rob Landley <rob at landley.net> wrote:

> Okay, instead of turning the length two string "\n" into a length
> three string "\\n", why not just turn the \n into an ascii 10 in the
> search pattern, and rip out the conversion/reversion stuff on the
> strings we're testing against?
>
> The following patch does that.  It fixes some bugs I encountered in
> the binutils build from the newline hackage basically screwing things
> up (the test case I posted earlier tonight), AND makes the code
> smaller and simpler.  I don't think it needs to be conditional anymore
> (it isn't in gnu), but I haven't touched menuconfig.
> 
> Treat with extreme skepticism: it worked for me configuring binutils
> (leaving me with the "s/blah/blah/;$s/blah/blah/" bug that's still
> blocking, but as far as I know that's the ONLY remaining bug, and the
> newline matches seem to be working), but I'm not entirely sure what
> the code I'm ripping out was trying to accomplish, so...

hmm, it doesnt fix it for me as this example shows, ill add this test to
the testsuite.

$ echo -e "a\nb" | sed 'N;s/a\nb/cd/'
cd
$ echo -e "a\nb" | ./busybox sed 'N;s/a\nb/cd/'
a
b
$

Does the above example work for you, from the looks of your patch it
still requires libc to be able to match on a '\n', are you using glibc
or uclibc ?

(I just realised the -e option for echo is needed to interpret escaped
characters, i.e. to treat \n as a single newline character.)

Also, a hint for debugging sed, the '=' command prints the current line
number, its usefull when working with the N command. The second example
shows that "foo\nbar" is in the pattern space at the same time rather
than being treated as seperate lines as in the first example.

$ echo -e "foo\nbar\nbaz" |sed '='
1
foo
2
bar
3
baz
$ echo -e "foo\nbar\nbaz" |sed '=;N'
1
foo
bar
3
baz


Glenn



More information about the busybox mailing list