Commit graph

33 commits

Author SHA1 Message Date
Tim J. Robbins 81a8648adb Make the 'y' (translate) command aware of multibyte characters. 2004-07-14 10:06:22 +00:00
Brian Somers 7bbdbe1482 Plug a file descriptor leak.
When sed is asked to inline-edit files, it forgets to close the temporary
file and runs out of descriptors for long command lines (assuming you reset
kern.maxfilesperproc to something sane that's less than the number of files
passed to sed).
2004-06-03 22:33:50 +00:00
Dag-Erling Smørgrav 591c337e01 Fix the case where the file is not in the current directory.
Discovered by:	Vladimir Kravchenko <jimson@mostcom.ru>
Pointy hat to:	des
2003-11-04 22:39:25 +00:00
Dag-Erling Smørgrav f54cda1467 Reimplement in-place editing in a slightly less disgusting manner. Also,
make an effort to preserve the ownership and mode of the file we are
editing.

Sponsored by:	Registrar AS
2003-11-04 13:09:16 +00:00
Dag-Erling Smørgrav e6478125c8 ANSIfy 2003-11-04 12:15:20 +00:00
Dag-Erling Smørgrav 9df25dda8c Correct style bugs in the in-place editing code. 2003-11-04 12:07:09 +00:00
Tony Finch d1691a2ff6 Fix some bugs in in-place editing:
(1) errors from freopen were not reported correctly
(2) large files were not handled correctly
(3) read-only files broke things

MFC after:	1 week
2002-07-30 19:42:18 +00:00
Tim J. Robbins 8523e9a677 Avoid checking whether each line is the last line of the file when we don't
need to know. Instead, check when we are trying to match a "$" address.
This does not change the way sed processes regular files, but makes it behave
more sensibly when used interactively.

PR:		40101
MFC after:	2 weeks
2002-07-03 14:38:27 +00:00
Tim J. Robbins ed92199d30 Don't store newlines at the end of each line in the hold/pattern spaces,
instead add the newline when the pattern space is printed. Make the `G' and
`H' commands add a newline to the space before the data, remove bogus
addition of newline from `x' command.

PR:		29790, 38195
2002-06-22 01:42:26 +00:00
Tim J. Robbins 254fac850d Correct the handling of (for example) the N command by only zeroing the
input space in mf_fgets() if we reach the end of all input files.
2002-06-16 08:44:39 +00:00
Tim J. Robbins 6689fb2bbc Exit with non-zero status if an input file can not be opened. This was
broken by rev. 1.22.
2002-06-14 02:20:05 +00:00
Maxim Sobolev 8701af62ee Fix one serious bug and one potential problem with in-place editing code:
- original version of code worked incorrectly when more than one
  input files were specified - it was moving the last line from the 1st file
  to be the first line of the 2nd, last line of the 2nd to be the first
  line of the 3rd and so on;

- use mmap()->write() to create temporary file instead of
  malloc()->read()->write(), which was not only slower, but also did not
  bother to free allocated memory once backup file was created, potentially
  leading to memory exhausting when regex is applied to a big file or a large
  number of small ones.
2002-06-14 01:28:52 +00:00
Tim J. Robbins 3af4dcb223 If a file argument cannot be processed, process the remaining ones
and exit non-zero (SUSv3)
2002-05-24 10:58:21 +00:00
Brian Feldman e7b663eff2 o Clean up tmp file usage a little by using mkstemp(3) instead of
mktemp(3).  It would be amazingly unlikely, but the former method
  could result in a symlink attack.  A better solution would use
  ${TMPDIR}, though.
o Make sed not overwrite old backup files with no warning.
2002-05-14 23:15:42 +00:00
Juli Mallett 90f7fe63e9 Oops, update usage() to have -i. 2002-05-07 23:33:44 +00:00
Juli Mallett 5d16412db7 Add handling for any nil-length string passed to -i for the backup extension.
Add a note that this is kinda-sorta dangerous to the manual page.
2002-05-07 23:32:26 +00:00
Juli Mallett d88e9d841a Un-shadow the `fname' variable. 2002-05-07 23:06:47 +00:00
Juli Mallett 839af0c103 Add a -i option to sed(1) to do inplace editing, to give us an alternative to
Perl for such things.  The key difference to Perl is that a backup extension
*MUST* be specified, because on one hand it isn't recommended to have options
which optionally take a parameter, and on the other hand, it'd be slightly
unpleasent to implement proper handling for that.

The difference between this and the version posted to developers@ is that it
does handle multiple files in argv after the getopt(3) handling "correctly",
in that the inplace editing-specific code has been moved out to a function,
and that function is used beyond the first file in our linked list.

This option has been documented as FreeBSD-specific in the manpage.

Reviewed by:	developers@ (got feedback from: des, fanf, sobomax, roberto,
		obrien)
MFC after:	1 week
2002-05-07 18:32:18 +00:00
Warner Losh 3f330d7d1a remove __P 2002-03-22 01:42:45 +00:00
Mark Murray e74bf75f1c WARNS=2 partial fix; use NO_WERROR to protect against some hard-to-fix warnings.
Use __FBSDID(), kill register keyword.
2001-12-12 23:20:16 +00:00
David E. O'Brien 8e33c0a0f6 Expand xmalloc in-place, along with xrealloc; which wasn't even ANSI in its
implementation.
2001-07-24 14:05:21 +00:00
Nick Sayer f6c7a9efb8 Small style fix '=' -> ' = ' 2000-05-11 20:15:16 +00:00
Nick Sayer e6121e72f6 Fix compatibility issue in sed. Do so by explicitely adding a
newline to the end of any -e argument.

PR: bin/18474
2000-05-11 17:01:52 +00:00
Brian Feldman 175de1e677 Add a new flag: -E enables "extended" regular expressions. 2000-03-19 19:41:53 +00:00
Peter Wemm c3aac50f28 $Id$ -> $FreeBSD$ 1999-08-28 01:08:13 +00:00
Archie Cobbs c56690ef7b Fix a new bug introduced by the previous bug fix 1998-12-08 21:29:22 +00:00
Philippe Charnier 73a08bb2ad Remove local redefinition for err(). Add usage(). 1997-08-11 07:21:08 +00:00
Warner Losh 1c8af87873 compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.
1997-03-29 04:34:07 +00:00
Wolfram Schneider 5f4cf81e9d fix C programmer's bug number 12.2
submitted by: bruce
1996-11-17 02:16:34 +00:00
Joerg Wunsch 771301de24 Fix the C programmer's bug #1: EOF is of type int', not char'.
Strong 2.2 candidate.

Submitted by:	wosch
1996-11-17 00:22:54 +00:00
Andrey A. Chernov 726aebe5e0 Localize it
8bit cleanup
1996-08-11 17:46:35 +00:00
Rodney W. Grimes 2828ae663a Fix spelling error (scipt -> script).
Submitted by:	<jhawk@MIT.EDU>
Obtained from:	NetBSD-bugs mailling list
1995-02-23 17:46:35 +00:00
Rodney W. Grimes 9b50d90275 BSD 4.4 Lite Usr.bin Sources 1994-05-27 12:33:43 +00:00