From 9d0bffebde2adc6227b8af40d3ee7fc7720d3116 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Mon, 1 Oct 2012 17:52:44 +0000 Subject: [PATCH] Mapster32: factor out some code (3x) into GetSaveBoardFilename(). git-svn-id: https://svn.eduke32.com/eduke32@3046 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/editor.h | 1 + polymer/eduke32/build/src/build.c | 35 +++++++------------------- polymer/eduke32/source/astub.c | 11 +------- 3 files changed, 11 insertions(+), 36 deletions(-) diff --git a/polymer/eduke32/build/include/editor.h b/polymer/eduke32/build/include/editor.h index a5abc667f..d26749043 100644 --- a/polymer/eduke32/build/include/editor.h +++ b/polymer/eduke32/build/include/editor.h @@ -178,6 +178,7 @@ extern const char *ExtGetSectorType(int32_t lotag); extern int32_t LoadBoard(const char *filename, uint32_t flags); extern const char *SaveBoard(const char *fn, uint32_t flags); +extern const char *GetSaveBoardFilename(const char *fn); #define CORRUPT_SECTOR (1<<17) #define CORRUPT_WALL (1<<18) diff --git a/polymer/eduke32/build/src/build.c b/polymer/eduke32/build/src/build.c index fae7c57f7..1c179d3e5 100644 --- a/polymer/eduke32/build/src/build.c +++ b/polymer/eduke32/build/src/build.c @@ -157,7 +157,6 @@ int32_t g_doScreenShot; static int32_t backup_highlighted_map(mapinfofull_t *mapinfo); static int32_t restore_highlighted_map(mapinfofull_t *mapinfo, int32_t forreal); static void SaveBoardAndPrintMessage(const char *fn); -static const char *GetSaveBoardFilename(void); /* static char scantoasc[128] = @@ -7298,7 +7297,7 @@ CANCEL: #else _printmessage16("(N)ew, (L)oad, (S)ave, save (A)s, (T)est map, (Q)uit"); #endif - printext16(16*8, ydim-STATUS2DSIZ2-12, editorcolors[15], -1, GetSaveBoardFilename(), 0); + printext16(16*8, ydim-STATUS2DSIZ2-12, editorcolors[15], -1, GetSaveBoardFilename(NULL), 0); showframe(1); bflushchars(); @@ -7703,10 +7702,13 @@ static void SaveBoardAndPrintMessage(const char *fn) } } -// get the file name of the file that would be written if SaveBoard(NULL, 0) was called -static const char *GetSaveBoardFilename(void) +// get the file name of the file that would be written if SaveBoard(fn, 0) was called +const char *GetSaveBoardFilename(const char *fn) { - const char *fn = boardfilename, *f; + const char *f; + + if (!fn) + fn = boardfilename; if (pathsearchmode) f = fn; @@ -7727,27 +7729,11 @@ static const char *GetSaveBoardFilename(void) // flags: 1:no ExtSaveMap (backup.map) and no taglabels saving const char *SaveBoard(const char *fn, uint32_t flags) { - const char *f; int32_t ret; + const char *f = GetSaveBoardFilename(fn); saveboard_savedtags = 0; - if (!fn) - fn = boardfilename; - - if (pathsearchmode) - f = fn; - else - { - // virtual filesystem mode can't save to directories so drop the file into - // the current directory - f = Bstrrchr(fn, '/'); - if (!f) - f = fn; - else - f++; - } - saveboard_fixedsprites = ExtPreSaveMap(); ret = saveboard(f, &startpos, startang, startsectnum); if ((flags&1)==0) @@ -7756,10 +7742,7 @@ const char *SaveBoard(const char *fn, uint32_t flags) saveboard_savedtags = !taglab_save(f); } - if (!ret) - return f; - else - return NULL; + return (ret==0) ? f : NULL; } // flags: 1: for running on Mapster32 init diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index 320bc760d..c5ba7df37 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -11097,16 +11097,7 @@ static void Keys2d3d(void) if (totalclock < (lastsave + 120*10) || !AskIfSure("Are you sure you want to load the last saved map?")) { int32_t sposx=pos.x,sposy=pos.y,sposz=pos.z,sang=ang; - char *f; - - if (pathsearchmode) f = levelname; - else - { - // virtual filesystem mode can't save to directories so drop the file into - // the current directory - f = Bstrrchr(levelname, '/'); - if (!f) f = levelname; else f++; - } + const char *f = GetSaveBoardFilename(levelname); lastsave=totalclock; // sectorhighlightstat = -1;