12.3.5. Handling See Also Entries
One type of index entry is a "see also." Like a "see" reference, it
refers the reader to another entry. However, a "see also" entry may
have a page number as well. In other words, this entry contains
information of its own but refers the reader elsewhere for additional
information. Here are a few sample entries.
error procedure 34
error procedure (see also XtAppSetErrorMsgHandler) 35
error procedure (see also XtAppErrorMsg)
The first entry in this sample has a page number while the last one
does not. When the input.idx program finds a "see
also" entry, it checks to see if a page number ($2) is supplied. If
there is one, it outputs two records, the first of which is the entry
without the page number and the second of which is an entry and page
number without the "see also" reference.
#< input.idx
# if no page number
if ($2 == "") {
print $0 ":"
next
}
else {
# output two entries:
# print See Also entry w/out page number
print $1 ":"
# remove See Also
sub(/ *~zz\(see also.*$/, "", $1)
sub(/;/, "", $1)
# print as normal entry
if ( $1 ~ /:/ )
print $1 ":" $2
else
print $1 "::" $2
next
}
The next problem to be solved was how to get the entries sorted in the
proper order. The sort program, using the options
we gave it, sorted the secondary keys for "see also" entries together
under "s." (The -d option causes the parenthesis to
be ignored.) To change the order of the sort, we alter the sort key
by adding the sequence "~zz" to the front of it.
#< input.idx
# add "~zz" for sort at end
sub(/\([Ss]ee [Aa]lso/, "~zz(see also", $1)
The tilde is not interpreted by the sort but it helps us identify the
string later when we remove it. Adding "~zz" assures us of sorting to
the end of the list of secondary or tertiary keys.
The pagenums.idx script removes the sort string
from "see also" entries. However, as we described earlier, we look
for a series of "see also" entries for the same key and create a list.
Therefore, we also remove that which is the same for all entries, and
put the reference itself in an array:
#< pagenums.idx
# remove secondary key along with "~zz"
sub(/^.*~zz\([Ss]ee +[Aa]lso */, "", SECONDARY)
sub(/\) */, "", SECONDARY)
# assign to next element of seeAlsoList
seeAlsoList[++eachSeeAlso] = SECONDARY "; "
There is a function that outputs the list of "see also" entries,
separating each of them by a semicolon. Thus, the output of the "see
also" entry by pagenums.idx looks like:
error procedure:(see also XtAppErrorMsg; XtAppSetErrorHandler.)