2003-09-28 21:09:04 +00:00
|
|
|
/*
|
2005-01-29 07:21:44 +00:00
|
|
|
* "$Id$"
|
2003-09-28 21:09:04 +00:00
|
|
|
*
|
2004-05-02 16:04:40 +00:00
|
|
|
* Private functions for Mini-XML, a small XML-like file parsing library.
|
2003-09-28 21:09:04 +00:00
|
|
|
*
|
2007-09-21 04:46:02 +00:00
|
|
|
* Copyright 2003-2007 by Michael Sweet.
|
2003-09-28 21:09:04 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2, 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.
|
|
|
|
*
|
|
|
|
* Contents:
|
|
|
|
*
|
2003-12-03 03:59:04 +00:00
|
|
|
* mxml_error() - Display an error message.
|
2003-09-28 21:09:04 +00:00
|
|
|
* mxml_integer_cb() - Default callback for integer values.
|
|
|
|
* mxml_opaque_cb() - Default callback for opaque values.
|
|
|
|
* mxml_real_cb() - Default callback for real number values.
|
2007-09-22 21:00:56 +00:00
|
|
|
* _mxml_global() - Get global data.
|
2003-09-28 21:09:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Include necessary headers...
|
|
|
|
*/
|
|
|
|
|
2007-09-21 04:46:02 +00:00
|
|
|
#include "mxml-private.h"
|
2003-12-03 03:59:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 'mxml_error()' - Display an error message.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
mxml_error(const char *format, /* I - Printf-style format string */
|
|
|
|
...) /* I - Additional arguments as needed */
|
|
|
|
{
|
|
|
|
va_list ap; /* Pointer to arguments */
|
2005-08-16 14:46:18 +00:00
|
|
|
char s[1024]; /* Message string */
|
2007-09-21 04:46:02 +00:00
|
|
|
_mxml_global_t *global = _mxml_global();
|
|
|
|
/* Global data */
|
2003-12-03 03:59:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Range check input...
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!format)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Format the error message string...
|
|
|
|
*/
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
2005-08-16 14:46:18 +00:00
|
|
|
vsnprintf(s, sizeof(s), format, ap);
|
2003-12-03 03:59:04 +00:00
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* And then display the error message...
|
|
|
|
*/
|
|
|
|
|
2007-09-21 04:46:02 +00:00
|
|
|
if (global->error_cb)
|
|
|
|
(*global->error_cb)(s);
|
2003-12-03 03:59:04 +00:00
|
|
|
else
|
2004-06-01 20:19:34 +00:00
|
|
|
fprintf(stderr, "mxml: %s\n", s);
|
2003-12-03 03:59:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-07 23:43:45 +00:00
|
|
|
/*
|
|
|
|
* 'mxml_ignore_cb()' - Default callback for ignored values.
|
|
|
|
*/
|
|
|
|
|
|
|
|
mxml_type_t /* O - Node type */
|
|
|
|
mxml_ignore_cb(mxml_node_t *node) /* I - Current node */
|
|
|
|
{
|
|
|
|
(void)node;
|
|
|
|
|
|
|
|
return (MXML_IGNORE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-28 21:09:04 +00:00
|
|
|
/*
|
|
|
|
* 'mxml_integer_cb()' - Default callback for integer values.
|
|
|
|
*/
|
|
|
|
|
|
|
|
mxml_type_t /* O - Node type */
|
|
|
|
mxml_integer_cb(mxml_node_t *node) /* I - Current node */
|
|
|
|
{
|
|
|
|
(void)node;
|
|
|
|
|
|
|
|
return (MXML_INTEGER);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 'mxml_opaque_cb()' - Default callback for opaque values.
|
|
|
|
*/
|
|
|
|
|
|
|
|
mxml_type_t /* O - Node type */
|
|
|
|
mxml_opaque_cb(mxml_node_t *node) /* I - Current node */
|
|
|
|
{
|
|
|
|
(void)node;
|
|
|
|
|
|
|
|
return (MXML_OPAQUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 'mxml_real_cb()' - Default callback for real number values.
|
|
|
|
*/
|
|
|
|
|
|
|
|
mxml_type_t /* O - Node type */
|
|
|
|
mxml_real_cb(mxml_node_t *node) /* I - Current node */
|
|
|
|
{
|
|
|
|
(void)node;
|
|
|
|
|
|
|
|
return (MXML_REAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-22 21:00:56 +00:00
|
|
|
#ifdef HAVE_PTHREAD_H /**** POSIX threading ****/
|
|
|
|
# include <pthread.h>
|
|
|
|
|
|
|
|
static pthread_key_t _mxml_key = -1; /* Thread local storage key */
|
|
|
|
static pthread_once_t _mxml_key_once = PTHREAD_ONCE_INIT;
|
|
|
|
/* One-time initialization object */
|
|
|
|
static void _mxml_init(void);
|
|
|
|
static void _mxml_destructor(void *g);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* '_mxml_global()' - Get global data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
_mxml_global_t * /* O - Global data */
|
|
|
|
_mxml_global(void)
|
|
|
|
{
|
|
|
|
_mxml_global_t *global; /* Global data */
|
|
|
|
|
|
|
|
|
|
|
|
pthread_once(&_mxml_key_once, _mxml_init);
|
|
|
|
|
|
|
|
if ((global = (_mxml_global_t *)pthread_getspecific(_mxml_key)) == NULL)
|
|
|
|
{
|
|
|
|
global = (_mxml_global_t *)calloc(1, sizeof(_mxml_global_t));
|
|
|
|
pthread_setspecific(_mxml_key, global);
|
|
|
|
|
|
|
|
global->num_entity_cbs = 1;
|
|
|
|
global->entity_cbs[0] = _mxml_entity_cb;
|
|
|
|
global->wrap = 72;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (global);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* '_mxml_init()' - Initialize global data...
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
_mxml_init(void)
|
|
|
|
{
|
|
|
|
pthread_key_create(&_mxml_key, _mxml_destructor);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* '_mxml_destructor()' - Free memory used for globals...
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
_mxml_destructor(void *g) /* I - Global data */
|
|
|
|
{
|
|
|
|
free(g);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else /**** No threading ****/
|
|
|
|
/*
|
|
|
|
* '_mxml_global()' - Get global data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
_mxml_global_t * /* O - Global data */
|
|
|
|
_mxml_global(void)
|
|
|
|
{
|
|
|
|
static _mxml_global_t global = /* Global data */
|
|
|
|
{
|
|
|
|
NULL, /* error_cb */
|
|
|
|
1, /* num_entity_cbs */
|
|
|
|
{ _mxml_entity_cb }, /* entity_cbs */
|
|
|
|
72, /* wrap */
|
|
|
|
NULL, /* custom_load_cb */
|
|
|
|
NULL /* custom_save_cb */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return (&global);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_PTHREAD_H */
|
|
|
|
|
|
|
|
|
2003-09-28 21:09:04 +00:00
|
|
|
/*
|
2005-01-29 07:21:44 +00:00
|
|
|
* End of "$Id$".
|
2003-09-28 21:09:04 +00:00
|
|
|
*/
|