changeset 8170:1f6ae3d15f19

Allow to use the asx parser for some other purposes A few 10L fix
author albeu
date Tue, 12 Nov 2002 14:19:53 +0000
parents 7c9253521f9c
children 2b1db607a09c
files asxparser.c asxparser.h
diffstat 2 files changed, 40 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/asxparser.c	Tue Nov 12 14:16:30 2002 +0000
+++ b/asxparser.c	Tue Nov 12 14:19:53 2002 +0000
@@ -17,8 +17,6 @@
 
 ////// List utils
 
-typedef void (*ASX_FreeFunc)(void* arg);
-
 void
 asx_list_add(void* list_ptr,void* entry){
   void** list = *(void***)list_ptr;
@@ -80,7 +78,7 @@
 
 /////// Attribs utils
 
-static char*
+char*
 asx_get_attrib(char* attrib,char** attribs) {
   char** ptr;
 
@@ -92,7 +90,7 @@
   return NULL;
 }
 
-static int
+int
 asx_attrib_to_enum(char* val,char** valid_vals) {
   char** ptr;
   int r = 0;
@@ -150,8 +148,6 @@
   return r;
 }
 
-#define asx_free_attribs(a) asx_list_free((void***)&a,free)
-
 #define asx_warning_attrib_required(p,e,a) mp_msg(MSGT_PLAYTREE,MSGL_WARN,"At line %d : element %s don't have the required attribute %s",p->line,e,a)
 #define asx_warning_body_parse_error(p,e) mp_msg(MSGT_PLAYTREE,MSGL_WARN,"At line %d : error while parsing %s body",p->line,e)
 
@@ -172,7 +168,7 @@
 #define LETTER "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
 #define SPACE " \n\t\r"
 
-static int
+int
 asx_parse_attribs(ASX_Parser_t* parser,char* buffer,char*** _attribs) {
   char *ptr1, *ptr2, *ptr3;
   int n_attrib = 0;
@@ -232,7 +228,7 @@
 /*
  * Return -1 on error, 0 when nothing is found, 1 on sucess
  */
-static int
+int
 asx_get_element(ASX_Parser_t* parser,char** _buffer,
 		char** _element,char** _body,char*** _attribs) {
   char *ptr1,*ptr2, *ptr3, *ptr4;
@@ -240,6 +236,7 @@
   char *element = NULL, *body = NULL, *ret = NULL, *buffer;
   int n_attrib = 0;
   int body_line = 0,attrib_line,ret_line,in = 0;
+  int quotes = 0;
 
   if(_buffer == NULL || _element == NULL || _body == NULL || _attribs == NULL) {
     mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : asx_get_element called with invalid value",parser->line);
@@ -340,7 +337,8 @@
   
 
   for(ptr3 = ptr2; ptr3[0] != '\0'; ptr3++) { // Go to element end
-    if(ptr3[0] == '>' || strncmp(ptr3,"/>",2) == 0)
+    if(ptr3[0] == '"') quotes ^= 1;  
+    if(!quotes && (ptr3[0] == '>' || strncmp(ptr3,"/>",2) == 0))
       break;
     if(ptr3[0] == '\n') parser->line++;
   }
@@ -378,7 +376,7 @@
 	}
 	if(ptr4[0] == '\n') parser->line++;
       }
-      if(strncmp(ptr4,"<!--",4) == 0) { // Comments
+      if(ptr4 && strncmp(ptr4,"<!--",4) == 0) { // Comments
 	for( ; strncmp(ptr4,"-->",3) != 0 ; ptr4++) {
 	if(ptr4[0] == '\0') {
 	  ptr4 = NULL;
--- a/asxparser.h	Tue Nov 12 14:16:30 2002 +0000
+++ b/asxparser.h	Tue Nov 12 14:19:53 2002 +0000
@@ -15,3 +15,35 @@
   int deep;
 };
   
+ASX_Parser_t*
+asx_parser_new(void);
+
+void
+asx_parser_free(ASX_Parser_t* parser);
+
+/*
+ * Return -1 on error, 0 when nothing is found, 1 on sucess
+ */
+int
+asx_get_element(ASX_Parser_t* parser,char** _buffer,
+		char** _element,char** _body,char*** _attribs);
+
+int
+asx_parse_attribs(ASX_Parser_t* parser,char* buffer,char*** _attribs);
+
+/////// Attribs utils
+
+char*
+asx_get_attrib(char* attrib,char** attribs);
+
+int
+asx_attrib_to_enum(char* val,char** valid_vals);
+
+#define asx_free_attribs(a) asx_list_free((void***)&a,free)
+
+////// List utils
+
+typedef void (*ASX_FreeFunc)(void* arg);
+
+void
+asx_list_free(void* list_ptr,ASX_FreeFunc free_func);