PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/quakeforge/branches/release_0_5_3/libs/gib/gib_init.c

#
C | 115 lines | 68 code | 11 blank | 36 comment | 14 complexity | dbe8b999842e1c91775ec0a0083d1ed8 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-3.0, AGPL-1.0, Unlicense
  1. /*
  2. #FILENAME#
  3. #DESCRIPTION#
  4. Copyright (C) 2002 #AUTHOR#
  5. Author: #AUTHOR#
  6. Date: #DATE#
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. See the GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to:
  17. Free Software Foundation, Inc.
  18. 59 Temple Place - Suite 330
  19. Boston, MA 02111-1307, USA
  20. */
  21. #ifdef HAVE_CONFIG_H
  22. # include "config.h"
  23. #endif
  24. static __attribute__ ((unused))
  25. const char rcsid[] =
  26. "$Id: gib_init.c 9483 2003-04-14 01:17:55Z snax $";
  27. #include <string.h>
  28. #include <stdlib.h>
  29. #include "QF/qtypes.h"
  30. #include "QF/cbuf.h"
  31. #include "QF/quakefs.h"
  32. #include "QF/cmd.h"
  33. #include "QF/sys.h"
  34. #include "QF/zone.h"
  35. #include "QF/cvar.h"
  36. #include "QF/gib.h"
  37. #include "gib_parse.h"
  38. #include "gib_vars.h"
  39. #include "gib_regex.h"
  40. #include "gib_builtin.h"
  41. #include "gib_thread.h"
  42. #include "gib_handle.h"
  43. static void
  44. GIB_Exec_Override_f (void)
  45. {
  46. char *f;
  47. int mark;
  48. if (Cmd_Argc () != 2) {
  49. Sys_Printf ("exec <filename> : execute a script file\n");
  50. return;
  51. }
  52. mark = Hunk_LowMark ();
  53. f = (char *) QFS_LoadHunkFile (Cmd_Argv (1));
  54. if (!f) {
  55. Sys_Printf ("couldn't exec %s\n", Cmd_Argv (1));
  56. return;
  57. }
  58. if (!Cvar_Command ()
  59. && (cmd_warncmd->int_val || (developer && developer->int_val)))
  60. Sys_Printf ("execing %s\n", Cmd_Argv (1));
  61. if (!strcmp (Cmd_Argv (1) + strlen (Cmd_Argv (1)) - 4, ".gib")
  62. || cbuf_active->interpreter == GIB_Interpreter ()) {
  63. // GIB script, put it in a new buffer on the stack
  64. cbuf_t *sub = Cbuf_PushStack (GIB_Interpreter ());
  65. GIB_DATA (sub)->script = malloc (sizeof (gib_script_t));
  66. GIB_DATA (sub)->script->file = strdup (Cmd_Argv (1));
  67. GIB_DATA (sub)->script->text = strdup (f);
  68. GIB_DATA (sub)->script->refs = 1;
  69. Cbuf_AddText (sub, f);
  70. if (gib_parse_error && cbuf_active->interpreter == GIB_Interpreter ())
  71. GIB_Error ("parse", "%s: Parse error while executing %s.",
  72. Cmd_Argv (0), Cmd_Argv (1));
  73. } else
  74. Cbuf_InsertText (cbuf_active, f);
  75. Hunk_FreeToLowMark (mark);
  76. }
  77. void
  78. GIB_Init (qboolean sandbox)
  79. {
  80. // Override the exec command with a GIB-aware one
  81. if (Cmd_Exists ("exec")) {
  82. Cmd_RemoveCommand ("exec");
  83. Cmd_AddCommand ("exec", GIB_Exec_Override_f, "Execute a script file.");
  84. }
  85. // Initialize handle system
  86. GIB_Handle_Init ();
  87. // Initialize variables
  88. GIB_Var_Init ();
  89. // Initialize regex cache
  90. GIB_Regex_Init ();
  91. // Initialize builtins
  92. GIB_Builtin_Init (sandbox);
  93. // Initialize event system
  94. GIB_Event_Init ();
  95. }