# CLOSURE v1.30 - compute transitive closure

#### Revised 23-Aug-97. Copyright (c) 1996-97 by Rune Berg. TextTools Freeware.

Usage - Description - Example - Options - Limitations - Return codes

### USAGE

closure [log logfile] [option] key [graphfile] [to resultfile]

### DESCRIPTION

closure builds a directed graph of strings from the contents of graphfile, computes the set of strings belonging to the transitive closure starting at key, and writes that set to resultfile.

key is a string.

graphfile is an ASCII text file containing lines with 0 .. 100 (by default, but see -i option) whitespace-separated fields; this is described in more detail in the documentation for tcols. Each such field is considered a 'string' in this discussion.

For each line with strings S1 S2 ... SN in graphfile, closure adds nodes S1 S2 ... SN, and edges S1->S2 ... S1->SN, to the directed graph.

For each line with just one string S1 in graphfile, closure adds a node S1 (but no edges) to the directed graph.

closure ignores empty (whitespace only) lines in graphfile.

closure ensures the directed graph never contains duplicate nodes or edges.

If key is a string equal one of the strings in graphfile, then closure writes, to resultfile, one string per line: key and all strings reachable by following paths of edges from key's node.

If key does not appear in graphfile, then closure writes nothing to resultfile.

closure does not write duplicate strings.

If key is not equal to any of the strings in graphfile, resultfile will be empty.

If you don't specify graphfile, closure reads from standard input.
If you don't specify resultfile, closure writes to standard output.
If you don't specify logfile, closure writes error messages to standard error.

### EXAMPLE

As an example, consider the (zoologically rather dubious) graphfile "fauna.txt":

            animal dog horse bird fish
            horse pony
            bird   sparrow eagle penguin
            fish whale shark
            shark  hammerhead great-white

For the command:

            closure fish fauna.txt

closure builds (internally) the graph:

            animal
              |--> dog
              |--> horse
              |      +--> pony
              |--> bird
              |      |--> sparrow
              |      |--> eagle
              |      +--> penguin
              +--> fish
                     |--> whale
                     |      |--> hammerhead
                     |      +--> great-white
                     +--> shark

and writes as result (though not necessarily in this order):

            fish
            whale
            shark
            hammerhead
            great-white

### OPTIONS

closure recognizes the following command line options:

Option | Function
--- | ---
-iC | Separate input fields by character C (except \). Use \t to form a tab.
-r | Print internal table and hashing statistics.
-v | Print version banner and usage info to standard error (or logfile, if given), then exit.

### LIMITATIONS

Input lines in graphfile must be no longer than 255 characters, not counting the end-of-line marker (newline).

When using the -i option, make sure that graphfile does not have unwanted spaces at the end of lines - closure regards trailing spaces as part of the last field.

DOS:

closure cannot handle more than 1000 graph nodes.
closure cannot handle more than 4000 graph edges.

Win32 console mode:

closure cannot handle more than 5000 graph nodes.
closure cannot handle more than 20000 graph edges.

Graph string data is limited only by available memory.

### RETURN CODES

closure returns with one of the following codes ("error levels"):

Code | Meaning
--- | ---
0 | Success
2 | key not found in graphfile (warning)
101 | Out of memory
102 | Incorrect command line arguments
104 | Error opening file
105 | I/O error
106 | Capacity overrun
107 | File name clash

##### End of document