tsort(1) — Commands
OSF
NAME
tsort − Sorts an unordered list of ordered pairs (topological sort)
SYNOPSIS
tsort [file]
DESCRIPTION
The tsort command reads from file or standard input an unordered list of ordered pairs, builds an ordered list, and writes it to standard output.
The input file should contain pairs of nonempty strings separated by spaces. 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 tsorti odd number of data fields encountered.
EXAMPLES
To create a subroutine library, enter:
lorder charin.o scanfld.o scan.o scanln.o
| tsort | xargs ar qv libsubs.a
(Enter the command entirely on one line, not on two lines as shown above.)
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:
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 you 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 | (vertical bar) 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.