From e7ffad87722796a687603bea76215e33ebc1877c Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 16 Jan 2004 07:03:58 +0000 Subject: [PATCH] more rua cleanups: now just one init function to call (it calls the rest) --- include/Makefile.am | 4 +-- include/QF/ruamoko.h | 29 ++----------------- include/rua_internal.h | 60 +++++++++++++++++++++++++++++++++++++++ libs/console/menu.c | 14 ++------- libs/ruamoko/rua_cbuf.c | 5 ++-- libs/ruamoko/rua_cmd.c | 5 ++-- libs/ruamoko/rua_cvar.c | 5 ++-- libs/ruamoko/rua_file.c | 5 ++-- libs/ruamoko/rua_hash.c | 5 ++-- libs/ruamoko/rua_init.c | 32 ++++++++++++--------- libs/ruamoko/rua_plist.c | 5 ++-- libs/ruamoko/rua_qfile.c | 3 +- libs/ruamoko/rua_qfs.c | 5 ++-- libs/ruamoko/rua_string.c | 5 ++-- nq/source/host.c | 2 -- nq/source/sv_pr_cmds.c | 5 +++- qw/source/cl_main.c | 1 - qw/source/sv_pr_cmds.c | 7 +++-- qw/source/sv_progs.c | 4 --- 19 files changed, 121 insertions(+), 80 deletions(-) create mode 100644 include/rua_internal.h diff --git a/include/Makefile.am b/include/Makefile.am index 00dcf18ff..0a0189b90 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -9,8 +9,8 @@ EXTRA_DIST = asm_i386.h alsa_funcs_list.h adivtab.h anorm_dots.h anorms.h \ gib_thread.h gib_tree.h gib_vars.h gl_warp_sin.h in_win.h logos.h menu.h \ net_dgrm.h net_loop.h net_udp.h net_vcr.h net_wins.h netchan.h netmain.h \ old_keys.h ops.h qstring.h quakeasm.h regex.h r_cvar.h r_dynamic.h \ - r_local.h r_screen.h r_shared.h sbar.h skin_stencil.h snd_render.h \ - varrays.h vgamodes.h view.h vregset.h winquake.h world.h \ + r_local.h r_screen.h r_shared.h rua_internal.h sbar.h skin_stencil.h \ + snd_render.h varrays.h vgamodes.h view.h vregset.h winquake.h world.h \ \ win32/fnmatch.h \ \ diff --git a/include/QF/ruamoko.h b/include/QF/ruamoko.h index fb65fcca4..8cf315b38 100644 --- a/include/QF/ruamoko.h +++ b/include/QF/ruamoko.h @@ -32,35 +32,10 @@ #ifndef __QF_ruamoko_h #define __QF_ruamoko_h - struct progs_s; struct cbuf_s; -void RUA_Init (void); - -void RUA_Cbuf_Init (struct progs_s *pr); -void Cbuf_Progs_SetCbuf (struct progs_s *pr, struct cbuf_s *cbuf); - -void RUA_Cmd_Init (struct progs_s *pr); - -void RUA_Cvar_Init (struct progs_s *pr); - -void RUA_File_Init (struct progs_s *pr); - -void RUA_Hash_Init (struct progs_s *pr); - -void RUA_Plist_Init (struct progs_s *pr); - -void RUA_String_Init (struct progs_s *pr); - -#include "QF/quakeio.h" -#define QFILE_MAX_HANDLES 20 -typedef struct { - QFile *handles[QFILE_MAX_HANDLES]; -} qfile_resources_t; - -void RUA_QFile_Init (struct progs_s *pr, int secure); -QFile **QFile_AllocHandle (struct progs_s *pr, qfile_resources_t *res); -void RUA_QFS_Init (struct progs_s *pr); +void RUA_Init (struct progs_s *pr, int secure); +void RUA_Cbuf_SetCbuf (struct progs_s *pr, struct cbuf_s *cbuf); #endif//__QF_ruamoko_h diff --git a/include/rua_internal.h b/include/rua_internal.h new file mode 100644 index 000000000..3e2055b21 --- /dev/null +++ b/include/rua_internal.h @@ -0,0 +1,60 @@ +/* + rua_internal.h + + ruamoko internal prototypes + + Copyright (C) 2001 Bill Currie + + Author: Bill Currie + Date: 2003/1/15 + + 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 + + $Id$ +*/ + +#ifndef __rua_internal_h +#define __rua_internal_h + +#include "QF/quakeio.h" +#define QFILE_MAX_HANDLES 20 +typedef struct { + QFile *handles[QFILE_MAX_HANDLES]; +} qfile_resources_t; + +void RUA_Cbuf_Init (struct progs_s *pr, int secure); + +void RUA_Cmd_Init (struct progs_s *pr, int secure); + +void RUA_Cvar_Init (struct progs_s *pr, int secure); + +void RUA_File_Init (struct progs_s *pr, int secure); + +void RUA_Hash_Init (struct progs_s *pr, int secure); + +void RUA_Plist_Init (struct progs_s *pr, int secure); + +void RUA_String_Init (struct progs_s *pr, int secure); + +void RUA_QFile_Init (struct progs_s *pr, int secure); +QFile **QFile_AllocHandle (struct progs_s *pr, qfile_resources_t *res); + +void RUA_QFS_Init (struct progs_s *pr, int secure); + +#endif//__rua_internal_h diff --git a/libs/console/menu.c b/libs/console/menu.c index e242898d2..93699c398 100644 --- a/libs/console/menu.c +++ b/libs/console/menu.c @@ -445,28 +445,20 @@ Menu_Init (void) menu_pr_state.free_progs_mem = menu_free_progs_mem; menu_pr_state.load_file = menu_load_file; - PR_Resources_Init (&menu_pr_state); - menu_hash = Hash_NewTable (61, menu_get_key, menu_free, 0); PR_RegisterBuiltins (&menu_pr_state, builtins); PR_Obj_Progs_Init (&menu_pr_state); + RUA_Init (&menu_pr_state, 1); + InputLine_Progs_Init (&menu_pr_state); Key_Progs_Init (&menu_pr_state); GIB_Progs_Init (&menu_pr_state); PR_Cmds_Init (&menu_pr_state); R_Progs_Init (&menu_pr_state); - RUA_Cbuf_Init (&menu_pr_state); - RUA_Cmd_Init (&menu_pr_state); - RUA_Cvar_Init (&menu_pr_state); - RUA_File_Init (&menu_pr_state); - RUA_QFile_Init (&menu_pr_state, 1); - RUA_QFS_Init (&menu_pr_state); - RUA_String_Init (&menu_pr_state); - PR_AddLoadFunc (&menu_pr_state, menu_resolve_globals); confirm_quit = Cvar_Get ("confirm_quit", "1", CVAR_ARCHIVE, NULL, @@ -508,7 +500,7 @@ Menu_Load (void) Con_SetOrMask (0x00); return; } - Cbuf_Progs_SetCbuf (&menu_pr_state, con_data.cbuf); + RUA_Cbuf_SetCbuf (&menu_pr_state, con_data.cbuf); InputLine_Progs_SetDraw (&menu_pr_state, C_DrawInputLine); PR_ExecuteProgram (&menu_pr_state, menu_init); } diff --git a/libs/ruamoko/rua_cbuf.c b/libs/ruamoko/rua_cbuf.c index 010254e8e..39570412b 100644 --- a/libs/ruamoko/rua_cbuf.c +++ b/libs/ruamoko/rua_cbuf.c @@ -38,6 +38,7 @@ static __attribute__ ((unused)) const char rcsid[] = #include "QF/progs.h" #include "QF/ruamoko.h" +#include "rua_internal.h" typedef struct { cbuf_t *cbuf; @@ -111,7 +112,7 @@ static builtin_t builtins[] = { }; void -RUA_Cbuf_Init (progs_t *pr) +RUA_Cbuf_Init (progs_t *pr, int secure) { cbuf_resources_t *res = calloc (sizeof (cbuf_resources_t), 1); PR_Resources_Register (pr, "Cbuf", res, bi_cbuf_clear); @@ -119,7 +120,7 @@ RUA_Cbuf_Init (progs_t *pr) } void -Cbuf_Progs_SetCbuf (progs_t *pr, cbuf_t *cbuf) +RUA_Cbuf_SetCbuf (progs_t *pr, cbuf_t *cbuf) { cbuf_resources_t *res = PR_Resources_Find (pr, "Cbuf"); res->cbuf = cbuf; diff --git a/libs/ruamoko/rua_cmd.c b/libs/ruamoko/rua_cmd.c index 69f8c803c..be8a670ae 100644 --- a/libs/ruamoko/rua_cmd.c +++ b/libs/ruamoko/rua_cmd.c @@ -45,9 +45,10 @@ static __attribute__ ((unused)) const char rcsid[] = #include "QF/cmd.h" #include "QF/hash.h" #include "QF/progs.h" -#include "QF/ruamoko.h" #include "QF/sys.h" +#include "rua_internal.h" + typedef struct bi_cmd_s { struct bi_cmd_s *next; char *name; @@ -156,7 +157,7 @@ static builtin_t builtins[] = { }; void -RUA_Cmd_Init (progs_t *pr) +RUA_Cmd_Init (progs_t *pr, int secure) { cmd_resources_t *res = malloc (sizeof (cmd_resources_t)); diff --git a/libs/ruamoko/rua_cvar.c b/libs/ruamoko/rua_cvar.c index 3f33e1c63..b6c1a3445 100644 --- a/libs/ruamoko/rua_cvar.c +++ b/libs/ruamoko/rua_cvar.c @@ -40,9 +40,10 @@ static __attribute__ ((unused)) const char rcsid[] = #include "QF/cvar.h" #include "QF/progs.h" -#include "QF/ruamoko.h" #include "QF/zone.h" +#include "rua_internal.h" + /* bi_Cvar_GetCvarString @@ -62,7 +63,7 @@ static builtin_t builtins[] = { }; void -RUA_Cvar_Init (progs_t *pr) +RUA_Cvar_Init (progs_t *pr, int secure) { PR_RegisterBuiltins (pr, builtins); } diff --git a/libs/ruamoko/rua_file.c b/libs/ruamoko/rua_file.c index fce84cb5b..b72468452 100644 --- a/libs/ruamoko/rua_file.c +++ b/libs/ruamoko/rua_file.c @@ -56,10 +56,11 @@ int fnmatch (const char *__pattern, const char *__string, int __flags); #include "QF/cvar.h" #include "QF/progs.h" #include "QF/quakefs.h" -#include "QF/ruamoko.h" #include "QF/va.h" #include "QF/zone.h" +#include "rua_internal.h" + static const char *file_ban_list[] = { "default.cfg{,.gz}", "demo1.dem{,.gz}", @@ -179,7 +180,7 @@ static builtin_t builtins[] = { }; void -RUA_File_Init (progs_t *pr) +RUA_File_Init (progs_t *pr, int secure) { PR_RegisterBuiltins (pr, builtins); } diff --git a/libs/ruamoko/rua_hash.c b/libs/ruamoko/rua_hash.c index 924caa3e9..1f67085e6 100644 --- a/libs/ruamoko/rua_hash.c +++ b/libs/ruamoko/rua_hash.c @@ -44,7 +44,8 @@ static __attribute__ ((unused)) const char rcsid[] = #include "QF/hash.h" #include "QF/progs.h" -#include "QF/ruamoko.h" + +#include "rua_internal.h" typedef struct bi_hashtab_s { struct bi_hashtab_s *next; @@ -325,7 +326,7 @@ static builtin_t builtins[] = { }; void -RUA_Hash_Init (progs_t *pr) +RUA_Hash_Init (progs_t *pr, int secure) { hash_resources_t *res = malloc (sizeof (hash_resources_t)); res->tabs = 0; diff --git a/libs/ruamoko/rua_init.c b/libs/ruamoko/rua_init.c index 928c5256a..fee428255 100644 --- a/libs/ruamoko/rua_init.c +++ b/libs/ruamoko/rua_init.c @@ -34,20 +34,26 @@ static __attribute__ ((unused)) const char rcsid[] = #include "QF/progs.h" #include "QF/ruamoko.h" -#define U __attribute__ ((unused)) -static U void (*const cbuf_progs_init)(progs_t *) = RUA_Cbuf_Init; -static U void (*const cmd_progs_init)(progs_t *) = RUA_Cmd_Init; -static U void (*const cvar_progs_init)(progs_t *) = RUA_Cvar_Init; -static U void (*const file_progs_init)(progs_t *) = RUA_File_Init; -static U void (*const hash_progs_init)(progs_t *) = RUA_Hash_Init; -static U void (*const plist_progs_init)(progs_t *) = RUA_Plist_Init; -static U void (*const qfile_progs_init)(progs_t *, int) = RUA_QFile_Init; -static U void (*const qfs_progs_init)(progs_t *) = RUA_QFS_Init; -static U void (*const string_progs_init)(progs_t *) = RUA_String_Init; -#undef U +#include "rua_internal.h" + +static void (*init_funcs[])(progs_t *, int) = { + RUA_Cbuf_Init, + RUA_Cmd_Init, + RUA_Cvar_Init, + RUA_File_Init, + RUA_Hash_Init, + RUA_Plist_Init, + RUA_QFile_Init, + RUA_QFS_Init, + RUA_String_Init, +}; void -RUA_Init (void) +RUA_Init (progs_t *pr, int secure) { - // do nothing stub for now. used to force linking + int i; + + PR_Resources_Init (pr); + for (i = 0; i < sizeof (init_funcs) / sizeof (init_funcs[0]); i++) + init_funcs[i] (pr, secure); } diff --git a/libs/ruamoko/rua_plist.c b/libs/ruamoko/rua_plist.c index be60f3ad1..d2581f7fc 100644 --- a/libs/ruamoko/rua_plist.c +++ b/libs/ruamoko/rua_plist.c @@ -45,7 +45,8 @@ static __attribute__ ((unused)) const char rcsid[] = #include "QF/hash.h" #include "QF/progs.h" #include "QF/qfplist.h" -#include "QF/ruamoko.h" + +#include "rua_internal.h" typedef struct { hashtab_t *items; @@ -184,7 +185,7 @@ static builtin_t builtins[] = { }; void -RUA_Plist_Init (progs_t *pr) +RUA_Plist_Init (progs_t *pr, int secure) { plist_resources_t *res = malloc (sizeof (plist_resources_t)); res->items = Hash_NewTable (1021, 0, 0, 0); diff --git a/libs/ruamoko/rua_qfile.c b/libs/ruamoko/rua_qfile.c index cdf7fb1a3..646c7f9a3 100644 --- a/libs/ruamoko/rua_qfile.c +++ b/libs/ruamoko/rua_qfile.c @@ -41,10 +41,11 @@ static __attribute__ ((unused)) const char rcsid[] = #include "QF/progs.h" #include "QF/quakefs.h" -#include "QF/ruamoko.h" #include "QF/va.h" #include "QF/zone.h" +#include "rua_internal.h" + static void bi_qfile_clear (progs_t *pr, void *data) { diff --git a/libs/ruamoko/rua_qfs.c b/libs/ruamoko/rua_qfs.c index ea736014a..486458f01 100644 --- a/libs/ruamoko/rua_qfs.c +++ b/libs/ruamoko/rua_qfs.c @@ -41,10 +41,11 @@ static __attribute__ ((unused)) const char rcsid[] = #include "QF/progs.h" #include "QF/quakefs.h" -#include "QF/ruamoko.h" #include "QF/va.h" #include "QF/zone.h" +#include "rua_internal.h" + static void check_buffer (progs_t *pr, pr_type_t *buf, int count, const char *name) { @@ -125,7 +126,7 @@ static builtin_t builtins[] = { }; void -RUA_QFS_Init (progs_t *pr) +RUA_QFS_Init (progs_t *pr, int secure) { PR_RegisterBuiltins (pr, builtins); } diff --git a/libs/ruamoko/rua_string.c b/libs/ruamoko/rua_string.c index 388f2b01a..cdf585a06 100644 --- a/libs/ruamoko/rua_string.c +++ b/libs/ruamoko/rua_string.c @@ -44,7 +44,8 @@ static __attribute__ ((unused)) const char rcsid[] = #include "QF/dstring.h" #include "QF/progs.h" -#include "QF/ruamoko.h" + +#include "rua_internal.h" static void bi_str_new (progs_t *pr) @@ -86,7 +87,7 @@ static builtin_t builtins[] = { }; void -RUA_String_Init (progs_t *pr) +RUA_String_Init (progs_t *pr, int secure) { PR_RegisterBuiltins (pr, builtins); } diff --git a/nq/source/host.c b/nq/source/host.c index 0bf33bbc3..bfb544e95 100644 --- a/nq/source/host.c +++ b/nq/source/host.c @@ -44,7 +44,6 @@ static __attribute__ ((unused)) const char rcsid[] = #include "QF/plugin.h" #include "QF/progs.h" #include "QF/qargs.h" -#include "QF/ruamoko.h" #include "QF/screen.h" #include "QF/sys.h" #include "QF/va.h" @@ -917,7 +916,6 @@ Host_Init (void) V_Init_Cvars (); PR_Init (); - RUA_Init (); V_Init (); Game_Init (); diff --git a/nq/source/sv_pr_cmds.c b/nq/source/sv_pr_cmds.c index fbadde278..9c376095d 100644 --- a/nq/source/sv_pr_cmds.c +++ b/nq/source/sv_pr_cmds.c @@ -44,6 +44,7 @@ static __attribute__ ((unused)) const char rcsid[] = #include "QF/console.h" #include "QF/cvar.h" #include "QF/msg.h" +#include "QF/ruamoko.h" #include "QF/sys.h" #include "QF/va.h" @@ -1411,8 +1412,10 @@ static builtin_t builtins[] = { void SV_PR_Cmds_Init () { - PR_Cmds_Init (&sv_pr_state); PR_Obj_Progs_Init (&sv_pr_state); + RUA_Init (&sv_pr_state, 1); + + PR_Cmds_Init (&sv_pr_state); PR_RegisterBuiltins (&sv_pr_state, builtins); } diff --git a/qw/source/cl_main.c b/qw/source/cl_main.c index 45812a80f..fae0dab1a 100644 --- a/qw/source/cl_main.c +++ b/qw/source/cl_main.c @@ -1685,7 +1685,6 @@ Host_Init (void) VID_Init_Cvars (); PR_Init (); - RUA_Init (); CL_Chat_Init (); diff --git a/qw/source/sv_pr_cmds.c b/qw/source/sv_pr_cmds.c index 64cc584ca..ed427a678 100644 --- a/qw/source/sv_pr_cmds.c +++ b/qw/source/sv_pr_cmds.c @@ -44,6 +44,7 @@ static __attribute__ ((unused)) const char rcsid[] = #include "QF/cmd.h" #include "QF/cvar.h" #include "QF/msg.h" +#include "QF/ruamoko.h" #include "QF/sys.h" #include "QF/va.h" @@ -2006,9 +2007,11 @@ void SV_PR_Cmds_Init () { builtin_t *bi; - PR_Cmds_Init (&sv_pr_state); - PR_Obj_Progs_Init (&sv_pr_state); + PR_Obj_Progs_Init (&sv_pr_state); + RUA_Init (&sv_pr_state, 1); + + PR_Cmds_Init (&sv_pr_state); // (override standard builtin) // float (string s) cvar bi = PR_FindBuiltin (&sv_pr_state, "cvar"); diff --git a/qw/source/sv_progs.c b/qw/source/sv_progs.c index 03fa40d55..b4d4df471 100644 --- a/qw/source/sv_progs.c +++ b/qw/source/sv_progs.c @@ -38,7 +38,6 @@ #include "QF/cmd.h" #include "QF/cvar.h" #include "QF/quakefs.h" -#include "QF/ruamoko.h" #include "QF/sys.h" #include "compat.h" @@ -392,11 +391,8 @@ SV_Progs_Init (void) sv_pr_state.free_edict = free_edict; // eww, I hate the need for this :( sv_pr_state.bi_map = bi_map; - PR_Resources_Init (&sv_pr_state); SV_PR_Cmds_Init (); SV_PR_QWE_Init (&sv_pr_state); - RUA_Cmd_Init (&sv_pr_state); - RUA_Hash_Init (&sv_pr_state); Cmd_AddCommand ("edict", ED_PrintEdict_f, "Report information on a given " "edict in the game. (edict (edict number))");