Re: svn commit: r362017 - in head/usr.bin/sed: . tests
Hey. Ian Lepore wrote in : |On Thu, 2020-06-11 at 16:29 +0200, Steffen Nurpmeso wrote: |> Hello. |> |> Mateusz Piotrowski wrote in |> <995726df-cb28-c294-09ca-6cca302b2...@freebsd.org>: |>|On 6/11/20 12:06 AM, Steffen Nurpmeso wrote: |>|> Yuri Pankov wrote in |>|> : |>|>|Mateusz Piotrowski wrote: |>|>|> Author: 0mp (doc,ports committer) |>|>|> Date: Wed Jun 10 19:23:58 2020 |>|>|> New Revision: 362017 |>|>|> URL: https://svnweb.freebsd.org/changeset/base/362017 |>|>|> |>|>|> Log: |>|>|>Read commands from stdin when -f - is passed to sed(1) |>|> .. |>|>|Am I reading it wrong, or is it the same test case added 3 times? |>|> |>|> It also used "Fl f Cm -" instead of "Fl f Ar -". Just saying.. |> |>|Which is correct. "-" is not a variable here. It is a fixed string hence |>|the use of Cm. |> |> I would rather say no, .Ar is an argument (to the ".Fl"ag f), |> whereas .Cm is a command modifier: |> |>Command Modifiers |> The command modifier is identical to the '.Fl' (flag) command \ |> with the |> exception that the '.Cm' macro does not assert a dash in front \ |> of every |> argument. Traditionally flags are marked by the preceding dash, \ |> however, |> some commands or subsets of commands do not use them. Command \ |> modifiers |> may also be specified in conjunction with interactive commands \ |> such as |> editor commands. |> | |Yeah, but... | | The '.Fl' macro without any arguments results in a dash representing | stdin/stdout. Note that giving '.Fl' a single dash will result in | two dashes. The '.Fl' macro is parsed and is callable. | |And that seems to argue that "Fl f Fl" is correct. This will not result in a well-formed XML document. I seem to have lost track now. He wanted to document the typical "is standard input" argument to the command line option (flag) -f, didn't he? If so then "Fl f Ar -" should be the correct way of documenting this. Of course - "modifies the command" ("is a command modifier"), heh. You could also say "Fl f Pa -" if you go that route, because the argument should be a path, yet it is not in this very special case, which denotes standard input. But i would use "Fl f Ar -". --steffen | |Der Kragenbaer,The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt) ___ svn-src-all@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"
Re: svn commit: r362017 - in head/usr.bin/sed: . tests
On Thu, 2020-06-11 at 16:29 +0200, Steffen Nurpmeso wrote: > Hello. > > Mateusz Piotrowski wrote in > <995726df-cb28-c294-09ca-6cca302b2...@freebsd.org>: > |On 6/11/20 12:06 AM, Steffen Nurpmeso wrote: > |> Yuri Pankov wrote in > |> : > |>|Mateusz Piotrowski wrote: > |>|> Author: 0mp (doc,ports committer) > |>|> Date: Wed Jun 10 19:23:58 2020 > |>|> New Revision: 362017 > |>|> URL: https://svnweb.freebsd.org/changeset/base/362017 > |>|> > |>|> Log: > |>|>Read commands from stdin when -f - is passed to sed(1) > |> .. > |>|Am I reading it wrong, or is it the same test case added 3 times? > |> > |> It also used "Fl f Cm -" instead of "Fl f Ar -". Just saying.. > > |Which is correct. "-" is not a variable here. It is a fixed string hence > |the use of Cm. > > I would rather say no, .Ar is an argument (to the ".Fl"ag f), > whereas .Cm is a command modifier: > >Command Modifiers > The command modifier is identical to the '.Fl' (flag) command with the > exception that the '.Cm' macro does not assert a dash in front of every > argument. Traditionally flags are marked by the preceding dash, however, > some commands or subsets of commands do not use them. Command modifiers > may also be specified in conjunction with interactive commands such as > editor commands. > Yeah, but... The '.Fl' macro without any arguments results in a dash representing stdin/stdout. Note that giving '.Fl' a single dash will result in two dashes. The '.Fl' macro is parsed and is callable. And that seems to argue that "Fl f Fl" is correct. -- Ian ___ svn-src-all@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"
Re: svn commit: r362017 - in head/usr.bin/sed: . tests
Hello. Mateusz Piotrowski wrote in <995726df-cb28-c294-09ca-6cca302b2...@freebsd.org>: |On 6/11/20 12:06 AM, Steffen Nurpmeso wrote: |> Yuri Pankov wrote in |> : |>|Mateusz Piotrowski wrote: |>|> Author: 0mp (doc,ports committer) |>|> Date: Wed Jun 10 19:23:58 2020 |>|> New Revision: 362017 |>|> URL: https://svnweb.freebsd.org/changeset/base/362017 |>|> |>|> Log: |>|>Read commands from stdin when -f - is passed to sed(1) |> .. |>|Am I reading it wrong, or is it the same test case added 3 times? |> |> It also used "Fl f Cm -" instead of "Fl f Ar -". Just saying.. |Which is correct. "-" is not a variable here. It is a fixed string hence |the use of Cm. I would rather say no, .Ar is an argument (to the ".Fl"ag f), whereas .Cm is a command modifier: Command Modifiers The command modifier is identical to the '.Fl' (flag) command with the exception that the '.Cm' macro does not assert a dash in front of every argument. Traditionally flags are marked by the preceding dash, however, some commands or subsets of commands do not use them. Command modifiers may also be specified in conjunction with interactive commands such as editor commands. --steffen | |Der Kragenbaer,The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt) ___ svn-src-all@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"
Re: svn commit: r362017 - in head/usr.bin/sed: . tests
On 6/10/20 11:44 PM, Yuri Pankov wrote: > Mateusz Piotrowski wrote: >> Author: 0mp (doc,ports committer) >> Date: Wed Jun 10 19:23:58 2020 >> New Revision: 362017 >> URL: https://svnweb.freebsd.org/changeset/base/362017 >> >> Log: >> Read commands from stdin when -f - is passed to sed(1) [...] >> Modified: head/usr.bin/sed/tests/sed2_test.sh [...] >> 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 commands_on_stdin >> + atf_add_test_case commands_on_stdin >> atf_add_test_case hex_subst >> } >> > > Am I reading it wrong, or is it the same test case added 3 times? Sigh, yes, it does not make any sense. Thanks for spotting. Removing those 2 extra lines should do, right? Can I commit it? ___ svn-src-all@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"
Re: svn commit: r362017 - in head/usr.bin/sed: . tests
Hi, On 6/11/20 12:06 AM, Steffen Nurpmeso wrote: > Yuri Pankov wrote in > : > |Mateusz Piotrowski wrote: > |> Author: 0mp (doc,ports committer) > |> Date: Wed Jun 10 19:23:58 2020 > |> New Revision: 362017 > |> URL: https://svnweb.freebsd.org/changeset/base/362017 > |> > |> Log: > |>Read commands from stdin when -f - is passed to sed(1) > .. > |Am I reading it wrong, or is it the same test case added 3 times? > > It also used "Fl f Cm -" instead of "Fl f Ar -". Just saying.. Which is correct. "-" is not a variable here. It is a fixed string hence the use of Cm. ___ svn-src-all@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"
Re: svn commit: r362017 - in head/usr.bin/sed: . tests
Yuri Pankov wrote in : |Mateusz Piotrowski wrote: |> Author: 0mp (doc,ports committer) |> Date: Wed Jun 10 19:23:58 2020 |> New Revision: 362017 |> URL: https://svnweb.freebsd.org/changeset/base/362017 |> |> Log: |>Read commands from stdin when -f - is passed to sed(1) .. |Am I reading it wrong, or is it the same test case added 3 times? It also used "Fl f Cm -" instead of "Fl f Ar -". Just saying.. --steffen | |Der Kragenbaer,The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt) ___ svn-src-all@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"
Re: svn commit: r362017 - in head/usr.bin/sed: . tests
Mateusz Piotrowski wrote: Author: 0mp (doc,ports committer) Date: Wed Jun 10 19:23:58 2020 New Revision: 362017 URL: https://svnweb.freebsd.org/changeset/base/362017 Log: 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 MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D24079 Modified: head/usr.bin/sed/main.c head/usr.bin/sed/sed.1 head/usr.bin/sed/tests/sed2_test.sh [...] Modified: head/usr.bin/sed/tests/sed2_test.sh == --- head/usr.bin/sed/tests/sed2_test.sh Wed Jun 10 18:59:46 2020 (r362016) +++ head/usr.bin/sed/tests/sed2_test.sh Wed Jun 10 19:23:58 2020 (r362017) @@ -116,11 +116,68 @@ hex_subst_body() atf_check -o "inline:" sed 's/\xx//' d } +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_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_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 commands_on_stdin + atf_add_test_case commands_on_stdin atf_add_test_case hex_subst } Am I reading it wrong, or is it the same test case added 3 times? ___ svn-src-all@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"
svn commit: r362017 - in head/usr.bin/sed: . tests
Author: 0mp (doc,ports committer) Date: Wed Jun 10 19:23:58 2020 New Revision: 362017 URL: https://svnweb.freebsd.org/changeset/base/362017 Log: 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 MFC after:2 weeks Differential Revision:https://reviews.freebsd.org/D24079 Modified: head/usr.bin/sed/main.c head/usr.bin/sed/sed.1 head/usr.bin/sed/tests/sed2_test.sh Modified: head/usr.bin/sed/main.c == --- head/usr.bin/sed/main.c Wed Jun 10 18:59:46 2020(r362016) +++ head/usr.bin/sed/main.c Wed Jun 10 19:23:58 2020(r362017) @@ -126,12 +126,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) @@ -157,6 +158,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': @@ -193,6 +196,8 @@ main(int argc, char *argv[]) if (*argv) for (; *argv; argv++) add_file(*argv); + else if (fflagstdin) + exit(rval); else add_file(NULL); process(); @@ -236,9 +241,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: head/usr.bin/sed/sed.1 == --- head/usr.bin/sed/sed.1 Wed Jun 10 18:59:46 2020(r362016) +++ head/usr.bin/sed/sed.1 Wed Jun 10 19:23:58 2020(r362017) @@ -31,7 +31,7 @@ .\"@(#)sed.1 8.2 (Berkeley) 12/30/93 .\" $FreeBSD$ .\" -.Dd May 19, 2020 +.Dd June 10, 2020 .Dt SED 1 .Os .Sh NAME @@ -98,6 +98,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 . @@ -636,7 +640,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: head/usr.bin/sed/tests/sed2_test.sh == --- head/usr.bin/sed/tests/sed2_test.sh Wed Jun 10 18:59:46 2020 (r362016) +++ head/usr.bin/sed/tests/sed2_test.sh Wed Jun 10 19:23:58 2020 (r362017) @@ -116,11 +116,68 @@ hex_subst_body() atf_check -o "inline:" sed 's/\xx//' d } +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_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. +