From owner-svn-src-stable-11@freebsd.org Sat Jun 27 14:31:36 2020 Return-Path: Delivered-To: svn-src-stable-11@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6685C352490; Sat, 27 Jun 2020 14:31:36 +0000 (UTC) (envelope-from 0mp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49vGQv0PT8z3ypL; Sat, 27 Jun 2020 14:31:35 +0000 (UTC) (envelope-from 0mp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E1A7F26994; Sat, 27 Jun 2020 14:31:34 +0000 (UTC) (envelope-from 0mp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 05REVYvH076783; Sat, 27 Jun 2020 14:31:34 GMT (envelope-from 0mp@FreeBSD.org) Received: (from 0mp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 05REVYF8076781; Sat, 27 Jun 2020 14:31:34 GMT (envelope-from 0mp@FreeBSD.org) Message-Id: <202006271431.05REVYF8076781@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: 0mp set sender to 0mp@FreeBSD.org using -f From: Mateusz Piotrowski <0mp@FreeBSD.org> Date: Sat, 27 Jun 2020 14:31:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r362688 - in stable/11/usr.bin/sed: . tests X-SVN-Group: stable-11 X-SVN-Commit-Author: 0mp X-SVN-Commit-Paths: in stable/11/usr.bin/sed: . tests X-SVN-Commit-Revision: 362688 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Jun 2020 14:31:37 -0000 Author: 0mp (doc,ports committer) Date: Sat Jun 27 14:31:33 2020 New Revision: 362688 URL: https://svnweb.freebsd.org/changeset/base/362688 Log: MFC 362017, 362039, 362071: Read commands from stdin when -f - is passed to sed(1) This patch teaches sed to interpret a "-" in a special way when given as an argument to the -f flag. This behavior is also present in GNU sed. PR: 244872 Tested by: antoine (exp-run) Reviewed by: pfg, tobik (older version) Approved by: pfg (src) Relnotes: yes Differential Revision: https://reviews.freebsd.org/D24079 Remove duplicate lines from sed tests Reported by: yuripv Approved by: pfg (src) Remove some more duplicate test cases I accidentally committed Reported by: markj, yuripv Modified: stable/11/usr.bin/sed/main.c stable/11/usr.bin/sed/sed.1 stable/11/usr.bin/sed/tests/sed2_test.sh Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.bin/sed/main.c ============================================================================== --- stable/11/usr.bin/sed/main.c Sat Jun 27 14:27:37 2020 (r362687) +++ stable/11/usr.bin/sed/main.c Sat Jun 27 14:31:33 2020 (r362688) @@ -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: Modified: stable/11/usr.bin/sed/sed.1 ============================================================================== --- stable/11/usr.bin/sed/sed.1 Sat Jun 27 14:27:37 2020 (r362687) +++ stable/11/usr.bin/sed/sed.1 Sat Jun 27 14:31:33 2020 (r362688) @@ -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 Modified: stable/11/usr.bin/sed/tests/sed2_test.sh ============================================================================== --- stable/11/usr.bin/sed/tests/sed2_test.sh Sat Jun 27 14:27:37 2020 (r362687) +++ stable/11/usr.bin/sed/tests/sed2_test.sh Sat Jun 27 14:31:33 2020 (r362688) @@ -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 }