File: guihelp.tcl

package info (click to toggle)
espresso 5.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 146,004 kB
  • ctags: 17,245
  • sloc: f90: 253,041; sh: 51,271; ansic: 27,494; tcl: 15,570; xml: 14,508; makefile: 2,958; perl: 2,035; fortran: 1,924; python: 337; cpp: 200; awk: 57
file content (163 lines) | stat: -rw-r--r-- 4,306 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
namespace eval ::helpdoc::gui_help {
    variable helpContent
    variable helpNameList ""

    proc printHelp_ {channel} {
	variable helpContent
	variable helpNameList
	
	foreach name $helpNameList {
	    puts $channel "\n# ------------------------------------------------------------------------"	    
	    if { [llength $name] > 1 } {
		puts $channel "grouphelp [list $name] -helpfmt helpdoc -helptext [list $helpContent($name)]\n"
	    } else {
		puts $channel "help $name -helpfmt helpdoc -helptext [list $helpContent($name)]\n"
	    }
	}
    }

    proc addHelp_ {names helpTxt} {
	variable helpContent
	variable helpNameList
		
	::tclu::ladd helpNameList $names
	append helpContent($names) ${helpTxt}\n
    }

    proc grouphelp {names helpTxt} {
	foreach name $names {
	    if { [info exists ::guib::moduleObj::module_item($name)] } {
		if { $::guib::moduleObj::module_item(ident,$name) != "" } {
		    switch -- $::guib::moduleObj::module_item($name) {
			var - dimension - table  {
			    lappend ok_names $::guib::moduleObj::module_item(ident,$name)
			}
		    }
		}
	    }
	}
	if { [info exists ok_names] } {	    
	    addHelp_ $ok_names $helpTxt
	}	
    }

    proc help {name helpTxt} {

	# hande exceptions
	
	switch -- $::module {
	    atomic {
		switch -- $name {		    
		    nwfts - test_wfs {
			# in module file we have nwfts_*
			#puts "[array names ::guib::moduleObj::module_item -glob ${name}_*]"
			set names [array names ::guib::moduleObj::module_item -glob ${name}_*]
			if { $names != "" } {
			    grouphelp $names $helpTxt			
			}
		    }
		}
	    }

	    ph {
		if { $name eq "alpha_mix(niter)" } {
		    # in module file we have alpha_mix(1)
		    set name alpha_mix(1)
		}
	    }	    		    
	}

	if { $name == "occupations_table" } {
	    puts "occupations_table"
	    puts "      def-exists [info exists ::helpdoc::def_item($name)]"
	    puts "   module-exists [info exists ::guib::moduleObj::module_item($name)]"
	    puts "    module-ident $::guib::moduleObj::module_item(ident,$name)"
	}

	if { [info exists ::guib::moduleObj::module_item($name)] } {
	    if { $::guib::moduleObj::module_item(ident,$name) != "" } {
		switch -- $::guib::moduleObj::module_item($name) {
		    var - dimension - table - text {
			# important: we must pass from name to ident		    

			addHelp_ $::guib::moduleObj::module_item(ident,$name) $helpTxt
		    }
		}
	    }
	}
    }        
}


proc ::helpdoc::checkGui_makeHelpFile {deffile modulefile} {
    variable xsltproc
    variable helpfile
    variable xml_temp

    if { $xsltproc == "" } {
	::tclu::ERROR "can't find useable xsltproc, gui help file creation skipped"
    }
            
    # help file will be written to $helpfile

    set helpfile      [file tail [file rootname $modulefile]]-help.tcl
    set orig_helpfile [file rootname $modulefile]-help.tcl

    if { "$helpfile" == "$orig_helpfile" } {
	puts stderr [::tclu::labelMsg WARNING "file \"$orig_helpfile\" exists.\nMaking a $orig_helpfile.bak backup copy."]
	file copy -force $orig_helpfile $orig_helpfile.bak
    }


    # open/create a temporaty xml file ...
    
    set orig_xmlfile [file rootname $deffile].xml
    set xml_prefix   [file tail [file rootname $deffile]]

    if { "$xml_prefix.xml" == "$orig_xmlfile" } {
	# ups, we don't want to overwrite $xmlfile
	set xml_temp ${xml_prefix}_temp.xml
    } else {
	set xml_temp ${xml_prefix}.xml
    }
    set xml_fid [open $xml_temp w]


    # copy $orig_xmlfile to $xml_temp, but replace the stylesheet input_xx.xsl by guihelp.xsl

    ::tclu::lineread line $orig_xmlfile {
	if { [string match {<?xml-stylesheet*} $line] } {
	    puts $xml_fid {<?xml-stylesheet type="text/xsl" href="guihelp.xsl"?>}
	} else {
	    puts $xml_fid $line
	}
    }
    close $xml_fid
    puts "\n\tXml-file $xml_temp has been written.\n"

    catch [list exec $xsltproc $xml_temp > $xml_temp.tcl]    

    puts "\n\tAuxiliary help-file $xml_temp.tcl has been written.\n"


    # create a $helpfile

    namespace eval gui_help {

	set helpID [open $::helpdoc::helpfile w]

	puts $helpID {
#
# Help-file automatically created by helpdoc utility
#
#    !!! DO NOT EDIT: CHANGES WILL BE LOST !!!
#
	}
	
	source $::helpdoc::xml_temp.tcl
	printHelp_ $helpID
	close $helpID
    }
    puts "\n\tHelp-file $helpfile has been written.\n"
}