The manpage of tsort(1) says

     Node names in the input are separated by white space
     and there must be an even number of node pairs.

That's not true: there needs to be a even number of _nodes_,
i.e., they need to come in pairs (obviously, when describing
a binary relation); but there is no need to have
"an even number of node pairs". For example

        echo a b | tsort 

is _one_ node pair; that is, an odd number of _pairs_
(which is completely OK).

An error would be to specify an odd number of nodes, as in

        echo a b c | tsort

because they don't come in pairs. The error message

        tsort: odd number of pairs in stdin

is also misleading: it's an odd number of nodes, not pairs.
In fact, the EXAMPLE itself contains an odd number of pairs:

        a b
        b c
        b d
        d f
        c e

Jan



Index: tsort.1
===================================================================
RCS file: /cvs/src/usr.bin/tsort/tsort.1,v
retrieving revision 1.22
diff -u -p -r1.22 tsort.1
--- tsort.1     3 Sep 2010 11:09:29 -0000       1.22
+++ tsort.1     28 Mar 2012 09:21:24 -0000
@@ -57,8 +57,8 @@ Input is taken from the named
 or from standard input if no file
 is given.
 .Pp
-Node names in the input are separated by white space and there must
-be an even number of node pairs.
+Node names in the input are separated by white space
+and they must come in pairs.
 .Pp
 Presence of a node in a graph can be represented by an arc from the node
 to itself.
Index: tsort.c
===================================================================
RCS file: /cvs/src/usr.bin/tsort/tsort.c,v
retrieving revision 1.20
diff -u -p -r1.20 tsort.c
--- tsort.c     20 Jan 2006 23:10:19 -0000      1.20
+++ tsort.c     28 Mar 2012 09:21:24 -0000
@@ -342,7 +342,7 @@ read_pairs(FILE *f, struct ohash *h, int
                }
        }
        if (toggle == 0)
-               errx(EX_DATAERR, "odd number of pairs in %s", name);
+               errx(EX_DATAERR, "odd number of nodes in %s", name);
        if (!feof(f))
                err(EX_IOERR, "error reading %s", name);
        return order;

Reply via email to