# Library functions for the Tcl XML interface
#
# File: ic_xml/lib/ic_xml_setup.tcl
#
# $Revision$ on $Date$
# 
# Copyright (c) 1993-2003 ICEM CFD Engineering
#
#---------------------------------------------------------------------

global env

namespace eval IcXml {
    
    variable _debug    0
    variable _lib_path ""
    
    namespace export ic_xml_*
    
    proc ::IcXml {args} { return [IcXml::_init $args] }    

    proc ic_xml_put {text {color black}} {
	if {"" != [info commands mess]} {
	    mess "$text\n" red
	} else {
	    puts $text
	}
    }
    
    proc ic_xml_err {text} {
	ic_xml_put "Error: $text" red
    }
    
    proc ic_xml_debug {text} {
	variable _debug
	if $_debug {
	    ic_xml_put "debug-->$text" green
	}
    }
    
    proc ic_xml_lib_path {} {
	variable _lib_path
	return "$_lib_path"
    }
    
    proc err {text}   { return [ic_xml_err   "IcXml: $text"] }
    proc debug {text} { return [ic_xml_debug "IcXml: $text"] }
}

## Set up Tcl XML interface etc

proc IcXml::_init {args} {
    
    set filelist {
	ic_xml_inter.tcl
	ic_xml_report.tcl
	testbench_report.tcl
	mesh_report.tcl	
	assembly_report.tcl
    }
    
    variable _lib_path
    set _lib_path [file dirname [info script]]
    
    foreach f $filelist {
	set file [file join $_lib_path $f]
	if [catch { uplevel \#0 "source {$file}" } res] {
	    err $res
	} else {
	    debug "sourced file $file: $res"
	}
    }
    #if {0 >= [namespace children ::IcXmlInter]} {
    #	ic_xml_put "namespace IcXmlInter seems not to have any children"
    #	return 1
    #}
    
    if [IcXmlInter::_init] {
	return 0
    } else {
	return 1
    }
}

if [IcXml] {
    err "could not set up XML scripting interface"
    return 1
}

return 0
