tsort(1)							     tsort(1)


  tsort - Sorts an unordered list of ordered pairs (topological sort)


  tsort [file]


  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.
  For creating a subroutine library, do not use tsort; use the following com-
  mand in its place:

       % ar -ts file.a

  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.


  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 com-
  mands 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 con-
  verts it into the ordering you need:


  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.


  Commands:  ar(1), lorder(1), xargs(1).