Remove reliance on PSS_STYLE

This commit is contained in:
twinaphex 2013-01-19 10:22:57 +01:00
parent c2cc9e28a9
commit 6da3ddfcd6
4 changed files with 103 additions and 129 deletions

View File

@ -188,7 +188,7 @@ void retro_init()
#if defined(WANT_16BPP) && defined(FRONTEND_SUPPORTS_RGB565)
enum retro_pixel_format rgb565 = RETRO_PIXEL_FORMAT_RGB565;
if(environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &rgb565))
if (environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &rgb565))
fprintf(stderr, "Frontend supports RGB565 - will use that instead of XRGB1555.\n");
#endif
@ -249,20 +249,22 @@ bool retro_load_game(const struct retro_game_info *info)
void retro_unload_game()
{
if(game)
if (!game)
return;
MDFN_FlushGameCheats(0);
game->CloseGame();
if (game->name)
{
MDFN_FlushGameCheats(0);
game->CloseGame();
if(game->name)
{
free(game->name);
game->name=0;
}
MDFNMP_Kill();
game = NULL;
free(game->name);
game->name=0;
}
MDFNMP_Kill();
game = NULL;
}
static unsigned retro_devices[2];
@ -653,14 +655,14 @@ void retro_run()
spec.VideoFormatChanged = false;
spec.SoundFormatChanged = false;
if(memcmp(&last_pixel_format, &spec.surface->format, sizeof(MDFN_PixelFormat)))
if (memcmp(&last_pixel_format, &spec.surface->format, sizeof(MDFN_PixelFormat)))
{
spec.VideoFormatChanged = TRUE;
last_pixel_format = spec.surface->format;
}
if(spec.SoundRate != last_sound_rate)
if (spec.SoundRate != last_sound_rate)
{
spec.SoundFormatChanged = true;
last_sound_rate = spec.SoundRate;
@ -669,9 +671,9 @@ void retro_run()
curgame->Emulate(&spec);
#ifdef NEED_DEINTERLACER
if(spec.InterlaceOn)
if (spec.InterlaceOn)
{
if(!PrevInterlaced)
if (!PrevInterlaced)
deint.ClearState();
deint.Process(spec.surface, spec.DisplayRect, spec.LineWidths, spec.InterlaceField);

View File

@ -36,28 +36,19 @@ using namespace std;
// Really dumb, maybe we should use boost?
static bool IsAbsolutePath(const char *path)
{
#if PSS_STYLE==4
if(path[0] == ':')
#elif PSS_STYLE==1
if(path[0] == '/')
#else
if(path[0] == '\\'
#if PSS_STYLE!=3
|| path[0] == '/'
#endif
)
#endif
{
return(TRUE);
}
if (
#ifdef _WIN32
path[0] == '\\' ||
#endif
path[0] == '/'
)
return(TRUE);
#if defined(WIN32) || defined(DOS)
if((path[0] >= 'a' && path[0] <= 'z') || (path[0] >= 'A' && path[0] <= 'Z'))
{
if(path[1] == ':')
{
return(TRUE);
}
if(path[1] == ':')
return(TRUE);
}
#endif
@ -93,29 +84,24 @@ bool MDFN_IsFIROPSafe(const std::string &path)
return(true);
}
void MDFN_GetFilePathComponents(const std::string &file_path, std::string *dir_path_out, std::string *file_base_out, std::string *file_ext_out)
void MDFN_GetFilePathComponents(const std::string &file_path,
std::string *dir_path_out, std::string *file_base_out,
std::string *file_ext_out)
{
size_t final_ds; // in file_path
size_t final_ds; // in file_path
string file_name;
size_t fn_final_dot; // in local var file_name
// Temporary output:
string dir_path, file_base, file_ext;
size_t fn_final_dot; // in local var file_name
string dir_path, file_base, file_ext; // Temporary output
#if PSS_STYLE==4
final_ds = file_path.find_last_of(':');
#elif PSS_STYLE==1
final_ds = file_path.find_last_of('/');
#else
#ifdef _WIN32
final_ds = file_path.find_last_of('\\');
#if PSS_STYLE!=3
{
size_t alt_final_ds = file_path.find_last_of('/');
size_t alt_final_ds = file_path.find_last_of('/');
if(final_ds == string::npos || (alt_final_ds != string::npos && alt_final_ds > final_ds))
if(final_ds == string::npos || (alt_final_ds != string::npos && alt_final_ds > final_ds))
final_ds = alt_final_ds;
}
#endif
#else
final_ds = file_path.find_last_of('/');
#endif
if(final_ds == string::npos)
@ -154,40 +140,43 @@ void MDFN_GetFilePathComponents(const std::string &file_path, std::string *dir_p
std::string MDFN_EvalFIP(const std::string &dir_path, const std::string &rel_path, bool skip_safety_check)
{
if(!skip_safety_check && !MDFN_IsFIROPSafe(rel_path))
throw MDFN_Error(0, _("Referenced path \"%s\" is potentially unsafe. See \"filesys.untrusted_fip_check\" setting.\n"), rel_path.c_str());
char slash;
#ifdef _WIN32
slash = '\\';
#else
slash = '/';
#endif
if(IsAbsolutePath(rel_path.c_str()))
return(rel_path);
else
{
return(dir_path + std::string(PSS) + rel_path);
}
if(!skip_safety_check && !MDFN_IsFIROPSafe(rel_path))
throw MDFN_Error(0, _("Referenced path \"%s\" is potentially unsafe. See \"filesys.untrusted_fip_check\" setting.\n"), rel_path.c_str());
if(IsAbsolutePath(rel_path.c_str()))
return(rel_path);
else
return(dir_path + slash + rel_path);
}
const char * GetFNComponent(const char *str)
{
const char *tp1;
const char *tp1;
#if PSS_STYLE==4
tp1=((char *)strrchr(str,':'));
#elif PSS_STYLE==1
tp1=((char *)strrchr(str,'/'));
#else
tp1=((char *)strrchr(str,'\\'));
#if PSS_STYLE!=3
{
const char *tp3;
tp3=((char *)strrchr(str,'/'));
if(tp1<tp3) tp1=tp3;
}
#endif
#endif
#ifdef _WIN32
tp1 = ((char *)strrchr(str,'\\'));
if(tp1)
return(tp1+1);
else
return(str);
const char *tp3;
tp3 = ((char *)strrchr(str,'/'));
if (tp1<tp3)
tp1 = tp3;
#else
tp1 = ((char *)strrchr(str,'/'));
#endif
if (tp1)
return (tp1+1);
else
return (str);
}
// Remove whitespace from beginning of string
@ -200,17 +189,17 @@ void MDFN_ltrim(char *string)
while(string[si])
{
if(InWhitespace && (string[si] == ' ' || string[si] == '\r' || string[si] == '\n' || string[si] == '\t' || string[si] == 0x0b))
{
if(InWhitespace && (string[si] == ' ' || string[si] == '\r' || string[si] == '\n' || string[si] == '\t' || string[si] == 0x0b))
{
}
else
{
InWhitespace = FALSE;
string[di] = string[si];
di++;
}
si++;
}
else
{
InWhitespace = FALSE;
string[di] = string[si];
di++;
}
si++;
}
string[di] = 0;
}
@ -218,23 +207,22 @@ void MDFN_ltrim(char *string)
// Remove whitespace from end of string
void MDFN_rtrim(char *string)
{
int32 len = strlen(string);
if(len)
{
for(int32 x = len - 1; x >= 0; x--)
{
if(string[x] == ' ' || string[x] == '\r' || string[x] == '\n' || string[x] == '\t' || string[x] == 0x0b)
string[x] = 0;
else
break;
}
}
int32 len = strlen(string);
if(len)
{
for(int32 x = len - 1; x >= 0; x--)
{
if(string[x] == ' ' || string[x] == '\r' || string[x] == '\n' || string[x] == '\t' || string[x] == 0x0b)
string[x] = 0;
else
break;
}
}
}
void MDFN_trim(char *string)
{
MDFN_rtrim(string);
MDFN_ltrim(string);
MDFN_rtrim(string);
MDFN_ltrim(string);
}

View File

@ -94,29 +94,6 @@ typedef struct
};
} Uuint32;
#if PSS_STYLE==2
#define PSS "\\"
#define MDFN_PS '\\'
#elif PSS_STYLE==1
#define PSS "/"
#define MDFN_PS '/'
#elif PSS_STYLE==3
#define PSS "\\"
#define MDFN_PS '\\'
#elif PSS_STYLE==4
#define PSS ":"
#define MDFN_PS ':'
#endif
typedef uint32 UTF32; /* at least 32 bits */
typedef uint16 UTF16; /* at least 16 bits */
typedef uint8 UTF8; /* typically 8 bits */

View File

@ -38,24 +38,31 @@ static void sanitize_path(std::string &path)
// Use a simpler approach to make sure that things go right for libretro.
std::string MDFN_MakeFName(MakeFName_Type type, int id1, const char *cd1)
{
char slash;
#ifdef _WIN32
slash = '\\';
#else
slash = '/';
#endif
std::string ret;
switch (type)
{
case MDFNMKF_SAV:
ret = retro_base_directory + std::string(PSS) + retro_base_name +
ret = retro_base_directory + slash + retro_base_name +
std::string(".") + md5_context::asciistr(MDFNGameInfo->MD5, 0) + std::string(".") +
std::string(cd1);
break;
case MDFNMKF_FIRMWARE:
ret = std::string(cd1);
#ifdef _WIN32
sanitize_path(ret); // Because Windows path handling is mongoloid.
#endif
break;
default:
break;
}
#ifdef _WIN32
sanitize_path(ret); // Because Windows path handling is mongoloid.
#endif
fprintf(stderr, "%s\n", ret.c_str());
return ret;
}