History log of /freebsd-current/usr.bin/sed/process.c
Revision Date Author Comments
# bdcbfde3 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

usr.bin: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# b4805026 29-Aug-2018 Mark Johnston <markj@FreeBSD.org>

sed: Fix -i option behavior with 'q' command.

Don't just exit when encountering the 'q' command if we edit file
inplace, and give mf_fgets() a chance to actually handle the
inplace case.

Also add a regression test.

Submitted by: Yuri Pankov <yuripv@yuripv.net>
Approved by: re (kib)
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D16798


# 0649b670 30-Jul-2018 Pedro F. Giffuni <pfg@FreeBSD.org>

sed: unsign some indexes to fix sign-compare warnings.

Hinted by: OpenBSD (CVS 1.32)

MFC after: 1 week


# 8a16b7a1 20-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

General further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.


# fbbd9655 28-Feb-2017 Warner Losh <imp@FreeBSD.org>

Renumber copyright clause 4

Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by: Jan Schaumann <jschauma@stevens.edu>
Pull Request: https://github.com/freebsd/freebsd/pull/96


# 249a8a80 02-Aug-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

sed(1): Revert r303047 "cleanup" and therefore r303572.

While big, the change was meant to have no effect on behavior and instead
so far we have found two regressions: one in the etcupdate tests and
another one in the games/openttd port[1].

Revert to a known working state. We will likely have to split the patch in
functional parts before bringing back the changes.

PR: 195929
Reported by: danfe, madpilot [1]


# f05dbca7 21-Jul-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

sed(1): Appease older GCC.


# b4932d18 19-Jul-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

sed(1): Assorted cleanups and simplifications.

Const-ify several variables, make it build cleanly with WARNS level 5.

Submitted by: mi
PR: 195929
MFC after: 1 month


# 4386fba7 17-Jul-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

sed(1): Fix off by one introduced in r299211.

Detected by running the gsed tests.

Submitted by: Mikhail Teterin
PR: 195929
MFC after: 3 days


# 7e777743 01-Jun-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

sed(1): Fix a mismatch and sync with the OpenBSD's commit.

This was causing some strange behaviour.

Reported by: olivier
Obtained from: OpenBSD (CVS rev. 1.28)


# 924b84c1 25-May-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

sed: convert sed to use REG_STARTEND more explicitly.

Summarizing the findings in the OpenBSD list:

This solves a reproduceable issue with very recent Mesa where REG_NOTBOL
combined with a match at the begin of the string causes our regex library
to treat the word as not begin of word.

Thanks to Martijn van Duren and Ingo Schwarze for taking the time to
solve this in the least invasive way.

PR: 209352, 209387
Taken from: openbsd-tech (Martijn van Duren)
MFC after: 1 month


# b6f5aa57 06-May-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

sed: rewrite the main loop.

Rewrite the main loop of the "sed s/..." command, shortening it by ten
lines and simplifying it by removing the switch statement implementing
/g, /1, and /2 separately and repetitively.

This will be needed to bring a fix from OpenBSD later.

Obtained from: OpenBSD (schwarze CVS Rev. 1.18)
MFC after: 3 weeks


# fc04dce0 27-Jan-2015 Pedro F. Giffuni <pfg@FreeBSD.org>

Fix resource leak and dereference after NULL.

process.c:
Protect access against NULL.

main.c:
Prevent outfile overwrite resource leak.

CID: 271181
CID: 1006930

Obtained from: NetBSD
MFC after: 3 days


# a161398a 12-Jan-2015 Pedro F. Giffuni <pfg@FreeBSD.org>

Replace __inline GNUism with the standard inline.

MFC after: 1 week


# 707c9cc5 08-Jan-2015 Pedro F. Giffuni <pfg@FreeBSD.org>

sed: Address warnings with clang and gcc48.

MFC after: 2 weeks


# 96d68291 08-Aug-2014 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>

sed(1): Don't force a newline on last line, if input stream doesn't have one

While here, change how we check if the current line is the last one.
Before, we just checked if there were more files after the current one.
Now, we check the actual content of those files: they files may not have
a line at all. This matches the definition of the "last line" by the
Open Group.

The new behavior is closer to GNU sed.

