summaryrefslogtreecommitdiff
path: root/scripts/haltcl.in
blob: baf9353783fd8718945de6ad334b3179edc63623 (plain)
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
#!@TCLSH@
load @EMC2_TCL_LIB_DIR@/hal.so

proc parse_ini {filename} {
    set f [open $filename]

    while {[gets $f line] >= 0} {
        if {[regexp {^\[(.*)\]\s*$} $line _ section]} {
            # nothing
        } elseif {[regexp {^([^#]+?)\s*=\s*(.*?)\s*$} $line _  k v]} {
            upvar $section s
            lappend s([string trim $k]) $v
        }
    }

    close $f
}

if {   [llength $argv] > 0 \
    && (  ([lindex $argv 0] == "-i") || ([lindex $argv 0] == "-ini")  )} {
    parse_ini [lindex $argv 1]
    set argv [lrange $argv 2 end]
}

    
proc setp {p v} {
    set v [uplevel [list expr $v]]
    hal setp $p $v
}

proc sets {p v} {
    set v [uplevel [list expr $v]]
    hal sets $p $v
}

foreach c [hal --commands] {
    if {[info commands $c] == {}} {
        proc $c args "eval hal $c \$args"
    }
}

if {[llength $argv] == 0} {
    package require tclreadline
    namespace eval tclreadline {
      proc prompt1 {} {
        return "haltcl: "
      }
    }
    ::tclreadline::Loop
}

set filename [lindex $argv 0]
set argv [lindex $argv 1 end]

set result [source $filename]