mirror of
https://github.com/mamedev/mame.git
synced 2024-11-18 10:06:19 +01:00
Added new option -snapname which lets you provide a template for how snapshot
names are generated. Added new astring functions astring_del, astring_replace, and astring_replacec to help perform simple search/replace substitution.
This commit is contained in:
parent
eeb821032e
commit
65934e7aa5
6 changed files with 134 additions and 15 deletions
|
@ -453,6 +453,20 @@ Core state/playback options
|
||||||
(.cfg), NVRAM (.nv), and memory card files deleted. The default is
|
(.cfg), NVRAM (.nv), and memory card files deleted. The default is
|
||||||
NULL (no recording).
|
NULL (no recording).
|
||||||
|
|
||||||
|
-snapname <name>
|
||||||
|
|
||||||
|
Describes how MAME should name files for snapshots. <name> is a string
|
||||||
|
that provides a template that is used to generate a filename. Three
|
||||||
|
simple substitutions are provided: the / character represents the
|
||||||
|
path separator on any target platform (even Windows); the string %g
|
||||||
|
represents the driver name of the current game; and the string %i
|
||||||
|
represents an incrementing index. If %i is omitted, then each
|
||||||
|
snapshot taken will overwrite the previous one; otherwise, MAME will
|
||||||
|
find the next empty value for %i and use that for a filename. The
|
||||||
|
default is %g/%i, which creates a separate folder for each game,
|
||||||
|
and names the snapshots under it starting with 0000 and increasing
|
||||||
|
from there.
|
||||||
|
|
||||||
-mngwrite <filename>
|
-mngwrite <filename>
|
||||||
|
|
||||||
Writes each video frame to the given <filename> in MNG format,
|
Writes each video frame to the given <filename> in MNG format,
|
||||||
|
|
|
@ -64,6 +64,7 @@ const options_entry mame_core_options[] =
|
||||||
{ "autosave", "0", OPTION_BOOLEAN, "enable automatic restore at startup, and automatic save at exit time" },
|
{ "autosave", "0", OPTION_BOOLEAN, "enable automatic restore at startup, and automatic save at exit time" },
|
||||||
{ "playback;pb", NULL, 0, "playback an input file" },
|
{ "playback;pb", NULL, 0, "playback an input file" },
|
||||||
{ "record;rec", NULL, 0, "record an input file" },
|
{ "record;rec", NULL, 0, "record an input file" },
|
||||||
|
{ "snapname", "%g/%i", 0, "override of the default snapshot naming; %g == gamename, %i == index" },
|
||||||
{ "mngwrite", NULL, 0, "optional filename to write a MNG movie of the current session" },
|
{ "mngwrite", NULL, 0, "optional filename to write a MNG movie of the current session" },
|
||||||
{ "aviwrite", NULL, 0, "optional filename to write an AVI movie of the current session" },
|
{ "aviwrite", NULL, 0, "optional filename to write an AVI movie of the current session" },
|
||||||
{ "wavwrite", NULL, 0, "optional filename to write a WAV file of the current session" },
|
{ "wavwrite", NULL, 0, "optional filename to write a WAV file of the current session" },
|
||||||
|
|
|
@ -63,6 +63,7 @@
|
||||||
#define OPTION_AUTOSAVE "autosave"
|
#define OPTION_AUTOSAVE "autosave"
|
||||||
#define OPTION_PLAYBACK "playback"
|
#define OPTION_PLAYBACK "playback"
|
||||||
#define OPTION_RECORD "record"
|
#define OPTION_RECORD "record"
|
||||||
|
#define OPTION_SNAPNAME "snapname"
|
||||||
#define OPTION_MNGWRITE "mngwrite"
|
#define OPTION_MNGWRITE "mngwrite"
|
||||||
#define OPTION_AVIWRITE "aviwrite"
|
#define OPTION_AVIWRITE "aviwrite"
|
||||||
#define OPTION_WAVWRITE "wavwrite"
|
#define OPTION_WAVWRITE "wavwrite"
|
||||||
|
|
|
@ -2214,28 +2214,63 @@ static void create_snapshot_bitmap(const device_config *screen)
|
||||||
|
|
||||||
static file_error mame_fopen_next(running_machine *machine, const char *pathoption, const char *extension, mame_file **file)
|
static file_error mame_fopen_next(running_machine *machine, const char *pathoption, const char *extension, mame_file **file)
|
||||||
{
|
{
|
||||||
|
const char *snapname = options_get_string(mame_options(), OPTION_SNAPNAME);
|
||||||
|
astring *snapstr = astring_alloc();
|
||||||
|
astring *fname = astring_alloc();
|
||||||
file_error filerr;
|
file_error filerr;
|
||||||
char *fname;
|
int index;
|
||||||
int seq;
|
|
||||||
|
/* handle defaults */
|
||||||
/* allocate temp space for the name */
|
if (snapname == NULL || snapname[0] == 0)
|
||||||
fname = malloc_or_die(strlen(machine->basename) + 1 + 10 + strlen(extension) + 1);
|
snapname = "%g/%i";
|
||||||
|
astring_cpyc(snapstr, snapname);
|
||||||
/* try until we succeed */
|
|
||||||
for (seq = 0; ; seq++)
|
/* strip any extension in the provided name and add our own */
|
||||||
|
index = astring_rchr(snapstr, 0, '.');
|
||||||
|
if (index != -1)
|
||||||
|
astring_substr(snapstr, 0, index);
|
||||||
|
astring_catc(snapstr, ".");
|
||||||
|
astring_catc(snapstr, extension);
|
||||||
|
|
||||||
|
/* substitute path and gamename up front */
|
||||||
|
astring_replacec(snapstr, 0, "/", PATH_SEPARATOR);
|
||||||
|
astring_replacec(snapstr, 0, "%g", machine->basename);
|
||||||
|
|
||||||
|
/* determine if the template has an index; if not, we always use the same name */
|
||||||
|
if (astring_findc(snapstr, 0, "%i") == -1)
|
||||||
|
astring_cpy(fname, snapstr);
|
||||||
|
|
||||||
|
/* otherwise, we scan for the next available filename */
|
||||||
|
else
|
||||||
{
|
{
|
||||||
sprintf(fname, "%s" PATH_SEPARATOR "%04d.%s", machine->basename, seq, extension);
|
int seq;
|
||||||
filerr = mame_fopen(pathoption, fname, OPEN_FLAG_READ, file);
|
|
||||||
if (filerr != FILERR_NONE)
|
/* try until we succeed */
|
||||||
break;
|
for (seq = 0; ; seq++)
|
||||||
mame_fclose(*file);
|
{
|
||||||
|
char seqtext[10];
|
||||||
|
|
||||||
|
/* make text for the sequence number */
|
||||||
|
sprintf(seqtext, "%04d", seq);
|
||||||
|
|
||||||
|
/* build up the filename */
|
||||||
|
astring_cpy(fname, snapstr);
|
||||||
|
astring_replacec(fname, 0, "%i", seqtext);
|
||||||
|
|
||||||
|
/* try to open the file; stop when we fail */
|
||||||
|
filerr = mame_fopen(pathoption, astring_c(fname), OPEN_FLAG_READ, file);
|
||||||
|
if (filerr != FILERR_NONE)
|
||||||
|
break;
|
||||||
|
mame_fclose(*file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create the final file */
|
/* create the final file */
|
||||||
filerr = mame_fopen(pathoption, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, file);
|
filerr = mame_fopen(pathoption, astring_c(fname), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, file);
|
||||||
|
|
||||||
/* free the name and get out */
|
/* free the name and get out */
|
||||||
free(fname);
|
astring_free(fname);
|
||||||
|
astring_free(snapstr);
|
||||||
return filerr;
|
return filerr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -290,6 +290,30 @@ astring *astring_substr(astring *str, int start, int count)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------------------------------
|
||||||
|
astring_del - delete a substring of
|
||||||
|
ourself, keeping everything else
|
||||||
|
-------------------------------------------------*/
|
||||||
|
|
||||||
|
astring *astring_del(astring *str, int start, int count)
|
||||||
|
{
|
||||||
|
int strlength = strlen(str->text);
|
||||||
|
|
||||||
|
/* ignore attempts to do this on the dummy */
|
||||||
|
if (str == &dummy_astring)
|
||||||
|
return str;
|
||||||
|
|
||||||
|
/* normalize parameters */
|
||||||
|
normalize_substr(&start, &count, strlength);
|
||||||
|
|
||||||
|
/* move the data and NULL-terminate */
|
||||||
|
if (count > 0)
|
||||||
|
memmove(str->text + start, str->text + start + count, strlength - (start + count));
|
||||||
|
str->text[strlength - count] = 0;
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------------
|
/*-------------------------------------------------
|
||||||
astring_printf - printf text into an astring
|
astring_printf - printf text into an astring
|
||||||
-------------------------------------------------*/
|
-------------------------------------------------*/
|
||||||
|
@ -498,6 +522,41 @@ int astring_findc(const astring *str, int start, const char *search)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------------------------------
|
||||||
|
astring_replace - search in an astring for
|
||||||
|
another astring, replacing all instances with
|
||||||
|
a third and returning the number of matches
|
||||||
|
-------------------------------------------------*/
|
||||||
|
|
||||||
|
int astring_replace(astring *str, int start, const astring *search, const astring *replace)
|
||||||
|
{
|
||||||
|
return astring_replacec(str, start, search->text, replace->text);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------------------------------
|
||||||
|
astring_replacec - search in an astring for a
|
||||||
|
C string, replacing all instances with another
|
||||||
|
C string and returning the number of matches
|
||||||
|
-------------------------------------------------*/
|
||||||
|
|
||||||
|
int astring_replacec(astring *str, int start, const char *search, const char *replace)
|
||||||
|
{
|
||||||
|
int searchlen = strlen(search);
|
||||||
|
int replacelen = strlen(replace);
|
||||||
|
int matches = 0;
|
||||||
|
int curindex;
|
||||||
|
|
||||||
|
for (curindex = astring_findc(str, start, search); curindex != -1; curindex = astring_findc(str, curindex + replacelen, search))
|
||||||
|
{
|
||||||
|
matches++;
|
||||||
|
astring_del(str, curindex, searchlen);
|
||||||
|
astring_insc(str, curindex, replace);
|
||||||
|
}
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
ASTRING UTILITIES
|
ASTRING UTILITIES
|
||||||
|
|
|
@ -69,6 +69,9 @@ astring *astring_inssubstr(astring *dst, int insbefore, const astring *src, int
|
||||||
/* extract a substring of ourself, removing everything else */
|
/* extract a substring of ourself, removing everything else */
|
||||||
astring *astring_substr(astring *str, int start, int count);
|
astring *astring_substr(astring *str, int start, int count);
|
||||||
|
|
||||||
|
/* delete a substring from ourself, keeping everything else */
|
||||||
|
astring *astring_del(astring *str, int start, int count);
|
||||||
|
|
||||||
/* formatted printf to an astring */
|
/* formatted printf to an astring */
|
||||||
int astring_printf(astring *dst, const char *format, ...) ATTR_PRINTF(2,3);
|
int astring_printf(astring *dst, const char *format, ...) ATTR_PRINTF(2,3);
|
||||||
|
|
||||||
|
@ -118,6 +121,12 @@ int astring_find(const astring *str, int start, const astring *search);
|
||||||
/* search in an astring for a C string, returning offset or -1 if not found */
|
/* search in an astring for a C string, returning offset or -1 if not found */
|
||||||
int astring_findc(const astring *str, int start, const char *search);
|
int astring_findc(const astring *str, int start, const char *search);
|
||||||
|
|
||||||
|
/* search in an astring for another astring, replacing all instances with a third and returning the number of matches */
|
||||||
|
int astring_replace(astring *str, int start, const astring *search, const astring *replace);
|
||||||
|
|
||||||
|
/* search in an astring for a C string, replacing all instances with another C string and returning the number of matches */
|
||||||
|
int astring_replacec(astring *str, int start, const char *search, const char *replace);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ----- astring utilties ----- */
|
/* ----- astring utilties ----- */
|
||||||
|
|
Loading…
Reference in a new issue