2001-07-16 20:41:10 +00:00
|
|
|
/*
|
|
|
|
console.c
|
|
|
|
|
|
|
|
console api
|
|
|
|
|
|
|
|
Copyright (C) 2001 Bill Currie <bill@taniwha.org>
|
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2001-09-10 12:56:23 +00:00
|
|
|
|
2001-07-16 20:41:10 +00:00
|
|
|
#include <stdarg.h>
|
2001-08-09 12:19:15 +00:00
|
|
|
#include <stdio.h>
|
2001-07-16 20:41:10 +00:00
|
|
|
|
2001-10-02 03:24:36 +00:00
|
|
|
#include "QF/cmd.h"
|
2001-07-16 20:41:10 +00:00
|
|
|
#include "QF/console.h"
|
|
|
|
#include "QF/cvar.h"
|
2001-09-21 04:22:46 +00:00
|
|
|
#include "QF/sys.h"
|
2001-07-16 20:41:10 +00:00
|
|
|
|
2012-02-13 12:58:34 +00:00
|
|
|
#include "QF/plugin/general.h"
|
|
|
|
#include "QF/plugin/console.h"
|
|
|
|
|
2021-06-12 13:50:51 +00:00
|
|
|
#include "QF/ui/inputline.h"
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
//FIXME probably shouldn't be visible
|
2007-04-07 02:14:22 +00:00
|
|
|
VISIBLE int con_linewidth; // characters across screen
|
2001-07-16 20:41:10 +00:00
|
|
|
|
2007-04-07 02:14:22 +00:00
|
|
|
VISIBLE plugin_t *con_module;
|
2001-09-10 12:56:23 +00:00
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
#define U __attribute__ ((used))
|
2003-04-17 00:01:48 +00:00
|
|
|
static U con_buffer_t *(*const buffer) (size_t, int) = Con_CreateBuffer;
|
|
|
|
static U void (*const complete)(inputline_t *) = Con_BasicCompleteCommandLine;
|
|
|
|
static U inputline_t *(*const create)(int, int, char) = Con_CreateInputLine;
|
|
|
|
static U void (*const display)(const char **, int) = Con_DisplayList;
|
|
|
|
#undef U
|
2001-09-25 20:16:24 +00:00
|
|
|
|
2007-03-18 03:48:09 +00:00
|
|
|
static cvar_t *con_interpreter;
|
2021-12-29 12:50:38 +00:00
|
|
|
static sys_printf_t saved_sys_printf;
|
2007-03-18 03:48:09 +00:00
|
|
|
|
|
|
|
static void
|
2007-04-07 02:14:22 +00:00
|
|
|
Con_Interp_f (cvar_t *var)
|
2007-03-18 03:48:09 +00:00
|
|
|
{
|
2010-03-12 10:51:07 +00:00
|
|
|
cbuf_interpreter_t *interp;
|
|
|
|
|
2009-03-16 11:49:52 +00:00
|
|
|
if (!con_module)
|
|
|
|
return;
|
|
|
|
|
2010-03-12 10:51:07 +00:00
|
|
|
interp = Cmd_GetProvider(var->string);
|
2007-03-23 13:13:26 +00:00
|
|
|
|
2009-03-16 11:49:52 +00:00
|
|
|
if (interp) {
|
2007-03-22 23:20:57 +00:00
|
|
|
cbuf_t *new;
|
|
|
|
|
2007-03-23 13:13:26 +00:00
|
|
|
Sys_Printf ("Switching to interpreter '%s'\n", var->string);
|
2007-03-22 23:20:57 +00:00
|
|
|
|
2007-03-23 13:13:26 +00:00
|
|
|
new = Cbuf_New (interp);
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2007-03-23 13:13:26 +00:00
|
|
|
if (con_module->data->console->cbuf) {
|
2007-03-18 03:48:09 +00:00
|
|
|
new->down = con_module->data->console->cbuf;
|
|
|
|
new->state = CBUF_STATE_STACK;
|
|
|
|
con_module->data->console->cbuf->up = new;
|
|
|
|
}
|
|
|
|
con_module->data->console->cbuf = new;
|
2007-03-23 13:13:26 +00:00
|
|
|
} else {
|
|
|
|
Sys_Printf ("Unknown interpreter '%s'\n", var->string);
|
2007-03-18 07:12:23 +00:00
|
|
|
}
|
2007-03-18 03:48:09 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 14:15:26 +00:00
|
|
|
static void
|
2020-06-25 05:03:52 +00:00
|
|
|
Con_shutdown (void *data)
|
2019-07-12 14:15:26 +00:00
|
|
|
{
|
2021-12-29 12:50:38 +00:00
|
|
|
if (saved_sys_printf) {
|
|
|
|
Sys_SetStdPrintf (saved_sys_printf);
|
|
|
|
}
|
2019-07-12 14:15:26 +00:00
|
|
|
if (con_module) {
|
2021-06-22 10:47:20 +00:00
|
|
|
con_module->functions->general->shutdown ();
|
2019-07-12 14:15:26 +00:00
|
|
|
PI_UnloadPlugin (con_module);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-16 11:49:52 +00:00
|
|
|
VISIBLE void
|
|
|
|
Con_Init (const char *plugin_name)
|
|
|
|
{
|
2020-06-25 05:03:52 +00:00
|
|
|
Sys_RegisterShutdown (Con_shutdown, 0);
|
2019-07-12 14:15:26 +00:00
|
|
|
|
2009-03-16 11:49:52 +00:00
|
|
|
con_module = PI_LoadPlugin ("console", plugin_name);
|
|
|
|
if (con_module) {
|
2021-12-29 12:50:38 +00:00
|
|
|
__auto_type funcs = con_module->functions->console;
|
|
|
|
saved_sys_printf = Sys_SetStdPrintf (funcs->print);
|
2009-03-16 11:49:52 +00:00
|
|
|
} else {
|
|
|
|
setvbuf (stdout, 0, _IOLBF, BUFSIZ);
|
|
|
|
}
|
2012-05-21 23:23:22 +00:00
|
|
|
con_interpreter =
|
2009-03-16 11:49:52 +00:00
|
|
|
Cvar_Get("con_interpreter", "id", CVAR_NONE, Con_Interp_f,
|
|
|
|
"Interpreter for the interactive console");
|
|
|
|
}
|
|
|
|
|
2007-04-07 05:50:29 +00:00
|
|
|
VISIBLE void
|
|
|
|
Con_ExecLine (const char *line)
|
|
|
|
{
|
|
|
|
console_data_t *cd = con_module->data->console;
|
|
|
|
int echo = 1;
|
|
|
|
if (line[0] == '/' && line [1] == '/') {
|
|
|
|
goto no_lf;
|
|
|
|
} else if (line[0] == '|') {
|
|
|
|
Cbuf_AddText (cd->cbuf, line);
|
|
|
|
Cbuf_AddText (cd->cbuf, "\n");
|
2010-01-13 06:51:13 +00:00
|
|
|
} else if (line[0] == '/') {
|
2007-04-07 05:50:29 +00:00
|
|
|
Cbuf_AddText (cd->cbuf, line + 1);
|
|
|
|
Cbuf_AddText (cd->cbuf, "\n");
|
|
|
|
} else if (cd->exec_line) {
|
|
|
|
echo = cd->exec_line (cd->exec_data, line);
|
|
|
|
} else {
|
|
|
|
Cbuf_AddText (cd->cbuf, line);
|
|
|
|
Cbuf_AddText (cd->cbuf, "\n");
|
|
|
|
}
|
|
|
|
no_lf:
|
|
|
|
if (echo)
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("%s\n", line);
|
2007-04-07 05:50:29 +00:00
|
|
|
}
|
|
|
|
|
2007-04-07 02:14:22 +00:00
|
|
|
VISIBLE void
|
2007-11-07 08:19:17 +00:00
|
|
|
Con_Printf (const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start (args, fmt);
|
|
|
|
if (con_module)
|
2021-06-22 10:47:20 +00:00
|
|
|
con_module->functions->console->print (fmt, args);
|
2007-11-07 08:19:17 +00:00
|
|
|
else
|
|
|
|
vfprintf (stdout, fmt, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
|
|
|
|
VISIBLE void
|
2002-01-17 02:47:22 +00:00
|
|
|
Con_Print (const char *fmt, va_list args)
|
|
|
|
{
|
|
|
|
if (con_module)
|
2021-06-22 10:47:20 +00:00
|
|
|
con_module->functions->console->print (fmt, args);
|
2002-01-17 02:47:22 +00:00
|
|
|
else
|
|
|
|
vfprintf (stdout, fmt, args);
|
|
|
|
}
|
|
|
|
|
2021-11-08 02:20:04 +00:00
|
|
|
VISIBLE void
|
|
|
|
Con_SetState (con_state_t state)
|
|
|
|
{
|
|
|
|
if (con_module) {
|
|
|
|
con_module->functions->console->set_state (state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-07 02:14:22 +00:00
|
|
|
VISIBLE void
|
2001-09-16 05:41:28 +00:00
|
|
|
Con_ProcessInput (void)
|
|
|
|
{
|
2001-12-02 20:11:21 +00:00
|
|
|
if (con_module) {
|
2021-06-22 10:47:20 +00:00
|
|
|
con_module->functions->console->process_input ();
|
2001-12-02 20:11:21 +00:00
|
|
|
} else {
|
|
|
|
static int been_there_done_that = 0;
|
|
|
|
|
|
|
|
if (!been_there_done_that) {
|
|
|
|
been_there_done_that = 1;
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("no input for you\n");
|
2001-12-02 20:11:21 +00:00
|
|
|
}
|
|
|
|
}
|
2001-09-16 05:41:28 +00:00
|
|
|
}
|
2002-01-16 21:53:42 +00:00
|
|
|
|
2007-04-07 02:14:22 +00:00
|
|
|
VISIBLE void
|
2002-01-16 21:53:42 +00:00
|
|
|
Con_SetOrMask (int mask)
|
|
|
|
{
|
|
|
|
if (con_module)
|
|
|
|
con_module->data->console->ormask = mask;
|
|
|
|
}
|
|
|
|
|
2007-04-07 02:14:22 +00:00
|
|
|
VISIBLE void
|
2003-07-25 22:21:47 +00:00
|
|
|
Con_DrawConsole (void)
|
2002-01-16 21:53:42 +00:00
|
|
|
{
|
|
|
|
if (con_module)
|
2021-06-22 10:47:20 +00:00
|
|
|
con_module->functions->console->draw_console ();
|
2002-01-16 21:53:42 +00:00
|
|
|
}
|
|
|
|
|
2007-04-07 02:14:22 +00:00
|
|
|
VISIBLE void
|
2002-01-16 21:53:42 +00:00
|
|
|
Con_CheckResize (void)
|
|
|
|
{
|
|
|
|
if (con_module)
|
2021-06-22 10:47:20 +00:00
|
|
|
con_module->functions->console->check_resize ();
|
2002-01-16 21:53:42 +00:00
|
|
|
}
|
2002-01-18 19:19:33 +00:00
|
|
|
|
2007-04-07 02:14:22 +00:00
|
|
|
VISIBLE void
|
2002-01-18 19:19:33 +00:00
|
|
|
Con_NewMap (void)
|
|
|
|
{
|
|
|
|
if (con_module)
|
2021-06-22 10:47:20 +00:00
|
|
|
con_module->functions->console->new_map ();
|
2002-01-18 19:19:33 +00:00
|
|
|
}
|