#include "SPARTA.h"
#include "time.h"
#include <sys/timeb.h>


int main( int argc, char ** argv )
{
	string argList;
	bool time = true;
	SPARTA sparta;

	if(argc == 1) {
		sparta.printSyntax();
	}

	for(int i = 1; i < argc; i++){
		argList+= (" ");
		argList+= (argv[i]);
	}

	vector<string> fields = GDB::split(" -", argList);


	map<string, string> argments;
	for(int i = 0; i < fields.size(); i++)
	{
		vector<string> temp;
		int pos = fields[i].find_first_of(' ');
		temp.push_back( fields[i].substr(0,pos) );
		temp.push_back( fields[i].substr(pos+1,fields[i].length()-pos-1 ));
		string arg = PDB::simplifyWhiteSpace(temp[1]);

		vector<string>::iterator it = find(sparta.argList.begin(), sparta.argList.end(), temp[0]);
		if( it == sparta.argList.end() ) //not an valid argument
		{
			cerr << "Invaid arg name -" << temp[0] << endl;
			exit(0);
		}
		
		if( temp[0] == "compile" ) arg = "true";
		else if( temp[0] == "notime" ) time = false;
		
		argments[ temp[0] ] = arg;

	}
	
	clock_t start, finish;
	start = clock();

	sparta.setArgs(argments);
	
	if( argments["compile"].length() > 0 )
		sparta.Compile();
	else
		sparta.runPredict();

	finish = clock();
	if( time )
    		cout << "\tRunning time: " << (float)(finish - start)/ CLOCKS_PER_SEC << " seconds" << endl;
}
