Slightly simplify S_OpenAudio()...

git-svn-id: https://svn.eduke32.com/eduke32@7210 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2018-11-18 18:12:11 +00:00
parent 871207294e
commit bb8e441d0d

View file

@ -1121,57 +1121,46 @@ static int32_t S_TryExtensionReplacements(char * const testfn, char const search
int32_t S_OpenAudio(const char *fn, char searchfirst, uint8_t const ismusic)
{
int32_t const origfp = kopen4loadfrommod(fn, searchfirst);
char const * const origparent = origfp != -1 ? kfileparent(origfp) : NULL;
uint32_t const origparentlength = origparent != NULL ? Bstrlen(origparent) : 0;
char const *const origparent = origfp != -1 ? kfileparent(origfp) : NULL;
uint32_t const parentlength = origparent != NULL ? Bstrlen(origparent) : 0;
char * const testfn = (char *)Xmalloc(Bstrlen(fn) + 12 + origparentlength); // "music/" + overestimation of parent minus extension + ".flac" + '\0'
auto testfn = (char *)Xmalloc(Bstrlen(fn) + 12 + parentlength); // "music/" + overestimation of parent minus extension + ".flac" + '\0'
// look in ./
// ex: ./grabbag.mid
{
Bstrcpy(testfn, fn);
int32_t const fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic);
int32_t fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic);
if (fp >= 0)
{
Bfree(testfn);
kclose(origfp);
return fp;
}
}
goto success;
// look in ./music/<file's parent GRP name>/
// ex: ./music/duke3d/grabbag.mid
// ex: ./music/nwinter/grabbag.mid
if (origparent != NULL)
{
char const * const origparentextension = Bstrrchr(origparent, '.');
uint32_t namelength = origparentextension != NULL ? (unsigned)(origparentextension - origparent) : origparentlength;
char const * const parentextension = Bstrrchr(origparent, '.');
uint32_t const namelength = parentextension != NULL ? (unsigned)(parentextension - origparent) : parentlength;
Bsprintf(testfn, "music/%.*s/%s", namelength, origparent, fn);
int32_t const fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic);
fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic);
if (fp >= 0)
{
Bfree(testfn);
kclose(origfp);
return fp;
}
goto success;
}
// look in ./music/
// ex: ./music/grabbag.mid
{
Bsprintf(testfn, "music/%s", fn);
int32_t const fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic);
fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic);
if (fp >= 0)
{
Bfree(testfn);
kclose(origfp);
return fp;
}
}
goto success;
fp = origfp;
success:
Bfree(testfn);
return origfp;
if (fp != origfp)
kclose(origfp);
return fp;
}
void Duke_CommonCleanup(void)