summaryrefslogtreecommitdiffstats
path: root/usr.bin/sed/compile.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* As an extension to POSIX, for consistency with our behaviour forschwarze2018-12-071-2/+2
| | | | | | | | | | 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@
* Improve consistency of the substitution command further.schwarze2018-08-141-20/+32
| | | | | | | | | | | | | | | | | | 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@.
* When using '[' as the delimiter in sed(1) s/// (don't do that, of course)schwarze2018-07-091-3/+3
| | | | | | | | 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@
* Fix array index by signed char; from martijn@millert2017-12-131-4/+3
|
* Fix sign compare warnings; OK martijn@millert2017-12-131-4/+4
|
* Fix 2 bugs introduced by previous.martijn2017-12-121-3/+3
| | | | | | Pointed out by kshe59 <at> zoho <dot> eu OK millert@
* Fix and change y command in the following ways:martijn2017-12-111-44/+58
| | | | | | | | | | | | | | | | | | - 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@
* Make the r command filename obligatory, similar to what FreeBSD and NetBSDmartijn2017-12-081-23/+9
| | | | | | | | | | 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@
* Apply stricter pledge rules if possible. These are based on the usage ofmartijn2017-08-011-3/+8
| | | | | | | | | | | 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@
* Split error() into error() and warning() so error() can be marked __dead tokrw2017-01-201-6/+4
| | | | | | appease gcc. ok procter@ deraadt@
* Tidy up error() levels: merge COMPILE and COMPILE2, and kill ERROR (unused)jca2015-10-261-3/+3
| | | | ok tobias@
* Rename err() to error() to prevent confusion with the stdlib function.mmcc2015-10-261-40/+40
| | | | Discussed with jca@.
* POSIX specifies that that multiple '!' characters preceding amillert2015-06-231-2/+2
| | | | | function should be treated as a single negation. From FreeBSD via Liviu Daia.
* Bounds check the file path used in the 'w' command. Modified versionjsg2014-12-121-2/+5
| | | | | of a diff from Sebastien Marie to prevent a crash found by Sebastien with the afl fuzzer.
* add a xreallocarray() like the existing fatal xmalloc(), and use it toderaadt2014-10-081-3/+3
| | | | | detect potential integer. ok doug
* unsigned char for ctypederaadt2013-11-281-4/+5
| | | | ok krw okan
* NUL-terminate buffer in compiler_text() after realloc, not before.millert2010-11-151-2/+3
| | | | | Now that we have dynamically sized buffers there may not be room for the NUL until after realloc.
* Follow POSIX (IEEE Std 1003.1, 2004 Edition) in the implementationnaddy2010-07-011-7/+10
| | | | | | | | | | 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@
* Allow [ to be used as a delimiter.naddy2010-07-011-2/+2
| | | | From FreeBSD; ok millert@ halex@
* rcsid[] and sccsid[] and copyright[] are essentially unmaintained (andderaadt2009-10-271-6/+1
| | | | | | | 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
* When adding text due to an a, c, or i command, don't eat the space(s) atreyk2009-10-231-3/+2
| | | | | | | | the beginning of the lines since the addition is supposed to be "verbatim". From NetBSD, also matches the bahaviour of GNU sed ok millert@
* add -E flag to compile regular expressions using the extended POSIXdjm2009-08-071-3/+3
| | | | | | | | 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@
* Move memory allocation closer to where it is needed. Also makemillert2008-10-161-31/+21
| | | | a distinction between len and size. OK deraadt@
* Now that len is set later in compile_subst() we need to move themillert2008-10-091-5/+5
| | | | xmalloc call that goes with it.
* In compile_subst(), adjust for the fact that the initial buffermillert2008-10-091-3/+6
| | | | | that is passed in may now be larger than _POSIX2_LINE_MAX. Thanks to pedro@ for the test case. OK pedro@
* Allow sed to handle arbitrarily long lines. Also plug a memorymillert2008-10-081-26/+49
| | | | leak noticed in the process. Closes PR 5303. OK otto@ deraadt@
* remove some bogus *p tests from charles longeautedu2007-03-201-3/+3
| | | | ok deraadt millert
* Accept empty command, from Matthew R. Dempsky; ok deraadt@ millert@otto2007-01-091-3/+7
|
* pretty. the comma operator should not be used to cram two statements intotedu2006-10-091-24/+34
| | | | an if without braces, or worse, into a return.
* spacingderaadt2005-04-111-5/+5
|
* xmalloc()->xrealloc() so that patterns larger than _POSIX2_LINE_MAX*2-1otto2004-07-101-3/+3
| | | | | | work. From mycroft@netbsd. ok millert@
* From the other BSDs: fix a bug that made sed(1) fail if the lastotto2004-07-091-5/+26
| | | | | | character of the line buffer was a backslash. ok deraadt@
* 1-byte overflow; ryo@nerv.org, otto okderaadt2004-06-131-3/+3
|
* Unbreak numeric flag parsing. Based on a fix from Jared Yanovich; thisotto2004-02-171-5/+9
| | | | | | version with millert@. Resolves PR 3677. ok millert@
* handle ; terminators for strings like other sed programs do. this isderaadt2003-10-071-13/+30
| | | | | | | 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
* mostly ansi cleanup; pval okderaadt2003-06-101-36/+17
|
* Remove the advertising clause in the UCB license which Berkeleymillert2003-06-031-7/+3
| | | | rescinded 22 July 1999. Proofed by myself and Theo.
* make sed r command not bail out. try sed -e "/a/r"deraadt2002-07-091-6/+3
| | | | vtamara@wimsey.informatik.uni-kl.de, pr 2755
* kill err(3) newlines; ok miod@, deraadt@jsyn2002-06-111-4/+4
|
* 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.millert2002-02-161-16/+16
|
* kill more registersmpech2001-11-191-12/+12
| | | | millert@ ok
* correct sccsid, not like it really mattersmillert1998-09-241-3/+3
|
* Terminate our output string correctly if we've gotbrian1998-09-221-2/+3
| | | | | an ``a'' command that has an escaped newline on the last line of the last script that we're processing.
* fix a commentderaadt1998-02-151-3/+3
|
* Back out last change. ed and sed should not use extended regular expressions.millert1998-01-211-3/+3
|
* Support extended (modern) instead of basic (obsolescent)millert1998-01-181-3/+3
| | | | regular expressions. hubert.feyrer@rz.uni-regensburg.de
* fix for a line continuation bug, more than a year ald. work by mckusick,deraadt1997-11-141-7/+7
| | | | bostic, mark@linus.demon.co.uk, davidg, and bde.
* Use strtoul() not strtol() when assigning to an unsigned long.millert1997-04-281-3/+3
|
* rcsidderaadt1996-06-261-1/+3
|
* initial import of NetBSD treederaadt1995-10-181-0/+811