summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorMateusz Piotrowski <0mp@FreeBSD.org>2020-06-27 14:31:33 +0000
committerMateusz Piotrowski <0mp@FreeBSD.org>2020-06-27 14:31:33 +0000
commitfefce89d549691ed9deaf0ca7bad62520934a91a (patch)
tree95c072165def135c0313a78a2a88eae13f9fb299 /usr.bin
parent475df0462673eed0f69fdd60b8c2cacac62871c8 (diff)
downloadsrc-test2-fefce89d549691ed9deaf0ca7bad62520934a91a.tar.gz
src-test2-fefce89d549691ed9deaf0ca7bad62520934a91a.zip
Notes
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/sed/main.c18
-rw-r--r--usr.bin/sed/sed.110
-rwxr-xr-xusr.bin/sed/tests/sed2_test.sh21
3 files changed, 43 insertions, 6 deletions
diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c
index 7d700f6d3e92..26c2d22cdc0c 100644
--- a/usr.bin/sed/main.c
+++ b/usr.bin/sed/main.c
@@ -125,12 +125,13 @@ static void usage(void);
int
main(int argc, char *argv[])
{
- int c, fflag;
+ int c, fflag, fflagstdin;
char *temp_arg;
(void) setlocale(LC_ALL, "");
fflag = 0;
+ fflagstdin = 0;
inplace = NULL;
while ((c = getopt(argc, argv, "EI:ae:f:i:lnru")) != -1)
@@ -156,6 +157,8 @@ main(int argc, char *argv[])
break;
case 'f':
fflag = 1;
+ if (strcmp(optarg, "-") == 0)
+ fflagstdin = 1;
add_compunit(CU_FILE, optarg);
break;
case 'i':
@@ -192,6 +195,8 @@ main(int argc, char *argv[])
if (*argv)
for (; *argv; argv++)
add_file(*argv);
+ else if (fflagstdin)
+ exit(rval);
else
add_file(NULL);
process();
@@ -235,9 +240,14 @@ again:
linenum = 0;
switch (script->type) {
case CU_FILE:
- if ((f = fopen(script->s, "r")) == NULL)
- err(1, "%s", script->s);
- fname = script->s;
+ if (strcmp(script->s, "-") == 0) {
+ f = stdin;
+ fname = "stdin";
+ } else {
+ if ((f = fopen(script->s, "r")) == NULL)
+ err(1, "%s", script->s);
+ fname = script->s;
+ }
state = ST_FILE;
goto again;
case CU_STRING:
diff --git a/usr.bin/sed/sed.1 b/usr.bin/sed/sed.1
index 9c4489a651c8..f7fed1f36d9c 100644
--- a/usr.bin/sed/sed.1
+++ b/usr.bin/sed/sed.1
@@ -31,7 +31,7 @@
.\" @(#)sed.1 8.2 (Berkeley) 12/30/93
.\" $FreeBSD$
.\"
-.Dd March 27, 2017
+.Dd June 10, 2020
.Dt SED 1
.Os
.Sh NAME
@@ -96,6 +96,10 @@ Append the editing commands found in the file
.Ar command_file
to the list of commands.
The editing commands should each be listed on a separate line.
+The commands are read from the standard input if
+.Ar command_file
+is
+.Dq Li - .
.It Fl I Ar extension
Edit files in-place, saving backups with the specified
.Ar extension .
@@ -633,7 +637,9 @@ The
.Fl E , I , a
and
.Fl i
-options, the prefixing
+options, the special meaning of
+.Fl f Cm - ,
+the prefixing
.Dq \&+
in the second member of an address range,
as well as the
diff --git a/usr.bin/sed/tests/sed2_test.sh b/usr.bin/sed/tests/sed2_test.sh
index 9acd628a8f1e..1b2a4ffcae6a 100755
--- a/usr.bin/sed/tests/sed2_test.sh
+++ b/usr.bin/sed/tests/sed2_test.sh
@@ -69,9 +69,30 @@ inplace_command_q_body()
atf_check -s not-exit:0 stat -q '.!'*
}
+atf_test_case commands_on_stdin
+commands_on_stdin_head()
+{
+ atf_set "descr" "Verify -f -"
+}
+commands_on_stdin_body()
+{
+ printf "a\n" > a
+ printf "s/a/b/\n" > a_to_b
+ printf "s/b/c/\n" > b_to_c
+ printf "s/c/d/\n" > ./-
+ atf_check -o 'inline:d\n' sed -f a_to_b -f - -f ./- a < b_to_c
+
+ # Verify that nothing is printed if there are no input files provided.
+ printf 'i\\\nx' > insert_x
+ atf_check -o 'empty' sed -f - < insert_x
+}
+
atf_init_test_cases()
{
atf_add_test_case inplace_command_q
atf_add_test_case inplace_hardlink_src
atf_add_test_case inplace_symlink_src
+ atf_add_test_case escape_subst
+ atf_add_test_case commands_on_stdin
+ atf_add_test_case hex_subst
}