TSORT(1,C) AIX Commands Reference TSORT(1,C)
-------------------------------------------------------------------------------
tsort
PURPOSE
Sorts an unordered list of ordered pairs (a topological sort).
SYNTAX
+--------+
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 non-empty strings separated by blanks.
Pairs of different items indicate a relative order. Pairs of identical items
indicate presence, 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
dependencies:
Processed November 8, 1990 TSORT(1,C) 1
TSORT(1,C) AIX Commands Reference TSORT(1,C)
charin.o charin.o
scanfld.o scanfld.o
scan.o scan.o
scanln.o scanln.o
scanfld.o charin.o
scan.o scanfld.o
scan.o scanln.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
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 constructs 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
See the following commands: "ar," "lorder," and "xargs."
Processed November 8, 1990 TSORT(1,C) 2