Open aureliojargas opened 10 years ago
Solution B is not correct. The last matched address is unknown before execution. In this very example, it has changed once the loop began: first it was e
then f
. Being a preprocessor, sedsed can't figure that out.
It seems the same bug affects test/gnused/recall.sed
. It's skipped in the run
script.
This sed script is taken from the BSD sed test-suite:
This GNU sed execution shows the expected behavior.
In the first pass it changes the first
e
toX
and the seconde
toY
. Then it starts a loop (commandb
) until no moref
is found. Inside this loop, thes//Y/p
matches onef
and changes it toY
.Note that the
s
pattern is empty, meaning that the last matched pattern should be used. In this case, it'sf
, matched by the loop conditional/f/ b x
. Here lies the sedsed problem, demonstrated below. When using sedsed, the last matched pattern ise
instead off
, causing an infinite loop:It's a tricky problem to solve.
Currently, sedsed adds extra
s///
debug commands that alter the "last matched pattern" state:Solution A: do not use
s///
commands for the debug messages. But how to show the pattern space contents with aPATT:
prefix without usings
?Solution B: reset the last matched address before every command with a bogus (and harmless) command such as
/address/ { ; }
. BTW, I'm already doing something similar to preserve the "last substitution status" used by thet
command.Solution C: any ideas?