diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index ff66eb33ba..a8f3b4bfce 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -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" diff --git a/stepmania/src/NetworkSyncManager.cpp b/stepmania/src/NetworkSyncManager.cpp index bca7dace58..a2c1d52a58 100644 --- a/stepmania/src/NetworkSyncManager.cpp +++ b/stepmania/src/NetworkSyncManager.cpp @@ -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" diff --git a/stepmania/src/PrefsManager.cpp b/stepmania/src/PrefsManager.cpp index 4338c2f54e..c389c2a35b 100644 --- a/stepmania/src/PrefsManager.cpp +++ b/stepmania/src/PrefsManager.cpp @@ -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 diff --git a/stepmania/src/RageUtil.cpp b/stepmania/src/RageUtil.cpp index bbbf57e5b1..92076a1d30 100644 --- a/stepmania/src/RageUtil.cpp +++ b/stepmania/src/RageUtil.cpp @@ -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 diff --git a/stepmania/src/RageUtil.h b/stepmania/src/RageUtil.h index b465cd1908..a228b2b9fd 100644 --- a/stepmania/src/RageUtil.h +++ b/stepmania/src/RageUtil.h @@ -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 ); diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index 1fe57379b7..80bba3c73b 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -80,9 +80,6 @@ #define ZIPS_DIR "Packages/" -int g_argc = 0; -char **g_argv = NULL; - static bool g_bHasFocus = true; static Preference 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(); diff --git a/stepmania/src/StepMania.h b/stepmania/src/StepMania.h index 9f5eb6e3a6..cfe6c22557 100644 --- a/stepmania/src/StepMania.h +++ b/stepmania/src/StepMania.h @@ -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 ¶msOut ); diff --git a/stepmania/src/tests/test_misc.cpp b/stepmania/src/tests/test_misc.cpp index b6211a8663..6fc016dcea 100644 --- a/stepmania/src/tests/test_misc.cpp +++ b/stepmania/src/tests/test_misc.cpp @@ -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 )