Commit Graph

214 Commits

Author SHA1 Message Date
Julio Merino
3a92d97ff0 Migrate most of tools/regression/usr.bin/ to the new tests layout.
I'm starting with the easy cases.  The leftovers need to be looked at a
bit more closely.

Note that this change _does_ modify the code of the old tests.  This is
required in order to allow the code to locate the data files in the
source directory instead of the current directory, because Kyua
automatically changes the latter to a temporary directory.

Also note that at least one test is known to be broken here.  Actually,
the test is not really broken: it's marked as a TODO but unfortunately
Kyua's TAP parser currently does not understand that.  Will have to be
fixed separately.
2014-03-16 08:04:06 +00:00
Eitan Adler
49e8901465 Per the resolution of POSIX bug 0000779 (note 0002050) add support for using 'i'
as a case insensitive flag.

PR:		standards/184641
Requested by:	David A. Wheeler <dwheeler@dwheeler.com>
MFC After:	1 week
2013-12-09 18:57:20 +00:00
Simon J. Gerraty
d1d0158641 Merge from head 2013-09-05 20:18:59 +00:00
Pedro F. Giffuni
1a2a4fc8ce sed: use getline() instead of fgetln().
In BSD, fgetln() available in libc but in Illumos the Solaris port had to
include it internally. It also seems to have caused problems [1].

Aid portability by using getline() instead.

Reference:
https://www.illumos.org/issues/3820 [1]

Submitted by:	Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.com>
Reviewed by:	dds
MFC after:	2 weeks
2013-06-26 04:14:19 +00:00
Simon J. Gerraty
7cf3a1c6b2 Updated dependencies 2013-03-11 17:21:52 +00:00
Simon J. Gerraty
f5f7c05209 Updated dependencies 2013-02-16 01:23:54 +00:00
Marcel Moolenaar
7750ad47a9 Sync FreeBSD's bmake branch with Juniper's internal bmake branch.
Requested by: Simon Gerraty <sjg@juniper.net>
2012-08-22 19:25:57 +00:00
Eitan Adler
50d675f7a9 Remove trailing whitespace per mdoc lint warning
Disussed with:	gavin
No objection from:	doc
Approved by:	joel
MFC after:	3 days
2012-03-29 05:02:12 +00:00
Andrey A. Chernov
7d3c2941c4 Reword '}' description to sound more clear.
Submitted by:   dougb
MFC after:      7 days
2011-10-29 06:13:47 +00:00
Andrey A. Chernov
c7d7f9a140 Update '}' description to reflect reality (and POSIX)
PR:             96236
Submitted by:   "Andreas Kohn" <andreas@syndrom23.de>
MFC after:      7 days
2011-10-28 20:28:13 +00:00
Jilles Tjoelker
919e14f01e sed: Try hard links to make -i target available continually.
When creating a backup file, sed renamed the original before renaming the
changed copy into place, leading to a short time when no file with the
original name was present (usually only visible on SMP systems). Try
creating the backup file using a hard link instead, avoiding this problem.
If creating the hard link fails for any reason, fall back to the old rename
method.

When not creating a backup file, sed already renamed the changed copy onto
the original. This remains unchanged.

I am not adding the suppression of redundant fchown/fchmod to this commit,
because FreeBSD appears to check this in the kernel (for msdosfs at least).

PR:		bin/153261
Submitted by:	Pedro F. Giffuni
Reviewed by:	dds (older version)
Obtained from:	Illumos
MFC after:	2 weeks
2011-01-08 00:03:18 +00:00
Warner Losh
701d73b65c Make -r mean exactly the same thing as -E for increased compatibility
with GNU sed.

MFC after:	7 days
2010-03-31 17:40:13 +00:00
Ed Schouten
b7946da96b Build usr.bin/ with WARNS=6 by default.
Also add some missing $FreeBSD$ to keep svn happy.
2010-01-02 10:27:05 +00:00
Xin LI
821df508e8 Revert most part of 200420 as requested, as more review and polish is
needed.
2009-12-13 03:14:06 +00:00
Xin LI
6f2d322192 Remove unneeded header includes from usr.bin/ except contributed code.
Tested with:	make universe
2009-12-11 23:35:38 +00:00
Diomidis Spinellis
ac8f32ce62 IEEE Std 1003.1, 2004 Edition states:
"The escape sequence '\n' shall match a <newline> embedded in
the pattern space."

