2001-02-19 21:15:25 +00:00
|
|
|
/*
|
2021-03-21 07:13:03 +00:00
|
|
|
plist.h
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Property list management types and prototypes
|
|
|
|
|
2001-06-19 02:10:47 +00:00
|
|
|
Copyright (C) 2000 Jeff Teunissen <deek@d2dc.net>
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2021-03-21 07:13:03 +00:00
|
|
|
#ifndef __QF_plist_h
|
|
|
|
#define __QF_plist_h
|
2001-06-19 02:10:47 +00:00
|
|
|
|
2022-05-12 08:54:23 +00:00
|
|
|
struct hashctx_s;
|
2021-02-09 00:57:07 +00:00
|
|
|
|
2021-03-21 07:13:03 +00:00
|
|
|
/** \defgroup plist Property lists
|
2006-12-05 11:40:00 +00:00
|
|
|
\ingroup utils
|
2004-11-11 11:18:00 +00:00
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2004-11-11 11:18:00 +00:00
|
|
|
|
|
|
|
#include "QF/qtypes.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2011-08-20 07:26:51 +00:00
|
|
|
/** The type of the property list item.
|
|
|
|
|
2011-08-20 10:23:31 +00:00
|
|
|
For further details, see \ref property-list.
|
2004-01-06 11:09:40 +00:00
|
|
|
*/
|
2011-08-20 07:26:51 +00:00
|
|
|
typedef enum {
|
|
|
|
QFDictionary, ///< The property list item represents a dictionary.
|
|
|
|
QFArray, ///< The property list item represents an array.
|
|
|
|
QFBinary, ///< The property list item represents arbitrary binary
|
|
|
|
///< data.
|
2021-01-02 05:02:33 +00:00
|
|
|
QFString, ///< The property list item represents a C string.
|
|
|
|
|
|
|
|
QFMultiType = (1 << 31) ///< if bit 31 is set, the type indicates a mask
|
|
|
|
///< of allowed types for plfield_t
|
2011-08-20 07:26:51 +00:00
|
|
|
} pltype_t;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2010-08-20 04:10:37 +00:00
|
|
|
/** Generic property list item.
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2010-08-20 04:10:37 +00:00
|
|
|
All inspection and manipulation is to be done via the accessor functions.
|
2001-06-19 02:10:47 +00:00
|
|
|
*/
|
2010-08-20 04:10:37 +00:00
|
|
|
typedef struct plitem_s plitem_t;
|
2001-08-01 06:51:06 +00:00
|
|
|
|
2020-07-02 05:20:46 +00:00
|
|
|
struct plfield_s;
|
|
|
|
/** Custom parser for the field.
|
|
|
|
|
|
|
|
With this, custom parsing of any property list object type is
|
|
|
|
supported. For example, parsing of strings into numeric values,
|
|
|
|
converting binary objects to images, and deeper parsing of array and
|
|
|
|
dictionary objects.
|
|
|
|
|
|
|
|
If null, then the default parser for the object type is used:
|
2022-04-02 01:53:23 +00:00
|
|
|
* QFString: pointer to the actual string. The string continues to
|
|
|
|
be owned by the string object.
|
2020-07-02 05:20:46 +00:00
|
|
|
* QFBinary: pointer to fixed-size DARRAY_TYPE(byte) (so size isn't
|
|
|
|
lost)
|
|
|
|
* QFArray: pointer to fixed-size DARRAY_TYPE(plitem_t *) with the
|
2022-04-02 01:53:23 +00:00
|
|
|
individual objects. The individual objects continue to be owned
|
2020-07-02 05:20:46 +00:00
|
|
|
by the array object.
|
|
|
|
* QFDictionary: pointer to the hashtab_t hash table used for the
|
|
|
|
dictionary object. The hash table continues to be owned by the
|
|
|
|
dictionary object.
|
|
|
|
|
|
|
|
\param field Pointer to this field item.
|
|
|
|
\param item The property list item being parsed into the field.
|
|
|
|
\param data Pointer to the field in the structure being parsed.
|
|
|
|
\param messages An array object the parser can use to store any
|
|
|
|
error messages. Messages should be strings, but no
|
|
|
|
checking is done: it is up to the top-level caller to
|
|
|
|
parse out the messages.
|
2020-12-21 04:55:54 +00:00
|
|
|
\param context Additional context data passed to the parser.
|
2022-04-02 01:53:23 +00:00
|
|
|
\return 0 for error, 1 for success. See \a PL_ParseStruct,
|
|
|
|
\a PL_ParseArray, \a PL_ParseLabeledArray, and
|
|
|
|
\a PL_ParseSymtab.
|
2020-07-02 05:20:46 +00:00
|
|
|
*/
|
|
|
|
typedef int (*plparser_t) (const struct plfield_s *field,
|
|
|
|
const struct plitem_s *item,
|
|
|
|
void *data,
|
2020-12-21 04:55:54 +00:00
|
|
|
struct plitem_s *messages,
|
|
|
|
void *context);
|
2020-07-02 05:20:46 +00:00
|
|
|
|
|
|
|
/** A field to be parsed from a dictionary item.
|
|
|
|
|
2022-04-02 01:53:23 +00:00
|
|
|
\a PL_ParseStruct uses an array (terminated by an element with \a name
|
|
|
|
set to null) of these to describe the fields in the structure being
|
|
|
|
parsed.
|
|
|
|
|
|
|
|
\a PL_ParseArray, \a PL_ParseLabeledArray, and \a PL_ParseSymtab use only
|
|
|
|
a single \a plfield_t object, and then only the \a data field, which must
|
|
|
|
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
|
|
|
|
\a parser.
|
2020-07-02 05:20:46 +00:00
|
|
|
*/
|
|
|
|
typedef struct plfield_s {
|
|
|
|
const char *name; ///< matched by dictionary key
|
|
|
|
size_t offset; ///< the offset of the field within the structure
|
|
|
|
pltype_t type; ///< the required type of the dictionary object
|
|
|
|
plparser_t parser; ///< custom parser function
|
|
|
|
void *data; ///< additional data for \a parser
|
|
|
|
} plfield_t;
|
|
|
|
|
2020-07-14 03:05:34 +00:00
|
|
|
typedef struct plelement_s {
|
|
|
|
pltype_t type; ///< the required type of the array elements
|
|
|
|
size_t stride; ///< the size of each element
|
2021-02-09 06:01:55 +00:00
|
|
|
void *(*alloc) (void *ctx, size_t size);///< allocator for array memory
|
2020-07-14 03:05:34 +00:00
|
|
|
plparser_t parser; ///< custom parser function
|
|
|
|
void *data; ///< additional data for \a parser
|
|
|
|
} plelement_t;
|
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
/** Create an in-memory representation of the contents of a property list.
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2004-01-06 11:09:40 +00:00
|
|
|
\param string the saved plist, as read from a file.
|
2022-05-12 08:54:23 +00:00
|
|
|
\param hashctx Hashlink chain to use when creating dictionaries (see
|
2021-02-09 00:57:07 +00:00
|
|
|
Hash_NewTable()). May be null.
|
2004-01-06 11:09:40 +00:00
|
|
|
|
|
|
|
\return Returns an object equivalent to the passed-in string.
|
2010-11-18 15:06:53 +00:00
|
|
|
\note You are responsible for freeing the returned object.
|
2004-01-06 11:09:40 +00:00
|
|
|
*/
|
2021-02-09 00:57:07 +00:00
|
|
|
plitem_t *PL_GetPropertyList (const char *string,
|
2022-05-12 08:54:23 +00:00
|
|
|
struct hashctx_s **hashctx);
|
2004-01-06 11:09:40 +00:00
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
/** Create a property list string from the in-memory representation.
|
|
|
|
|
|
|
|
\param pl the in-memory representation
|
|
|
|
\return the text representation of the property list
|
2010-11-18 15:06:53 +00:00
|
|
|
\note You are responsible for freeing the returned string.
|
2004-11-11 11:18:00 +00:00
|
|
|
*/
|
2021-02-25 02:55:25 +00:00
|
|
|
char *PL_WritePropertyList (const plitem_t *pl);
|
2004-11-11 11:18:00 +00:00
|
|
|
|
|
|
|
/** Retrieve the type of an object.
|
|
|
|
|
2021-03-03 09:01:35 +00:00
|
|
|
\param item The object. Must not be null.
|
2004-11-11 11:18:00 +00:00
|
|
|
\return the type of the object
|
|
|
|
*/
|
2020-07-16 15:22:47 +00:00
|
|
|
pltype_t PL_Type (const plitem_t *item) __attribute__((pure));
|
2004-11-11 11:18:00 +00:00
|
|
|
|
2020-07-01 12:47:09 +00:00
|
|
|
/** Retrieve the line number of an object.
|
|
|
|
|
2021-03-03 09:01:35 +00:00
|
|
|
\param item The object. Must not be null.
|
2020-07-01 12:47:09 +00:00
|
|
|
\return the line number on which the object began, or 0 if not from a
|
|
|
|
string
|
|
|
|
*/
|
2020-07-16 15:22:47 +00:00
|
|
|
int PL_Line (const plitem_t *item) __attribute__((pure));
|
2020-07-01 12:47:09 +00:00
|
|
|
|
2020-12-23 05:07:30 +00:00
|
|
|
/** Retrieve the data size from a binary object.
|
|
|
|
|
|
|
|
\param binary The binary object
|
2021-03-03 09:01:35 +00:00
|
|
|
\return the size in bytes of the binary object 0 if \a binary isn't a
|
|
|
|
binary object (includes if \a binary is null).
|
2020-12-23 05:07:30 +00:00
|
|
|
*/
|
2020-12-24 06:59:33 +00:00
|
|
|
size_t PL_BinarySize (const plitem_t *binary) __attribute__((pure));
|
2020-12-23 05:07:30 +00:00
|
|
|
|
|
|
|
/** Retrieve the data from a binary object.
|
|
|
|
|
|
|
|
\param binary The binary object
|
2021-03-03 09:01:35 +00:00
|
|
|
\return pointer to the actual data or NULL if \b binary isn't a binary
|
|
|
|
object (includes if \a binary is null).
|
2020-12-23 05:07:30 +00:00
|
|
|
\note You are NOT responsible for freeing the returned object. It will
|
|
|
|
be destroyed when its container is.
|
|
|
|
*/
|
|
|
|
const void *PL_BinaryData (const plitem_t *binary) __attribute__((pure));
|
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
/** Retrieve a string from a string object.
|
|
|
|
|
|
|
|
\param string The string object
|
|
|
|
\return pointer to the actual string value or NULL if string isn't a
|
2021-03-03 09:01:35 +00:00
|
|
|
string (includes if \a string is null).
|
2004-11-11 11:18:00 +00:00
|
|
|
\note You are NOT responsible for freeing the returned object. It will
|
|
|
|
be destroyed when its container is.
|
|
|
|
*/
|
2020-07-16 13:02:26 +00:00
|
|
|
const char *PL_String (const plitem_t *string) __attribute__((pure));
|
2004-11-11 11:18:00 +00:00
|
|
|
|
|
|
|
/** Retrieve a value from a dictionary object.
|
2004-01-06 11:09:40 +00:00
|
|
|
|
|
|
|
\param dict The dictionary to retrieve a value from
|
|
|
|
\param key The unique key associated with the value
|
2021-03-03 09:01:35 +00:00
|
|
|
\return the value associated with the key, or NULL if not found or \a dict
|
|
|
|
isn't a dictionary (includes if \a dict is null).
|
2004-11-11 11:18:00 +00:00
|
|
|
\note You are NOT responsible for freeing the returned object. It will
|
2004-01-06 11:09:40 +00:00
|
|
|
be destroyed when its container is.
|
|
|
|
*/
|
2021-02-09 05:56:48 +00:00
|
|
|
plitem_t *PL_ObjectForKey (const plitem_t *dict, const char *key);
|
2004-01-06 11:09:40 +00:00
|
|
|
|
2006-12-18 13:11:26 +00:00
|
|
|
/** Remove a value from a dictionary object.
|
2006-12-09 06:00:36 +00:00
|
|
|
|
|
|
|
\param dict The Dictionary to remove the value from
|
|
|
|
\param key The unique key associated with the value to be removed
|
2021-03-03 09:01:35 +00:00
|
|
|
\return the value associated with the key, or NULL if not found or \a dict
|
|
|
|
isn't a dictionary (includes if \a dict is null).
|
2006-12-09 06:00:36 +00:00
|
|
|
\note You are responsible for freeing the returned object.
|
|
|
|
*/
|
2021-12-06 04:03:49 +00:00
|
|
|
plitem_t *PL_RemoveObjectForKey (plitem_t *dict, const char *key);
|
2006-12-09 06:00:36 +00:00
|
|
|
|
2021-02-09 07:53:21 +00:00
|
|
|
/** Retrieve a key from a dictionary object.
|
|
|
|
|
|
|
|
\param dict The dictionary to get the key from
|
|
|
|
\param index The index of the key
|
|
|
|
\return the key at the specified index, or NULL if index is out of range or
|
2021-03-03 09:01:35 +00:00
|
|
|
dict is not a dictionary (includes if \a dict is null).
|
2021-02-09 07:53:21 +00:00
|
|
|
\note You are NOT responsible for freeing the returned object. It will
|
|
|
|
be destroyed when its container is.
|
|
|
|
*/
|
2021-03-03 09:01:35 +00:00
|
|
|
const char *PL_KeyAtIndex (const plitem_t *dict, int index) __attribute__((pure));
|
2021-02-09 07:53:21 +00:00
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
/** Retrieve a value from an array object.
|
2004-01-06 11:09:40 +00:00
|
|
|
|
|
|
|
\param array The array to get the value from
|
2004-01-07 20:06:15 +00:00
|
|
|
\param index The index within the array to retrieve
|
2021-03-03 09:01:35 +00:00
|
|
|
\return the value at the specified index, or NULL if \a index is out of
|
|
|
|
range or \a array is not an array (includes in \a array is null).
|
2004-11-11 11:18:00 +00:00
|
|
|
\note You are NOT responsible for freeing the returned object. It will
|
2004-01-06 11:09:40 +00:00
|
|
|
be destroyed when its container is.
|
|
|
|
*/
|
2021-02-09 05:56:48 +00:00
|
|
|
plitem_t *PL_ObjectAtIndex (const plitem_t *array, int index) __attribute__((pure));
|
2003-03-18 19:15:31 +00:00
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
/** Retrieve a list of all keys in a dictionary.
|
2004-01-06 11:09:40 +00:00
|
|
|
|
|
|
|
\param dict The dictionary to list
|
2021-03-03 09:01:35 +00:00
|
|
|
\return an Array containing Strings or NULL if \a dict isn't a dictionary
|
|
|
|
(includes if \a dict is null).
|
2004-11-11 11:18:00 +00:00
|
|
|
\note You are responsible for freeing this array.
|
2004-01-06 11:09:40 +00:00
|
|
|
*/
|
2021-02-25 02:55:25 +00:00
|
|
|
plitem_t *PL_D_AllKeys (const plitem_t *dict);
|
2004-01-06 11:09:40 +00:00
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
/** Retrieve the number of keys in a dictionary.
|
2004-02-07 07:47:23 +00:00
|
|
|
|
|
|
|
\param dict The dictionary to get the number of keys of.
|
|
|
|
|
2021-03-03 09:01:35 +00:00
|
|
|
\return Returns the number of keys in the dictionary or 0 if \a dict isn't
|
|
|
|
a dictionary (includes if \a dict is null).
|
2004-02-07 07:47:23 +00:00
|
|
|
*/
|
2021-02-09 05:56:48 +00:00
|
|
|
int PL_D_NumKeys (const plitem_t *dict) __attribute__((pure));
|
2004-02-07 07:47:23 +00:00
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
/** Add a key/value pair to a dictionary.
|
2004-01-07 06:19:11 +00:00
|
|
|
|
2010-11-18 15:06:53 +00:00
|
|
|
\param dict The dictionary to which the key/value pair will be added
|
2004-01-07 06:19:11 +00:00
|
|
|
\param key The key of the key/value pair to be added to the dictionary
|
|
|
|
\param value The value of the key/value pair to be added to the dictionary
|
|
|
|
|
2021-03-03 09:01:35 +00:00
|
|
|
\return true on success, false on failure (\a dict is null or not a
|
|
|
|
dictionary)
|
2004-01-07 06:19:11 +00:00
|
|
|
|
2006-12-09 06:00:36 +00:00
|
|
|
\note the dictionary becomes the owner of the value.
|
2004-01-07 06:19:11 +00:00
|
|
|
*/
|
2006-12-09 06:00:36 +00:00
|
|
|
qboolean PL_D_AddObject (plitem_t *dict, const char *key, plitem_t *value);
|
2004-11-11 11:18:00 +00:00
|
|
|
|
|
|
|
/** Add an item to an array.
|
2004-01-09 03:32:00 +00:00
|
|
|
|
2010-11-18 15:06:53 +00:00
|
|
|
\param array The array to which the item will be added
|
2004-01-09 03:32:00 +00:00
|
|
|
\param item The item to be added to the array
|
|
|
|
|
2021-03-03 09:01:35 +00:00
|
|
|
\return true on success, false on failure (\a array is null or not an
|
|
|
|
array)
|
2004-01-09 03:32:00 +00:00
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
\note the array becomes the owner of the added item.
|
2004-01-09 03:32:00 +00:00
|
|
|
*/
|
2004-11-11 11:18:00 +00:00
|
|
|
qboolean PL_A_AddObject (plitem_t *array, plitem_t *item);
|
|
|
|
|
|
|
|
/** Retrieve the number of items in an array.
|
2004-01-09 03:32:00 +00:00
|
|
|
|
2010-11-18 15:06:53 +00:00
|
|
|
\param array The array from which to get the number of objects
|
2004-02-07 07:47:23 +00:00
|
|
|
|
2021-03-03 09:01:35 +00:00
|
|
|
\return number of objects in the array or 0 if \a array is null or not
|
|
|
|
an array.
|
2004-02-07 07:47:23 +00:00
|
|
|
*/
|
2021-02-25 02:55:25 +00:00
|
|
|
int PL_A_NumObjects (const plitem_t *array) __attribute__((pure));
|
2004-02-07 07:47:23 +00:00
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
/** Insert an item into an array before the specified location.
|
|
|
|
|
2010-11-18 15:06:53 +00:00
|
|
|
\param array The array to which the item will be added
|
2004-01-09 03:32:00 +00:00
|
|
|
\param item The item to be added to the array
|
|
|
|
\param index The location at which to insert the item into the array
|
|
|
|
|
2021-03-03 09:01:35 +00:00
|
|
|
\return true on success, false on failure (\a array is null or not an
|
|
|
|
array).
|
2004-01-09 03:32:00 +00:00
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
\note the array becomes the owner of the added item.
|
2004-01-09 03:32:00 +00:00
|
|
|
*/
|
2004-11-11 11:18:00 +00:00
|
|
|
qboolean PL_A_InsertObjectAtIndex (plitem_t *array, plitem_t *item, int index);
|
2003-03-18 19:15:31 +00:00
|
|
|
|
2006-12-09 02:33:08 +00:00
|
|
|
/** Remove a value from an array object.
|
|
|
|
The array items will be shuffled to fill the resulting hole.
|
|
|
|
|
2010-11-18 15:06:53 +00:00
|
|
|
\param array The array from which to remove the value
|
2006-12-09 02:33:08 +00:00
|
|
|
\param index The index within the array to remove
|
|
|
|
\return the value associated with the index, or NULL if not found or array
|
2021-03-03 09:01:35 +00:00
|
|
|
is noll or an array.
|
2006-12-09 02:33:08 +00:00
|
|
|
\note You are responsible for freeing the returned object.
|
|
|
|
*/
|
|
|
|
plitem_t *PL_RemoveObjectAtIndex (plitem_t *array, int index);
|
|
|
|
|
2010-08-20 04:10:37 +00:00
|
|
|
/** Create a new dictionary object.
|
|
|
|
The dictionary will be empty.
|
2022-05-12 08:54:23 +00:00
|
|
|
\param hashctx Hashlink chain to use when creating dictionaries (see
|
2021-02-09 00:57:07 +00:00
|
|
|
Hash_NewTable()). May be null.
|
2010-08-20 04:10:37 +00:00
|
|
|
\return the new dictionary object
|
|
|
|
*/
|
2022-05-12 08:54:23 +00:00
|
|
|
plitem_t *PL_NewDictionary (struct hashctx_s **hashctx);
|
2010-08-20 04:10:37 +00:00
|
|
|
|
|
|
|
/** Create a new array object.
|
|
|
|
The array will be empty.
|
|
|
|
\return the new array object
|
|
|
|
*/
|
2003-03-18 19:15:31 +00:00
|
|
|
plitem_t *PL_NewArray (void);
|
2010-08-20 04:10:37 +00:00
|
|
|
|
|
|
|
/** Create a new data object from the given data.
|
2010-08-20 04:21:22 +00:00
|
|
|
Takes ownership of the given data.
|
2010-08-20 04:10:37 +00:00
|
|
|
\param data pointer to data buffer
|
|
|
|
\param size number of bytes in the buffer
|
|
|
|
\return the new dictionary object
|
2010-08-20 04:21:22 +00:00
|
|
|
\note The data will be freed via free() when the item is freed.
|
2010-08-20 04:10:37 +00:00
|
|
|
*/
|
2010-08-20 04:21:22 +00:00
|
|
|
plitem_t *PL_NewData (void *data, size_t size);
|
2010-08-20 04:10:37 +00:00
|
|
|
|
|
|
|
/** Create a new string object.
|
|
|
|
Makes a copy of the given string.
|
|
|
|
\param str C string to copy
|
|
|
|
\return the new dictionary object
|
|
|
|
*/
|
|
|
|
plitem_t *PL_NewString (const char *str);
|
2003-03-18 19:15:31 +00:00
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
/** Free a property list object.
|
2004-01-06 11:09:40 +00:00
|
|
|
|
|
|
|
This function takes care of freeing any referenced property list data, so
|
2021-03-03 09:01:35 +00:00
|
|
|
call it only on top-level objects. Safe to call with a null argument.
|
2004-11-11 11:18:00 +00:00
|
|
|
|
|
|
|
\param item the property list object to be freed
|
2004-01-06 11:09:40 +00:00
|
|
|
*/
|
2004-11-11 11:18:00 +00:00
|
|
|
void PL_Free (plitem_t *item);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-01-06 16:10:25 +00:00
|
|
|
int PL_CheckType (pltype_t field_type, pltype_t item_type) __attribute__((const));
|
2021-01-05 14:39:52 +00:00
|
|
|
void PL_TypeMismatch (plitem_t *messages, const plitem_t *item,
|
|
|
|
const char *name, pltype_t field_type,
|
|
|
|
pltype_t item_type);
|
|
|
|
|
2020-07-02 05:20:46 +00:00
|
|
|
/** Parse a dictionary object into a structure.
|
|
|
|
|
|
|
|
For each key in the dictionary, the corresponding field item is used to
|
|
|
|
determine how to parse the object associated with that key. Duplicate
|
|
|
|
field items are ignored: only the first item is used, and no checking is
|
|
|
|
done. Fields for which there is no key in the dictionary are also ignored,
|
|
|
|
and the destination is left unmodified. However, keys that have no
|
|
|
|
corresponding field are treated as errors and a suitable message is added
|
|
|
|
to the \a messages object.
|
|
|
|
|
|
|
|
When an error occurs (unknown key, incorrect item type (item type does not
|
|
|
|
match the type specified in the field item) or the field item's \a parser
|
|
|
|
returns 0), processing continues but the error result is returned.
|
|
|
|
|
|
|
|
Can be used recursively to parse deep hierarchies.
|
|
|
|
|
|
|
|
\param fields Array of field items describing the structure. Terminated
|
|
|
|
by a field item with a null \a name pointer.
|
2020-12-24 06:59:33 +00:00
|
|
|
\param dict The dictionary object to parse
|
2020-07-02 05:20:46 +00:00
|
|
|
\param data Pointer to the structure into which the data will be
|
|
|
|
parsed.
|
|
|
|
\param messages Array object supplied by the caller used for storing
|
|
|
|
messages. The messages may or may not indicate errors (its
|
|
|
|
contents are not checked). This function itself will add
|
|
|
|
only string objects.
|
|
|
|
If there are any errors, suitable messages will be found in
|
|
|
|
the \a messages object. However, just because there are no
|
|
|
|
errors doesn't mean that \a messages will remain empty as
|
|
|
|
a field's \a parser may add other messages. The standard
|
|
|
|
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).
|
2020-12-21 04:55:54 +00:00
|
|
|
\param context Additional context data passed to the parser.
|
2020-07-02 05:20:46 +00:00
|
|
|
\return 0 if there are any errors, 1 if there are no errors.
|
|
|
|
*/
|
2020-12-24 04:33:37 +00:00
|
|
|
int PL_ParseStruct (const plfield_t *fields, const plitem_t *dict,
|
|
|
|
void *data, plitem_t *messages, void *context);
|
2020-12-24 06:59:33 +00:00
|
|
|
|
2021-02-09 06:01:55 +00:00
|
|
|
/** Parse an array object into a dynamic array (see darray.h).
|
2020-12-24 06:59:33 +00:00
|
|
|
|
|
|
|
For each object in the array, the field item is used to determine how to
|
|
|
|
parse the object. If the array is empty, the destination will be
|
|
|
|
initialized to an empty array.
|
|
|
|
|
|
|
|
When an error occurs (incorrect item type (item type does not match the
|
|
|
|
type specified in the element object) or the element object's \a parser
|
|
|
|
returns 0), processing continues but the error result is returned.
|
|
|
|
|
|
|
|
Can be used recursively to parse deep hierarchies.
|
|
|
|
|
|
|
|
\param field Pointer to a single field that has the field data pointer
|
|
|
|
set to reference a plelement_t object used to describe
|
|
|
|
the contents of the array.
|
|
|
|
\param array The array object to parse
|
|
|
|
\param data Pointer to the pointer to which the dynamic array will
|
|
|
|
be written. The dynamic array is allocated using
|
2021-02-09 06:01:55 +00:00
|
|
|
DARRAY_ALLOCFIXED_OBJ().
|
2020-12-24 06:59:33 +00:00
|
|
|
\param messages Array object supplied by the caller used for storing
|
|
|
|
messages. The messages may or may not indicate errors (its
|
|
|
|
contents are not checked). This function itself will add
|
|
|
|
only string objects.
|
|
|
|
If there are any errors, suitable messages will be found in
|
|
|
|
the \a messages object. However, just because there are no
|
|
|
|
errors doesn't mean that \a messages will remain empty as
|
|
|
|
a field's \a parser may add other messages. The standard
|
|
|
|
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).
|
2021-02-09 06:01:55 +00:00
|
|
|
\param context Additional context data passed to the parser and allocator.
|
2020-12-24 06:59:33 +00:00
|
|
|
\return 0 if there are any errors, 1 if there are no errors.
|
|
|
|
*/
|
|
|
|
int PL_ParseArray (const plfield_t *field, const plitem_t *array,
|
2020-12-21 04:55:54 +00:00
|
|
|
void *data, plitem_t *messages, void *context);
|
2020-12-24 06:59:33 +00:00
|
|
|
|
2021-02-09 06:24:28 +00:00
|
|
|
/** Parse a dictionary object into a dynamic array (see darray.h).
|
|
|
|
|
|
|
|
This is useful when the dictionary object is meant to be a labeled list
|
|
|
|
rather than a representation of a structure.
|
|
|
|
|
|
|
|
For each object in the array, the field item is used to determine how to
|
|
|
|
parse the object. If the array is empty, the destination will be
|
|
|
|
initialized to an empty array.
|
|
|
|
|
|
|
|
When an error occurs (incorrect item type (item type does not match the
|
|
|
|
type specified in the element object) or the element object's \a parser
|
|
|
|
returns 0), processing continues but the error result is returned.
|
|
|
|
|
|
|
|
Can be used recursively to parse deep hierarchies.
|
|
|
|
|
|
|
|
\param field Pointer to a single field that has the field data pointer
|
|
|
|
set to reference a plelement_t object used to describe
|
|
|
|
the contents of the array.
|
|
|
|
\param dict The dict object to parse
|
|
|
|
\param data Pointer to the pointer to which the dynamic array will
|
|
|
|
be written. The dynamic array is allocated using
|
|
|
|
DARRAY_ALLOCFIXED_OBJ().
|
|
|
|
\param messages Array object supplied by the caller used for storing
|
|
|
|
messages. The messages may or may not indicate errors (its
|
|
|
|
contents are not checked). This function itself will add
|
|
|
|
only string objects.
|
|
|
|
If there are any errors, suitable messages will be found in
|
|
|
|
the \a messages object. However, just because there are no
|
|
|
|
errors doesn't mean that \a messages will remain empty as
|
|
|
|
a field's \a parser may add other messages. The standard
|
|
|
|
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 and allocator.
|
|
|
|
\return 0 if there are any errors, 1 if there are no errors.
|
|
|
|
*/
|
|
|
|
int PL_ParseLabeledArray (const plfield_t *field, const plitem_t *dict,
|
|
|
|
void *data, plitem_t *messages, void *context);
|
|
|
|
|
2020-12-24 06:59:33 +00:00
|
|
|
/** Parse a dictionary object into a hash table.
|
|
|
|
|
|
|
|
For each key in the dictionary, the element object is used to determine
|
|
|
|
how to parse the object associated with that key. Duplicate keys are an
|
|
|
|
error: they must be unique. A suitable message is added to the
|
|
|
|
\a messages object. If the dictionary object is empty, the destination
|
|
|
|
table is left unmodified.
|
|
|
|
|
|
|
|
When an error occurs (duplicate keys, incorrect type, or the element
|
|
|
|
object's \a parser returns 0), processing continues but the error
|
|
|
|
result is returned.
|
|
|
|
|
|
|
|
Can be used recursively to parse deep hierarchies.
|
|
|
|
|
|
|
|
Hash_Add() is used to add objects to the hash table, and Hash_Find() is
|
|
|
|
used to check for duplicates. Hash_Free() is used to free unused
|
|
|
|
objects. The means that the hash table is expected to use standard
|
|
|
|
objects with embedded keys (the parser is expected to put the key in the
|
|
|
|
object) and to have a free function.
|
|
|
|
|
|
|
|
The parser's data paramenter points to a pre-allocated block of memory
|
|
|
|
of the sized indicated by the element object's size field, using the
|
|
|
|
element object's alloc callback. The name field in the field paramenter
|
|
|
|
is set to the object's key and remains owned by the dictionary.
|
|
|
|
|
|
|
|
\param field Pointer to a single field that has the field data pointer
|
|
|
|
set to reference a plelement_t object used to describe
|
|
|
|
the contents of the dictionary.
|
|
|
|
\param dict The dictionary object to parse
|
|
|
|
\param data Pointer to the structure into which the data will be
|
|
|
|
parsed.
|
|
|
|
\param messages Array object supplied by the caller used for storing
|
|
|
|
messages. The messages may or may not indicate errors (its
|
|
|
|
contents are not checked). This function itself will add
|
|
|
|
only string objects.
|
|
|
|
If there are any errors, suitable messages will be found in
|
|
|
|
the \a messages object. However, just because there are no
|
|
|
|
errors doesn't mean that \a messages will remain empty as
|
|
|
|
a field's \a parser may add other messages. The standard
|
|
|
|
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).
|
2021-02-09 06:01:55 +00:00
|
|
|
\param context Additional context data passed to the parser and allocator.
|
2020-12-24 06:59:33 +00:00
|
|
|
\return 0 if there are any errors, 1 if there are no errors.
|
|
|
|
*/
|
|
|
|
int PL_ParseSymtab (const plfield_t *field, const plitem_t *dict,
|
|
|
|
void *data, plitem_t *messages, void *context);
|
2021-03-27 10:52:59 +00:00
|
|
|
void __attribute__((format(PRINTF,3,4)))
|
2020-07-16 13:04:33 +00:00
|
|
|
PL_Message (plitem_t *messages, const plitem_t *item, const char *fmt, ...);
|
2020-07-02 05:20:46 +00:00
|
|
|
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-03-21 07:13:03 +00:00
|
|
|
#endif//__QF_plist_h
|