2003-04-07 20:02:06 +00:00
|
|
|
/*
|
|
|
|
bi_plist.c
|
|
|
|
|
|
|
|
QuakeC plist api
|
|
|
|
|
2003-04-10 16:54:12 +00:00
|
|
|
Copyright (C) 2003 Bill Currie
|
2003-04-07 20:02:06 +00:00
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
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
|
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "QF/hash.h"
|
2021-03-21 07:13:03 +00:00
|
|
|
#include "QF/plist.h"
|
2003-04-07 20:02:06 +00:00
|
|
|
#include "QF/progs.h"
|
2004-01-16 07:03:58 +00:00
|
|
|
|
|
|
|
#include "rua_internal.h"
|
2003-04-07 20:02:06 +00:00
|
|
|
|
2013-09-27 14:08:33 +00:00
|
|
|
#define always_inline inline __attribute__((__always_inline__))
|
|
|
|
|
2010-11-19 04:39:20 +00:00
|
|
|
typedef struct bi_plist_s {
|
|
|
|
struct bi_plist_s *next;
|
|
|
|
struct bi_plist_s **prev;
|
|
|
|
plitem_t *plitem;
|
|
|
|
int own;
|
|
|
|
} bi_plist_t;
|
|
|
|
|
2003-04-07 20:02:06 +00:00
|
|
|
typedef struct {
|
2010-11-19 04:39:20 +00:00
|
|
|
PR_RESMAP (bi_plist_t) plist_map;
|
|
|
|
bi_plist_t *plists;
|
|
|
|
hashtab_t *plist_tab;
|
2003-04-07 20:02:06 +00:00
|
|
|
} plist_resources_t;
|
|
|
|
|
2010-11-19 04:39:20 +00:00
|
|
|
static bi_plist_t *
|
|
|
|
plist_new (plist_resources_t *res)
|
2003-04-07 20:02:06 +00:00
|
|
|
{
|
2021-03-21 12:26:36 +00:00
|
|
|
return PR_RESNEW (res->plist_map);
|
2003-04-07 20:02:06 +00:00
|
|
|
}
|
|
|
|
|
2010-11-19 04:39:20 +00:00
|
|
|
static void
|
|
|
|
plist_free (plist_resources_t *res, bi_plist_t *plist)
|
2003-04-07 20:02:06 +00:00
|
|
|
{
|
2021-03-21 12:26:36 +00:00
|
|
|
PR_RESFREE (res->plist_map, plist);
|
2003-04-07 20:02:06 +00:00
|
|
|
}
|
|
|
|
|
2010-11-19 04:39:20 +00:00
|
|
|
static void
|
|
|
|
plist_reset (plist_resources_t *res)
|
2003-04-07 20:02:06 +00:00
|
|
|
{
|
2021-03-21 12:26:36 +00:00
|
|
|
PR_RESRESET (res->plist_map);
|
2003-04-07 20:02:06 +00:00
|
|
|
}
|
|
|
|
|
2010-11-19 04:39:20 +00:00
|
|
|
static inline bi_plist_t *
|
|
|
|
plist_get (plist_resources_t *res, unsigned index)
|
2003-04-07 20:02:06 +00:00
|
|
|
{
|
2021-03-21 12:26:36 +00:00
|
|
|
return PR_RESGET(res->plist_map, index);
|
2010-11-19 04:39:20 +00:00
|
|
|
}
|
|
|
|
|
2020-12-20 17:12:51 +00:00
|
|
|
static inline int __attribute__((pure))
|
2010-11-19 04:39:20 +00:00
|
|
|
plist_index (plist_resources_t *res, bi_plist_t *plist)
|
|
|
|
{
|
2021-03-21 12:26:36 +00:00
|
|
|
return PR_RESINDEX(res->plist_map, plist);
|
2010-11-19 04:39:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_plist_clear (progs_t *pr, void *_res)
|
2010-11-19 04:39:20 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = (plist_resources_t *) _res;
|
2010-11-19 04:39:20 +00:00
|
|
|
bi_plist_t *plist;
|
|
|
|
|
|
|
|
for (plist = res->plists; plist; plist = plist->next) {
|
|
|
|
if (plist->own)
|
|
|
|
PL_Free (plist->plitem);
|
|
|
|
}
|
2011-07-09 00:42:11 +00:00
|
|
|
res->plists = 0;
|
2010-11-19 04:39:20 +00:00
|
|
|
|
|
|
|
Hash_FlushTable (res->plist_tab);
|
|
|
|
plist_reset (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
plist_handle (plist_resources_t *res, plitem_t *plitem)
|
|
|
|
{
|
|
|
|
bi_plist_t dummy = {0, 0, plitem, 0};
|
|
|
|
bi_plist_t *plist = Hash_FindElement (res->plist_tab, &dummy);
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2010-11-19 04:39:20 +00:00
|
|
|
if (plist)
|
|
|
|
return plist_index (res, plist);
|
|
|
|
|
|
|
|
plist = plist_new (res);
|
|
|
|
|
|
|
|
if (!plist)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
plist->next = res->plists;
|
|
|
|
plist->prev = &res->plists;
|
|
|
|
if (res->plists)
|
|
|
|
res->plists->prev = &plist->next;
|
|
|
|
res->plists = plist;
|
|
|
|
|
|
|
|
plist->plitem = plitem;
|
|
|
|
|
|
|
|
Hash_AddElement (res->plist_tab, plist);
|
|
|
|
return plist_index (res, plist);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
plist_free_handle (plist_resources_t *res, bi_plist_t *plist)
|
|
|
|
{
|
|
|
|
Hash_DelElement (res->plist_tab, plist);
|
|
|
|
*plist->prev = plist->next;
|
2011-07-09 00:42:11 +00:00
|
|
|
if (plist->next)
|
|
|
|
plist->next->prev = plist->prev;
|
2010-11-19 04:39:20 +00:00
|
|
|
plist_free (res, plist);
|
|
|
|
}
|
|
|
|
|
2022-02-14 10:30:50 +00:00
|
|
|
static always_inline bi_plist_t * __attribute__((pure))
|
2022-02-14 03:28:38 +00:00
|
|
|
get_plist (progs_t *pr, plist_resources_t *res, const char *name, int handle)
|
2010-11-19 04:39:20 +00:00
|
|
|
{
|
|
|
|
bi_plist_t *plist = plist_get (res, handle);
|
|
|
|
|
|
|
|
// plist->prev will be null if the handle is unallocated
|
|
|
|
if (!plist || !plist->prev)
|
|
|
|
PR_RunError (pr, "invalid plist passed to %s", name + 3);
|
|
|
|
return plist;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
plist_retain (plist_resources_t *res, plitem_t *plitem)
|
|
|
|
{
|
|
|
|
int handle;
|
|
|
|
bi_plist_t *plist;
|
|
|
|
|
|
|
|
if (!plitem)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
handle = plist_handle (res, plitem);
|
|
|
|
if (!handle) {
|
|
|
|
// we're taking ownership of the plitem, but we have nowhere to store
|
|
|
|
// it, so we have to lose it. However, in this situation, we have worse
|
|
|
|
// things to worry about.
|
|
|
|
PL_Free (plitem);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
plist = plist_get (res, handle);
|
|
|
|
plist->own = 1;
|
|
|
|
return handle;
|
2003-04-07 20:02:06 +00:00
|
|
|
}
|
|
|
|
|
2010-11-24 04:12:41 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_PL_GetFromFile (progs_t *pr, void *_res)
|
2010-11-24 04:12:41 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = _res;
|
2010-11-24 04:12:41 +00:00
|
|
|
QFile *file = QFile_GetFile (pr, P_INT (pr, 0));
|
|
|
|
plitem_t *plitem;
|
|
|
|
long offset;
|
|
|
|
long size;
|
|
|
|
long len;
|
|
|
|
char *buf;
|
|
|
|
|
|
|
|
offset = Qtell (file);
|
|
|
|
size = Qfilesize (file);
|
|
|
|
len = size - offset;
|
|
|
|
buf = malloc (len + 1);
|
|
|
|
Qread (file, buf, len);
|
|
|
|
buf[len] = 0;
|
|
|
|
|
2021-02-09 00:57:07 +00:00
|
|
|
plitem = PL_GetPropertyList (buf, pr->hashlink_freelist);
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2010-11-24 04:12:41 +00:00
|
|
|
R_INT (pr) = plist_retain (res, plitem);
|
|
|
|
}
|
|
|
|
|
2003-04-07 20:02:06 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_PL_GetPropertyList (progs_t *pr, void *_res)
|
2003-04-07 20:02:06 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = _res;
|
2021-02-09 00:57:07 +00:00
|
|
|
plitem_t *plitem = PL_GetPropertyList (P_GSTRING (pr, 0),
|
|
|
|
pr->hashlink_freelist);
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2010-11-19 04:39:20 +00:00
|
|
|
R_INT (pr) = plist_retain (res, plitem);
|
2003-04-07 20:02:06 +00:00
|
|
|
}
|
|
|
|
|
2004-11-11 22:42:00 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_PL_WritePropertyList (progs_t *pr, void *_res)
|
2004-11-11 22:42:00 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = _res;
|
2010-11-19 04:39:20 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_plist_t *plist = get_plist (pr, res, __FUNCTION__, handle);
|
2010-11-19 04:39:20 +00:00
|
|
|
char *pl = PL_WritePropertyList (plist->plitem);
|
|
|
|
|
2004-11-11 22:42:00 +00:00
|
|
|
R_STRING (pr) = PR_SetDynamicString (pr, pl);
|
|
|
|
free (pl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_PL_Type (progs_t *pr, void *_res)
|
2004-11-11 22:42:00 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = _res;
|
2010-11-19 04:39:20 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_plist_t *plist = get_plist (pr, res, __FUNCTION__, handle);
|
2010-11-19 04:39:20 +00:00
|
|
|
|
|
|
|
R_INT (pr) = PL_Type (plist->plitem);
|
2004-11-11 22:42:00 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 12:52:42 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_PL_Line (progs_t *pr, void *_res)
|
2020-12-23 12:52:42 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = _res;
|
2020-12-23 12:52:42 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_plist_t *plist = get_plist (pr, res, __FUNCTION__, handle);
|
2020-12-23 12:52:42 +00:00
|
|
|
|
|
|
|
R_INT (pr) = PL_Line (plist->plitem);
|
|
|
|
}
|
|
|
|
|
2004-11-11 22:42:00 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_PL_String (progs_t *pr, void *_res)
|
2004-11-11 22:42:00 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = _res;
|
2010-11-19 04:39:20 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_plist_t *plist = get_plist (pr, res, __FUNCTION__, handle);
|
2010-11-19 04:39:20 +00:00
|
|
|
const char *str = PL_String (plist->plitem);
|
|
|
|
|
2004-11-11 22:42:00 +00:00
|
|
|
RETURN_STRING (pr, str);
|
|
|
|
}
|
|
|
|
|
2003-04-07 20:02:06 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_PL_ObjectForKey (progs_t *pr, void *_res)
|
2003-04-07 20:02:06 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = _res;
|
2010-11-19 04:39:20 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_plist_t *plist = get_plist (pr, res, __FUNCTION__, handle);
|
2010-11-19 04:39:20 +00:00
|
|
|
const char *key = P_GSTRING (pr, 1);
|
|
|
|
plitem_t *plitem = PL_ObjectForKey (plist->plitem, key);
|
|
|
|
|
|
|
|
R_INT (pr) = 0;
|
|
|
|
if (!plitem)
|
|
|
|
return;
|
|
|
|
R_INT (pr) = plist_handle (res, plitem);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_PL_RemoveObjectForKey (progs_t *pr, void *_res)
|
2010-11-19 04:39:20 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = _res;
|
2010-11-19 04:39:20 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_plist_t *plist = get_plist (pr, res, __FUNCTION__, handle);
|
2010-11-19 04:39:20 +00:00
|
|
|
const char *key = P_GSTRING (pr, 1);
|
|
|
|
plitem_t *plitem = PL_RemoveObjectForKey (plist->plitem, key);
|
|
|
|
|
|
|
|
R_INT (pr) = plist_retain (res, plitem);
|
2003-04-07 20:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_PL_ObjectAtIndex (progs_t *pr, void *_res)
|
2003-04-07 20:02:06 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = _res;
|
2010-11-19 04:39:20 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_plist_t *plist = get_plist (pr, res, __FUNCTION__, handle);
|
2010-11-19 04:39:20 +00:00
|
|
|
int ind = P_INT (pr, 1);
|
|
|
|
plitem_t *plitem = PL_ObjectAtIndex (plist->plitem, ind);
|
|
|
|
|
|
|
|
R_INT (pr) = 0;
|
|
|
|
if (!plitem)
|
|
|
|
return;
|
|
|
|
R_INT (pr) = plist_handle (res, plitem);
|
2003-04-07 20:02:06 +00:00
|
|
|
}
|
|
|
|
|
2004-11-11 22:42:00 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_PL_D_AllKeys (progs_t *pr, void *_res)
|
2004-11-11 22:42:00 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = _res;
|
2010-11-19 04:39:20 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_plist_t *plist = get_plist (pr, res, __FUNCTION__, handle);
|
2010-11-19 04:39:20 +00:00
|
|
|
plitem_t *plitem = PL_D_AllKeys (plist->plitem);
|
|
|
|
|
|
|
|
R_INT (pr) = plist_retain (res, plitem);
|
2004-11-11 22:42:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_PL_D_NumKeys (progs_t *pr, void *_res)
|
2004-11-11 22:42:00 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = _res;
|
2010-11-19 04:39:20 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_plist_t *plist = get_plist (pr, res, __FUNCTION__, handle);
|
2010-11-19 04:39:20 +00:00
|
|
|
|
|
|
|
R_INT (pr) = PL_D_NumKeys (plist->plitem);
|
2004-11-11 22:42:00 +00:00
|
|
|
}
|
|
|
|
|
2003-04-07 20:02:06 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_PL_D_AddObject (progs_t *pr, void *_res)
|
2003-04-07 20:02:06 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = _res;
|
2010-11-19 04:39:20 +00:00
|
|
|
int dict_handle = P_INT (pr, 0);
|
|
|
|
int obj_handle = P_INT (pr, 2);
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_plist_t *dict = get_plist (pr, res, __FUNCTION__, dict_handle);
|
2010-11-19 04:39:20 +00:00
|
|
|
const char *key = P_GSTRING (pr, 1);
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_plist_t *obj = get_plist (pr, res, __FUNCTION__, obj_handle);
|
2010-11-19 04:39:20 +00:00
|
|
|
|
|
|
|
obj->own = 0;
|
|
|
|
R_INT (pr) = PL_D_AddObject (dict->plitem, key, obj->plitem);
|
2003-04-07 20:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_PL_A_AddObject (progs_t *pr, void *_res)
|
2003-04-07 20:02:06 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = _res;
|
2010-11-19 04:39:20 +00:00
|
|
|
int arr_handle = P_INT (pr, 0);
|
|
|
|
int obj_handle = P_INT (pr, 1);
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_plist_t *arr = get_plist (pr, res, __FUNCTION__, arr_handle);
|
|
|
|
bi_plist_t *obj = get_plist (pr, res, __FUNCTION__, obj_handle);
|
2010-11-19 04:39:20 +00:00
|
|
|
|
|
|
|
obj->own = 0;
|
|
|
|
R_INT (pr) = PL_A_AddObject (arr->plitem, obj->plitem);
|
2003-04-07 20:02:06 +00:00
|
|
|
}
|
|
|
|
|
2004-11-11 22:42:00 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_PL_A_NumObjects (progs_t *pr, void *_res)
|
2004-11-11 22:42:00 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = _res;
|
2010-11-19 04:39:20 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_plist_t *plist = get_plist (pr, res, __FUNCTION__, handle);
|
2010-11-19 04:39:20 +00:00
|
|
|
|
|
|
|
R_INT (pr) = PL_A_NumObjects (plist->plitem);
|
2004-11-11 22:42:00 +00:00
|
|
|
}
|
|
|
|
|
2003-04-07 20:02:06 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_PL_A_InsertObjectAtIndex (progs_t *pr, void *_res)
|
2003-04-07 20:02:06 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = _res;
|
2010-11-19 04:39:20 +00:00
|
|
|
int dict_handle = P_INT (pr, 0);
|
|
|
|
int obj_handle = P_INT (pr, 1);
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_plist_t *arr = get_plist (pr, res, __FUNCTION__, dict_handle);
|
|
|
|
bi_plist_t *obj = get_plist (pr, res, __FUNCTION__, obj_handle);
|
2010-11-19 04:39:20 +00:00
|
|
|
int ind = P_INT (pr, 2);
|
|
|
|
|
|
|
|
obj->own = 0;
|
|
|
|
R_INT (pr) = PL_A_InsertObjectAtIndex (arr->plitem, obj->plitem, ind);
|
2003-04-07 20:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_PL_RemoveObjectAtIndex (progs_t *pr, void *_res)
|
2003-04-07 20:02:06 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = _res;
|
2010-11-19 04:39:20 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_plist_t *plist = get_plist (pr, res, __FUNCTION__, handle);
|
2010-11-19 04:39:20 +00:00
|
|
|
int ind = P_INT (pr, 1);
|
|
|
|
plitem_t *plitem = PL_RemoveObjectAtIndex (plist->plitem, ind);
|
|
|
|
|
|
|
|
R_INT (pr) = plist_retain (res, plitem);
|
2003-04-07 20:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_PL_NewDictionary (progs_t *pr, void *_res)
|
2003-04-07 20:02:06 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = _res;
|
2021-02-09 00:57:07 +00:00
|
|
|
plitem_t *plitem = PL_NewDictionary (pr->hashlink_freelist);
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2010-11-19 04:39:20 +00:00
|
|
|
R_INT (pr) = plist_retain (res, plitem);
|
2003-04-07 20:02:06 +00:00
|
|
|
}
|
2004-11-11 22:42:00 +00:00
|
|
|
|
2003-04-07 20:02:06 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_PL_NewArray (progs_t *pr, void *_res)
|
2003-04-07 20:02:06 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = _res;
|
2010-11-19 04:39:20 +00:00
|
|
|
plitem_t *plitem = PL_NewArray ();
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2010-11-19 04:39:20 +00:00
|
|
|
R_INT (pr) = plist_retain (res, plitem);
|
2003-04-07 20:02:06 +00:00
|
|
|
}
|
2004-11-11 22:42:00 +00:00
|
|
|
|
2003-04-07 20:02:06 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_PL_NewData (progs_t *pr, void *_res)
|
2003-04-07 20:02:06 +00:00
|
|
|
{
|
2010-11-19 04:39:20 +00:00
|
|
|
//FIXME not safe
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = _res;
|
2010-11-19 04:39:20 +00:00
|
|
|
plitem_t *plitem = PL_NewData (P_GPOINTER (pr, 0), P_INT (pr, 1));
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2010-11-19 04:39:20 +00:00
|
|
|
R_INT (pr) = plist_retain (res, plitem);
|
2003-04-07 20:02:06 +00:00
|
|
|
}
|
|
|
|
|
2004-11-11 22:42:00 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_PL_NewString (progs_t *pr, void *_res)
|
2004-11-11 22:42:00 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = _res;
|
2010-11-19 04:39:20 +00:00
|
|
|
plitem_t *plitem = PL_NewString (P_GSTRING (pr, 0));
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2010-11-19 04:39:20 +00:00
|
|
|
R_INT (pr) = plist_retain (res, plitem);
|
2004-11-11 22:42:00 +00:00
|
|
|
}
|
|
|
|
|
2003-04-07 20:02:06 +00:00
|
|
|
static void
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_PL_Free (progs_t *pr, void *_res)
|
2003-04-07 20:02:06 +00:00
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = _res;
|
2010-11-19 04:39:20 +00:00
|
|
|
int handle = P_INT (pr, 0);
|
2022-02-14 03:28:38 +00:00
|
|
|
bi_plist_t *plist = get_plist (pr, res, __FUNCTION__, handle);
|
2010-11-19 04:39:20 +00:00
|
|
|
|
|
|
|
if (!plist->own)
|
|
|
|
PR_RunError (pr, "attempt to free unowned plist");
|
|
|
|
|
|
|
|
PL_Free (plist->plitem);
|
2003-04-07 20:02:06 +00:00
|
|
|
|
2010-11-19 04:39:20 +00:00
|
|
|
plist_free_handle (res, plist);
|
2003-04-07 20:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-12-21 15:24:14 +00:00
|
|
|
plitem_t *
|
|
|
|
Plist_GetItem (progs_t *pr, int handle)
|
|
|
|
{
|
2022-02-14 03:28:38 +00:00
|
|
|
plist_resources_t *res = PR_Resources_Find (pr, "plist");
|
|
|
|
bi_plist_t *plist = get_plist (pr, res, __FUNCTION__, handle);
|
2021-12-21 15:24:14 +00:00
|
|
|
return plist->plitem;
|
|
|
|
}
|
|
|
|
|
2007-04-04 07:48:14 +00:00
|
|
|
static uintptr_t
|
2012-07-18 13:34:37 +00:00
|
|
|
plist_get_hash (const void *key, void *unused)
|
2003-04-07 20:15:38 +00:00
|
|
|
{
|
2010-11-19 04:39:20 +00:00
|
|
|
bi_plist_t *plist = (bi_plist_t *) key;
|
|
|
|
return (uintptr_t) plist->plitem;
|
2003-04-07 20:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-07-18 13:34:37 +00:00
|
|
|
plist_compare (const void *k1, const void *k2, void *unused)
|
2003-04-07 20:15:38 +00:00
|
|
|
{
|
2010-11-19 04:39:20 +00:00
|
|
|
bi_plist_t *pl1 = (bi_plist_t *) k1;
|
|
|
|
bi_plist_t *pl2 = (bi_plist_t *) k2;
|
|
|
|
return pl1->plitem == pl2->plitem;
|
2003-04-07 20:15:38 +00:00
|
|
|
}
|
|
|
|
|
2022-01-23 12:54:03 +00:00
|
|
|
#define bi(x,np,params...) {#x, bi_##x, -1, np, {params}}
|
|
|
|
#define p(type) PR_PARAM(type)
|
2004-01-06 05:51:09 +00:00
|
|
|
static builtin_t builtins[] = {
|
2022-01-23 12:54:03 +00:00
|
|
|
bi(PL_GetFromFile, 1, p(ptr)),
|
|
|
|
bi(PL_GetPropertyList, 1, p(string)),
|
|
|
|
bi(PL_WritePropertyList, 1, p(ptr)),
|
|
|
|
bi(PL_Type, 1, p(ptr)),
|
|
|
|
bi(PL_Line, 1, p(ptr)),
|
|
|
|
bi(PL_String, 1, p(ptr)),
|
|
|
|
bi(PL_ObjectForKey, 2, p(ptr), p(string)),
|
|
|
|
bi(PL_RemoveObjectForKey, 2, p(ptr), p(string)),
|
|
|
|
bi(PL_ObjectAtIndex, 2, p(ptr), p(int)),
|
|
|
|
bi(PL_D_AllKeys, 1, p(ptr)),
|
|
|
|
bi(PL_D_NumKeys, 1, p(ptr)),
|
|
|
|
bi(PL_D_AddObject, 3, p(ptr), p(string), p(ptr)),
|
|
|
|
bi(PL_A_AddObject, 2, p(ptr), p(ptr)),
|
|
|
|
bi(PL_A_NumObjects, 1, p(ptr)),
|
|
|
|
bi(PL_A_InsertObjectAtIndex, 3, p(ptr), p(ptr), p(int)),
|
|
|
|
bi(PL_RemoveObjectAtIndex, 2, p(ptr), p(int)),
|
|
|
|
bi(PL_NewDictionary, 0),
|
|
|
|
bi(PL_NewArray, 0),
|
|
|
|
bi(PL_NewData, 2, p(ptr), p(int)),
|
|
|
|
bi(PL_NewString, 1, p(string)),
|
|
|
|
bi(PL_Free, 1, p(ptr)),
|
2004-01-06 05:51:09 +00:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
2003-04-07 20:02:06 +00:00
|
|
|
void
|
2004-01-16 07:03:58 +00:00
|
|
|
RUA_Plist_Init (progs_t *pr, int secure)
|
2003-04-07 20:02:06 +00:00
|
|
|
{
|
2004-11-11 22:42:00 +00:00
|
|
|
plist_resources_t *res = calloc (1, sizeof (plist_resources_t));
|
2020-03-25 06:43:16 +00:00
|
|
|
res->plist_tab = Hash_NewTable (1021, 0, 0, 0, pr->hashlink_freelist);
|
2010-11-19 04:39:20 +00:00
|
|
|
Hash_SetHashCompare (res->plist_tab, plist_get_hash, plist_compare);
|
2003-04-07 20:02:06 +00:00
|
|
|
|
|
|
|
PR_Resources_Register (pr, "plist", res, bi_plist_clear);
|
2022-01-23 15:20:05 +00:00
|
|
|
PR_RegisterBuiltins (pr, builtins, res);
|
2003-04-07 20:02:06 +00:00
|
|
|
}
|