tsort
PURPOSE
Sorts an unordered list of ordered pairs (a topological
sort).
SYNOPSIS
tsort [ file ]
DESCRIPTION
The tsort command reads from file or standard input an
unordered list of ordered pairs, it builds a completely
ordered list, and writes it to standard output.
The input file should contain pairs of nonempty strings
separated by blanks. Pairs of different items indicate a
relative order. Pairs of identical items indicate pres-
ence, but no relative order. You can use tsort to sort
the output of the lorder command.
If file contains an odd number of fields, tsort writes
the error message "Odd data".
EXAMPLE
To create a subroutine library:
lorder charin.o scanfld.o scan.o scanln.o \
| tsort | xargs ar qv libsubs.a
This creates a subroutine library named "libsubs.a" that
contains "charin.o", "scanfld.o", "scan.o", and
"scanln.o". The ordering of the object modules in the
library is important. The ld command requires each
module to precede all the other modules that it calls or
references. The lorder and tsort commands together add
the subroutines to the library in the proper order.
Suppose that "scan.o" calls "scanfld.o" and "scanln.o".
"scanfld.o" also calls "charin.o". First, the lorder
command creates a list of pairs that shows these depend-
encies:
charin.o charin.o
scanfld.o scanfld.o
scan.o scan.o
scanln.o scanln.o
scanfld.o charin.o
scanln.o charin.o
scan.o scanfld.o
Next, the "|" (vertical bar) sends this list to the tsort
command, which converts it into the ordering we need:
scan.o
scanfld.o
scanln.o
charin.o
Note that each module precedes the module it calls.
"charin.o", which does not call another module, is last.
The second "|" then sends this list to xargs, which con-
structs and runs the following ar command:
ar qv libsubs.a scan.o scanfld.o scanln.o charin.o
This ar command creates the properly ordered library.
RELATED INFORMATION
The following commands: "ar," "lorder," and "xargs."