Files
sics/site_ansto/instrument/gumxml.tcl
Douglas Clowes 3224422d60 Implement hlistprop $path tclnames
Squashed commit of the following:

commit 736f0f3da501ee39fb89735a1142fe6ff2b2c4dd
Author: Douglas Clowes <dcl@ansto.gov.au>
Date:   Wed Jul 2 12:21:32 2014 +1000

    Use hlistprop $path tclnames in hipadaba_configuration_common.tcl

commit 428cac5ac8fe37f6998d3114c71ca01fc9446644
Author: Douglas Clowes <dcl@ansto.gov.au>
Date:   Wed Jul 2 12:11:47 2014 +1000

    Use hlistprop $path tclnames in nxscripts_common_1.tcl

commit 123cc63924e92a9453bfd1297a4ee6398b31bd1d
Author: Douglas Clowes <dcl@ansto.gov.au>
Date:   Wed Jul 2 10:56:34 2014 +1000

    Use hlistprop $path tclnames in gumxml.tcl

commit e23f8befd36a2066ceaa32ce3d37d53bc462f870
Author: Douglas Clowes <dcl@ansto.gov.au>
Date:   Wed Jul 2 10:55:48 2014 +1000

    Use hlistprop $path tclnames in testing

commit a3587be0a8cc9a9452a75cb0e19572558d35a08a
Author: Douglas Clowes <dcl@ansto.gov.au>
Date:   Wed Jul 2 10:55:01 2014 +1000

    Implement hlistprop $path tclnames
2014-07-02 12:28:41 +10:00

164 lines
4.0 KiB
Tcl

proc getdataType {path} {
return [lindex [split [hinfo $path] ,] 0]
}
proc encode {str} {
set result [string map -nocase {
"\"" {&quot;}
{'} {&apos;}
{<} {&lt;}
{>} {&gt;}
{&} {&amp;}
\u0 {}
\u1 {}
\u2 {}
\u3 {}
\u4 {}
\u5 {}
\u6 {}
\u7 {}
\u8 {}
\u9 {&#x09;}
\ua {&#x0a;}
\ub {}
\uc {}
\ud {&#x0d;}
\ue {}
\uf {}
\u10 {}
\u11 {}
\u12 {}
\u13 {}
\u14 {}
\u15 {}
\u16 {}
\u17 {}
\u18 {}
\u19 {}
\u1a {}
\u1b {}
\u1c {}
\u1d {}
\u1e {}
\u1f {}
} $str]
return $result
}
proc make_nodes {path result indent} {
if {[hpropexists $path "control"]} {
set value [hgetpropval $path "control"]
if {[string compare -nocase $value "false"] == 0} {
return $result
}
}
set nodename [file tail $path];
set type [getdataType $path]
set prefix [string repeat " " $indent]
set newIndent [expr $indent + 2]
append result "$prefix<component id=\"$nodename\" dataType=\"$type\">\n"
if {[string compare -nocase $type "none"] != 0} {
if [ catch {
set value [encode [hval $path]]
} message ] {
set value "HVAL_ERROR:${message}"
}
append result "$prefix <value>$value</value>\n"
}
foreach p [property_elements $path $newIndent] {
append result $p
}
foreach x [lsort [hlist $path]] {
set result [make_nodes [string map {// /} "$path/$x"] $result $newIndent]
}
append result "$prefix</component>\n"
return $result
}
proc property_elements {path indent} {
set prefix [string repeat " " $indent]
foreach {key} [lsort [hlistprop $path tclnames]] {
if {[string compare -nocase $key "control"] == 0} {continue}
set value [encode [hgetpropval $path $key]]
lappend proplist "$prefix<property id=\"$key\">\n"
if {[string compare -nocase $key "help"] == 0} {
lappend proplist "$prefix <value>$value</value>\n"
} else {
foreach v [split $value ,] {
lappend proplist "$prefix <value>$v</value>\n"
}
}
lappend proplist "$prefix</property>\n"
}
if [info exists proplist] {return $proplist}
}
proc getgumtreexml {path} {
append result "<?xml version = \"1.0\" encoding = \"UTF-8\"?>\n"
append result "<hipadaba:SICS xmlns:hipadaba=\"http://www.psi.ch/sics/hipadaba\" >\n"
if {[string compare $path "/" ] == 0} {
foreach n [lsort [hlist $path]] {
set result [make_nodes $n $result 2]
}
} else {
set result [make_nodes $path $result 2]
}
append result "</hipadaba:SICS>\n"
}
proc make_value_nodes {path result indent} {
if {[hpropexists $path "control"]} {
set value [hgetpropval $path "control"]
if {[string compare -nocase $value "false"] == 0} {
return $result
}
}
set nodename [file tail $path];
set type [getdataType $path]
set prefix [string repeat " " $indent]
set newIndent [expr $indent + 2]
append result "$prefix<component id=\"$nodename\" dataType=\"$type\">\n"
if {[string compare -nocase $type "none"] != 0} {
if [ catch {
set value [encode [hval $path]]
} message ] {
set value "HVAL_ERROR:${message}"
}
append result "$prefix <value>$value</value>\n"
}
foreach x [lsort [hlist $path]] {
set result [make_value_nodes [string map {// /} "$path/$x"] $result $newIndent]
}
append result "$prefix</component>\n"
return $result
}
proc getgumtreexmlvalues {path} {
append result "<?xml version = \"1.0\" encoding = \"UTF-8\"?>\n"
append result "<hipadaba:SICS xmlns:hipadaba=\"http://www.psi.ch/sics/hipadaba\" >\n"
if {[string compare $path "/" ] == 0} {
foreach n [lsort [hlist $path]] {
set result [make_value_nodes $n $result 2]
}
} else {
set result [make_value_nodes $path $result 2]
}
append result "</hipadaba:SICS>\n"
}
if {[info exists guminit] == 0} {
set guminit 1
Publish getgumtreexml Spy
Publish getgumtreexmlvalues Spy
}