os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tools/man2html.tcl
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
#!/proj/tcl/install/5.x-sparc/bin/tclsh7.5
sl@0
     2
sl@0
     3
if [catch {
sl@0
     4
sl@0
     5
# man2html.tcl --
sl@0
     6
#
sl@0
     7
# This file contains procedures that work in conjunction with the
sl@0
     8
# man2tcl program to generate a HTML files from Tcl manual entries.
sl@0
     9
#
sl@0
    10
# Copyright (c) 1996 by Sun Microsystems, Inc.
sl@0
    11
#
sl@0
    12
# SCCS: @(#) man2html.tcl 1.5 96/04/11 20:21:43
sl@0
    13
#
sl@0
    14
sl@0
    15
set homeDir /home/rjohnson/Projects/tools/generic
sl@0
    16
sl@0
    17
# sarray -
sl@0
    18
#
sl@0
    19
# Save an array to a file so that it can be sourced.
sl@0
    20
#
sl@0
    21
# Arguments:
sl@0
    22
# file -		Name of the output file
sl@0
    23
# args -		Name of the arrays to save
sl@0
    24
#
sl@0
    25
proc sarray {file args} {
sl@0
    26
    set file [open $file w]
sl@0
    27
    foreach a $args {
sl@0
    28
	upvar $a array
sl@0
    29
	if ![array exists array] {
sl@0
    30
	    puts "sarray: \"$a\" isn't an array"
sl@0
    31
	    break
sl@0
    32
	}	
sl@0
    33
    
sl@0
    34
	foreach name [lsort [array names array]] {
sl@0
    35
	    regsub -all " " $name "\\ " name1
sl@0
    36
	    puts $file "set ${a}($name1) \{$array($name)\}"
sl@0
    37
	}
sl@0
    38
    }
sl@0
    39
    close $file
sl@0
    40
}
sl@0
    41
sl@0
    42
sl@0
    43
sl@0
    44
# footer --
sl@0
    45
#
sl@0
    46
# Builds footer info for HTML pages
sl@0
    47
#
sl@0
    48
# Arguments:
sl@0
    49
# None
sl@0
    50
sl@0
    51
proc footer {packages} {
sl@0
    52
    lappend f "<HR>"
sl@0
    53
    set h {[}
sl@0
    54
    foreach package $packages {
sl@0
    55
	lappend h "<A HREF=\"../$package/contents.html\">$package</A>"
sl@0
    56
	lappend h "|"
sl@0
    57
    }
sl@0
    58
    lappend f [join [lreplace $h end end {]} ] " "]
sl@0
    59
    lappend f "<HR>"
sl@0
    60
    lappend f "<PRE>Copyright &#169; 1989-1994 The Regents of the University of California."
sl@0
    61
    lappend f "Copyright &#169; 1994-1996 Sun Microsystems, Inc."
sl@0
    62
    lappend f "</PRE>"
sl@0
    63
    return [join $f "\n"]
sl@0
    64
}
sl@0
    65
sl@0
    66
sl@0
    67
sl@0
    68
sl@0
    69
# doDir --
sl@0
    70
#
sl@0
    71
# Given a directory as argument, translate all the man pages in
sl@0
    72
# that directory.
sl@0
    73
#
sl@0
    74
# Arguments:
sl@0
    75
# dir -			Name of the directory.
sl@0
    76
sl@0
    77
proc doDir dir {
sl@0
    78
    foreach f [lsort [glob -directory $dir "*.\[13n\]"]] {
sl@0
    79
	do $f	;# defined in man2html1.tcl & man2html2.tcl
sl@0
    80
    }
sl@0
    81
}
sl@0
    82
sl@0
    83
sl@0
    84
if {$argc < 2} {
sl@0
    85
    puts stderr "usage: $argv0 html_dir tcl_dir packages..."
sl@0
    86
    puts stderr "usage: $argv0 -clean html_dir"
sl@0
    87
    exit 1
sl@0
    88
}
sl@0
    89
	
sl@0
    90
if {[lindex $argv 0] == "-clean"} {
sl@0
    91
    set html_dir [lindex $argv 1]
sl@0
    92
    puts -nonewline "recursively remove: $html_dir? "
sl@0
    93
    flush stdout
sl@0
    94
    if {[gets stdin] == "y"} {
sl@0
    95
	puts "removing: $html_dir"
sl@0
    96
	exec rm -r $html_dir
sl@0
    97
    }
sl@0
    98
    exit 0
sl@0
    99
}
sl@0
   100
sl@0
   101
set html_dir [lindex $argv 0]
sl@0
   102
set tcl_dir  [lindex $argv 1]
sl@0
   103
set packages [lrange $argv 2 end]
sl@0
   104
sl@0
   105
#### need to add glob capability to packages ####
sl@0
   106
sl@0
   107
# make sure there are doc directories for each package
sl@0
   108
sl@0
   109
foreach i $packages {
sl@0
   110
    if ![file exists $tcl_dir/$i/doc] {
sl@0
   111
	puts stderr "Error: doc directory for package $i is missing"
sl@0
   112
	exit 1
sl@0
   113
    }
sl@0
   114
    if ![file isdirectory $tcl_dir/$i/doc] {
sl@0
   115
	puts stderr "Error: $tcl_dir/$i/doc is not a directory"
sl@0
   116
	exit 1
sl@0
   117
    }
sl@0
   118
}
sl@0
   119
sl@0
   120
sl@0
   121
# we want to start with a clean sheet
sl@0
   122
sl@0
   123
if [file exists $html_dir] {
sl@0
   124
    puts stderr "Error: HTML directory already exists"
sl@0
   125
    exit 1
sl@0
   126
} else {
sl@0
   127
    exec mkdir $html_dir
sl@0
   128
}
sl@0
   129
sl@0
   130
set footer [footer $packages]
sl@0
   131
sl@0
   132
sl@0
   133
# make the hyperlink arrays and contents.html for all packages
sl@0
   134
	
sl@0
   135
foreach package $packages {
sl@0
   136
    global homeDir
sl@0
   137
    exec mkdir $html_dir/$package
sl@0
   138
    
sl@0
   139
    # build hyperlink database arrays: NAME_file and KEY_file
sl@0
   140
    #
sl@0
   141
    puts "\nScanning man pages in $tcl_dir/$package/doc..."
sl@0
   142
    source $homeDir/man2html1.tcl
sl@0
   143
    
sl@0
   144
    doDir $tcl_dir/$package/doc
sl@0
   145
sl@0
   146
    # clean up the NAME_file and KEY_file database arrays
sl@0
   147
    #
sl@0
   148
    catch {unset KEY_file()}
sl@0
   149
    foreach name [lsort [array names NAME_file]] {
sl@0
   150
	set file_name $NAME_file($name)
sl@0
   151
	if {[llength $file_name] > 1} {
sl@0
   152
	    set file_name [lsort $file_name]
sl@0
   153
	    puts stdout "Warning: '$name' multiply defined in: $file_name; using last"
sl@0
   154
	    set NAME_file($name) [lindex $file_name end]
sl@0
   155
	}
sl@0
   156
    }
sl@0
   157
#   sarray $html_dir/$package/xref.tcl NAME_file KEY_file
sl@0
   158
sl@0
   159
    # build the contents file from NAME_file
sl@0
   160
    #
sl@0
   161
    puts "\nGenerating contents.html for $package"
sl@0
   162
    doContents $html_dir/$package/contents.html $lib ;# defined in man2html1.tcl
sl@0
   163
sl@0
   164
    # now translate the man pages to HTML pages
sl@0
   165
    #
sl@0
   166
    source $homeDir/man2html2.tcl
sl@0
   167
    puts "\nBuilding html pages from man pages in $tcl_dir/$package/doc..."
sl@0
   168
    doDir $tcl_dir/$package/doc
sl@0
   169
sl@0
   170
    unset NAME_file
sl@0
   171
}
sl@0
   172
sl@0
   173
	
sl@0
   174
sl@0
   175
} result] {
sl@0
   176
    global errorInfo
sl@0
   177
    puts stderr $result
sl@0
   178
    puts stderr "in"
sl@0
   179
    puts stderr $errorInfo
sl@0
   180
}
sl@0
   181