#!/usr/bin/perl

use strict;
use warnings;
use Syntax::Kamelon::Debugger;

my $noindex = 0;
my $syntax;
my $xmldir;
my $file;
my $ifh = *STDIN;

while (@ARGV) {
	my $o = shift @ARGV;
	if ($o eq '-xmlfolder') {
		$xmldir = shift @ARGV;
	} elsif ($o eq '-syntax') {
		$syntax = shift @ARGV
	} elsif ($o eq '-file') {
		$file = shift @ARGV
	} elsif ($o eq '-noindex') {
		$noindex = 1
	} else {
		die "available options: -xmlfolder, -syntax, -file, -noindex";
	}
}

my @o = (noindex => $noindex);
if (defined $xmldir) {
	die "$xmldir folder does not exist" unless -e $xmldir;
	die "$xmldir is not a folder" unless -d $xmldir;
	push @o, 'xmlfolder', $xmldir;
}

if (defined $file) {
	die "File $file does not exist" unless -e $file;
	die "File $file is a folder" unless -f $file;
	die "Cannot open input $file" unless open($ifh, "<", $file);
}

die "Option -syntax must be specified" unless defined $syntax;

my $kam = Syntax::Kamelon::Debugger->new(@o);
$kam->Syntax($syntax);
$kam->SetTasks('step');

unless (open($ifh, "<", $file)) {  }

while (my $in = <$ifh>) {
	$kam->ParseRaw($in);
}

close $ihf;
