├── .prev-version ├── doc ├── s-texi ├── sed-dummy.1 ├── config.texi ├── local.mk └── dummy-man ├── gnulib-tests └── Makefile.am ├── .gitattributes ├── ChangeLog-2014 ├── testsuite ├── 8bit.inp ├── 8bit.sh ├── 8bit.good ├── mac-mf.good ├── mac-mf.sed ├── no-perl ├── uniq.sed ├── word-delim.sh ├── uniq.sh ├── follow-symlinks-stdin.sh ├── mac-mf.sh ├── in-place-hyphen.sh ├── madding.sh ├── bsd-wrapper.sh ├── get-mb-cur-max.c ├── colon-with-no-label.sh ├── inplace-hold.sh ├── title-case.sh ├── range-overlap.sh ├── posix-mode-bad-ref.sh ├── subst-mb-incomplete.sh ├── CuSkip.pm ├── unbuffered.sh ├── help.sh ├── stdin-prog.sh ├── stdin.sh ├── missing-filename.sh ├── xemacs.sh ├── temp-file-cleanup.sh ├── regex-errors.sh ├── distrib.inp ├── bug32271-1.sh ├── badenc.sh ├── newline-dfa-bug.sh ├── invalid-mb-seq-UMR.sh ├── newjis.sh ├── envvar-check ├── cmd-R.sh ├── cmd-0r.sh ├── binary.sh ├── mb-match-slash.sh ├── dc.sh ├── regex-max-int.sh ├── posix-mode-N.sh ├── posix-mode-ERE.sh ├── recursive-escape-c.sh ├── in-place-suffix-backup.sh ├── posix-char-class.sh ├── inplace-selinux.sh ├── posix-mode-s.sh ├── normalize-text.sh ├── cmd-l.sh ├── nulldata.sh ├── xemacs.inp ├── xemacs.good ├── comment-n.sh ├── sandbox.sh ├── posix-mode-addr.sh ├── eval.sh ├── bug32082.sh ├── 8to7.sh ├── follow-symlinks.sh ├── subst-replacement.sh ├── CuTmpdir.pm ├── mb-bad-delim.sh ├── panic-tests.sh ├── bug32271-2.sh ├── subst-options.sh ├── obinary.sh ├── distrib.sh ├── command-endings.sh ├── utf8-ru.sh ├── compile-tests.sh ├── mb-y-translate.sh ├── mb-charclass-non-utf8.sh ├── execute-tests.sh └── convert-number.sh ├── .gitmodules ├── po ├── POTFILES.in ├── .gitignore └── ChangeLog-2014 ├── AUTHORS ├── thanks-gen ├── .mailmap ├── lib ├── local.mk └── .gitignore ├── README ├── .gitignore ├── sed ├── local.mk ├── utils.h └── mbcs.c ├── bootstrap.conf ├── THANKS.in ├── basicdefs.h ├── m4 └── .gitignore ├── README-hacking └── Makefile.am /.prev-version: -------------------------------------------------------------------------------- 1 | 4.9 2 | -------------------------------------------------------------------------------- /doc/s-texi: -------------------------------------------------------------------------------- 1 | stamp 2 | -------------------------------------------------------------------------------- /gnulib-tests/Makefile.am: -------------------------------------------------------------------------------- 1 | include gnulib.mk 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ChangeLog merge=merge-changelog 2 | -------------------------------------------------------------------------------- /ChangeLog-2014: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirror/sed/HEAD/ChangeLog-2014 -------------------------------------------------------------------------------- /testsuite/8bit.inp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirror/sed/HEAD/testsuite/8bit.inp -------------------------------------------------------------------------------- /testsuite/8bit.sh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirror/sed/HEAD/testsuite/8bit.sh -------------------------------------------------------------------------------- /testsuite/8bit.good: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirror/sed/HEAD/testsuite/8bit.good -------------------------------------------------------------------------------- /testsuite/mac-mf.good: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirror/sed/HEAD/testsuite/mac-mf.good -------------------------------------------------------------------------------- /testsuite/mac-mf.sed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirror/sed/HEAD/testsuite/mac-mf.sed -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "gnulib"] 2 | path = gnulib 3 | url = https://git.savannah.gnu.org/git/gnulib 4 | -------------------------------------------------------------------------------- /po/POTFILES.in: -------------------------------------------------------------------------------- 1 | lib/copy-acl.c 2 | lib/dfa.c 3 | lib/error.c 4 | lib/obstack.c 5 | lib/quotearg.c 6 | lib/regcomp.c 7 | lib/set-acl.c 8 | lib/version-etc.c 9 | lib/xalloc-die.c 10 | sed/compile.c 11 | sed/execute.c 12 | sed/regexp.c 13 | sed/sed.c 14 | sed/utils.c 15 | -------------------------------------------------------------------------------- /testsuite/no-perl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Perl is not available, the test should be considered skipped. 3 | # FD 9 should have been opened by the test suite harness, pointing 4 | # to the original stderr (usually, the user's terminal). 5 | echo "test skipped: no usable version of Perl found" >&9 6 | exit 77 7 | -------------------------------------------------------------------------------- /po/.gitignore: -------------------------------------------------------------------------------- 1 | *.gmo 2 | *.po 3 | *~ 4 | /.reference/ 5 | /LINGUAS 6 | /Makefile.in.in 7 | /Makevars 8 | /Makevars.template 9 | /POTFILES 10 | /Rules-quot 11 | /boldquot.sed 12 | /en@boldquot.header 13 | /en@quot.header 14 | /insert-header.sin 15 | /quot.sed 16 | /remove-potcdate.sed 17 | /remove-potcdate.sin 18 | /sed.pot 19 | /stamp-po 20 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | GNU Sed was first authored by Jay Fenlason (hack@gnu.org) 2 | and later modified by Tom Lord (lord@gnu.org). 3 | 4 | Ken Pizzini (ken@gnu.org) and Paolo Bonzini (bonzini@gnu.org) 5 | took over and maintained it for many years. 6 | 7 | GNU Sed is currently being maintained by Jim Meyering (jim@meyering.net) 8 | and Assaf Gordon (agn@gnu.org). 9 | -------------------------------------------------------------------------------- /testsuite/uniq.sed: -------------------------------------------------------------------------------- 1 | h 2 | 3 | :b 4 | # On the last line, print and exit 5 | $b 6 | N 7 | /^\(.*\)\n\1$/ { 8 | # The two lines are identical. Undo the effect of 9 | # the n command. 10 | g 11 | bb 12 | } 13 | 14 | # If the @code{N} command had added the last line, print and exit 15 | $b 16 | 17 | # The lines are different; print the first and go 18 | # back working on the second. 19 | P 20 | D 21 | -------------------------------------------------------------------------------- /thanks-gen: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -nl 2 | # Use Perl's multi-byte alignment code, via sprintf, while 3 | # performing a rudimentary check for duplicate names and 4 | # removing duplicate name,email pairs. 5 | use Encode; 6 | 7 | BEGIN { my (%seen, %name) } 8 | 9 | chomp; 10 | my ($name, $email) = split '\0', decode ('UTF-8', $_); 11 | 12 | $seen{$name}++ 13 | and warn "$0: THANKS.in: duplicate name: $name\n"; 14 | 15 | print encode ('UTF-8', sprintf ('%-36s', $name)), $email 16 | unless $seen{"$name\0$email"}++; 17 | -------------------------------------------------------------------------------- /doc/sed-dummy.1: -------------------------------------------------------------------------------- 1 | .TH SED "1" "VERSION" "User Commands" 2 | .SH NAME 3 | sed \- stream editor for filtering and transforming text 4 | .SH SYNOPSIS 5 | .B sed 6 | [\fIOPTION\fR]... \fI{script-only-if-no-other-script} \fR[\fIinput-file\fR]... 7 | .SH DESCRIPTION 8 | .B OOOPS! 9 | .B sed 10 | manual page could not be built (missing perl or 11 | cross-compilation). 12 | .PP 13 | For the full documentation for 14 | .B sed 15 | see 16 | .UR https://www.gnu.org/software/sed 17 | GNU SED Website (https://www.gnu.org/software/sed) 18 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | # Map git author names and email addresses to canonical/preferred form. 2 | 3 | 4 | 5 | Paul Eggert 6 | Paul Eggert 7 | 8 | 9 | 10 | 11 | 12 | # Consolidate upper/lower case email 13 | 14 | -------------------------------------------------------------------------------- /testsuite/word-delim.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Exercise the DFA regression in sed-4.6. 3 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 4 | print_ver_ sed 5 | 6 | require_en_utf8_locale_ 7 | 8 | # Also ensure that this works in both the C locale and that multibyte one. 9 | # In the C locale, it failed due to a dfa.c regression in sed-4.6. 10 | echo 123-x > in || framework_failure_ 11 | echo 123 > exp || framework_failure_ 12 | 13 | for locale in C en_US.UTF-8; do 14 | LC_ALL=$locale sed 's/.\bx//' in > out 2>err || fail=1 15 | compare exp out || fail=1 16 | compare /dev/null err || fail=1 17 | done 18 | 19 | Exit $fail 20 | -------------------------------------------------------------------------------- /lib/local.mk: -------------------------------------------------------------------------------- 1 | # Copyright 1997-2024 Free Software Foundation, Inc. 2 | # 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation; either version 3, or (at your option) 6 | # any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | # 16 | 17 | include lib/gnulib.mk 18 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This is the GNU implementation of sed, the Unix stream editor. 2 | 3 | GNU Sed website: https://www.gnu.org/software/sed/ 4 | 5 | See the NEWS file for a brief summary and the ChangeLog for 6 | more detailed descriptions of changes. 7 | 8 | If you obtained this file as part of a "git clone", then see the 9 | README-hacking file. If this file came to you as part of a tar archive, 10 | then see the file INSTALL for compilation and installation instructions. 11 | 12 | See the file BUGS for instructions about reporting bugs. 13 | 14 | See the files AUTHORS and THANKS for a list of authors and other contributors. 15 | 16 | See the file COPYING for copying conditions. 17 | 18 | After installation run 'sed --help' or 'man sed' for short usage information, 19 | and 'info sed' for the complete manual. The manual is also available on 20 | sed's website. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.exe 3 | *.gcda 4 | *.gcno 5 | *.gz 6 | *.o 7 | *.sig 8 | *.xz 9 | *~ 10 | +* 11 | .deps/ 12 | .dirstamp 13 | /.version 14 | /ABOUT-NLS 15 | /ChangeLog 16 | /GNUmakefile 17 | /INSTALL 18 | /README-release 19 | /THANKS 20 | /aclocal.m4 21 | /autom4te.cache 22 | /confdefs.h 23 | /config.cache 24 | /config.h 25 | /config.log 26 | /config.status 27 | /config_h.in 28 | /configure 29 | /conftest* 30 | /doc/.gitignore 31 | /doc/coverage/ 32 | /doc/sed.1 33 | /doc/sed.aux 34 | /doc/sed.cp 35 | /doc/sed.cps 36 | /doc/sed.fn 37 | /doc/sed.fns 38 | /doc/sed.info 39 | /doc/sed.ky 40 | /doc/sed.log 41 | /doc/sed.op 42 | /doc/sed.pdf 43 | /doc/sed.pg 44 | /doc/sed.t2p/ 45 | /doc/sed.toc 46 | /doc/sed.tp 47 | /doc/sed.vr 48 | /doc/stamp-vti 49 | /doc/version.texi 50 | /gnulib-tests/ 51 | !/gnulib-tests/Makefile.am 52 | /maint.mk 53 | /sed-[4-9]* 54 | /sed/sed 55 | /sed/version.[ch] 56 | /stamp-h1 57 | /testsuite/*.log 58 | /testsuite/*.out 59 | /testsuite/*.trs 60 | /testsuite/eval.in2 61 | /testsuite/get-mb-cur-max 62 | /testsuite/init.sh 63 | /testsuite/test-mbrtowc 64 | Makefile 65 | Makefile.in 66 | gt-bug* 67 | test-suite.log 68 | -------------------------------------------------------------------------------- /testsuite/uniq.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Test runner for the uniq.sed script 4 | 5 | # Copyright (C) 2017-2024 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 20 | print_ver_ sed 21 | 22 | # location of the external SED scripts 23 | dir="$abs_top_srcdir/testsuite" 24 | 25 | sed -f "$dir/uniq.sed" < "$dir/uniq.inp" > out || fail=1 26 | remove_cr_inplace out 27 | compare "$dir/uniq.good" out || fail=1 28 | 29 | 30 | Exit $fail 31 | -------------------------------------------------------------------------------- /testsuite/follow-symlinks-stdin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Verify that --follow-symlinks does not break reading from stdin. 3 | 4 | # Copyright (C) 2015-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | echo dbc > exp-out || framework_failure_ 22 | 23 | echo abc | sed --follow-symlinks s/a/d/ > out 2> err || fail=1 24 | 25 | compare exp-out out || fail=1 26 | compare /dev/null err || fail=1 27 | 28 | Exit $fail 29 | -------------------------------------------------------------------------------- /testsuite/mac-mf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Runner for old 'mac-mf' test 4 | 5 | # Copyright (C) 2017-2024 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 20 | print_ver_ sed 21 | 22 | # location of external test files 23 | dir="$abs_top_srcdir/testsuite" 24 | 25 | sed -f "$dir/"mac-mf.sed "$dir/mac-mf.inp" > mac-mf-out || fail=1 26 | remove_cr_inplace mac-mf-out 27 | compare "$dir/mac-mf.good" mac-mf-out || fail=1 28 | 29 | 30 | Exit $fail 31 | -------------------------------------------------------------------------------- /testsuite/in-place-hyphen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Verify that "-" is treated as a file name with --in-place. 3 | 4 | # Copyright (C) 2015-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | echo abc > ./- || framework_failure_ 22 | echo aXc > exp-out || framework_failure_ 23 | 24 | sed -i 's/b/X/' - > out 2> err || fail=1 25 | 26 | compare exp-out ./- || fail=1 27 | compare /dev/null err || fail=1 28 | 29 | Exit $fail 30 | -------------------------------------------------------------------------------- /testsuite/madding.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Runner for old 'madding' test (long lines) 4 | 5 | # Copyright (C) 2017-2024 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 20 | print_ver_ sed 21 | 22 | # location of external test files 23 | dir="$abs_top_srcdir/testsuite" 24 | 25 | sed -f "$dir/"madding.sed "$dir/madding.inp" > madding-out || fail=1 26 | remove_cr_inplace madding-out 27 | compare "$dir/madding.good" madding-out || fail=1 28 | 29 | 30 | Exit $fail 31 | -------------------------------------------------------------------------------- /testsuite/bsd-wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Test runner for the old bsd tests 4 | 5 | # Copyright (C) 2017-2024 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 20 | print_ver_ sed 21 | 22 | # location of the external SED scripts 23 | dir="$abs_top_srcdir/testsuite" 24 | 25 | # The 'bsd.sh' script runs multiple tests and generates sed.out file. 26 | sh "$dir/bsd.sh" || fail=1 27 | remove_cr_inplace sed.out 28 | compare "$dir/bsd.good" sed.out || fail=1 29 | 30 | 31 | Exit $fail 32 | -------------------------------------------------------------------------------- /testsuite/get-mb-cur-max.c: -------------------------------------------------------------------------------- 1 | /* Auxiliary program to detect support for a locale. 2 | Copyright 2010-2024 Free Software Foundation, Inc. 3 | 4 | This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 3, or (at your option) 7 | any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; If not, see . */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "progname.h" 23 | 24 | int 25 | main (int argc, char **argv) 26 | { 27 | set_program_name (argv[0]); 28 | if (1 < argc && setlocale (LC_ALL, argv[1])) 29 | { 30 | printf ("%d\n", (int) MB_CUR_MAX); 31 | exit (EXIT_SUCCESS); 32 | } 33 | 34 | exit (EXIT_FAILURE); 35 | } 36 | -------------------------------------------------------------------------------- /testsuite/colon-with-no-label.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Verify that a ":" command with no label is now rejected. 3 | 4 | # Copyright (C) 2015-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | echo 'sed: -e expression #1, char 1: ":" lacks a label' > exp-err \ 22 | || framework_failure_ 23 | 24 | # Before sed-4.3, sed would mistakenly accept a ":" with no following 25 | # label name. 26 | echo x | returns_ 1 sed : > out 2> err || fail=1 27 | 28 | compare /dev/null out || fail=1 29 | compare exp-err err || fail=1 30 | 31 | Exit $fail 32 | -------------------------------------------------------------------------------- /testsuite/inplace-hold.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Test runner for old 'inplace-hold' test 4 | 5 | # Copyright (C) 2017-2024 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 20 | print_ver_ sed 21 | 22 | echo > inplace-hold-exp || framework_failure_ 23 | 24 | echo x > inplace-hold-out1 || framework_failure_ 25 | echo y > inplace-hold-out2 || framework_failure_ 26 | 27 | sed -i x inplace-hold-out1 inplace-hold-out2 || fail=1 28 | 29 | compare inplace-hold-exp inplace-hold-out1 || fail=1 30 | compare inplace-hold-exp inplace-hold-out2 || fail=1 31 | 32 | Exit $fail 33 | -------------------------------------------------------------------------------- /testsuite/title-case.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test case insensitive matching for titlecase and similarly odd chars. 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | require_el_iso88597_locale_ 22 | 23 | a='\323' # SIGMA 24 | b='\362' # stigma 25 | c='\363' # sigma 26 | 27 | printf "$a\\n$b\\n$c\\n" >in || framework_failure_ 28 | for chr in "$a" "$b" "$c"; do 29 | printf '/()\\1'"$chr"/Ip >prog || fail=1 30 | LC_ALL=el_GR.iso88597 sed -r -n -f prog in >out || fail=1 31 | compare_ in out || fail=1 32 | done 33 | 34 | Exit $fail 35 | -------------------------------------------------------------------------------- /testsuite/range-overlap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Verify that even with overlapping ranges of line numbers, 3 | # only the selected lines are affected. 4 | 5 | # Copyright (C) 2015-2024 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 20 | print_ver_ sed 21 | 22 | printf '%s\n' 1 2 3 4 5 6 > in || framework_failure_ 23 | printf '%s\n' 1 5 6 > exp || framework_failure_ 24 | 25 | # Before sed-4.3, this would mistakenly modify line 5 like this: 26 | # 1 27 | # yx5 28 | # 6 29 | sed '2,4d;2,3s/^/x/;3,4s/^/y/' in > out 2> err || framework_failure_ 30 | 31 | compare exp out || fail=1 32 | compare /dev/null err || fail=1 33 | 34 | Exit $fail 35 | -------------------------------------------------------------------------------- /testsuite/posix-mode-bad-ref.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test non-posix-conforming gnu extensions when using --posix. 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | cat <<\EOF >exp-err || framework_failure_ 22 | sed: -e expression #1, char 10: invalid reference \1 on 's' command's RHS 23 | EOF 24 | 25 | # Invalid references are errors in non-posix mode 26 | returns_ 1 sed 's/abc/\1/g' 2>err < /dev/null || fail=1 27 | compare_ exp-err err || fail=1 28 | 29 | # Invalid references are silently ignored in posix mode 30 | sed --posix 's/abc/\1/g' < /dev/null || fail=1 31 | 32 | Exit $fail 33 | -------------------------------------------------------------------------------- /testsuite/subst-mb-incomplete.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Ensure that sed no longer writes beyond the end of a heap buffer when 3 | # performing a substitution with a replacement string containing an 4 | # incomplete multi-byte character. 5 | 6 | # Copyright (C) 2015-2024 Free Software Foundation, Inc. 7 | 8 | # This program is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program. If not, see . 20 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 21 | print_ver_ sed 22 | 23 | require_en_utf8_locale_ 24 | 25 | echo > in || framework_failure_ 26 | printf '\233\375\200\n' > exp-out || framework_failure_ 27 | 28 | LC_ALL=en_US.utf8 sed $(printf 's/^/\\L\233\375\\\200/') in > out 2> err 29 | 30 | compare exp-out out || fail=1 31 | compare /dev/null err || fail=1 32 | 33 | Exit $fail 34 | -------------------------------------------------------------------------------- /testsuite/CuSkip.pm: -------------------------------------------------------------------------------- 1 | package CuSkip; 2 | # Skip a test: emit diag to log and to stderr, and exit 77 3 | 4 | # Copyright (C) 2011-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | use strict; 20 | use warnings; 21 | 22 | our $ME = $0 || ""; 23 | 24 | # Emit a diagnostic both to stderr and to $stderr_fileno_. 25 | # FIXME: don't hard-code that value (9), since it's already defined in init.cfg. 26 | sub skip ($) 27 | { 28 | my ($msg) = @_; 29 | my $stderr_fileno_ = 9; 30 | warn $msg; 31 | open FH, ">&$stderr_fileno_" 32 | or warn "$ME: failed to dup stderr\n"; 33 | print FH $msg; 34 | close FH 35 | or warn "$ME: failed to close FD $stderr_fileno_\n"; 36 | exit 77; 37 | } 38 | 39 | 1; 40 | -------------------------------------------------------------------------------- /testsuite/unbuffered.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test -u/--unbuffered option 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | printf "1\n2\n" > in1 || framework_failure_ 22 | 23 | # expected output for both programs 24 | printf "1\n" >> exp || framework_failure_ 25 | 26 | 27 | # in unbuffered mode, 28 | # sed should consume and print the first line, 29 | # wc should see the rest of the input (second line). 30 | # The second sed trims optional leading whitespace. 31 | ( sed -u 1q > out-sed ; wc -l | sed 's/^ *//' > out-wc ) < in1 32 | 33 | compare_ exp out-sed || fail=1 34 | compare_ exp out-wc || fail=1 35 | 36 | 37 | Exit $fail 38 | -------------------------------------------------------------------------------- /testsuite/help.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Test --help screen 4 | 5 | # Copyright (C) 2017-2024 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 20 | print_ver_ sed 21 | 22 | # Help screen should include the contact email address 23 | sed --help | grep E-mail > /dev/null 2>&1 || fail=1 24 | 25 | 26 | # With explicit --help - show usage then email at the bottom. 27 | # With missing parameters - show the usage without the email. 28 | # Ensure these are identical (except for the email). 29 | sed --help \ 30 | | sed '1s/ [^ ]* / sed /; /^E-mail/,$d' > help-out1 31 | 32 | sed 2>&1 \ 33 | | sed '1s/ [^ ]* / sed /' > help-out2 34 | 35 | compare help-out1 help-out2 || fail=1 36 | 37 | 38 | Exit $fail 39 | -------------------------------------------------------------------------------- /testsuite/stdin-prog.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test program file from STDIN 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | echo X > in1 || framework_failure_ 22 | printf "1\nX\n" > exp1 || framework_failure_ 23 | 24 | # program filename starts with '-' 25 | printf "=\n" > ./-myprog || framework_failure_ 26 | 27 | 28 | # program from STDIN 29 | printf "=\n" | sed -f - in1 > out1 || fail=1 30 | compare_ exp1 out1 || fail=1 31 | 32 | # program filename starting with '-' 33 | # (if a buggy sed reads from STDIN, the 'v9' command will fail) 34 | printf "v9\n" | sed -f -myprog in1 > out2 || fail=1 35 | compare_ exp1 out2 || fail=1 36 | 37 | Exit $fail 38 | -------------------------------------------------------------------------------- /testsuite/stdin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Test runner for old 'stdin' test 4 | 5 | # Copyright (C) 2017-2024 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 20 | print_ver_ sed 21 | 22 | 23 | cat << \EOF > stdin-in || framework_failure_ 24 | foo foo fo oo f oo foo foo foo foo foo foo foo foo foo foo foo foo foo 25 | foo foo fo oo f oo foo foo foo foo foo foo foo foo foo foo foo foo foo 26 | EOF 27 | 28 | # This checks for a bug in 3.02 and 3.02.80 29 | ( sed d ; sed G ) < stdin-in > stdin-out1 || fail=1 30 | cat stdin | ( sed d ; sed G ) > stdin-out2 || fail=1 31 | 32 | remove_cr_inplace stdin-out1 33 | remove_cr_inplace stdin-out2 34 | 35 | compare stdin-out1 stdin-out2 || fail=1 36 | 37 | Exit $fail 38 | -------------------------------------------------------------------------------- /testsuite/missing-filename.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test r/R/w/W commands without a file name. 3 | 4 | # Copyright (C) 2018-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | # Same error message, different character position in the sed program. 22 | for i in 1 7 ; do 23 | err="sed: -e expression #1, char $i: missing filename in r/R/w/W commands" 24 | echo "$err" > exp-err$i || framework_failure_ 25 | done 26 | 27 | # r/R/w/W commands 28 | for cmd in r R w W ; do 29 | returns_ 1 sed $cmd /dev/null 2>err1 || fail=1 30 | compare exp-err1 err1 || fail=1 31 | done 32 | 33 | returns_ 1 sed 's/1/2/w' /dev/null 2>err7 || fail=1 34 | compare exp-err7 err7 || fail=1 35 | 36 | Exit $fail 37 | -------------------------------------------------------------------------------- /testsuite/xemacs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Test runner for xemacs.sed 4 | 5 | # Copyright (C) 2017-2024 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 20 | print_ver_ sed 21 | 22 | # location of external test files 23 | dir="$abs_top_srcdir/testsuite" 24 | 25 | # Inspired by xemacs' config.status script 26 | # submitted by John Fremlin (john@fremlin.de) 27 | cat << \EOF > xemacs.sed || framework_failure_ 28 | /^# Generated/d 29 | s%/\*\*/#.*%% 30 | s/^ *# */#/ 31 | /^##/d 32 | /^#/ { 33 | p 34 | d 35 | } 36 | /./ { 37 | s/\([\"]\)/\\\1/g 38 | s/^/"/ 39 | s/$/"/ 40 | } 41 | EOF 42 | 43 | 44 | sed -f xemacs.sed < "$dir/xemacs.inp" > out || fail=1 45 | remove_cr_inplace out 46 | compare "$dir/xemacs.good" out || fail=1 47 | 48 | 49 | Exit $fail 50 | -------------------------------------------------------------------------------- /testsuite/temp-file-cleanup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Verify that an erroneous use of sed -i no longer leaves behind 3 | # a temporary file. 4 | 5 | # Copyright (C) 2015-2024 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 20 | print_ver_ sed 21 | 22 | # The input file must have at least one line. 23 | echo > in || framework_failure_ 24 | printf 'sed: -e expression #1, char 0: no previous regular expression\n' \ 25 | > exp || framework_failure_ 26 | 27 | # Before sed-4.3, this would create a file named sed?????? 28 | returns_ 1 sed -i s//b/ in > out 2> err || fail=1 29 | 30 | compare /dev/null out || fail=1 31 | compare exp err || fail=1 32 | 33 | # Ensure that no other file has been created in this directory. 34 | files=$(echo *) 35 | test "$files" = "err exp in out" || fail=1 36 | 37 | Exit $fail 38 | -------------------------------------------------------------------------------- /po/ChangeLog-2014: -------------------------------------------------------------------------------- 1 | 2004-11-11 Paolo Bonzini 2 | 3 | * Makevars: New. 4 | 5 | 2004-11-02 gettextize 6 | 7 | * Makefile.in.in: Upgrade to gettext-0.10.40. 8 | 9 | 2002-10-26 Paolo Bonzini 10 | 11 | * po/*.po: updated from Translation Project 12 | 13 | 2001-10-19 gettextize 14 | 15 | * Makefile.in.in: Upgrade to gettext-0.10.40. 16 | * cat-id-tbl.c: Remove file. 17 | * stamp-cat-id: Remove file. 18 | 19 | 2001-03-02 Paolo Bonzini 20 | 21 | * po/it.po: updated 22 | * po/sed.pot: likewise. 23 | 24 | 2000-12-10 Paolo Bonzini 25 | 26 | * po/it.po: Italian translation reviewed for new POT file. 27 | * po/sed.pot: updated 28 | 29 | Mon Mar 15 16:25:53 PST 1999 Ken Pizzini 30 | 31 | * po/it.po: new translation file. 32 | 33 | Sun Feb 7 21:22:17 PST 1999 Ken Pizzini 34 | 35 | * po/de.po: new translation file. 36 | 37 | Sat Dec 12 11:18:55 PST 1998 Ken Pizzini 38 | 39 | * po/ru.po: new translation file. 40 | 41 | Sun Dec 6 00:51:23 PST 1998 Ken Pizzini 42 | 43 | * po/fr.po: new translation file. 44 | 45 | Sun Aug 16 02:59:20 PDT 1998 Ken Pizzini 46 | 47 | * sed/compile.c: added N_() markers and corresponding gettext() 48 | (er, _()) calls. 49 | * po/sed.pot: updated to reflect changed and newly marked text. 50 | 51 | 1998-07-24 Erick Branderhorst 52 | 53 | * po/nl.po: Dutch translation. 54 | -------------------------------------------------------------------------------- /testsuite/regex-errors.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Exercise regex_compile errors 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | # 22 | # Invalid backref in address regex 23 | # 24 | cat <<\EOF >exp-err-inv-backref || framework_failure_ 25 | sed: -e expression #1, char 4: Invalid back reference 26 | EOF 27 | 28 | returns_ 1 sed '/\1/,$p' err-inv-backref || fail=1 29 | compare_ exp-err-inv-backref err-inv-backref || fail=1 30 | 31 | 32 | # 33 | # modifiers on empty regex (BAD_MODIF in regex.c) 34 | # 35 | cat <<\EOF >exp-err-bad-modif || framework_failure_ 36 | sed: -e expression #1, char 3: cannot specify modifiers on empty regexp 37 | EOF 38 | 39 | returns_ 1 sed '//M,$p' err-bad-modif || fail=1 40 | compare_ exp-err-bad-modif err-bad-modif || fail=1 41 | 42 | 43 | Exit $fail 44 | -------------------------------------------------------------------------------- /testsuite/distrib.inp: -------------------------------------------------------------------------------- 1 | From crash@cygnus.com Wed Mar 8 18:02:42 1995 2 | Received: from s1.msi.umn.edu (s1.msi.umn.edu [128.101.24.1]) by cygnus.com (8.6.9/8.6.9) with ESMTP id SAA21692 for ; Wed, 8 Mar 1995 18:02:41 -0800 3 | Received: from cygint.cygnus.com (cygint.cygnus.com [140.174.1.1]) by s1.msi.umn.edu (8.6.10/8.6.9) with ESMTP id TAA13398 for ; Wed, 8 Mar 1995 19:59:18 -0600 4 | Received: from phydeaux.cygnus.com (phydeaux.cygnus.com [140.174.1.85]) by cygnus.com (8.6.9/8.6.9) with SMTP id SAA21688 for ; Wed, 8 Mar 1995 18:02:33 -0800 5 | From: Jason Molenda 6 | Received: by phydeaux.cygnus.com (5.65/4.7) id AA06931; Wed, 8 Mar 1995 18:02:28 -0800 7 | Message-Id: <9503090202.AA06931@phydeaux.cygnus.com> 8 | Subject: Note for sed testsuite 9 | To: molenda@msi.umn.edu 10 | Date: Wed, 8 Mar 1995 18:02:24 -0800 (PST) 11 | X-Mailer: ELM [version 2.4 PL23] 12 | 13 | _Summum Bonum_ 14 | 15 | All the breath and the bloom of the 16 | year in the bag of one bee: 17 | All the wonder and wealth of the mine in 18 | the heart of one gem: 19 | In the core of one pearl all the shade and the 20 | shine of the sea: 21 | Breath and bloom, shade and shine, -- wonder, 22 | wealth, and -- how far above them -- 23 | Truth, thats brighter than gem, 24 | Trust, that's purer than pearl, -- 25 | Brightest truth, purest trust in the universe -- 26 | all were for me 27 | In the kiss of one girl. 28 | -- Robert Browning 29 | -------------------------------------------------------------------------------- /testsuite/bug32271-1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # sed would incorrectly copy internal buffers under certain s/// uses. 3 | # Before sed 4.6 these would result in an extraneous NUL at end of lines. 4 | # 5 | 6 | # Copyright (C) 2018-2024 Free Software Foundation, Inc. 7 | 8 | # This program is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program. If not, see . 20 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 21 | print_ver_ sed 22 | 23 | printf '0\n' > in || framework_failure_ 24 | printf '0\n' > exp || framework_failure_ 25 | 26 | # Before sed 4.6, this would result in: 0x30 0x00 0x0a. 27 | sed -e 's/$/a/2' in > out 2> err || fail=1 28 | 29 | compare exp out || fail=1 30 | compare /dev/null err || fail=1 31 | 32 | # To ease debugging / error reporting (the above 'compare' 33 | # will report "binary files differ" - not very helpful here) 34 | if test -n "$fail" ; then 35 | echo "---- TEST FAILED" 36 | echo "out:" 37 | od -tx1 out 38 | echo "exp:" 39 | od -tx1 exp 40 | echo "err:" 41 | od -tx1 err 42 | fi 43 | 44 | 45 | Exit $fail 46 | -------------------------------------------------------------------------------- /testsuite/badenc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Test runner for old 'badenc' test 4 | 5 | # Copyright (C) 2017-2024 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 20 | print_ver_ sed 21 | 22 | require_en_utf8_locale_ 23 | 24 | # The input (and also the expected output) 25 | # containing an invalid multibyte sequences in utf-8 (octet \320 = 0xD0). 26 | printf "abc\nde\320f\nghi\njkl\nmno\npqr\nstu\nvwx\nyz\n" > badenc-inp \ 27 | || framework_failure_ 28 | 29 | 30 | # The progarm: using 'z' to clear the pattern-space even 31 | # if it contains invalid multibyte sequences. 32 | # Using 's/.*//' would not be able to clear the pattern-space. 33 | cat << \EOF > badenc.sed || framework_failure_ 34 | /.*/ { H ; g ; s/\n// ; p ; z ; x } 35 | EOF 36 | 37 | 38 | env LC_ALL=en_US.UTF-8 sed -nf badenc.sed badenc-inp > badenc-out || fail=1 39 | remove_cr_inplace badenc-out 40 | compare badenc-inp badenc-out || fail=1 41 | 42 | 43 | Exit $fail 44 | -------------------------------------------------------------------------------- /testsuite/newline-dfa-bug.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # sed may access to uninitialized memory if transit to 15th dfa state 3 | # with newline. This bug affected sed version 4.3. 4 | 5 | # Copyright (C) 2017-2024 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 20 | print_ver_ sed 21 | 22 | require_valgrind_ 23 | 24 | printf 'abcdefg abcdefg\nB\n' > in || framework_failure_ 25 | printf 'B\n' > exp || framework_failure_ 26 | 27 | valgrind --quiet --error-exitcode=1 \ 28 | sed 'N;s/abcdefg.*\n//' in > out 2> err || fail=1 29 | 30 | # Work around a bug in CentOS 5.10's valgrind 31 | # FIXME: remove in 2018 or when CentOS 5 is no longer officially supported 32 | grep 'valgrind: .*Assertion.*failed' err > /dev/null \ 33 | && skip_ 'you seem to have a buggy version of valgrind' 34 | 35 | # Remove any valgrind-added diagnostics from stderr. 36 | sed -i '/^==/d' err 37 | 38 | compare exp out || fail=1 39 | compare /dev/null err || fail=1 40 | 41 | Exit $fail 42 | -------------------------------------------------------------------------------- /testsuite/invalid-mb-seq-UMR.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Inserting an invalid multibyte sequence could lead to 3 | # reading uninitialized memory. 4 | 5 | # Copyright (C) 2015-2024 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 20 | print_ver_ sed 21 | 22 | require_valgrind_ 23 | 24 | test "$LOCALE_JA" = none && skip_ found no Japanese EUC locale 25 | 26 | # Ensure the implementation is not buggy (skip otherwise) 27 | require_valid_ja_eucjp_locale_ "$LOCALE_JA" 28 | 29 | echo a > in || framework_failure_ 30 | printf 'b\262C\n' > exp || framework_failure_ 31 | LC_ALL=$LOCALE_JA valgrind --quiet --error-exitcode=1 \ 32 | sed 's/a/b\U\xb2c/' in > out 2> err || fail=1 33 | 34 | # Work around a bug in CentOS 5.10's valgrind 35 | # FIXME: remove in 2018 or when CentOS 5 is no longer officially supported 36 | grep 'valgrind: .*Assertion.*failed' err > /dev/null \ 37 | && skip_ 'you seem to have a buggy version of valgrind' 38 | 39 | compare exp out || fail=1 40 | compare /dev/null err || fail=1 41 | 42 | Exit $fail 43 | -------------------------------------------------------------------------------- /testsuite/newjis.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Test runner for newjis 4 | 5 | # Copyright (C) 2017-2024 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 20 | print_ver_ sed 21 | 22 | # Input file. \033 is ASCII escape (0x1B). 23 | { 24 | printf '\033$B$H$J$j$N$?$1$,$-$K\033(B\n' ; 25 | printf '\033$B$?$F$+$1$?$N$O\033(B\n' ; 26 | printf '\033$B$?$F$+$1$?$+$C$?$+$i\033(B\n' ; 27 | printf '\033$B$?$F$+$1$?!#\033(B\n' ; 28 | } > newjis-inp || framework_failure_ 29 | 30 | # The expected output. 31 | { 32 | printf '\033$B$H$J$j$NM9JX6I$K\033(B\n'; 33 | printf '\033$B$?$F$+$1$?$N$O\033(B\n' ; 34 | printf '\033$B$?$F$+$1$?$+$C$?$+$i\033(B\n' ; 35 | printf '\033$B$?$F$+$1$?!#\033(B\n' ; 36 | } > newjis-exp || framework_failure_ 37 | 38 | # The sed program. 39 | cat <<\EOF > newjis.sed || framework_failure_ 40 | s/$?$1$,$-/M9JX6I/ 41 | EOF 42 | 43 | sed -f newjis.sed < newjis-inp > newjis-out || fail=1 44 | remove_cr_inplace newjis-out 45 | compare newjis-exp newjis-out || fail=1 46 | 47 | 48 | Exit $fail 49 | -------------------------------------------------------------------------------- /testsuite/envvar-check: -------------------------------------------------------------------------------- 1 | # -*- sh -*- 2 | # Check environment variables for sane values while testing. 3 | 4 | # Copyright (C) 2000-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | if (FOO=FOO; unset FOO) >/dev/null 2>&1; then 20 | as_unset=unset 21 | else 22 | as_unset=false 23 | fi 24 | 25 | envvar_check_fail=0 26 | vars=' 27 | _POSIX2_VERSION 28 | _STDBUF_E 29 | _STDBUF_I 30 | _STDBUF_O 31 | BASH_ENV 32 | BLOCKSIZE 33 | BLOCK_SIZE 34 | CDPATH 35 | COLS 36 | COLUMNS 37 | DF_BLOCK_SIZE 38 | DU_BLOCK_SIZE 39 | ENV 40 | LANGUAGE 41 | LS_BLOCK_SIZE 42 | LS_COLORS 43 | OMP_NUM_THREADS 44 | POSIXLY_CORRECT 45 | QUOTING_STYLE 46 | SIMPLE_BACKUP_SUFFIX 47 | TABSIZE 48 | TERM 49 | COLORTERM 50 | TIME_STYLE 51 | TMPDIR 52 | VERSION_CONTROL 53 | ' 54 | for var in $vars 55 | do 56 | $as_unset $var 57 | if eval test \"\${$var+set}\" = set; then 58 | echo "$0: the $var environment variable is set --" \ 59 | ' unset it and rerun this test' >&2 60 | envvar_check_fail=1 61 | fi 62 | done 63 | 64 | test "$envvar_check_fail" = 1 && exit 1 65 | -------------------------------------------------------------------------------- /testsuite/cmd-R.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test 'R' command 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | printf "%s\n" x y > a || framework_failure_ 22 | printf "%s\n" 1 2 > b || framework_failure_ 23 | printf "%s\n" X > c || framework_failure_ 24 | touch d || framework_failure_ 25 | 26 | # Read and interleave two lines 27 | printf "%s\n" x 1 y 2 > exp1 || framework_failure_ 28 | sed -e 1Rb -e 2Rb a > out1 || fail=1 29 | compare_ exp1 out1 || fail=1 30 | 31 | # Read a non-existing file, silently ignored 32 | sed -e 1Rq a > out2 || fail=1 33 | compare_ a out2 34 | 35 | # Read two lines from a file, second time will be EOF 36 | # (implementation note: EOF from get_delim()) 37 | printf "%s\n" x X y > exp3 || framework_failure_ 38 | sed -e 1Rc -e 2Rc a > out3 || fail=1 39 | compare_ exp3 out3 || fail=1 40 | 41 | # Read two lines from an empty file, both will be EOF 42 | # (implementation note: EOF in before get_delim()) 43 | sed -e 1Rd -e 2Rd a > out4 || fail=1 44 | compare_ a out4 || fail=1 45 | 46 | 47 | Exit $fail 48 | -------------------------------------------------------------------------------- /testsuite/cmd-0r.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test '0rFILE' command 3 | 4 | # Copyright (C) 2021-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | cat <<\EOF >in1 || framework_failure_ 22 | HELLO 23 | WORLD 24 | EOF 25 | 26 | cat <<\EOF >in2 || framework_failure_ 27 | 1 28 | 2 29 | 3 30 | EOF 31 | 32 | cat <<\EOF >exp1 || framework_failure_ 33 | HELLO 34 | WORLD 35 | 1 36 | 2 37 | 3 38 | EOF 39 | 40 | cat <<\EOF >exp2 || framework_failure_ 41 | 1 42 | HELLO 43 | WORLD 44 | 2 45 | HELLO 46 | WORLD 47 | 3 48 | EOF 49 | 50 | cat <<\EOF> exp-err-addr0 || framework_failure_ 51 | sed: -e expression #1, char 4: invalid usage of line address 0 52 | EOF 53 | 54 | # Typical usage 55 | sed '0rin1' in2 >out1 || fail=1 56 | compare_ exp1 out1 || fail=1 57 | 58 | # Ensure no regression for '0,/REGEXP/r' 59 | sed '0,/2/rin1' in2 >out2 || fail=1 60 | compare_ exp2 out2 || fail=1 61 | 62 | # Ensure '0r' doesn't accept a numeric address range 63 | returns_ 1 sed '0,4rin1' in2 2>err3 || fail=1 64 | compare_ exp-err-addr0 err3 || fail=1 65 | 66 | # Test with -i 67 | sed -i '0rin1' in2 || fail=1 68 | compare_ exp1 in2 || fail=1 69 | 70 | Exit $fail 71 | -------------------------------------------------------------------------------- /testsuite/binary.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Test runner for the binary-operation version of dc.sed. 4 | # Adapted from old-style 'binary.sed' test. 5 | 6 | # Copyright (C) 2017-2024 Free Software Foundation, Inc. 7 | 8 | # This program is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program. If not, see . 20 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 21 | print_ver_ sed 22 | 23 | cat << \EOF > inp || framework_failure_ 24 | 192.168.1.2 br b8dpP 16>11111111& dpP 8>11111111& dpP 11111111& dpP 27 | | DDD 24>dpP 16>11111111& dpP 8>11111111& dpP 11111111& dpP 28 | EOF 29 | 30 | 31 | cat << \EOF > exp || framework_failure_ 32 | 192 33 | 168 34 | 1 35 | 0 36 | 192 37 | 168 38 | 1 39 | 255 40 | EOF 41 | 42 | 43 | # location of the external SED scripts 44 | dir="$abs_top_srcdir/testsuite" 45 | 46 | 47 | # Run the three variations of the sed script 48 | sed -n -f "$dir/binary.sed" < inp > out1 || fail=1 49 | remove_cr_inplace out1 50 | compare exp out1 || fail=1 51 | 52 | sed -n -f "$dir/binary2.sed" < inp > out2 || fail=1 53 | remove_cr_inplace out2 54 | compare exp out2 || fail=1 55 | 56 | sed -n -f "$dir/binary3.sed" < inp > out3 || fail=1 57 | remove_cr_inplace out3 58 | compare exp out3 || fail=1 59 | 60 | 61 | Exit $fail 62 | -------------------------------------------------------------------------------- /testsuite/mb-match-slash.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test slash following an incomplete multibyte character 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | require_en_utf8_locale_ 22 | 23 | # before sed-4.3, a slash following an incomplete multibyte character 24 | # would be ignored during program compilation, leading to an error. 25 | 26 | 27 | # Test 1: match_slash in 's' command. 28 | # Before sed-4.3, this would fail with "unterminated `s' command". 29 | printf 's/\316/X/' > p1 || framework_failure_ 30 | LC_ALL=en_US.UTF-8 sed -f p1 out1 || fail=1 31 | compare_ /dev/null out1 || fail=1 32 | 33 | # Test 2: match_slash in address regex. 34 | # Before sed-4.3, this would fail with "unterminated address regex". 35 | printf '/\316/p' >p2 || framework_failure_ 36 | LC_ALL=en_US.UTF-8 sed -f p2 out2 || fail=1 37 | compare_ /dev/null out2 || fail=1 38 | 39 | # Test 3: match_slash in 'y' command.. 40 | # Before sed-4.3, this would fail with "unterminated `y' command". 41 | printf 'y/\316/X/' >p3 || framework_failure_ 42 | LC_ALL=en_US.UTF-8 sed -f p3 out3 || fail=1 43 | compare_ /dev/null out3 || fail=1 44 | 45 | 46 | Exit $fail 47 | -------------------------------------------------------------------------------- /doc/config.texi: -------------------------------------------------------------------------------- 1 | @dircategory Text creation and manipulation 2 | @direntry 3 | * sed: (sed). Stream EDitor. 4 | 5 | @end direntry 6 | 7 | @clear PERL 8 | @set SSEDEXT GNU extensions 9 | @set SSED GNU @command{sed} 10 | 11 | @c Ugly hack to enable using new texinfo commands '@codequotebacktick' 12 | @c and '@codequoteundirected' or define empty fallbacks if they are 13 | @c not available. 14 | 15 | @ifclear txicommandconditionals 16 | @c If we got here, this is a REALLY old texinfo (pre 5.0), 17 | @c and '@ifcommandnotdefined' is not defined. 18 | @c Assume these commands are not defined as well. 19 | @macro codequotebacktick 20 | @end macro 21 | @macro codequoteundirected 22 | @end macro 23 | @end ifclear 24 | 25 | @ifset txicommandconditionals 26 | @c if we got here, this texinfo supports checking for defined 27 | @c commands. If these commands aren't available - define empty 28 | @c fallbacks. 29 | @ifcommandnotdefined codequotebacktick 30 | @macro codequotebacktick 31 | @end macro 32 | @macro codequoteundirected 33 | @end macro 34 | @end ifcommandnotdefined 35 | @end ifset 36 | 37 | 38 | @c define variables that will render as characters 39 | @c on both HTML (with @U{}) and PDF (with greek symbols). 40 | @c Use with: @value{ucsigma} 41 | @c 42 | @c Based on: 43 | @c https://lists.gnu.org/archive/html/help-texinfo/2012-06/msg00004.html 44 | @iftex 45 | @set ucsigma @math{@Sigma{}} 46 | @end iftex 47 | @ifnottex 48 | @set ucsigma @U{03A3} 49 | @end ifnottex 50 | 51 | @iftex 52 | @set lcsigma @math{@sigma{}} 53 | @end iftex 54 | @ifnottex 55 | @set lcsigma @U{03C3} 56 | @end ifnottex 57 | 58 | @c Unicode Replacement Character (U+FFFD): 59 | @c no easy/portable tex equivalent, so use another 60 | @c distinct symbol (which will be rendered very differently 61 | @c than ascii characters in @examples. 62 | @iftex 63 | @set unicodeFFFD @math{@otimes{}} 64 | @end iftex 65 | @ifnottex 66 | @set unicodeFFFD @U{FFFD} 67 | @end ifnottex 68 | -------------------------------------------------------------------------------- /testsuite/dc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Test runner for dc.sed 4 | 5 | # Copyright (C) 2017-2024 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 20 | print_ver_ sed 21 | 22 | # Compute Easter of 2002... 23 | # usage: (echo YEAR; cat easter.dc) | dc.sed 24 | cat << \EOF > easter.dc || framework_failure_ 25 | [ddsf[lfp[too early 26 | ]Pq]s@1583>@ 27 | ddd19%1+sg100/1+d3*4/12-sx8*5+25/5-sz5*4/lx-10-sdlg11*20+lz+lx-30% 28 | d[30+]s@0>@d[[1+]s@lg11<@]s@25=@d[1+]s@24=@se44le-d[30+]s@21>@dld+7%-7+ 29 | [March ]smd[31-[April ]sm]s@31<@psnlmPpsn1z>p]splpx 30 | EOF 31 | 32 | cat <<\EOF > easter-exp || framework_failure_ 33 | 31 34 | March 2002 35 | EOF 36 | 37 | 38 | # Compute square root of 2 39 | cat << \EOF > sqrt2-inp || framework_failure_ 40 | 16oAk2vpq 41 | EOF 42 | 43 | 44 | cat << \EOF > sqrt2-exp || framework_failure_ 45 | 1.6A09E667A 46 | EOF 47 | 48 | 49 | # location of external test files 50 | dir="$abs_top_srcdir/testsuite" 51 | 52 | # Easter 2002 53 | ( echo 2002 ; cat easter.dc ) | sed -n -f "$dir/dc.sed" > easter-out|| fail=1 54 | compare easter-exp easter-out || fail=1 55 | 56 | # Square root of 2 57 | sed -n -f "$dir/dc.sed" sqrt2-inp > sqrt2-out || fail=1 58 | compare sqrt2-exp sqrt2-out || fail=1 59 | 60 | 61 | 62 | Exit $fail 63 | -------------------------------------------------------------------------------- /testsuite/regex-max-int.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test regex on input buffers larger than 2GB 3 | 4 | # Copyright (C) 2018-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | very_expensive_ 20 | print_ver_ sed 21 | 22 | # Create a file larger than 2GB and containing a single line 23 | # (resulting in a regex match against the entire file) 24 | # 25 | # This is a "very expensive" test, we can assume it is only run by 26 | # developers or advanced users, and we can assume truncate(1) exists. 27 | # 28 | # On most modern file-systems, the file will be sparse and would not 29 | # consume 2GB of physical storage. 30 | 31 | truncate -s 1G input || framework_failure_ 32 | printf aaaa >> input || framework_failure_ 33 | truncate -s +1G input || framework_failure_ 34 | printf 'a\n' >> input || framework_failure_ 35 | 36 | # The expected error message 37 | cat <<\EOF > exp-err1 || framework_failure_ 38 | sed: regex input buffer length larger than INT_MAX 39 | EOF 40 | 41 | 42 | # Before sed-4.5, this was silently a no-op: would not perform the subsitution 43 | # but would not indicate any error either (https://bugs.gnu.org/30520). 44 | # Exit code 4 is "panic". 45 | returns_ 4 sed 's/a/b/g' input >/dev/null 2>err1 || fail=1 46 | compare_ exp-err1 err1 || fail=1 47 | 48 | Exit $fail 49 | -------------------------------------------------------------------------------- /doc/local.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 2 | 3 | # This program is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation, either version 3 of the License, or 6 | # (at your option) any later version. 7 | 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | 16 | info_TEXINFOS = doc/sed.texi 17 | doc_sed_TEXINFOS = doc/config.texi doc/version.texi doc/fdl.texi 18 | dist_man_MANS = doc/sed.1 19 | dist_noinst_DATA = doc/sed.x doc/sed-dummy.1 20 | HELP2MAN = $(top_srcdir)/build-aux/help2man 21 | SEDBIN = sed/sed 22 | EXTRA_DIST += doc/dummy-man 23 | 24 | # The customization variable CHECK_NORMAL_MENU_STRUCTURE is necessary with 25 | # makeinfo versions ≥ 6.8. 26 | MAKEINFO = @MAKEINFO@ -c CHECK_NORMAL_MENU_STRUCTURE=1 27 | 28 | AM_MAKEINFOHTMLFLAGS = --no-split 29 | 30 | ## Use the distributed man pages if cross compiling or lack perl 31 | if CROSS_COMPILING 32 | run_help2man = $(SHELL) $(srcdir)/doc/dummy-man 33 | else 34 | ## Graceful degradation for systems lacking perl. 35 | if HAVE_PERL 36 | if BOLD_MAN_REFS 37 | help2man_OPTS=--bold-refs 38 | endif 39 | run_help2man = $(PERL) -- $(HELP2MAN) $(help2man_OPTS) 40 | else 41 | run_help2man = $(SHELL) $(srcdir)/doc/dummy-man 42 | endif 43 | endif 44 | 45 | doc/sed.1: sed/sed$(EXEEXT) .version $(srcdir)/doc/sed.x 46 | $(AM_V_GEN)$(MKDIR_P) doc 47 | $(AM_V_at)rm -rf $@ $@-t 48 | $(AM_V_at)$(run_help2man) \ 49 | --info-page=sed \ 50 | --include $(srcdir)/doc/sed.x \ 51 | --output=$@-t \ 52 | $(SEDBIN) \ 53 | && chmod a-w $@-t \ 54 | && mv $@-t $@ 55 | -------------------------------------------------------------------------------- /testsuite/posix-mode-N.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test 'N' command with/without posix conformity 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | # in/exp as identical, but using 'exp' for both input and output 22 | # will cause unneeded confusion when looking at the logs. 23 | printf "A\nB\n" > in1 || framework_failure_ 24 | cp in1 exp1 || framework_failure_ 25 | printf "A\n" > in2 || framework_failure_ 26 | cp in2 exp2 || framework_failure_ 27 | 28 | # If there is a 'next' line, N behaves the same regardless of posixicity 29 | sed N in1 > out1 || fail=1 30 | compare exp1 out1 || fail=1 31 | 32 | sed --posix N in1 > out2 || fail=1 33 | compare exp1 out2 || fail=1 34 | 35 | POSIXLY_CORRECT=y sed N in1 > out3 || fail=1 36 | compare exp1 out3 || fail=1 37 | 38 | 39 | # If there is no 'next' line, 40 | # gnu-N quits with printing 41 | # posix-N quits without printing. 42 | sed N in2 > out4 || fail=1 43 | compare exp2 out4 || fail=1 44 | 45 | sed --posix N in2 > out5 || fail=1 46 | compare /dev/null out5 || fail=1 47 | 48 | POSIXLY_CORRECT=y sed N in2 > out6 || fail=1 49 | compare /dev/null out6 || fail=1 50 | 51 | # exception: gnu-mode N but no default output, should not print anything. 52 | sed -n N in2 > out7 || fail=1 53 | compare /dev/null out7 || fail=1 54 | 55 | 56 | Exit $fail 57 | -------------------------------------------------------------------------------- /doc/dummy-man: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Poor man's placeholder for help2man invocation on systems lacking perl, 3 | # or when cross compiling. 4 | # It just copies the distributed man pages. 5 | 6 | set -e; set -u 7 | 8 | fatal_ () 9 | { 10 | printf '%s: %s\n' "$0" "$*" >&2 11 | exit 1 12 | } 13 | 14 | basename_ () 15 | { 16 | printf '%s\n' "$1" | sed 's,.*/,,' 17 | } 18 | 19 | output= 20 | source="GNU sed" 21 | while test $# -gt 0; do 22 | case $1 in 23 | # Help2man options we recognize and handle. 24 | --output=*) output=`expr x"$1" : x'--output=\(.*\)'`;; 25 | --output) shift; output=$1;; 26 | --include=*) include=`expr x"$1" : x'--include=\(.*\)'`;; 27 | --include) shift; include=$1;; 28 | --source=*) source=`expr x"$1" : x'--source=\(.*\)'`;; 29 | --source) shift; source=$1;; 30 | # Recognize (as no-op) other help2man options that might be used 31 | # in the makefile. 32 | --info-page=*);; 33 | -*) fatal_ "invalid or unrecognized help2man option '$1'";; 34 | --) shift; break;; 35 | *) break;; 36 | esac 37 | shift 38 | done 39 | 40 | test $# -gt 0 || fatal_ "missing argument" 41 | test $# -le 1 || fatal_ "too many non-option arguments" 42 | 43 | dist_man=$(printf '%s\n' "$include" | sed 's/\.x$/.1/') 44 | test -f "$dist_man" && cp "$dist_man" "$output" && exit || : 45 | 46 | baseout=`basename_ "$output"` 47 | sed 's/^/WARNING: /' >&2 <"$output" <. 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | printf "hi+\n" > in1 || framework_failure_ 22 | 23 | printf "{hi+}\n" > exp-special || framework_failure_ 24 | printf "h{i+}\n" > exp-literal || framework_failure_ 25 | 26 | # '+' is special in ERE 27 | sed -E 's/(.+)/{\1}/' in1 > out0 || fail=1 28 | compare_ exp-special out0 || fail=1 29 | 30 | # '+' is special in ERE, even if --posix is used. 31 | # sed-4.4 and earlier did not treat it as special (bug#26409). 32 | sed --posix -E 's/(.+)/{\1}/' in1 > out1 || fail=1 33 | compare_ exp-special out1 || fail=1 34 | 35 | # Escape the '+' it to remove special meaning in ERE 36 | sed --posix -E 's/(.\+)/{\1}/' in1 > out2 || fail=1 37 | compare_ exp-literal out2 || fail=1 38 | 39 | # with BRE and --posix, '+' should have no special meaning 40 | sed --posix 's/\(.+\)/{\1}/' in1 > out3 || fail=1 41 | compare_ exp-literal out3 || fail=1 42 | 43 | # with BRE without --posix, '+' should have no special meaning 44 | sed 's/\(.+\)/{\1}/' in1 > out4 || fail=1 45 | compare_ exp-literal out4 || fail=1 46 | 47 | # with BRE without --posix, '\+' is special (GNU extension) 48 | sed 's/\(.\+\)/{\1}/' in1 > out5 || fail=1 49 | compare_ exp-special out5 || fail=1 50 | 51 | 52 | Exit $fail 53 | -------------------------------------------------------------------------------- /sed/local.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 2 | 3 | # This program is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation, either version 3 of the License, or 6 | # (at your option) any later version. 7 | 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | 16 | bin_PROGRAMS += sed/sed 17 | 18 | localedir = $(datadir)/locale 19 | 20 | sed_sed_SOURCES = \ 21 | sed/compile.c \ 22 | sed/debug.c \ 23 | sed/execute.c \ 24 | sed/mbcs.c \ 25 | sed/regexp.c \ 26 | sed/sed.c \ 27 | sed/utils.c 28 | 29 | noinst_HEADERS += \ 30 | sed/sed.h \ 31 | sed/utils.h 32 | 33 | sed_sed_CPPFLAGS = $(AM_CPPFLAGS) -DLOCALEDIR=\"$(localedir)\" 34 | sed_sed_CFLAGS = $(AM_CFLAGS) $(WARN_CFLAGS) $(WERROR_CFLAGS) 35 | sed_sed_LDADD = sed/libver.a lib/libsed.a \ 36 | $(LIB_ACL) $(QCOPY_ACL_LIB) $(CLOCK_TIME_LIB) $(GETRANDOM_LIB) \ 37 | $(HARD_LOCALE_LIB) $(MBRTOWC_LIB) $(LIB_SELINUX) $(SETLOCALE_NULL_LIB) \ 38 | $(LIBINTL) $(LIBTHREAD) 39 | sed_sed_DEPENDENCIES = lib/libsed.a sed/libver.a 40 | 41 | $(sed_sed_OBJECTS): $(BUILT_SOURCES) 42 | 43 | BUILT_SOURCES += sed/version.c 44 | DISTCLEANFILES += sed/version.c 45 | sed/version.c: Makefile 46 | $(AM_V_GEN)rm -f $@ 47 | $(AM_V_at)printf '#include \n' > $@t 48 | $(AM_V_at)printf 'char const *Version = "$(PACKAGE_VERSION)";\n' >> $@t 49 | $(AM_V_at)chmod a-w $@t 50 | $(AM_V_at)mv $@t $@ 51 | 52 | BUILT_SOURCES += sed/version.h 53 | DISTCLEANFILES += sed/version.h 54 | sed/version.h: Makefile 55 | $(AM_V_GEN)rm -f $@ 56 | $(AM_V_at)printf 'extern char const *Version;\n' > $@t 57 | $(AM_V_at)chmod a-w $@t 58 | $(AM_V_at)mv $@t $@ 59 | 60 | noinst_LIBRARIES += sed/libver.a 61 | nodist_sed_libver_a_SOURCES = sed/version.c sed/version.h 62 | -------------------------------------------------------------------------------- /testsuite/recursive-escape-c.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # test \c escaping 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | unset POSIXLY_CORRECT 22 | export LC_ALL=C 23 | 24 | # input file, any 6 lines would do, each a different test case 25 | printf "%s\n" a a a a a a >in1 || framework_failure_ 26 | 27 | # input program 28 | cat << \EOF > prog1 || framework_failure_ 29 | 1s/./\cA/ 30 | 2s/./\cB/ 31 | 3s/./\c[/ 32 | 4s/./\c]/ 33 | 34 | # '\c' at end-of-buffer, a backslash is pushed up 35 | # on level of interpretation, and the '.' match is replaced 36 | # with one backslash. 37 | 5s/./\c/ 38 | 39 | # This would return incorrect results before 4.3, 40 | # producing both \034 and another backslash. 41 | 6s/./\c\\/ 42 | EOF 43 | 44 | # expected output: 45 | printf '\001\n\002\n\033\n\035\n\\\n\034\n' > exp1 || framework_failure_ 46 | 47 | # 48 | # Run simple test cases 49 | # 50 | sed -f prog1 in1 > out1 || fail=1 51 | compare_ exp1 out1 || fail=1 52 | 53 | # for easier troubleshooting, if users ever report errors 54 | if test "$fail" -eq 1 ; then 55 | od -tx1c prog1 56 | od -tx1c exp1 57 | od -tx1c out1 58 | fi 59 | 60 | # 61 | # Test invalid usage 62 | # 63 | cat << \EOF > exp-err || framework_failure_ 64 | sed: -e expression #1, char 10: recursive escaping after \c not allowed 65 | EOF 66 | 67 | # Before sed-4.3, this resulted in '\034d'. Now, it is rejected. 68 | returns_ 1 sed '1s/./\c\d/' in1 2>err || fail=1 69 | compare_ exp-err err || fail=1 70 | 71 | Exit $fail 72 | -------------------------------------------------------------------------------- /testsuite/in-place-suffix-backup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test -i/--inplace with backup suffixes 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | 22 | # create multiple uniquely-named input files 23 | # (the content does not matter for the first few) 24 | touch a b c d e || framework_failure_ 25 | echo z > z || framework_failure_ 26 | printf "1\nz\n" >> exp-z || framework_failure_ 27 | 28 | 29 | # TODO: misleading error: the problem is the target filename of rename(2), 30 | # not the source filename. 31 | cat <<\EOF >exp-err-rename || framework_failure_ 32 | sed: cannot rename ./e to ./e./e./e: No such file or directory 33 | EOF 34 | 35 | 36 | # simple backup suffix 37 | sed -i.bak = a || fail=1 38 | test -e a.bak || fail=1 39 | 40 | # backup suffix with explicit wildcard 41 | sed -i'*.foo' = b || fail=1 42 | test -e b.foo || fail=1 43 | 44 | sed -i'==*==' = c || fail=1 45 | test -e ==c== || fail=1 46 | 47 | # abuse the suffix-name resolver 48 | sed -i'*=*' = d || fail=1 49 | test -e d=d || fail=1 50 | 51 | # This fails (as expected, with the backup name resolving './e./e./e'). 52 | # TODO: improve error message; 53 | # document why exit code is 4. 54 | returns_ 4 sed -i'***' = ./e 2>err-rename || fail=1 55 | compare_ exp-err-rename err-rename || fail=1 56 | 57 | # backup filename resolving to the same as the input filename, 58 | # silently ignored, backup not created (in execute.c:closedown() ). 59 | sed -i'*' = z || fail=1 60 | # ensure the input file was modified in-place 61 | compare_ exp-z z || fail=1 62 | 63 | 64 | Exit $fail 65 | -------------------------------------------------------------------------------- /sed/utils.h: -------------------------------------------------------------------------------- 1 | /* Functions from hack's utils library. 2 | Copyright (C) 1989-2024 Free Software Foundation, Inc. 3 | 4 | This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 3, or (at your option) 7 | any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; If not, see . */ 16 | 17 | #include 18 | 19 | #include "basicdefs.h" 20 | 21 | enum exit_codes { 22 | /* EXIT_SUCCESS is already defined as 0 */ 23 | EXIT_BAD_USAGE = 1, /* bad program syntax, invalid command-line options */ 24 | EXIT_BAD_INPUT = 2, /* failed to open some of the input files */ 25 | EXIT_PANIC = 4 /* PANIC during program execution */ 26 | }; 27 | 28 | 29 | _Noreturn void panic (const char *str, ...) 30 | _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 2); 31 | 32 | FILE *ck_fopen (const char *name, const char *mode, int fail); 33 | FILE *ck_fdopen (int fd, const char *name, const char *mode, int fail); 34 | void ck_fwrite (const void *ptr, idx_t size, idx_t nmemb, FILE *stream); 35 | idx_t ck_fread (void *ptr, idx_t size, idx_t nmemb, FILE *stream); 36 | void ck_fflush (FILE *stream); 37 | void ck_fclose (FILE *stream); 38 | const char *follow_symlink (const char *path); 39 | ssize_t ck_getdelim (char **text, size_t *buflen, char buffer_delimiter, 40 | FILE *stream); 41 | FILE * ck_mkstemp (char **p_filename, const char *tmpdir, const char *base, 42 | const char *mode) _GL_ARG_NONNULL ((1, 2, 3, 4)); 43 | void ck_rename (const char *from, const char *to); 44 | 45 | void cancel_cleanup (void); 46 | void remove_cleanup_file (void); 47 | 48 | struct buffer *init_buffer (void) _GL_ATTRIBUTE_MALLOC; 49 | char *get_buffer (struct buffer const *b) _GL_ATTRIBUTE_PURE; 50 | idx_t size_buffer (struct buffer const *b) _GL_ATTRIBUTE_PURE; 51 | char *add_buffer (struct buffer *b, const char *p, idx_t n); 52 | char *add1_buffer (struct buffer *b, int ch); 53 | void free_buffer (struct buffer *b); 54 | -------------------------------------------------------------------------------- /testsuite/posix-char-class.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test character-class definitions in POSIX mode. 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | # NOTE: 20 | # In GNU Extension mode, all text is normalized (e.g. backslash-X combinations). 21 | # In POSIX mode, normalize_text() ensures content of character 22 | # classes is not normalized. 23 | # 24 | # Compare: 25 | # $ printf "t\t\n" | sed 's/[\t]/X/' | od -a 26 | # 0000000 t X nl 27 | # $ printf "t\t\n" | sed --posix 's/[\t]/X/' | od -a 28 | # 0000000 X ht nl 29 | # 30 | # This test unit validates the special handling of character classes 31 | # in posix mode (compile.c:normalize_text() implementation). 32 | 33 | 34 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 35 | print_ver_ sed 36 | 37 | echo X > exp || framework_failure_ 38 | 39 | # Closing bracket without opening bracket, match as-is 40 | echo ']' | sed --posix 's/]/X/' > out1 || fail=1 41 | compare_ exp out1 || fail=1 42 | 43 | # Two opening brackets (same state when opening the second one) 44 | echo '[' | sed --posix 's/[[]/X/' > out2 || fail=1 45 | compare_ exp out2 || fail=1 46 | 47 | # Escaping before and after the character class, but not inside it (POSIX MODE) 48 | printf "\tt\t\n" | sed --posix 's/\t[\t]\t/X/' > out3 || fail=1 49 | compare_ exp out3 || fail=1 50 | 51 | # Escaping before, inside, and after the character class (GNU MODE) 52 | printf "\t\t\t\n" | sed 's/\t[\t]\t/X/' > out4 || fail=1 53 | compare_ exp out4 || fail=1 54 | 55 | # Special characters, but outside a valid character-class syntax 56 | printf "=\n" | sed --posix 's/[.=:.]/X/' > out5 || fail=1 57 | compare_ exp out5 || fail=1 58 | 59 | # A valid character class definition 60 | printf "b\n" | sed --posix 's/[[:alpha:]]/X/' > out6 || fail=1 61 | compare_ exp out6 || fail=1 62 | 63 | 64 | 65 | Exit $fail 66 | -------------------------------------------------------------------------------- /testsuite/inplace-selinux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (C) 2017-2024 Free Software Foundation, Inc. 4 | 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 18 | print_ver_ sed 19 | require_selinux_ 20 | 21 | sed --version | grep "with SELinux" > /dev/null \ 22 | || skip_ "sed built without SELinux support" 23 | sed --version | grep "^SELinux is enabled" > /dev/null \ 24 | || skip_ "sed reports SELinux is disabled on this system" 25 | 26 | touch a || framework_failure_ 27 | chcon -u system_u a || skip_ "chcon doesn't work" 28 | chcon -u user_u a || skip_ "chcon doesn't work" 29 | 30 | # Create the first file and symlink pointing at it. 31 | echo "Hello World" > inplace-selinux-file || framework_failure_ 32 | ln -s ./inplace-selinux-file inplace-selinux-link || framework_failure_ 33 | 34 | chcon -h -u system_u inplace-selinux-file || framework_failure_ 35 | chcon -h -u user_u inplace-selinux-link || framework_failure_ 36 | 37 | 38 | # Create the second file and symlink pointing at it. 39 | # These will be used with the --follow-symlink option. 40 | echo "Hello World" > inplace-selinux-file2 || framework_failure_ 41 | ln -s ./inplace-selinux-file2 inplace-selinux-link2 || framework_failure_ 42 | 43 | chcon -h -u system_u inplace-selinux-file2 || framework_failure_ 44 | chcon -h -u user_u inplace-selinux-link2 || framework_failure_ 45 | 46 | # Modify prepared files inplace via the symlinks 47 | sed -i -e "s~Hello~Hi~" inplace-selinux-link || fail=1 48 | sed -i --follow-symlinks -e "s~Hello~Hi~" inplace-selinux-link2 || fail=1 49 | 50 | # Check selinux context - the first file should be created with the context 51 | # of the symlink... 52 | ls -Z inplace-selinux-link | grep user_u: || fail=1 53 | # ...the second file should use the context of the file itself. 54 | ls -Z inplace-selinux-file2 | grep system_u: || fail=1 55 | 56 | Exit $fail 57 | -------------------------------------------------------------------------------- /testsuite/posix-mode-s.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Ensure GNU extensions are rejected in posix mode 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | cat <<\EOF >exp-err || framework_failure_ 22 | sed: -e expression #1, char 7: unknown option to 's' 23 | EOF 24 | 25 | # substitution command options ( 26 | # TODO: conditionally test sSxX in perl mode 27 | for opt in i I m M ; 28 | do 29 | # These options should fail in strict POSIX mode 30 | returns_ 1 sed --posix "s/a/b/$opt" err || fail=1 31 | compare_ exp-err err || fail=1 32 | 33 | # These options are allowed otherwise 34 | sed "s/a/b/$opt" in1 || framework_failure_ 43 | 44 | printf "hello\n" >exp-gnu-e || framework_failure_ 45 | sed 's/./printf hello/e' in1 > out-gnu-e || fail=1 46 | compare exp-gnu-e out-gnu-e || fail=1 47 | 48 | 49 | # s///e rejected in POSIX mode 50 | cat <<\EOF >exp-err-psx-e || framework_failure_ 51 | sed: -e expression #1, char 10: unknown option to 's' 52 | EOF 53 | returns_ 1 sed --posix 's/./echo/e' in1 2>err-posix-e || fail=1 54 | compare_ exp-err-psx-e err-posix-e || fail=1 55 | 56 | 57 | # substitution special commands (e.g \l \L \U \u \E). 58 | # see compile.c:setup_replacement() 59 | printf "a\n" > exp-gnu || framework_failure_ 60 | printf "lA\n" > exp-posix || framework_failure_ 61 | 62 | # gnu-extension: turn the next character to lowercase 63 | sed 's/./\l&/' in1 > out-gnu || fail=1 64 | compare_ exp-gnu out-gnu || fail=1 65 | 66 | # posix: '\l' is just 'l' 67 | sed --posix 's/./\l&/' in1 > out-posix || fail=1 68 | compare_ exp-posix out-posix || fail=1 69 | 70 | 71 | Exit $fail 72 | -------------------------------------------------------------------------------- /testsuite/normalize-text.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Text text escaping (compile.c:normalize_text()). 3 | # NOTE: 4 | # \dNNN \xNN \oNNN - tested in 'convert-number.sh' 5 | # character-classes in POSIX mode - tested in 'posix-char-class.sh' 6 | 7 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 8 | 9 | # This program is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program. If not, see . 21 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 22 | print_ver_ sed 23 | 24 | # 25 | # Common backslash combinations 26 | # 27 | printf "%s\n" a a a a a a >in1 || framework_failure_ 28 | cat <<\EOF >prog1 || framework_failure_ 29 | 1y/a/\a/ 30 | 2y/a/\f/ 31 | 3y/a/\n/ 32 | 4y/a/\r/ 33 | 5y/a/\t/ 34 | 6y/a/\v/ 35 | EOF 36 | printf "\a\n\f\n\n\n\r\n\t\n\v\n" > exp1 || framework_failure_ 37 | 38 | sed -f prog1 in1 > out1 || fail=1 39 | compare_ exp1 out1 || fail=1 40 | 41 | # 42 | # test '\\\n' (backslash followed by ASCII 0x0A) 43 | # normalized to a simple '\n' . 44 | # 45 | echo a > in2 || framework_failure_ 46 | printf "y/a/\\\n/" > prog2 || framework_failure_ 47 | printf "\n\n" > exp2 || framework_failure_ 48 | sed -f prog2 in2 > out2 || fail=1 49 | compare_ exp2 out2 || fail=1 50 | 51 | # 52 | # \cX combination 53 | # 54 | printf "%s\n" a a a a a a a a a a > in3 || framework_failure_ 55 | cat <<\EOF >prog3 || framework_failure_ 56 | 1y/a/\cA/ 57 | 2y/a/\ca/ 58 | 3y/a/\cZ/ 59 | 4y/a/\cz/ 60 | 5y/a/\c{/ 61 | 6y/a/\c;/ 62 | 7y/a/\c#/ 63 | 8y/a/\c[/ 64 | 9y/a/\c\\/ 65 | 10y/a/\c]/ 66 | EOF 67 | 68 | printf "\1\n\1\n\32\n\32\n;\n{\nc\n\33\n\34\n\35\n" > exp3 || framework_failure_ 69 | sed -f prog3 in3 > out3 || fail=1 70 | compare_ exp3 out3 || fail=1 71 | 72 | # \c at end of (valid) text - normalize_text() stops, returns control to caller. 73 | # TODO: is this a bug? 74 | # compare with 'y/a/\d/' and 'y/a/\x/' 75 | cat <<\EOF >exp-err-c || framework_failure_ 76 | sed: -e expression #1, char 7: 'y' command strings have different lengths 77 | EOF 78 | returns_ 1 sed 'y/a/\c/' err-c || fail=1 79 | compare_ exp-err-c err-c || fail=1 80 | 81 | Exit $fail 82 | -------------------------------------------------------------------------------- /sed/mbcs.c: -------------------------------------------------------------------------------- 1 | /* GNU SED, a batch stream editor. 2 | Copyright (C) 2003-2024 Free Software Foundation, Inc. 3 | 4 | This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 3, or (at your option) 7 | any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; If not, see . */ 16 | 17 | #include "sed.h" 18 | #include 19 | #include 20 | 21 | #include "localcharset.h" 22 | 23 | int mb_cur_max; 24 | bool is_utf8; 25 | 26 | /* Return non-zero if CH is part of a valid multibyte sequence: 27 | Either incomplete yet valid sequence (in case of a leading byte), 28 | or the last byte of a valid multibyte sequence. 29 | 30 | Return zero in all other cases: 31 | CH is a valid single-byte character (e.g. 0x01-0x7F in UTF-8 locales); 32 | CH is an invalid byte in a multibyte sequence for the currentl locale, 33 | CH is the NUL byte. 34 | 35 | Reset CUR_STAT in the case of an invalid byte. 36 | */ 37 | int 38 | is_mb_char (int ch, mbstate_t *cur_stat) 39 | { 40 | const char c = ch ; 41 | const int mb_pending = !mbsinit (cur_stat); 42 | const int result = mbrtowc (NULL, &c, 1, cur_stat); 43 | 44 | switch (result) 45 | { 46 | case -2: /* Beginning or middle of valid multibyte sequence */ 47 | return 1; 48 | 49 | case -1: /* Invalid sequence, byte treated like a single-byte character */ 50 | memset (cur_stat, 0, sizeof (mbstate_t)); 51 | return 0; 52 | 53 | case 1: /* A valid byte, check if part of on-going multibyte sequence */ 54 | return mb_pending; 55 | 56 | case 0: /* Special case of mbrtowc(3): the NUL character */ 57 | /* TODO: test this */ 58 | return 1; 59 | 60 | default: /* Should never happen, as per mbrtowc(3) documentation */ 61 | panic ("is_mb_char: mbrtowc (0x%x) returned %d", 62 | (unsigned int) ch, result); 63 | } 64 | } 65 | 66 | void 67 | initialize_mbcs (void) 68 | { 69 | /* For UTF-8, we know that the encoding is stateless. */ 70 | const char *codeset_name; 71 | 72 | codeset_name = locale_charset (); 73 | is_utf8 = (strcmp (codeset_name, "UTF-8") == 0); 74 | 75 | mb_cur_max = MB_CUR_MAX; 76 | } 77 | -------------------------------------------------------------------------------- /testsuite/cmd-l.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test 'l' command with different widths 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | # 10 20 30 40 50 60 70 75 22 | cat <<\EOF >in1 || framework_failure_ 23 | 0123456789012345678901234567890123456789012345678901234567890123456789012345 24 | EOF 25 | 26 | # default: 70 characters (including the \n) 27 | cat <<\EOF >exp-def || framework_failure_ 28 | 012345678901234567890123456789012345678901234567890123456789012345678\ 29 | 9012345$ 30 | EOF 31 | 32 | # 11 characters 33 | cat <<\EOF >exp-11 || framework_failure_ 34 | 0123456789\ 35 | 0123456789\ 36 | 0123456789\ 37 | 0123456789\ 38 | 0123456789\ 39 | 0123456789\ 40 | 0123456789\ 41 | 012345$ 42 | EOF 43 | 44 | # command 'l n' is a gnu extension, rejected in posix mode 45 | cat <<\EOF >exp-err-posix-ln || framework_failure_ 46 | sed: -e expression #1, char 2: extra characters after command 47 | EOF 48 | 49 | # sed's default: 70 characters 50 | sed -n l in1 >out-def || fail=1 51 | compare_ exp-def out-def || fail=1 52 | 53 | # limit with COLS envvar, sed subtracts one to avoid ttys linewraps 54 | COLS=12 sed -n l in1 >out-cols12 || fail=1 55 | compare_ exp-11 out-cols12 || fail=1 56 | 57 | # invalid COLS envvar should be ignored (wrap at default=70) 58 | COLS=0 sed -n l in1 >out-cols0 || fail=1 59 | compare_ exp-def out-cols0 || fail=1 60 | COLS=foo sed -n l in1 >out-cols-foo || fail=1 61 | compare_ exp-def out-cols-foo || fail=1 62 | 63 | # limit with -l parameter 64 | sed -l 11 -n l in1 >out-l11 || fail=1 65 | compare_ exp-11 out-l11 || fail=1 66 | 67 | # limit with 'ln' command (gnu extension) 68 | sed -n l11 in1 >out-ln-11 || fail=1 69 | compare_ exp-11 out-ln-11 || fail=1 70 | 71 | # limit with 'ln' command (gnu extension) 72 | returns_ 1 sed --posix -n l11 in1 2>err-posix-ln || fail=1 73 | compare_ exp-err-posix-ln err-posix-ln || fail=1 74 | 75 | Exit $fail 76 | -------------------------------------------------------------------------------- /testsuite/nulldata.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test -z/--null-data option 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | # Two lines, differ based on the EOL character. 22 | printf "AB\000CD\nEF\n\000" > in1 || framework_failure_ 23 | 24 | # 's/^./x/' cmd processed with EOF=\n 25 | printf "xB\000CD\nxF\nx" > exp-s-nl || framework_failure_ 26 | # 's/^./x/' cmd processed with EOF=\0 27 | printf "xB\000xD\nEF\n\000" > exp-s-z || framework_failure_ 28 | 29 | # '=' cmd processed with EOF=\n 30 | printf "1\nAB\000CD\n2\nEF\n3\n\000" > exp-=-nl || framework_failure_ 31 | 32 | # '=' cmd processed with EOF=\0 33 | printf "1\000AB\0002\000CD\nEF\n\000" > exp-=-z || framework_failure_ 34 | 35 | 36 | # 'l' cmd processed with EOF=\n 37 | cat <<\EOF >exp-l-nl || framework_failure_ 38 | AB\000CD$ 39 | EF$ 40 | \000$ 41 | EOF 42 | 43 | # 'l' cmd processed with EOF=\0 44 | printf 'AB$\000CD\\nEF\\n$\000' >exp-l-z || framework_failure_ 45 | 46 | # 'F' cmd with EOL=\n 47 | printf "in1\n" > exp-F-nl || framework_failure_ 48 | 49 | # 'F' cmd with EOL=\0 50 | printf "in1\000" > exp-F-z || framework_failure_ 51 | 52 | 53 | # Test substitution 54 | sed 's/^./x/' in1 > out-s-nl || fail=1 55 | compare_ exp-s-nl out-s-nl || fail=1 56 | 57 | sed -z 's/^./x/' in1 > out-s-z || fail=1 58 | compare_ exp-s-z out-s-z || fail=1 59 | 60 | 61 | 62 | # Test '=' command 63 | sed = in1 > out-=-nl || fail=1 64 | compare_ exp-=-nl out-=-nl || fail=1 65 | 66 | sed -z = in1 > out-=-z || fail=1 67 | compare_ exp-=-z out-=-z || fail=1 68 | 69 | 70 | 71 | # Test 'l' command 72 | sed -n l in1 > out-l-nl || fail=1 73 | compare_ exp-l-nl out-l-nl || fail=1 74 | 75 | sed -zn l in1 > out-l-z || fail=1 76 | compare_ exp-l-z out-l-z || fail=1 77 | 78 | 79 | # Test 'F' command 80 | sed -n 1F in1 > out-F-nl || fail=1 81 | compare_ exp-F-nl out-F-nl || fail=1 82 | 83 | sed -zn 1F in1 > out-F-z || fail=1 84 | compare_ exp-F-z out-F-z || fail=1 85 | 86 | 87 | Exit $fail 88 | -------------------------------------------------------------------------------- /testsuite/xemacs.inp: -------------------------------------------------------------------------------- 1 | # Makefile.in generated automatically by automake 1.5 from Makefile.am. 2 | 3 | # Copyright 1994-2024 Free Software Foundation, Inc. 4 | # This Makefile.in is free software; the Free Software Foundation 5 | # gives unlimited permission to copy and/or distribute it, 6 | # with or without modifications, as long as this notice is preserved. 7 | 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY, to the extent permitted by law; without 10 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | # PARTICULAR PURPOSE. 12 | 13 | @SET_MAKE@ 14 | 15 | # Automake requirements 16 | 17 | SHELL = @SHELL@ 18 | 19 | PACKAGE = sed 20 | 21 | EXTRA_DIST = BUGS THANKS README.boot bootstrap.sh dc.sed autogen \ 22 | m4/codeset.m4 m4/gettext.m4 m4/iconv.m4 m4/lcmessage.m4 \ 23 | m4/getline.m4 m4/glibc21.m4 m4/isc-posix.m4 m4/progtest.m4 \ 24 | m4/obstack.m4 25 | 26 | subdir = . 27 | ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 28 | mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs 29 | CONFIG_HEADER = config.h 30 | CONFIG_CLEAN_FILES = bootstrap.sh intl/Makefile 31 | DIST_SOURCES = 32 | DATA = $(noinst_DATA) 33 | 34 | HEADERS = $(noinst_HEADERS) 35 | 36 | 37 | RECURSIVE_TARGETS = info-recursive dvi-recursive install-info-recursive \ 38 | uninstall-info-recursive all-recursive install-data-recursive \ 39 | install-exec-recursive installdirs-recursive install-recursive \ 40 | uninstall-recursive check-recursive installcheck-recursive 41 | DIST_COMMON = README $(noinst_HEADERS) ./stamp-h.in ABOUT-NLS AUTHORS \ 42 | COPYING ChangeLog INSTALL Makefile.am Makefile.in NEWS THANKS \ 43 | TODO acconfig.h aclocal.m4 bootstrap.sh.in config.guess \ 44 | config.sub config_h.in configure configure.ac depcomp \ 45 | install-sh missing mkinstalldirs 46 | DIST_SUBDIRS = $(SUBDIRS) 47 | all: config.h 48 | $(MAKE) $(AM_MAKEFLAGS) all-recursive 49 | 50 | .SUFFIXES: 51 | $(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.ac $(ACLOCAL_M4) 52 | cd $(top_srcdir) && \ 53 | $(AUTOMAKE) --gnu Makefile 54 | Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status 55 | cd $(top_builddir) && \ 56 | CONFIG_HEADERS= CONFIG_LINKS= \ 57 | CONFIG_FILES=$@ $(SHELL) ./config.status 58 | 59 | $(top_builddir)/config.status: $(srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) 60 | $(SHELL) ./config.status --recheck 61 | $(srcdir)/configure: $(srcdir)/configure.ac $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES) 62 | cd $(srcdir) && $(AUTOCONF) 63 | 64 | $(ACLOCAL_M4): configure.ac m4/codeset.m4 m4/getline.m4 m4/gettext.m4 m4/glibc21.m4 m4/iconv.m4 m4/isc-posix.m4 m4/lcmessage.m4 m4/obstack.m4 m4/progtest.m4 65 | cd $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) 66 | config.h: stamp-h 67 | -------------------------------------------------------------------------------- /testsuite/xemacs.good: -------------------------------------------------------------------------------- 1 | #Makefile.in generated automatically by automake 1.5 from Makefile.am. 2 | 3 | #Copyright 1994-2024 Free Software Foundation, Inc. 4 | #This Makefile.in is free software; the Free Software Foundation 5 | #gives unlimited permission to copy and/or distribute it, 6 | #with or without modifications, as long as this notice is preserved. 7 | 8 | #This program is distributed in the hope that it will be useful, 9 | #but WITHOUT ANY WARRANTY, to the extent permitted by law; without 10 | #even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | #PARTICULAR PURPOSE. 12 | 13 | "@SET_MAKE@" 14 | 15 | #Automake requirements 16 | 17 | "SHELL = @SHELL@" 18 | 19 | "PACKAGE = sed" 20 | 21 | "EXTRA_DIST = BUGS THANKS README.boot bootstrap.sh dc.sed autogen \\" 22 | " m4/codeset.m4 m4/gettext.m4 m4/iconv.m4 m4/lcmessage.m4 \\" 23 | " m4/getline.m4 m4/glibc21.m4 m4/isc-posix.m4 m4/progtest.m4 \\" 24 | " m4/obstack.m4" 25 | 26 | "subdir = ." 27 | "ACLOCAL_M4 = $(top_srcdir)/aclocal.m4" 28 | "mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs" 29 | "CONFIG_HEADER = config.h" 30 | "CONFIG_CLEAN_FILES = bootstrap.sh intl/Makefile" 31 | "DIST_SOURCES =" 32 | "DATA = $(noinst_DATA)" 33 | 34 | "HEADERS = $(noinst_HEADERS)" 35 | 36 | 37 | "RECURSIVE_TARGETS = info-recursive dvi-recursive install-info-recursive \\" 38 | " uninstall-info-recursive all-recursive install-data-recursive \\" 39 | " install-exec-recursive installdirs-recursive install-recursive \\" 40 | " uninstall-recursive check-recursive installcheck-recursive" 41 | "DIST_COMMON = README $(noinst_HEADERS) ./stamp-h.in ABOUT-NLS AUTHORS \\" 42 | " COPYING ChangeLog INSTALL Makefile.am Makefile.in NEWS THANKS \\" 43 | " TODO acconfig.h aclocal.m4 bootstrap.sh.in config.guess \\" 44 | " config.sub config_h.in configure configure.ac depcomp \\" 45 | " install-sh missing mkinstalldirs" 46 | "DIST_SUBDIRS = $(SUBDIRS)" 47 | "all: config.h" 48 | " $(MAKE) $(AM_MAKEFLAGS) all-recursive" 49 | 50 | ".SUFFIXES:" 51 | "$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.ac $(ACLOCAL_M4)" 52 | " cd $(top_srcdir) && \\" 53 | " $(AUTOMAKE) --gnu Makefile" 54 | "Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status" 55 | " cd $(top_builddir) && \\" 56 | " CONFIG_HEADERS= CONFIG_LINKS= \\" 57 | " CONFIG_FILES=$@ $(SHELL) ./config.status" 58 | 59 | "$(top_builddir)/config.status: $(srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)" 60 | " $(SHELL) ./config.status --recheck" 61 | "$(srcdir)/configure: $(srcdir)/configure.ac $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES)" 62 | " cd $(srcdir) && $(AUTOCONF)" 63 | 64 | "$(ACLOCAL_M4): configure.ac m4/codeset.m4 m4/getline.m4 m4/gettext.m4 m4/glibc21.m4 m4/iconv.m4 m4/isc-posix.m4 m4/lcmessage.m4 m4/obstack.m4 m4/progtest.m4" 65 | " cd $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)" 66 | "config.h: stamp-h" 67 | -------------------------------------------------------------------------------- /testsuite/comment-n.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test the '#n' silent mode (activated by first line comment) 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | echo X > in1 || framework_failure_ 22 | 23 | # expected output with 'sed -n = in1' (silent mode) 24 | echo 1 > exp-silent || framework_failure_ 25 | 26 | # expected output with 'sed = in1' (not silent mode) 27 | printf "1\nX\n" > exp-norm || framework_failure_ 28 | 29 | 30 | # A comment '#n' in the first script, in the first line 31 | sed -e '#n' in1 > out1 || fail=1 32 | compare_ /dev/null out1 || fail=1 33 | 34 | sed -e '#n' -e = in1 > out2 || fail=1 35 | compare_ exp-silent out2 || fail=1 36 | 37 | sed -e '#ni!' -e = in1 > out3 || fail=1 38 | compare_ exp-silent out3 || fail=1 39 | 40 | # not the first 2 characters, or space before n, 41 | # or uppercase N - do not activate silent mode 42 | sed -e '=#n' in1 > out4 || fail=1 43 | compare_ exp-norm out4 || fail=1 44 | 45 | sed -e '# n' -e = in1 > out5 || fail=1 46 | compare_ exp-norm out5 || fail=1 47 | 48 | sed -e '#N' -e = in1 > out6 || fail=1 49 | compare_ exp-norm out6 || fail=1 50 | 51 | sed -e = -e '#n' in1 > out7 || fail=1 52 | compare_ exp-norm out7 || fail=1 53 | 54 | 55 | # 56 | # Test the same, with a program instead of -e. 57 | # 58 | cat << \EOF > prog1 || framework_failure_ 59 | #n 60 | = 61 | EOF 62 | sed -f prog1 in1 > out8 || fail=1 63 | compare_ exp-silent out8 || fail=1 64 | 65 | # not in the first 2 characters 66 | cat << \EOF > prog2 || framework_failure_ 67 | = 68 | #n 69 | EOF 70 | sed -f prog2 in1 > out9 || fail=1 71 | compare_ exp-norm out9 || fail=1 72 | 73 | # not in the first 2 characters 74 | cat << \EOF > prog3 || framework_failure_ 75 | # n 76 | = 77 | EOF 78 | sed -f prog3 in1 > out10 || fail=1 79 | compare_ exp-norm out10 || fail=1 80 | 81 | 82 | # -e then a program file. 83 | cat << \EOF > prog4 || framework_failure_ 84 | #n 85 | EOF 86 | sed -e = -f prog4 in1 > out11 || fail=1 87 | compare_ exp-norm out11 || fail=1 88 | 89 | 90 | # If the program comes before -e , silent mode is activated. 91 | sed -f prog4 -e = in1 > out12 || fail=1 92 | compare_ exp-silent out12 || fail=1 93 | 94 | 95 | Exit $fail 96 | -------------------------------------------------------------------------------- /testsuite/sandbox.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test --sandbox mode 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | echo a > a || framework_failure_ 22 | echo b > b || framework_failure_ 23 | 24 | # Same error message, different character position in the sed program. 25 | for i in 1 6 14 ; do 26 | err="sed: -e expression #1, char $i: e/r/w commands disabled in sandbox mode" 27 | echo "$err" > exp-err$i || framework_failure_ 28 | done 29 | 30 | # read command - without sandbox 31 | printf "a\nb\n" > exp || framework_failure_ 32 | sed rb a > out || fail=1 33 | compare exp out || fail=1 34 | 35 | # read command - with sandbox 36 | returns_ 1 sed --sandbox -e 'ra' b >/dev/null 2>err1 || fail=1 37 | compare exp-err1 err1 || fail=1 38 | 39 | 40 | # write command (create file 'c') - without sandbox 41 | sed wc a > out || fail=1 42 | compare a c || fail=1 43 | compare out a || fail=1 44 | 45 | # write command - with sandbox 46 | returns_ 1 sed --sandbox -e 'wd' a >/dev/null 2>err2 || fail=1 47 | compare exp-err1 err1 || fail=1 48 | # ensure file 'd' was not created 49 | test -e d && fail=1 50 | 51 | 52 | 53 | # execute command - without sandbox 54 | sed 'etouch e' b > out || fail=1 55 | compare b out || fail=1 56 | # ensure 'e' was created 57 | test -e e || fail=1 58 | 59 | # execute command - with sandbox 60 | returns_ 1 sed --sandbox -e 'etouch f' b >/dev/null 2>err3 || fail=1 61 | compare exp-err1 err3 || fail=1 62 | # ensure 'f' was not created 63 | test -e f && fail=1 64 | 65 | 66 | 67 | # substitute+write option - without sandbox 68 | sed 's/^//wg' a > out || fail=1 69 | test -e g || fail=1 70 | 71 | # substitute+write option - with sandbox 72 | returns_ 1 sed --sandbox 's/^//wh' a >/dev/null 2>err4 || fail=1 73 | compare exp-err6 err4 || fail=1 74 | # ensure file 'h' was not created 75 | test -e h && fail=1 76 | 77 | 78 | 79 | # substitute+execute option - without sandbox 80 | sed 's/.*/touch i/e' a > out || fail=1 81 | test -e i || fail=1 82 | 83 | # substitute+execute option - with sandbox 84 | returns_ 1 sed --sandbox 's/.*/touch j/e' a >/dev/null 2>err5 || fail=1 85 | compare exp-err14 err5 || fail=1 86 | # ensure file 'j' was not created 87 | test -e j && fail=1 88 | 89 | 90 | Exit $fail 91 | -------------------------------------------------------------------------------- /testsuite/posix-mode-addr.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Ensure GNU address extensions are rejected in posix mode 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | cat <<\EOF> exp-err-addr0 || framework_failure_ 22 | sed: -e expression #1, char 6: invalid usage of line address 0 23 | EOF 24 | 25 | cat <<\EOF >exp-err-bad-addr || framework_failure_ 26 | sed: -e expression #1, char 3: unexpected ',' 27 | EOF 28 | 29 | printf "%s\n" A B A C D E F G H I J >in1 || framework_failure_ 30 | 31 | # The expected output with zero-line address '0,/A/' 32 | # the regex will match the first line 33 | printf "A\n" >exp-l0 || framework_failure_ 34 | 35 | # The expected output with one-line address '1,/A/' 36 | # the regex will not be checked against the first line, 37 | # will match the third line 38 | printf "%s\n" A B A >exp-l1 || framework_failure_ 39 | 40 | # The expected output with address '2,+1' 41 | # (from line 2, count 1 addition line = line 3) 42 | printf "%s\n" B A >exp-plus || framework_failure_ 43 | 44 | # The expected output with address '5,~4' 45 | # (from line 5 till a multiple of 4 = line 8) 46 | printf "%s\n" D E F G >exp-mult || framework_failure_ 47 | 48 | 49 | # 50 | # Addressing extension: 0,/regexp/ 51 | # 52 | 53 | # sanity check: address line=1 is valid for both posix and gnu 54 | sed -n '1,/A/p' in1 > out-l1 || fail=1 55 | compare_ exp-l1 out-l1 || fail=1 56 | 57 | # address line=0 is a gnu extension 58 | sed -n '0,/A/p' in1 > out-gnu-l0 || fail=1 59 | compare_ exp-l0 out-gnu-l0 || fail=1 60 | # rejected in posix mode 61 | returns_ 1 sed --posix -n '0,/A/p' in1 2>err-posix-l0 || fail=1 62 | compare_ exp-err-addr0 err-posix-l0 || fail=1 63 | 64 | 65 | 66 | # 67 | # Addressing extension: addr,+N 68 | # 69 | sed -n '2,+1p' in1 > out-plus || fail=1 70 | compare_ exp-plus out-plus || fail=1 71 | 72 | returns_ 1 sed --posix -n '2,+1p' in1 2> err-plus || fail=1 73 | compare_ exp-err-bad-addr err-plus || fail=1 74 | 75 | 76 | 77 | # 78 | # Addressing extension: addr,~N 79 | # 80 | 81 | sed -n '5,~4p' in1 > out-mult || fail=1 82 | compare_ exp-mult out-mult || fail=1 83 | 84 | returns_ 1 sed --posix -n '5,~4p' in1 2> err-mult || fail=1 85 | compare_ exp-err-bad-addr err-mult || fail=1 86 | 87 | 88 | 89 | Exit $fail 90 | -------------------------------------------------------------------------------- /testsuite/eval.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Test runner for old 'eval' test 4 | 5 | # Copyright (C) 2017-2024 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 20 | print_ver_ sed 21 | 22 | cat << \EOF > eval-in || framework_failure_ 23 | 17380: 2 2 5 11 79 24 | abcd 25 | cpu 26 | abcd 27 | cpu 28 | EOF 29 | 30 | # create a copy of the input file. 31 | # Keep the name 'eval.in2' - it is used in the 'eval' commands in the 32 | # sed program below. 33 | cp eval-in eval.in2 || framework_failure_ 34 | 35 | 36 | # The sed program - containing multiple 'e' (eval) commands. 37 | # NOTE: the program executes 'sed' using 'e' commands - and 38 | # assumes GNU sed is in the $PATH (which is the case here). 39 | cat << \EOF > eval.sed || framework_failure_ 40 | 1d 41 | 42 | #Try eval command 43 | /cpu/!b2 44 | esed 1q eval.in2 45 | 46 | :2 47 | p 48 | i--- 49 | h 50 | 51 | #Try eval option 52 | s,.* *cpu *,sed 1q eval.in2; echo "&",e 53 | 54 | :3 55 | p 56 | g 57 | i--- 58 | 59 | h 60 | #Try eval option with print 61 | s,.* *cpu.*,sed 1q eval.in2,ep 62 | g 63 | 64 | 65 | :4 66 | p 67 | i--- 68 | 69 | $!d 70 | 71 | #Do some more tests 72 | s/.*/Doing some more tests -----------------------/p 73 | s,.*,sed 1q eval.in2,ep 74 | i--- 75 | s,.*,sed 1q eval.in2,pe 76 | i--- 77 | s,.*,sed 1q eval.in2, 78 | h 79 | e 80 | p 81 | g 82 | i--- 83 | s/^/echo /ep 84 | i--- 85 | s/^fubar$/echo wozthis/e 86 | EOF 87 | 88 | 89 | # The expected output file 90 | cat << \EOF > eval-exp || framework_failure_ 91 | abcd 92 | --- 93 | abcd 94 | --- 95 | abcd 96 | --- 97 | 17380: 2 2 5 11 79 98 | cpu 99 | --- 100 | 17380: 2 2 5 11 79 101 | cpu 102 | --- 103 | 17380: 2 2 5 11 79 104 | cpu 105 | --- 106 | abcd 107 | --- 108 | abcd 109 | --- 110 | abcd 111 | --- 112 | 17380: 2 2 5 11 79 113 | cpu 114 | --- 115 | 17380: 2 2 5 11 79 116 | cpu 117 | --- 118 | 17380: 2 2 5 11 79 119 | cpu 120 | --- 121 | Doing some more tests ----------------------- 122 | 17380: 2 2 5 11 79 123 | --- 124 | sed 1q eval.in2 125 | --- 126 | 17380: 2 2 5 11 79 127 | --- 128 | sed 1q eval.in2 129 | --- 130 | sed 1q eval.in2 131 | EOF 132 | 133 | 134 | 135 | 136 | sed -f eval.sed eval-in > eval-out || fail=1 137 | remove_cr_inplace eval-out 138 | compare eval-exp eval-out || fail=1 139 | 140 | 141 | Exit $fail 142 | -------------------------------------------------------------------------------- /testsuite/bug32082.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # sed would access uninitialized memory for certain invalid backreference uses. 3 | # Before sed 4.6 these would result in "Invalid read size of 4" reported 4 | # by valgrind from execute.c:992 5 | 6 | # Copyright (C) 2018-2024 Free Software Foundation, Inc. 7 | 8 | # This program is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program. If not, see . 20 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 21 | print_ver_ sed 22 | 23 | require_valgrind_ 24 | 25 | printf '1\n2\n' > in || framework_failure_ 26 | printf '1\n2\n\n' > exp-posix || framework_failure_ 27 | printf '1\n1\n2\n2\n' > exp-no-posix || framework_failure_ 28 | 29 | # 30 | # Test 1: with "--posix" 31 | # 32 | # using "--posix" disables the backref safety check in 33 | # regexp.c:compile_regex_1(), which is reported as: 34 | # "invalid reference \\%d on 's' command's RHS" 35 | 36 | valgrind --quiet --error-exitcode=1 \ 37 | sed --posix -e '/2/p ; 2s//\9/' in > out-posix 2> err-posix || fail=1 38 | 39 | echo "valgrind report for 'posix' test:" 40 | echo "==================================" 41 | cat err-posix 42 | echo "==================================" 43 | 44 | 45 | # Work around a bug in CentOS 5.10's valgrind 46 | # FIXME: remove in 2018 or when CentOS 5 is no longer officially supported 47 | grep 'valgrind: .*Assertion.*failed' err-posix > /dev/null \ 48 | && skip_ 'you seem to have a buggy version of valgrind' 49 | 50 | compare exp-posix out-posix || fail=1 51 | compare /dev/null err || fail=1 52 | 53 | 54 | 55 | # 56 | # Test 2: without "--posix" 57 | # 58 | # When not using "--posix", using a backref to a non-existing group 59 | # would be caught in compile_regex_1. 60 | # As reported in bugs.gnu.org/32082 by bugs@feusi.co, 61 | # using the recent begline/endline optimization with a few "previous regex" 62 | # tricks bypasses this check. 63 | 64 | valgrind --quiet --error-exitcode=1 \ 65 | sed -e '/^/s///p ; 2s//\9/' in > out-no-posix 2> err-no-posix || fail=1 66 | 67 | echo "valgrind report for 'no-posix' test:" 68 | echo "====================================" 69 | cat err-no-posix 70 | echo "====================================" 71 | 72 | # Work around a bug in CentOS 5.10's valgrind 73 | # FIXME: remove in 2018 or when CentOS 5 is no longer officially supported 74 | grep 'valgrind: .*Assertion.*failed' err-no-posix > /dev/null \ 75 | && skip_ 'you seem to have a buggy version of valgrind' 76 | 77 | compare exp-no-posix out-no-posix || fail=1 78 | compare /dev/null err || fail=1 79 | 80 | 81 | Exit $fail 82 | -------------------------------------------------------------------------------- /testsuite/8to7.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Runner for old '8to7' test 4 | 5 | # Copyright (C) 2017-2024 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 20 | print_ver_ sed 21 | 22 | # Generate the input file, containing non-ascii 8-bit octets. 23 | # printf with octal escape sequences is the most portable way 24 | # to produce these. 25 | { 26 | printf '\344\306\244\342\244\350 \244\337\344\306\273\375\244\301\n' ; 27 | printf '\267\241\266\372\244\342\244\350 ' ; 28 | printf '\244\337\267\241\266\372\273\375\244\301\n' ; 29 | printf '\244\263\244\316\265\326\244\313 ' ; 30 | printf '\272\332\305\246\244\336\244\271\273\371\n' ; 31 | printf '\262\310\264\326\244\253\244\312 \271\360\244\351\244\265\244\315\n' ; 32 | printf '\244\275\244\351\244\337\244\304 '; 33 | printf '\302\347\317\302\244\316\271\361\244\317\n' ; 34 | printf '\244\252\244\267\244\343\244\312\244\331\244\306 ' ; 35 | printf '\244\357\244\354\244\263\244\275\265\357\244\354\n' ; 36 | printf '\244\267\244\255\244\312\244\331\244\306 ' ; 37 | printf '\244\357\244\354\244\263\244\275 ' ; 38 | printf '\272\302\244\273\n'; 39 | printf '\244\357\244\313\244\263\244\275\244\317 ' ; 40 | printf '\271\360\244\351\244\341\n' ; 41 | printf '\262\310\244\362\244\342\314\276\244\362\244\342\n'; 42 | } > 8to7-inp || framework_failure_ 43 | 44 | 45 | # The expected output. 46 | # NOTE: 47 | # shell-escaping is OFF with here-doc preceded by a backslash 48 | # i.e. the first 4 octets in the output will be the characters 49 | # '\', '3', '4', '4'. 50 | cat <<\EOF > 8to7-exp || framework_failure_ 51 | \344\306\244\342\244\350 \244\337\344\306\273\375\244\301$ 52 | \267\241\266\372\244\342\244\350 \244\337\267\241\266\372\273\375\244\ 53 | \301$ 54 | \244\263\244\316\265\326\244\313 \272\332\305\246\244\336\244\271\273\ 55 | \371$ 56 | \262\310\264\326\244\253\244\312 \271\360\244\351\244\265\244\315$ 57 | \244\275\244\351\244\337\244\304 \302\347\317\302\244\316\271\361\244\ 58 | \317$ 59 | \244\252\244\267\244\343\244\312\244\331\244\306 \244\357\244\354\244\ 60 | \263\244\275\265\357\244\354$ 61 | \244\267\244\255\244\312\244\331\244\306 \244\357\244\354\244\263\244\ 62 | \275 \272\302\244\273$ 63 | \244\357\244\313\244\263\244\275\244\317 \271\360\244\351\244\341$ 64 | \262\310\244\362\244\342\314\276\244\362\244\342$ 65 | EOF 66 | 67 | sed -e 'l;d' 8to7-inp > 8to7-out || fail=1 68 | remove_cr_inplace 8to7-out 69 | compare 8to7-exp 8to7-out || fail=1 70 | 71 | 72 | Exit $fail 73 | -------------------------------------------------------------------------------- /testsuite/follow-symlinks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test --follow-symlinks option 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | # 22 | # 'F' with/out follow-symlinks 23 | # 24 | echo dummy > a || framework_failure_ 25 | ln -s a la1 || framework_failure_ 26 | ln -s la1 la2 || framework_failure_ 27 | 28 | echo a > exp-a || framework_failure_ 29 | echo la1 > exp-la1 || framework_failure_ 30 | 31 | # Sanity-check: the real file 32 | sed 'F;Q' a > out-a || fail=1 33 | compare_ exp-a out-a || fail=1 34 | 35 | # Without follow-symlinks 36 | sed -n 'F' la1 > out-la1 || fail=1 37 | compare_ exp-la1 out-la1 || fail=1 38 | 39 | # With follow-symlinks 40 | sed -n --follow-symlinks 'F' la1 > out-la1-flw || fail=1 41 | compare_ exp-a out-la1-flw || fail=1 42 | 43 | # With follow-symlinks and two levels of indirections 44 | sed -n --follow-symlinks 'F' la2 > out-la2-flw || fail=1 45 | compare_ exp-a out-la2-flw || fail=1 46 | 47 | # Two symlinks input 48 | # (implementation note: utils.c:follow_symlinks() uses a static buffer 49 | # which will be non-empty on the second invocation) 50 | printf "%s\n" a a > exp-two-symlinks || framework_failure_ 51 | sed --follow-symlinks -n 'F' la1 la2 > out-two-symlinks || fail=1 52 | compare_ exp-two-symlinks out-two-symlinks || fail=1 53 | 54 | # non-existing input with --follow-symlink 55 | # implementation note: readlink called before open, thus "couldn't readlink" 56 | cat <<\EOF >exp-stat || framework_failure_ 57 | sed: couldn't readlink badfile: 58 | EOF 59 | returns_ 4 sed --follow-symlinks 'F' badfile >/dev/null 2>err-stat || fail=1 60 | 61 | # trim the filename/errno message (using sed itself...) 62 | sed -i 's/badfile:.*$/badfile:/' err-stat || framework_failure_ 63 | compare_ exp-stat err-stat || fail=1 64 | 65 | 66 | # symlinks with absolute path 67 | ln -s "$PWD/a" la-abs || framework_failure_ 68 | echo "$PWD/a" > exp-la-abs || framework_failure_ 69 | sed -n --follow-symlinks 'F' la-abs > out-la-abs || fail=1 70 | compare_ exp-la-abs out-la-abs || fail=1 71 | 72 | # symlink loop 73 | ln -s la-loop la-loop || framework_failure_ 74 | sed --follow-symlinks -i s/a/b/ la-loop && fail=1 75 | 76 | # symlink of length 128 77 | long=d/ 78 | for i in 2 3 4 5 6 7; do 79 | long=$long$long 80 | done 81 | dir=${long%/d/} 82 | file=$dir/xx 83 | mkdir -p $dir && 84 | echo x >$file && 85 | ln -s $file yy && 86 | ln -s yy xx || framework_failure_ 87 | sed -i --follow-symlinks s/x/y/ xx || fail=1 88 | 89 | Exit $fail 90 | -------------------------------------------------------------------------------- /testsuite/subst-replacement.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test Substitute replacements, e.g. 's/(.)/\U\1/' 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | # 22 | # Backslash followed by unrecognized letter, 23 | # use letter as-is. 24 | echo a > in-rpl1 || framework_failure_ 25 | echo Q > exp-rpl1 || framework_failure_ 26 | sed -E 's/(.)/\Q/' in-rpl1 > out-rpl1 || fail=1 27 | compare_ exp-rpl1 out-rpl1 || fail=1 28 | 29 | # 30 | # numbered backreferences 31 | # 32 | echo 123456789 > in-rpl2 || framework_failure_ 33 | for i in 1 2 3 4 5 6 7 8 9 ; 34 | do 35 | echo $i > exp-rpl2-$i || framework_failure_ 36 | sed -E "s/(.)(.)(.)(.)(.)(.)(.)(.)(.)/\\$i/" in-rpl2 > out-rpl2-$i || fail=1 37 | compare_ exp-rpl2-$i out-rpl2-$i || fail=1 38 | done 39 | 40 | # \0 matches entire pattern (TODO: is this documented?) 41 | # output should be the same as the input. 42 | sed -E 's/(.)(.)(.)(.)(.)(.)(.)(.)(.)/\0/' in-rpl2 > out-rpl2-0 || fail=1 43 | compare_ in-rpl2 out-rpl2-0 || fail=1 44 | 45 | # Unescaped '&' matches entire pattern 46 | # output should be the same as the input. 47 | sed -E 's/(.)(.)(.)(.)(.)(.)(.)(.)(.)/&/' in-rpl2 > out-rpl2-amp || fail=1 48 | compare_ in-rpl2 out-rpl2-amp || fail=1 49 | 50 | 51 | # 52 | # gnu extension: \U \u \L \l \E 53 | # 54 | echo abCde > in-rpl3 || framework_failure_ 55 | 56 | # \U - all uppercase 57 | echo ABCde > exp-rpl3-U || framework_failure_ 58 | sed -E 's/(.)(.)(.)/\U\1\2\3/' in-rpl3 > out-rpl3-U || fail=1 59 | compare_ exp-rpl3-U out-rpl3-U || fail=1 60 | 61 | # \u - next-char uppercase 62 | echo AbCde > exp-rpl3-u || framework_failure_ 63 | sed -E 's/(.)(.)(.)/\u\1\2\3/' in-rpl3 > out-rpl3-u || fail=1 64 | compare_ exp-rpl3-u out-rpl3-u || fail=1 65 | 66 | # \L - all lowercase 67 | echo abcde > exp-rpl3-L || framework_failure_ 68 | sed -E 's/(.)(.)(.)/\L\1\2\3/' in-rpl3 > out-rpl3-L || fail=1 69 | compare_ exp-rpl3-L out-rpl3-L || fail=1 70 | 71 | # \l - next-char lowercase 72 | echo abCde > exp-rpl3-l || framework_failure_ 73 | sed -E 's/(.)(.)(.)/\l\1\2\3/' in-rpl3 > out-rpl3-l || fail=1 74 | compare_ exp-rpl3-l out-rpl3-l || fail=1 75 | 76 | # \E - stop \U \u \L \l processing 77 | echo AbCde > exp-rpl3-E1 || framework_failure_ 78 | sed -E 's/(.)(.)(.)/\U\1\E\2\3/' in-rpl3 > out-rpl3-E1 || fail=1 79 | compare_ exp-rpl3-E1 out-rpl3-E1 || fail=1 80 | 81 | echo abCde > exp-rpl3-E2 || framework_failure_ 82 | sed -E 's/(.)(.)(.)/\L\1\2\E\3/' in-rpl3 > out-rpl3-E2 || fail=1 83 | compare_ exp-rpl3-E2 out-rpl3-E2 || fail=1 84 | 85 | 86 | Exit $fail 87 | -------------------------------------------------------------------------------- /testsuite/CuTmpdir.pm: -------------------------------------------------------------------------------- 1 | package CuTmpdir; 2 | # create, then chdir into a temporary sub-directory 3 | 4 | # Copyright (C) 2007-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | use strict; 20 | use warnings; 21 | 22 | use File::Temp; 23 | use File::Find; 24 | 25 | our $ME = $0 || ""; 26 | 27 | my $dir; 28 | 29 | sub skip_test($) 30 | { 31 | warn "$ME: skipping test: unsafe working directory name: '$_[0]'\n"; 32 | exit 77; 33 | } 34 | 35 | sub chmod_1 36 | { 37 | my $name = $_; 38 | 39 | # Skip symlinks and non-directories. 40 | -l $name || !-d _ 41 | and return; 42 | 43 | chmod 0700, $name; 44 | } 45 | 46 | sub chmod_tree 47 | { 48 | # When tempdir fails, it croaks, which leaves $dir undefined. 49 | defined $dir 50 | or return; 51 | 52 | # Perform the equivalent of find "$dir" -type d -print0|xargs -0 chmod -R 700. 53 | my $options = {untaint => 1, wanted => \&chmod_1}; 54 | find ($options, $dir); 55 | } 56 | 57 | sub import { 58 | my $prefix = $_[1]; 59 | 60 | $ME eq '-' && defined $prefix 61 | and $ME = $prefix; 62 | 63 | if ($prefix !~ /^\//) 64 | { 65 | eval 'use Cwd'; 66 | my $cwd = $@ ? '.' : Cwd::getcwd(); 67 | $prefix = "$cwd/$prefix"; 68 | } 69 | 70 | # Untaint for the upcoming mkdir. 71 | $prefix =~ m!^([-+\@\w./]+)$! 72 | or skip_test $prefix; 73 | $prefix = $1; 74 | 75 | my $original_pid = $$; 76 | 77 | my $on_sig_remove_tmpdir = sub { 78 | my ($sig) = @_; 79 | if ($$ == $original_pid and defined $dir) 80 | { 81 | chmod_tree; 82 | # Older versions of File::Temp lack this method. 83 | exists &File::Temp::cleanup 84 | and &File::Temp::cleanup; 85 | } 86 | $SIG{$sig} = 'DEFAULT'; 87 | kill $sig, $$; 88 | }; 89 | 90 | foreach my $sig (qw (INT TERM HUP)) 91 | { 92 | $SIG{$sig} = $on_sig_remove_tmpdir; 93 | } 94 | 95 | my $cleanup = $ENV{SAVE_TEMPS} ? 0 : 1; 96 | $dir = File::Temp::tempdir("$prefix.tmp-XXXX", CLEANUP => $cleanup ); 97 | chdir $dir 98 | or warn "$ME: failed to chdir to $dir: $!\n"; 99 | 100 | warn "Temp directory: $dir\n" unless $cleanup; 101 | } 102 | 103 | END { 104 | # Move cwd out of the directory we're about to remove. 105 | # This is required on some systems, and by some versions of File::Temp. 106 | chdir '..' 107 | or warn "$ME: failed to chdir to .. from $dir: $!\n"; 108 | 109 | my $saved_errno = $?; 110 | chmod_tree; 111 | $? = $saved_errno; 112 | } 113 | 114 | 1; 115 | -------------------------------------------------------------------------------- /testsuite/mb-bad-delim.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test 's' and 'y' non-slash delimiters in multibyte locales 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | require_en_utf8_locale_ 22 | 23 | # These tests use the following unicode character in various ways: 24 | # GREEK CAPITAL LETTER PHI (U+03A6) 25 | # UTF-8: hex: 0xCE 0xA6 26 | # oct: 0316 0246 27 | # bin: 11001110 10100110 28 | # 29 | # Octal encoding is used due to printf not supporting hex on older systems. 30 | # Using the first octet alone (\316) causes various multibyte related functions 31 | # to return '-2' (incomplete multibyte sequence). 32 | # using the second octet alone (\246) causess same functions to return '-1' 33 | # (ivalid multibyte sequence). 34 | 35 | 36 | # Reject a valid multibyte delimiter (instead of slash). 37 | printf 's\316\246a\316\246b\316\246' > prog1 || framework_failure_ 38 | 39 | cat <<\EOF > exp-err1 || framework_failure_ 40 | sed: file prog1 line 1: delimiter character is not a single-byte character 41 | EOF 42 | 43 | returns_ 1 env LC_ALL=en_US.UTF-8 sed -f prog1 < /dev/null 2>err1 || fail=1 44 | compare_ exp-err1 err1 || fail=1 45 | 46 | 47 | # Reject an incomplete multibyte delimiter (instead of slash). 48 | # This is an implmentation-specific behavior: 49 | # error is triggered upon first octet, before entire multibyte character 50 | # is scanned. 51 | printf 's\316a\316b\316' > prog2 || framework_failure_ 52 | 53 | cat <<\EOF > exp-err2 || framework_failure_ 54 | sed: file prog2 line 1: delimiter character is not a single-byte character 55 | EOF 56 | 57 | returns_ 1 env LC_ALL=en_US.UTF-8 sed -f prog2 err2 || fail=1 58 | compare_ exp-err2 err2 || fail=1 59 | 60 | # ... but accept octet \316 as delimiter in C locale 61 | echo a > in2 || framework_failure_ 62 | echo b > exp2 || framework_failure_ 63 | LC_ALL=C sed -f prog2 out2 || fail=1 64 | compare_ exp2 out2 || fail=1 65 | 66 | 67 | 68 | # An invalid multibyte sequence is treated as a valid single byte, 69 | # thus accepted as a delimter (instead of slash). 70 | # This is an implmentation-specific behavior. 71 | printf 's\246a\246b\246' > prog3 || framework_failure_ 72 | echo a > in3 || framework_failure_ 73 | echo b > exp3 || framework_failure_ 74 | 75 | LC_ALL=en_US.UTF-8 sed -f prog3 out3 || fail=1 76 | compare_ exp3 out3 || fail=1 77 | 78 | # Expect identical result in C locale 79 | LC_ALL=C sed -f prog3 out4 || fail=1 80 | compare_ exp3 out4 || fail=1 81 | 82 | 83 | Exit $fail 84 | -------------------------------------------------------------------------------- /testsuite/panic-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Exercise some panic stops 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | # 22 | # failure to create temp file 23 | # 24 | 25 | # inplace with an unwritable directory 26 | mkdir a || framework_failure_ 27 | touch a/a || framework_failure_ 28 | chmod a-w a || framework_failure_ 29 | 30 | # Expected error message, with actual filename/errno trimmed 31 | cat <<\EOF >exp-err-temp || framework_failure_ 32 | sed: couldn't open temporary file 33 | EOF 34 | 35 | # TODO: why exit-code 4 (currently hard-coded) 36 | returns_ 4 sed -i = a/a 2>err-temp || fail=1 37 | 38 | # trim the filename/errno message (using sed itself...) 39 | sed -i 's/file.*$/file/' err-temp || framework_failure_ 40 | compare_ exp-err-temp err-temp || fail=1 41 | 42 | # restore writability, to ensure it can be deleted 43 | chmod a+w a || framework_failure_ 44 | 45 | 46 | # 47 | # no input files (with inplace) 48 | # 49 | 50 | # Expected error message 51 | cat <<\EOF> exp-err-no-files || framework_failure_ 52 | sed: no input files 53 | EOF 54 | 55 | # /dev/null to ensure it doesn't hang if panic is not invoked 56 | returns_ 4 sed -i = err-no-files || fail=1 57 | compare_ exp-err-no-files err-no-files || fail=1 58 | 59 | 60 | # 61 | # Not a regular file (with inplace) 62 | # 63 | cat <<\EOF >exp-err-not-reg-file || framework_failure_ 64 | sed: couldn't edit f: not a regular file 65 | EOF 66 | 67 | mkfifo f || framework_failure_ 68 | 69 | # NOTE: the file-mode check is not performed until the first line is read. 70 | # an empty/blocking fifo will hang forever. 71 | printf a > f & 72 | 73 | # TODO: add a timeout in case of bug leading to a blocking fifo? 74 | returns_ 4 sed -i = f 2>err-not-reg-file || fail=1 75 | compare_ exp-err-not-reg-file err-not-reg-file || fail=1 76 | 77 | 78 | # 79 | # inplace on a terminal device 80 | # (if available) 81 | # 82 | 83 | #NOTE: device name is replaced later 84 | cat <<\EOF >exp-err-tty || framework_failure_ 85 | sed: couldn't edit X: is a terminal 86 | EOF 87 | 88 | ttydev=no-such-file 89 | type tty >/dev/null 2>&1 && ttydev=$(tty 2>/dev/null) 90 | if test -w "$ttydev" && test -r "$ttydev" ; then 91 | returns_ 4 sed -i = "$ttydev" 2>err-tty || fail=1 92 | 93 | # remove the actual terminal device name (using sed itself...) 94 | sed -i 's/edit.*:/edit X:/' err-tty || framework_failure_ 95 | 96 | compare_ exp-err-tty err-tty || fail=1 97 | fi 98 | 99 | 100 | 101 | Exit $fail 102 | -------------------------------------------------------------------------------- /testsuite/bug32271-2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # sed would access uninitialized memory for certain regexes. 3 | # Before sed 4.6 these would result in "Conditional jump or move depends on 4 | # uninitialised value(s)" and "Invalid read of size 1" 5 | # by valgrind from regexp.c:286 6 | 7 | # Copyright (C) 2018-2024 Free Software Foundation, Inc. 8 | 9 | # This program is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program. If not, see . 21 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 22 | print_ver_ sed 23 | 24 | require_valgrind_ 25 | 26 | # 40 characters ensures valgrind detects the bug 27 | # (with less than 25 - it does not). 28 | z=0000000000000000000000000000000000000000 29 | 30 | printf '%s\n' $z $z > in || framework_failure_ 31 | printf '%s\n' $z $z > exp || framework_failure_ 32 | 33 | # Before sed-4.6, this would fail with: 34 | # [...] 35 | # ==13131== Conditional jump or move depends on uninitialised value(s) 36 | # ==13131== at 0x4C3002B: memchr (vg_replace_strmem.c:883) 37 | # ==13131== by 0x1120BD: match_regex (regexp.c:286) 38 | # ==13131== by 0x110736: do_subst (execute.c:1101) 39 | # ==13131== by 0x1115D3: execute_program (execute.c:1591) 40 | # ==13131== by 0x111A4C: process_files (execute.c:1774) 41 | # ==13131== by 0x112E1C: main (sed.c:405) 42 | # ==13131== 43 | # ==13131== Invalid read of size 1 44 | # ==13131== at 0x4C30027: memchr (vg_replace_strmem.c:883) 45 | # ==13131== by 0x1120BD: match_regex (regexp.c:286) 46 | # ==13131== by 0x110736: do_subst (execute.c:1101) 47 | # ==13131== by 0x1115D3: execute_program (execute.c:1591) 48 | # ==13131== by 0x111A4C: process_files (execute.c:1774) 49 | # ==13131== by 0x112E1C: main (sed.c:405) 50 | # ==13131== Address 0x55ec765 is 0 bytes after a block of size 101 alloc'd 51 | # ==13131== at 0x4C2DDCF: realloc (vg_replace_malloc.c:785) 52 | # ==13131== by 0x113BA2: ck_realloc (utils.c:418) 53 | # ==13131== by 0x10E682: resize_line (execute.c:154) 54 | # ==13131== by 0x10E6F0: str_append (execute.c:165) 55 | # ==13131== by 0x110779: do_subst (execute.c:1106) 56 | # ==13131== by 0x1115D3: execute_program (execute.c:1591) 57 | # ==13131== by 0x111A4C: process_files (execute.c:1774) 58 | # ==13131== by 0x112E1C: main (sed.c:405) 59 | valgrind --quiet --error-exitcode=1 \ 60 | sed -e 'N; s/$//m2' in > out 2> err || fail=1 61 | 62 | # Work around a bug in CentOS 5.10's valgrind 63 | # FIXME: remove in 2018 or when CentOS 5 is no longer officially supported 64 | grep 'valgrind: .*Assertion.*failed' err-no-posix > /dev/null \ 65 | && skip_ 'you seem to have a buggy version of valgrind' 66 | 67 | # Remove any valgrind-added diagnostics from stderr. 68 | sed -i '/^==/d' err 69 | 70 | compare exp out || fail=1 71 | compare /dev/null err || fail=1 72 | 73 | echo "valgrind report:" 74 | echo "==================================" 75 | cat err 76 | echo "==================================" 77 | 78 | exit $fail 79 | -------------------------------------------------------------------------------- /testsuite/subst-options.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test Substitute options (for code-coverage purposes as well) 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | # 22 | # Simple modifiers to s// 23 | # (specific characters included as make_subst_opts's implementation 24 | # checks for them before returning control) 25 | printf "%s\n" a a a a a a > subst-in1 || framework_failure_ 26 | printf "%s\n" x x x x x x > subst-exp1 || framework_failure_ 27 | cat << \EOF >> subst-prog1 || framework_failure_ 28 | 1s/A/x/i 29 | 2s/A/x/I 30 | 31 | # s// followed by '}' 32 | 3{s/./x/} 33 | # s// followed by '#' 34 | 4s/./x/# 35 | # s// followed by ';' 36 | 5s/./x/; 37 | # s// followed by '\n 38 | 6s/./x/ 39 | EOF 40 | 41 | sed -f subst-prog1 subst-in1 > subst-out1 || fail=1 42 | compare_ subst-exp1 subst-out1 || fail=1 43 | 44 | 45 | # 46 | # Number modifiers to s// 47 | # 48 | 49 | cat << \EOF >subst-in2 || framework_failure_ 50 | bbbbbbbbbb 51 | bbbbbbbbbb 52 | bbbbbbbbbb 53 | bbbbbbbbbb 54 | bbbbbbbbbb 55 | bbbbbbbbbb 56 | bbbbbbbbbb 57 | bbbbbbbbbb 58 | bbbbbbbbbb 59 | bbbbbbbbbb 60 | EOF 61 | 62 | cat << \EOF >subst-prog2 || framework_failure_ 63 | 1s/./x/g 64 | 2s/./x/1 65 | 3s/./x/2 66 | 4s/./x/3 67 | 5s/./x/4 68 | 6s/./x/5 69 | 7s/./x/6 70 | 8s/./x/7 71 | 9s/./x/8 72 | 10s/./x/9 73 | EOF 74 | 75 | cat << \EOF >subst-exp2 76 | xxxxxxxxxx 77 | xbbbbbbbbb 78 | bxbbbbbbbb 79 | bbxbbbbbbb 80 | bbbxbbbbbb 81 | bbbbxbbbbb 82 | bbbbbxbbbb 83 | bbbbbbxbbb 84 | bbbbbbbxbb 85 | bbbbbbbbxb 86 | EOF 87 | 88 | sed -f subst-prog2 subst-in2 > subst-out2 || fail=1 89 | compare_ subst-exp2 subst-out2 || fail=1 90 | 91 | # 92 | # Multiline modifier: s///m 93 | # ('N' will read and concatenate the second line 94 | # into the patten space, making it "foo\nbar". 95 | # s// will then operate on it as one string). 96 | printf "foo\nbar\n" > subst-in3 || fail=1 97 | printf "Xoo\nXar\n" > subst-exp3 || fail=1 98 | 99 | sed 'N;s/^./X/gm' subst-in3 > subst-out3-1 || fail=1 100 | compare_ subst-exp3 subst-out3-1 || fail=1 101 | sed 'N;s/^./X/gM' subst-in3 > subst-out3-2 || fail=1 102 | compare_ subst-exp3 subst-out3-2 || fail=1 103 | 104 | # sanity-check: without m, only the first line should match 105 | printf "Xoo\nbar\n" > subst-exp3-3 || fail=1 106 | sed 'N;s/^./X/g' subst-in3 > subst-out3-3 || fail=1 107 | compare_ subst-exp3-3 subst-out3-3 || fail=1 108 | 109 | 110 | # 111 | # s// followed by \r\n 112 | # 113 | 114 | printf "s/./X/\r\n" > subst-prog4 || framework_failure_ 115 | echo a > subst-in4 || framework_failure_ 116 | echo X > subst-exp4 || framework_failure_ 117 | sed -f subst-prog4 subst-in4 > subst-out4 || fail=1 118 | compare_ subst-exp4 subst-out4 || fail=1 119 | 120 | 121 | 122 | 123 | Exit $fail 124 | -------------------------------------------------------------------------------- /bootstrap.conf: -------------------------------------------------------------------------------- 1 | # Bootstrap configuration. 2 | 3 | # Copyright (C) 2006-2024 Free Software Foundation, Inc. 4 | 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 3 of the License, or 8 | # (at your option) any later version. 9 | 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | avoided_gnulib_modules=' 19 | --avoid=lock-tests 20 | ' 21 | 22 | # gnulib modules used by this package. 23 | gnulib_modules=' 24 | acl 25 | binary-io 26 | btowc 27 | dfa 28 | eloop-threshold 29 | extensions 30 | fwriting 31 | getdelim 32 | gettext-h 33 | git-version-gen 34 | gitlog-to-changelog 35 | idx 36 | ignore-value 37 | localcharset 38 | manywarnings 39 | mbrtowc 40 | mbsinit 41 | memchr 42 | mempcpy 43 | memrchr 44 | minmax 45 | mkostemp 46 | obstack 47 | perl 48 | progname 49 | readlink 50 | readme-release 51 | regex 52 | rename 53 | selinux-h 54 | ssize_t 55 | stat-macros 56 | stdbool 57 | stdckdint 58 | strerror 59 | strtoimax 60 | strverscmp 61 | unlocked-io 62 | update-copyright 63 | version-etc-fsf 64 | wcrtomb 65 | wctob 66 | xalloc 67 | ' 68 | gnulib_name=libsed 69 | 70 | checkout_only_file= 71 | MSGID_BUGS_ADDRESS=bug-gnu-utils@gnu.org 72 | 73 | # Additional xgettext options to use. Use "\\\newline" to break lines. 74 | XGETTEXT_OPTIONS=$XGETTEXT_OPTIONS'\\\ 75 | --keyword=bad_prog --flag=bad_prog:1:c-format\\\ 76 | --from-code=UTF-8\\\ 77 | ' 78 | 79 | gnulib_tool_option_extras="--tests-base=gnulib-tests --with-tests --symlink\ 80 | --makefile-name=gnulib.mk --automake-subdir 81 | $avoided_gnulib_modules 82 | " 83 | 84 | # Build prerequisites 85 | buildreq="\ 86 | autoconf 2.64 87 | automake 1.11.2 88 | autopoint 0.19.2 89 | gettext 0.19.2 90 | git 1.4.4 91 | gzip - 92 | m4 - 93 | makeinfo 6.1 94 | perl 5.5 95 | tar - 96 | texi2pdf 6.1 97 | wget - 98 | xz - 99 | " 100 | 101 | bootstrap_post_import_hook () 102 | { 103 | # Automake requires that ChangeLog exist. 104 | touch ChangeLog || return 1 105 | 106 | # Copy tests/init.sh from Gnulib. 107 | $gnulib_tool --copy-file tests/init.sh testsuite/init.sh 108 | } 109 | 110 | bootstrap_epilogue() 111 | { 112 | perl -pi -e "s/\@PACKAGE\@/$package/g" README-release 113 | 114 | # Since this is a "GNU" package, replace this line 115 | # if LC_ALL=C grep 'GNU @PACKAGE@' $(top_srcdir)/* 2>/dev/null \ 116 | # | grep -v 'libtool:' >/dev/null; then 117 | # with this: 118 | # if true; then 119 | # Why? That pipeline searches all files in $(top_srcdir), and if you 120 | # happen to have large files (or apparently large sparse files), the 121 | # first grep may well run out of memory. 122 | perl -pi -e 's/if LC_ALL=C grep .GNU .PACKAGE.*; then/if true; then/' \ 123 | po/Makefile.in.in 124 | 125 | # Add dummy 'install-html' target, required for packages using 126 | # non-recursive makefiles with older gettext. 127 | # See https://debbugs.gnu.org/25690 128 | if ! grep -w 'install-html' po/Makefile.in.in ; then 129 | printf 'install-%s:;\n' dvi ps pdf html >> po/Makefile.in.in 130 | fi 131 | } 132 | -------------------------------------------------------------------------------- /THANKS.in: -------------------------------------------------------------------------------- 1 | These people have contributed to the GNU sed. Those contributions are 2 | described in the version control logs. If your name has been left out, 3 | if you'd rather not be listed, or if you'd prefer a different address 4 | be used, please send a note to the bug-report mailing list (as seen at 5 | end of e.g., sed --help). 6 | ## 7 | ## There is no need to list here any name that appears as an Author in 8 | ## "git log" output. Those are automatically added when this template 9 | ## is used to generate the THANKS file. Note that numerous people listed 10 | ## here would have been listed as commit authors if we had been using git 11 | ## for version control when they contributed. 12 | 13 | Akim Demaille akim@epita.fr 14 | Alan Modra alan@spri.levels.unisa.edu.au 15 | Andreas Schwab schwab@issan.informatik.uni-dortmund.de 16 | Andrew Herbert andrew@werple.apana.org.au 17 | Arnold Robbins arnold@skeeve.com 18 | Chip Salzenberg chip@fin.uucp 19 | Chris Weber weber@bucknell.edu 20 | Corinna Vinschen vinschen@redhat.com 21 | Daniel R. Grayson dan@math.uiuc.edu 22 | David Eckelkamp eckelkamp@mcc.com 23 | David J. MacKenzie djm@nutrimat 24 | David Schmidt davids@isc-br.isc-br.com 25 | Dietrich Kappe kap1@tao.cpe.uchicago.edu 26 | Doug McIlroy doug@research.att.com 27 | Eero Hakkinen eero17@bigfoot.com 28 | Eli Zaretskii eliz@is.elta.co.il 29 | Eric Pement epement@moody.edu 30 | Erick Branderhorst Erick.Branderhorst@asml.nl 31 | Francois Pinard pinard@iro.umontreal.ca 32 | Gaumond Pierre gaumondp@ERE.UMontreal.CA 33 | Greg Ubben gsu@romulus.ncsc.mil 34 | Isamu Hasegawa isamu@yamato.ibm.com 35 | J.T. Conklin jtc@gain.com 36 | Jakub Jelinek jakub@redhat.com 37 | Jason Molenda crash@cygnus.com 38 | Karl Berry karl@freefriends.org 39 | Karl Heuer kwzh@gnu.org 40 | Kaveh R. Ghazi ghazi@caip.rutgers.edu 41 | Kevin Buettner kev@cujo.geg.mot.com 42 | Laurent Vogel lvl@club-internet.fr 43 | Maciej W. Rozycki macro@linux-mips.org 44 | Mark Kettenis kettenis@phys.uva.nl 45 | Michael De La Rue delarue@NTCCSC01WA.ntc.nokia.com 46 | Michel de Ruiter mdruiter@cs.vu.nl 47 | Randall Cotton recotton@earthlink.net 48 | Robert A Bruce rab@allspice.berkeley.edu 49 | Ronnie Glasscock Ronnie.N.Glasscock@bridge.bellsouth.com 50 | Sergey Farbotka z8sergey8z@gmail.com 51 | Simon Taylor simon@unisolve.com.au 52 | Stepan Kasal kasal@ucw.cz 53 | Stephen Davis stephend@ksr.com 54 | Steve Ingram si@maps-r-us.com 55 | Tapani Tarvainen tarvaine@tukki.jyu.fi 56 | Timothy Baker timothypaulbaker@gmail.com 57 | Timothy J Luoma luomat@peak.org 58 | Tom R.Hageman tom@basil.icce.rug.nl 59 | Ulrich Drepper drepper@redhat.com 60 | Vladimir Marek vladimir.marek@sun.com 61 | Vladimir Volovich vvv@vvv.vsu.ru 62 | Wichert Akkerman wakkerma@debian.org 63 | Zhongxing Xu xuzhongxing@gmail.com 64 | -------------------------------------------------------------------------------- /basicdefs.h: -------------------------------------------------------------------------------- 1 | /* GNU SED, a batch stream editor. 2 | Copyright (C) 1998-2024 Free Software Foundation, Inc. 3 | 4 | This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 2, or (at your option) 7 | any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; If not, see . */ 16 | 17 | #ifndef BASICDEFS_H 18 | #define BASICDEFS_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #define _(String) gettext(String) 27 | 28 | #include "idx.h" 29 | #include "xalloc.h" 30 | 31 | /* some basic definitions to avoid undue promulgating of ugliness */ 32 | #define MEMDUP(x,n,t) ((t *)xmemdup((x),(n)*sizeof(t))) 33 | #define OB_MALLOC(o,n,t) ((t *)(void *)obstack_alloc(o,(n)*sizeof(t))) 34 | 35 | #define obstack_chunk_alloc xzalloc 36 | #define obstack_chunk_free free 37 | 38 | #define STREQ(a, b) (strcmp (a, b) == 0) 39 | #define STREQ_LEN(a, b, n) (strncmp (a, b, n) == 0) 40 | #define STRPREFIX(a, b) (strncmp (a, b, strlen (b)) == 0) 41 | 42 | /* MAX_PATH is not defined in some platforms, most notably GNU/Hurd. 43 | In that case we define it here to some constant. Note however that 44 | this relies in the fact that sed does reallocation if a buffer 45 | needs to be larger than PATH_MAX. */ 46 | #ifndef PATH_MAX 47 | # define PATH_MAX 200 48 | #endif 49 | 50 | /* handle misdesigned macros (snarfed from lib/regex.c) */ 51 | /* Jim Meyering writes: 52 | 53 | "... Some ctype macros are valid only for character codes that 54 | isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when 55 | using /bin/cc or gcc but without giving an ansi option). So, all 56 | ctype uses should be through macros like ISPRINT... If 57 | STDC_HEADERS is defined, then autoconf has verified that the ctype 58 | macros don't need to be guarded with references to isascii. ... 59 | Defining isascii to 1 should let any compiler worth its salt 60 | eliminate the && through constant folding." 61 | Solaris defines some of these symbols so we must undefine them first. */ 62 | 63 | #undef ISASCII 64 | #if defined STDC_HEADERS || (!defined isascii && !defined HAVE_ISASCII) 65 | # define ISASCII(c) 1 66 | #else 67 | # define ISASCII(c) isascii(c) 68 | #endif 69 | 70 | #if defined isblank || defined HAVE_ISBLANK 71 | # define ISBLANK(c) (ISASCII (c) && isblank (c)) 72 | #else 73 | # define ISBLANK(c) ((c) == ' ' || (c) == '\t') 74 | #endif 75 | 76 | #undef ISPRINT 77 | #define ISPRINT(c) (ISASCII (c) && isprint (c)) 78 | #define ISDIGIT(c) (ISASCII (c) && isdigit ((unsigned char) (c))) 79 | #define ISALNUM(c) (ISASCII (c) && isalnum (c)) 80 | #define ISALPHA(c) (ISASCII (c) && isalpha (c)) 81 | #define ISCNTRL(c) (ISASCII (c) && iscntrl (c)) 82 | #define ISLOWER(c) (ISASCII (c) && islower (c)) 83 | #define ISPUNCT(c) (ISASCII (c) && ispunct (c)) 84 | #define ISSPACE(c) (ISASCII (c) && isspace (c)) 85 | #define ISUPPER(c) (ISASCII (c) && isupper (c)) 86 | #define ISXDIGIT(c) (ISASCII (c) && isxdigit (c)) 87 | 88 | #ifndef initialize_main 89 | # ifdef __EMX__ 90 | # define initialize_main(argcp, argvp) \ 91 | { _response (argcp, argvp); _wildcard (argcp, argvp); } 92 | # else /* NOT __EMX__ */ 93 | # define initialize_main(argcp, argvp) 94 | # endif 95 | #endif 96 | 97 | #endif /*!BASICDEFS_H*/ 98 | -------------------------------------------------------------------------------- /testsuite/obinary.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test CR/LF behaviour on platforms which support O_BINARY file mode 3 | # (i.e. differentiates between text and binary files). 4 | 5 | # Copyright (C) 2018-2024 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 20 | print_ver_ sed 21 | 22 | # Test if O_TEXT is enabled by default (i.e. lines terminated with "\r\n"). 23 | # If not, skip the test. 24 | printf a | sed cb > out1 \ 25 | || framework_failure_ "failed to run sed 'cb'" 26 | size=$(LC_ALL=C wc -c < out1 | tr -d '[:space:]') \ 27 | || framework_failure_ "failed to check size of 'out1'" 28 | case $size in 29 | 2) skip_ "platform does not enable O_TEXT by default" ;; 30 | 3) ;; 31 | *) framework_failure_ "unexpected size '$size'" ;; 32 | esac 33 | 34 | 35 | # files with "\r\n" and with just "\n" 36 | printf 'a\015\12' > inT || framework_failure_ 37 | printf 'a\12' > inB || framework_failure_ 38 | cp inT inplaceT1 || framework_failure_ 39 | cp inT inplaceT2 || framework_failure_ 40 | cp inT inplaceT3 || framework_failure_ 41 | cp inB inplaceB1 || framework_failure_ 42 | cp inB inplaceB2 || framework_failure_ 43 | 44 | printf 'z\015\12' > expT || framework_failure_ 45 | printf 'z\12' > expB || framework_failure_ 46 | 47 | 48 | # First round of tests. These all seem equivalent, 49 | # but older seds had sublte implementation differences 50 | # between STDIN and explicit input files (bug#25459). 51 | # Similarly, also test --inplace type output. 52 | sed 's/a/z/' inT > out1 || fail=1 53 | sed 's/a/z/' < inT > out2 || fail=1 54 | cat inT | sed 's/a/z/' > out3 || fail=1 55 | sed -i 's/a/z/' inplaceT1 || fail=1 56 | 57 | compare_ expT out1 || fail=1 58 | compare_ expT out2 || fail=1 59 | compare_ expT out3 || fail=1 60 | compare_ expT inplaceT1 || fail=1 61 | 62 | # Input file with only "\n". Output should contain "\r\n". 63 | sed 's/a/z/' inB > out4 || fail=1 64 | sed 's/a/z/' < inB > out5 || fail=1 65 | cat inB | sed 's/a/z/' > out6 || fail=1 66 | sed -i 's/a/z/' inplaceB1 || fail=1 67 | 68 | compare_ expT out4 || fail=1 69 | compare_ expT out5 || fail=1 70 | compare_ expT out6 || fail=1 71 | compare_ expT inplaceB1 || fail=1 72 | 73 | # Input file with only "\n", with "sed -b" should output only "\n". 74 | sed -b 's/a/z/' inB > out7 || fail=1 75 | sed -b 's/a/z/' < inB > out8 || fail=1 76 | cat inB | sed -b 's/a/z/' > out9 || fail=1 77 | sed -b -i 's/a/z/' inplaceB2 || fail=1 78 | 79 | compare_ expB out7 || fail=1 80 | compare_ expB out8 || fail=1 81 | compare_ expB out9 || fail=1 82 | compare_ expB inplaceB2 || fail=1 83 | 84 | # End-of-line tests on input file with "\r\n". 85 | # In TEXT mode, "\r\n" is end-of-line, the "y" character will be added prior to 86 | # it. In BINARY mode, "\r" is just another character - the "y" character will 87 | # be added after the "\r". 88 | printf 'ay\015\012' > expTeol || framework_failure_ 89 | printf 'a\015y\012' > expBeol || framework_failure_ 90 | 91 | sed 's/$/y/' inT > out10 || fail=1 92 | sed 's/$/y/' < inT > out11 || fail=1 93 | cat inT | sed 's/$/y/' > out12 || fail=1 94 | sed -i 's/$/y/' inplaceT2 || fail=1 95 | 96 | sed -b 's/$/y/' inT > out13 || fail=1 97 | sed -b 's/$/y/' < inT > out14 || fail=1 98 | cat inT | sed -b 's/$/y/' > out15 || fail=1 99 | sed -i -b 's/$/y/' inplaceT3 || fail=1 100 | 101 | compare_ expTeol out10 || fail=1 102 | compare_ expTeol out11 || fail=1 103 | compare_ expTeol out12 || fail=1 104 | compare_ expTeol inplaceT2 || fail=1 105 | 106 | compare_ expBeol out13 || fail=1 107 | compare_ expBeol out14 || fail=1 108 | compare_ expBeol out15 || fail=1 109 | compare_ expBeol inplaceT3 || fail=1 110 | 111 | Exit $fail 112 | -------------------------------------------------------------------------------- /testsuite/distrib.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Test runner for the old 'distrib' test 4 | 5 | # Copyright (C) 2017-2024 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 20 | print_ver_ sed 21 | 22 | # This is straight out of C News 23 | # 24 | # 25 | # All this does is massage the headers so they look like what news 26 | # software expects. To:, Cc: and Resent-*: headers are masked. 27 | # Reply-To: is turned into references, which is questionable (could 28 | # just as well be dropped. 29 | # 30 | # The From: line is rewritten to use the "address (comments)" form 31 | # instead of "phrase " form our mailer uses. Also, addresses 32 | # with no "@domainname" are assumed to originate locally, and so are 33 | # given a domain. 34 | # 35 | # The Sender: field below reflects the address of the person who 36 | # maintains our mailing lists. The Approved: field is in a special 37 | # form, so that we can do bidirectional gatewaying. Any message 38 | # in a newsgroup that bears this stamp will not be fed into the 39 | # matching mailing list. 40 | cat << \EOF > distrib.sed || framework_failure_ 41 | 1i\ 42 | Path: mailnewsgateway 43 | :a 44 | /^[Rr]eceived:/b r 45 | /^[Nn]ewsgroups:/b r 46 | /^[Pp]ath:/b r 47 | /^[Tt][Oo]:/s/^/Original-/ 48 | /^[Cc][Cc]:/s/^/Original-/ 49 | /^[Rr][Ee][Ss][Ee][Nn][Tt]-.*/s/^/Original-/ 50 | /^[Mm][Ee][Ss][Ss][Aa][Gg][Ee]-[Ii][Dd]:/s/@/.alt.buddha.fat.short.guy@/ 51 | s/^[Ii]n-[Rr]eply-[Tt]o:/References:/ 52 | /^From:/{ 53 | s/<\([^@]*\)>$/<\1@$thissite>/ 54 | s/^From:[ ][ ]*\(.*\) *<\(.*\)>$/From: \2 (\1)/ 55 | } 56 | s/-[Ii]d:/-ID:/ 57 | s/^[Ss][Uu][Bb][Jj][Ee][Cc][Tt]:[ ]*$/Subject: (none)/ 58 | s/^\([^:]*:\)[ ]*/\1 / 59 | /^$/{i\ 60 | Newsgroups: alt.buddha.short.fat.guy\ 61 | Distribution: world\ 62 | Sender: news@cygnus.com\ 63 | Approved: alt.buddha.short.fat.guy@cygnus.com 64 | b e 65 | } 66 | p 67 | n 68 | b a 69 | :r 70 | s/.*//g 71 | n 72 | /^[ ]/b r 73 | b a 74 | :e 75 | p 76 | n 77 | b e 78 | EOF 79 | 80 | 81 | # The expected output 82 | cat << \EOF > distrib-exp || framework_failure_ 83 | Path: mailnewsgateway 84 | From crash@cygnus.com Wed Mar 8 18: 02:42 1995 85 | From: crash@cygnus.com (Jason Molenda) 86 | Message-ID: <9503090202.AA06931.alt.buddha.fat.short.guy@phydeaux.cygnus.com> 87 | Subject: Note for sed testsuite 88 | Original-To: molenda@msi.umn.edu 89 | Date: Wed, 8 Mar 1995 18:02:24 -0800 (PST) 90 | X-Mailer: ELM [version 2.4 PL23] 91 | Newsgroups: alt.buddha.short.fat.guy 92 | Distribution: world 93 | Sender: news@cygnus.com 94 | Approved: alt.buddha.short.fat.guy@cygnus.com 95 | 96 | _Summum Bonum_ 97 | 98 | All the breath and the bloom of the 99 | year in the bag of one bee: 100 | All the wonder and wealth of the mine in 101 | the heart of one gem: 102 | In the core of one pearl all the shade and the 103 | shine of the sea: 104 | Breath and bloom, shade and shine, -- wonder, 105 | wealth, and -- how far above them -- 106 | Truth, thats brighter than gem, 107 | Trust, that's purer than pearl, -- 108 | Brightest truth, purest trust in the universe -- 109 | all were for me 110 | In the kiss of one girl. 111 | -- Robert Browning 112 | EOF 113 | 114 | # NOTE: 115 | # The input has lines wider than 80 characters, and is kept as a separate file. 116 | 117 | # location of external test files 118 | dir="$abs_top_srcdir/testsuite" 119 | 120 | 121 | sed -n -f distrib.sed < "$dir/distrib.inp" > distrib-out || fail=1 122 | remove_cr_inplace distrib-out 123 | compare distrib-exp distrib-out || fail=1 124 | 125 | 126 | Exit $fail 127 | -------------------------------------------------------------------------------- /testsuite/command-endings.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test command separators and endings 3 | 4 | # Copyright (C) 2017-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | # Allowed endings/separators after most commands: 22 | # newline, comment, closing brace, semicolon, EOF 23 | # they are also allowed after opening and closing braces themselves. 24 | # 25 | # Not tested here: 26 | # r/R/w/R/e and s///[we] which use read_filename() and do not 27 | # accept comments or semicolons. 28 | 29 | 30 | 31 | # Test commands and braces followed by: 32 | # closing braces, comment, semicolons, EOF (newlines are tested later). 33 | # 34 | # sed-4.3 wrongly rejected y/// followed by '}' or '#' (bug#22460). 35 | # 36 | # Implementation notes (see compile.c): 37 | # Simple commands, '}', and 'y///' commands use read_end_of_cmd(). 38 | # 39 | # q/Q/l/L have additional check for optional integer, 40 | # then call read_end_of_cmd(). 41 | # 42 | # labels use 'read_label()'. 43 | # 44 | # 's///' has special handling, depending on additional flags 45 | # (with 's///[we]' commands and semicolons are not allowed). 46 | # Implemented in mark_subst_opts(). 47 | # 48 | for p in \ 49 | 'h' \ 50 | 'h;' \ 51 | 'h ;' \ 52 | 'h# foo' \ 53 | 'h # foo' \ 54 | '{h}' \ 55 | '{h } ' \ 56 | '{ h } ' \ 57 | \ 58 | '{h}# foo' \ 59 | '{h} # foo' \ 60 | '{h};' \ 61 | '{h} ;' \ 62 | '{;h;} ' \ 63 | '{{h}}' \ 64 | '{;{h};}' \ 65 | \ 66 | 'y/1/a/' \ 67 | 'y/1/a/;d' \ 68 | 'y/1/a/ ;d' \ 69 | '{y/1/a/}' \ 70 | 'y/1/a/#foo'\ 71 | 'y/1/a/ #fo'\ 72 | \ 73 | 's/1/a/' \ 74 | 's/1/a/;d' \ 75 | 's/1/a/ ;d' \ 76 | '{s/1/a/}' \ 77 | 's/1/a/#foo'\ 78 | 's/1/a/ #fo'\ 79 | \ 80 | 's/1/a/i ;' \ 81 | 's/1/a/i #foo' \ 82 | '{ s/1/a/i }' \ 83 | \ 84 | 'bx; :x' \ 85 | 'bx; :x;' \ 86 | 'bx; :x ;' \ 87 | 'bx; :x#foo' \ 88 | 'bx; :x #foo' \ 89 | '{ bx; :x }' \ 90 | \ 91 | 'l' \ 92 | 'l;' \ 93 | 'l ;' \ 94 | 'l#foo' \ 95 | 'l #foo' \ 96 | '{l}' \ 97 | '{l }' \ 98 | 'l1' \ 99 | 'l1;' \ 100 | 'l1 ;' \ 101 | 'l1#foo' \ 102 | 'l1 #foo' \ 103 | '{l1}' \ 104 | '{l1 }' \ 105 | ; 106 | do 107 | sed -n "$p" < /dev/null >out 2>err || fail=1 108 | compare /dev/null err || fail=1 109 | compare /dev/null out || fail=1 110 | done 111 | 112 | 113 | # Create files to test newlines after commands 114 | # (instead of having to embed newlines in shell variables in a portable way) 115 | printf 'd\n' > nl1 || framework_failure_ 116 | printf '{\nd}' > nl2 || framework_failure_ 117 | printf '{d\n}' > nl3 || framework_failure_ 118 | printf '{d}\n' > nl4 || framework_failure_ 119 | printf 'y/1/a/\n' > nl5 || framework_failure_ 120 | printf 's/1/a/\n' > nl6 || framework_failure_ 121 | printf 'bx\n:x\n' > nl7 || framework_failure_ 122 | printf 'l\n' > nl8 || framework_failure_ 123 | printf 'l1\n' > nl9 || framework_failure_ 124 | # s/// has special allowance for \r in mark_subst_opts(), 125 | # even if not on windows. 126 | # TODO: should other commands allow it ? 127 | printf 's/1/a/\r\n' > nl10 || framework_failure_ 128 | 129 | for i in 1 2 3 4 5 6 7 8 9 10 ; 130 | do 131 | sed -n -f "nl$i" out 2>err || fail=1 132 | compare /dev/null err || fail=1 133 | compare /dev/null out || fail=1 134 | done 135 | 136 | 137 | Exit $fail 138 | -------------------------------------------------------------------------------- /m4/.gitignore: -------------------------------------------------------------------------------- 1 | /wchar_t.m4 2 | /wint_t.m4~ 3 | /lock.m4~ 4 | /lcmessage.m4~ 5 | /codeset.m4~ 6 | /00gnulib.m4 7 | /__inline.m4 8 | /absolute-header.m4 9 | /acl.m4 10 | /alloca.m4 11 | /arpa_inet_h.m4 12 | /assert.m4 13 | /assert_h.m4 14 | /btowc.m4 15 | /builtin-expect.m4 16 | /c-bool.m4 17 | /calloc.m4 18 | /canonicalize.m4 19 | /clock_time.m4 20 | /close.m4 21 | /closedir.m4 22 | /codeset.m4 23 | /ctype_h.m4 24 | /dirent_h.m4 25 | /dirfd.m4 26 | /double-slash-root.m4 27 | /dup2.m4 28 | /eealloc.m4 29 | /environ.m4 30 | /errno_h.m4 31 | /error.m4 32 | /error_h.m4 33 | /extensions.m4 34 | /extern-inline.m4 35 | /fcntl-o.m4 36 | /fcntl.m4 37 | /fcntl_h.m4 38 | /fdopen.m4 39 | /fflush.m4 40 | /flexmember.m4 41 | /fopen.m4 42 | /fpending.m4 43 | /fpurge.m4 44 | /freading.m4 45 | /free.m4 46 | /fseek.m4 47 | /fseeko.m4 48 | /fstat.m4 49 | /ftell.m4 50 | /ftello.m4 51 | /ftruncate.m4 52 | /fwriting.m4 53 | /getcwd.m4 54 | /getdelim.m4 55 | /getdtablesize.m4 56 | /getpagesize.m4 57 | /getprogname.m4 58 | /getrandom.m4 59 | /gettext.m4 60 | /gettimeofday.m4 61 | /glibc2.m4 62 | /glibc21.m4 63 | /gnulib-cache.m4 64 | /gnulib-common.m4 65 | /gnulib-comp.m4 66 | /gnulib-tool.m4 67 | /iconv.m4 68 | /include_next.m4 69 | /inet_pton.m4 70 | /intdiv0.m4 71 | /intl-thread-locale.m4 72 | /intl.m4 73 | /intldir.m4 74 | /intlmacosx.m4 75 | /intmax.m4 76 | /inttypes-pri.m4 77 | /inttypes.m4 78 | /inttypes_h.m4 79 | /ioctl.m4 80 | /isblank.m4 81 | /langinfo_h.m4 82 | /largefile.m4 83 | /lcmessage.m4 84 | /lib-ld.m4 85 | /lib-link.m4 86 | /lib-prefix.m4 87 | /limits-h.m4 88 | /link.m4 89 | /localcharset.m4 90 | /locale-fr.m4 91 | /locale-ja.m4 92 | /locale-tr.m4 93 | /locale-zh.m4 94 | /locale_h.m4 95 | /localeconv.m4 96 | /localename.m4 97 | /lock.m4 98 | /longlong.m4 99 | /lseek.m4 100 | /lstat.m4 101 | /malloc.m4 102 | /malloca.m4 103 | /manywarnings-c++.m4 104 | /manywarnings.m4 105 | /mbrtowc.m4 106 | /mbsinit.m4 107 | /mbstate_t.m4 108 | /mbtowc.m4 109 | /memchr.m4 110 | /mempcpy.m4 111 | /memrchr.m4 112 | /memset_explicit.m4 113 | /minmax.m4 114 | /mkdir.m4 115 | /mkostemp.m4 116 | /mmap-anon.m4 117 | /mode_t.m4 118 | /msvc-inval.m4 119 | /msvc-nothrow.m4 120 | /multiarch.m4 121 | /musl.m4 122 | /nanosleep.m4 123 | /netinet_in_h.m4 124 | /nl_langinfo.m4 125 | /nls.m4 126 | /nocrash.m4 127 | /obstack.m4 128 | /off_t.m4 129 | /open-cloexec.m4 130 | /open-slash.m4 131 | /open.m4 132 | /opendir.m4 133 | /pathmax.m4 134 | /perl.m4 135 | /perror.m4 136 | /pid_t.m4 137 | /pipe.m4 138 | /po.m4 139 | /printf-posix.m4 140 | /progtest.m4 141 | /pselect.m4 142 | /pthread-thread.m4 143 | /pthread_h.m4 144 | /pthread_rwlock_rdlock.m4 145 | /pthread_sigmask.m4 146 | /putenv.m4 147 | /quote.m4 148 | /quotearg.m4 149 | /raise.m4 150 | /rawmemchr.m4 151 | /read-file.m4 152 | /readdir.m4 153 | /readlink.m4 154 | /realloc.m4 155 | /reallocarray.m4 156 | /regex.m4 157 | /rename.m4 158 | /rmdir.m4 159 | /sched_h.m4 160 | /select.m4 161 | /selinux-context-h.m4 162 | /selinux-label-h.m4 163 | /selinux-selinux-h.m4 164 | /setenv.m4 165 | /setlocale.m4 166 | /setlocale_null.m4 167 | /signal_h.m4 168 | /signalblocking.m4 169 | /size_max.m4 170 | /sleep.m4 171 | /socketlib.m4 172 | /sockets.m4 173 | /socklen.m4 174 | /sockpfaf.m4 175 | /ssize_t.m4 176 | /stat-time.m4 177 | /stat.m4 178 | /std-gnu11.m4 179 | /stdalign.m4 180 | /stdarg.m4 181 | /stddef_h.m4 182 | /stdint.m4 183 | /stdint_h.m4 184 | /stdio_h.m4 185 | /stdlib_h.m4 186 | /strdup.m4 187 | /strerror.m4 188 | /strerror_r.m4 189 | /string_h.m4 190 | /strtoimax.m4 191 | /strtoll.m4 192 | /strverscmp.m4 193 | /symlink.m4 194 | /sys_ioctl_h.m4 195 | /sys_random_h.m4 196 | /sys_select_h.m4 197 | /sys_socket_h.m4 198 | /sys_stat_h.m4 199 | /sys_time_h.m4 200 | /sys_types_h.m4 201 | /sys_uio_h.m4 202 | /tempname.m4 203 | /thread.m4 204 | /threadlib.m4 205 | /time_h.m4 206 | /uintmax_t.m4 207 | /ungetc.m4 208 | /unistd_h.m4 209 | /unlocked-io.m4 210 | /vararrays.m4 211 | /version-etc.m4 212 | /visibility.m4 213 | /warn-on-use.m4 214 | /warnings.m4 215 | /wchar_h.m4 216 | /wcrtomb.m4 217 | /wctob.m4 218 | /wctomb.m4 219 | /wctype_h.m4 220 | /wint_t.m4 221 | /xalloc.m4 222 | /xattr.m4 223 | /xsize.m4 224 | /zzgnulib.m4 225 | /off64_t.m4 226 | /pthread-cond.m4 227 | /pthread-mutex.m4 228 | /pthread-once.m4 229 | /pthread-rwlock.m4 230 | /pthread-spin.m4 231 | /pthread_mutex_timedlock.m4 232 | /random.m4 233 | /random_r.m4 234 | /sched_yield.m4 235 | /semaphore.m4 236 | /sys_cdefs_h.m4 237 | /yield.m4 238 | -------------------------------------------------------------------------------- /lib/.gitignore: -------------------------------------------------------------------------------- 1 | *.bak 2 | /_Noreturn.h 3 | /acl-errno-valid.c 4 | /acl-internal.c 5 | /acl-internal.h 6 | /acl.h 7 | /acl_entries.c 8 | /alignof.h 9 | /alloca.h 10 | /alloca.in.h 11 | /arg-nonnull.h 12 | /assert.h 13 | /assert.in.h 14 | /attribute.h 15 | /basename-lgpl.c 16 | /basename-lgpl.h 17 | /binary-io.c 18 | /binary-io.h 19 | /btowc.c 20 | /c++defs.h 21 | /c-ctype.c 22 | /c-ctype.h 23 | /c-strcase.h 24 | /c-strcasecmp.c 25 | /c-strcaseeq.h 26 | /c-strncasecmp.c 27 | /calloc.c 28 | /canonicalize-lgpl.c 29 | /cdefs.h 30 | /cloexec.c 31 | /cloexec.h 32 | /close-stream.c 33 | /close-stream.h 34 | /close.c 35 | /copy-acl.c 36 | /ctype.h 37 | /ctype.in.h 38 | /dfa.c 39 | /dfa.h 40 | /dirname-lgpl.c 41 | /dirname.h 42 | /dup2.c 43 | /dynarray.h 44 | /eloop-threshold.h 45 | /errno.h 46 | /errno.in.h 47 | /error.c 48 | /error.h 49 | /error.in.h 50 | /exitfail.c 51 | /exitfail.h 52 | /fcntl.c 53 | /fcntl.h 54 | /fcntl.in.h 55 | /fd-hook.c 56 | /fd-hook.h 57 | /filename.h 58 | /flexmember.h 59 | /fpending.c 60 | /fpending.h 61 | /free.c 62 | /fstat.c 63 | /fwriting.c 64 | /fwriting.h 65 | /get-permissions.c 66 | /getdelim.c 67 | /getdtablesize.c 68 | /getfilecon.c 69 | /getprogname.c 70 | /getprogname.h 71 | /getrandom.c 72 | /gettext.h 73 | /glthread/ 74 | /gnulib.mk 75 | /hard-locale.c 76 | /hard-locale.h 77 | /ialloc.c 78 | /ialloc.h 79 | /idx.h 80 | /ignore-value.h 81 | /intprops-internal.h 82 | /intprops.h 83 | /inttypes.h 84 | /inttypes.in.h 85 | /langinfo.h 86 | /langinfo.in.h 87 | /lc-charset-dispatch.c 88 | /lc-charset-dispatch.h 89 | /libc-config.h 90 | /limits.h 91 | /limits.in.h 92 | /localcharset.c 93 | /localcharset.h 94 | /locale.h 95 | /locale.in.h 96 | /localeconv.c 97 | /localeinfo.c 98 | /localeinfo.h 99 | /lstat.c 100 | /malloc.c 101 | /malloc/ 102 | /malloca.c 103 | /malloca.h 104 | /mbrtowc-impl-utf8.h 105 | /mbrtowc-impl.h 106 | /mbrtowc.c 107 | /mbsinit.c 108 | /mbtowc-impl.h 109 | /mbtowc-lock.c 110 | /mbtowc-lock.h 111 | /mbtowc.c 112 | /memchr.c 113 | /memchr.valgrind 114 | /mempcpy.c 115 | /memrchr.c 116 | /minmax.h 117 | /mkdir.c 118 | /mkostemp.c 119 | /msvc-inval.c 120 | /msvc-inval.h 121 | /msvc-nothrow.c 122 | /msvc-nothrow.h 123 | /nl_langinfo-lock.c 124 | /nl_langinfo.c 125 | /obstack.c 126 | /obstack.h 127 | /open.c 128 | /pathmax.h 129 | /progname.c 130 | /progname.h 131 | /pthread-once.c 132 | /pthread.h 133 | /pthread.in.h 134 | /qcopy-acl.c 135 | /qset-acl.c 136 | /quote.h 137 | /quotearg.c 138 | /quotearg.h 139 | /rawmemchr.c 140 | /rawmemchr.valgrind 141 | /readlink.c 142 | /realloc.c 143 | /reallocarray.c 144 | /regcomp.c 145 | /regex.c 146 | /regex.h 147 | /regex_internal.c 148 | /regex_internal.h 149 | /regexec.c 150 | /rename.c 151 | /rmdir.c 152 | /same-inode.h 153 | /sched.h 154 | /sched.in.h 155 | /scratch_buffer.h 156 | /se-context.c 157 | /se-context.h 158 | /se-context.in.h 159 | /se-label.c 160 | /se-label.h 161 | /se-label.in.h 162 | /se-selinux.c 163 | /se-selinux.h 164 | /se-selinux.in.h 165 | /selinux/ 166 | /set-acl.c 167 | /set-permissions.c 168 | /setlocale-lock.c 169 | /setlocale_null.c 170 | /setlocale_null.h 171 | /stat-macros.h 172 | /stat-time.c 173 | /stat-time.h 174 | /stat-w32.c 175 | /stat-w32.h 176 | /stat.c 177 | /stdarg.h 178 | /stdarg.in.h 179 | /stdckdint.h 180 | /stdckdint.in.h 181 | /stddef.h 182 | /stddef.in.h 183 | /stdint.h 184 | /stdint.in.h 185 | /stdio-impl.h 186 | /stdio-read.c 187 | /stdio-write.c 188 | /stdio.h 189 | /stdio.in.h 190 | /stdlib.h 191 | /stdlib.in.h 192 | /streq.h 193 | /strerror-override.c 194 | /strerror-override.h 195 | /strerror.c 196 | /string.h 197 | /string.in.h 198 | /stripslash.c 199 | /strtoimax.c 200 | /strtol.c 201 | /strtoll.c 202 | /strverscmp.c 203 | /sys/ 204 | /sys_random.in.h 205 | /sys_stat.in.h 206 | /sys_types.in.h 207 | /tempname.c 208 | /tempname.h 209 | /time.h 210 | /time.in.h 211 | /uchar.h 212 | /unicase.h 213 | /unictype.h 214 | /uninorm.h 215 | /unistd.c 216 | /unistd.h 217 | /unistd.in.h 218 | /unitypes.h 219 | /unlocked-io.h 220 | /verify.h 221 | /version-etc-fsf.c 222 | /version-etc.c 223 | /version-etc.h 224 | /warn-on-use.h 225 | /wchar.h 226 | /wchar.in.h 227 | /wcrtomb.c 228 | /wctob.c 229 | /wctomb-impl.h 230 | /wctomb.c 231 | /wctype-h.c 232 | /wctype.h 233 | /wctype.in.h 234 | /windows-initguard.h 235 | /windows-mutex.c 236 | /windows-mutex.h 237 | /windows-once.c 238 | /windows-once.h 239 | /windows-recmutex.c 240 | /windows-recmutex.h 241 | /windows-rwlock.c 242 | /windows-rwlock.h 243 | /xalloc-die.c 244 | /xalloc-oversized.h 245 | /xalloc.h 246 | /xmalloc.c 247 | -------------------------------------------------------------------------------- /testsuite/utf8-ru.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Test GNU extension "\u" and "\U" (uppercase conversion) 4 | # in "s///" command. 5 | # This is an adaptation of the old utf8-1/2/3/4 tests. 6 | 7 | # Copyright (C) 2017-2024 Free Software Foundation, Inc. 8 | 9 | # This program is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program. If not, see . 21 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 22 | print_ver_ sed 23 | 24 | require_ru_utf8_locale_ 25 | 26 | # The letter used in these tests are: 27 | # UTF8:Octal UTF8:HEX CodePoint Name 28 | # А \320\220 \xD0\x90 U+0410 \N{CYRILLIC CAPITAL LETTER A} 29 | # Д \320\224 \xD0\x94 U+0414 \N{CYRILLIC CAPITAL LETTER DE} 30 | # а \320\260 \xD0\xB0 U+0430 \N{CYRILLIC SMALL LETTER A} 31 | # д \320\264 \xD0\xB4 U+0434 \N{CYRILLIC SMALL LETTER DE} 32 | 33 | # Using octal values, as these are the most portable access various printfs. 34 | 35 | 36 | # Input: Same input for all test (all lower case letters) 37 | # д а д 38 | printf '\320\264\320\260 \320\264\n' > utf8-inp || framework_failure_ 39 | 40 | 41 | # Test 1: Convert "small DE" to upper case (with \U) 42 | # s/д/\U&/g 43 | printf 's/\320\264/\\U&/g' > utf8-1.sed || framework_failure_ 44 | 45 | # Test 1: Expected output - two capital DE letters. 46 | # Д а Д 47 | printf '\320\224\320\260 \320\224\n' > utf8-1-exp || framework_failure_ 48 | 49 | 50 | # Test 2: Convert "small DE" to upper case (with \u - next character only) 51 | # s/д/\u&/g 52 | printf 's/\320\264/\\u&/g\n' > utf8-2.sed || framework_failure_ 53 | 54 | # The expected output of test 2 is identical to test 1. 55 | # We create the file to make the test loop (below) simpler. 56 | cp utf8-1-exp utf8-2-exp || framework_failure_ 57 | 58 | 59 | 60 | # Test 3: Capitalize only the next character (\u) 61 | # Only the first "DE" should be capitilized. 62 | # s/д.*/\u&/g 63 | printf 's/\320\264.*/\\u&/g' > utf8-3.sed || framework_failure_ 64 | 65 | # Test 3: Expected output - First DE capitilized, second DE not. 66 | # Д а д 67 | printf '\320\224\320\260 \320\264\n' > utf8-3-exp || framework_failure_ 68 | 69 | 70 | # Test 4: Capitalize all matched characters 71 | # s/д.*/\U&/g 72 | printf 's/\320\264.*/\\U&/g' > utf8-4.sed || framework_failure_ 73 | 74 | 75 | # Test 4: Expected output - All capital letters: 76 | # Д А Д 77 | printf '\320\224\320\220 \320\224\n' > utf8-4-exp || framework_failure_ 78 | 79 | # Step 1: force Russian UTF8 locale. 80 | # The case-conversion should either work, or not modify the input. 81 | for i in 1 2 3 4; 82 | do 83 | LC_ALL=ru_RU.UTF-8 \ 84 | sed -f utf8-$i.sed < utf8-inp > utf8-$i-ru-out || fail=1 85 | 86 | remove_cr_inplace utf8-$i-ru-out 87 | 88 | # If we have the expected output - continue to next text 89 | compare utf8-$i-exp utf8-$i-ru-out && continue 90 | 91 | # Otherwise, ensure the input wasn't modified 92 | # (i.e. sed did not modify partial octets resulting in 93 | # invalid multibyte sequences) 94 | compare utf8-$i-inp utf8-$i-ru-out || fail=1 95 | done 96 | 97 | 98 | # Step 2: If the current locale supports UTF8, repeat the above tests. 99 | l=$(locale | grep '^LC_CTYPE=' | sed 's/^.*="// ; s/"$//') 100 | case "$n" in 101 | *UTF-8 | *UTF8 | *utf8 | *utf-8) utf8=yes;; 102 | *) utf8=no;; 103 | esac 104 | 105 | if test "$utf8" = yes ; then 106 | for i in 1 2 3 4; 107 | do 108 | sed -f utf8-$i.sed < utf8-inp > utf8-$i-out || fail=1 109 | 110 | remove_cr_inplace utf8-$i-out 111 | 112 | # If we have the expected output - continue to next text 113 | compare utf8-$i-exp utf8-$i-out && continue 114 | 115 | # Otherwise, ensure the input wasn't modified 116 | # (i.e. sed did not modify partial octets resulting in 117 | # invalid multibyte sequences) 118 | compare utf8-$i-inp utf8-$i-out || fail=1 119 | done 120 | fi 121 | 122 | 123 | Exit $fail 124 | -------------------------------------------------------------------------------- /testsuite/compile-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test compilation less-common cases 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | # 22 | # Special file names, with gnu extensions and without (if the host 23 | # supports /dev/std{out,err} ) 24 | # 25 | echo a > a || framework_failure_ 26 | 27 | # With gnu extension enabled, /dev/stderr is emulated internally 28 | # regardless of the operating system. 29 | sed 'w/dev/stderr' a >out 2>err|| fail=1 30 | compare_ a out || fail=1 31 | compare_ a err || fail=1 32 | 33 | # In posix mode /dev/std* are not emulated internally. Skip if they 34 | # don't exist. 'env' is used to avoid built-in 'test' which 35 | # simulates /dev/stderr, e.g. bash on AIX. 36 | if env test -w /dev/stderr ; then 37 | sed --posix 'w/dev/stderr' a >out-psx 2>err-psx || fail=1 38 | compare_ a out-psx || fail=1 39 | compare_ a err-psx || fail=1 40 | fi 41 | 42 | 43 | # 44 | # labels followed by various characters 45 | # (read_label) 46 | echo a > lbl-in-exp || framework_failure_ 47 | cat << \EOF > lbl-prog || framework_failure_ 48 | bZ 49 | :Z 50 | bY; 51 | :Y 52 | {bX} 53 | :X ; 54 | b W 55 | : W 56 | EOF 57 | sed -f lbl-prog lbl-in-exp > lbl-out || fail=1 58 | compare_ lbl-in-exp lbl-out 59 | 60 | 61 | 62 | # 63 | # character classes (compile.c:snarf_char_class) 64 | # 65 | 66 | # open brackets followed by EOF 67 | cat <<\EOF >exp-err-op-bracket || framework_failure_ 68 | sed: -e expression #1, char 2: unterminated address regex 69 | EOF 70 | returns_ 1 sed '/[' err-op-bracket1 || fail=1 71 | compare_ exp-err-op-bracket err-op-bracket1 || fail=1 72 | 73 | 74 | # open brackets followed by \n 75 | printf "/[\n" > op-bracket-prog || framework_failure_ 76 | cat <<\EOF >exp-err-op-bracket || framework_failure_ 77 | sed: file op-bracket-prog line 1: unterminated address regex 78 | EOF 79 | returns_ 1 sed -f op-bracket-prog err-op-bracket2 || fail=1 80 | compare_ exp-err-op-bracket err-op-bracket2 || fail=1 81 | 82 | 83 | # unterminated character class '[.' 84 | # (snarf_char_class terminates on char 7, then returns) 85 | cat <<\EOF >exp-chr-class || framework_failure_ 86 | sed: -e expression #1, char 7: unterminated 's' command 87 | EOF 88 | returns_ 1 sed 's/[[.//' err-chr-class || fail=1 89 | compare_ exp-chr-class err-chr-class || fail=1 90 | 91 | 92 | # closing bracket immediately after char-class opening 93 | # sequence (e.g. '[:]' instead of '[:alpha:]' ). 94 | cat<< \EOF >exp-chr-class2 || framework_failure_ 95 | sed: -e expression #1, char 9: unterminated 's' command 96 | EOF 97 | returns_ 1 sed 's/[[:]]//' err-chr-class2 || fail=1 98 | compare_ exp-chr-class2 err-chr-class2 || fail=1 99 | 100 | 101 | # EOF after backslash in a regex (compile.c:match_slash()) 102 | cat<< \EOF >exp-backslash-eof || framework_failure_ 103 | sed: -e expression #1, char 2: unterminated address regex 104 | EOF 105 | returns_ 1 sed '/\' err-backslash-eof || fail=1 106 | compare_ exp-backslash-eof err-backslash-eof || fail=1 107 | 108 | 109 | # Valid version requirement 110 | sed 'v4' < /dev/null || fail=1 111 | 112 | # Closing braces followed by another closing braces, and '#' 113 | echo X > in-exp || framework_failure_ 114 | sed -n '{{p}}' in-exp > out-braces-1 || fail=1 115 | compare_ in-exp out-braces-1 || fail=1 116 | 117 | sed -n '{p}#foo' in-exp > out-braces-2 || fail=1 118 | compare_ in-exp out-braces-2 || fail=1 119 | 120 | # 'l' followed by closing braces, and '#' 121 | printf 'X$\n' > exp-l || framework_failure_ 122 | sed -n '{l}' in-exp > out-l-braces || fail=1 123 | compare_ exp-l out-l-braces || fail=1 124 | sed -n 'l#foo' in-exp > out-l-hash || fail=1 125 | compare_ exp-l out-l-hash || fail=1 126 | 127 | 128 | # 129 | # unterminated a/c/i as last command 130 | # (pending_text) 131 | sed -e 'a\' in-exp > out-unterm-a1 || fail=1 132 | compare_ in-exp out-unterm-a1 || fail=1 133 | 134 | 135 | Exit $fail 136 | -------------------------------------------------------------------------------- /README-hacking: -------------------------------------------------------------------------------- 1 | Building from a Git repository -*- outline -*- 2 | 3 | These notes intend to help people working on the checked-out sources. 4 | These requirements do not apply when building from a distribution tarball. 5 | If this package has a file HACKING, please also read that file for 6 | more detailed contribution guidelines. 7 | 8 | * Requirements 9 | 10 | We've opted to keep only the highest-level sources in the Git repository. 11 | This eases our maintenance burden (fewer merges etc.), but imposes more 12 | requirements on anyone wishing to build from the just-checked-out sources. 13 | (The requirements to build from a release are much less and are just 14 | the requirements of the standard './configure && make' procedure.) 15 | Specific development tools and versions will be checked for and listed by 16 | the bootstrap script. See README-prereq for specific notes on obtaining 17 | these prerequisite tools. 18 | 19 | Valgrind is also highly recommended, if 20 | Valgrind supports your architecture. See also README-valgrind 21 | (if present). 22 | 23 | While building from a just-cloned source tree may require installing a 24 | few prerequisites, later, a plain 'git pull && make' typically suffices. 25 | 26 | * First Git checkout 27 | 28 | You can get a copy of the source repository like this: 29 | 30 | $ git clone https://git.savannah.gnu.org/git/ 31 | $ cd 32 | 33 | where '' stands for 'coreutils' or whatever other package 34 | you are building. 35 | 36 | To use the most-recent Gnulib (as opposed to the Gnulib version that 37 | the package last synchronized to), do this next: 38 | 39 | $ git submodule foreach git pull origin master 40 | $ git commit -m 'build: update gnulib submodule to latest' gnulib 41 | 42 | As an optional step, if you already have a copy of the Gnulib Git 43 | repository, then you can use it as a reference to reduce download 44 | time and file system space requirements: 45 | 46 | $ export GNULIB_SRCDIR=/path/to/gnulib 47 | 48 | The next step is to get and check other files needed to build, 49 | which are extracted from other source packages: 50 | 51 | $ ./bootstrap 52 | 53 | And there you are! Just 54 | 55 | $ ./configure --quiet #[--disable-gcc-warnings] [*] 56 | $ make 57 | $ make check 58 | 59 | At this point, there should be no difference between your local copy, 60 | and the Git master copy: 61 | 62 | $ git diff 63 | 64 | should output no difference. 65 | 66 | Enjoy! 67 | 68 | [*] By default GCC warnings are enabled when building from Git. 69 | If you get warnings with recent GCC and Glibc with default 70 | configure-time options, please report the warnings to the bug 71 | reporting address of this package instead of to bug-gnulib, 72 | even if the problem seems to originate in a Gnulib-provided file. 73 | If you get warnings with other configurations, you can run 74 | './configure --disable-gcc-warnings' or 'make WERROR_CFLAGS=' 75 | to build quietly or verbosely, respectively. 76 | ----- 77 | 78 | * Submitting patches 79 | 80 | If you develop a fix or a new feature, please send it to the 81 | appropriate bug-reporting address as reported by the --help option of 82 | each program. One way to do this is to use vc-dwim 83 | ), as follows. 84 | 85 | Run the command "vc-dwim --initialize" from the top-level directory 86 | of this package's git-cloned hierarchy. 87 | 88 | Edit the (empty) ChangeLog file that this command creates, creating a 89 | properly-formatted entry according to the GNU coding standards 90 | . 91 | 92 | Make your changes. 93 | 94 | Run the command "vc-dwim" and make sure its output (the diff of all 95 | your changes) looks good. 96 | 97 | Run "vc-dwim --commit". 98 | 99 | Run the command "git format-patch --stdout -1", and email its output 100 | in, using the output's subject line. 101 | 102 | ----- 103 | 104 | Copyright (C) 2002-2024 Free Software Foundation, Inc. 105 | 106 | This program is free software: you can redistribute it and/or modify 107 | it under the terms of the GNU General Public License as published by 108 | the Free Software Foundation, either version 3 of the License, or 109 | (at your option) any later version. 110 | 111 | This program is distributed in the hope that it will be useful, 112 | but WITHOUT ANY WARRANTY; without even the implied warranty of 113 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 114 | GNU General Public License for more details. 115 | 116 | You should have received a copy of the GNU General Public License 117 | along with this program. If not, see . 118 | -------------------------------------------------------------------------------- /testsuite/mb-y-translate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test multibyte y/// translations 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | require_en_utf8_locale_ 22 | 23 | # These tests use the following unicode characters in various ways: 24 | # GREEK CAPITAL LETTER PHI (U+03A6) 25 | # UTF-8: hex: 0xCE 0xA6 26 | # oct: 0316 0246 27 | # bin: 11001110 10100110 28 | # 29 | # GREEK CAPITAL LETTER DELTA (U+0394) 30 | # UTF-8: hex: 0xCE 0x94 31 | # oct: 0316 0224 32 | # bin: 11001110 10010100 33 | # 34 | # Octal encoding is used due to printf not supporting hex on older systems. 35 | # Using the first octet alone (\316) causes various multibyte related functions 36 | # to return '-2' (incomplete multibyte sequence). 37 | # using the second octet alone (\246) causess same functions to return '-1' 38 | # (invalid multibyte sequence). 39 | 40 | 41 | # 42 | # Test 1: valid multibyte 'dest-chars' 43 | # 44 | printf 'y/a/\316\246/' > p1 || framework_failure_ 45 | echo Xa > in1 || framework_failure_ 46 | printf 'X\316\246\n' > exp1 || framework_failure_ 47 | 48 | LC_ALL=en_US.UTF-8 sed -f p1 out1 || fail=1 49 | compare_ exp1 out1 || fail=1 50 | 51 | # in C locale, report error of mismatched length 52 | cat <<\EOF > exp-err1 || framework_failure_ 53 | sed: file p1 line 1: 'y' command strings have different lengths 54 | EOF 55 | returns_ 1 env LC_ALL=C sed -f p1 err1 || fail=1 56 | compare_ exp-err1 err1 || fail=1 57 | 58 | 59 | # 60 | # Test 2: valid multibyte 'src-chars' 61 | # 62 | printf 'y/\316\246/a/' > p2 || framework_failure_ 63 | printf 'X\316\246\n' > in2 || framework_failure_ 64 | echo Xa > exp2 || framework_failure_ 65 | 66 | LC_ALL=en_US.UTF-8 sed -f p2 out2 || fail=1 67 | compare_ exp2 out2 || fail=1 68 | 69 | # in C locale, report error of mismatched length 70 | cat <<\EOF > exp-err2 || framework_failure_ 71 | sed: file p2 line 1: 'y' command strings have different lengths 72 | EOF 73 | returns_ 1 env LC_ALL=C sed -f p2 err2 || fail=1 74 | compare_ exp-err2 err2 || fail=1 75 | 76 | 77 | # 78 | # Tests 3-6: invalid/incomplete multibyte characters in src/dest. 79 | # All work as-is in C locale, treated as single-bytes in multibyte locales. 80 | # None should fail. 81 | 82 | # Test 3: invalid multibyte 'dest-chars'. 83 | echo Xa > in3 || framework_failure_ 84 | printf 'y/a/\246/' > p3 || framework_failure_ 85 | printf 'X\246\n' > exp3 || framework_failure_ 86 | 87 | # Test 4: incomplete multibyte 'dest-chars'. 88 | echo Xa > in4 || framework_failure_ 89 | printf 'y/a/\316/' > p4 || framework_failure_ 90 | printf 'X\316\n' > exp4 || framework_failure_ 91 | 92 | # Test 5: invalid multibyte 'src-chars'. 93 | printf 'X\246\n' > in5 || framework_failure_ 94 | printf 'y/\246/a/' > p5 || framework_failure_ 95 | echo Xa > exp5 || framework_failure_ 96 | 97 | # Test 6: incomplete multibyte 'dest-chars'. 98 | printf 'X\316\n' > in6 || framework_failure_ 99 | printf 'y/\316/a/' > p6 || framework_failure_ 100 | echo Xa > exp6 || framework_failure_ 101 | 102 | for t in 3 4 5 6 ; 103 | do 104 | for l in C en_US.UTF-8 ; 105 | do 106 | LC_ALL=$l sed -f p$t out$t-$l || fail=1 107 | compare_ exp$t out$t-$l || fail=1 108 | done 109 | done 110 | 111 | 112 | # 113 | # Tests 7,8: length mismatch in multibyte locales 114 | # Implementation note: the code path for length check differ between 115 | # single-byte/multibyte locales. The actual characters don't have to be 116 | # multibyte themselves. 117 | printf 'y/abc/d/' > p7 || framework_failure_ 118 | cat <<\EOF > exp-err7 || framework_failure_ 119 | sed: file p7 line 1: 'y' command strings have different lengths 120 | EOF 121 | 122 | returns_ 1 env LC_ALL=en_US.UTF-8 sed -f p7 err7 || fail=1 123 | compare_ exp-err7 err7 || fail=1 124 | 125 | printf 'y/a/bcd/' > p8 || framework_failure_ 126 | cat <<\EOF > exp-err8 || framework_failure_ 127 | sed: file p8 line 1: 'y' command strings have different lengths 128 | EOF 129 | 130 | returns_ 1 env LC_ALL=en_US.UTF-8 sed -f p8 err8 || fail=1 131 | compare_ exp-err8 err8 || fail=1 132 | 133 | 134 | Exit $fail 135 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (C) 1990-2024 Free Software Foundation, Inc. 2 | 3 | # This program is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation, either version 3 of the License, or 6 | # (at your option) any later version. 7 | 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | 16 | PACKAGE = sed 17 | 18 | SUBDIRS = po . gnulib-tests 19 | 20 | 21 | # This applies to all parts: gnulib, sed, testsuites 22 | AM_CPPFLAGS = -I$(top_srcdir) \ 23 | -I$(top_srcdir)/lib \ 24 | -I$(top_builddir)/lib \ 25 | -I$(top_builddir)/sed 26 | 27 | AM_CFLAGS = 28 | BUILT_SOURCES = 29 | CLEANFILES = 30 | EXTRA_DIST = 31 | MAINTAINERCLEANFILES = 32 | MOSTLYCLEANDIRS = 33 | MOSTLYCLEANFILES = 34 | SUFFIXES = 35 | bin_PROGRAMS = 36 | noinst_LIBRARIES = 37 | noinst_DATA = 38 | noinst_HEADERS = basicdefs.h 39 | DISTCLEANFILES = 40 | 41 | EXTRA_DIST += BUGS THANKS.in \ 42 | .version \ 43 | .mailmap ChangeLog-2014 po/ChangeLog-2014 \ 44 | bootstrap bootstrap.conf build-aux/help2man \ 45 | thanks-gen 46 | 47 | BUILT_SOURCES += .version 48 | .version: 49 | $(AM_V_GEN)echo $(VERSION) > $@-t && mv $@-t $@ 50 | 51 | # Arrange so that .tarball-version appears only in the distribution 52 | # tarball, and never in a checked-out repository. 53 | dist-hook: gen-ChangeLog 54 | $(AM_V_GEN)echo $(VERSION) > $(distdir)/.tarball-version 55 | 56 | gen_start_date = 2014-09-06 57 | .PHONY: gen-ChangeLog 58 | gen-ChangeLog: 59 | $(AM_V_GEN)if test -d .git; then \ 60 | log_fix="$(srcdir)/build-aux/git-log-fix"; \ 61 | test -e "$$log_fix" \ 62 | && amend_git_log="--amend=$$log_fix" \ 63 | || amend_git_log=; \ 64 | $(top_srcdir)/build-aux/gitlog-to-changelog \ 65 | $$amend_git_log --since=$(gen_start_date) > $(distdir)/cl-t && \ 66 | { rm -f $(distdir)/ChangeLog && \ 67 | mv $(distdir)/cl-t $(distdir)/ChangeLog; } \ 68 | fi 69 | 70 | # Sort in traditional ASCII order, regardless of the current locale; 71 | # otherwise we may get into trouble with distinct strings that the 72 | # current locale considers to be equal. 73 | ASSORT = LC_ALL=C sort 74 | 75 | # Extract all lines up to the first one starting with "##". 76 | prologue = perl -ne '/^\#\#/ and exit; print' $(srcdir)/THANKS.in 77 | 78 | THANKS: THANKS.in Makefile.am .mailmap thanks-gen .version 79 | $(AM_V_GEN)rm -f $@-t $@; \ 80 | { \ 81 | $(prologue); echo; \ 82 | { perl -ne '/^$$/.../^$$/ and print' $(srcdir)/THANKS.in \ 83 | | grep -v '^$$' | perl -pe 's/ +/\0/'; \ 84 | git log --pretty=format:'%aN%x00%aE' \ 85 | | $(ASSORT) -u; \ 86 | } | $(srcdir)/thanks-gen \ 87 | | LC_ALL=en_US.UTF-8 sort -f; \ 88 | echo; \ 89 | printf ';; %s\n' 'Local Variables:' 'coding: utf-8' End:; \ 90 | } > $@-t && chmod a-w $@-t && mv $@-t $@ 91 | 92 | 93 | AM_DISTCHECK_CONFIGURE_FLAGS = XGETTEXT='$(SHELL) -c : dummy' $(EXTRA_DC_FLAGS) 94 | EXTRA_DC_FLAGS = 95 | 96 | full-distcheck: 97 | $(MAKE) distcheck EXTRA_DC_FLAGS='--enable-regex-tests' 98 | $(MAKE) distcheck EXTRA_DC_FLAGS='--enable-html' 99 | $(MAKE) distcheck EXTRA_DC_FLAGS='--disable-i18n' 100 | $(MAKE) distcheck EXTRA_DC_FLAGS='--disable-nls' 101 | $(MAKE) distcheck EXTRA_DC_FLAGS='--without-included-gettext' 102 | @case "$(host)" in \ 103 | *-linux*|*-gnu*) \ 104 | echo $(MAKE) distcheck \ 105 | EXTRA_DC_FLAGS=\'--without-included-regex\'; \ 106 | $(MAKE) distcheck EXTRA_DC_FLAGS='--without-included-regex' \ 107 | ;; \ 108 | *) \ 109 | echo Skipping check --without-included-regex \ 110 | ;; \ 111 | esac 112 | 113 | include $(top_srcdir)/lib/local.mk 114 | include $(top_srcdir)/sed/local.mk 115 | include $(top_srcdir)/doc/local.mk 116 | include $(top_srcdir)/testsuite/local.mk 117 | 118 | # Remove the generated sed.1 file, but only for a non-srcdir build. 119 | # Without this, 'make distcheck's final comparison would fail. 120 | # Also remove lib/.deps/{getfilecon,obstack}.Po, 121 | # which are left behind by bleeding edge automake. 122 | # Without this, 'make distcheck's final comparison would fail. 123 | distclean-local: 124 | test x$(srcdir) = x$(builddir) || rm -f $(dist_man_MANS) 125 | rm -f lib/.deps/getfilecon.Po lib/.deps/obstack.Po 126 | 127 | # Shortcut targets to make it easier to run (very) expensive tests. 128 | check-expensive: 129 | $(MAKE) check RUN_EXPENSIVE_TESTS=yes 130 | check-very-expensive: 131 | $(MAKE) check-expensive RUN_VERY_EXPENSIVE_TESTS=yes 132 | -------------------------------------------------------------------------------- /testsuite/mb-charclass-non-utf8.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test multibyte locale which is not UTF-8 (ja_JP.shift_jis) 3 | # This is a stateful locale. Same byte value can be either 4 | # a single-byte character, or the second byte of a multibyte 5 | # character. 6 | 7 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 8 | 9 | # This program is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program. If not, see . 21 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 22 | print_ver_ sed 23 | 24 | # If found, LOCALE_JA_SJIS will contain the locale name. 25 | require_ja_shiftjis_locale_ 26 | 27 | # Ensure the implementation is not buggy (skip otherwise) 28 | require_valid_ja_shiftjis_locale_ "$LOCALE_JA_SJIS" 29 | 30 | # This test uses two characters: 31 | # Unicode Character 'KATAKANA LETTER ZE' (U+30BC) 32 | # Unicode Character 'KATAKANA LETTER ZO' (U+30BE) 33 | # 34 | # In SHIFT-JIS locale, these multibyte characters contain 35 | # open/close brackets (ASCII 0x5B/0x5D) as the trailing byte. 36 | # 37 | # See also: 38 | # https://en.wikipedia.org/wiki/Shift_JIS 39 | # http://www.rikai.com/library/kanjitables/kanji_codes.sjis.shtml 40 | 41 | # Unicode Character 'KATAKANA LETTER ZE' (U+30BC) 42 | # 43 | # UTF-8: hex: 0xE3 0x82 0xBC 44 | # bin: 11100011 10000010 10111100 45 | # 46 | # Shift-jis hex: 0x83 0x5B 47 | # oct: 203 133 48 | # bin: 10000011 01011011 49 | # 50 | # Conversion example: 51 | # $ printf '\x83\x5B' | iconv -f SHIFT-JIS -t UTF-8 | od -tx1o1c 52 | # 0000000 e3 82 bc 53 | # 343 202 274 54 | # 343 202 274 55 | 56 | # Unicode Character 'KATAKANA LETTER ZO' (U+30BE) 57 | # 58 | # UTF-8: hex: 0xE3 0x82 0xBE 59 | # bin: 11100011 10000010 10111110 60 | # 61 | # Shift-jis hex: 0x83 0x5D 62 | # oct: 203 135 63 | # bin: 10000011 01011101 64 | # 65 | # Conversion example: 66 | # $ printf '\x83\x5D' | iconv -f SHIFT-JIS -t UTF-8 | od -tx1o1c 67 | # 0000000 e3 82 be 68 | # 343 202 276 69 | # 343 202 276 70 | # 71 | 72 | 73 | # 74 | # Tests 1,2: Test y/// command with multibyte, non-utf8 seqeunce. 75 | # Implmenetation notes: str_append() has special code path for non-utf8 cases. 76 | # 77 | 78 | # Test 1: valid multibyte seqeunce 79 | printf 'y/a/\203\133/' > p1 || framework_failure_ 80 | echo Xa > in1 || framework_failure_ 81 | printf 'X\203\133\n' > exp1 || framework_failure_ 82 | 83 | LC_ALL="$LOCALE_JA_SJIS" sed -f p1 out1 || fail=1 84 | compare_ exp1 out1 || fail=1 85 | 86 | # Test 2: invalid multibyte seqeunce, treated as two single-byte characters. 87 | printf 'y/aa/\203\060/' > p2 || framework_failure_ 88 | LC_ALL="$LOCALE_JA_SJIS" sed -f p2 out2 || fail=1 89 | compare_ /dev/null out2 || fail=1 90 | 91 | # 92 | # Test 3: multibyte character class with these characters. 93 | # 94 | # Before sed-4.3, snarf_char_class would parse it incorrectly, 95 | # Treating the first closing-bracket as closing the character-class, 96 | # instead of being part of a multibyte sequence. 97 | 98 | printf '/[\203]/]/p' > p3 || framework_failure_ 99 | LC_ALL="$LOCALE_JA_SJIS" sed -f p3 out3 || fail=1 100 | compare_ /dev/null out3 || fail=1 101 | 102 | # Test 4: 103 | # Same as test 3, but with the other multibyte character. 104 | # (this did not cause a failure before sed-4.3, but the code was incorrect). 105 | # Keep this test for code-coverage purposes. 106 | printf '/[\203[/]/p' > p4 || framework_failure_ 107 | LC_ALL="$LOCALE_JA_SJIS" sed -f p4 out4 || fail=1 108 | compare_ /dev/null out4 || fail=1 109 | 110 | # TODO: Find a locale in which ':.=' can be part of a valid multibyte octet. 111 | # 112 | # snarf_char_class specifically tests for five bytes: ':.=[]' . 113 | # '[' and ']' are tested above, yet '.:=' are not valid as part of a 114 | # multibyte shift-jis sequence. 115 | # 116 | # valid: 117 | # $ printf '\203]' | iconv -f SHIFT-JIS -t utf-8 118 | # $ printf '\203[' | iconv -f SHIFT-JIS -t utf-8 119 | # 120 | # invalid: 121 | # $ printf '\203:' | iconv -f SHIFT-JIS -t utf-8 122 | # iconv: (stdin):1:0: cannot convert 123 | # 124 | # $ printf '\203=' | iconv -f SHIFT-JIS -t utf-8 125 | # iconv: (stdin):1:0: cannot convert 126 | # 127 | # $ printf '\203.' | iconv -f SHIFT-JIS -t utf-8 128 | # iconv: (stdin):0:0: cannot convert 129 | 130 | Exit $fail 131 | -------------------------------------------------------------------------------- /testsuite/execute-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test execution less-common cases 3 | 4 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 19 | print_ver_ sed 20 | 21 | # 22 | # 'D' when pattern-space has no newline (act like 'd') 23 | # 24 | echo a | sed 1D > out1 || fail=1 25 | compare_ /dev/null out1 || fail=1 26 | 27 | # 28 | # s///e with a command that returns zero output 29 | # 30 | printf "\n" > exp2 || framework_failure_ 31 | echo "" | sed '1etrue' > out2 || fail=1 32 | compare_ exp2 out2 || fail=1 33 | 34 | 35 | # 36 | # plain 'e' with a command that returns non-delimted output 37 | # 38 | printf "a\n" > exp3 || framework_failure_ 39 | echo "printf a" | sed '1e' > out3 || fail=1 40 | compare_ exp3 out3 || fail=1 41 | 42 | # 43 | # plain 'e' with a command that returns delimted '\n' output 44 | # (implementation note: the delimiter is first chomp'd) 45 | printf "a\n" > exp4 || framework_failure_ 46 | echo "echo a" | sed '1e' > out4 || fail=1 47 | compare_ exp4 out4 || fail=1 48 | 49 | # 50 | # e with a command that returns delimted '\0' output 51 | # 52 | printf "b\0" > exp5 || framework_failure_ 53 | # This input file contains the shell command to be excuted: 54 | printf 'cat exp5' > in5 || framework_failure_ 55 | sed -z '1e' out5 || fail=1 56 | compare_ exp5 out5 || fail=1 57 | 58 | if test "$fail" -eq 1 ; then 59 | od -tx1c exp5 60 | od -tx1c out5 61 | fi 62 | 63 | # 64 | # 'P' command, with and without '\n' in the pattern space 65 | # 66 | echo a > in6 || framework_failure_ 67 | printf "%s\n" a b | sed -n 'N;P' > out6 || fail=1 68 | compare_ in6 out6 || fail=1 69 | 70 | printf "%s\n" a | sed -n 'P' > out7 || fail=1 71 | compare_ in6 out7 || fail=1 72 | 73 | # 74 | # 'q' and other commands with big numbers (2**256 + 1, 2 ** 256 + 2) 75 | # 76 | big1=115792089237316195423570985008687907853269984665640564039457584007913129639937 77 | big2=115792089237316195423570985008687907853269984665640564039457584007913129639938 78 | printf '%s\n' a b >in7a || framework_failure_ 79 | sed ${big1}q in7a >out7a1 || fail=1 80 | compare_ in7a out7a1 || fail=1 81 | sed -n 1,${big1}p in7a >out7a2 || fail=1 82 | compare_ in7a out7a2 || fail=1 83 | sed ${big1},${big2}d in7a >out7a3 || fail=1 84 | compare_ in7a out7a3 || fail=1 85 | 86 | # 87 | # 'Q' with exit code 88 | # 89 | echo a > in7 || framework_failure_ 90 | returns_ 42 sed '1Q42' in7 || fail=1 91 | 92 | # 93 | # 'r' without a filename (silently ignored) 94 | # 95 | echo c > in8 || framework_failure_ 96 | sed 'rfoo.bar' in8 > out8 || fail=1 97 | compare_ in8 out8 || fail=1 98 | 99 | # 100 | # 'W' without a filename (silently ignored) 101 | # 102 | echo d > in9 || framework_failure_ 103 | sed 'Wfoo1' in9 > out9 || fail=1 104 | compare_ in9 out9 || fail=1 105 | 106 | # 107 | # 'W', with and without '\n' in pattern space 108 | # 109 | 110 | # pattern-space with '\n', only 'a' should be written 111 | printf "%s\n" a b > in10 || framework_failure_ 112 | echo a > a || framework_failure_ 113 | sed 'N;Ww1.txt' in10 > out10 || fail=1 114 | compare_ a w1.txt || fail=1 115 | compare_ in10 out10 || fail=1 116 | 117 | # pattern-space without '\n', entire pattern-space ('a') should be written 118 | sed 'Ww2.txt' a > out11 || fail=1 119 | compare_ a out11 || fail=1 120 | compare_ a w2.txt || fail=1 121 | 122 | 123 | # 124 | # 'T' command 125 | # 126 | 127 | # Unsuccessful substitute, 'T' jumps to 'skip'. 128 | echo a | sed -n 's/X/Y/ ; Tskip ; Q42 ; :skip' || fail=1 129 | 130 | # Successful substitute, 'T' does not jumps to 'skip', sed exits with code 42. 131 | echo a | returns_ 42 sed -n 's/a/Y/ ; Tskip ; Q42 ; :skip' || fail=1 132 | 133 | 134 | # 135 | # 'F' command 136 | # 137 | echo a > in12 || framework_failure_ 138 | printf "%s\n" in12 a > exp12 || framework_failure_ 139 | sed F in12 > out12 || fail=1 140 | compare_ exp12 out12 || fail=1 141 | 142 | # 'F' with multiple files 143 | echo b > in13 || framework_failure_ 144 | echo c > in14 || framework_failure_ 145 | printf "%s\n" in12 a in13 b in14 c > exp14 || framework_failure_ 146 | sed F in12 in13 in14 > out14 || fail=1 147 | compare_ exp14 out14 || fail=1 148 | 149 | # 'F' with stdin 150 | printf "%s\n" - a > exp15 || framework_failure_ 151 | sed F < in12 > out15 || fail=1 152 | compare_ exp15 out15 || fail=1 153 | 154 | 155 | Exit $fail 156 | -------------------------------------------------------------------------------- /testsuite/convert-number.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test number conversion from escape sequences \xNN \oNNN \dNNN 3 | # (compile.c:convert_number()) 4 | 5 | # Copyright (C) 2016-2024 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed 20 | print_ver_ sed 21 | 22 | # 23 | # Test \dNNN conversions 24 | # 25 | printf "%s\n" a a a a a a a > in-d || framework_failure_ 26 | 27 | # Each line is a separate test case 28 | cat <<\EOF >prog-d 29 | # Expected output: ASCII 0x0D '\r' 30 | 1s/./\d13/ 31 | 32 | # Expected output: ASCII 0xff '\3ff' 33 | 2s/./\d255/ 34 | 35 | # Expected (?) output: 'dB' 36 | # (\d followed by character >= base 10, treated as '\d', which is 'd'). 37 | 3s/./\dB/ 38 | 39 | # Expected (?) output: 'dQ' 40 | # (\d followed by non-hex character, treated as '\d', which is 'd'). 41 | 4s/./\dQ/ 42 | 43 | # Expected output: '{4' 44 | # \dNNN is limited to three digits. 45 | # The first three digits are 123 = 0x7b = '{'. '4' is treated as-is. 46 | 5s/./\d1234/ 47 | 48 | # Expected (?) output: '\1' 49 | # undocumented implementation-specific limitation: 50 | # After 3 digit limits, the 8-bit value is used, 51 | # decimal 513 wraps-around to 1. 52 | 6s/./\d513/ 53 | 54 | # Expected output: '\0','7' 55 | # (three digit limit) 56 | 7s/./\d0007/ 57 | EOF 58 | 59 | printf '\r\n\377\ndB\ndQ\n{4\n\1\n\0007\n' > exp-d || framework_failure_ 60 | 61 | sed -f prog-d in-d > out-d || fail=1 62 | compare_ exp-d out-d || fail=1 63 | 64 | if test "$fail" -eq 1 ; then 65 | od -tx1c prog-d 66 | od -tx1c exp-d 67 | od -tx1c out-d 68 | fi 69 | 70 | 71 | 72 | 73 | # 74 | # Test \oNNN conversions 75 | # 76 | printf "%s\n" a a a a a a > in-o || framework_failure_ 77 | 78 | # Each line is a separate test case 79 | cat <<\EOF >prog-o 80 | # Expected output: '\5' 81 | 1s/./\o5/ 82 | 83 | # Expected output: ASCII 0xff '\3ff' 84 | 2s/./\o377/ 85 | 86 | # Expected (?) output: 'o9' 87 | # (\o followed by character >= base 18, treated as '\o', which is 'o'). 88 | 3s/./\o9/ 89 | 90 | # Expected (?) output: 'oQ' 91 | # (\o followed by non-hex character, treated as '\o', which is 'o'). 92 | 4s/./\oQ/ 93 | 94 | # Expected output: 'S4' 95 | # \oNNN is limited to three digits. 96 | # The first three digits are o123 = 0x53 = 'S'. '4' is treated as-is. 97 | 5s/./\o1234/ 98 | 99 | # Expected (?) output: '\1' 100 | # undocumented implementation-specific limitation: 101 | # After 3 digit limits, the 8-bit value is used, 102 | # octal 401 wraps-around to 1. 103 | 6s/./\o401/ 104 | EOF 105 | 106 | printf '\5\n\377\no9\noQ\nS4\n\1\n' > exp-o || framework_failure_ 107 | 108 | sed -f prog-o in-o > out-o || fail=1 109 | compare_ exp-o out-o || fail=1 110 | 111 | if test "$fail" -eq 1 ; then 112 | od -tx1c prog-o 113 | od -tx1c exp-o 114 | od -tx1c out-o 115 | fi 116 | 117 | 118 | 119 | 120 | 121 | # 122 | # Test \xNN conversions 123 | # 124 | printf "%s\n" a a a a > in-x || framework_failure_ 125 | 126 | # Each line is a separate test case 127 | cat <<\EOF >prog-x 128 | # Expected output: ASCII 0x06 '\6' 129 | 1s/./\x6/ 130 | 131 | # Expected output: ASCII 0xCE '\316' 132 | 2s/./\xce/ 133 | 134 | # Expected (?) output: 'xy' 135 | # (\x followed by non-hex character, treated as '\x', which is 'x'). 136 | 3s/./\xy/ 137 | 138 | # Expected output: '\253' 'c' (0xAB = 253 octal) 139 | # \xNN is limited to two digits. 140 | 4s/./\xabc/ 141 | EOF 142 | 143 | printf '\6\n\316\nxy\n\253c\n' > exp-x || framework_failure_ 144 | 145 | sed -f prog-x in-x > out-x || fail=1 146 | compare_ exp-x out-x || fail=1 147 | 148 | if test "$fail" -eq 1 ; then 149 | od -tx1c prog-x 150 | od -tx1c exp-x 151 | od -tx1c out-x 152 | fi 153 | 154 | 155 | # for completeness, cover all possible letters/digits 156 | 157 | printf "%s\n" a a a a a a a a a a a > cnv-num-in || framework_failure_ 158 | cat << \EOF > cnv-num-prog || framework_failure_ 159 | 1s/./\x01/ 160 | 2s/./\x23/ 161 | 3s/./\x45/ 162 | 4s/./\x67/ 163 | 5s/./\x89/ 164 | 6s/./\xAB/ 165 | 7s/./\xab/ 166 | 8s/./\xCD/ 167 | 9s/./\xcd/ 168 | 10s/./\xef/ 169 | 11s/./\xEF/ 170 | EOF 171 | 172 | printf '\1\n#\nE\ng\n\211\n\253\n\253\n\315\n\315\n\357\n\357\n' \ 173 | > cnv-num-exp || framework_failure_ 174 | 175 | sed -f cnv-num-prog cnv-num-in > cnv-num-out || fail=1 176 | compare_ cnv-num-exp cnv-num-out || fail=1 177 | 178 | Exit $fail 179 | --------------------------------------------------------------------------------