- cleanup of -map setup.

This commit is contained in:
Christoph Oelckers 2019-12-11 01:11:35 +01:00
parent cb051b44ea
commit ec96ae8992
4 changed files with 37 additions and 37 deletions

View file

@ -47,6 +47,7 @@
#endif
#endif
#include "cmdlib.h"
#include "compat.h"
#include <sys/types.h>
#include <sys/stat.h>
@ -757,3 +758,17 @@ bool IsAbsPath(const char *name)
#endif /* _WIN32 */
return 0;
}
//==========================================================================
//
//
//
//==========================================================================
void NormalizeFileName(FString &str)
{
auto strp = str.LockBuffer();
Bcorrectfilename(strp, false);
str.UnlockBuffer();
}

View file

@ -27,6 +27,7 @@ bool DirEntryExists (const char *pathname, bool *isdir = nullptr);
extern FString progdir;
void DefaultExtension (FString &path, const char *extension);
void NormalizeFileName(FString &str);
FString ExtractFilePath (const char *path);
FString ExtractFileBase (const char *path, bool keep_extension=false);

View file

@ -5656,38 +5656,30 @@ static void G_Startup(void)
if (userConfig.CommandMap.IsNotEmpty())
{
FString startupMap;
if (VOLUMEONE)
{
initprintf("The -map option is available in the registered version only!\n");
boardfilename[0] = 0;
}
else
{
char *dot, *slash;
startupMap = userConfig.CommandMap;
if (startupMap.IndexOfAny("/\\") < 0) startupMap.Insert(0, "/");
DefaultExtension(startupMap, ".map");
startupMap.Substitute("\\", "/");
NormalizeFileName(startupMap);
boardfilename[0] = '/';
boardfilename[1] = 0;
Bstrcat(boardfilename, userConfig.CommandMap);
dot = Bstrrchr(boardfilename,'.');
slash = Bstrrchr(boardfilename,'/');
if (!slash) slash = Bstrrchr(boardfilename,'\\');
if ((!slash && !dot) || (slash && dot < slash))
Bstrcat(boardfilename,".map");
Bcorrectfilename(boardfilename,0);
if (fileSystem.FileExists(boardfilename))
if (fileSystem.FileExists(startupMap))
{
initprintf("Using level: \"%s\".\n",boardfilename);
initprintf("Using level: \"%s\".\n",startupMap.GetChars());
}
else
{
initprintf("Level \"%s\" not found.\n",boardfilename);
initprintf("Level \"%s\" not found.\n",startupMap.GetChars());
boardfilename[0] = 0;
}
}
strncpy(boardfilename, startupMap, BMAX_PATH);
}
for (i=0; i<MAXPLAYERS; i++)

View file

@ -7094,38 +7094,30 @@ static void G_Startup(void)
if (userConfig.CommandMap.IsNotEmpty())
{
FString startupMap;
if (VOLUMEONE)
{
initprintf("The -map option is available in the registered version only!\n");
boardfilename[0] = 0;
}
else
{
char *dot, *slash;
startupMap = userConfig.CommandMap;
if (startupMap.IndexOfAny("/\\") < 0) startupMap.Insert(0, "/");
DefaultExtension(startupMap, ".map");
startupMap.Substitute("\\", "/");
NormalizeFileName(startupMap);
boardfilename[0] = '/';
boardfilename[1] = 0;
Bstrcat(boardfilename, userConfig.CommandMap);
dot = Bstrrchr(boardfilename,'.');
slash = Bstrrchr(boardfilename,'/');
if (!slash) slash = Bstrrchr(boardfilename,'\\');
if ((!slash && !dot) || (slash && dot < slash))
Bstrcat(boardfilename,".map");
Bcorrectfilename(boardfilename,0);
if (fileSystem.FileExists(boardfilename))
if (fileSystem.FileExists(startupMap))
{
initprintf("Using level: \"%s\".\n",boardfilename);
initprintf("Using level: \"%s\".\n",startupMap.GetChars());
}
else
{
initprintf("Level \"%s\" not found.\n",boardfilename);
initprintf("Level \"%s\" not found.\n",startupMap.GetChars());
boardfilename[0] = 0;
}
}
strncpy(boardfilename, startupMap, BMAX_PATH);
}
for (i=0; i<MAXPLAYERS; i++)