Commit Graph
311 Commits
Author SHA1 Message Date
Stanislav Brabec e387009c78 sed: fix --follow-symlinks to work when reading stdin
When reading from stdin, use of --follow-symlinks would cause failure:

  $ echo abc | sed --follow-symlinks s/a/d/
  sed: cannot stat -: No such file or directory

* sed/execute.c (open_next_file): Set input->in_file_name earlier,
so we can rearrange logic to avoid calling follow_symlink("-").
* testsuite/follow-symlinks-stdin.sh: New file.
* testsuite/Makefile.am (T): Add it.
* NEWS (Bug fixes): Mention it.
Bug introduced by commit v4.2.1-13-g84066bf.
http://bugs.gnu.org/20795
2015-07-15 21:40:31 -07:00
Jim Meyering fe9c9b6cfa typo fix: s/singlebyte/single-byte/
* sed/compile.c (compile_program, normalize_text): Fix typo.
* sed/mbcs.c (brlen): Likewise.
2015-06-23 15:32:35 -07:00
Jim Meyering c033bdee41 sed -i: do not treat "-" as a file name
Most GNU utilities treat "-" as standard input, sed itself does that --
in most contexts.  However, since the addition of support for
--in-place (-i) in sed-4.0, sed -i has treated a "-" argument as a
file name, i.e., like ./-.  Now, that usage evokes a diagnostic:

  $ sed -i s/a/b/ -
  sed: couldn't edit -: is a terminal

If you require the old behavior, specify the file name as "./-".
Prompted by the report/patch from Stanislav Brabec in
http://bugs.gnu.org/20796 to document the strangely
inconsistent legacy behavior.

* sed/execute.c (open_next_file): Call panic before
even attempting to operate on the file descriptor.
* testsuite/in-place-hyphen.sh: New file.  Test for this.
* testsuite/Makefile.am (T): Add it.
* NEWS (Feature removal): Mention it. Admittedly, the old behavior
feels more like a misfeature.
2015-06-20 19:58:08 -07:00
Jim Meyering 2714d42345 tests: initialize $fail to 0
* testsuite/range-overlap.sh: Otherwise, with $fail set to
nonzero in the environment, this test would report failure,
even when it should pass.
2015-06-20 19:58:08 -07:00
Jim Meyering 68e47c0c62 build: avoid warning about implicit declaration of unlink
* sed/sed.c: Include <unistd.h>, for declaration of unlink.
Without this change, commit makes sed v4.2.2-84-g7689015 fail
to compile when configured with --enable-gcc-warnings.
2015-05-10 09:33:27 -07:00
Jim Meyering 768901548e sed -i: don't leave behind a temporary sedXXXXXX file
For example, running a command like "sed -i s//b/ F" would fail
to remove a temporary file named sedXXXXXX (for random XXXXXX)
in the directory alongside F.
* sed/sed.c (G_file_to_unlink): New global.
(register_cleanup_file, cancel_cleanup, cleanup): New functions.
(main): Call atexit.
* sed/execute.c (open_next_file): Register for unlink.
(closedown): Call cancel_cleanup right after the rename.
* sed/sed.h: Declare two of the new functions.
* NEWS (Bug fixes): Mention it.
* testsuite/temp-file-cleanup.sh: New file.  Test for this.
* testsuite/Makefile.am (T): Add it.
Reported by David Jones in http://bugs.gnu.org/20002.
2015-05-10 09:29:04 -07:00
Jim Meyering 3201f1dcbe maint: remove stray blank line in the middle of a comment
* sed/utils.c (ck_mkstemp): As above.
2015-05-07 08:07:03 -07:00
Jim Meyering af342f7233 tests: skip the new test in presence of buggy valgrind
* testsuite/invalid-mb-seq-UMR.sh: Upon failure due to a
valgrind-internal assertion, skip this test.
Reported by Norihiro Tanaka in http://debbugs.gnu.org/20490
2015-05-07 08:04:48 -07:00
Norihiro Tanaka 4c75f64068 sed: fix mishandling of overlapping address ranges
When the line number ranges of two or more editing commands overlap,
sed applies all commands but the first to a line that is just beyond
the union of all ranges.  E.g., with this command,
seq 9|sed '2,7d;3,6d', sed would mistakenly delete line 8.

