Removed the virtual Settings::usage() method from the SettingsUNIX

and SettingsWin32 classes, since they both did the same thing, and
placed the method in the Settings class itself (ifdef'ed out for
OSX).  It was done this way when core was still in flux and each port
didn't support all the same options.  Since the core is now unified,
it didn't make sense to have a separate usage() method for each port.

Added the '-listrominfo' argument (can only be called from the commandline,
not set with the INI file).  This returns selected info from the stella.pro
file and exits immediately.  It returns data in the form of:

   # of roms (first line)
   MD5|Name|Rarity|Manufacturer|Note (# of roms lines) ...

This makes it much easier for GUI frontends to interface with Stella,
since all stella.pro parsing is now done within Stella itself.

Added various print() methods to Properties and PropertiesSet to
facilitate the above '-listrominfo' argument.

Fixed a bug in PropertiesSet::size(); it always returned 0.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@295 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2004-07-05 00:53:48 +00:00
parent 3496d66495
commit d77a84297b
11 changed files with 178 additions and 179 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: mainSDL.cxx,v 1.9 2004-06-28 23:16:24 stephena Exp $
// $Id: mainSDL.cxx,v 1.10 2004-07-05 00:53:48 stephena Exp $
//============================================================================
#include <fstream>
@ -61,7 +61,7 @@ static void cleanup();
static bool setupJoystick();
static void handleEvents();
static uInt32 getTicks();
static bool setupProperties(PropertiesSet& set);
static void setupProperties(PropertiesSet& set);
#ifdef JOYSTICK_SUPPORT
// static uInt32 thePaddleNumber;
@ -705,49 +705,38 @@ void handleEvents()
/**
Setup the properties set by first checking for a user file
"$HOME/.stella/stella.pro", then a system-wide file "/etc/stella.pro".
Return false if neither file is found, else return true.
@param set The properties set to setup
Setup the properties set by first checking for a user file,
then a system-wide file.
*/
bool setupProperties(PropertiesSet& set)
void setupProperties(PropertiesSet& set)
{
bool useMemList = false;
string theAlternateProFile = theSettings->getString("altpro");
string theUserProFile = theSettings->userPropertiesFilename();
string theSystemProFile = theSettings->systemPropertiesFilename();
// When 'listroms' is specified, we need to have the full list in memory
if(theSettings->getBool("listrominfo"))
useMemList = true;
#ifdef DEVELOPER_SUPPORT
// If the user wishes to merge any property modifications to the
// PropertiesSet file, then the PropertiesSet file MUST be loaded
// into memory.
// If 'useMemList' is true, do not override it
if(!useMemList)
useMemList = theSettings->getBool("mergeprops");
#endif
// Check to see if the user has specified an alternate .pro file.
if(theAlternateProFile != "")
{
set.load(theAlternateProFile, &Console::defaultProperties(), useMemList);
return true;
}
if(theUserProFile != "")
{
else if(theUserProFile != "")
set.load(theUserProFile, &Console::defaultProperties(), useMemList);
return true;
}
else if(theSystemProFile != "")
{
set.load(theSystemProFile, &Console::defaultProperties(), useMemList);
return true;
}
else
{
set.load("", &Console::defaultProperties(), false);
return true;
}
}
@ -804,8 +793,19 @@ int main(int argc, char* argv[])
// Take care of commandline arguments
if(!theSettings->loadCommandLine(argc, argv))
{
string message = "Stella version 1.4_cvs\n\nUsage: stella [options ...] romfile";
theSettings->usage(message);
cleanup();
return 0;
}
// Create a properties set for us to use and set it up
PropertiesSet propertiesSet;
setupProperties(propertiesSet);
// Check to see if the 'listroms' argument was given
// If so, list the roms and immediately exit
if(theSettings->getBool("listrominfo"))
{
propertiesSet.print();
cleanup();
return 0;
}
@ -827,8 +827,6 @@ int main(int argc, char* argv[])
if(!in)
{
cerr << "ERROR: Couldn't open " << file << "..." << endl;
string message = "Stella version 1.4_cvs\n\nUsage: stella [options ...] romfile";
theSettings->usage(message);
cleanup();
return 0;
}
@ -838,15 +836,6 @@ int main(int argc, char* argv[])
uInt32 size = in.gcount();
in.close();
// Create a properties set for us to use and set it up
PropertiesSet propertiesSet;
if(!setupProperties(propertiesSet))
{
delete[] image;
cleanup();
return 0;
}
// Create an SDL window
string videodriver = theSettings->getString("video");
if(videodriver == "soft")

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Props.cxx,v 1.4 2002-11-11 02:49:02 stephena Exp $
// $Id: Props.cxx,v 1.5 2004-07-05 00:53:48 stephena Exp $
//============================================================================
#include "Props.hxx"
@ -278,3 +278,15 @@ void Properties::merge(const Properties& properties)
}
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Properties::print()
{
cout << "|"
<< get("Cartridge.MD5") << "|"
<< get("Cartridge.Name") << "|"
<< get("Cartridge.Rarity") << "|"
<< get("Cartridge.Manufactuer") << "|"
<< get("Cartridge.Note") << "|"
<< endl;
}

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Props.hxx,v 1.3 2002-11-09 23:29:51 stephena Exp $
// $Id: Props.hxx,v 1.4 2004-07-05 00:53:48 stephena Exp $
//============================================================================
#ifndef PROPERTIES_HXX
@ -30,7 +30,7 @@
if the property key is not found in the original property list.
@author Bradford W. Mott
@version $Id: Props.hxx,v 1.3 2002-11-09 23:29:51 stephena Exp $
@version $Id: Props.hxx,v 1.4 2004-07-05 00:53:48 stephena Exp $
*/
class Properties
{
@ -95,6 +95,11 @@ class Properties
*/
void merge(const Properties& properties);
/**
Print the attributes of this properties object
*/
void print();
public:
/**
Read the next quoted string from the specified input stream

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: PropsSet.cxx,v 1.6 2002-11-11 02:52:02 stephena Exp $
// $Id: PropsSet.cxx,v 1.7 2004-07-05 00:53:48 stephena Exp $
//============================================================================
#include <assert.h>
@ -152,6 +152,8 @@ void PropertiesSet::insertNode(TreeNode* &t, const Properties& properties)
t->props = new Properties(properties);
t->left = 0;
t->right = 0;
++mySize;
}
}
@ -208,6 +210,12 @@ void PropertiesSet::save(ostream& out)
saveNode(out, myRoot);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PropertiesSet::print()
{
cout << size() << endl;
printNode(myRoot);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PropertiesSet::saveNode(ostream& out, TreeNode *node)
@ -220,6 +228,17 @@ void PropertiesSet::saveNode(ostream& out, TreeNode *node)
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PropertiesSet::printNode(TreeNode *node)
{
if(node)
{
node->props->print();
printNode(node->left);
printNode(node->right);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 PropertiesSet::size() const
{

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: PropsSet.hxx,v 1.4 2002-11-11 02:52:02 stephena Exp $
// $Id: PropsSet.hxx,v 1.5 2004-07-05 00:53:48 stephena Exp $
//============================================================================
#ifndef PROPERTIESSET_HXX
@ -84,6 +84,11 @@ class PropertiesSet
*/
uInt32 size() const;
/**
Prints the contents of the PropertiesSet as a flat file.
*/
void print();
/**
Merge the given properties into the collection.
@ -136,6 +141,13 @@ class PropertiesSet
*/
void saveNode(ostream& out, TreeNode *node);
/**
Prints the current node properties
@param node The current subroot of the tree
*/
void printNode(TreeNode *node);
// The root of the BST
TreeNode* myRoot;

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Settings.cxx,v 1.22 2004-06-27 22:44:04 stephena Exp $
// $Id: Settings.cxx,v 1.23 2004-07-05 00:53:48 stephena Exp $
//============================================================================
#include <cassert>
@ -132,14 +132,39 @@ bool Settings::loadCommandLine(Int32 argc, char** argv)
{
// Make sure we have the correct number of command line arguments
if(argc == 1)
{
usage();
return false;
}
for(Int32 i = 1; i < (argc - 1); ++i)
for(Int32 i = 1; i < argc; ++i)
{
// strip off the '-' character
string key = argv[i];
if(key[0] != '-')
return true; // stop processing here, ignore the remaining items
key = key.substr(1, key.length());
string value = argv[++i];
// Take care of the arguments which are meant to be executed immediately
// (and then Stella should exit)
if(key == "help")
{
usage();
return false;
}
else if(key == "listrominfo")
{
set(key, "true", false);
return true;
}
if(++i >= argc)
{
cerr << "Missing argument for '" << key << "'" << endl;
return false;
}
string value = argv[i];
// Settings read from the commandline must not be saved to
// the rc-file, unless they were previously set
@ -149,6 +174,59 @@ bool Settings::loadCommandLine(Int32 argc, char** argv)
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Settings::usage()
{
#ifndef MAC_OSX
cout << endl
<< "Stella version 1.4_cvs\n\nUsage: stella [options ...] romfile" << endl
<< endl
<< "Valid options are:" << endl
<< endl
<< " -video <type> Type is one of the following:\n"
<< " soft SDL software mode\n"
#ifdef DISPLAY_OPENGL
<< " gl SDL OpenGL mode\n"
<< endl
<< " -gl_filter <type> Type is one of the following:\n"
<< " nearest Normal scaling (GL_NEAREST)\n"
<< " linear Blurred scaling (GL_LINEAR)\n"
<< " -gl_aspect <number> Scale the width by the given amount\n"
<< " -gl_fsmax <0|1> Use the largest available screenmode in fullscreen OpenGL\n"
<< endl
#endif
<< " -sound <0|1> Enable sound generation\n"
<< " -fragsize <number> The size of sound fragments (must be a power of two)\n"
<< " -framerate <number> Display the given number of frames per second\n"
<< " -zoom <size> Makes window be 'size' times normal\n"
<< " -fullscreen <0|1> Play the game in fullscreen mode\n"
<< " -grabmouse <0|1> Keeps the mouse in the game window\n"
<< " -hidecursor <0|1> Hides the mouse cursor in the game window\n"
<< " -volume <number> Set the volume (0 - 100)\n"
<< " -paddle <0|1|2|3> Indicates which paddle the mouse should emulate\n"
<< " -altpro <props file> Use the given properties file instead of stella.pro\n"
<< " -showinfo <0|1> Shows some game info\n"
<< " -accurate <0|1> Accurate game timing (uses more CPU)\n"
#ifdef SNAPSHOT_SUPPORT
<< " -ssdir <path> The directory to save snapshot files to\n"
<< " -ssname <name> How to name the snapshot (romname or md5sum)\n"
<< " -sssingle <0|1> Generate single snapshot instead of many\n"
#endif
<< endl
#ifdef DEVELOPER_SUPPORT
<< " DEVELOPER options (see Stella manual for details)\n"
<< " -Dformat Sets \"Display.Format\"\n"
<< " -Dxstart Sets \"Display.XStart\"\n"
<< " -Dwidth Sets \"Display.Width\"\n"
<< " -Dystart Sets \"Display.YStart\"\n"
<< " -Dheight Sets \"Display.Height\"\n"
<< " -mergeprops <0|1> Merge changed properties into properties file,\n"
<< " or save into a separate file\n"
#endif
<< endl;
#endif
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Settings::saveConfig()
{

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Settings.hxx,v 1.13 2004-05-28 22:07:57 stephena Exp $
// $Id: Settings.hxx,v 1.14 2004-07-05 00:53:48 stephena Exp $
//============================================================================
#ifndef SETTINGS_HXX
@ -30,7 +30,7 @@
This class provides an interface for accessing frontend specific settings.
@author Stephen Anthony
@version $Id: Settings.hxx,v 1.13 2004-05-28 22:07:57 stephena Exp $
@version $Id: Settings.hxx,v 1.14 2004-07-05 00:53:48 stephena Exp $
*/
class Settings
{
@ -58,9 +58,16 @@ class Settings
/**
This method should be called to load the arguments from the commandline.
@return False on any errors, otherwise true
*/
bool loadCommandLine(Int32 argc, char** argv);
/**
This method should be called to display usage information.
*/
void usage();
/**
Get the value assigned to the specified key. If the key does
not exist then -1 is returned.
@ -159,13 +166,6 @@ class Settings
*/
virtual bool fileExists(const string& filename) = 0;
/**
This method should be called to display usage information.
@param message A short message about this version of Stella
*/
virtual void usage(string& message) = 0;
public:
/**
This method should be called to get the filename of the users'

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: SettingsUNIX.cxx,v 1.5 2004-07-04 15:16:22 stephena Exp $
// $Id: SettingsUNIX.cxx,v 1.6 2004-07-05 00:53:48 stephena Exp $
//============================================================================
#include <cstdlib>
@ -63,57 +63,6 @@ SettingsUNIX::~SettingsUNIX()
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SettingsUNIX::usage(string& message)
{
cout << endl
<< message << endl
<< endl
<< "Valid options are:" << endl
<< endl
<< " -video <type> Type is one of the following:\n"
<< " soft SDL software mode\n"
#ifdef DISPLAY_OPENGL
<< " gl SDL OpenGL mode\n"
<< endl
<< " -gl_filter <type> Type is one of the following:\n"
<< " nearest Normal scaling (GL_NEAREST)\n"
<< " linear Blurred scaling (GL_LINEAR)\n"
<< " -gl_aspect <number> Scale the width by the given amount\n"
<< " -gl_fsmax <0|1> Use the largest available screenmode in fullscreen OpenGL\n"
<< endl
#endif
<< " -sound <0|1> Enable sound generation\n"
<< " -fragsize <number> The size of sound fragments (must be a power of two)\n"
<< " -framerate <number> Display the given number of frames per second\n"
<< " -zoom <size> Makes window be 'size' times normal\n"
<< " -fullscreen <0|1> Play the game in fullscreen mode\n"
<< " -grabmouse <0|1> Keeps the mouse in the game window\n"
<< " -hidecursor <0|1> Hides the mouse cursor in the game window\n"
<< " -volume <number> Set the volume (0 - 100)\n"
<< " -paddle <0|1|2|3> Indicates which paddle the mouse should emulate\n"
<< " -altpro <props file> Use the given properties file instead of stella.pro\n"
<< " -showinfo <0|1> Shows some game info\n"
<< " -accurate <0|1> Accurate game timing (uses more CPU)\n"
#ifdef SNAPSHOT_SUPPORT
<< " -ssdir <path> The directory to save snapshot files to\n"
<< " -ssname <name> How to name the snapshot (romname or md5sum)\n"
<< " -sssingle <0|1> Generate single snapshot instead of many\n"
#endif
<< endl
#ifdef DEVELOPER_SUPPORT
<< " DEVELOPER options (see Stella manual for details)\n"
<< " -Dformat Sets \"Display.Format\"\n"
<< " -Dxstart Sets \"Display.XStart\"\n"
<< " -Dwidth Sets \"Display.Width\"\n"
<< " -Dystart Sets \"Display.YStart\"\n"
<< " -Dheight Sets \"Display.Height\"\n"
<< " -mergeprops <0|1> Merge changed properties into properties file,\n"
<< " or save into a separate file\n"
#endif
<< endl;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string SettingsUNIX::stateFilename(const string& md5, uInt32 state)
{

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: SettingsUNIX.hxx,v 1.2 2004-05-28 22:07:57 stephena Exp $
// $Id: SettingsUNIX.hxx,v 1.3 2004-07-05 00:53:48 stephena Exp $
//============================================================================
#ifndef SETTINGS_UNIX_HXX
@ -26,7 +26,7 @@
This class defines UNIX-like OS's (Linux) system specific settings.
@author Stephen Anthony
@version $Id: SettingsUNIX.hxx,v 1.2 2004-05-28 22:07:57 stephena Exp $
@version $Id: SettingsUNIX.hxx,v 1.3 2004-07-05 00:53:48 stephena Exp $
*/
class SettingsUNIX : public Settings
{
@ -62,13 +62,6 @@ class SettingsUNIX : public Settings
@return boolean representing whether or not the file exists
*/
virtual bool fileExists(const string& filename);
/**
Display the commandline settings for this UNIX version of Stella.
@param message A short message about this version of Stella
*/
virtual void usage(string& message);
};
#endif

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: SettingsWin32.cxx,v 1.7 2004-07-04 15:23:20 stephena Exp $
// $Id: SettingsWin32.cxx,v 1.8 2004-07-05 00:53:48 stephena Exp $
//============================================================================
#include <sstream>
@ -69,57 +69,6 @@ SettingsWin32::~SettingsWin32()
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SettingsWin32::usage(string& message)
{
cout << endl
<< message << endl
<< endl
<< "Valid options are:" << endl
<< endl
<< " -video <type> Type is one of the following:\n"
<< " soft SDL software mode\n"
#ifdef DISPLAY_OPENGL
<< " gl SDL OpenGL mode\n"
<< endl
<< " -gl_filter <type> Type is one of the following:\n"
<< " nearest Normal scaling (GL_NEAREST)\n"
<< " linear Blurred scaling (GL_LINEAR)\n"
<< " -gl_aspect <number> Scale the width by the given amount\n"
<< " -gl_fsmax <0|1> Use the largest available screenmode in fullscreen OpenGL\n"
<< endl
#endif
<< " -sound <0|1> Enable sound generation\n"
<< " -fragsize <number> The size of sound fragments (must be a power of two)\n"
<< " -framerate <number> Display the given number of frames per second\n"
<< " -zoom <size> Makes window be 'size' times normal\n"
<< " -fullscreen <0|1> Play the game in fullscreen mode\n"
<< " -grabmouse <0|1> Keeps the mouse in the game window\n"
<< " -hidecursor <0|1> Hides the mouse cursor in the game window\n"
<< " -volume <number> Set the volume (0 - 100)\n"
<< " -paddle <0|1|2|3> Indicates which paddle the mouse should emulate\n"
<< " -altpro <props file> Use the given properties file instead of stella.pro\n"
<< " -showinfo <0|1> Shows some game info\n"
<< " -accurate <0|1> Accurate game timing (uses more CPU)\n"
#ifdef SNAPSHOT_SUPPORT
<< " -ssdir <path> The directory to save snapshot files to\n"
<< " -ssname <name> How to name the snapshot (romname or md5sum)\n"
<< " -sssingle <0|1> Generate single snapshot instead of many\n"
#endif
<< endl
#ifdef DEVELOPER_SUPPORT
<< " DEVELOPER options (see Stella manual for details)\n"
<< " -Dformat Sets \"Display.Format\"\n"
<< " -Dxstart Sets \"Display.XStart\"\n"
<< " -Dwidth Sets \"Display.Width\"\n"
<< " -Dystart Sets \"Display.YStart\"\n"
<< " -Dheight Sets \"Display.Height\"\n"
<< " -mergeprops <0|1> Merge changed properties into properties file,\n"
<< " or save into a separate file\n"
#endif
<< endl;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string SettingsWin32::stateFilename(const string& md5, uInt32 state)
{

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: SettingsWin32.hxx,v 1.3 2004-05-28 23:16:26 stephena Exp $
// $Id: SettingsWin32.hxx,v 1.4 2004-07-05 00:53:48 stephena Exp $
//============================================================================
#ifndef SETTINGS_WIN32_HXX
@ -26,7 +26,7 @@
This class defines Windows system specific settings.
@author Stephen Anthony
@version $Id: SettingsWin32.hxx,v 1.3 2004-05-28 23:16:26 stephena Exp $
@version $Id: SettingsWin32.hxx,v 1.4 2004-07-05 00:53:48 stephena Exp $
*/
class SettingsWin32 : public Settings
{
@ -61,13 +61,6 @@ class SettingsWin32 : public Settings
@return boolean representing whether or not the file exists
*/
virtual bool fileExists(const string& filename);
/**
Display the commandline settings for this UNIX version of Stella.
@param message A short message about this version of Stella
*/
virtual void usage(string& message);
};
#endif