ed: Restore newlines in match() - sbase - suckless unix tools
 (HTM) git clone git://git.suckless.org/sbase
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit f6a1fbb9b1c6b5058371daeeb903a7e7a3643bbd
 (DIR) parent beb6a2fa2aeaa9791738510097231e7e9da45f47
 (HTM) Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
       Date:   Mon,  8 Dec 2025 17:54:10 +0100
       
       ed: Restore newlines in match()
       
       Match was removing the trailing newline to fix some problems
       in regex, but this modified the content of the line making
       that the output file had embedded NUL characters (and obviously
       no newlines).
       
       Diffstat:
         M ed.c                                |       7 ++++++-
         A tests/0008-ed.sh                    |      18 ++++++++++++++++++
       
       2 files changed, 24 insertions(+), 1 deletion(-)
       ---
 (DIR) diff --git a/ed.c b/ed.c
       @@ -442,9 +442,14 @@ compile(int delim)
        static int
        match(int num)
        {
       +        int r;
       +
                lastmatch = gettxt(num);
                text.str[text.siz - 2] = '\0';
       -        return !regexec(pattern, lastmatch, 10, matchs, 0);
       +        r =!regexec(pattern, lastmatch, 10, matchs, 0);
       +        text.str[text.siz - 2] = '\n';
       +
       +        return r;
        }
        
        static int
 (DIR) diff --git a/tests/0008-ed.sh b/tests/0008-ed.sh
       @@ -0,0 +1,18 @@
       +#!/bin/sh
       +
       +set -e
       +
       +tmp=tmp.$$
       +
       +trap 'rm -f $tmp' EXIT
       +trap 'rm -f $tmp; kill -KILL $$' HUP INT TERM
       +
       +../ed <<EOF > /dev/null
       +0a
       +This is important
       +.
       +s/^@//
       +w $tmp
       +EOF
       +
       +echo 'This is important' | diff -u - $tmp