2022-01-10 01:20:44 +01:00
|
|
|
//=============================================================================//
|
|
|
|
//
|
|
|
|
// Purpose: Command line utilities
|
|
|
|
//
|
|
|
|
//=============================================================================//
|
|
|
|
|
|
|
|
#include "core/stdafx.h"
|
|
|
|
#include "tier0/commandline.h"
|
2022-04-09 16:16:40 +02:00
|
|
|
#include "tier1/cvar.h"
|
2022-01-10 01:20:44 +01:00
|
|
|
|
2022-06-24 12:10:46 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
CCommandLine::CCommandLine(void)
|
|
|
|
{
|
|
|
|
m_pszCmdLine = NULL;
|
|
|
|
m_nParmCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
CCommandLine::~CCommandLine(void)
|
|
|
|
{
|
|
|
|
CleanUpParms();
|
|
|
|
delete[] m_pszCmdLine;
|
|
|
|
}
|
|
|
|
|
2022-01-10 01:20:44 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: Create a command line from the passed in string
|
2022-01-23 18:33:01 +01:00
|
|
|
// Note that if you pass in a @filename, then the routine will read settings
|
|
|
|
// from a file instead of the command line
|
2022-01-10 01:20:44 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void CCommandLine::CreateCmdLine(const char* pszCommandline)
|
|
|
|
{
|
2022-01-23 18:26:48 +01:00
|
|
|
static int index = 0;
|
|
|
|
CallVFunc<void>(index, this, pszCommandline);
|
2022-01-10 01:20:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-01-23 18:26:48 +01:00
|
|
|
// Purpose: creates a command line from the arguments passed in
|
2022-01-10 01:20:44 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void CCommandLine::CreateCmdLine(int argc, char** argv)
|
|
|
|
{
|
2022-01-23 18:26:48 +01:00
|
|
|
static int index = 1;
|
|
|
|
CallVFunc<void>(index, this, argc, argv);
|
2022-01-10 01:20:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-01-23 18:26:48 +01:00
|
|
|
// Purpose: allocates a pool for the command line [seems unused]
|
2022-01-10 01:20:44 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void CCommandLine::CreatePool(void* pMem)
|
|
|
|
{
|
2022-01-23 18:26:48 +01:00
|
|
|
static int index = 2;
|
|
|
|
CallVFunc<void>(index, this, pMem);
|
2022-01-10 01:20:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: Return current command line
|
|
|
|
// Output : const char
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
const char* CCommandLine::GetCmdLine(void)
|
|
|
|
{
|
2022-01-23 18:26:48 +01:00
|
|
|
static int index = 3;
|
|
|
|
return CallVFunc<const char*>(index, this);
|
2022-01-10 01:20:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: Search for the parameter in the current commandline
|
|
|
|
// Input : *psz -
|
|
|
|
// **ppszValue -
|
|
|
|
// Output : char
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
const char* CCommandLine::CheckParm(const char* psz, const char** ppszValue)
|
|
|
|
{
|
2022-01-23 18:26:48 +01:00
|
|
|
static int index = 4;
|
|
|
|
return CallVFunc<const char*>(index, this, psz, ppszValue);
|
2022-01-10 01:20:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: Remove specified string ( and any args attached to it ) from command line
|
|
|
|
// Input : *pszParm -
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-01-23 18:26:48 +01:00
|
|
|
void CCommandLine::RemoveParm(const char* pszParm)
|
2022-01-10 01:20:44 +01:00
|
|
|
{
|
2022-01-23 18:26:48 +01:00
|
|
|
static int index = 5;
|
|
|
|
CallVFunc<void>(index, this, pszParm);
|
2022-01-10 01:20:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: Append parameter and argument values to command line
|
|
|
|
// Input : *pszParm -
|
|
|
|
// *pszValues -
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void CCommandLine::AppendParm(const char* pszParm, const char* pszValues)
|
|
|
|
{
|
2022-01-23 18:26:48 +01:00
|
|
|
static int index = 6;
|
|
|
|
CallVFunc<void>(index, this, pszParm, pszValues);
|
2022-01-10 01:20:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-02-13 15:16:09 +01:00
|
|
|
// Purpose: returns the argument after the one specified, or the default if not found
|
2022-01-10 01:20:44 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-06-24 02:42:28 +02:00
|
|
|
float CCommandLine::ParmValue(const char* psz, float flDefaultVal)
|
2022-01-10 01:20:44 +01:00
|
|
|
{
|
2022-01-23 18:26:48 +01:00
|
|
|
static int index = 7;
|
2022-06-24 02:42:28 +02:00
|
|
|
return CallVFunc<float>(index, this, psz, flDefaultVal);
|
2022-01-10 01:20:44 +01:00
|
|
|
}
|
|
|
|
int CCommandLine::ParmValue(const char* psz, int nDefaultVal)
|
|
|
|
{
|
2022-01-23 18:26:48 +01:00
|
|
|
static int index = 8;
|
|
|
|
return CallVFunc<int>(index, this, psz, nDefaultVal);
|
2022-01-10 01:20:44 +01:00
|
|
|
}
|
2022-06-24 02:42:28 +02:00
|
|
|
const char* CCommandLine::ParmValue(const char* psz, const char* pDefaultVal)
|
2022-01-10 01:20:44 +01:00
|
|
|
{
|
2022-01-23 18:26:48 +01:00
|
|
|
static int index = 9;
|
2022-06-24 02:42:28 +02:00
|
|
|
return CallVFunc<const char*>(index, this, psz, pDefaultVal);
|
2022-01-10 01:20:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-01-23 18:26:48 +01:00
|
|
|
// Purpose: returns individual command line arguments
|
2022-01-10 01:20:44 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
int CCommandLine::ParmCount(void)
|
|
|
|
{
|
2022-01-23 18:26:48 +01:00
|
|
|
static int index = 10;
|
|
|
|
return CallVFunc<int>(index, this);
|
2022-01-10 01:20:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int CCommandLine::FindParm(const char* psz)
|
|
|
|
{
|
2022-01-23 18:26:48 +01:00
|
|
|
static int index = 11;
|
|
|
|
return CallVFunc<int>(index, this, psz);
|
2022-01-10 01:20:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* CCommandLine::GetParm(int nIndex)
|
|
|
|
{
|
2022-01-23 18:26:48 +01:00
|
|
|
static int index = 12;
|
|
|
|
return CallVFunc<const char*>(index, this, nIndex);
|
2022-01-10 01:20:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCommandLine::SetParm(int nIndex, char const* pParm)
|
|
|
|
{
|
2022-04-16 00:30:46 +02:00
|
|
|
static int index = 14;
|
2022-01-23 18:26:48 +01:00
|
|
|
CallVFunc<void>(index, this, nIndex, pParm);
|
2022-01-10 01:20:44 +01:00
|
|
|
}
|
|
|
|
|
2022-06-24 12:10:46 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Individual command line arguments
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void CCommandLine::CleanUpParms(void)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < m_nParmCount; ++i)
|
|
|
|
{
|
|
|
|
delete[] m_ppParms[i];
|
|
|
|
m_ppParms[i] = NULL;
|
|
|
|
}
|
|
|
|
m_nParmCount = 0;
|
|
|
|
}
|
2022-04-16 00:30:46 +02:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Instance singleton and expose interface to rest of code
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
CCommandLine* CommandLine(void)
|
|
|
|
{
|
|
|
|
return g_pCmdLine;
|
|
|
|
}
|
2022-06-24 12:10:46 +02:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
CCommandLine* g_pCmdLine = nullptr;
|