From 2e9fade00ac16e6698bc791fc2a56a68dc0d93ea Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 25 Feb 2012 17:05:52 +0100 Subject: [PATCH] Add name generation from id. --- console/rom_ext.c | 27 +++++++++++++++++++++++++++ console/rom_ext.h | 5 +++++ 2 files changed, 32 insertions(+) diff --git a/console/rom_ext.c b/console/rom_ext.c index d524dd1c9c..be4dc8e211 100644 --- a/console/rom_ext.c +++ b/console/rom_ext.c @@ -19,6 +19,7 @@ #include "../boolean.h" #include "../libsnes.hpp" #include +#include const char *ssnes_console_get_rom_ext(void) { @@ -46,3 +47,29 @@ const char *ssnes_console_get_rom_ext(void) return NULL; } +void ssnes_console_name_from_id(char *name, size_t size) +{ + if (size == 0) + return; + + const char *id = snes_library_id(); + if (!id || strlen(id) >= size) + { + name[0] = '\0'; + return; + } + + name[strlen(id)] = '\0'; + + for (size_t i = 0; i < size && id[i]; i++) + { + char c = id[i]; + if (isspace(c) || isblank(c)) + name[i] = '_'; + else if (isupper(c)) + name[i] = tolower(c); + else + name[i] = c; + } +} + diff --git a/console/rom_ext.h b/console/rom_ext.h index 0702dc475a..33c900fdd1 100644 --- a/console/rom_ext.h +++ b/console/rom_ext.h @@ -18,10 +18,15 @@ #ifndef ROM_EXT_H__ #define ROM_EXT_H__ +#include + // Get rom extensions for current library. // Infers info from snes_library_id(). // Returns NULL if library doesn't have any preferences in particular. const char *ssnes_console_get_rom_ext(void); +// Transforms a library id to a name suitable as a pathname. +void ssnes_console_name_from_id(char *name, size_t size); + #endif