1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-22 16:42:56 -08:00
Commit Graph

53 Commits

Author SHA1 Message Date
millert
58b8553b11 sed: use warn()/err() where appropriate
Use warn()/err() instead of sed's homegrown warning()/error() for
things other than parser problems.  The warning()/error() functions
display the file and line number in addition to the error message.
This also removes of the COMPILE/FATAL argument to error() since
now all calls to error() are for compilation/parsing issues.
OK op@ espie@
2024-07-17 20:57:15 +00:00
millert
f73b4cc0fa Rename mf_fgets() and cu_fgets() to mf_getline() and cu_getline().
These functions now use getline(), not fgets().  From espie@
2024-06-18 00:32:22 +00:00
jmc
d9a51c353c spelling fixes; from paul tagliamonte
amendments to his diff are noted on tech
2022-12-26 19:16:00 +00:00
schwarze
53ac6a9873 As an extension to POSIX, for consistency with our behaviour for
the "b" and "t" commands with a label, and for compatibility with
GNU sed, also accept ";" followed by another command after "b"
and "t" commands without a label: branch to the end of the script
instead of erroring out.  Parsing is unchanged.

Missing feature reported by Lars dot Nooden at gmail dot com on bugs@.
OK martijn@ millert@
2018-12-07 14:45:40 +00:00
schwarze
2f0eb88516 Improve consistency of the substitution command further.
When the opening square bracket ('[') is abused as the delimiter, the regular
expression contains a bracket expression, and the bracket expression contains
another opening square bracket (sick! - i mean, sic!), then do not require
escaping that innermost bracket and treat a preceding backslash as a literal
backslash character, in accordance with POSIX:

   $ printf 'x[x\\x\n' | sed 's[\[[][R[g'
  xRx\x
   $ printf 'x[x\\x\n' | sed 's[\[\[][R[g'
  xRxRx

While here, also make the implementation more readable and insert
some comments.