PR: 160745
Phabric: https://phabric.freebsd.org/D431
Reviewed by: jilles
Approved by: jilles
Exp-run by: antoine


# b38ebc05 30-Jul-2014 Jeremie Le Hen <jlh@FreeBSD.org>

Fix relative numerical addressing (addr,+N).

As a bonus the patch untangles a bit the logic and makes the code
easier to grasp.

PR: 192108
MFC after: 1 week


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# f879e8d9 25-May-2009 Brian Somers <brian@FreeBSD.org>

Implement "addr1,+N" ranges - not dissimilar to grep's -A switch.

PR: 134856
Submitted by: Jeremie Le Hen - jeremie at le-hen dot org


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# d3e5e11c 09-Feb-2008 David Malone <dwmalone@FreeBSD.org>

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


# 85ae5d2f 11-Jun-2007 Yaroslav Tykhiy <ytykhiy@gmail.com>

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)


# 26a5710c 11-Jun-2007 Yaroslav Tykhiy <ytykhiy@gmail.com>

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


# bebfe2ad 12-Jun-2007 Yaroslav Tykhiy <ytykhiy@gmail.com>

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)


# f6703c9c 20-Apr-2007 Yaroslav Tykhiy <ytykhiy@gmail.com>

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


# e9a0eed4 02-Apr-2007 Yaroslav Tykhiy <ytykhiy@gmail.com>

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


# b1b46280 02-Apr-2007 Yaroslav Tykhiy <ytykhiy@gmail.com>

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)


# 6b8ef681 01-Apr-2007 Yaroslav Tykhiy <ytykhiy@gmail.com>

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


# c691c0ed 31-Mar-2007 Yaroslav Tykhiy <ytykhiy@gmail.com>

Make the comment for cspace() match reality.


# 85184b8b 27-May-2006 Kirill Ponomarev <krion@FreeBSD.org>

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


# 6c97c3d1 09-Apr-2005 Stefan Farfeleder <stefanf@FreeBSD.org>

Remove unused variables.


# 30fd73fb 09-Aug-2004 Diomidis Spinellis <dds@FreeBSD.org>

Per letter dated July 22, 1999 remove 3rd clause of Berkeley derived
software (original contributor).

Reviewed by: imp


# 81a8648a 14-Jul-2004 Tim J. Robbins <tjr@FreeBSD.org>

Make the 'y' (translate) command aware of multibyte characters.


# b4828720 12-Jul-2004 Tim J. Robbins <tjr@FreeBSD.org>

Overhaul lputs() to deal with multibyte characters, characters that take
up more than one column position, and null bytes.


# f54cda14 04-Nov-2003 Dag-Erling Smørgrav <des@FreeBSD.org>

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


# 9cde9a2e 03-Nov-2003 Dag-Erling Smørgrav <des@FreeBSD.org>

Whitespace cleanup


# e6478125 03-Nov-2003 Dag-Erling Smørgrav <des@FreeBSD.org>

ANSIfy


# ce20a8e9 02-Nov-2003 Tim J. Robbins <tjr@FreeBSD.org>

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


# c2b9b6eb 04-Jun-2003 Tony Finch <fanf@FreeBSD.org>

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


# 2f17b7e2 04-Jun-2003 Tony Finch <fanf@FreeBSD.org>

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


# b81df081 20-Sep-2002 Eric Melville <eric@FreeBSD.org>

Initialize a variable in order to fix when faced with picky compilers.

Sponsored by: Apple


# 13ee49d3 11-Aug-2002 Tim J. Robbins <tjr@FreeBSD.org>

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


# 8bd89d7e 19-Jul-2002 Mark Murray <markm@FreeBSD.org>

s/inline/__inline/


# dfb072f4 08-Jul-2002 Tim J. Robbins <tjr@FreeBSD.org>

Make cspace()'s second argument const. Make `escapes' in lputs() const.


# 8523e9a6 03-Jul-2002 Tim J. Robbins <tjr@FreeBSD.org>

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


# 5a323225 03-Jul-2002 Tim J. Robbins <tjr@FreeBSD.org>

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


# d1a1392d 24-Jun-2002 Tim J. Robbins <tjr@FreeBSD.org>

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>


# 5953156d 21-Jun-2002 Tim J. Robbins <tjr@FreeBSD.org>

