#! /usr/bin/env tclsh

namespace eval system {
	package require {ycl struct tree tree}

	package require {ycl proc}
	[yclprefix] proc alias aliases [yclprefix] proc aliases

	aliases  {
		{ycl proc} {
			imports
		}
	}


	proc new {filename args} {
		if {[file exists $filename]} {
			error [list {file already exists} $filename]
		}

		set tree [info cmdcount]_tree

		[yclprefix] struct tree tree .new $tree
		try {
			set res [$tree .init dbname $filename dbcreate 1]
		} finally {
			rename $tree {}
		}
		puts $res
	}


	proc node {filename node cmd args} {
		set tree [info cmdcount]_tree
		[yclprefix] struct tree tree .new $tree
		$tree .init dbname $filename
		try {
			set res [$tree node $cmd $node {*}$args]
		} finally {
			rename $tree {}
		}
		puts $res
	}

	imports [namespace parent] [namespace current] {
		new
		node
	}
}

