From: Paul Eggert Date: Thu, 14 Aug 2025 16:17:51 +0000 (-0700) Subject: tsort: add do-nothing -w option X-Git-Tag: v9.8~108 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=39eec70f7ba360577020099b5f179940700bc67f;p=thirdparty%2Fcoreutils.git tsort: add do-nothing -w option This is for conformance to POSIX.1-2024 * src/tsort.c: Include getopt.h. (main): Accept and ignore -w. Do not bother altering the usage message, as the option is useless. * tests/misc/tsort.pl (cycle-3): New test. --- diff --git a/NEWS b/NEWS index bfde1e62d4..cc4a913039 100644 --- a/NEWS +++ b/NEWS @@ -84,6 +84,8 @@ GNU coreutils NEWS -*- outline -*- the same as realpath with no options. The corresponding long option is --canonicalize. + tsort now accepts and ignores -w, to conform to POSIX.1-2024. + ** Improvements 'factor' is now much faster at identifying large prime numbers, diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 4f54770ec9..9038979b4b 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -6280,8 +6280,9 @@ total ordering. In the context of the call graph above, the function @code{parse_options} may be placed anywhere in the list as long as it precedes @code{main}. -The only options are @option{--help} and @option{--version}. @xref{Common -options}. +To conform to POSIX.1-2024, @command{tsort} accepts and ignores the +option @option{-w}. The only other options are @option{--help} and +@option{--version}. @xref{Common options}. @exitstatus diff --git a/src/tsort.c b/src/tsort.c index 2377f7082b..65050db113 100644 --- a/src/tsort.c +++ b/src/tsort.c @@ -22,6 +22,7 @@ #include +#include #include #include "system.h" @@ -538,9 +539,32 @@ main (int argc, char **argv) atexit (close_stdout); - parse_gnu_standard_options_only (argc, argv, PROGRAM_NAME, PACKAGE_NAME, - Version, true, usage, AUTHORS, - (char const *) nullptr); + while (true) + { + static struct option const long_options[] = + { + {GETOPT_HELP_OPTION_DECL}, + {GETOPT_VERSION_OPTION_DECL}, + {nullptr, 0, nullptr, 0} + }; + int c = getopt_long (argc, argv, "w", long_options, nullptr); + + if (c == -1) + break; + + switch (c) + { + case 'w': + break; + + case_GETOPT_HELP_CHAR; + + case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); + + default: + usage (EXIT_FAILURE); + } + } if (1 < argc - optind) { diff --git a/tests/misc/tsort.pl b/tests/misc/tsort.pl index f1ca28a087..d2e8d2b85b 100755 --- a/tests/misc/tsort.pl +++ b/tests/misc/tsort.pl @@ -31,6 +31,10 @@ my @Tests = ['cycle-2', {IN => {f => "t x\nt s\ns t\n"}}, {OUT => "s\nt\nx\n"}, {EXIT => 1}, {ERR => "tsort: f: input contains a loop:\ntsort: s\ntsort: t\n"} ], + ['cycle-3', '-w', {IN => {f => "a a\na b\na c\nc a\nb a"}}, + {OUT => "a\nc\nb\n"}, {EXIT => 1}, + {ERR => "tsort: f: input contains a loop:\ntsort: a\ntsort: b\n" + . "tsort: f: input contains a loop:\ntsort: a\ntsort: c\n"} ], ['posix-1', {IN => "a b c c d e\ng g\nf g e f\nh h\n"}, {OUT => "a\nc\nd\nh\nb\ne\nf\ng\n"}],