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