PageRenderTime 56ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/quakeforge/trunk/libs/gib/gib_init.c

#
C | 120 lines | 72 code | 10 blank | 38 comment | 15 complexity | 3fd536d4d4c60343be407e8d4c2a92ff 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__ ((used))
  25. const char rcsid[] =
  26. "$Id: gib_init.c 11379 2007-03-10 12:00:59Z taniwha $";
  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. #include "gib_object.h"
  44. static void
  45. GIB_Exec_Override_f (void)
  46. {
  47. char *f;
  48. int mark;
  49. if (Cmd_Argc () != 2) {
  50. Sys_Printf ("exec <filename> : execute a script file\n");
  51. return;
  52. }
  53. mark = Hunk_LowMark ();
  54. f = (char *) QFS_LoadHunkFile (Cmd_Argv (1));
  55. if (!f) {
  56. Sys_Printf ("couldn't exec %s\n", Cmd_Argv (1));
  57. return;
  58. }
  59. if (!Cvar_Command ()
  60. && (cmd_warncmd->int_val || (developer && developer->int_val)))
  61. Sys_Printf ("execing %s\n", Cmd_Argv (1));
  62. if ((strlen (Cmd_Argv (1)) >= 4
  63. && !strcmp (Cmd_Argv (1) + strlen (Cmd_Argv (1)) - 4, ".gib"))
  64. || cbuf_active->interpreter == GIB_Interpreter ()) {
  65. // GIB script, put it in a new buffer on the stack
  66. cbuf_t *sub = Cbuf_PushStack (GIB_Interpreter ());
  67. GIB_DATA (sub)->script = malloc (sizeof (gib_script_t));
  68. GIB_DATA (sub)->script->file = strdup (Cmd_Argv (1));
  69. GIB_DATA (sub)->script->text = strdup (f);
  70. GIB_DATA (sub)->script->refs = 1;
  71. Cbuf_AddText (sub, f);
  72. if (gib_parse_error && cbuf_active->interpreter == GIB_Interpreter ())
  73. GIB_Error ("parse", "%s: Parse error while executing %s.",
  74. Cmd_Argv (0), Cmd_Argv (1));
  75. } else
  76. Cbuf_InsertText (cbuf_active, f);
  77. Hunk_FreeToLowMark (mark);
  78. }
  79. VISIBLE void
  80. GIB_Init (qboolean sandbox)
  81. {
  82. // Override the exec command with a GIB-aware one
  83. if (Cmd_Exists ("exec")) {
  84. Cmd_RemoveCommand ("exec");
  85. Cmd_AddCommand ("exec", GIB_Exec_Override_f, "Execute a script file.");
  86. }
  87. // Initialize handle system
  88. GIB_Handle_Init ();
  89. // Initialize variables
  90. GIB_Var_Init ();
  91. // Initialize regex cache
  92. GIB_Regex_Init ();
  93. // Initialize builtins
  94. GIB_Builtin_Init (sandbox);
  95. // Initialize thread system;
  96. GIB_Thread_Init ();
  97. // Initialize event system
  98. GIB_Event_Init ();
  99. // Initialize object system
  100. GIB_Object_Init ();
  101. }