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