The tag file is structured as sorted lines of tab-separated records. The first field in the line is the tag, other fields identify the position of the tag in a particular source file. With this, we can check a candidate tag
$TAGagainst the tag file
look "$TAG" "$TAGFILE"
Easy and fast.
To use tags to find the definition of a symbol, we'll want to hang onto all the information about each matching tag; the above use of
lookis all we need. For use in text completion, we'll want a longer pipeline eliminating extraneous information:
look "$TAG" "$TAGFILE" | cut -f1 | sort -u
The pipeline drops all fields but the first, the tag field, using
cutand eliminates duplicates with
sort -u(I suspect that
uniqshould work here, but
lookis curiously unspecific about whether it always produces its output in sorted order).
And that's it for matching tags. The file format was clearly set up with just this sort of use in mind. More details on the file format are available elsewhere.