Commit Graph

90 Commits

Author SHA1 Message Date
schweikh
c353aec149 Correct typos, mostly s/ a / an / where appropriate. Some whitespace cleanup,
especially in troff files.
2003-01-01 18:49:04 +00:00
ru
07cd1d9dbe mdoc(7) police: markup polishing.
Approved by:	re
2002-11-26 17:33:37 +00:00
eric
346283a0eb Initialize a variable in order to fix when faced with picky compilers.
Sponsored by:	Apple
2002-09-20 19:40:23 +00:00
tjr
6adab203fa 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
fanf
c12174d890 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
tjr
ba1a9e1f8e Ignore leading semicolons on commands; required by SUSv3.
Obtained from:	NetBSD (kleink, Aymeric Vincent)
2002-07-30 14:07:30 +00:00
markm
619f7aad5d s/inline/__inline/ 2002-07-19 14:12:27 +00:00
tjr
a1fabbea6d Make cspace()'s second argument const. Make `escapes' in lputs() const. 2002-07-08 06:00:55 +00:00
tjr
54275ff2a0 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
tjr
b6cf230874 Update another mention of <CR><CR> I missed the first time around (rev 1.2) 2002-07-04 05:16:19 +00:00
tjr
ef4e93b7dc 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
tjr
315438ce0a 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
tjr
6f56a8cbf2 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
tjr
2f325d81c8 Sort sections, and refer to sed as a utility, not a function. 2002-06-25 08:36:19 +00:00
tjr
92bc41240a 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
tjr
3e274b5fa3 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
tjr
80b8872b68 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
sobomax
6f11fab231 Kill superfluous blank line. 2002-06-17 08:21:53 +00:00
tjr
27fdba1c02 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
tjr
99bf0b1851 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
sobomax
c465526eb9 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
tjr
26db9dd471 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
tjr
8022fb8d6a 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
tjr
0d7946a551 Newlines are not escaped anymore. 2002-06-10 07:27:32 +00:00
tjr
c2aff30319 Don't write escape newlines with `l' command (SUSv3) 2002-06-10 07:25:35 +00:00
tjr
f153f4e3b8 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
tjr
07e556f9f5 Wrap lines correctly for the `l' command. 2002-06-04 10:40:14 +00:00
tjr
93373f411d Document the fact that the `l' command uses the COLUMNS environment
variable (SUSv3)
2002-06-04 10:01:06 +00:00
tjr
7bd1f78fe0 Ignore COLUMNS environment variable if it is empty (SUSv3) 2002-06-04 10:00:08 +00:00
green
1bad573c26 Fix a bug in sed(1)'s "s" command wherein if an escape ("\" character)
was initiated at the last character of the line buffer, the Wrong
Thing was done and sed barfed by interpreting the following NUL byte
as a digit.  Instead, pull up the next buffer and record that the "\"
was last seen.
2002-06-01 13:25:47 +00:00
ru
37f7b8ac8d mdoc(7) police: typo in .Dd. 2002-05-30 06:05:42 +00:00
tjr
e3fa9a7d54 If a file argument cannot be processed, process the remaining ones
and exit non-zero (SUSv3)
2002-05-24 10:58:21 +00:00
trhodes
ec2a348c1f More consistancy. file system > filesystem 2002-05-16 02:19:14 +00:00
green
85348d7f2d 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
jmallett
d212299e3e Oops, update usage() to have -i. 2002-05-07 23:33:44 +00:00
jmallett
b74e4bbb9f 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
jmallett
d8aba2da57 Un-shadow the `fname' variable. 2002-05-07 23:06:47 +00:00
jmallett
d3a49a4ed5 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
keramida
be2cdb1ae1 Remove duplicated text.
PR:		docs/37287
Submitted by:	Tony Finch <dot@dotat.at>
MFC after:	3 days
2002-04-21 14:48:47 +00:00
sobomax
084230c015 Fix an ages-old bug in sed(1), which resulted in the absolutely valid
substitution expressions in the form `s,[fooexp],[barexp],;...' treated
as invalid when the third `,' is (_POSIX2_LINE_MAX * N)-th character in
the line.

MFC after:	2 weeks
2002-04-12 19:46:05 +00:00
jmallett
d203b6396c 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
2002-04-07 02:29:56 +00:00
jmallett
499c22e7da 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
2002-04-05 05:40:20 +00:00
imp
6b8e9d623c remove __P 2002-03-22 01:42:45 +00:00
markm
fcaa25d991 Remove NO_WERRORs and WARNS=n's. To be revisited after GCC3. 2002-02-08 23:07:37 +00:00
markm
85dc936b28 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
mikeh
752abf2535 Don't allocate a zero byte segment.
PR:		bin/11900
MFC after:	2 weeks
2001-11-08 16:47:05 +00:00
ru
e6bcd7b5b8 mdoc(7) police: utilize the new .Ex macro. 2001-08-15 09:09:47 +00:00
ru
09d142dfd5 mdoc(7) police:
Avoid using parenthesis enclosure macros (.Pq and .Po/.Pc) with plain text.
Not only this slows down the mdoc(7) processing significantly, but it also
has an undesired (in this case) effect of disabling hyphenation within the
entire enclosed block.
2001-08-07 15:48:51 +00:00
obrien
bd27550ed7 Expand xmalloc in-place, along with xrealloc; which wasn't even ANSI in its
implementation.
2001-07-24 14:05:21 +00:00
ru
e4e77900bb Don't leak memory when compiling text following the a', c' or `i' command.
Testcase:

echo FOO | sed "/FOO/c\\
`jot -b 'aaaa\' 500`"

Submitted by:	Max Khon <fjoe@newst.net>
2001-05-18 09:48:17 +00:00