OSD command 'map': entering a name with a '*' wildcard lists those that match.

A new function maybe_append_ext() is added to common.c and used in the handling
of the -d<demo.edm> cmdline parameter and the 'map' OSD command with one
non-wildcard arg.  (It's slightly different from the way the extension was
maybe-appended previously.)

git-svn-id: https://svn.eduke32.com/eduke32@3004 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2012-09-08 22:18:31 +00:00
parent ef7e057fd9
commit 06a64b8dd4
4 changed files with 28 additions and 13 deletions

View file

@ -62,6 +62,7 @@ void G_LoadGroupsInDir(const char *dirname);
void G_DoAutoload(const char *dirname);
char *dup_filename(const char *fn);
int32_t maybe_append_ext(char *wbuf, int32_t wbufsiz, const char *fn, const char *ext);
// timer defs for profiling function chunks the simple way
#define EDUKE32_TMRDEF int32_t t[20], ti=0; const char *tmrstr=__func__; fprintf(stderr,"%s\n",tmrstr); t[ti++]=getticks();

View file

@ -315,3 +315,18 @@ char *dup_filename(const char *fn)
return Bstrncpyz(buf, fn, BMAX_PATH);
}
// Copy FN to WBUF and append an extension if it's not there, which is checked
// case-insensitively.
// Returns: 1 if not all characters could be written to WBUF, 0 else.
int32_t maybe_append_ext(char *wbuf, int32_t wbufsiz, const char *fn, const char *ext)
{
const int32_t slen=Bstrlen(fn), extslen=Bstrlen(ext);
const int32_t haveext = (slen>=extslen && Bstrcasecmp(&fn[slen-extslen], ext)==0);
Bassert((intptr_t)wbuf != (intptr_t)fn); // no aliasing
// If 'fn' has no extension suffixed, append one.
return (Bsnprintf(wbuf, wbufsiz, "%s%s", fn, haveext ? "" : ext) >= wbufsiz);
}

View file

@ -8961,17 +8961,10 @@ static void G_CheckCommandLine(int32_t argc, const char **argv)
ud.m_coop--;
break;
case 'd':
{
char *dot;
c++;
Bstrcpy(g_firstDemoFile,c);
dot = Bstrchr(g_firstDemoFile,'.');
if (!dot && Bstrlen(g_firstDemoFile)+4 < sizeof(g_firstDemoFile))
Bstrcat(g_firstDemoFile,".edm");
maybe_append_ext(g_firstDemoFile, sizeof(g_firstDemoFile), c, ".edm");
initprintf("Play demo %s.\n",g_firstDemoFile);
break;
}
case 'g':
c++;
if (*c)

View file

@ -167,13 +167,21 @@ static int32_t osdcmd_map(const osdfuncparm_t *parm)
int32_t i;
char filename[BMAX_PATH];
if (parm->numparms != 1)
const int32_t wildcardp = parm->numparms==1 &&
(Bstrchr(parm->parms[0], '*') != NULL);
if (parm->numparms != 1 || wildcardp)
{
CACHE1D_FIND_REC *r;
fnlist_t fnlist = FNLIST_INITIALIZER;
int32_t maxwidth = 0;
fnlist_getnames(&fnlist, "/", "*.MAP", -1, 0);
if (wildcardp)
maybe_append_ext(filename, sizeof(filename), parm->parms[0], ".map");
else
Bstrcpy(filename, "*.MAP");
fnlist_getnames(&fnlist, "/", filename, -1, 0);
for (r=fnlist.findfiles; r; r=r->next)
maxwidth = max((unsigned)maxwidth, Bstrlen(r->name));
@ -211,9 +219,7 @@ static int32_t osdcmd_map(const osdfuncparm_t *parm)
}
#endif
strcpy(filename,parm->parms[0]);
if (strchr(filename,'.') == 0)
strcat(filename,".map");
maybe_append_ext(filename, sizeof(filename), parm->parms[0], ".map");
if ((i = kopen4loadfrommod(filename,0)) < 0)
{