File: guihelp.tcl

package info (click to toggle)
espresso 6.7-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 311,040 kB
  • sloc: f90: 447,429; ansic: 52,566; sh: 40,631; xml: 37,561; tcl: 20,077; lisp: 5,923; makefile: 4,502; python: 4,379; perl: 1,219; cpp: 761; fortran: 618; java: 568; awk: 128
file content (226 lines) | stat: -rw-r--r-- 6,254 bytes parent folder | download | duplicates (3)
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
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 if_exists_addHelp_ {name helpTxt} {
	if { [info exists ::guib::moduleObj::module_item($name)] } {
	    if { $::guib::moduleObj::module_item(ident,$name) != "" } {
		switch -- $::guib::moduleObj::module_item($name) {
		    var - dimension - multidimension - table - text {
			# important: we must pass from name to ident		    
			
			addHelp_ $::guib::moduleObj::module_item(ident,$name) $helpTxt
			return 1
		    }
		}
	    }
	}
	return 0
    }

    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 - multidimension - table  {
			    lappend ok_names $::guib::moduleObj::module_item(ident,$name)
			}
			
		    }
		}
	    } else {
		# pehaps the variable name is a dimension-like name, i.e. dimen(i,j,k),
		# and there is the "(i,j,k)" mismatch between module and def name;
		# try to see if "dimen" only exists ...
		
		set name [lindex [split $name \(] 0]
		
		if { [info exists ::guib::moduleObj::module_item($name)] } {
		    if { $::guib::moduleObj::module_item(ident,$name) != "" } {
			switch -- $::guib::moduleObj::module_item($name) {
			    var - dimension - multidimension - table  {
				lappend ok_names $::guib::moduleObj::module_item(ident,$name)
			    }
			    
			}
		    }
		}
	    }       	
	}
	if { [info exists ok_names] } {	    
	    addHelp_ $ok_names $helpTxt
	}
    }

    #proc grouphelp {names helpTxt} {
    #	foreach name $names {
    #	    if { ! [if_exists_addHelp_ $name $helpTxt] } {	     	
    #
    #		# pehaps the variable name is a dimension-like name, i.e. dimen(i,j,k),
    #		# and there is the "(i,j,k)" mismatch between module and def name;
    #		# try to see if "dimen" only exists ...
    #		puts "pre.name = $name"
    #		set name [lindex [split $name \(] 0]
    #		puts "post.name = $name"
    #		
    #		if_exists_addHelp_ $name $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)
		}

		# for the time being ...
		if { $name eq "dvscf_star" || $name eq "drho_star" } {
		    foreach elem {open dir ext basis pat} {
			lappend names $name%$elem
		    }
		    grouphelp $names $helpTxt
		    return
		}
	    }   		    
	}

	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 { ! [if_exists_addHelp_ $name $helpTxt] } {	     	

	    # pehaps the variable name is a dimension-like name, i.e. dimen(i,j,k),
	    # and there is the "(i,j,k)" mismatch between module and def name;
	    # try to see if "dimen" only exists ...

	    set name [lindex [split $name \(] 0]
	    
	    if_exists_addHelp_ $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"
    }
            
    # open/create a temporaty xml file ...
    
    set orig_xmlfile [file rootname $deffile].xml
    if { ! [file exists $orig_xmlfile] } {
        ::tclu::ERROR "file $orig_xmlfile does not exists, remake the documentation first! 

Gui help file creation skipped."
    }
    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]

    # 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
    }


    # 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"
}