From 15b381909e872bfbb23be068f605a5a83090a90d Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 5 Nov 2001 22:24:16 +0000 Subject: [PATCH] move maplist from quakefs.c to console/maplist.c. Unfortunatly, until the client console plugin is usable, this means the clients link maplist.o directly. --- include/QF/console.h | 2 + include/QF/vfs.h | 26 ++++- libs/console/Makefile.am | 2 +- libs/console/maplist.c | 203 +++++++++++++++++++++++++++++++++++++++ libs/util/quakefs.c | 143 --------------------------- nq/source/Makefile.am | 3 +- nq/source/cl_main.c | 2 +- qw/source/Makefile.am | 1 + qw/source/cl_main.c | 2 +- qw/source/sv_ccmds.c | 3 +- 10 files changed, 238 insertions(+), 149 deletions(-) create mode 100644 libs/console/maplist.c diff --git a/include/QF/console.h b/include/QF/console.h index 7ed18b511..4a9a8c25f 100644 --- a/include/QF/console.h +++ b/include/QF/console.h @@ -128,4 +128,6 @@ void Con_Shutdown (void); void Con_ProcessInput (void); +void Con_Maplist_f (void); + #endif // __console_h diff --git a/include/QF/vfs.h b/include/QF/vfs.h index f89700a2f..b0325f6b0 100644 --- a/include/QF/vfs.h +++ b/include/QF/vfs.h @@ -38,6 +38,31 @@ #define MAX_OSPATH 128 // max length of a filesystem pathname +/* + In-memory pack file structs +*/ + +typedef struct { + char name[MAX_QPATH]; + int filepos, filelen; +} packfile_t; + +typedef struct pack_s { + char filename[MAX_OSPATH]; + VFile *handle; + int numfiles; + packfile_t *files; + struct hashtab_s *file_hash; +} pack_t; + +typedef struct searchpath_s { + char filename[MAX_OSPATH]; + pack_t *pack; // only one of filename / pack will be used + struct searchpath_s *next; +} searchpath_t; + +extern searchpath_t *com_searchpaths; + extern struct cvar_s *fs_userpath; extern struct cvar_s *fs_sharepath; extern struct cvar_s *fs_basegame; @@ -74,7 +99,6 @@ void COM_Gamedir (const char *dir); void COM_Filesystem_Init (void); void COM_Filesystem_Init_Cvars (void); void COM_Path_f (void); -void COM_Maplist_f (void); void COM_CreateGameDirectory (const char *gamename); #endif // __quakefs_h diff --git a/libs/console/Makefile.am b/libs/console/Makefile.am index 316894b72..b7dd67a21 100644 --- a/libs/console/Makefile.am +++ b/libs/console/Makefile.am @@ -3,7 +3,7 @@ INCLUDES= -I$(top_srcdir)/include lib_LTLIBRARIES= libQFconsole.la plugin_LTLIBRARIES= libconsole_server.la #libconsole_client.la -common_sources= buffer.c complete.c console.c inputline.c list.c +common_sources= buffer.c complete.c console.c inputline.c list.c maplist.c client_sources= client.c server_sources= server.c diff --git a/libs/console/maplist.c b/libs/console/maplist.c new file mode 100644 index 000000000..4bf1ce11b --- /dev/null +++ b/libs/console/maplist.c @@ -0,0 +1,203 @@ +/* + maplist.c + + maplist command + + 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 + +*/ +static const char rcsid[] = + "$Id$"; + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#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" //FIXME maplist really shouldn't be in here +#include "QF/cvar.h" +#include "QF/hash.h" +#include "QF/qargs.h" +#include "QF/qendian.h" +#include "QF/qtypes.h" +#include "QF/sys.h" +#include "QF/va.h" +#include "QF/vfs.h" +#include "QF/zone.h" + +#include "compat.h" + +#ifndef HAVE_FNMATCH_PROTO +int fnmatch (const char *__pattern, const char *__string, int __flags); +#endif + +struct maplist { + char **list; + int count; + int size; +}; + +static struct maplist * +maplist_new (void) +{ + return calloc (1, sizeof (struct maplist)); +} + +static void +maplist_free (struct maplist *maplist) +{ + int i; + + for (i = 0; i < maplist->count; i++) + free (maplist->list[i]); + free (maplist->list); + free (maplist); +} + +static void +maplist_add_map (struct maplist *maplist, char *fname) +{ + char **new_list; + + if (maplist->count == maplist->size) { + maplist->size += 32; + new_list = realloc (maplist->list, maplist->size * sizeof (char *)); + + if (!new_list) { + maplist->size -= 32; + return; + } + maplist->list = new_list; + } + fname = strdup (fname); + *strstr (fname, ".bsp") = 0; + maplist->list[maplist->count++] = fname; +} + +static int +maplist_cmp (const void *_a, const void *_b) +{ + char *a = *(char **) _a; + char *b = *(char **) _b; + + return strcmp (a, b); +} + +static void +maplist_print (struct maplist *maplist) +{ + int i; + const char **list; + + if (maplist->count) { + qsort (maplist->list, maplist->count, sizeof (char *), maplist_cmp); + + list = (const char **)malloc (maplist->count + 1); + list[maplist->count] = 0; + for (i = 0; i < maplist->count; i++) + list[i] = maplist->list[i]; + Con_DisplayList (list, con_linewidth); + free (list); + } +} + +/* + Con_Maplist_f + + List map files in gamepaths. +*/ +void +Con_Maplist_f (void) +{ + searchpath_t *search; + DIR *dir_ptr; + struct dirent *dirent; + char buf[MAX_OSPATH]; + + for (search = com_searchpaths; search != NULL; search = search->next) { + if (search->pack) { + int i; + pack_t *pak = search->pack; + struct maplist *maplist = maplist_new (); + + Sys_Printf ("Looking in %s...\n", search->pack->filename); + for (i = 0; i < pak->numfiles; i++) { + char *name = pak->files[i].name; + + if (!fnmatch ("maps/*.bsp", name, FNM_PATHNAME) + || !fnmatch ("maps/*.bsp.gz", name, FNM_PATHNAME)) + maplist_add_map (maplist, name + 5); + } + maplist_print (maplist); + maplist_free (maplist); + } else { + struct maplist *maplist = maplist_new (); + + snprintf (buf, sizeof (buf), "%s/maps", search->filename); + dir_ptr = opendir (buf); + Sys_Printf ("Looking in %s...\n", buf); + if (!dir_ptr) + continue; + while ((dirent = readdir (dir_ptr))) + if (!fnmatch ("*.bsp", dirent->d_name, 0) + || !fnmatch ("*.bsp.gz", dirent->d_name, 0)) + maplist_add_map (maplist, dirent->d_name); + closedir (dir_ptr); + maplist_print (maplist); + maplist_free (maplist); + } + } +} diff --git a/libs/util/quakefs.c b/libs/util/quakefs.c index 4a054ab74..7ebc7d94a 100644 --- a/libs/util/quakefs.c +++ b/libs/util/quakefs.c @@ -67,7 +67,6 @@ static const char rcsid[] = #include #include "QF/cmd.h" -#include "QF/console.h" //FIXME maplist really shouldn't be in here #include "QF/cvar.h" #include "QF/hash.h" #include "QF/qargs.h" @@ -120,23 +119,6 @@ cvar_t *fs_skinbase; int com_filesize; -/* - In-memory pack file structs -*/ - -typedef struct { - char name[MAX_QPATH]; - int filepos, filelen; -} packfile_t; - -typedef struct pack_s { - char filename[MAX_OSPATH]; - VFile *handle; - int numfiles; - packfile_t *files; - hashtab_t *file_hash; -} pack_t; - /* Structs for pack files on disk */ @@ -155,13 +137,6 @@ typedef struct { char com_gamedir[MAX_OSPATH]; -typedef struct searchpath_s { - char filename[MAX_OSPATH]; - pack_t *pack; // only one of filename / pack will - // be used - struct searchpath_s *next; -} searchpath_t; - searchpath_t *com_searchpaths; searchpath_t *com_base_searchpaths; // without gamedirs @@ -242,124 +217,6 @@ COM_Path_f (void) } } -struct maplist { - char **list; - int count; - int size; -}; - -static struct maplist * -maplist_new (void) -{ - return calloc (1, sizeof (struct maplist)); -} - -static void -maplist_free (struct maplist *maplist) -{ - int i; - - for (i = 0; i < maplist->count; i++) - free (maplist->list[i]); - free (maplist->list); - free (maplist); -} - -static void -maplist_add_map (struct maplist *maplist, char *fname) -{ - char **new_list; - - if (maplist->count == maplist->size) { - maplist->size += 32; - new_list = realloc (maplist->list, maplist->size * sizeof (char *)); - - if (!new_list) { - maplist->size -= 32; - return; - } - maplist->list = new_list; - } - fname = strdup (fname); - *strstr (fname, ".bsp") = 0; - maplist->list[maplist->count++] = fname; -} - -static int -maplist_cmp (const void *_a, const void *_b) -{ - char *a = *(char **) _a; - char *b = *(char **) _b; - - return strcmp (a, b); -} - -static void -maplist_print (struct maplist *maplist) -{ - int i; - const char **list; - - if (maplist->count) { - qsort (maplist->list, maplist->count, sizeof (char *), maplist_cmp); - - list = (const char **)malloc (maplist->count + 1); - list[maplist->count] = 0; - for (i = 0; i < maplist->count; i++) - list[i] = maplist->list[i]; - Con_DisplayList (list, con_linewidth); - free (list); - } -} - -/* - COM_Maplist_f - - List map files in gamepaths. -*/ -void -COM_Maplist_f (void) -{ - searchpath_t *search; - DIR *dir_ptr; - struct dirent *dirent; - char buf[MAX_OSPATH]; - - for (search = com_searchpaths; search != NULL; search = search->next) { - if (search->pack) { - int i; - pack_t *pak = search->pack; - struct maplist *maplist = maplist_new (); - - Sys_Printf ("Looking in %s...\n", search->pack->filename); - for (i = 0; i < pak->numfiles; i++) { - char *name = pak->files[i].name; - - if (!fnmatch ("maps/*.bsp", name, FNM_PATHNAME) - || !fnmatch ("maps/*.bsp.gz", name, FNM_PATHNAME)) - maplist_add_map (maplist, name + 5); - } - maplist_print (maplist); - maplist_free (maplist); - } else { - struct maplist *maplist = maplist_new (); - - snprintf (buf, sizeof (buf), "%s/maps", search->filename); - dir_ptr = opendir (buf); - Sys_Printf ("Looking in %s...\n", buf); - if (!dir_ptr) - continue; - while ((dirent = readdir (dir_ptr))) - if (!fnmatch ("*.bsp", dirent->d_name, 0) - || !fnmatch ("*.bsp.gz", dirent->d_name, 0)) - maplist_add_map (maplist, dirent->d_name); - closedir (dir_ptr); - maplist_print (maplist); - maplist_free (maplist); - } - } -} - /* COM_WriteFile diff --git a/nq/source/Makefile.am b/nq/source/Makefile.am index f3d9858d0..20e87e196 100644 --- a/nq/source/Makefile.am +++ b/nq/source/Makefile.am @@ -63,7 +63,8 @@ EXTRA_libqfnet_la_SOURCES= \ client_LIBFILES= \ $(top_builddir)/libs/video/targets/libQFjs.la \ $(top_builddir)/libs/audio/libQFcd.la \ - $(top_builddir)/libs/audio/libQFsound.la + $(top_builddir)/libs/audio/libQFsound.la \ + $(top_builddir)/libs/console/maplist.o server_LIBFILES= \ $(top_builddir)/libs/models/libQFmodels.la \ diff --git a/nq/source/cl_main.c b/nq/source/cl_main.c index 85271e547..820bced38 100644 --- a/nq/source/cl_main.c +++ b/nq/source/cl_main.c @@ -738,7 +738,7 @@ CL_Init (void) Cmd_AddCommand ("stop", CL_Stop_f, "No Description"); Cmd_AddCommand ("playdemo", CL_PlayDemo_f, "No Description"); Cmd_AddCommand ("timedemo", CL_TimeDemo_f, "No Description"); - Cmd_AddCommand ("maplist", COM_Maplist_f, "No Description"); + Cmd_AddCommand ("maplist", Con_Maplist_f, "No Description"); Cmd_AddCommand ("force_centerview", Force_CenterView_f, "force the view " "to be level"); diff --git a/qw/source/Makefile.am b/qw/source/Makefile.am index c6bb70d0a..b26a4f537 100644 --- a/qw/source/Makefile.am +++ b/qw/source/Makefile.am @@ -103,6 +103,7 @@ qf_client_LIBS= \ $(top_builddir)/libs/gamecode/builtins/libQFgamecode_builtins.la \ $(top_builddir)/libs/audio/libQFcd.la \ $(top_builddir)/libs/audio/libQFsound.la \ + $(top_builddir)/libs/console/maplist.o \ $(top_builddir)/libs/util/libQFutil.la client_LIBS= libqfnet.la libasm.la $(qf_client_LIBS) $(NET_LIBS) diff --git a/qw/source/cl_main.c b/qw/source/cl_main.c index 742ceacbb..d42bc3af7 100644 --- a/qw/source/cl_main.c +++ b/qw/source/cl_main.c @@ -1130,7 +1130,7 @@ CL_Init (void) Cmd_AddCommand ("playdemo", CL_PlayDemo_f, "Play a recorded demo"); Cmd_AddCommand ("timedemo", CL_TimeDemo_f, "Play a demo as fast as your " "hardware can. Useful for benchmarking."); - Cmd_AddCommand ("maplist", COM_Maplist_f, "List maps available"); + Cmd_AddCommand ("maplist", Con_Maplist_f, "List maps available"); Cmd_AddCommand ("quit", CL_Quit_f, "Exit the program"); Cmd_AddCommand ("connect", CL_Connect_f, "Connect to a server 'connect " "hostname:port'"); diff --git a/qw/source/sv_ccmds.c b/qw/source/sv_ccmds.c index 1179adb85..8fcffb20b 100644 --- a/qw/source/sv_ccmds.c +++ b/qw/source/sv_ccmds.c @@ -41,6 +41,7 @@ static const char rcsid[] = #include #include "QF/cmd.h" +#include "QF/console.h" #include "QF/cvar.h" #include "QF/msg.h" #include "QF/qargs.h" @@ -1202,7 +1203,7 @@ SV_InitOperatorCommands (void) Cmd_AddCommand ("floodprotmsg", SV_Floodprotmsg_f, "Sets the message " "displayed after flood protection is invoked (floodprotmsg " "message)"); - Cmd_AddCommand ("maplist", COM_Maplist_f, "List all maps on the server"); + Cmd_AddCommand ("maplist", Con_Maplist_f, "List all maps on the server"); Cmd_AddCommand ("say", SV_ConSay_f, "Say something to everyone on the " "server. Will show up as the name 'Console' (or 'Admin') " "in game");