* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
-#include "config.h"
+#include <vlc_common.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
-#include <xlist.h>
-
-#undef XTAG_DEBUG
+#include "xlist.h"
-#undef FALSE
-#undef TRUE
+#include <assert.h>
-#define FALSE (0)
-#define TRUE (!FALSE)
+#undef XTAG_DEBUG
#undef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
char * end;
};
+void xtag_free (XTag * xtag);
+XTag * xtag_new_parse (const char * s, int n);
+char * xtag_get_name (XTag * xtag);
+char * xtag_get_pcdata (XTag * xtag);
+char * xtag_get_attribute (XTag * xtag, const char* attribute);
+XTag * xtag_first_child (XTag * xtag, const char * name);
+XTag * xtag_next_child (XTag * xtag, char * name);
+int xtag_snprint (char * buf, int n, XTag * xtag);
+
/* Character classes */
#define X_NONE 0
#define X_WHITESPACE 1<<0
xtag_cin (char c, int char_class)
{
if (char_class & X_WHITESPACE)
- if (isspace(c)) return TRUE;
+ if (isspace(c)) return true;
if (char_class & X_OPENTAG)
- if (c == '<') return TRUE;
+ if (c == '<') return true;
if (char_class & X_CLOSETAG)
- if (c == '>') return TRUE;
+ if (c == '>') return true;
if (char_class & X_DQUOTE)
- if (c == '"') return TRUE;
+ if (c == '"') return true;
if (char_class & X_SQUOTE)
- if (c == '\'') return TRUE;
+ if (c == '\'') return true;
if (char_class & X_EQUAL)
- if (c == '=') return TRUE;
+ if (c == '=') return true;
if (char_class & X_SLASH)
- if (c == '/') return TRUE;
+ if (c == '/') return true;
- return FALSE;
+ return false;
}
static int
}
}
- return;
+ return;
}
#endif
xi = xtag_index (parser, good_end | bad_end);
if (xi > 0 && xtag_cin (s[xi], good_end)) {
- ret = malloc ((xi+1) * sizeof(char));
+ ret = malloc (xi+1);
strncpy (ret, s, xi);
ret[xi] = '\0';
parser->start = &s[xi];
{
char * s;
- if (!parser->valid) return FALSE;
+ if (!parser->valid) return false;
s = parser->start;
if (!xtag_cin (s[0], char_class)) {
- parser->valid = FALSE;
- return FALSE;
+ parser->valid = false;
+ return false;
}
parser->start = &s[1];
- return TRUE;
+ return true;
}
static char *
}
}
- ret = malloc ((xi+1) * sizeof(char));
+ ret = malloc (xi+1);
strncpy (ret, s, xi);
ret[xi] = '\0';
parser->start = &s[xi];
- if (!xtag_assert_and_pass (parser, quote)) return NULL;
+ if (!xtag_assert_and_pass (parser, quote))
+ {
+ free( ret );
+ return NULL;
+ }
return ret;
}
err_free_name:
free (name);
- parser->valid = FALSE;
+ parser->valid = false;
return NULL;
}
#ifdef XTAG_DEBUG
printf ("got %s expected %s\n", name, tag->name);
#endif
- parser->valid = FALSE;
+ parser->valid = false;
}
free (name);
}
return tag;
}
-XTag *
-xtag_free (XTag * xtag)
+void xtag_free (XTag * xtag)
{
XList * l;
XAttribute * attr;
XTag * child;
- if (xtag == NULL) return NULL;
+ if( !xtag )
+ return;
- if (xtag->name) free (xtag->name);
- if (xtag->pcdata) free (xtag->pcdata);
+ free( xtag->name );
+ free( xtag->pcdata );
- for (l = xtag->attributes; l; l = l->next) {
- if ((attr = (XAttribute *)l->data) != NULL) {
- if (attr->name) free (attr->name);
- if (attr->value) free (attr->value);
- free (attr);
+ for( l = xtag->attributes; l; l = l->next) {
+ if((attr = (XAttribute *)l->data) != NULL) {
+ free( attr->name );
+ free( attr->value );
+ free( attr );
}
}
xlist_free (xtag->attributes);
for (l = xtag->children; l; l = l->next) {
child = (XTag *)l->data;
- xtag_free (child);
+ xtag_free( child );
}
xlist_free (xtag->children);
- free (xtag);
-
- return NULL;
+ free( xtag );
}
XTag *
XTagParser parser;
XTag * tag, * ttag, * wrapper;
- parser.valid = TRUE;
+ parser.valid = true;
parser.current_tag = NULL;
parser.start = (char *)s;
return NULL;
}
-char *
-xtag_get_attribute (XTag * xtag, char * attribute)
+char* xtag_get_attribute (XTag * xtag, const char * attribute)
{
- XList * l;
- XAttribute * attr;
-
- if (xtag == NULL) return NULL;
-
- for (l = xtag->attributes; l; l = l->next) {
- if ((attr = (XAttribute *)l->data) != NULL) {
- if (attr->name && attribute && !strcmp (attr->name, attribute))
- return attr->value;
+ XList * l;
+ XAttribute * attr;
+
+ if( !xtag )
+ return NULL;
+
+ for( l = xtag->attributes; l; l = l->next )
+ {
+ if( ( attr = (XAttribute *)l->data ) != NULL )
+ {
+ if( attr->name && attribute && !strcmp( attr->name, attribute ) )
+ return attr->value;
+ }
}
- }
-
- return NULL;
+ return NULL;
}
-XTag *
-xtag_first_child (XTag * xtag, char * name)
+XTag* xtag_first_child (XTag * xtag, const char * name)
{
- XList * l;
- XTag * child;
+ XList * l;
+ XTag * child;
- if (xtag == NULL) return NULL;
+ if( !xtag )
+ return NULL;
- if ((l = xtag->children) == NULL) return NULL;
+ if( ( l = xtag->children ) == NULL )
+ return NULL;
- if (name == NULL) {
- xtag->current_child = l;
- return (XTag *)l->data;
- }
+ if( !name )
+ {
+ xtag->current_child = l;
+ return (XTag *)l->data;
+ }
- for (; l; l = l->next) {
- child = (XTag *)l->data;
+ for( ; l; l = l->next )
+ {
+ child = (XTag *)l->data;
- if (child->name && name && !strcmp(child->name, name)) {
- xtag->current_child = l;
- return child;
+ if( child->name && name && !strcmp( child->name, name ) )
+ {
+ xtag->current_child = l;
+ return child;
+ }
}
- }
- xtag->current_child = NULL;
-
- return NULL;
+ xtag->current_child = NULL;
+ return NULL;
}
XTag *
int len, to_copy, total = 0;
va_start (ap, n);
-
+
for (s = va_arg (ap, char *); s; s = va_arg (ap, char *)) {
len = strlen (s);
for (l = xtag->attributes; l; l = l->next) {
attr = (XAttribute *)l->data;
-
+
nn = xtag_snprints (buf, n, " ", attr->name, "=\"", attr->value, "\"",
NULL);
FORWARD(nn);
}
-
+
if (xtag->children == NULL) {
nn = xtag_snprints (buf, n, "/>", NULL);
FORWARD(nn);
return written;
}
-
+
nn = xtag_snprints (buf, n, ">", NULL);
FORWARD(nn);
}