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
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
static char *con_interpreter;
|
|
|
|
static cvar_t con_interpreter_cvar = {
|
|
|
|
.name = "con_interpreter",
|
|
|
|
.description =
|
|
|
|
"Interpreter for the interactive console",
|
|
|
|
.default_value = "id",
|
|
|
|
.flags = CVAR_NONE,
|
2022-04-24 11:04:06 +00:00
|
|
|
.value = { .type = 0, .value = &con_interpreter },
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
};
|
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
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Con_Interp_f (void *data, const cvar_t *cvar)
|
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;
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
interp = Cmd_GetProvider(con_interpreter);
|
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;
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Sys_Printf ("Switching to interpreter '%s'\n", con_interpreter);
|
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 {
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Sys_Printf ("Unknown interpreter '%s'\n", con_interpreter);
|
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);
|
|
|
|
}
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Cvar_Register (&con_interpreter_cvar, Con_Interp_f, 0);
|
2009-03-16 11:49:52 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|