mirror of https://github.com/stella-emu/stella.git
Minor cleanup of the BSPF API, and fix bool warning from VS 2012.
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2789 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
c840bb9809
commit
45115d5754
|
@ -57,7 +57,7 @@
|
|||
typedef __int64 Int64;
|
||||
typedef unsigned __int64 uInt64;
|
||||
#else
|
||||
#error Update BSPF.hxx for datatypes
|
||||
#error Update src/common/bspf.hxx for datatypes
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -74,31 +74,12 @@
|
|||
using namespace std;
|
||||
|
||||
// Defines to help with path handling
|
||||
#if defined BSPF_UNIX
|
||||
#if (defined(BSPF_UNIX) || defined(BSPF_MAC_OSX))
|
||||
#define BSPF_PATH_SEPARATOR "/"
|
||||
#elif (defined(BSPF_DOS) || defined(BSPF_WIN32) || defined(BSPF_OS2))
|
||||
#define BSPF_PATH_SEPARATOR "\\"
|
||||
#elif defined BSPF_MAC_OSX
|
||||
#define BSPF_PATH_SEPARATOR "/"
|
||||
#elif defined BSPF_GP2X
|
||||
#define BSPF_PATH_SEPARATOR "/"
|
||||
#endif
|
||||
|
||||
// I wish Windows had a complete POSIX layer
|
||||
#if defined BSPF_WIN32 && !defined __GNUG__
|
||||
#define BSPF_strcasecmp _stricmp
|
||||
#define BSPF_strncasecmp _strnicmp
|
||||
#define BSPF_isblank(c) ((c == ' ') || (c == '\t'))
|
||||
#define BSPF_snprintf _snprintf
|
||||
#define BSPF_vsnprintf _vsnprintf
|
||||
#else
|
||||
#define HAVE_UNISTD_H // needed for building zlib
|
||||
#include <strings.h>
|
||||
#define BSPF_strcasecmp strcasecmp
|
||||
#define BSPF_strncasecmp strncasecmp
|
||||
#define BSPF_isblank(c) isblank(c)
|
||||
#define BSPF_snprintf snprintf
|
||||
#define BSPF_vsnprintf vsnprintf
|
||||
#error Update src/common/bspf.hxx for path separator
|
||||
#endif
|
||||
|
||||
// CPU architecture type
|
||||
|
@ -113,7 +94,22 @@ using namespace std;
|
|||
#define BSPF_ARCH "NOARCH"
|
||||
#endif
|
||||
|
||||
// I wish Windows had a complete POSIX layer
|
||||
#if defined BSPF_WIN32 && !defined __GNUG__
|
||||
#define BSPF_snprintf _snprintf
|
||||
#define BSPF_vsnprintf _vsnprintf
|
||||
#else
|
||||
#define HAVE_UNISTD_H // needed for building zlib
|
||||
#include <strings.h>
|
||||
#define BSPF_snprintf snprintf
|
||||
#define BSPF_vsnprintf vsnprintf
|
||||
#endif
|
||||
|
||||
static const string EmptyString("");
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Some convenience functions
|
||||
|
||||
template<typename T> inline void BSPF_swap(T& a, T& b) { T tmp = a; a = b; b = tmp; }
|
||||
template<typename T> inline T BSPF_abs (T x) { return (x>=0) ? x : -x; }
|
||||
template<typename T> inline T BSPF_min (T a, T b) { return (a<b) ? a : b; }
|
||||
|
@ -125,6 +121,33 @@ static bool BSPF_equalsIgnoreCaseChar(char ch1, char ch2)
|
|||
{
|
||||
return toupper((unsigned char)ch1) == toupper((unsigned char)ch2);
|
||||
}
|
||||
|
||||
// Compare two strings, ignoring case
|
||||
inline int BSPF_compareIgnoreCase(const string& s1, const string& s2)
|
||||
{
|
||||
#if defined WIN32 && !defined __GNUG__
|
||||
return _stricmp(s1.c_str(), s2.c_str());
|
||||
#else
|
||||
return strcasecmp(s1.c_str(), s2.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
// Test whether the first string starts with the second one (case insensitive)
|
||||
inline bool BSPF_startsWithIgnoreCase(const string& s1, const string& s2)
|
||||
{
|
||||
#if defined WIN32 && !defined __GNUG__
|
||||
return _strnicmp(s1.c_str(), s2.c_str(), s2.length()) == 0;
|
||||
#else
|
||||
return strncasecmp(s1.c_str(), s2.c_str(), s2.length()) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Test whether two strings are equal (case insensitive)
|
||||
inline bool BSPF_equalsIgnoreCase(const string& s1, const string& s2)
|
||||
{
|
||||
return BSPF_compareIgnoreCase(s1, s2) == 0;
|
||||
}
|
||||
|
||||
// Find location (if any) of the second string within the first,
|
||||
// starting from 'startpos' in the first string
|
||||
inline size_t BSPF_findIgnoreCase(const string& s1, const string& s2, int startpos = 0)
|
||||
|
@ -134,26 +157,6 @@ inline size_t BSPF_findIgnoreCase(const string& s1, const string& s2, int startp
|
|||
return pos == s1.end() ? string::npos : pos - (s1.begin()+startpos);
|
||||
}
|
||||
|
||||
// Test whether two strings are equal (case insensitive)
|
||||
inline bool BSPF_equalsIgnoreCase(const string& s1, const string& s2)
|
||||
{
|
||||
return BSPF_strcasecmp(s1.c_str(), s2.c_str()) == 0;
|
||||
}
|
||||
inline bool BSPF_equalsIgnoreCase(const char* s1, const char* s2)
|
||||
{
|
||||
return BSPF_strcasecmp(s1, s2) == 0;
|
||||
}
|
||||
|
||||
// Test whether the first string starts with the second one (case insensitive)
|
||||
inline bool BSPF_startsWithIgnoreCase(const string& s1, const string& s2)
|
||||
{
|
||||
return BSPF_strncasecmp(s1.c_str(), s2.c_str(), s2.length()) == 0;
|
||||
}
|
||||
inline bool BSPF_startsWithIgnoreCase(const char* s1, const char* s2)
|
||||
{
|
||||
return BSPF_strncasecmp(s1, s2, strlen(s2)) == 0;
|
||||
}
|
||||
|
||||
// Test whether the first string ends with the second one (case insensitive)
|
||||
inline bool BSPF_endsWithIgnoreCase(const string& s1, const string& s2)
|
||||
{
|
||||
|
@ -171,6 +174,4 @@ inline bool BSPF_containsIgnoreCase(const string& s1, const string& s2)
|
|||
return BSPF_findIgnoreCase(s1, s2) != string::npos;
|
||||
}
|
||||
|
||||
static const string EmptyString("");
|
||||
|
||||
#endif
|
||||
|
|
|
@ -737,12 +737,12 @@ void Debugger::getCompletions(const char* in, StringList& list) const
|
|||
for(iter = functions.begin(); iter != functions.end(); ++iter)
|
||||
{
|
||||
const char* l = iter->first.c_str();
|
||||
if(BSPF_strncasecmp(l, in, strlen(in)) == 0)
|
||||
if(BSPF_equalsIgnoreCase(l, in))
|
||||
list.push_back(l);
|
||||
}
|
||||
|
||||
for(int i = 0; pseudo_registers[i][0] != 0; ++i)
|
||||
if(BSPF_strncasecmp(pseudo_registers[i][0], in, strlen(in)) == 0)
|
||||
if(BSPF_equalsIgnoreCase(pseudo_registers[i][0], in))
|
||||
list.push_back(pseudo_registers[i][0]);
|
||||
}
|
||||
|
||||
|
|
|
@ -715,12 +715,12 @@ bool Cartridge::isProbablyEF(const uInt8* image, uInt32 size, const char*& type)
|
|||
// This signature is attributed to "RevEng" of AtariAge
|
||||
uInt8 efef[] = { 'E', 'F', 'E', 'F' };
|
||||
uInt8 efsc[] = { 'E', 'F', 'S', 'C' };
|
||||
if(searchForBytes(image+size-8, 8, efef, 4, 1) > 0)
|
||||
if(searchForBytes(image+size-8, 8, efef, 4, 1))
|
||||
{
|
||||
type = "EF";
|
||||
return true;
|
||||
}
|
||||
else if(searchForBytes(image+size-8, 8, efsc, 4, 1) > 0)
|
||||
else if(searchForBytes(image+size-8, 8, efsc, 4, 1))
|
||||
{
|
||||
type = "EFSC";
|
||||
return true;
|
||||
|
|
|
@ -105,7 +105,7 @@ class FilesystemNode
|
|||
if (isDirectory() != node.isDirectory())
|
||||
return isDirectory();
|
||||
|
||||
return BSPF_strcasecmp(getName().c_str(), node.getName().c_str()) < 0;
|
||||
return BSPF_compareIgnoreCase(getName(), node.getName()) < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,7 +114,7 @@ class FilesystemNode
|
|||
*/
|
||||
inline bool operator==(const FilesystemNode& node) const
|
||||
{
|
||||
return BSPF_strcasecmp(getName().c_str(), node.getName().c_str()) == 0;
|
||||
return BSPF_compareIgnoreCase(getName(), node.getName()) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -126,7 +126,7 @@ bool PropertiesSet::getMD5(const string& md5, Properties& properties,
|
|||
while(low <= high)
|
||||
{
|
||||
int i = (low + high) / 2;
|
||||
int cmp = BSPF_strncasecmp(md5.c_str(), DefProps[i][Cartridge_MD5], 32);
|
||||
int cmp = BSPF_compareIgnoreCase(md5, DefProps[i][Cartridge_MD5]);
|
||||
|
||||
if(cmp == 0) // found it
|
||||
{
|
||||
|
|
|
@ -271,8 +271,7 @@ bool ListWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
|
|||
int newSelectedItem = 0;
|
||||
for (StringList::const_iterator i = _list.begin(); i != _list.end(); ++i)
|
||||
{
|
||||
if(BSPF_strncasecmp((*i).c_str(), _quickSelectStr.c_str(),
|
||||
_quickSelectStr.length()) == 0)
|
||||
if(BSPF_startsWithIgnoreCase(*i, _quickSelectStr))
|
||||
{
|
||||
_selectedItem = newSelectedItem;
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue