/**
* Compiles a var file and calls write_template_file
*/
function compile_var_file($filename)
{
    $destfile = resolve_template_compiled_file_name($filename, TMPL_IMPORT);
    if (!($sourcefile = resolve_template_source_file_name($filename))) {
        error('MISSINGFILE2', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('srcfile' => $filename));
    }
    $text = serialize(parse_var_file($sourcefile));
    write_template_file($destfile, $text);
}
/**
* Compiles a template file. Uses the file scheme to location the source,
* instantiates the code_writer and root_compiler_component (as the root) component then
* instantiates the source_file_parser to parse the template.
* Creates the initialize and render functions in the compiled template.
* 
* @see root_compiler_component
* @see code_writer
* @see source_file_parser
* @param string $ name of source template
* @return void 
*/
function compile_template_file($filename, $resolve_path = true)
{
	global $tag_dictionary;
	
	if($resolve_path)
	{
		if(!$sourcefile = resolve_template_source_file_name($filename))
			error('template file not found', 
						__FILE__ . ' : ' . __LINE__ . ' : ' .  __FUNCTION__, 
						array('file' => $filename));
	}
	else
		$sourcefile = $filename;
		
	$destfile = resolve_template_compiled_file_name($sourcefile, TMPL_INCLUDE);
	
	if (empty($sourcefile))
	{
		error('MISSINGFILE2', __FILE__ . ' : ' . __LINE__ . ' : ' .  __FUNCTION__, array('srcfile' => $filename));
	} 

	$code =& new codewriter();
	$code->set_function_prefix(md5($destfile));

	$tree =& new root_compiler_component();
	$tree->source_file = $sourcefile;

	$sfp =& new source_file_parser($sourcefile, $tag_dictionary);
	$sfp->parse($tree);
	
	$tree->prepare();

	$render_function = $code->begin_function('(&$dataspace)');
	$tree->generate($code);
	$code->end_function();

	$construct_function = $code->begin_function('(&$dataspace)');
	$tree->generate_constructor($code);
	$code->end_function();

	$code->write_php('$GLOBALS[\'template_render\'][$this->codefile] = \'' . $render_function . '\';');
	$code->write_php('$GLOBALS[\'template_construct\'][$this->codefile] = \'' . $construct_function . '\';');

	write_template_file($destfile, $code->get_code());
}