Debian Codegraph @

tools/index.tcl

raw
1 # index.tcl --
2 #
3 # This file defines procedures that are used during the first pass of
4 # the man page conversion. It is used to extract information used to
5 # generate a table of contents and a keyword list.
6 #
7 # Copyright (c) 1996 Sun Microsystems, Inc.
8 #
9 # See the file "license.terms" for information on usage and redistribution
10 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
12 # Global variables used by these scripts:
13 #
14 # state - state variable that controls action of text proc.
15 #
16 # topics - array indexed by (package,section,topic) with value
17 # of topic ID.
18 #
19 # keywords - array indexed by keyword string with value of topic ID.
20 #
21 # curID - current topic ID, starts at 0 and is incremented for
22 # each new topic file.
23 #
24 # curPkg - current package name (e.g. Tcl).
25 #
26 # curSect - current section title (e.g. "Tcl Built-In Commands").
27 #
28
29 # getPackages --
30 #
31 # Generate a sorted list of package names from the topics array.
32 #
33 # Arguments:
34 # none.
35
36 proc getPackages {} {
37 global topics
38 foreach i [array names topics] {
39 regsub {^(.*),.*,.*$} $i {\1} i
40 set temp($i) {}
41 }
42 lsort [array names temp]
43 }
44
45 # getSections --
46 #
47 # Generate a sorted list of section titles in the specified package
48 # from the topics array.
49 #
50 # Arguments:
51 # pkg - Name of package to search.
52
53 proc getSections {pkg} {
54 global topics
55 regsub -all {[][*?\\]} $pkg {\\&} pkg
56 foreach i [array names topics "${pkg},*"] {
57 regsub {^.*,(.*),.*$} $i {\1} i
58 set temp($i) {}
59 }
60 lsort [array names temp]
61 }
62
63 # getTopics --
64 #
65 # Generate a sorted list of topics in the specified section of the
66 # specified package from the topics array.
67 #
68 # Arguments:
69 # pkg - Name of package to search.
70 # sect - Name of section to search.
71
72 proc getTopics {pkg sect} {
73 global topics
74 regsub -all {[][*?\\]} $pkg {\\&} pkg
75 regsub -all {[][*?\\]} $sect {\\&} sect
76 foreach i [array names topics "${pkg},${sect},*"] {
77 regsub {^.*,.*,(.*)$} $i {\1} i
78 set temp($i) {}
79 }
80 lsort [array names temp]
81 }
82
83 # text --
84 #
85 # This procedure adds entries to the hypertext arrays topics and keywords.
86 #
87 # Arguments:
88 # string - Text to index.
89
90
91 proc text string {
92 global state curID curPkg curSect topics keywords
93
94 switch $state {
95 NAME {
96 foreach i [split $string ","] {
97 set topic [string trim $i]
98 set index "$curPkg,$curSect,$topic"
99 if {[info exists topics($index)]
100 && [string compare $topics($index) $curID] != 0} {
101 puts stderr "duplicate topic $topic in $curPkg"
102 }
103 set topics($index) $curID
104 lappend keywords($topic) $curID
105 }
106 }
107 KEY {
108 foreach i [split $string ","] {
109 lappend keywords([string trim $i]) $curID
110 }
111 }
112 DT -
113 OFF -
114 DASH {}
115 default {
116 puts stderr "text: unknown state: $state"
117 }
118 }
119 }
120
121
122 # macro --
123 #
124 # This procedure is invoked to process macro invocations that start
125 # with "." (instead of ').
126 #
127 # Arguments:
128 # name - The name of the macro (without the ".").
129 # args - Any additional arguments to the macro.
130
131 proc macro {name args} {
132 switch $name {
133 SH - SS {
134 global state
135
136 switch $args {
137 NAME {
138 if {$state eq "INIT" } {
139 set state NAME
140 }
141 }
142 DESCRIPTION {set state DT}
143 INTRODUCTION {set state DT}
144 KEYWORDS {set state KEY}
145 default {set state OFF}
146 }
147
148 }
149 TH {
150 global state curID curPkg curSect topics keywords
151 set state INIT
152 if {[llength $args] != 5} {
153 set args [join $args " "]
154 puts stderr "Bad .TH macro: .$name $args"
155 }
156 incr curID
157 set topic [lindex $args 0] ;# Tcl_UpVar
158 set curPkg [lindex $args 3] ;# Tcl
159 set curSect [lindex $args 4] ;# {Tcl Library Procedures}
160 regsub -all {\\ } $curSect { } curSect
161 set index "$curPkg,$curSect,$topic"
162 set topics($index) $curID
163 lappend keywords($topic) $curID
164 }
165 }
166 }
167
168
169 # dash --
170 #
171 # This procedure is invoked to handle dash characters ("\-" in
172 # troff). It only function in pass1 is to terminate the NAME state.
173 #
174 # Arguments:
175 # None.
176
177 proc dash {} {
178 global state
179 if {$state eq "NAME"} {
180 set state DASH
181 }
182 }
183
184
185
186 # initGlobals, tab, font, char, macro2 --
187 #
188 # These procedures do nothing during the first pass.
189 #
190 # Arguments:
191 # None.
192
193 proc initGlobals {} {}
194 proc newline {} {}
195 proc tab {} {}
196 proc font type {}
197 proc char name {}
198 proc macro2 {name args} {}
199