//===========================================================================//
// File:        rp4lbe4.cc                                                          //
// Project: MUNGA           Brick: Red Planet LBE Application                                     //
// Contents:                                                                                                                                                                      //
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
//                                                                                                                                                                                                //
//---------------------------------------------------------------------------//
// Copyright (C) 1994, Virtual World Entertainment, Inc.                     //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//

#include <rpl4.hpp>
#pragma hdrstop

#if !defined(RPTOOL_HPP)
#	include <rptool.hpp>
#endif

#if !defined(RPL4MODE_HPP)
#	include <rpl4mode.hpp>
#endif

#if !defined(L4TOOL_HPP)
#	include <l4tool.hpp>
#endif

#if !defined(RPL4VER_HPP)
#	include <rpl4ver.hpp>
#endif


class RPL4Tool:
public L4Tool
{
public:
	RPL4Tool();
	~RPL4Tool();

	Logical
		ConvertStringToModeMask(
			const char *string,
			ModeMask *returned_value_ptr
	);

protected:
	RPL4ModeManager
		*modeManager;
};

//----------------------------------------------------------------------
RPL4Tool::RPL4Tool() :
	L4Tool()
{
	Check_Pointer(this);

	modeManager = new RPL4ModeManager(RPL4ModeManager::ModeInitial);
	Register_Object(modeManager);

//	gaugeAlarmManager = new RPL4GaugeAlarmManager();
//	Register_Object(gaugeAlarmManager);
	Check_Fpu();
}

//----------------------------------------------------------------------
RPL4Tool::~RPL4Tool()
{
//	Check(this);
//	Unregister_Object(gaugeAlarmManager);
//	delete gaugeAlarmManager;
//	gaugeAlarmManager = NULL;

	Unregister_Object(modeManager);
	delete modeManager;
	modeManager = NULL;
	Check_Fpu();
}

//----------------------------------------------------------------------
Logical
	RPL4Tool::ConvertStringToModeMask(
		const char *name,
		ModeMask *returned_value
	)
{
//	Check(this);

	Check_Pointer(name); 
	Check_Pointer(returned_value); 
	Check(modeManager);

	Check_Fpu();
	return modeManager->ModeStringLookup(name, returned_value);
}

//##########################################################################
//##################    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";
		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";
			goto Usage;
		}
	}

	Stop_Registering();
	return status;
}

