mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-13 08:27:39 +00:00
[plist] Pass array index/label to the parse function
I ran into the need to get at the label of labeled array element and the best way seemed to be by setting the name field of the plfield_t item passed to the parser function, and then found that PL_ParseSymtab already does this. I then decided passing the array index would also be good, and the offset field made sense.
This commit is contained in:
parent
35df90cb3f
commit
d5b93c20b3
2 changed files with 13 additions and 0 deletions
|
@ -107,6 +107,16 @@ typedef int (*plparser_t) (const struct plfield_s *field,
|
||||||
point to a \a plelement_t object. This allows all the parse functions to
|
point to a \a plelement_t object. This allows all the parse functions to
|
||||||
be used directly as either a \a plfield_t or \a plelement_t object's
|
be used directly as either a \a plfield_t or \a plelement_t object's
|
||||||
\a parser.
|
\a parser.
|
||||||
|
|
||||||
|
\a PL_ParseLabeledArray and \a PL_ParseSymtab pass to the parser a field
|
||||||
|
with \a name set to the key of the current item and \a offset set to 0.
|
||||||
|
For \a PL_ParseArray, \a name is set to null and \a offset is set to the
|
||||||
|
current index. \a PL_ParseLabeledArray also sets \a offset to the current
|
||||||
|
index. \a type, \a parser, and \a data are taken from the \a plelement_t
|
||||||
|
passed in to them.
|
||||||
|
|
||||||
|
\a PL_ParseStruct passes the currently parsed field without any
|
||||||
|
modifications.
|
||||||
*/
|
*/
|
||||||
typedef struct plfield_s {
|
typedef struct plfield_s {
|
||||||
const char *name; ///< matched by dictionary key
|
const char *name; ///< matched by dictionary key
|
||||||
|
|
|
@ -1330,6 +1330,7 @@ PL_ParseArray (const plfield_t *field, const plitem_t *array, void *data,
|
||||||
plitem_t *item = plarray->values[i];
|
plitem_t *item = plarray->values[i];
|
||||||
void *eledata = &arr->a[i * element->stride];
|
void *eledata = &arr->a[i * element->stride];
|
||||||
|
|
||||||
|
f.offset = i;
|
||||||
if (!PL_CheckType (element->type, item->type)) {
|
if (!PL_CheckType (element->type, item->type)) {
|
||||||
char index[16];
|
char index[16];
|
||||||
snprintf (index, sizeof(index) - 1, "%d", i);
|
snprintf (index, sizeof(index) - 1, "%d", i);
|
||||||
|
@ -1381,6 +1382,8 @@ PL_ParseLabeledArray (const plfield_t *field, const plitem_t *item,
|
||||||
plitem_t *item = current->value;
|
plitem_t *item = current->value;
|
||||||
void *eledata = &arr->a[i * element->stride];
|
void *eledata = &arr->a[i * element->stride];
|
||||||
|
|
||||||
|
f.name = current->key;
|
||||||
|
f.offset = i;
|
||||||
if (!PL_CheckType (element->type, item->type)) {
|
if (!PL_CheckType (element->type, item->type)) {
|
||||||
char index[16];
|
char index[16];
|
||||||
snprintf (index, sizeof(index) - 1, "%zd", i);
|
snprintf (index, sizeof(index) - 1, "%zd", i);
|
||||||
|
|
Loading…
Reference in a new issue