-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathhmscript.tcl
More file actions
executable file
·73 lines (59 loc) · 1.55 KB
/
Copy pathhmscript.tcl
File metadata and controls
executable file
·73 lines (59 loc) · 1.55 KB
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
##
# hmscript.tcl
# Ausführen von HomeMatic Script.
#
# Autor: Falk Werner
##
package require HomeMatic
proc hmscript {script {p_args -}} {
set _script_ ""
if { "-" != $p_args } then {
upvar $p_args args
foreach name [array names args] {
append _script_ "var $name = \"[hmscript_escapeString $args($name)]\";\n"
}
}
append _script_ $script
return [hmscript_run _script_]
}
##
# Führt ein HomeMatic Script aus und liefert das Ergebnis
##
proc hmscript_run { p_script } {
upvar $p_script script
if { ![catch {array set result [rega_script $script]}] } then {
return $result(STDOUT)
}
return ""
}
proc hmscript_runInline { script } {
if { ![catch {array set result [rega_script $script]}] } then {
return $result(STDOUT)
}
return ""
}
proc hmscript_runFromFile { filename {p_args -}} {
set script ""
if { "-" != $p_args } then {
upvar $p_args args
foreach name [array names args] {
append script "var $name = \"[hmscript_escapeString $args($name)]\";\n"
}
}
append script [file_load $filename]
return [hmscript_run script]
}
proc hmscript_escapeString { str } {
# Backslash MUST be escaped first, otherwise a backslash placed directly
# before a quote in user input would (after the quote is escaped to \")
# be read by ReGa as an escaped backslash, closing the string literal
# early and turning the rest of the input into executable HomeMatic Script.
return [string map {
"\\" "\\\\"
"\'" "\\\'"
"\"" "\\\""
"\n" "\\n"
"\r" "\\r"
"\t" "\\t"
} $str]
}