Add mxmlOptions APIs
michaelrsweet opened this issue · 2 comments
michaelrsweet commented
The current 4.0 API can be further improved by moving all of the thread-global options/callbacks and call-time load/save callbacks into a common mxml_options_t
object that can be passed to the mxmlLoadXxx
and mxmlSaveXxx
functions. Proposed API is as follows:
typedef struct _mxml_options_s mxml_options_t; // Load/save options
typedef size_t (*mxml_io_cb_t)(void *cbdata, void *buffer, size_t bytes); // IO callback function
extern void mxmlOptionsDelete(mxml_options_t *options);
extern mxml_options_t *mxmlOptionsNew(void);
extern void mxmlOptionsSetCustomCallbacks(mxml_options_t *options, mxml_custom_load_cb_t load_cb, mxml_custom_save_cb_t save_cb, void *cbdata);
extern void mxmlOptionsSetEntityCallback(mxml_options_t *options, mxml_entity_cb_t cb, void *cbdata);
extern void mxmlOptionsSetErrorCallback(mxml_options_t *options, mxml_error_cb_t cb, void *cbdata);
extern void mxmlOptionsSetSAXCallback(mxml_options_t *options, mxml_sax_cb_t cb, void *cbdata);
extern void mxmlOptionsSetTypeCallback(mxml_options_t *options, mxml_type_cb_t cb, void *cbdata);
extern void mxmlOptionsSetTypeValue(mxml_options_t *options, mxml_type_t type);
extern void mxmlOptionsSetWhitespaceCallback(mxml_options_t *options, mxml_ws_cb_t cb, void *cbdata);
extern void mxmlOptionsSetWrapMargin(mxml_options_t *options, int col);
extern mxml_node_t *mxmlLoadFd(mxml_node_t *top, mxml_options_t *options, int fd);
extern mxml_node_t *mxmlLoadFile(mxml_node_t *top, mxml_options_t *options, FILE *fp);
extern mxml_node_t *mxmlLoadFilename(mxml_node_t *top, mxml_options_t *options, const char *filename);
extern mxml_node_t *mxmlLoadIO(mxml_node_t *top, mxml_options_t *options, mxml_io_cb_t cb, void *cbdata);
extern mxml_node_t *mxmlLoadString(mxml_node_t *top, mxml_options_t *options, const char *s);
extern char *mxmlSaveAllocString(mxml_node_t *node, mxml_options_t *options);
extern bool mxmlSaveFd(mxml_node_t *node, mxml_options_t *options, int fd);
extern bool mxmlSaveFile(mxml_node_t *node, mxml_options_t *options, FILE *fp);
extern bool mxmlSaveFilename(mxml_node_t *node, mxml_options_t *options, const char *filename);
extern bool mxmlSaveIO(mxml_node_t *node, mxml_options_t *options, mxml_io_cb_t cb, void *cbdata);
extern size_t mxmlSaveString(mxml_node_t *node, mxml_options_t *options, char *buffer, size_t bufsize);
The string callback functions would remain thread-global since otherwise we'd need to pass the options everywhere or maintain extra pointers in the mxml_node_t
structure.
michaelrsweet commented
michaelrsweet commented