It is unclear whether this also applies to a \n embedded in a
character class.  Disable the existing handling of \n in a character
class following Mac OS X, GNU sed version 4.1.5 with --posix, and
SunOS 5.10 /usr/bin/sed.

Pointed by:	Marius Strobl
Obtained from:	Mac OS X
2009-09-20 15:47:31 +00:00
Diomidis Spinellis
76570d0a99 Follow POSIX (IEEE Std 1003.1, 2004 Edition) in the implementation
of the y (translate) command.

"If a backslash character is immediately followed by a backslash
character in string1 or string2, the two backslash characters shall
be counted as a single literal backslash character"

Pointed by:	Marius Strobl
Obtained from:	Mac OS X
2009-09-20 15:17:40 +00:00
Diomidis Spinellis
128e6a12b5 Allow [ to be used as a delimiter.
Pointed by:	Marius Strobl
Obtained from:	Apple
2009-09-20 14:11:33 +00:00
Brian Somers
f1b746f92d Bump the document date to reflect the recent address range enhancements.
Suggested by:	throdes
2009-05-25 21:29:06 +00:00
Brian Somers
f879e8d923 Implement "addr1,+N" ranges - not dissimilar to grep's -A switch.
PR:		134856
Submitted by:	Jeremie Le Hen - jeremie at le-hen dot org
2009-05-25 06:45:33 +00:00
Diomidis Spinellis
46da6c4869 Fix the code to conform to the "or more" part of the following POSIX
specification and regression test regress:25.

  "A function can be preceded by one or more '!' characters, in which
  case the function shall be applied if the addresses do not select
  the pattern space."

MFC after:	2 weeks
2008-11-11 17:15:57 +00:00
Hiroki Sato
d3d0d3a3b5 Add workaround for a back reference when no corresponding
parenthesized subexpression is defined.  For example, the
following command line caused unexpected behavior like
segmentation fault:

 % echo test | sed -e 's/test/\1/'

PR:		bin/126682
MFC after:	1 week
2008-11-09 01:10:21 +00:00
Yaroslav Tykhiy
db6fc08364 Correct a silly typo I introduced: withing -> within.
Noticed by:	das
2008-09-01 17:48:40 +00:00
Yaroslav Tykhiy
625451f9f4 Explicitly tell that one needs to start a context address with a
backslash if he/she wants to use a non-traditional delimiter, i.e.,
anything other than a slash.  That is, /abc/ works as is, but xabcx
needs to be spelled as \xabcx.

Add appropriate markup.

Bump Dd.

Checked with:	IEEE Std 1003.1, 2004 Edition
MFC after:	3 days
2008-08-24 13:47:53 +00:00
David Malone
d3e5e11ce6 WARNS fixes:
1) Add missing parens around assignment that is compared to zero.
2) Make some variables that only take non-negative values unsigned.
3) Some casts/type changes to fix other constness warnings.
4) Make one variable a const char *.
5) Make sure termwidth is positive, it doesn't make sense for it to be negative.

Approved by:	dds
2008-02-09 09:12:02 +00:00
Diomidis Spinellis
a511e63958 Fix visibility of "inplace".
Found by: CScout
2007-11-08 08:57:51 +00:00
Xin LI
870945d830 Before doing compile_re() which needs a parameter to identify
whether we should ignore case, determine the flag by calling
compile_flags() first.  Also, make sure that we obtain an
initialized cmd->u.s buffer before processing further.  We
may want to refine this solution later, but for now, make
the changes in order to unbreak world build after a sed(1)
with rev. 1.29 of compile.c is installed.

Approved by:	re (hrs)
2007-07-06 16:34:56 +00:00
Suleiman Souhlal
bdd72b703b Add case-insensitive matching to sed, using the 'I' flag, similarly to GNU sed.
For example,
	sed /foo/Id
	sed s/foo/bar/Ig

Reviewed by:	dds
Approved by:	re (hrs)
2007-07-04 16:42:41 +00:00
Yaroslav Tykhiy
85ae5d2f94 Drop the argument to the OUT macro because it can't emit
anything but the pattern space anyway.  Apply style(9)
to the macro.

Tested with:	md5(1)
2007-06-12 12:17:25 +00:00
Yaroslav Tykhiy
26a5710c40 Don't forget to clear out the hold space for each subsequent file
when in -i mode so that each file gets a clean context of its own.

Add a regression test for the bug.

