rework the maplist code to use Con_DisplayList. this results in both

prettier code and prettier output.
This commit is contained in:
Bill Currie 2001-11-05 21:30:53 +00:00
parent e0dfa2b453
commit 460b53e9ee

View file

@ -67,6 +67,7 @@ static const char rcsid[] =
#include <limits.h> #include <limits.h>
#include "QF/cmd.h" #include "QF/cmd.h"
#include "QF/console.h" //FIXME maplist really shouldn't be in here
#include "QF/cvar.h" #include "QF/cvar.h"
#include "QF/hash.h" #include "QF/hash.h"
#include "QF/qargs.h" #include "QF/qargs.h"
@ -279,7 +280,9 @@ maplist_add_map (struct maplist *maplist, char *fname)
} }
maplist->list = new_list; maplist->list = new_list;
} }
maplist->list[maplist->count++] = strdup (fname); fname = strdup (fname);
*strstr (fname, ".bsp") = 0;
maplist->list[maplist->count++] = fname;
} }
static int static int
@ -287,34 +290,25 @@ maplist_cmp (const void *_a, const void *_b)
{ {
char *a = *(char **) _a; char *a = *(char **) _a;
char *b = *(char **) _b; char *b = *(char **) _b;
int al = strstr (a, ".bsp") - a;
int bl = strstr (b, ".bsp") - b;
int cmp = strncmp (a, b, min (al, bl));
if (cmp == 0) return strcmp (a, b);
return al - bl;
return cmp;
} }
static void static void
maplist_print (struct maplist *maplist) maplist_print (struct maplist *maplist)
{ {
int i; int i;
char *end; const char **list;
char *name;
if (maplist->count) { if (maplist->count) {
qsort (maplist->list, maplist->count, sizeof (char *), maplist_cmp); qsort (maplist->list, maplist->count, sizeof (char *), maplist_cmp);
for (i = 0; i < maplist->count - 1; i++) { list = (const char **)malloc (maplist->count + 1);
name = maplist->list[i]; list[maplist->count] = 0;
end = strstr (name, ".bsp"); for (i = 0; i < maplist->count; i++)
Sys_Printf ("%-8.*s%c", end - name, name, list[i] = maplist->list[i];
((i + 1) % 4) ? ' ' : '\n'); Con_DisplayList (list, con_linewidth);
} free (list);
name = maplist->list[i];
end = strstr (name, ".bsp");
Sys_Printf ("%-9.*s\n", end - name, name);
} }
} }