/// @file standalonetester_main.cpp
/// Standalone tester file with int main(), useful for testing compressors
///  through commandline or interactively.
///
/// @remarks
/// The main procedure initializes a global OctaneCompressorManager object,
///  and either sends it commandline arguments as commands, or initiates
///  an interactive loop of executing commands from user.
///
/// @author mouser
/// @date   2003.07.29
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// application includes
#include "octanetester.hpp"
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// system includes
using namespace std;
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------
// default file which contains commands we will run on interactive startup
#define OCTANE_DEFAULTINIFILENAME "octane.ini"
//---------------------------------------------------------------------------



//---------------------------------------------------------------------------
int main(int argc,char **argv)
{
	// create an octane tester class
	OctaneTester octanetester;

	// if the default commandfile exists, run it
	octanetester.ExecuteCommandsFromFile(OCTANE_DEFAULTINIFILENAME,true);
	
	// parse commandline or enter an interactive test loop
	if (argc==1)
		{
		// no commandline arguments, so run it in an interactive test loop
		octanetester.TestLoop();
		}
	else
		{
		// parse the commandline arguments, which are just ; separated commands as described in Compressor.ShowHelp();
		string commandstr;
		bool runcommandnow=false;
		for (int curarg=1;curarg<argc;++curarg)
			{
			if (strcmp(argv[curarg],";")!=0)
				{
				// add word to current command
				if (commandstr.length()>0)
					commandstr+=" ";
				commandstr+=argv[curarg];
				// check and make sure there is no attached separator
				if (commandstr[commandstr.length()-1]==';')
					{
					// yes we found a separator ; attached to end of this command
					commandstr=commandstr.substr(0,commandstr.length()-1);
					runcommandnow=true;
					}
				// always run it when we hit the end
				if (curarg==argc-1)
					runcommandnow=true;
				}
			if (runcommandnow==true || strcmp(argv[curarg],";")==0)
				{
				// execute this command
				if (commandstr.length()>0)
					{
					cout << ">"<<commandstr<<endl;
					if (commandstr=="interactive")
						{
						// this is a commandline-only option that can force the system to go into interactive mode
						octanetester.TestLoop();
						}
					else
						{
						octanetester.ParseCommand(commandstr.c_str());
						}
					}
				commandstr="";
				runcommandnow=false;
				}
			}
		}

	// return success
	return 0;
}
//---------------------------------------------------------------------------