Tested with:	regression tests
2007-06-12 12:05:24 +00:00
Yaroslav Tykhiy
bebfe2adf7 There is a symbolic antonym for REPLACE as a flag to cspace()
and mf_fgets(): APPEND.  So use it instead of a 0 constant for
clarity.

Tested with:	md5(1)
2007-06-12 10:56:38 +00:00
Yaroslav Tykhiy
70b36fc0c8 Don't forget to bump document date after changing the content. 2007-04-21 01:22:51 +00:00
Yaroslav Tykhiy
f6703c9c0a Change the semantics of -i (in-place editing) so that it treats
each file independently from other files.  The new semantics are
desired in the most of practical cases, e.g.: delete lines 5-9
from each file.

Keep the previous semantics of -i under a new option, -I, which
uses a single continuous address space covering all files to edit
in-place -- they are too cool to just drop them.

Add regression tests for -i and -I.

Approved by:	dds
Compared with:	GNU sed
Discussed on:	-hackers
MFC after:	2 weeks
2007-04-21 01:21:36 +00:00
Yaroslav Tykhiy
9cfc96edd7 style(9):
Use a single space before $FreeBSD$ to avoid terminal line overflow.

Pointed out by:		ru (The All-Seeing Eye)
2007-04-06 08:43:30 +00:00
Yaroslav Tykhiy
4ebdfcd2e1 Add an important detail to paragraph 12: the range is reset only if its
second address is a line number.
2007-04-05 17:12:01 +00:00
Yaroslav Tykhiy
0d68e7fead Reflect the change in rev. 1.44 of process.c.
Add $FreeBSD$ to please commit_prep.pl.
2007-04-05 13:31:17 +00:00
Yaroslav Tykhiy
e9a0eed451 Don't forget to close the range if we branched over its end
and had no chance to match it by the 2nd address precisely.
Otherwise the unclosed range would bogusly extend to the end
of stream.