Joint work with martijn@ (started during g2k18) and OK martijn@.
2018-08-14 18:10:09 +00:00
schwarze
a778be042b When using '[' as the delimiter in sed(1) s/// (don't do that, of course)
and then including '[' in the regular expression by prepending a backslash
to it, remove the backslash before feeding the RE to the RE engine, just
like we already do it for other special characters like .^$*+?{(|.
This makes sed 's[\[xy][...[' treat the xy thingy as a char class.
Joint work with martijn@, OK guenther@ martijn@
2018-07-09 09:43:54 +00:00
millert
89312d65ae Fix array index by signed char; from martijn@ 2017-12-13 16:07:54 +00:00
millert
59d77f5c78 Fix sign compare warnings; OK martijn@ 2017-12-13 16:06:34 +00:00
martijn
fb2122284b Fix 2 bugs introduced by previous.
Pointed out by kshe59 <at> zoho <dot> eu

OK millert@
2017-12-12 12:52:01 +00:00
martijn
0a3faa2e7b Fix and change y command in the following ways:
- When 'n' is used as a delimiter escaping 'n' will remain a newline
  instead of becoming a 'n' character. This is how POSIX specifies how this
  should work. Other implementations tested also do this wrong.
- '[' and maybe other characters are not special during the parsing of the
  y command and don't need to be matched or treated special in any way.
- POSIX specifies that a backslash followed by anything other than the
  delimiter, 'n', and another backslash, as well as repeating characters in
  string1 are unspecified. Since the various implementations handle these
  situations in opposing ways choose to error out on them to prevent people
  falling into the pitfall of expecting identical behaviour on various
  implementations.

Inspired by the sed.1 patch by kshe59 <at> zoho <dot> eu
Feedback and OK millert@
Manpage bits OK jmc@
2017-12-11 13:25:57 +00:00
martijn
d077d0ac78 Make the r command filename obligatory, similar to what FreeBSD and NetBSD
do for several years.
While here make corresponding error message for missing read and write file
consistent between commands/flag, and shrink the the code of the w flag of
the s command by making it use the same code as the w command.

Prompted by a larger diff by kshe59 <at> zoho <dot> eu
OK millert@
2017-12-08 18:41:59 +00:00
martijn
8ca80aa950 Apply stricter pledge rules if possible. These are based on the usage of
the 'w' and 'r' functions and the 'w' flag to the 's' function.

If non of the above is used and input is being read from stdin, we drop
all the way down to stdio!

Original inspiration by benno@.

OK millert@
2017-08-01 18:05:53 +00:00
krw
5c4e30b8f3 Split error() into error() and warning() so error() can be marked __dead to
appease gcc.

ok procter@ deraadt@
2017-01-20 10:26:16 +00:00
jca
1086528a6c Tidy up error() levels: merge COMPILE and COMPILE2, and kill ERROR (unused)
ok tobias@
2015-10-26 22:24:44 +00:00
mmcc
3ec97946df Rename err() to error() to prevent confusion with the stdlib function.
Discussed with jca@.
2015-10-26 14:08:47 +00:00
millert
3ad711f663 POSIX specifies that that multiple '!' characters preceding a
function should be treated as a single negation.  From FreeBSD
via Liviu Daia.
2015-06-23 22:52:55 +00:00
jsg
53ac88bd3c Bounds check the file path used in the 'w' command. Modified version
of a diff from Sebastien Marie to prevent a crash found by Sebastien
with the afl fuzzer.
2014-12-12 03:32:55 +00:00
deraadt
61867d6004 add a xreallocarray() like the existing fatal xmalloc(), and use it to
detect potential integer.
ok doug
2014-10-08 04:19:08 +00:00
deraadt
f69332c7b5 unsigned char for ctype
ok krw okan
2013-11-28 18:24:54 +00:00
millert
1d6c415822 NUL-terminate buffer in compiler_text() after realloc, not before.
Now that we have dynamically sized buffers there may not be room
for the NUL until after realloc.
2010-11-15 20:26:00 +00:00
naddy
555ffc6645 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"

From FreeBSD; ok millert@ halex@
2010-07-01 17:04:24 +00:00
naddy
fc40af3fbe Allow [ to be used as a delimiter.
From FreeBSD; ok millert@ halex@
2010-07-01 17:02:02 +00:00
deraadt
043fbe51c1 rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable).  these days, people use source.  these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms
2009-10-27 23:59:19 +00:00
reyk
0ff19dceef When adding text due to an a, c, or i command, don't eat the space(s) at
the beginning of the lines since the addition is supposed to be "verbatim".

From NetBSD, also matches the bahaviour of GNU sed

ok millert@
2009-10-23 15:24:41 +00:00
djm
dfaac9d7e1 add -E flag to compile regular expressions using the extended POSIX
syntax. The -E flag is compatible with the other BSDs and OSX. -r is
also provided as an alias for compatibility with GNU sed.

feedback from jmc@ and millert@
ok millert@ pyr@ henning@ marco@
2009-08-07 03:30:56 +00:00
millert
acd8f0ab2b Move memory allocation closer to where it is needed. Also make
a distinction between len and size.  OK deraadt@
2008-10-16 16:34:32 +00:00
millert
a08d189c87 Now that len is set later in compile_subst() we need to move the
xmalloc call that goes with it.
2008-10-09 21:14:58 +00:00
millert
c510cb78f7 In compile_subst(), adjust for the fact that the initial buffer
that is passed in may now be larger than _POSIX2_LINE_MAX.
Thanks to pedro@ for the test case.  OK pedro@
2008-10-09 16:40:56 +00:00
millert
fd361c219e Allow sed to handle arbitrarily long lines. Also plug a memory
leak noticed in the process.  Closes PR 5303.  OK otto@ deraadt@
2008-10-08 17:26:47 +00:00
tedu
b65df67967 remove some bogus *p tests from charles longeau
ok deraadt millert
2007-03-20 03:50:38 +00:00
otto
185c69583b Accept empty command, from Matthew R. Dempsky; ok deraadt@ millert@ 2007-01-09 08:37:44 +00:00
tedu
e94735573f pretty. the comma operator should not be used to cram two statements into
an if without braces, or worse, into a return.
2006-10-09 00:23:56 +00:00
deraadt
8aa8e8b89d spacing 2005-04-11 07:11:44 +00:00
otto
9318432458 xmalloc()->xrealloc() so that patterns larger than _POSIX2_LINE_MAX*2-1
work.  From mycroft@netbsd.

ok millert@
2004-07-10 11:41:26 +00:00
otto
fb27686ddd From the other BSDs: fix a bug that made sed(1) fail if the last
character of the line buffer was a backslash.

ok deraadt@
2004-07-09 19:39:40 +00:00
deraadt
34fab0c534 1-byte overflow; ryo@nerv.org, otto ok 2004-06-13 17:11:17 +00:00
otto
7dd6850ea4 Unbreak numeric flag parsing. Based on a fix from Jared Yanovich; this
version with millert@. Resolves PR 3677.

ok millert@
2004-02-17 16:13:33 +00:00
deraadt
d2088dc9aa handle ; terminators for strings like other sed programs do. this is
apparently an extension, but without it you cannot express longer labelled
sed scripts as one-liners.  noted by seb@todesplanet.de apr 2002.  also
noted by cerille lefevre a bit later.  fixed by otto and myself, tested
on tree builds to be careful
2003-10-07 17:56:26 +00:00
deraadt
1837a5ca50 mostly ansi cleanup; pval ok 2003-06-10 22:20:44 +00:00
millert
f75387cb26 Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999.  Proofed by myself and Theo.
2003-06-03 02:56:05 +00:00
deraadt
52f0e374c0 make sed r command not bail out. try sed -e "/a/r"
vtamara@wimsey.informatik.uni-kl.de, pr 2755
2002-07-09 21:31:03 +00:00
jsyn
c20d9ad407 kill err(3) newlines; ok miod@, deraadt@ 2002-06-11 06:16:36 +00:00
millert
c72b5b24e1 Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically. 2002-02-16 21:27:05 +00:00
mpech
c0932ef1ff kill more registers
millert@ ok
2001-11-19 19:02:13 +00:00
millert
58ca0557b2 correct sccsid, not like it really matters 1998-09-24 03:00:59 +00:00
brian
4f32412617 Terminate our output string correctly if we've got
an ``a'' command that has an escaped newline on the
last line of the last script that we're processing.
1998-09-22 21:21:43 +00:00
deraadt
30db690aef fix a comment 1998-02-15 10:38:35 +00:00
millert
84e1e8069f Back out last change. ed and sed should not use extended regular expressions. 1998-01-21 03:51:49 +00:00
millert
59a0aab617 Support extended (modern) instead of basic (obsolescent)
regular expressions.  hubert.feyrer@rz.uni-regensburg.de
1998-01-18 22:01:53 +00:00
deraadt
f448a15b8a fix for a line continuation bug, more than a year ald. work by mckusick,
bostic, mark@linus.demon.co.uk, davidg, and bde.
1997-11-14 03:59:25 +00:00