move GetCommandlineArgument, g_argc and g_argv into RageUtil.cpp,

so tests don't have to duplicate stuff, and because PrefsManager
uses it
This commit is contained in:
Glenn Maynard
2005-11-22 21:18:43 +00:00
parent 100ce95f14
commit 90ad56522c
8 changed files with 59 additions and 56 deletions
-1
View File
@@ -25,7 +25,6 @@
#include "MemoryCardManager.h"
#include "StatsManager.h"
#include "GameConstantsAndTypes.h"
#include "StepMania.h"
#include "CommonMetrics.h"
#include "Actor.h"
#include "PlayerState.h"
-1
View File
@@ -31,7 +31,6 @@ int NetworkSyncManager::GetSMOnlineSalt() { return 0; }
#include "ezsockets.h"
#include "ProfileManager.h"
#include "RageLog.h"
#include "StepMania.h"
#include "ScreenManager.h"
#include "song.h"
#include "Course.h"
-1
View File
@@ -10,7 +10,6 @@
#include "Foreach.h"
#include "Preference.h"
#include "RageLog.h"
#include "StepMania.h"
const CString DEFAULTS_INI_PATH = "Data/Defaults.ini"; // these can be overridden
const CString PREFERENCES_INI_PATH = "Save/Preferences.ini"; // overlay on Defaults.ini, contains the user's choices
+51 -1
View File
@@ -687,6 +687,56 @@ CString GetFileNameWithoutExtension( const CString &sPath )
return sFName;
}
int g_argc = 0;
char **g_argv = NULL;
void SetCommandlineArguments( int argc, char **argv )
{
g_argc = argc;
g_argv = argv;
}
/*
* Search for the commandline argument given; eg. "test" searches for the
* option "--test". All commandline arguments are getopt_long style: --foo;
* short arguments (-x) are not supported. (These are not intended for
* common, general use, so having short options isn't currently needed.)
* If argument is non-NULL, accept an argument.
*/
bool GetCommandlineArgument( const CString &option, CString *argument, int iIndex )
{
const CString optstr = "--" + option;
for( int arg = 1; arg < g_argc; ++arg )
{
const CString CurArgument = g_argv[arg];
const size_t i = CurArgument.find( "=" );
CString CurOption = CurArgument.substr(0,i);
if( CurOption.CompareNoCase(optstr) )
continue; /* no match */
/* Found it. */
if( iIndex )
{
--iIndex;
continue;
}
if( argument )
{
if( i != CString::npos )
*argument = CurArgument.substr( i+1 );
else
*argument = "";
}
return true;
}
return false;
}
CString GetCwd()
{
#ifdef _XBOX
@@ -1878,7 +1928,7 @@ bool FileCopy( RageFileBasic &in, RageFileBasic &out, CString &sError, bool *bRe
}
/*
* Copyright (c) 2001-2004 Chris Danford, Glenn Maynard
* Copyright (c) 2001-2005 Chris Danford, Glenn Maynard
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
+5
View File
@@ -298,6 +298,11 @@ CString join( const CString &sDelimitor, CStringArray::const_iterator begin, CSt
CString GetCwd();
void SetCommandlineArguments( int argc, char **argv );
bool GetCommandlineArgument( const CString &option, CString *argument=NULL, int iIndex=0 );
extern int g_argc;
extern char **g_argv;
void CRC32( unsigned int &iCRC, const void *pBuffer, size_t iSize );
unsigned int GetHashForString( const CString &s );
unsigned int GetHashForFile( const CString &sPath );
+1 -44
View File
@@ -80,9 +80,6 @@
#define ZIPS_DIR "Packages/"
int g_argc = 0;
char **g_argv = NULL;
static bool g_bHasFocus = true;
static Preference<bool> g_bAllowMultipleInstances( "AllowMultipleInstances", false );
@@ -919,45 +916,6 @@ static void ApplyLogPreferences()
Checkpoints::LogCheckpoints( PREFSMAN->m_bLogCheckpoints );
}
/* Search for the commandline argument given; eg. "test" searches for
* the option "--test". All commandline arguments are getopt_long style:
* --foo; short arguments (-x) are not supported. (As commandline arguments
* are not intended for common, general use, having short options isn't
* needed.) If argument is non-NULL, accept an argument. */
bool GetCommandlineArgument( const CString &option, CString *argument, int iIndex )
{
const CString optstr = "--" + option;
for( int arg = 1; arg < g_argc; ++arg )
{
const CString CurArgument = g_argv[arg];
const size_t i = CurArgument.find( "=" );
CString CurOption = CurArgument.substr(0,i);
if( CurOption.CompareNoCase(optstr) )
continue; /* no match */
/* Found it. */
if( iIndex )
{
--iIndex;
continue;
}
if( argument )
{
if( i != CString::npos )
*argument = CurArgument.substr( i+1 );
else
*argument = "";
}
return true;
}
return false;
}
#ifdef _XBOX
void __cdecl main()
#else
@@ -969,8 +927,7 @@ int main(int argc, char* argv[])
char *argv[] = {"default.xbe"};
#endif
g_argc = argc;
g_argv = argv;
SetCommandlineArguments( argc, argv );
/* Set up arch hooks first. This may set up crash handling. */
HOOKS = MakeArchHooks();
-4
View File
@@ -22,10 +22,6 @@ CString SaveScreenshot( CString sDir, bool bSaveCompressed, bool bMakeSignature,
void InsertCoin( int iNum = 1, const RageTimer *pTime = NULL );
void InsertCredit();
extern int g_argc;
extern char **g_argv;
bool GetCommandlineArgument( const CString &option, CString *argument=NULL, int iIndex=0 );
struct VideoModeParams;
void GetPreferredVideoModeParams( VideoModeParams &paramsOut );
+2 -4
View File
@@ -3,6 +3,7 @@
#include "RageFileManager.h"
#include "RageLog.h"
#include "RageUtil.h"
#include "arch/arch.h"
#include "arch/ArchHooks/ArchHooks.h"
void ExitGame() { }
@@ -10,8 +11,6 @@ void ExitGame() { }
CString g_Driver = "dir", g_Root = ".";
CString argv0;
int g_argc = 0;
char **g_argv = NULL;
void HandleException( CString sErr )
{
@@ -20,8 +19,7 @@ void HandleException( CString sErr )
void test_handle_args( int argc, char *argv[] )
{
g_argc = argc;
g_argv = argv;
SetCommandlineArguments( argc, argv );
argv0 = argv[0];
while( 1 )