When a range command is first evaluated on a line after its numeric first
address (inside a block, or after d, n, N, c or a branch skipped it), start
the range on the current line, as GNU sed does, unless a numeric second
address has also been passed. The range can start this way only once.
Fixes#541
The substitution and transliteration compilers read the delimiter with
ScriptCharProvider::current() even when the command letter was the last
character on the line. This indexed past the end of the line and
aborted.
Check for the end of the line first and report an unterminated command,
as GNU sed does. Scripts such as `s`, `1y`, and `p;s` now exit 1 with a
diagnostic instead of aborting.
The address-parser aborts from #570 were fixed separately in #578.
When stderr is a terminal (or UUTILS_DIAG=always), quote the offending
script line and underline the faulty character, in the layout uucore's
diagnostics use. Pipes and the test suite still get the single-line
message.
Both error constructors handle this, so no call site changes.
ScriptLocation now carries the line text, captured only when diagnostics
are on and shared between commands from the same line, so semantic
errors raised after compilation can still be drawn.
Anything that cannot be drawn (non-UTF-8 script, empty line, no line
recorded) leaves the message unchanged.
A range address that ended early made the parser panic: `1~` read past
the end of the line, and `1~p`, `1,~p` or `1,p` handed a command letter
to the address parser, which only knew how to panic on it. A missing
~step now counts as 0, and a comma with no address after it is reported
as an unexpected `,'. The address parser returns an error instead of
panicking.
A step of 0 was not handled either: `2,~0` ran to the end of the input
instead of selecting line 2 alone, and `0~0`, which can select no line,
was accepted.
sed -i with more than one file treated them as one continuous stream:
line numbers continued across files, $ matched only the last line of
the last file, and N could join lines from different files. GNU sed
documents -i as implying -s, so enable separate-file processing for
--in-place as well as --separate.
There was a second bug when automatic output was suppressed. At the end
of a file, process_file cleared a pending N action only when
!context.quiet. With -n, the action carried into the next file and
joined with its first line. Clear the action in either mode, but write
the pattern space only when automatic output is enabled.
The same bug can be reproduced without -i. With f1 containing a1, a2,
a3 and f2 containing b1, b2, b3:
sed -n -s -e 'N;s/\n/+/;p' f1 f2
Before this change it prints a1+a2, a3+b1, b2+b3. GNU prints a1+a2,
b1+b2.
Add coverage for line numbers, $, ranges, N across file boundaries,
hold space, Q, backup suffixes, and -n.
The R command reads one line at a time from a named file. All R commands
naming the same file share a single cursor so they read successive lines,
matching GNU sed. Rejected under --sandbox like the other file commands.
Includes unit and integration tests. Makes the GNU sed testsuite `cmd-R`
test pass.
Adjust `l` command to list Unicode characters by default as
octal byte sequences of the corresponding UTF-8 bytes.
A new -U --uutil-extensions option allows listing them
with the common Unicode \u and \U hex escapes.
Replace `NamedTempFile` with a regular file inside a `TempDir`, so the
file is closed and can be renamed or replaced by in-place editing on
Windows. `TempDir` also simplifies cleanup by automatically removing
the file, backup, and directory when dropped.