Add a basic regression test for the bug fixed.  (This change
also fixes the more complex case 5.3 from `multitest.t'.)

Compared with:	SUN and GNU seds
Tested by:	regression tests
MFC after:	1 week
2007-04-02 08:14:46 +00:00
Yaroslav Tykhiy
b1b46280cb Prevent foot-shooting in advance: Put the MATCH() macro's value
in parentheses.  The ?: operator has a remarkably low precedence, so
expressions like (MATCH(foo) && bar) would have an unexpected meaning
w/o the parentheses around MATCH().

Tested with:	md5(1)
2007-04-02 06:47:48 +00:00
Yaroslav Tykhiy
6b8ef68111 This trivial change should fix at least 3 similar bugs. All of
them are related to the `c' function's need to know if we are at
the actual end of the address range.  (It must print the text not
earlier than the whole pattern space was deleted.)  It appears the
only sed function with this requirement.

There is `lastaddr' set by applies(), which is to notify the `c'
function, but it can't always help because it's false when we are
hitting the end of file early.  There is also a bug in applies()
due to which `lastaddr' isn't set to true on degenerate ranges such
as `$,$' or `N,$' if N appears the last line number.

Handling early EOF condition in applies() could look more logical,
but it would effectively revert sed to the unreasonable behaviour
rev. 1.26 of main.c fought against, as it would require lastline()
be called for each line within each address range.  So it's better
to call lastline() only if needed by the `c' function.

Together with this change to sed go regression tests for the bugs
fixed (c1-c3).  A basic test of `c' (c0) is also added as it helped
me to spot my own error.

Discussed with:		dds
Tested by:		the regression tests
MFC after:		1 week
2007-04-01 13:25:03 +00:00
Yaroslav Tykhiy
c691c0ed18 Make the comment for cspace() match reality. 2007-03-31 09:08:22 +00:00
Diomidis Spinellis
d6eb3444a3 Test files repo-copied into tools/regression/usr.bin/sed and integrated
into the regression testing framework.
2007-03-14 13:43:32 +00:00
Kirill Ponomarev
85184b8b23 Fix using "P" command on empty pattern space. If the "P" command is
used once on a non-empty pattern space and then again on an empty
pattern space, the second usage restores the pattern space length to
the length that it had when the first "P" was used.

PR:		bin/96052
Submitted by:	Andrey Zholos <aaz@althenia.net>
MFC after:	7 days
2006-05-27 19:32:28 +00:00
Stefan Farfeleder
7c4847b792 The function inplace_edit() doesn't exist anymore, remove the prototype.
Submitted by:	Leonardo Chiquitto Filho
2005-09-24 13:18:30 +00:00
Diomidis Spinellis
d432588e78 Bug fix: a numeric flag specification in the substitute command would
cause the next substitute flag to be ignored.
While working at it, detect and report overflows.

Reported by:	Jingsong Liu
MFC after:	1 week
2005-08-04 10:05:12 +00:00
Ruslan Ermilov
39c59153e9 Markup and wording fixes.
Approved by:	re (blanket)
2005-06-14 11:50:53 +00:00
Gleb Smirnoff
1ed86f6c90 Add option -l, to make output line buffered.
PR:		bin/78692
Submitted by:	Eugene Grosbein
MFC after:	2 weeks
2005-05-10 13:40:50 +00:00
Stefan Farfeleder
6c97c3d1d3 Remove unused variables. 2005-04-09 14:31:41 +00:00
Stefan Farfeleder
3dc2fe25dc Fix dubious C code construct. 2005-03-09 11:57:32 +00:00
Ruslan Ermilov
0227791b40 Expand *n't contractions. 2005-02-13 22:25:33 +00:00
Stefan Farfeleder
a3eb24c68b Include missing headers. 2005-02-09 09:13:36 +00:00
Ruslan Ermilov
a866e17077 Added the EXIT STATUS section where appropriate. 2005-01-17 07:44:44 +00:00
Ruslan Ermilov
4438d91ea2 Scheduled mdoc(7) sweep. 2005-01-11 10:32:52 +00:00
Diomidis Spinellis
30fd73fb81 Per letter dated July 22, 1999 remove 3rd clause of Berkeley derived
software (original contributor).

Reviewed by:	imp
2004-08-09 15:29:41 +00:00
Tim J. Robbins
e4d0177f50 Document the limitation that multibyte characters cannot be used as
delimiters with the 's' and 'y' commands.
2004-07-17 03:37:31 +00:00
Tim J. Robbins
220d8b581a Document the -E and -a options as being extensions. 2004-07-14 10:37:21 +00:00
Tim J. Robbins
8b086367a0 Update BUGS section to reflect current state of multibyte character support. 2004-07-14 10:33:29 +00:00
Tim J. Robbins
81a8648adb Make the 'y' (translate) command aware of multibyte characters. 2004-07-14 10:06:22 +00:00
Tim J. Robbins
b4828720f7 Overhaul lputs() to deal with multibyte characters, characters that take
up more than one column position, and null bytes.
2004-07-13 04:35:43 +00:00
Tim J. Robbins
4f45d81178 Document missing multibyte character support in utilities specified
by POSIX.
2004-07-03 01:28:21 +00:00
Ruslan Ermilov
6a3e8b0adc Mechanically kill hard sentence breaks. 2004-07-02 22:22:35 +00:00
Ruslan Ermilov
d37ea99837 Removed trailing whitespace. 2004-07-02 19:07:33 +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
Sean Kelly
528d980cc0 A new version that does exponents and lots of other neat things. Update
from the original author of math.sed.

Submitted by:	K S Braunsdorf <sed@ksb.npcguild.org>
2004-05-01 02:15:58 +00:00
Philippe Charnier
ca802a8abe Avoid using .Nm at the start of the sentence. 2004-01-04 15:33:06 +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
9cde9a2e85 Whitespace cleanup 2003-11-04 12:16:47 +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
Tim J. Robbins
ce20a8e9be Change the buffer length test in NEEDSP() so that it does not
subtract one unsigned number from another potentially smaller
one, leading to wraparound (and heap corruption, eventually).

PR:		58813
MFC after:	2 weeks
2003-11-02 23:20:24 +00:00
Diomidis Spinellis
b6059c5c01 Fixed .Nm element, updated HISTORY section, added AUTHORS section.
Reviewed by:	schweikh (mentor)
MFC after:	2 weeks
2003-07-22 19:23:45 +00:00
Diomidis Spinellis
37c94e1d78 Test 8.16 in sed.test tests the ability of a sed to handle an empty
regular expression as the first argument to a substitute command. If
used to test a sed which (erroneously) evaluates this at translation
time rather than at execution time, the bugged sed is put into an
infinite loop. This mode of failure seems excessive. Such a failing
sed is the Free Software Foundation's sed 3.02.

The specific test was also not being executed for the BSD sed.

Both problems are now fixed.

PR:		misc/25585
Submitted by:	Walter Briscoe <w.briscoe@ponl.com>
Approved by:	schweikh (mentor)
MFC after:	2 weeks
2003-07-22 19:22:08 +00:00
Tony Finch
c2b9b6eba8 Do not dribble zero bytes into the output, by replacing an obfuscated if
whose true and false clauses were equivalent with a check that we are
not about to stumble off the end of the line.

Reported by:	peter
Pointy hat to:	fanf
2003-06-05 12:10:19 +00:00
Tony Finch
2f17b7e279 Fix substitution when the regex matches the zero-length string.
There are two bugs: in the s///g case, the substitution didn't occur
at the end of the line; in the s///N case, the code didn't count
forwards along the line properly. See the sg, s3, s4, and s5 tests
in src/tools/regression/usr.bin/sed/.

Reviewed by:	tjr
2003-06-04 15:31:55 +00:00
Jens Schweikhardt
9d5abbddbf Correct typos, mostly s/ a / an / where appropriate. Some whitespace cleanup,
especially in troff files.
2003-01-01 18:49:04 +00:00
Ruslan Ermilov
06e482e60a mdoc(7) police: markup polishing.
Approved by:	re
2002-11-26 17:33:37 +00:00
Eric Melville
b81df0819d Initialize a variable in order to fix when faced with picky compilers.
Sponsored by:	Apple
2002-09-20 19:40:23 +00:00
Tim J. Robbins
13ee49d316 Correct boundary condition error in D' and P' commands when the last
line of the pattern space is empty. Don't emit spurious newline when
EOF is reached with the `N' command.

Pointed out by:	Oleg Osyka
MFC after:	1 week
2002-08-11 09:53:44 +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
0467aed3c9 Ignore leading semicolons on commands; required by SUSv3.
Obtained from:	NetBSD (kleink, Aymeric Vincent)
2002-07-30 14:07:30 +00:00
Mark Murray
8bd89d7e04 s/inline/__inline/ 2002-07-19 14:12:27 +00:00
Tim J. Robbins
dfb072f405 Make cspace()'s second argument const. Make `escapes' in lputs() const. 2002-07-08 06:00:55 +00:00
Tim J. Robbins
05018c64fd Silence WARNS=4 by passing a non-const buffer to regerror(). Since it
doesn't actually use the buffer when errbuf_size == 0, pass NULL.
2002-07-08 05:36:24 +00:00
Tim J. Robbins
54411faf6f Update another mention of <CR><CR> I missed the first time around (rev 1.2) 2002-07-04 05:16:19 +00:00
Tim J. Robbins
bfed7b6485 Note that two carriage returns aren't required after entering the
initial setup anymore (since process.c rev. 1.25). Add $FreeBSD$.

MFC after:	2 weeks
2002-07-03 14:42:53 +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
5a3232258e Don't let the pattern space become null if the `x' command is used when the
hold space is null; some functions assume it's never null.

MFC after:	3 days
2002-07-03 14:32:43 +00:00
Tim J. Robbins
42676968c6 Sort sections, and refer to sed as a utility, not a function. 2002-06-25 08:36:19 +00:00
Tim J. Robbins
d1a1392d8f Fix off by one in `y' (transliterate) command which caused the last character
of the pattern space not to be examined.

Noticed by:	Motoyuki Konno <motoyuki@bsdclub.org>
2002-06-24 11:24:02 +00:00
Tim J. Robbins
5953156dca Now that the pattern space contains no trailing newline, modify the `l'
command's output so it's the same as what SUSv3 specifies.
2002-06-22 03:00:52 +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
Maxim Sobolev
33bad4f17d Kill superfluous blank line. 2002-06-17 08:21:53 +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
e7cc3a2191 Refer to environ(7) for description of COLUMNS instead of describing it
in-line. Document effects of locale environment variables in the same way.
2002-06-10 07:55:13 +00:00
Tim J. Robbins
1fa600e8fe The 10 occurrence limit for the `s' command documented here has not existed
for a very long time (or never did exist).
2002-06-10 07:44:04 +00:00
Tim J. Robbins
2ef53777fd Newlines are not escaped anymore. 2002-06-10 07:27:32 +00:00
Tim J. Robbins
e307a7a172 Don't write escape newlines with `l' command (SUSv3) 2002-06-10 07:25:35 +00:00
Tim J. Robbins
03fef72fe9 Correctly handle global substitutions where the pattern is only "$", the
EOL anchor, when the last input line does not end in a newline character.
Picked up by the GNU sed test suite.
2002-06-10 06:06:20 +00:00