mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-05-05 23:41:10 +00:00
Add PL_GetFromFile builtin.
This is an extension "wrapper" (no such C function). This allows ruamoko programs to read property lists without worrying about the memory required to store the string for the property list being read.
This commit is contained in:
parent
defc2a264b
commit
addbcaa09c
5 changed files with 34 additions and 0 deletions
|
@ -175,6 +175,29 @@ plist_retain (plist_resources_t *res, plitem_t *plitem)
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
bi_PL_GetFromFile (progs_t *pr)
|
||||||
|
{
|
||||||
|
plist_resources_t *res = PR_Resources_Find (pr, "plist");
|
||||||
|
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;
|
||||||
|
|
||||||
|
plitem = PL_GetPropertyList (buf);
|
||||||
|
|
||||||
|
R_INT (pr) = plist_retain (res, plitem);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bi_PL_GetPropertyList (progs_t *pr)
|
bi_PL_GetPropertyList (progs_t *pr)
|
||||||
{
|
{
|
||||||
|
@ -403,6 +426,7 @@ plist_compare (void *k1, void *k2, void *unused)
|
||||||
}
|
}
|
||||||
|
|
||||||
static builtin_t builtins[] = {
|
static builtin_t builtins[] = {
|
||||||
|
{"PL_GetFromFile", bi_PL_GetFromFile, -1},
|
||||||
{"PL_GetPropertyList", bi_PL_GetPropertyList, -1},
|
{"PL_GetPropertyList", bi_PL_GetPropertyList, -1},
|
||||||
{"PL_WritePropertyList", bi_PL_WritePropertyList, -1},
|
{"PL_WritePropertyList", bi_PL_WritePropertyList, -1},
|
||||||
{"PL_Type", bi_PL_Type, -1},
|
{"PL_Type", bi_PL_Type, -1},
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
+ (PLItem) newData:(void[]) data size:(integer) len;
|
+ (PLItem) newData:(void[]) data size:(integer) len;
|
||||||
+ (PLItem) newString:(string) str;
|
+ (PLItem) newString:(string) str;
|
||||||
+ (PLItem) fromString:(string) str;
|
+ (PLItem) fromString:(string) str;
|
||||||
|
+ (PLItem) fromFile:(QFile) file;
|
||||||
|
|
||||||
- initWithItem:(plitem_t) item;
|
- initWithItem:(plitem_t) item;
|
||||||
- initWithOwnItem:(plitem_t) item;
|
- initWithOwnItem:(plitem_t) item;
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
#ifndef __ruamoko_plist_h
|
#ifndef __ruamoko_plist_h
|
||||||
#define __ruamoko_plist_h
|
#define __ruamoko_plist_h
|
||||||
|
|
||||||
|
#include "qfile.h"
|
||||||
|
|
||||||
struct plitem_s {integer dummy;};
|
struct plitem_s {integer dummy;};
|
||||||
#define PL_TEST(item) (item.dummy)
|
#define PL_TEST(item) (item.dummy)
|
||||||
typedef struct plitem_s plitem_t;
|
typedef struct plitem_s plitem_t;
|
||||||
typedef enum {QFDictionary, QFArray, QFBinary, QFString} pltype_t; // possible types
|
typedef enum {QFDictionary, QFArray, QFBinary, QFString} pltype_t; // possible types
|
||||||
|
|
||||||
|
@extern plitem_t (QFile file) PL_GetFromFile;
|
||||||
@extern plitem_t (string str) PL_GetPropertyList;
|
@extern plitem_t (string str) PL_GetPropertyList;
|
||||||
@extern string (plitem_t pl) PL_WritePropertyList;
|
@extern string (plitem_t pl) PL_WritePropertyList;
|
||||||
@extern pltype_t (plitem_t str) PL_Type;
|
@extern pltype_t (plitem_t str) PL_Type;
|
||||||
|
|
|
@ -27,6 +27,11 @@
|
||||||
return [[PLItem itemClass: PL_GetPropertyList (str)] autorelease];
|
return [[PLItem itemClass: PL_GetPropertyList (str)] autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (PLItem) fromFile:(QFile) file
|
||||||
|
{
|
||||||
|
return [[PLItem itemClass: PL_GetFromFile (file)] autorelease];
|
||||||
|
}
|
||||||
|
|
||||||
+ itemClass:(plitem_t) item
|
+ itemClass:(plitem_t) item
|
||||||
{
|
{
|
||||||
local string classname = NIL;
|
local string classname = NIL;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "plist.h"
|
#include "plist.h"
|
||||||
|
|
||||||
|
plitem_t (QFile file) PL_GetFromFile = #0;
|
||||||
plitem_t (string str) PL_GetPropertyList = #0;
|
plitem_t (string str) PL_GetPropertyList = #0;
|
||||||
string (plitem_t pl) PL_WritePropertyList = #0;
|
string (plitem_t pl) PL_WritePropertyList = #0;
|
||||||
pltype_t (plitem_t str) PL_Type = #0;
|
pltype_t (plitem_t str) PL_Type = #0;
|
||||||
|
|
Loading…
Reference in a new issue