From 104701a8c5d95d7bd495c974f4dd28a240d70a85 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 16 Jul 2001 20:41:10 +0000 Subject: [PATCH] the beginnings of the console lib (using plugins for the client/server type consoles). Currently, doesn't affect anybody other than the need to re-bootstrap. --- configure.in | 1 + include/QF/console.h | 2 +- include/QF/plugin.h | 4 ++ include/QF/plugin/console.h | 50 +++++++++++++++++++++ libs/Makefile.am | 2 +- libs/console/.gitignore | 7 +++ libs/console/Makefile.am | 13 ++++++ libs/console/console.c | 90 +++++++++++++++++++++++++++++++++++++ libs/console/list.c | 84 ++++++++++++++++++++++++++++++++++ nq/source/console.c | 2 +- nq/source/host.c | 2 +- qw/source/cl_main.c | 2 +- qw/source/console.c | 2 +- qw/source/sv_console.c | 2 +- qw/source/sv_main.c | 2 +- 15 files changed, 257 insertions(+), 8 deletions(-) create mode 100644 include/QF/plugin/console.h create mode 100644 libs/console/.gitignore create mode 100644 libs/console/Makefile.am create mode 100644 libs/console/console.c create mode 100644 libs/console/list.c diff --git a/configure.in b/configure.in index 3c689eda3..778b91d75 100644 --- a/configure.in +++ b/configure.in @@ -1371,6 +1371,7 @@ AC_OUTPUT( libs/audio/Makefile libs/audio/cd/Makefile libs/audio/targets/Makefile + libs/console/Makefile libs/gamecode/Makefile libs/gib/Makefile libs/models/Makefile diff --git a/include/QF/console.h b/include/QF/console.h index 7c94b0623..2c5a6592a 100644 --- a/include/QF/console.h +++ b/include/QF/console.h @@ -59,7 +59,7 @@ extern int con_notifylines; // scan lines to clear for notify lines void Con_DrawCharacter (int cx, int line, int num); void Con_CheckResize (void); -void Con_Init (void); +void Con_Init (const char *plugin_name); void Con_Shutdown (void); void Con_Init_Cvars (void); void Con_ProcessInput (void); diff --git a/include/QF/plugin.h b/include/QF/plugin.h index 7588d4911..3223ef131 100644 --- a/include/QF/plugin.h +++ b/include/QF/plugin.h @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -44,6 +45,7 @@ typedef enum { qfp_input, // Input (pointing devices, joysticks, etc) qfp_cd, // CD Audio qfp_sound, // Wave output (OSS, ALSA, Win32) + qfp_console, // Console `driver' } plugin_type_t; typedef struct plugin_funcs_s { @@ -51,6 +53,7 @@ typedef struct plugin_funcs_s { input_funcs_t *input; cd_funcs_t *cd; sound_funcs_t *sound; + console_funcs_t *console; } plugin_funcs_t; typedef struct plugin_data_s { @@ -58,6 +61,7 @@ typedef struct plugin_data_s { input_data_t *input; // cd_data_t *cd; sound_data_t *sound; + console_data_t *console; } plugin_data_t; typedef struct plugin_s { diff --git a/include/QF/plugin/console.h b/include/QF/plugin/console.h new file mode 100644 index 000000000..9d0618421 --- /dev/null +++ b/include/QF/plugin/console.h @@ -0,0 +1,50 @@ +/* + QF/plugin/console.h + + General plugin data and structures + + Copyright (C) 2001 Jeff Teunissen + + 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 + + $Id$ +*/ + +#ifndef __QF_plugin_console_h_ +#define __QF_plugin_console_h_ + +#include + +#include +#include + +typedef void (QFPLUGIN *P_C_Init) (void); +typedef void (QFPLUGIN *P_C_Shutdown) (void); +typedef void (QFPLUGIN *P_C_Print) (const char *fmt, va_list args); + +typedef struct console_func_s { + P_C_Init pC_Init; + P_C_Shutdown pC_Shutdown; + P_C_Print pC_Print; +} console_funcs_t; + +typedef struct console_data_s { +} console_data_t; + +#endif // __QF_plugin_console_h_ diff --git a/libs/Makefile.am b/libs/Makefile.am index 6a132bf04..c0bbcc0ee 100644 --- a/libs/Makefile.am +++ b/libs/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS= audio gamecode gib models video util +SUBDIRS= audio console gamecode gib models video util clean-local: rm -f *.a diff --git a/libs/console/.gitignore b/libs/console/.gitignore new file mode 100644 index 000000000..f4a8d5fec --- /dev/null +++ b/libs/console/.gitignore @@ -0,0 +1,7 @@ +*.la +*.lo +.deps +.libs +.vimrc +Makefile +Makefile.in diff --git a/libs/console/Makefile.am b/libs/console/Makefile.am new file mode 100644 index 000000000..f2fa54587 --- /dev/null +++ b/libs/console/Makefile.am @@ -0,0 +1,13 @@ +SUBDIRS= +INCLUDES= -I$(top_srcdir)/include + +lib_LTLIBRARIES = libQFconsole.la + +common_SOURCES = console.c list.c + +libQFconsole_la_LDFLAGS = -version-info 1:0:0 +libQFconsole_la_LIBADD = +libQFconsole_la_SOURCES = $(common_SOURCES) +libQFconsole_la_DEPENDENCIES = + +LIBLIST = libQFconsole.la diff --git a/libs/console/console.c b/libs/console/console.c new file mode 100644 index 000000000..3d2d54f6a --- /dev/null +++ b/libs/console/console.c @@ -0,0 +1,90 @@ +/* + console.c + + console api + + Copyright (C) 2001 Bill Currie + + Author: Bill Currie + Date: 2001/7/16 + + 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 + + $Id$ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#include + +#include "QF/console.h" +#include "QF/cvar.h" +#include "QF/plugin.h" + +static plugin_t *con_module; + +void +Con_Init (const char *plugin_name) +{ + con_module = PI_LoadPlugin ("console", plugin_name); + if (con_module) { + con_module->functions->console->pC_Init (); + } +} + +void +Con_Init_Cvars (void) +{ +} + +void +Con_Shutdown (void) +{ + if (con_module) { + con_module->functions->console->pC_Shutdown (); + PI_UnloadPlugin (con_module); + } +} + +void +Con_Printf (const char *fmt, ...) +{ + va_list args; + va_start (args, fmt); + if (con_module) + con_module->functions->console->pC_Print (fmt, args); + else + vfprintf (stdout, fmt, args); + va_end (args); +} + +void +Con_DPrintf (const char *fmt, ...) +{ + if (developer && developer->int_val) { + va_list args; + va_start (args, fmt); + if (con_module) + con_module->functions->console->pC_Print (fmt, args); + else + vfprintf (stdout, fmt, args); + va_end (args); + } +} diff --git a/libs/console/list.c b/libs/console/list.c new file mode 100644 index 000000000..232525bf8 --- /dev/null +++ b/libs/console/list.c @@ -0,0 +1,84 @@ +/* + list.c + + pretty print a list of strings to the console + + 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 + + $Id$ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#ifdef HAVE_STRING_H +# include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif + +#include "QF/console.h" + +/* + Con_DisplayList + + New function for tab-completion system + Added by EvilTypeGuy + MEGA Thanks to Taniwha + +*/ +void +Con_DisplayList(const char **list, int con_linewidth) +{ + int i = 0; + int pos = 0; + int len = 0; + int maxlen = 0; + int width = (con_linewidth - 4); + const char **walk = list; + + while (*walk) { + len = strlen(*walk); + if (len > maxlen) + maxlen = len; + walk++; + } + maxlen += 1; + + while (*list) { + len = strlen(*list); + if (pos + maxlen >= width) { + Con_Printf("\n"); + pos = 0; + } + + Con_Printf("%s", *list); + for (i = 0; i < (maxlen - len); i++) + Con_Printf(" "); + + pos += maxlen; + list++; + } + + if (pos) + Con_Printf("\n\n"); +} diff --git a/nq/source/console.c b/nq/source/console.c index 1e3a60f8e..500d846c4 100644 --- a/nq/source/console.c +++ b/nq/source/console.c @@ -217,7 +217,7 @@ Con_CheckResize (void) void -Con_Init (void) +Con_Init (const char *plugin_name) { con_debuglog = COM_CheckParm ("-condebug"); diff --git a/nq/source/host.c b/nq/source/host.c index 822ca485b..698889c26 100644 --- a/nq/source/host.c +++ b/nq/source/host.c @@ -958,7 +958,7 @@ Host_Init (quakeparms_t *parms) Host_InitLocal (); W_LoadWadFile ("gfx.wad"); Key_Init (); - Con_Init (); + Con_Init ("client"); // FIXME: MENUCODE // M_Init (); PR_Init (); diff --git a/qw/source/cl_main.c b/qw/source/cl_main.c index a5a73b955..7f3d853b0 100644 --- a/qw/source/cl_main.c +++ b/qw/source/cl_main.c @@ -1630,7 +1630,7 @@ Host_Init (void) W_LoadWadFile ("gfx.wad"); Key_Init (); - Con_Init (); + Con_Init ("client"); Mod_Init (); // Con_Printf ("Exe: "__TIME__" "__DATE__"\n"); diff --git a/qw/source/console.c b/qw/source/console.c index 1e3a60f8e..500d846c4 100644 --- a/qw/source/console.c +++ b/qw/source/console.c @@ -217,7 +217,7 @@ Con_CheckResize (void) void -Con_Init (void) +Con_Init (const char *plugin_name) { con_debuglog = COM_CheckParm ("-condebug"); diff --git a/qw/source/sv_console.c b/qw/source/sv_console.c index 915f4674b..3e3d47981 100644 --- a/qw/source/sv_console.c +++ b/qw/source/sv_console.c @@ -92,7 +92,7 @@ static const byte attr_map[256] = { }; void -Con_Init (void) +Con_Init (const char *plugin_name) { int i; diff --git a/qw/source/sv_main.c b/qw/source/sv_main.c index 10f4c75bf..e73c04dd7 100644 --- a/qw/source/sv_main.c +++ b/qw/source/sv_main.c @@ -2030,7 +2030,7 @@ SV_Init (void) PI_Init (); - Con_Init (); + Con_Init ("server"); COM_Filesystem_Init_Cvars (); Game_Init_Cvars ();