From 7001f1d851633628b881ba2fb1abc9c28427ec84 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 7 Apr 2003 20:02:06 +0000 Subject: [PATCH] plist api (hope it works:) --- include/QF/csqc.h | 2 + libs/gamecode/builtins/Makefile.am | 2 +- libs/gamecode/builtins/bi_init.c | 1 + libs/gamecode/builtins/bi_plist.c | 178 +++++++++++++++++++++++++++++ ruamoko/include/Makefile.am | 2 +- ruamoko/include/plist.h | 19 +++ ruamoko/lib/Makefile.am | 3 +- ruamoko/lib/plist.r | 14 +++ 8 files changed, 218 insertions(+), 3 deletions(-) create mode 100644 libs/gamecode/builtins/bi_plist.c create mode 100644 ruamoko/include/plist.h create mode 100644 ruamoko/lib/plist.r diff --git a/include/QF/csqc.h b/include/QF/csqc.h index 8ff3eaa3a..57661d475 100644 --- a/include/QF/csqc.h +++ b/include/QF/csqc.h @@ -55,6 +55,8 @@ void InputLine_Progs_SetDraw (struct progs_s *pr, void Key_Progs_Init (struct progs_s *pr); +void Plist_Progs_Init (struct progs_s *pr); + #include "QF/quakeio.h" #define QFILE_MAX_HANDLES 20 typedef struct { diff --git a/libs/gamecode/builtins/Makefile.am b/libs/gamecode/builtins/Makefile.am index 1b9a78680..e55a70016 100644 --- a/libs/gamecode/builtins/Makefile.am +++ b/libs/gamecode/builtins/Makefile.am @@ -11,5 +11,5 @@ libQFgamecode_builtins_la_SOURCES= pr_cmds.c libQFcsqc_la_LDFLAGS= -version-info 1:0:0 libQFcsqc_la_SOURCES=\ bi_cbuf.c bi_cmd.c bi_cvar.c bi_file.c bi_hash.c bi_init.c \ - bi_inputline.c \ + bi_inputline.c bi_plist.c \ bi_qfile.c bi_qfs.c bi_string.c bi_strhash.c diff --git a/libs/gamecode/builtins/bi_init.c b/libs/gamecode/builtins/bi_init.c index 756daf002..5f41cb960 100644 --- a/libs/gamecode/builtins/bi_init.c +++ b/libs/gamecode/builtins/bi_init.c @@ -40,6 +40,7 @@ static void (*const cvar_progs_init)(progs_t *) = Cvar_Progs_Init; static void (*const file_progs_init)(progs_t *) = File_Progs_Init; static void (*const hash_progs_init)(progs_t *) = Hash_Progs_Init; static void (*const inputline_progs_init)(progs_t *) = InputLine_Progs_Init; +static void (*const plist_progs_init)(progs_t *) = Plist_Progs_Init; static void (*const qfile_progs_init)(progs_t *, int) = QFile_Progs_Init; static void (*const qfs_progs_init)(progs_t *) = QFS_Progs_Init; static void (*const string_progs_init)(progs_t *) = String_Progs_Init; diff --git a/libs/gamecode/builtins/bi_plist.c b/libs/gamecode/builtins/bi_plist.c new file mode 100644 index 000000000..fff37c13a --- /dev/null +++ b/libs/gamecode/builtins/bi_plist.c @@ -0,0 +1,178 @@ +/* + bi_plist.c + + QuakeC plist api + + Copyright (C) 2002 Bill Currie + + Author: Bill Currie + Date: 2003/4/7 + + 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 + +static __attribute__ ((unused)) const char rcsid[] = + "$Id$"; + +#ifdef HAVE_STRING_H +# include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif +#include + +#include "QF/csqc.h" +#include "QF/hash.h" +#include "QF/progs.h" +#include "QF/qfplist.h" + +typedef struct { + hashtab_t *items; +} plist_resources_t; + +static inline void +return_plitem (progs_t *pr, plitem_t *plitem) +{ + memcpy (pr->pr_globals + OFS_RETURN, &plitem, sizeof (plitem)); +} + +static inline plitem_t * +p_plitem (progs_t *pr, int n) +{ + plitem_t *plitem; + memcpy (&plitem, pr->pr_globals + OFS_PARM0 + n * sizeof (pr_type_t), + sizeof (plitem)); + return plitem; +} + +static inline plitem_t * +record_plitem (progs_t *pr, plitem_t *plitem) +{ + plist_resources_t *res = PR_Resources_Find (pr, "plist"); + if (plitem) + Hash_AddElement (res->items, plitem); + return plitem; +} + +static inline plitem_t * +remove_plitem (progs_t *pr, plitem_t *plitem) +{ + plist_resources_t *res = PR_Resources_Find (pr, "plist"); + + Hash_DelElement (res->items, plitem); + return plitem; +} + +static void +bi_PL_GetPropertyList (progs_t *pr) +{ + plitem_t *plitem = PL_GetPropertyList (P_STRING (pr, 0)); + + return_plitem (pr, record_plitem (pr, plitem)); +} + +static void +bi_PL_ObjectForKey (progs_t *pr) +{ + return_plitem (pr, PL_ObjectForKey (p_plitem (pr, 0), P_STRING (pr, 1))); +} + +static void +bi_PL_ObjectAtIndex (progs_t *pr) +{ + return_plitem (pr, PL_ObjectAtIndex (p_plitem (pr, 0), P_INT (pr, 1))); +} + +static void +bi_PL_D_AddObject (progs_t *pr) +{ + return_plitem (pr, PL_D_AddObject (p_plitem (pr, 0), + remove_plitem (pr, p_plitem (pr, 1)), + remove_plitem (pr, p_plitem (pr, 2)))); +} + +static void +bi_PL_A_AddObject (progs_t *pr) +{ + return_plitem (pr, PL_A_AddObject (p_plitem (pr, 0), + remove_plitem (pr, p_plitem (pr, 1)))); +} + +static void +bi_PL_A_InsertObjectAtIndex (progs_t *pr) +{ + return_plitem (pr, PL_A_InsertObjectAtIndex (p_plitem (pr, 0), + remove_plitem (pr, p_plitem (pr, 1)), + P_INT (pr, 2))); +} + +static void +bi_PL_NewDictionary (progs_t *pr) +{ + return_plitem (pr, record_plitem (pr, PL_NewDictionary ())); +} + +static void +bi_PL_NewArray (progs_t *pr) +{ + return_plitem (pr, record_plitem (pr, PL_NewArray ())); +} +/* +static void +bi_PL_NewData (progs_t *pr) +{ +} +*/ +static void +bi_PL_NewString (progs_t *pr) +{ + return_plitem (pr, record_plitem (pr, PL_NewString (P_STRING (pr, 0)))); +} + +static void +bi_plist_clear (progs_t *pr, void *data) +{ + plist_resources_t *res = (plist_resources_t *) data; + + Hash_FlushTable (res->items); +} + +void +Plist_Progs_Init (progs_t *pr) +{ + plist_resources_t *res = malloc (sizeof (plist_resources_t)); + res->plist = PL_NewArray (); + + PR_Resources_Register (pr, "plist", res, bi_plist_clear); + PR_AddBuiltin (pr, "PL_GetPropertyList", bi_PL_GetPropertyList, -1); + PR_AddBuiltin (pr, "PL_ObjectForKey", bi_PL_ObjectForKey, -1); + PR_AddBuiltin (pr, "PL_ObjectAtIndex", bi_PL_ObjectAtIndex, -1); + PR_AddBuiltin (pr, "PL_D_AddObject", bi_PL_D_AddObject, -1); + PR_AddBuiltin (pr, "PL_A_AddObject", bi_PL_A_AddObject, -1); + PR_AddBuiltin (pr, "PL_A_InsertObjectAtIndex", bi_PL_A_InsertObjectAtIndex, -1); + PR_AddBuiltin (pr, "PL_NewDictionary", bi_PL_NewDictionary, -1); + PR_AddBuiltin (pr, "PL_NewArray", bi_PL_NewArray, -1); + //PR_AddBuiltin (pr, "PL_NewData", bi_PL_NewData, -1); + PR_AddBuiltin (pr, "PL_NewString", bi_PL_NewString, -1); +} diff --git a/ruamoko/include/Makefile.am b/ruamoko/include/Makefile.am index f93cd082f..613cf9457 100644 --- a/ruamoko/include/Makefile.am +++ b/ruamoko/include/Makefile.am @@ -7,5 +7,5 @@ include_HEADERS= \ \ draw.h key.h \ \ - cbuf.h cmd.h cvar.h file.h \ + cbuf.h cmd.h cvar.h file.h hash.h plist.h \ Object.h Array.h Entity.h InputLine.h Point.h Rect.h Size.h diff --git a/ruamoko/include/plist.h b/ruamoko/include/plist.h new file mode 100644 index 000000000..a096a0d5f --- /dev/null +++ b/ruamoko/include/plist.h @@ -0,0 +1,19 @@ +#ifndef __ruamoko_plist_h +#define __ruamoko_plist_h + +struct plitem_t = {integer [2] dummy;}; + +plitem_t (string str) PL_GetPropertyList; +plitem_t (plitem_t item, string key) PL_ObjectForKey; +plitem_t (plitem_t item, integer index) PL_ObjectAtIndex; + +plitem_t (plitem_t dict, plitem_t key, plitem_t value) PL_D_AddObject; +plitem_t (plitem_t array_item, plitem_t item) PL_A_AddObject; +plitem_t (plitem_t array_item, plitem_t item, integer index) PL_A_InsertObjectAtIndex; + +plitem_t () PL_NewDictionary; +plitem_t () PL_NewArray; +//plitem_t () PL_NewData; +plitem_t (string str) PL_NewString; + +#endif//__ruamoko_plist_h diff --git a/ruamoko/lib/Makefile.am b/ruamoko/lib/Makefile.am index 30e354a30..bb12fb3b0 100644 --- a/ruamoko/lib/Makefile.am +++ b/ruamoko/lib/Makefile.am @@ -28,7 +28,8 @@ EXTRA_LIBRARIES= $(ruamoko_libs) libr_a_SOURCES=\ crudefile.r debug.r hash.r entities.r infokey.r math.r message.r \ - nq_message.r physics.r qfile.r qw_message.r qw_physics.r qw_sys.r sound.r \ + nq_message.r physics.r plist.r qfile.r qw_message.r qw_physics.r qw_sys.r \ + sound.r \ string.r system.r Object.r Array.r Entity.r Point.r Size.r Rect.r libr_a_AR=$(PAK) -cf diff --git a/ruamoko/lib/plist.r b/ruamoko/lib/plist.r new file mode 100644 index 000000000..b0d0c1ae3 --- /dev/null +++ b/ruamoko/lib/plist.r @@ -0,0 +1,14 @@ +#include "plist.h" + +plitem_t (string str) PL_GetPropertyList = #0; +plitem_t (plitem_t item, string key) PL_ObjectForKey = #0; +plitem_t (plitem_t item, integer index) PL_ObjectAtIndex = #0; + +plitem_t (plitem_t dict, plitem_t key, plitem_t value) PL_D_AddObject = #0; +plitem_t (plitem_t array_item, plitem_t item) PL_A_AddObject = #0; +plitem_t (plitem_t array_item, plitem_t item, integer index) PL_A_InsertObjectAtIndex = #0; + +plitem_t () PL_NewDictionary = #0; +plitem_t () PL_NewArray = #0; +//plitem_t () PL_NewData = #0; +plitem_t (string str) PL_NewString = #0;