Debian Codegraph @

tools/man2help.tcl

raw
1 # man2help.tcl --
2 #
3 # This file defines procedures that work in conjunction with the
4 # man2tcl program to generate a Windows help file from Tcl manual
5 # entries.
6 #
7 # Copyright (c) 1996 Sun Microsystems, Inc.
8
9 #
10 # PASS 1
11 #
12
13 set man2tclprog [file join [file dirname [info script]] \
14 man2tcl[file extension [info nameofexecutable]]]
15
16 proc generateContents {basename version files} {
17 global curID topics
18 set curID 0
19 foreach f $files {
20 puts "Pass 1 -- $f"
21 flush stdout
22 doFile $f
23 }
24 set fd [open [file join [file dirname [info script]] $basename$version.cnt] w]
25 fconfigure $fd -translation crlf
26 puts $fd ":Base $basename$version.hlp"
27 foreach package [getPackages] {
28 foreach section [getSections $package] {
29 if {![info exists lastSection]} {
30 set lastSection {}
31 }
32 if {[string compare $lastSection $section]} {
33 puts $fd "1 $section"
34 }
35 set lastSection $section
36 set lastTopic {}
37 foreach topic [getTopics $package $section] {
38 if {[string compare $lastTopic $topic]} {
39 set id $topics($package,$section,$topic)
40 puts $fd "2 $topic=$id"
41 set lastTopic $topic
42 }
43 }
44 }
45 }
46 close $fd
47 }
48
49
50 #
51 # PASS 2
52 #
53
54 proc generateHelp {basename files} {
55 global curID topics keywords file id_keywords
56 set curID 0
57
58 foreach key [array names keywords] {
59 foreach id $keywords($key) {
60 lappend id_keywords($id) $key
61 }
62 }
63
64 set file [open [file join [file dirname [info script]] $basename.rtf] w]
65 fconfigure $file -translation crlf
66 puts $file "\{\\rtf1\\ansi \\deff0\\deflang1033\{\\fonttbl\{\\f0\\froman\\fcharset0\\fprq2 Times New Roman\;\}\{\\f1\\fmodern\\fcharset0\\fprq1 Courier New\;\}\}"
67 foreach f $files {
68 puts "Pass 2 -- $f"
69 flush stdout
70 initGlobals
71 doFile $f
72 pageBreak
73 }
74 puts $file "\}"
75 close $file
76 }
77
78 # doFile --
79 #
80 # Given a file as argument, translate the file to a tcl script and
81 # evaluate it.
82 #
83 # Arguments:
84 # file - Name of file to translate.
85
86 proc doFile {file} {
87 global man2tclprog
88 if {[catch {eval [exec $man2tclprog [glob $file]]} msg]} {
89 global errorInfo
90 puts stderr $msg
91 puts "in"
92 puts $errorInfo
93 exit 1
94 }
95 }
96
97 # doDir --
98 #
99 # Given a directory as argument, translate all the man pages in
100 # that directory.
101 #
102 # Arguments:
103 # dir - Name of the directory.
104
105 proc doDir dir {
106 puts "Generating man pages for $dir..."
107 foreach f [lsort [glob -directory $dir "*.\[13n\]"]] {
108 doFile $f
109 }
110 }
111
112 # process command line arguments
113
114 if {$argc < 3} {
115 puts stderr "usage: $argv0 \[options\] projectName version manFiles..."
116 exit 1
117 }
118
119 set arg 0
120
121 if {![string compare [lindex $argv $arg] "-bitmap"]} {
122 set bitmap [lindex $argv [incr arg]]
123 incr arg
124 }
125 set baseName [lindex $argv $arg]
126 set version [lindex $argv [incr arg]]
127 set files {}
128 foreach i [lrange $argv [incr arg] end] {
129 set i [file join $i]
130 if {[file isdir $i]} {
131 foreach f [lsort [glob -directory $i "*.\[13n\]"]] {
132 lappend files $f
133 }
134 } elseif {[file exists $i]} {
135 lappend files $i
136 }
137 }
138 source -encoding utf-8 [file join [file dirname [info script]] index.tcl]
139 generateContents $baseName $version $files
140 source -encoding utf-8 [file join [file dirname [info script]] man2help2.tcl]
141 generateHelp $baseName $files