mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-02-14 03:12:10 +02:00
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.
This commit is contained in:
2
NEWS
2
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,
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
30
src/tsort.c
30
src/tsort.c
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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"}],
|
||||
|
||||
Reference in New Issue
Block a user