2002-11-09 07:13:52 +00:00
|
|
|
/*
|
|
|
|
#FILENAME#
|
|
|
|
|
|
|
|
#DESCRIPTION#
|
|
|
|
|
|
|
|
Copyright (C) 2002 #AUTHOR#
|
|
|
|
|
|
|
|
Author: #AUTHOR#
|
|
|
|
Date: #DATE#
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2003-01-14 20:18:29 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
static __attribute__ ((used))
|
2003-02-14 22:42:11 +00:00
|
|
|
const char rcsid[] =
|
|
|
|
"$Id$";
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2002-11-09 07:13:52 +00:00
|
|
|
#include <string.h>
|
2003-02-14 08:06:01 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2002-11-09 07:13:52 +00:00
|
|
|
#include "QF/qtypes.h"
|
|
|
|
#include "QF/cbuf.h"
|
|
|
|
#include "QF/quakefs.h"
|
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/zone.h"
|
|
|
|
#include "QF/cvar.h"
|
2003-04-13 22:07:58 +00:00
|
|
|
#include "QF/gib.h"
|
|
|
|
|
|
|
|
#include "gib_parse.h"
|
|
|
|
#include "gib_vars.h"
|
|
|
|
#include "gib_regex.h"
|
|
|
|
#include "gib_builtin.h"
|
|
|
|
#include "gib_thread.h"
|
2003-04-14 01:17:55 +00:00
|
|
|
#include "gib_handle.h"
|
2003-09-11 06:03:13 +00:00
|
|
|
#include "gib_object.h"
|
2002-11-09 07:13:52 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2003-02-14 22:42:11 +00:00
|
|
|
GIB_Exec_Override_f (void)
|
|
|
|
{
|
2002-11-09 07:13:52 +00:00
|
|
|
char *f;
|
|
|
|
int mark;
|
|
|
|
|
|
|
|
if (Cmd_Argc () != 2) {
|
|
|
|
Sys_Printf ("exec <filename> : execute a script file\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mark = Hunk_LowMark ();
|
2003-02-14 19:46:07 +00:00
|
|
|
f = (char *) QFS_LoadHunkFile (Cmd_Argv (1));
|
2002-11-09 07:13:52 +00:00
|
|
|
if (!f) {
|
|
|
|
Sys_Printf ("couldn't exec %s\n", Cmd_Argv (1));
|
|
|
|
return;
|
|
|
|
}
|
2003-02-14 22:42:11 +00:00
|
|
|
if (!Cvar_Command ()
|
|
|
|
&& (cmd_warncmd->int_val || (developer && developer->int_val)))
|
2002-11-09 07:13:52 +00:00
|
|
|
Sys_Printf ("execing %s\n", Cmd_Argv (1));
|
2005-03-24 15:00:37 +00:00
|
|
|
if ((strlen (Cmd_Argv (1)) >= 4
|
|
|
|
&& !strcmp (Cmd_Argv (1) + strlen (Cmd_Argv (1)) - 4, ".gib"))
|
2003-04-13 22:07:58 +00:00
|
|
|
|| cbuf_active->interpreter == GIB_Interpreter ()) {
|
2002-11-09 07:13:52 +00:00
|
|
|
// GIB script, put it in a new buffer on the stack
|
2003-04-13 22:07:58 +00:00
|
|
|
cbuf_t *sub = Cbuf_PushStack (GIB_Interpreter ());
|
2003-02-14 22:42:11 +00:00
|
|
|
|
|
|
|
GIB_DATA (sub)->script = malloc (sizeof (gib_script_t));
|
|
|
|
GIB_DATA (sub)->script->file = strdup (Cmd_Argv (1));
|
|
|
|
GIB_DATA (sub)->script->text = strdup (f);
|
|
|
|
GIB_DATA (sub)->script->refs = 1;
|
2002-11-09 07:13:52 +00:00
|
|
|
Cbuf_AddText (sub, f);
|
2003-04-13 22:07:58 +00:00
|
|
|
if (gib_parse_error && cbuf_active->interpreter == GIB_Interpreter ())
|
2003-02-14 22:42:11 +00:00
|
|
|
GIB_Error ("parse", "%s: Parse error while executing %s.",
|
|
|
|
Cmd_Argv (0), Cmd_Argv (1));
|
2002-11-09 07:13:52 +00:00
|
|
|
} else
|
|
|
|
Cbuf_InsertText (cbuf_active, f);
|
|
|
|
Hunk_FreeToLowMark (mark);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-11-14 05:28:54 +00:00
|
|
|
GIB_Init (qboolean sandbox)
|
2002-11-09 07:13:52 +00:00
|
|
|
{
|
|
|
|
// Override the exec command with a GIB-aware one
|
2003-02-14 22:42:11 +00:00
|
|
|
if (Cmd_Exists ("exec")) {
|
2002-11-09 07:13:52 +00:00
|
|
|
Cmd_RemoveCommand ("exec");
|
|
|
|
Cmd_AddCommand ("exec", GIB_Exec_Override_f, "Execute a script file.");
|
|
|
|
}
|
2003-04-14 01:17:55 +00:00
|
|
|
// Initialize handle system
|
|
|
|
GIB_Handle_Init ();
|
2003-01-28 21:16:21 +00:00
|
|
|
// Initialize variables
|
|
|
|
GIB_Var_Init ();
|
2002-11-19 06:24:29 +00:00
|
|
|
// Initialize regex cache
|
|
|
|
GIB_Regex_Init ();
|
2002-11-09 07:13:52 +00:00
|
|
|
// Initialize builtins
|
2002-11-14 05:28:54 +00:00
|
|
|
GIB_Builtin_Init (sandbox);
|
2003-09-11 06:03:13 +00:00
|
|
|
// Initialize thread system;
|
|
|
|
GIB_Thread_Init ();
|
2003-01-03 04:30:38 +00:00
|
|
|
// Initialize event system
|
|
|
|
GIB_Event_Init ();
|
2003-09-11 06:03:13 +00:00
|
|
|
// Initialize object system
|
|
|
|
GIB_Object_Init ();
|
2002-11-09 07:13:52 +00:00
|
|
|
}
|