#include "rpl4.h"
#pragma hdrstop

#include <conio.h>
#include "..\rp\rptool.h"
#include "rpl4mode.h"
#include "..\munga_l4\l4tool.h"
#include "rpl4ver.h"

class RPL4Tool :
	public L4Tool
{
public:
	RPL4Tool() : L4Tool()
	{
		modeManager = new RPL4ModeManager(RPL4ModeManager::ModeInitial);
	}

	~RPL4Tool()
	{
		delete modeManager;
		modeManager = NULL;
	}

	Logical ConvertStringToModeMask(const char *name, ModeMask *returned_value_ptr)
	{
		return modeManager->ModeStringLookup(name, returned_value_ptr);
	}

protected:
	RPL4ModeManager *modeManager;
};

//##########################################################################
//##################    RP4L4Application Globals    ########################
//##########################################################################

extern const char* const ProgName;
const char* const ProgName = "rpl4tool";

//
//#############################################################################
// main
//#############################################################################
//
int main(int argc, char *argv[])
{
	int status;
	if (argc < 3)
	{
Usage:
		DEBUG_STREAM << "Building Usage: rpl4tool -b rpl4.bld [res2.bld]\n" << " Listing Usage: rpl4tool -l rpl4.res [res2.res ...]\n" << std::flush;
		status = 1;
	}
	else
	{
		RPL4Tool rpl4_tool;
		RPTool rp_l4_tool(&rpl4_tool);
		L4AudioCreateSymbols create_symbols;

		if (!strcmp(argv[1], "-b"))
		{
			status = rp_l4_tool.BuildResources(argc-1, &argv[1], create_symbols, MINOR_DATA_VERSION);
		}
		else if (!strcmp(argv[1], "-l"))
		{
			status = rp_l4_tool.ListResources(argc-1, &argv[1]);
		}
		else
		{
			DEBUG_STREAM << "Error: Unknown tool switch!\n" << std::flush;
			goto Usage;
		}
	}

	_getch();
	return status;
}
