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