Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mxmlOptions APIs #312

Closed
michaelrsweet opened this issue Mar 18, 2024 · 2 comments
Closed

Add mxmlOptions APIs #312

michaelrsweet opened this issue Mar 18, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request priority-high
Milestone

Comments

@michaelrsweet
Copy link
Owner

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 michaelrsweet self-assigned this Mar 18, 2024
@michaelrsweet michaelrsweet added enhancement New feature or request priority-high labels Mar 18, 2024
@michaelrsweet michaelrsweet added this to the v4.0 milestone Mar 18, 2024
@michaelrsweet
Copy link
Owner Author

Still need to finish documentation, but the core implementation is now done:

[master e676eb3] Implement mxmlOptions APIs to normalize all of the load/save option stuff (Issue #312)

@michaelrsweet
Copy link
Owner Author

[master db39074] Finalize documentation changes (Issue #312)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority-high
Projects
None yet
Development

No branches or pull requests

1 participant