2001-11-06 07:14:29 +00:00
|
|
|
/*
|
|
|
|
filelist.c
|
|
|
|
|
|
|
|
filelist commands
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
static __attribute__ ((used)) const char rcsid[] =
|
2003-01-15 15:31:36 +00:00
|
|
|
"$Id$";
|
|
|
|
|
2001-11-06 07:14:29 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_FNMATCH_H
|
|
|
|
# define model_t sunmodel_t
|
|
|
|
# include <fnmatch.h>
|
|
|
|
# undef model_t
|
|
|
|
#else
|
2004-01-20 03:47:27 +00:00
|
|
|
# ifdef _WIN32
|
2001-11-06 07:14:29 +00:00
|
|
|
# include "fnmatch.h"
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_IO_H
|
|
|
|
# include <io.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
# define _POSIX_
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/console.h"
|
|
|
|
#include "QF/cvar.h"
|
2007-04-07 05:06:42 +00:00
|
|
|
#include "QF/dstring.h"
|
2001-11-06 07:14:29 +00:00
|
|
|
#include "QF/hash.h"
|
2002-07-21 06:11:28 +00:00
|
|
|
#include "QF/pakfile.h"
|
2001-11-06 07:14:29 +00:00
|
|
|
#include "QF/qargs.h"
|
|
|
|
#include "QF/qendian.h"
|
|
|
|
#include "QF/qtypes.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakefs.h"
|
2001-11-06 07:14:29 +00:00
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/va.h"
|
|
|
|
#include "QF/zone.h"
|
|
|
|
|
|
|
|
#include "compat.h"
|
|
|
|
|
|
|
|
#ifndef HAVE_FNMATCH_PROTO
|
2007-04-07 05:06:42 +00:00
|
|
|
int fnmatch (const char *__pattern, const char *__string, int __flags);
|
2001-11-06 07:14:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static int
|
|
|
|
filelist_cmp (const void *_a, const void *_b)
|
|
|
|
{
|
|
|
|
char *a = *(char **) _a;
|
|
|
|
char *b = *(char **) _b;
|
|
|
|
|
|
|
|
return strcmp (a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-04-20 22:25:52 +00:00
|
|
|
filelist_print (filelist_t *filelist)
|
2001-11-06 07:14:29 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
const char **list;
|
|
|
|
|
|
|
|
if (filelist->count) {
|
2001-11-06 21:37:33 +00:00
|
|
|
qsort (filelist->list, filelist->count, sizeof (char *), filelist_cmp);
|
2001-11-06 07:14:29 +00:00
|
|
|
|
2007-04-07 05:06:42 +00:00
|
|
|
list = malloc ((filelist->count + 1) * sizeof (char **));
|
2001-11-06 07:14:29 +00:00
|
|
|
list[filelist->count] = 0;
|
|
|
|
for (i = 0; i < filelist->count; i++)
|
|
|
|
list[i] = filelist->list[i];
|
|
|
|
Con_DisplayList (list, con_linewidth);
|
2007-04-07 05:06:42 +00:00
|
|
|
free ((void *) list);
|
2001-11-06 07:14:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-07 02:14:22 +00:00
|
|
|
VISIBLE void
|
2001-11-06 07:14:29 +00:00
|
|
|
Con_Maplist_f (void)
|
|
|
|
{
|
2004-04-20 22:25:52 +00:00
|
|
|
filelist_t *maplist = QFS_FilelistNew ();
|
2007-04-07 05:06:42 +00:00
|
|
|
|
2004-04-20 22:52:09 +00:00
|
|
|
QFS_FilelistFill (maplist, "maps/", "bsp", 1);
|
2007-04-07 05:06:42 +00:00
|
|
|
|
2001-11-06 07:14:29 +00:00
|
|
|
filelist_print (maplist);
|
2004-04-20 22:25:52 +00:00
|
|
|
QFS_FilelistFree (maplist);
|
2001-11-06 07:14:29 +00:00
|
|
|
}
|
|
|
|
|
2007-04-07 02:14:22 +00:00
|
|
|
VISIBLE void
|
2001-11-06 07:14:29 +00:00
|
|
|
Con_Skinlist_f (void)
|
|
|
|
{
|
2004-04-20 22:25:52 +00:00
|
|
|
filelist_t *skinlist = QFS_FilelistNew ();
|
2007-04-07 05:06:42 +00:00
|
|
|
|
2004-04-20 22:52:09 +00:00
|
|
|
QFS_FilelistFill (skinlist, "skins/", "pcx", 1);
|
2001-11-06 07:14:29 +00:00
|
|
|
|
|
|
|
filelist_print (skinlist);
|
2004-04-20 22:25:52 +00:00
|
|
|
QFS_FilelistFree (skinlist);
|
2001-11-06 07:14:29 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
const char *sb_endings[] = {
|
2001-11-06 07:14:29 +00:00
|
|
|
"bk",
|
|
|
|
"dn",
|
|
|
|
"ft",
|
|
|
|
"lf",
|
|
|
|
"rt",
|
|
|
|
"up",
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2007-04-07 02:14:22 +00:00
|
|
|
VISIBLE void
|
2001-11-06 07:14:29 +00:00
|
|
|
Con_Skyboxlist_f (void)
|
|
|
|
{
|
2007-04-07 05:06:42 +00:00
|
|
|
int i, j, k, c, b;
|
|
|
|
size_t ending_len = strlen (sb_endings[0]);
|
|
|
|
dstring_t *basename = dstring_new ();
|
2001-11-06 07:14:29 +00:00
|
|
|
|
2004-04-20 22:25:52 +00:00
|
|
|
filelist_t *skyboxlist = QFS_FilelistNew ();
|
|
|
|
filelist_t *cutlist = QFS_FilelistNew ();
|
2001-11-06 07:14:29 +00:00
|
|
|
|
2004-04-20 22:52:09 +00:00
|
|
|
QFS_FilelistFill (skyboxlist, "env/", "tga", 1);
|
|
|
|
QFS_FilelistFill (skyboxlist, "env/", "pcx", 1);
|
2001-11-06 07:14:29 +00:00
|
|
|
|
|
|
|
for (i = 0; i < skyboxlist->count; i++) {
|
2007-04-07 05:06:42 +00:00
|
|
|
if (strlen(skyboxlist->list[i]) > ending_len
|
|
|
|
&& strcmp((skyboxlist->list[i] + strlen (skyboxlist->list[i])
|
|
|
|
- ending_len),
|
|
|
|
sb_endings[0]) == 0) {
|
|
|
|
dstring_copysubstr (basename, skyboxlist->list[i],
|
|
|
|
strlen (skyboxlist->list[i]) - ending_len);
|
2001-11-06 07:14:29 +00:00
|
|
|
c = 0;
|
|
|
|
for (j = 1; sb_endings[j]; j++) {
|
|
|
|
b = 0;
|
|
|
|
for (k = 0; k < skyboxlist->count; k++) {
|
2007-04-07 05:06:42 +00:00
|
|
|
if (strcmp(va("%s%s", basename->str, sb_endings[j]),
|
|
|
|
skyboxlist->list[k]) == 0) {
|
2001-11-06 07:14:29 +00:00
|
|
|
b = 1;
|
|
|
|
*skyboxlist->list[k] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c += b;
|
|
|
|
}
|
|
|
|
if (c == 5)
|
2007-04-07 05:06:42 +00:00
|
|
|
QFS_FilelistAdd (cutlist, basename->str, 0);
|
2001-11-06 07:14:29 +00:00
|
|
|
}
|
|
|
|
}
|
2004-04-20 22:25:52 +00:00
|
|
|
filelist_print (cutlist);
|
|
|
|
QFS_FilelistFree (cutlist);
|
|
|
|
QFS_FilelistFree (skyboxlist);
|
2007-04-07 05:06:42 +00:00
|
|
|
dstring_delete (basename);
|
2001-11-06 07:14:29 +00:00
|
|
|
}
|
|
|
|
|
2007-04-07 02:14:22 +00:00
|
|
|
VISIBLE void
|
2001-11-06 07:14:29 +00:00
|
|
|
Con_Demolist_QWD_f (void)
|
|
|
|
{
|
2004-04-20 22:25:52 +00:00
|
|
|
filelist_t *demolist = QFS_FilelistNew ();
|
2007-04-07 05:06:42 +00:00
|
|
|
|
2004-04-20 22:52:09 +00:00
|
|
|
QFS_FilelistFill (demolist, "", "qwd", 1);
|
2007-04-07 05:06:42 +00:00
|
|
|
|
2004-04-20 22:25:52 +00:00
|
|
|
filelist_print (demolist);
|
|
|
|
QFS_FilelistFree (demolist);
|
2007-04-07 05:06:42 +00:00
|
|
|
|
2001-11-06 07:14:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-04-07 02:14:22 +00:00
|
|
|
VISIBLE void
|
2001-11-06 07:14:29 +00:00
|
|
|
Con_Demolist_DEM_f (void)
|
|
|
|
{
|
2004-04-20 22:25:52 +00:00
|
|
|
filelist_t *demolist = QFS_FilelistNew ();
|
2007-04-07 05:06:42 +00:00
|
|
|
|
2004-04-20 22:52:09 +00:00
|
|
|
QFS_FilelistFill (demolist, "", "dem", 1);
|
2001-11-06 07:14:29 +00:00
|
|
|
|
2004-04-20 22:25:52 +00:00
|
|
|
filelist_print (demolist);
|
|
|
|
QFS_FilelistFree (demolist);
|
2001-11-06 07:14:29 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|