sl@0: # index.tcl -- sl@0: # sl@0: # This file defines procedures that are used during the first pass of sl@0: # the man page conversion. It is used to extract information used to sl@0: # generate a table of contents and a keyword list. sl@0: # sl@0: # Copyright (c) 1996 by Sun Microsystems, Inc. sl@0: # sl@0: # See the file "license.terms" for information on usage and redistribution sl@0: # of this file, and for a DISCLAIMER OF ALL WARRANTIES. sl@0: # sl@0: # RCS: @(#) $Id: index.tcl,v 1.3.40.1 2003/06/04 23:41:15 mistachkin Exp $ sl@0: # sl@0: sl@0: # Global variables used by these scripts: sl@0: # sl@0: # state - state variable that controls action of text proc. sl@0: # sl@0: # topics - array indexed by (package,section,topic) with value sl@0: # of topic ID. sl@0: # sl@0: # keywords - array indexed by keyword string with value of topic ID. sl@0: # sl@0: # curID - current topic ID, starts at 0 and is incremented for sl@0: # each new topic file. sl@0: # sl@0: # curPkg - current package name (e.g. Tcl). sl@0: # sl@0: # curSect - current section title (e.g. "Tcl Built-In Commands"). sl@0: # sl@0: sl@0: # getPackages -- sl@0: # sl@0: # Generate a sorted list of package names from the topics array. sl@0: # sl@0: # Arguments: sl@0: # none. sl@0: sl@0: proc getPackages {} { sl@0: global topics sl@0: foreach i [array names topics] { sl@0: regsub {^(.*),.*,.*$} $i {\1} i sl@0: set temp($i) {} sl@0: } sl@0: lsort [array names temp] sl@0: } sl@0: sl@0: # getSections -- sl@0: # sl@0: # Generate a sorted list of section titles in the specified package sl@0: # from the topics array. sl@0: # sl@0: # Arguments: sl@0: # pkg - Name of package to search. sl@0: sl@0: proc getSections {pkg} { sl@0: global topics sl@0: regsub -all {[][*?\\]} $pkg {\\&} pkg sl@0: foreach i [array names topics "${pkg},*"] { sl@0: regsub {^.*,(.*),.*$} $i {\1} i sl@0: set temp($i) {} sl@0: } sl@0: lsort [array names temp] sl@0: } sl@0: sl@0: # getTopics -- sl@0: # sl@0: # Generate a sorted list of topics in the specified section of the sl@0: # specified package from the topics array. sl@0: # sl@0: # Arguments: sl@0: # pkg - Name of package to search. sl@0: # sect - Name of section to search. sl@0: sl@0: proc getTopics {pkg sect} { sl@0: global topics sl@0: regsub -all {[][*?\\]} $pkg {\\&} pkg sl@0: regsub -all {[][*?\\]} $sect {\\&} sect sl@0: foreach i [array names topics "${pkg},${sect},*"] { sl@0: regsub {^.*,.*,(.*)$} $i {\1} i sl@0: set temp($i) {} sl@0: } sl@0: lsort [array names temp] sl@0: } sl@0: sl@0: # text -- sl@0: # sl@0: # This procedure adds entries to the hypertext arrays topics and keywords. sl@0: # sl@0: # Arguments: sl@0: # string - Text to index. sl@0: sl@0: sl@0: proc text string { sl@0: global state curID curPkg curSect topics keywords sl@0: sl@0: switch $state { sl@0: NAME { sl@0: foreach i [split $string ","] { sl@0: set topic [string trim $i] sl@0: set index "$curPkg,$curSect,$topic" sl@0: if {[info exists topics($index)] sl@0: && [string compare $topics($index) $curID] != 0} { sl@0: puts stderr "duplicate topic $topic in $curPkg" sl@0: } sl@0: set topics($index) $curID sl@0: lappend keywords($topic) $curID sl@0: } sl@0: } sl@0: KEY { sl@0: foreach i [split $string ","] { sl@0: lappend keywords([string trim $i]) $curID sl@0: } sl@0: } sl@0: DT - sl@0: OFF - sl@0: DASH {} sl@0: default { sl@0: puts stderr "text: unknown state: $state" sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: # macro -- sl@0: # sl@0: # This procedure is invoked to process macro invocations that start sl@0: # with "." (instead of '). sl@0: # sl@0: # Arguments: sl@0: # name - The name of the macro (without the "."). sl@0: # args - Any additional arguments to the macro. sl@0: sl@0: proc macro {name args} { sl@0: switch $name { sl@0: SH { sl@0: global state sl@0: sl@0: switch $args { sl@0: NAME { sl@0: if {$state == "INIT" } { sl@0: set state NAME sl@0: } sl@0: } sl@0: DESCRIPTION {set state DT} sl@0: INTRODUCTION {set state DT} sl@0: KEYWORDS {set state KEY} sl@0: default {set state OFF} sl@0: } sl@0: sl@0: } sl@0: TH { sl@0: global state curID curPkg curSect topics keywords sl@0: set state INIT sl@0: if {[llength $args] != 5} { sl@0: set args [join $args " "] sl@0: puts stderr "Bad .TH macro: .$name $args" sl@0: } sl@0: incr curID sl@0: set topic [lindex $args 0] ;# Tcl_UpVar sl@0: set curPkg [lindex $args 3] ;# Tcl sl@0: set curSect [lindex $args 4] ;# {Tcl Library Procedures} sl@0: regsub -all {\\ } $curSect { } curSect sl@0: set index "$curPkg,$curSect,$topic" sl@0: set topics($index) $curID sl@0: lappend keywords($topic) $curID sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: # dash -- sl@0: # sl@0: # This procedure is invoked to handle dash characters ("\-" in sl@0: # troff). It only function in pass1 is to terminate the NAME state. sl@0: # sl@0: # Arguments: sl@0: # None. sl@0: sl@0: proc dash {} { sl@0: global state sl@0: if {$state == "NAME"} { sl@0: set state DASH sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: # initGlobals, tab, font, char, macro2 -- sl@0: # sl@0: # These procedures do nothing during the first pass. sl@0: # sl@0: # Arguments: sl@0: # None. sl@0: sl@0: proc initGlobals {} {} sl@0: proc newline {} {} sl@0: proc tab {} {} sl@0: proc font type {} sl@0: proc char name {} sl@0: proc macro2 {name args} {} sl@0: