119 Commits
Author SHA1 Message Date
Anthony DePasquale 96afb29187 sed: test q newline behavior with explicit printing 2026-10-10 19:55:31 +02:00
Anthony DePasquale 7db579b0b8 sed: don't write a missing final newline on Q, as GNU sed does 2026-10-10 19:55:31 +02:00
sap1110 cccbcec479 fixup! sed: start a range whose numeric first address was already passed 2026-10-10 16:09:45 +02:00
sap1110 443b085fb9 sed: start a range whose numeric first address was already passed
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
2026-10-10 16:09:45 +02:00
Sylvestre Ledru 10fa717ee9 sed: report where an unmatched { was opened 2026-10-10 16:08:53 +02:00
Sichen e6829c3d16 compiler: report an unterminated s or y command instead of aborting
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.
2026-10-06 11:19:59 +02:00
Anthony DePasquale 8a7fc1bed9 sed: write appended text, R text and e output as GNU sed does 2026-10-05 22:21:04 +02:00
Anthony DePasquale d43d4dea6b sed: discard text queued by a, r and R on Q, as GNU sed does 2026-10-05 12:34:05 +02:00
Anthony DePasquale 479c4bedf0 sed: show an empty pattern space as $ in l, even without a newline 2026-10-05 00:14:25 +02:00
Anthony DePasquale 3676eac374 sed: name the two ways n and N read the next line, and test n with -i 2026-10-03 13:11:26 -04:00
Anthony DePasquale 8ba5a5f440 sed: continue with the next command after n instead of starting a new cycle 2026-10-03 13:11:26 -04:00
Daniel Hofstetter 111347950e clippy: fix warnings from assert_is_empty lint 2026-10-02 08:20:21 -04:00
Anthony DePasquale 75fbaca15b sed: leave other options' values alone when rewriting -i 2026-09-29 16:45:34 -04:00
Anthony DePasquale e40667ffc5 sed: take the -i suffix only when attached, as GNU sed does 2026-09-29 16:45:34 -04:00
Sylvestre Ledru a05d74344e sed: underline the offending script character at a terminal
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.
2026-09-27 20:55:01 +02:00
Sylvestre Ledru b451333205 sed: keep script position for errors at end of script 2026-09-27 20:54:49 +02:00
Sylvestre Ledru 72ed709088 sed: fix panics and zero steps in ~ and , addresses
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.
2026-09-27 16:44:36 +02:00
Sichen ab2f0a82d8 in-place editing: treat each file as a separate input
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.
2026-09-25 15:16:35 +02:00
Jorge Polanco e5474abccf sed: implement the GNU R command (read one line from a file)
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.
2026-09-25 09:00:25 +02:00
Diomidis Spinellis f1c5813aa4 Make Unicode listing GNU-sed compatible (#537)
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.
2026-08-29 23:24:09 +02:00
Diomidis SpinellisandMukunda Katta b038f8fb2d Implement GNU W (write pattern first line) command (#531)
While at it, also fix the w command on patterns missing a newline.

Co-authored-by: Mukunda Katta <mukunda.vjcs6@gmail.com>
2026-08-26 16:29:57 +02:00
Diomidis SpinellisandSylvestre Ledru e858951814 Add tests for non-pattern print on deletion
Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
2026-08-21 09:51:57 +02:00
Diomidis Spinellis 76efad4aa1 Fix failing test under Windows (#529)
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.
2026-08-20 10:07:47 +02:00
Diomidis Spinellis 3f72f93c5d Support F (output filename) command (#528)
This also requires storing input_name as PathBuf to avoid lossy
conversions when outputting an OS-specific byte sequence representing
the file name.
2026-08-19 12:20:27 +02:00
Mukunda Rao Katta 91465e566b fix: identify uutils in cli output (#435) 2026-08-09 00:55:37 +02:00