#!@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($k) $v
        }
    }

    close $f
}

if {[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]]
    puts "hal sets $p $v"
    hal sets $p $v
}

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


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

set result [source $filename]

