#!/bin/sh # \ exec $CCP4I_TCLTK/tclsh "$0" -- ${1+"$@"} # Copyright (C) 1999-2004 Liz Potterton, Peter Briggs # # This code is distributed under the terms and conditions of the # CCP4 Program Suite Licence Agreement as a CCP4 Library. # A copy of the CCP4 licence can be obtained by writing to the # CCP4 Secretary, Daresbury Laboratory, Warrington WA4 4AD, UK. # #CCP4i_cvs_Id $Id: create_docs,v 1.9 2008/08/12 10:48:37 pjx Exp $ # This is a copy of the "create_docs" script from $CCP4/ccp4i/bin # which has been modified to generate the documentation for the Tcl # files in the dbccp4i distribution # Source startup.tcl appropriate for operating system set system(OPSYS) [string toupper $tcl_platform(platform)] source [file join $env(CCP4I_TOP) bin $system(OPSYS) startup.tcl] # Source the useful utils source [file join $env(CCP4I_TOP) src system.tcl] source [file join $env(CCP4I_TOP) src utils.tcl] #---------------------------------------------------------------------- # The following declarations are liable to change #---------------------------------------------------------------------- # list of files to be processed - the inner loop is. # - a name for the output html file # - the ccp4i subdirectory containing files to be processed # - list of files set doclist [list [list dbClientAPI_tcl ClientAPI dbClientAPI dbxml ccp4ilite] ] set htmlHeader " dbCCP4i Tcl Client API Documentation

dbCCP4i Tcl Client API Documentation

Contents

\n" set htmlFooter " \n" #---------------------------------------------------------------------- #---------------------------------------------------------------------- # By default create docs for the current $CCP4I_TOP and place the # docs in $CCP4I_HELP/programmers/progdocs. Beware that if you change # these the default paths for html links defined below may need changing. set srcPath [GetEnvPath DBCCP4I_TOP] set docPath [file join [GetEnvPath DBCCP4I_TOP] doc] set indexFile dbClientAPI_tcl.html # Parse any command line input set nargs [llength $argv]; set n 0 while { $n < $nargs } { set cmd [string tolower [lindex $argv $n]] switch -regexp -- $cmd \ src { incr n; set srcPath [lindex $argv $n] } doc { incr n; set docPath [lindex $argv $n] } index { incr n; set indexFile [lindex $argv $n] } incr n } # Set up an index html file set contentsText $htmlHeader set htmlText "\n
\n" # Loop through every document on the doclist and create text for a new # html file foreach doc $doclist { set htmlFile $indexFile set modulePath [file join $srcPath [lindex $doc 1]] puts "Reading source file.." # # Loop over all specified source files - read the contents with # lines split into a list foreach file [lrange $doc 2 end] { set filePath [file join $modulePath $file.tcl] puts "..$filePath" if { ![ReadFile $filePath srctext -split] } { puts "ABORTING: Can not read file $filePath" exit } # # Loop over every line looking for the #d_ at start of line which indicates # a documentation tag. If a documentation line ends in continuation character # then you need to append the next line from the file (and get rid of the # continuation character. set l 0; set lmax [llength $srctext] while { $l < $lmax } { set line0 [lindex $srctext $l] if [regexp {^#d_} $line0] { set ll [string wordend $line0 1] set cmd [string range $line0 3 [expr $ll -1]] set line [string range $line0 [expr $ll + 1] end] while { [ regexp {\\$} $line] } { set line [string trimright $line \\ ] incr l; append line [lindex $srctext $l] } # # Handle the documentation line according to the tag # switch $cmd \ intro_title { set target [RemoveMetaChars $line] append htmlText "

$line

\n" append indexText "
$line
\n" } intro { append htmlText

$line

\n } index_title { set target [RemoveMetaChars $line] append contentsText "

$line
" append indexText "
$line
\n" append htmlText "

$line

\n" } sum { append indexText "
$procName $line
\n" append htmlText "

$procName $line

\n" append htmlText "

Argument list: $argList

\n" } desc { append htmlText

$line

\n } arg { append htmlText "

[lindex $line 0] [lrange $line 1 end]

\n" } opt0 { if { [llength $line] > 1 } { append htmlText "

[lindex $line 0] [lrange $line 1 end]

\n" } else { append htmlText "

$line

\n" } } opt1 { append htmlText "

$line

\n" } ref { set mode file set path {} switch [lindex $line 0] \ PROGRAMS { set path [file join "../../../../html/" [lindex $line 1]] } CCP4I { set path [file join "../../../help/" [lindex $line 1]] } PROGDOCS { set path [file join "./" [lindex $line 1]] } REMOTE { set path "http://[lindex $line 1]" set mode http } CURRENT { set path "#[lindex $line 1]" } append htmlText "[lrange $line 2 end]" } doc { append htmlText \ "See Programmers Documentation" } # # If find a procedure declaration in file then save the procedure name } elseif { [regexp {^proc } $line0] } { # remove the open/close brace from the line or it might be mishandled by lindex regsub -all {\{|\}} $line0 {} procLine set procName [lindex $procLine 1] # Create a formatted argument list for writing out later set argList "" for {set i 2} {$i<[llength $procLine]} {incr i} { append argList " <[lindex $procLine $i]>" } if {$argList == ""} { set argList "None" } } incr l } append htmlText "\n


\n" } } puts "Writing list of procedures to [file join $docPath $indexFile]" append contentsText \n $indexText $htmlFooter WriteFile [file join $docPath $indexFile] $htmlHeader -overwrite WriteFile [file join $docPath $indexFile] $indexText WriteFile [file join $docPath $indexFile] $htmlText WriteFile [file join $docPath $indexFile] $htmlFooter exit