Skip to content

Commit

Permalink
Minor reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
bradharding committed Aug 13, 2024
1 parent f9542e6 commit bd2d195
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
7 changes: 4 additions & 3 deletions src/d_iwad.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,10 @@ static const iwads_t iwads[] =
// of the specified name.
static bool DirIsFile(char *path, char *filename)
{
char *filenamewithext = M_StringJoin(filename, ".wad", NULL);
bool ret = (strchr(path, DIR_SEPARATOR) && !strcasecmp(leafname(path), filenamewithext));
free(filenamewithext);
char *filenamewithext = M_StringJoin(filename, ".wad", NULL);
bool ret = (strchr(path, DIR_SEPARATOR) && !strcasecmp(leafname(path), filenamewithext));

free(filenamewithext);
return ret;
}

Expand Down
48 changes: 29 additions & 19 deletions src/m_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ bool M_FileExists(const char *filename)

#if !defined(_WIN32) && !defined(__APPLE__)

bool file_exists_get_path(const char *basedir, const char *filename, char **retpath) {
bool file_exists_get_path(const char *basedir, const char *filename, char **retpath)
{
*retpath = M_StringJoin(basedir, DIR_SEPARATOR_S, filename, NULL);

if (M_FileExists(*retpath))
Expand All @@ -139,53 +140,62 @@ bool file_exists_get_path(const char *basedir, const char *filename, char **retp
// Returns a newly allocated string that the caller is responsible for freeing.
char *M_FileCaseExists(const char *path)
{
char *basedir;
char *filename;
char *retpath;
char *tmpfilename = NULL;
char *pos;
char *basedir;
char *filename;
char *retpath;
char *tmpfilename = NULL;
char *pos;

// actual path
if (M_FileExists(path))
return M_StringDuplicate(path);

pos = strrchr(path, DIR_SEPARATOR);
if(pos) {
basedir = M_SubString(path, 0, pos-path);
filename = M_StringDuplicate(pos+1);
} else {
if ((pos = strrchr(path, DIR_SEPARATOR)))
{
basedir = M_SubString(path, 0, pos - path);
filename = M_StringDuplicate(pos + 1);
}
else
{
basedir = ".";
filename = M_StringDuplicate(path);
}

// lowercase filename, e.g. doom2.wad
if(file_exists_get_path(basedir, lowercase(filename), &retpath))
if (file_exists_get_path(basedir, lowercase(filename), &retpath))
goto cleanup;

// uppercase filename, e.g. DOOM2.WAD
tmpfilename = uppercase(filename);
if(file_exists_get_path(basedir, tmpfilename, &retpath))

if (file_exists_get_path(basedir, tmpfilename, &retpath))
goto cleanup;

// uppercase basename with lowercase extension, e.g. DOOM2.wad
if ((pos = strrchr(tmpfilename, '.')) && tmpfilename[strlen(tmpfilename)-1] != '.') {
if ((pos = strrchr(tmpfilename, '.')) && tmpfilename[strlen(tmpfilename) - 1] != '.')
{
lowercase(pos + 1);

if(file_exists_get_path(basedir, tmpfilename, &retpath))
goto cleanup;
}

// lowercase filename with uppercase first letter, e.g. Doom2.wad
if (strlen(tmpfilename) > 1) {
if (strlen(tmpfilename) > 1)
{
lowercase(tmpfilename + 1);
if(file_exists_get_path(basedir, tmpfilename, &retpath))

if (file_exists_get_path(basedir, tmpfilename, &retpath))
goto cleanup;
}

cleanup:
cleanup:
free(filename);
if(tmpfilename)

if (tmpfilename)
free(tmpfilename);
if(strcmp(basedir, "."))

if (strcmp(basedir, "."))
free(basedir);

return retpath;
Expand Down

0 comments on commit bd2d195

Please sign in to comment.