/* 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 static __attribute__ ((used)) const char rcsid[] = "$Id$"; #ifdef HAVE_STRING_H # include #endif #ifdef HAVE_STRINGS_H # include #endif #ifdef HAVE_UNISTD_H # include #endif #include #include #include #include #include #ifdef HAVE_FNMATCH_H # define model_t sunmodel_t # include # undef model_t #else # ifdef _WIN32 # include "fnmatch.h" # endif #endif #ifdef HAVE_IO_H # include #endif #ifdef _MSC_VER # define _POSIX_ #endif #include #include "QF/cmd.h" #include "QF/console.h" #include "QF/cvar.h" #include "QF/hash.h" #include "QF/pakfile.h" #include "QF/qargs.h" #include "QF/qendian.h" #include "QF/qtypes.h" #include "QF/quakefs.h" #include "QF/sys.h" #include "QF/va.h" #include "QF/zone.h" #include "compat.h" #ifndef HAVE_FNMATCH_PROTO int fnmatch (const char *__pattern, const char *__string, int __flags); #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 filelist_print (filelist_t *filelist) { int i; const char **list; if (filelist->count) { qsort (filelist->list, filelist->count, sizeof (char *), filelist_cmp); //if (0) filelist_cmp (0, 0); list = (const char **)malloc ((filelist->count + 1)*sizeof(char **)); list[filelist->count] = 0; for (i = 0; i < filelist->count; i++) list[i] = filelist->list[i]; Con_DisplayList (list, con_linewidth); free ((void*)list); } } __attribute__ ((visibility ("default"))) void Con_Maplist_f (void) { filelist_t *maplist = QFS_FilelistNew (); QFS_FilelistFill (maplist, "maps/", "bsp", 1); filelist_print (maplist); QFS_FilelistFree (maplist); } __attribute__ ((visibility ("default"))) void Con_Skinlist_f (void) { filelist_t *skinlist = QFS_FilelistNew (); QFS_FilelistFill (skinlist, "skins/", "pcx", 1); filelist_print (skinlist); QFS_FilelistFree (skinlist); } const char *sb_endings[] = { "bk", "dn", "ft", "lf", "rt", "up", 0 }; __attribute__ ((visibility ("default"))) void Con_Skyboxlist_f (void) { int i, j, k, c, b; char basename[256]; filelist_t *skyboxlist = QFS_FilelistNew (); filelist_t *cutlist = QFS_FilelistNew (); QFS_FilelistFill (skyboxlist, "env/", "tga", 1); QFS_FilelistFill (skyboxlist, "env/", "pcx", 1); for (i = 0; i < skyboxlist->count; i++) { if (strlen(skyboxlist->list[i]) > strlen(sb_endings[0]) && strcmp(skyboxlist->list[i] + strlen(skyboxlist->list[i]) - strlen(sb_endings[0]), sb_endings[0]) == 0) { strncpy(basename, skyboxlist->list[i], sizeof(basename)); basename[strlen(skyboxlist->list[i]) - strlen(sb_endings[0])] = 0; c = 0; for (j = 1; sb_endings[j]; j++) { b = 0; for (k = 0; k < skyboxlist->count; k++) { if (strcmp(va("%s%s", basename, sb_endings[j]), skyboxlist->list[k]) == 0) { b = 1; *skyboxlist->list[k] = 0; } } c += b; } if (c == 5) QFS_FilelistAdd (cutlist, basename, 0); } } filelist_print (cutlist); QFS_FilelistFree (cutlist); QFS_FilelistFree (skyboxlist); } __attribute__ ((visibility ("default"))) void Con_Demolist_QWD_f (void) { filelist_t *demolist = QFS_FilelistNew (); QFS_FilelistFill (demolist, "", "qwd", 1); filelist_print (demolist); QFS_FilelistFree (demolist); return; } __attribute__ ((visibility ("default"))) void Con_Demolist_DEM_f (void) { filelist_t *demolist = QFS_FilelistNew (); QFS_FilelistFill (demolist, "", "dem", 1); filelist_print (demolist); QFS_FilelistFree (demolist); return; }