Add name generation from id.

This commit is contained in:
Themaister 2012-02-25 17:05:52 +01:00
parent 3dc5b21b78
commit 2e9fade00a
2 changed files with 32 additions and 0 deletions

View File

@ -19,6 +19,7 @@
#include "../boolean.h"
#include "../libsnes.hpp"
#include <string.h>
#include <ctype.h>
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;
}
}

View File

@ -18,10 +18,15 @@
#ifndef ROM_EXT_H__
#define ROM_EXT_H__
#include <stddef.h>
// 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