81 Commits

Author SHA1 Message Date
Devel 508d74fe4a Show usage when invoked without argments
* exit with code 1 when no arguments
* add a test for no arguments.
* Update test_sed.rs
* cargo fmt
* pass -n for missing script arguments test

Issue: #274
PR: #409
2026-06-02 18:37:35 +03:00
mukunda katta 142e70bd13 fix: reject empty text commands 2026-05-15 13:11:51 -07:00
LoukasPap 433635b583 Fix --separate flag 2026-05-03 13:28:03 +02:00
Daniel Hofstetter 7e7abc9407 tests.rs: adapt to ctor change 2026-05-03 13:22:23 +02:00
LoukasPap b7072cb4a5 Fix \?, \+ and \| to be treated as ERE in BRE mode 2026-04-30 22:05:25 +02:00
pocopepe d7a713e3c8 fix: correct newline handling for p and x commands 2026-04-23 08:44:58 +02:00
LoukasPap 5e9b821d80 Set max addresses to 2 for a, i and = and make n_addr conditional, based on POSIX flag
- Update `get_cmd_spec()` and `get_verified_cmd_spec()` to accept a boolean POSIX param
- Add unit and high level tests
- Update README.md
2026-03-19 22:21:56 +01:00
Alexander Wang 22abe5ea6c Preserve new line on exchanges (x) with empty hold spaces. (#259)
* fix: remove newline swap in exchange and swap content only

* fix: support non empty hold spaces and newline appended hold spaces

* nit: period in comment

* nit: useless comment removal

* chore: clarify newline swap logic for `x`
2026-02-13 10:36:51 +01:00
LoukasPap 361c45e6c3 Add test cases 2026-02-08 18:48:17 +01:00
Diomidis Spinellis 8039955354 Add support for GNU ~step address ranges 2026-01-28 08:40:54 +01:00
Diomidis Spinellis a0d82d678d Support ranges starting from line 0
This is a GNU extension that starts the range as latched.
While at it, also fix the handling of ranges straddling independent
files.
2026-01-28 08:40:54 +01:00
Sylvestre Ledru 35b6e84c16 Add unit test for issue #143 (newline behavior with -e p command) 2026-01-11 15:11:56 +01:00
Diomidis Spinellis e40ddb1c99 Add Mandelbrot set drawing 2025-12-30 11:40:09 +02:00
Diomidis Spinellis 8c840078c5 Add Bach prelude as an integration test
Thanks to: Olga Ustiuzhanina @laserbat for providing a suitable license.
2025-12-30 11:40:09 +02:00
Diomidis Spinellis 11f235d6f0 Use regex::bytes also for Unicode matching
Keep using regex_fancy for regexes containing backreferences.
This removes a complex unneeded matcher selection RE and also
provides an overall small performance boost.

     access-log-no-del pre-use-bytes is  1.02 times faster than use-re-bytes
    access-log-all-del use-re-bytes is  1.02 times faster than pre-use-bytes
   access-log-translit pre-use-bytes     is similarly fast as   use-re-bytes
access-log-complex-sub pre-use-bytes     is similarly fast as   use-re-bytes
     access-log-append pre-use-bytes     is similarly fast as   use-re-bytes
             remove-cr use-re-bytes is  1.08 times faster than pre-use-bytes
          genome-subst use-re-bytes is  1.05 times faster than pre-use-bytes
            number-fix pre-use-bytes is  1.02 times faster than use-re-bytes
           long-script use-re-bytes is  1.01 times faster than pre-use-bytes
                 hanoi pre-use-bytes     is similarly fast as   use-re-bytes
             factorial use-re-bytes is  1.03 times faster than pre-use-bytes

Suggested by: Andrew Gallant @BurntSushi
2025-12-16 21:07:09 +01:00
Sylvestre Ledru 8b6ff1d86a generate the sed binary directly 2025-12-14 18:07:22 +01:00
veju e64fc4bf0b adds testing 2025-12-13 19:29:06 +05:30
Diomidis Spinellis 65d319766c Improve performance with copy_file_range(2)
On file systems supporting reflinks or extent remapping, such
as XFS, Btrfs, NFS, regions of files that are not modified are
processed without any copying — with O(1) cost.

While at it:

- Correct the use of write(2) to handle partial writes and
  report appropriate errors.

- Improve buffer sizing.

These are the benchmark results
           no-op-short copy-file-range is  1.17 times faster than main
      access-log-no-op copy-file-range is  2.91 times faster than main
   access-log-no-subst copy-file-range is  1.56 times faster than main
      access-log-subst copy-file-range is  1.03 times faster than main
     access-log-no-del copy-file-range is  1.59 times faster than main
    access-log-all-del copy-file-range is  1.06 times faster than main
   access-log-translit copy-file-range is  1.05 times faster than main
access-log-complex-sub copy-file-range is  1.04 times faster than main
     access-log-append copy-file-range is  1.05 times faster than main
             remove-cr copy-file-range is  1.03 times faster than main
          genome-subst copy-file-range is  1.08 times faster than main
            number-fix copy-file-range is  1.03 times faster than main
           long-script         main     is similarly fast as   copy-file-range
                 hanoi         main is  1.03 times faster than copy-file-range
             factorial copy-file-range is  1.03 times faster than main

On suported file systems (XFS, BTRFS), output files with no or few in-place
modifications share large blocks with the input file, as can be seen
in the following example.

$ xfs_io -c 'fiemap -v' lines.txt
lines.txt:
 EXT: FILE-OFFSET      BLOCK-RANGE         TOTAL FLAGS
   0: [0..857199]:     11917304..12774503 857200 0x2000
   1: [857200..857207]: 12774504..12774511      8   0x1
2025-09-22 15:51:36 +03:00
Daniel Hofstetter 2d3b245981 test: remove two unused imports 2025-09-10 07:34:28 +02:00
Diomidis Spinellis 8ff9dd1e25 Implement silent comment command 2025-08-10 01:29:38 +03:00
Diomidis Spinellis 9f679cd974 Make c tests produce full output
This improves testing fidelity.
2025-07-27 13:21:59 +03:00
Diomidis Spinellis fc2047f4d1 Remove reverse range POSIX TODO item
All versions of sed now behave the same.
2025-07-27 13:21:59 +03:00
Diomidis Spinellis 80a7d0288c Support GNU syntax for the a, c, i commands
The original POSIX behavior is now available under --posix.

Issue: #86
2025-07-27 13:21:59 +03:00
Diomidis Spinellis f734ba3078 Error with script and input file/line when needed 2025-07-08 17:37:59 +03:00
Diomidis Spinellis 46a0f78218 Move script location outside fast_regex
Instead, detect and handle runtime errors at the point where regex
methods are called.

This is always faster or the same as the preceding method.

           no-op-short current is  1.03 times faster than preceding
      access-log-no-op current     is similarly fast as   preceding
   access-log-no-subst current is  1.05 times faster than preceding
      access-log-subst current     is similarly fast as   preceding
     access-log-no-del current is  1.05 times faster than preceding
    access-log-all-del current is  1.04 times faster than preceding
   access-log-translit current     is similarly fast as   preceding
access-log-complex-sub current     is similarly fast as   preceding
             remove-cr current is  1.03 times faster than preceding
          genome-subst current     is similarly fast as   preceding
            number-fix current     is similarly fast as   preceding
           long-script current is  1.01 times faster than preceding
                 hanoi current is  1.02 times faster than preceding
             factorial current     is similarly fast as   preceding

Also, this rectified most performance pessimization introduced by adding
error locations in fast_regex.

           no-op-short previous  is  1.07 times faster than error-loc
      access-log-no-op previous     is similarly fast as    error-loc
   access-log-no-subst error-loc is  1.04 times faster than previous
      access-log-subst previous     is similarly fast as    error-loc
     access-log-no-del error-loc is  1.03 times faster than previous
    access-log-all-del error-loc is  1.04 times faster than previous
   access-log-translit previous  is  1.06 times faster than error-loc
access-log-complex-sub error-loc is  1.02 times faster than previous
             remove-cr previous     is similarly fast as    error-loc
          genome-subst previous  is  1.04 times faster than error-loc
            number-fix previous  is  1.06 times faster than error-loc
           long-script previous     is similarly fast as    error-loc
                 hanoi previous     is similarly fast as    error-loc
             factorial previous     is similarly fast as    error-loc

TODO: In fast_regex distinguish between UTF-8 conversion and regex
errors.  The former should be reported as I/O errors with input file
location info, which the latter should be reported as script errors
with script file location info.
2025-07-08 17:37:59 +03:00