mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
[util] Add a context parameter to the plist parsers
Not used by the dict/array parsers themselves, but is passed on to any value parser callbacks for their own use.
This commit is contained in:
parent
ebcef5c8a4
commit
591667c36d
3 changed files with 19 additions and 16 deletions
|
@ -80,12 +80,14 @@ struct plfield_s;
|
|||
error messages. Messages should be strings, but no
|
||||
checking is done: it is up to the top-level caller to
|
||||
parse out the messages.
|
||||
\param context Additional context data passed to the parser.
|
||||
\return 0 for error, 1 for success. See \a PL_ParseDictionary.
|
||||
*/
|
||||
typedef int (*plparser_t) (const struct plfield_s *field,
|
||||
const struct plitem_s *item,
|
||||
void *data,
|
||||
struct plitem_s *messages);
|
||||
struct plitem_s *messages,
|
||||
void *context);
|
||||
|
||||
/** A field to be parsed from a dictionary item.
|
||||
|
||||
|
@ -320,12 +322,13 @@ void PL_Free (plitem_t *item);
|
|||
message format is "[line number]: [message]". If the line
|
||||
number is 0, then the actual line is unknown (due to the
|
||||
source item not being parsed from a file or string).
|
||||
\param context Additional context data passed to the parser.
|
||||
\return 0 if there are any errors, 1 if there are no errors.
|
||||
*/
|
||||
int PL_ParseDictionary (const plfield_t *fields, const plitem_t *dict,
|
||||
void *data, plitem_t *messages);
|
||||
void *data, plitem_t *messages, void *context);
|
||||
int PL_ParseArray (const plfield_t *fields, const plitem_t *dict,
|
||||
void *data, plitem_t *messages);
|
||||
void *data, plitem_t *messages, void *context);
|
||||
void __attribute__((format(printf,3,4)))
|
||||
PL_Message (plitem_t *messages, const plitem_t *item, const char *fmt, ...);
|
||||
|
||||
|
|
|
@ -1086,7 +1086,7 @@ PL_Message (plitem_t *messages, const plitem_t *item, const char *fmt, ...)
|
|||
|
||||
static int
|
||||
pl_default_parser (const plfield_t *field, const plitem_t *item, void *data,
|
||||
plitem_t *messages)
|
||||
plitem_t *messages, void *context)
|
||||
{
|
||||
switch (field->type) {
|
||||
case QFDictionary:
|
||||
|
@ -1125,7 +1125,7 @@ pl_default_parser (const plfield_t *field, const plitem_t *item, void *data,
|
|||
|
||||
VISIBLE int
|
||||
PL_ParseDictionary (const plfield_t *fields, const plitem_t *dict, void *data,
|
||||
plitem_t *messages)
|
||||
plitem_t *messages, void *context)
|
||||
{
|
||||
void **list, **l;
|
||||
dictkey_t *current;
|
||||
|
@ -1161,7 +1161,7 @@ PL_ParseDictionary (const plfield_t *fields, const plitem_t *dict, void *data,
|
|||
pl_types[item->type]);
|
||||
result = 0;
|
||||
} else {
|
||||
if (!parser (f, item, flddata, messages)) {
|
||||
if (!parser (f, item, flddata, messages, context)) {
|
||||
result = 0;
|
||||
}
|
||||
}
|
||||
|
@ -1180,7 +1180,7 @@ PL_ParseDictionary (const plfield_t *fields, const plitem_t *dict, void *data,
|
|||
|
||||
VISIBLE int
|
||||
PL_ParseArray (const plfield_t *field, const plitem_t *array, void *data,
|
||||
plitem_t *messages)
|
||||
plitem_t *messages, void *context)
|
||||
{
|
||||
int result = 1;
|
||||
plparser_t parser;
|
||||
|
@ -1219,7 +1219,7 @@ PL_ParseArray (const plfield_t *field, const plitem_t *array, void *data,
|
|||
pl_types[item->type]);
|
||||
result = 0;
|
||||
} else {
|
||||
if (!parser (&f, item, eledata, messages)) {
|
||||
if (!parser (&f, item, eledata, messages, context)) {
|
||||
result = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ static int find_enum (const char *valstr, enumval_t *enumval, int *val)
|
|||
}
|
||||
|
||||
static int parse_uint32_t (const plfield_t *field, const plitem_t *item,
|
||||
void *data, plitem_t *messages)
|
||||
void *data, plitem_t *messages, void *ctx)
|
||||
{
|
||||
int ret = 1;
|
||||
const char *valstr = PL_String (item);
|
||||
|
@ -125,7 +125,7 @@ static int parse_uint32_t (const plfield_t *field, const plitem_t *item,
|
|||
}
|
||||
|
||||
static int parse_enum (const plfield_t *field, const plitem_t *item,
|
||||
void *data, plitem_t *messages)
|
||||
void *data, plitem_t *messages, void *ctx)
|
||||
{
|
||||
int ret = 1;
|
||||
int val;
|
||||
|
@ -144,7 +144,7 @@ static int parse_enum (const plfield_t *field, const plitem_t *item,
|
|||
}
|
||||
|
||||
static int parse_flags (const plfield_t *field, const plitem_t *item,
|
||||
void *data, plitem_t *messages)
|
||||
void *data, plitem_t *messages, void *ctx)
|
||||
{
|
||||
int ret = 1;
|
||||
int val;
|
||||
|
@ -165,7 +165,7 @@ static int parse_flags (const plfield_t *field, const plitem_t *item,
|
|||
}
|
||||
|
||||
static int parse_single (const plfield_t *field, const plitem_t *item,
|
||||
void *data, plitem_t *messages)
|
||||
void *data, plitem_t *messages, void *ctx)
|
||||
{
|
||||
__auto_type single = (parse_single_t *) field->data;
|
||||
void *flddata = (byte *)data + single->value_offset;
|
||||
|
@ -180,7 +180,7 @@ static int parse_single (const plfield_t *field, const plitem_t *item,
|
|||
|
||||
plfield_t f = { 0, 0, single->type, single->parser, 0 };
|
||||
void *value = calloc (1, single->stride);
|
||||
if (!single->parser (&f, item, value, messages)) {
|
||||
if (!single->parser (&f, item, value, messages, ctx)) {
|
||||
free (value);
|
||||
return 0;
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ static int parse_single (const plfield_t *field, const plitem_t *item,
|
|||
}
|
||||
|
||||
static int parse_array (const plfield_t *field, const plitem_t *item,
|
||||
void *data, plitem_t *messages)
|
||||
void *data, plitem_t *messages, void *ctx)
|
||||
{
|
||||
__auto_type array = (parse_array_t *) field->data;
|
||||
__auto_type value = (void **) ((byte *)data + array->value_offset);
|
||||
|
@ -213,7 +213,7 @@ static int parse_array (const plfield_t *field, const plitem_t *item,
|
|||
// field->data, data);
|
||||
//Sys_Printf (" %d %zd %p %zd %zd\n", array->type, array->stride,
|
||||
// array->parser, array->value_offset, array->size_offset);
|
||||
if (!PL_ParseArray (&f, item, &arr, messages)) {
|
||||
if (!PL_ParseArray (&f, item, &arr, messages, ctx)) {
|
||||
return 0;
|
||||
}
|
||||
*value = malloc (array->stride * arr->size);
|
||||
|
@ -275,7 +275,7 @@ QFV_ParseRenderPass (qfv_device_t *device, plitem_t *plist)
|
|||
VkRenderPass renderpass;
|
||||
|
||||
if (!PL_ParseDictionary (renderpass_fields, plist,
|
||||
&renderpass_data, messages)) {
|
||||
&renderpass_data, messages, 0)) {
|
||||
for (int i = 0; i < PL_A_NumObjects (messages); i++) {
|
||||
Sys_Printf ("%s\n", PL_String (PL_ObjectAtIndex (messages, i)));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue