Files
sics/site_ansto/instrument/gumxml.tcl
2014-05-19 11:03:19 +10:00

160 lines
4.1 KiB
Tcl

proc getdataType {path} {
return [lindex [split [hinfo $path] ,] 0]
}
proc encode {str} {
set result [string map -nocase {
"\"" {"}
{'} {'}
{<} {&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} {
set nodename [file tail $path];
set type [getdataType $path]
set prefix [string repeat " " $indent]
set newIndent [expr $indent + 2]
set control "true"
foreach {key rvalue} [string map {= " "} [hlistprop $path tcl]] {
set value [encode $rvalue]
if {[string compare -nocase $key "control"] == 0} {
if {[string compare -nocase $value "false"] == 0} {
set control "false"
}
}
}
if {"$control" == "true"} {
append result "$prefix<component id=\"$nodename\" dataType=\"$type\">\n"
if {[string compare -nocase $type "none"] != 0} {
set value [encode [hval $path]]
append result "$prefix <value>$value</value>\n"
}
foreach p [property_elements $path $newIndent] {
append result $p
}
foreach x [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 rvalue} [string map {= " "} [hlistprop $path tcl]] {
set value [encode $rvalue]
if {[string compare -nocase $key "control"] == 0} {continue}
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 [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} {
set nodename [file tail $path];
set type [getdataType $path]
set prefix [string repeat " " $indent]
set newIndent [expr $indent + 2]
set control "true"
if {[hpropexists $path "control"]} {
set value [encode [hgetpropval $path "control"]]
if {[string compare -nocase $value "false"] == 0} {
set control "false"
}
}
if {"$control" == "true"} {
append result "$prefix<component id=\"$nodename\" dataType=\"$type\">\n"
if {[string compare -nocase $type "none"] != 0} {
set value [encode [hval $path]]
append result "$prefix <value>$value</value>\n"
}
foreach x [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 [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
}