package l3config;

use Exporter;
use Getopt::Long;

@ISA = ('Exporter');
@EXPORT = qw(%Config &init_config);

our $Config_File = "labmaker.conf";
our %Config = (
		"skip_empty" 			=> 	"yes",
		"skip_interrupted" 		=>	"no",
		"skip_wrong" 			=>	"no",
		"editors"			=>	["vi", "pico", "ee", "vim"],
		"pagers"			=>	["more", "less", "zmore", "zless", "info", 
							"man", "mc", "trafshow", "screen", "cfdisk",
							"trafshow-bsd", "yes", "lynx", "links", "centericq"
							],
		"terminal"			=>	["mc"],
		"suppress_editors"		=>	"yes",
		"suppress_pagers"		=>	"yes",
		"suppress_terminal"		=>	"yes",

		"terminal_width"		=> 	100,
		"terminal_height"		=> 	100,
		"verbose"			=>	"yes",

		"head_lines"			=> 	5,
		"tail_lines"			=>	5,
		"cache_head_lines"			=> 	5,
		"cache_tail_lines"			=>	5,
		"skip_text"			=>	"...",
		"show_time"			=>	"yes",
		"show_diffs"			=>	"yes",
		"show_comments"			=>	"yes",

		"input"				=>	"/root/.labmaker",
		"diffs"				=>	"",
		"input_mask"			=>	"*.script",
		"encoding"			=> 	"utf-8",

		"cache"				=>	"/tmp/report.xml",
		"cache_stat"			=>	"/tmp/.report.dat",

		"output"			=>	"/tmp/report.html",
		#"output"			=>	"report.xml",
		"output_mask"			=>	"INDEX",
		"output_format"			=>	"html",
		"frontend_css"			=>	"/l3/l3.css",
		"frontend_google_ico"		=>	"/l3/google.ico",
		"frontend_linux_ico"		=>	"/l3/linux.ico",
		"frontend_freebsd_ico"		=>	"/l3/freebsd.ico",
		"frontend_opennet_ico"		=>	"/l3/opennet.ico",
		"frontend_local_ico"		=>	"/l3/freebsd.ico",

		"signature"			=>	"#lm:",
		"from"				=>	"",
		"to"				=>	"",
		"lab"				=>	"",
		"keywords"			=>	"linux command",
		"files_keywords"		=>	"linux file",
		
		comment_width			=>	"300",
		time_width			=>	"60",
		
		"mode"				=>	"daemon",		# daemon | normal
		"daemon_sleep_interval"		=>	"1",
		"detach"			=>	"yes",
		"agent_pidfile"			=> 	"$ENV{HOME}/.labmaker/l3-agent.pid",

		"backend_address"		=>	"127.0.0.1",
		"backend_port"			=> 	"18030",
		"backend_pidfile"		=> 	"/tmp/l3-backend.pid",
		"backend_datafile"		=> 	"/tmp/backend.xml",

		"l3-agent"			=>	"l3-agent", 
		"l3-backend"			=>	"l3-backend", 
		
		"course-name" => "", 
		"course-code" => "", 
		"course-date" => "", 
		"course-center" => "", 
		"course-trainer" => "", 
		"course-student" => "", 
		);

sub read_config_file
{
	my $config = $_[0];
	my $filename = $_[1];
	open(CONFIG, "$filename")
		or return;
	while (<CONFIG>) {
		s/#.*//;
		next if /^\s*$/;
		my ($var, $val) =  split /\s*=\s*/, $_, 2;
		$var =~ s/\s*//;
		$config->{$var} = $val;
	}
	close(CONFIG);
}


sub init_config
{
	my %argv_config;
	my %file_config;
	read_config_file(\%file_config, $Config_File);
	GetOptions(\%argv_config, map "$_=s", keys %Config);
	%Config = (%Config, %file_config, %argv_config);
}

