global env
global scrib_lib_server_running

set icem_scrib ""
set port_start ""
set port_end ""

set icem_acn ""
#
#
#
puts "$argv"
foreach {n v} $argv {
    if {"-" != [string range $n 0 0]} {
	puts "Warning: cannot interpret tag \"$n\" in setting up scrib server!"
	continue
    }
    set [string range $n 1 end] $v
}
#
#
#
if {![info exists env(ICEM_SCRIB)] || ("" == $env(ICEM_SCRIB))} {
    if {"" != $icem_scrib} {
	set env(ICEM_SCRIB) $icem_scrib
    } else {
	puts "Error: cannot setup scrib_server without environment variable ICEM_SCRIB!"
	return
    }
}
#
#
#
set req_files [list scribserver]
foreach f $req_files {
    set file [file join $env(ICEM_SCRIB) server scribserver.tcl]
    if ![file isfile $file] {
	puts "Error: could not find file $file to setup scrib_server"
	return
    }
    if [catch {source $file} res] {
	puts "Error: $res"
	return
    }
}
#
# 
#
scrib_server_open_port $port_start

#vwait scrib_lib_server_running ... hmmm...

puts "scrib_server: ready for commands (type \"help\" for scrib_server comamnds)"

while { 1 } {
    puts -nonewline "\nscrib_server>"
    set line [ gets stdin ]
    catch { eval $line } res
    puts -nonewline "$res"
}
