]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tsort: add do-nothing -w option
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 14 Aug 2025 16:17:51 +0000 (09:17 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 15 Aug 2025 00:35:23 +0000 (17:35 -0700)
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.

NEWS
doc/coreutils.texi
src/tsort.c
tests/misc/tsort.pl

diff --git a/NEWS b/NEWS
index bfde1e62d41ea8285fa716409c5073f3698af560..cc4a91303967f732b5e20128d81c79ab6b219e12 100644 (file)
--- 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,
index 4f54770ec9caa7a5fa57dc62032b791d95f570e9..9038979b4bcfde2c654b766cbe3a1948e6c03c9c 100644 (file)
@@ -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
 
index 2377f7082bea52da49d2ecc2432dffb050a3984f..65050db113e03eda93a3b44cea6abeefe9fef9d0 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <config.h>
 
+#include <getopt.h>
 #include <sys/types.h>
 
 #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)
     {
index f1ca28a087abf4fb1ded31140bd351c80954c64d..d2e8d2b85b203b9c58a041f9f6da631c8c60adad 100755 (executable)
@@ -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"}],