rg_utils: Added rg_extension_match

This commit is contained in:
Alex Duchesne 2024-07-16 19:36:10 -04:00
parent 8ea557ee23
commit 51a03bbd36
4 changed files with 23 additions and 6 deletions

View File

@ -1,6 +1,7 @@
#include "rg_system.h"
#include "rg_utils.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
@ -57,18 +58,33 @@ const char *rg_basename(const char *path)
return name ? name + 1 : path;
}
const char *rg_extension(const char *path)
const char *rg_extension(const char *filename)
{
if (!path)
if (!filename)
return NULL;
const char *ptr = rg_basename(path);
const char *ptr = rg_basename(filename);
const char *ext = strrchr(ptr, '.');
if (!ext)
return ptr + strlen(ptr);
return ext + 1;
}
bool rg_extension_match(const char *filename, const char *extension)
{
const char *fileext = rg_extension(filename);
if (!fileext || !extension)
return false;
while (*fileext && *extension)
{
if (toupper(*fileext++) != toupper(*extension++))
return false;
}
return *fileext == 0 && *extension == 0;
}
const char *rg_relpath(const char *path)
{
if (!path)

View File

@ -61,7 +61,8 @@ char *rg_strtolower(char *str);
char *rg_strtoupper(char *str);
const char *rg_dirname(const char *path);
const char *rg_basename(const char *path);
const char *rg_extension(const char *path);
const char *rg_extension(const char *filename);
bool rg_extension_match(const char *filename, const char *extension);
const char *rg_relpath(const char *path);
uint32_t rg_crc32(uint32_t crc, const uint8_t *buf, size_t len);
uint32_t rg_hash(const char *buf, size_t len);

View File

@ -484,7 +484,7 @@ void app_main(void)
};
int argc = RG_COUNT(argv) - 3;
if (strcasecmp(rg_extension(app->romPath), "dsk") == 0)
if (rg_extension_match(app->romPath, "dsk"))
{
argv[argc++] = "-diska";
}

View File

@ -118,7 +118,7 @@ void sms_main(void)
option.extra_gg = 0;
option.tms_pal = rg_settings_get_number(NS_APP, SETTING_PALETTE, 0);
if (strcmp(rg_extension(app->romPath), "sg") == 0)
if (rg_extension_match(app->romPath, "sg"))
option.console = 5;
else if (strcmp(app->configNs, "col") == 0)
option.console = 6;