From b493e6ac324c7414f2fc8a902565f7da88214d7a Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 5 Jan 2021 23:39:52 +0900 Subject: [PATCH] [util] Expose plist type check support functions --- include/QF/qfplist.h | 5 +++++ libs/util/qfplist.c | 24 ++++++++++++------------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/include/QF/qfplist.h b/include/QF/qfplist.h index 20c7671bb..3f22a9e16 100644 --- a/include/QF/qfplist.h +++ b/include/QF/qfplist.h @@ -310,6 +310,11 @@ plitem_t *PL_NewString (const char *str); */ void PL_Free (plitem_t *item); +int PL_CheckType (pltype_t field_type, pltype_t item_type); +void PL_TypeMismatch (plitem_t *messages, const plitem_t *item, + const char *name, pltype_t field_type, + pltype_t item_type); + /** Parse a dictionary object into a structure. For each key in the dictionary, the corresponding field item is used to diff --git a/libs/util/qfplist.c b/libs/util/qfplist.c index c3fc5a756..273148657 100644 --- a/libs/util/qfplist.c +++ b/libs/util/qfplist.c @@ -1147,8 +1147,8 @@ pl_default_parser (const plfield_t *field, const plitem_t *item, void *data, return 0; } -static int -types_match (pltype_t field_type, pltype_t item_type) +VISIBLE int +PL_CheckType (pltype_t field_type, pltype_t item_type) { if (field_type & QFMultiType) { // field_type is a mask of allowed types @@ -1159,9 +1159,9 @@ types_match (pltype_t field_type, pltype_t item_type) } } -static void -type_mismatch (plitem_t *messages, const plitem_t *item, const char *name, - pltype_t field_type, pltype_t item_type) +VISIBLE void +PL_TypeMismatch (plitem_t *messages, const plitem_t *item, const char *name, + pltype_t field_type, pltype_t item_type) { const int num_types = sizeof (pl_types) / sizeof (pl_types[0]); if (field_type & QFMultiType) { @@ -1213,9 +1213,9 @@ PL_ParseStruct (const plfield_t *fields, const plitem_t *dict, void *data, } else { parser = pl_default_parser; } - if (!types_match (f->type, item->type)) { - type_mismatch (messages, item, current->key, - f->type, item->type); + if (!PL_CheckType (f->type, item->type)) { + PL_TypeMismatch (messages, item, current->key, + f->type, item->type); result = 0; } else { if (!parser (f, item, flddata, messages, context)) { @@ -1268,11 +1268,11 @@ PL_ParseArray (const plfield_t *field, const plitem_t *array, void *data, plitem_t *item = plarray->values[i]; void *eledata = &arr->a[i * element->stride]; - if (!types_match (element->type, item->type)) { + if (!PL_CheckType (element->type, item->type)) { char index[16]; snprintf (index, sizeof(index) - 1, "%d", i); index[15] = 0; - type_mismatch (messages, item, index, element->type, item->type); + PL_TypeMismatch (messages, item, index, element->type, item->type); result = 0; } else { if (!parser (&f, item, eledata, messages, context)) { @@ -1320,8 +1320,8 @@ PL_ParseSymtab (const plfield_t *field, const plitem_t *dict, void *data, const char *key = current->key; plitem_t *item = current->value; - if (!types_match (element->type, item->type)) { - type_mismatch (messages, item, key, element->type, item->type); + if (!PL_CheckType (element->type, item->type)) { + PL_TypeMismatch (messages, item, key, element->type, item->type); result = 0; continue; }