* sed/execute.c (match_an_address_p) [ADDR_IS_NUM]: Make this
function work also in this case.
(match_address_p): Move the ADDR_IS_NUM +
...->line_number == ...->addr_number comparison "up" into
match_an_address_p, so we can hoist two similar if/return
blocks out of "if" and "else" branches.
Change so that this function returns false when the current
line number is outside the specified range.
* testsuite/range-overlap.sh: New file, to test for this.
* testsuite/Makefile.am (T): Add it to the list.
* NEWS (Bug fixes): Mention it.
Reported as http://bugs.gnu.org/19899
2015-05-06 19:18:54 -07:00
Jim Meyering b1517867eb build: do not require autoconf.git
* configure.ac: Use AC_CONFIG_MACRO_DIR, not
the new (as yet unreleased) AC_CONFIG_MACRO_DIRS.
Reported by Hongyi Zhao in http://debbugs.gnu.org/20424
2015-05-04 07:29:31 -07:00
Jim Meyering 62ae3e9016 maint: housekeeping: sync a few rules from coreutils
* cfg.mk (sc_preprocessor_indentation): New rule, from coreutils.
(local-checks-to-skip): Exempt it, for now.
(sc_THANKS_in_sorted): Another rule from coreutils.  Enabled.
(announcement_Cc_): Define, so the auto-generated announcement
message template includes sed-devel@ as a recipient.
(update-copyright-env) [UPDATE_COPYRIGHT_USE_INTERVALS]: Update
to use =2, rather than=1, so that the next time we update
copyright dates, it will collapse a few more ranges.
2015-05-03 11:11:28 -07:00
Jim Meyering 7c826cb41f maint: tweak comments and rearrange code slightly
* sed/execute.c (str_append): Trivial NSC code transformation.
(str_append_modified): Tweak another comment.
2015-05-03 10:56:16 -07:00
Jim Meyering af7a509eaa tests: test for just-fixed UMR bug
* testsuite/invalid-mb-seq-UMR.sh: New file. Test for just-fixed bug.
* testsuite/Makefile.am (T): New variable.
Add the two init.sh-using test names here, rather than in
two separate lists.
(SEDTESTS, EXTRA_DIST): Use $(T).
(EXTRA_DIST): Add init.cfg.
* testsuite/init.cfg: New file, to add functions from coreutils.
(require_valgrind_, print_ver_): New functions.
2015-05-03 10:03:44 -07:00
Norihiro Tanaka 78e8e58ab0 sed: avoid a UMR bug when processing an invalid multibyte sequence
* sed/execute.c (str_append_modified): When attempting to append an
invalid multibyte sequence, e.g., from the RHS of a substitution
expression, we would read uninitialized memory.
Don't capitalize first word of diagnostic; remove exclamation point.
Wrap new translatable strings in _(...).
* NEWS (Bug fixes): Mention it.
This addresses http://debbugs.gnu.org/20490
2015-05-03 10:01:15 -07:00
Jim Meyering 3277f269a2 maint: remove SED_FEATURE_VERSION; use PACKAGE_VERSION instead
* configure.ac (SED_FEATURE_VERSION): Remove definition et al.
* sed/compile.c (compile_program): Remove sole use.
Use PACKAGE_VERSION instead.
2015-05-02 19:28:38 -07:00
Jim Meyering 29baca551b maint: add "/*~" to build-aux/ and m4/.gitignore files
Otherwise, bootstrap would add entries for individual file names.
* build-aux/.gitignore: Add /*~
* m4/.gitignore: Likewise.
2015-05-02 10:13:25 -07:00
Jim Meyering 857ed5c3b9 maint: enable sc_file_system
* cfg.mk (local-checks-to-skip): Remove its exemption.
* BUGS (characters): s/filesystem/file system/
* ChangeLog-2014 (setup_jump): Likewise.
* doc/sed-in.texi: Likewise.
* doc/sed.texi: Likewise.
2015-05-01 18:09:51 -07:00
Jim Meyering 312c75163a build: require gettext 0.19.2, perl-5.5
* configure.ac: Require gettext-0.19.2.
* bootstrap.conf: List perl and gettext version requirements.
2015-05-01 18:09:39 -07:00
Jim Meyering 885402bc29 tests: set sed's expected failure status to 4
* testsuite/help-version.sh (expected_failure_status_sed): As above.
2015-04-27 07:26:01 -07:00
Jim Meyering 44a0755f64 maint: invoke make via $(MAKE), not via "make"
* Makefile.am (html): Invoke make via $(MAKE).
(full-distcheck): Likewise.
2015-04-26 22:57:27 -07:00
Jim Meyering 2636740851 use generated version.[ch] and add init.sh and help-version.sh
* Makefile.am (DISTCLEANFILES): Initialize.
(EXTRA_DIST): Add .version.
(BUILT_SOURCES): Set to .version.
(.version): New rule.
(THANKS): Depend on .version.
* sed/Makefile.am: Add rules to build version.[ch].
* sed/sed.c: Include version.h, and use the new variable, Version.
* testsuite/Makefile.am: Arrange to distribute and run the new
help-version.sh test. Also distribute the new init.sh.
* testsuite/help-version.sh: New file.
* testsuite/init.sh: Likewise.
* .gitignore: Ignore the generated files, .version and src/version.[ch].
2015-04-26 12:30:33 -07:00
Jim Meyering 2f5dbefd8b maint: COPYRIGHT_YEAR: remove, along with tests that use it
This is covered by other tests, and the general --help/--version
checks provided by help-version.sh (about to be added) are more
thorough.
* configure.ac (COPYRIGHT_YEAR): Remove definition and AC_SUBST.
* Makefile.am (dist-hook): Remove test.
* testsuite/Makefile.am (SEDTESTS): Remove "version".
* testsuite/version.gin: Remove file.
* .gitignore: Remove mention of generated file, version.good.
2015-03-01 20:21:17 -08:00
Jim Meyering 5b16974db6 maint: initialize an mbstate_t with "= { 0, };", rather than with memset
I.e., use this:
  mbstate_t mbstate = { 0, };
rather than this:
  mbstate_t mbstate;
  memset (&cur_stat, 0, sizeof (mbstate_t));
Also, prefer "sizeof VAR" over sizeof(TYPE).
* sed/execute.c (execute_program, translate_mb): As above.
* sed/compile.c (match_slash, compile_program, normalize_text):
Likewise.
2015-01-01 19:21:26 -08:00
Jim Meyering 96fe108e64 maint: enable sc_prohibit_long_lines
* cfg.mk (local-checks-to-skip): Remove the overall exemption,
but continue to exempt some files in testsuite/.
* configure.ac: Split a long line.
* doc/sed-in.texi: Split long lines.
* doc/sed.texi: Likewise.
* sed/compile.c: Likewise.
* sed/execute.c: Split long lines.
(execute_program): Reorder "#ifdef HAVE_POPEN" and
"if (pipe_fp != NULL)" if/else blocks to make the code
clearer and (incidentally) the lines shorter, due to a
decrease in nesting level.
* sed/sed.c: Split long lines.
* sed/utils.c: Likewise.
* sed/utils.h: Likewise.
2015-01-01 19:21:26 -08:00
Jim Meyering 5445ae1fc3 maint: translate_mb: new function factored out of 'y'-handling case
* sed/execute.c (translate_mb): New function, factored out of
the "case 'y':" part of...
(execute_program): ...here.
2015-01-01 19:21:26 -08:00
Jim Meyering 63f190e574 maint: remove more unnecessary declarations
* sed/execute.c: Remove now-duplicate forward declarations.
2015-01-01 19:21:26 -08:00
Jim Meyering 082b25cc3e maint: update copyright year ranges to include 2015; update gnulib 2015-01-01 19:18:17 -08:00
Jim Meyering 311d11269e maint: enable sc_prohibit_strncpy check
* cfg.mk (exclude_file_name_regexp--sc_prohibit_strncpy): Remove
its exemption.
* sed/compile.c (compile_program): Remove two misuses of strncpy;
use memcpy instead.
* sed/execute.c (do_list): Likewise, for one instance.
2014-12-20 18:51:52 -08:00
Jim Meyering 9eb391523b maint: begin to use "size_t" more, where appropriate
* sed/execute.c (do_list): Update some "int" locals to "size_t",
and combine a few declarations with needlessly separate initializations.
2014-12-20 18:51:45 -08:00
Jim Meyering bea07ed28f maint: update .gitignore
* .gitignore: Ignore build artifacts.
2014-12-20 16:39:53 -08:00
Jim Meyering 0a6fe4a625 maint: remove po/sed.pot from version control
* po/sed.pot: Remove file.  It is unnecessary and undesirable to
version-control a file like this (mechanically-derived).
2014-12-20 16:11:49 -08:00
Jim Meyering 33493b14bb build: update build tool version requirements
* bootstrap.conf (buildreq): Blindly update tool-version number
requirements from those required by coreutils.
2014-12-20 16:03:50 -08:00
Jim Meyering a5d187ada0 maint: fix "make distcheck" failure
* Makefile.am (EXTRA_DIST): List THANKS.in, not THANKS.
Add .mailmap, too.
2014-12-20 16:03:50 -08:00
Jim Meyering 6783c9f367 build: build-aux/texi2dvi: remove file
* build-aux/texi2dvi: Remove file. It was out of date and could
no longer parse our .texi files.
* Makefile.am (EXTRA_DIST): Don't list it here.
* cfg.mk: Remove an exemption for that file.
* doc/Makefile.am (TEXI2DVI): Remove definition.
2014-12-20 16:03:40 -08:00
Jim Meyering be2d5c0d33 remove support for the 'L' (fmt/flow-paragraph) command
* sed/Makefile.am (sed_SOURCES): Remove fmt.c.
* sed/execute.c (execute_program):
* sed/fmt.c: Remove file.
* sed/sed.h (fmt): Remove declaration.
* doc/sed.texi: Remove documentation for 'L' command.
* doc/sed-in.texi: Likewise.
* NEWS (Feature removal): Document it.
Prompted by the report from Jodie Cunningham that using this
command with a large number could cause sed to segfault:
https://bugs.launchpad.net/ubuntu/+source/sed/+bug/1400575
2014-12-16 15:40:57 -08:00
Jim Meyering 38800587a9 doc: NEWS: mention the gzip->xz release tarball switch
* NEWS (Build-related): Mention that we are now distributing
only .tar.xz archives; no more gzip-compressed tarballs.
2014-12-01 21:59:02 -08:00
Jim Meyering 383efa5436 build: avoid warning about unused fchown result
* sed/execute.c: Include "ignore-value.h".
(closedown): Explicitly ignore fchown return value.
* bootstrap.conf (gnulib_modules): Add ignore-value.
* lib/.gitignore: Ignore the new .h file.
* .gitignore: Ignore all **~ backup files.
2014-12-01 11:07:16 -08:00
Jim Meyering 671770af8b build: use gnulib's manywarnings module
bootstrap.conf: Add the module name.
configure.ac: Copy boilerplate and exclusions from coreutils.
sed/Makefile.am (AM_CFLAGS): Define in terms of the two new
variables, $(WARN_CFLAGS) and $(WERROR_CFLAGS).
m4/.gitignore: Add the two new .m4 files.
2014-11-30 21:08:33 -08:00
Jim Meyering 263c26e4d1 maint: add three casts-in-initialization to avoid warnings
* sed/compile.c (special_files): When initializing, cast string
literals to (char *) to avoid warnings.
2014-11-30 21:08:33 -08:00
Jim Meyering 2fae6cb1e3 maint: avoid a gcc "const discard" warning
* sed/compile.c (compile_program): Make a local "const" to avoid
discarding "const" attribute in assignment.
2014-11-30 21:08:32 -08:00
Jim Meyering 157626b785 maint: avoid more gcc warnings: apply _GL_ATTRIBUTE_PURE
* sed/utils.h (get_buffer, size_buffer): Make each functions
sole parameter "const" and declare the function itself with the
"pure" attribute.
* sed/utils.c (get_buffer, size_buffer): Adjust definitions to match.
2014-11-30 21:08:32 -08:00
Jim Meyering e09428778d maint: add _Noreturn attribute to two functions
This avoids two gcc may-be-noreturn warnings:
* sed/sed.h (bad_prog): Add _Noreturn attribute.
* sed/utils.h (panic): Likewise.
2014-11-30 21:07:57 -08:00
Jim Meyering 366b04cabd maint: manually convert K&R to ANSI style decls; and add "static"
Convert many function definitions from K&R to ANSI style.
When possible, make a function static and remove the immediately-
preceding declaration of that same function.
Also, add the const to a few declarations.
* sed/compile.c: As above.
(special_files): Likewise.
* sed/execute.c: Likewise.
* sed/fmt.c: Likewise.
* sed/mbcs.c: Likewise.
* sed/regexp.c: Likewise.
* sed/sed.c: Likewise.
* sed/sed.h: Likewise.
* sed/utils.c: Likewise.
2014-11-30 20:47:09 -08:00
Jim Meyering 1743b7f3cb maint: declare several "int" locals to be of type size_t
* sed/compile.c (compile_program): Using "int" was wrong: not only
too narrow, but would also evoke warnings from gcc when comparing
with variables of unsigned type.
2014-11-30 18:59:35 -08:00
Jim Meyering c750cb5fd1 maint: avoid gcc warning about unused macro
* sed/regexp.c (END_ERRORS): Remove definition of unused macro.
2014-11-30 18:59:35 -08:00
Jim Meyering 3e28ea356a maint: avoid false-positive used-uninit. warning from gcc
* sed/sed.h (IF_LINT): Define.
* sed/compile.c (snarf_char_class) [lint]: Use it to initialize DELIM,
so that gcc doesn't report it is used uninitialized.
2014-11-30 18:59:35 -08:00
Jim Meyering 4916618496 maint: enable sc_prohibit_empty_lines_at_EOF check
* cfg.mk (exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF):
* cfg.mk (local-checks-to-skip): Remove its exemption.
Adjust many files to end in a single newline, but exempt a few
test suite input and output files.
* testsuite/fasts.sed: Remove three empty lines at EOF.
* BUGS: Remove empty line at EOF.
* sed/mbcs.c: Likewise.
* sed/sed.h: Likewise.
* testsuite/BOOST.tests: Likewise.
* testsuite/dc.inp: Add a newline at EOF; there was none.
* testsuite/flipcase.sed: Likewise.
* testsuite/utf8-1.good: Likewise.
* testsuite/utf8-1.inp: Likewise.
* testsuite/utf8-2.good: Likewise.
* testsuite/utf8-2.inp: Likewise.
* testsuite/utf8-3.good: Likewise.
* testsuite/utf8-3.inp: Likewise.
* testsuite/utf8-4.good: Likewise.
* testsuite/utf8-4.inp: Likewise.
* testsuite/xbxcx.good: Likewise.
* testsuite/xbxcx.inp: Likewise.
* testsuite/xemacs.good: Likewise.
* testsuite/xemacs.inp: Likewise.
2014-11-30 18:59:35 -08:00
Jim Meyering e48ca0d39c maint: enable sc_prohibit_tab_based_indentation syntax check
* cfg.mk (local-checks-to-skip): Remove its exemption.
Exempt all files under testsuite/, for now, and a few others.
* .gitmodules: Change each leading TAB to 8 spaces spaces.
* BUGS: Likewise.
* NEWS: Likewise.
* configure.ac: Likewise.
* sed/compile.c: Likewise.
* sed/execute.c: Likewise.
* sed/fmt.c: Likewise.
* sed/regexp.c: Likewise.
* sed/sed.c: Likewise.
* sed/sed.h: Likewise.
* sed/utils.c: Likewise.
* sed/utils.h: Likewise.
* COPYING: Update from coreutils.
2014-11-30 18:59:35 -08:00
Jim Meyering 8d5fa64778 maint: enable sc_m4_quote_check syntax check
* cfg.mk (local-checks-to-skip): Remove its exemption.
* configure.ac: Fix the under-quoting problems thus exposed.
2014-11-30 18:59:34 -08:00
Jim Meyering ba5e0dbcc9 maint: enable sc_cast_of_argument_to_free syntax check
* cfg.mk (local-checks-to-skip): Remove its exemption.
* testsuite/tst-rxspencer.c (mb_test): Remove a cast.
2014-11-30 18:59:34 -08:00