Now that the pattern space contains no trailing newline, modify the `l'
command's output so it's the same as what SUSv3 specifies.


# ed92199d 21-Jun-2002 Tim J. Robbins <tjr@FreeBSD.org>

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


# e307a7a1 10-Jun-2002 Tim J. Robbins <tjr@FreeBSD.org>

Don't write escape newlines with `l' command (SUSv3)


# 03fef72f 10-Jun-2002 Tim J. Robbins <tjr@FreeBSD.org>

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.


# d1ccc822 04-Jun-2002 Tim J. Robbins <tjr@FreeBSD.org>

Wrap lines correctly for the `l' command.


# 3714ae12 04-Jun-2002 Tim J. Robbins <tjr@FreeBSD.org>

Ignore COLUMNS environment variable if it is empty (SUSv3)


# 46c2a2cf 15-May-2002 Tom Rhodes <trhodes@FreeBSD.org>

More consistancy. file system > filesystem


# ae178600 06-Apr-2002 Juli Mallett <jmallett@FreeBSD.org>

Fix sed(1) in the case where a last line is specified and hold space is not
specified, and then the first part of the pattern space is deleted, when
there are two or more input lines, as this results in subtraction of one from
an unsigned integral value of '0'. That bogus value is used in one case
for a loop (that will run far too many times in this case) and a function to
search for a value within a specified range of memory, however now the range
of memory is obscenely large and a segmentation fault will occur. This is
fixed by checking for and appropriately handling a nil pattern space as if
the specified search in memory failed, as indeed it obviously will with nil
pattern space.

Submitted by: Tim J. Robbins <tim@robbins.dropbear.id.au>
PR: bin/34813
Reviewed by: mike
MFC after: 1 day


# acf9afb7 04-Apr-2002 Juli Mallett <jmallett@FreeBSD.org>

Fix sed(1) behaviour for 'G' when given null holdspace by making sure it
contains a \n.

PR: misc/26153
Submitted by: ashp
Reviewed by: mike
Obtained from: NetBSD
MFC after: 2 days


# 3f330d7d 21-Mar-2002 Warner Losh <imp@FreeBSD.org>

remove __P


# e74bf75f 12-Dec-2001 Mark Murray <markm@FreeBSD.org>

WARNS=2 partial fix; use NO_WERROR to protect against some hard-to-fix warnings.

Use __FBSDID(), kill register keyword.


# 8e33c0a0 24-Jul-2001 David E. O'Brien <obrien@FreeBSD.org>

Expand xmalloc in-place, along with xrealloc; which wasn't even ANSI in its
implementation.


# c3aac50f 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 96846ff6 25-Apr-1999 Warner Losh <imp@FreeBSD.org>

More egcs warning fixes:
o main returns int not void
o use return 0 at end of main when needed
o use braces to avoid potentially ambiguous else
o don't default to type int
o #ifdef 0 -> #if 0

Reviewed by: obrien and chuckr


# 2806aab7 06-Dec-1998 Archie Cobbs <archie@FreeBSD.org>

Compile -Wall


# 3492193d 29-Apr-1998 Andrey A. Chernov <ache@FreeBSD.org>

Make 'y' command 8bit clean
PR: 6458


# 73a08bb2 11-Aug-1997 Philippe Charnier <charnier@FreeBSD.org>

Remove local redefinition for err(). Add usage().


# 726aebe5 11-Aug-1996 Andrey A. Chernov <ache@FreeBSD.org>

Localize it
8bit cleanup


# ce19262d 15-Aug-1995 Jordan K. Hubbard <jkh@FreeBSD.org>

Merge various fixes from NetBSD. This will allow the WordPerfect for
SCO installation to run all the way through (some POSIX fixes).


# 7799f52a 30-May-1995 Rodney W. Grimes <rgrimes@FreeBSD.org>

Remove trailing whitespace.


# 30ad8d93 05-Feb-1995 Jean-Marc Zucconi <jmz@FreeBSD.org>

Correct a bug in the P function: according to 7th edition UNIX (tm), the
newline must be part of the pattern space i.e. `echo a|sed -e P' must print
a
a
and not
aa
This is consistent with gnu sed, SunOS, Ultrix (and probably others!)


# 9b50d902 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite Usr.bin Sources