diff src/xml.c @ 110472:52590453d4f9

Rename libxml2 functions, and make parse tree format consistent with xml.el. * xml.c: Switch to GNU indentation. (make_dom): Change parse tree format to match xml.el. (Fxml_parse_html_string_internal): Rename from html-parse-string. (Fxml_parse_string_internal): Rename from xml-parse-string. * configure.in: Announce whether libxml2 is linked to.
author Chong Yidong <cyd@stupidchicken.com>
date Tue, 21 Sep 2010 23:10:16 -0400
parents a828354ee483
children 49d445615c07
line wrap: on
line diff
--- a/src/xml.c	Wed Sep 22 11:57:19 2010 +0900
+++ b/src/xml.c	Tue Sep 21 23:10:16 2010 -0400
@@ -30,41 +30,46 @@
 
 Lisp_Object make_dom (xmlNode *node)
 {
-  if (node->type == XML_ELEMENT_NODE) {
-    Lisp_Object result = Fcons (intern (node->name), Qnil);
-    xmlNode *child;
-    xmlAttr *property;
+  if (node->type == XML_ELEMENT_NODE)
+    {
+      Lisp_Object result = Fcons (intern (node->name), Qnil);
+      xmlNode *child;
+      xmlAttr *property;
+      Lisp_Object plist = Qnil;
 
-    /* First add the attributes. */
-    property = node->properties;
-    while (property != NULL) {
-      if (property->children &&
-	  property->children->content) {
-	char *pname = xmalloc (strlen (property->name) + 2);
-	*pname = ':';
-	strcpy(pname + 1, property->name);
-	result = Fcons (Fcons (intern (pname),
-			       build_string(property->children->content)),
-			result);
-	xfree (pname);
-      }
-      property = property->next;
+      /* First add the attributes. */
+      property = node->properties;
+      while (property != NULL)
+	{
+	  if (property->children &&
+	      property->children->content)
+	    {
+	      plist = Fcons (Fcons (intern (property->name),
+				    build_string (property->children->content)),
+			     plist);
+	    }
+	  property = property->next;
+	}
+      result = Fcons (Fnreverse (plist), result);
+
+      /* Then add the children of the node. */
+      child = node->children;
+      while (child != NULL)
+	{
+	  result = Fcons (make_dom (child), result);
+	  child = child->next;
+	}
+
+      return Fnreverse (result);
     }
-    /* Then add the children of the node. */
-    child = node->children;
-    while (child != NULL) {
-      result = Fcons (make_dom (child), result);
-      child = child->next;
+  else if (node->type == XML_TEXT_NODE)
+    {
+      if (node->content)
+	return build_string (node->content);
+      else
+	return Qnil;
     }
-    return Fnreverse (result);
-  } else if (node->type == XML_TEXT_NODE) {
-    Lisp_Object content = Qnil;
-
-    if (node->content)
-      content = build_string (node->content);
-
-    return Fcons (intern (node->name), content);
-  } else
+  else
     return Qnil;
 }
 
@@ -81,47 +86,47 @@
 
   CHECK_STRING (string);
 
-  if (! NILP (base_url)) {
-    CHECK_STRING (base_url);
-    burl = SDATA (base_url);
-  }
+  if (! NILP (base_url))
+    {
+      CHECK_STRING (base_url);
+      burl = SDATA (base_url);
+    }
 
-  if (htmlp)
-    doc = htmlReadMemory (SDATA (string), SBYTES (string), burl, "utf-8",
-			  HTML_PARSE_RECOVER|HTML_PARSE_NONET|
-			  HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR);
-  else
-    doc = xmlReadMemory (SDATA (string), SBYTES (string), burl, "utf-8",
-			 XML_PARSE_NONET|XML_PARSE_NOWARNING|
-			 XML_PARSE_NOERROR);
+  doc = htmlp
+    ? htmlReadMemory (SDATA (string), SBYTES (string), burl, "utf-8",
+		      HTML_PARSE_RECOVER|HTML_PARSE_NONET|
+		      HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR)
+    : xmlReadMemory (SDATA (string), SBYTES (string), burl, "utf-8",
+		     XML_PARSE_NONET|XML_PARSE_NOWARNING|
+		     XML_PARSE_NOERROR);
 
-  if (doc != NULL) {
-    node = xmlDocGetRootElement (doc);
-    if (node != NULL)
-      result = make_dom (node);
-
-    xmlFreeDoc (doc);
-    xmlCleanupParser ();
-  }
+  if (doc != NULL)
+    {
+      node = xmlDocGetRootElement (doc);
+      if (node != NULL)
+	result = make_dom (node);
+      xmlFreeDoc (doc);
+      xmlCleanupParser ();
+    }
 
   return result;
 }
 
-DEFUN ("html-parse-string", Fhtml_parse_string, Shtml_parse_string,
+DEFUN ("xml-parse-html-string-internal", Fxml_parse_html_string_internal,
+       Sxml_parse_html_string_internal,
        1, 2, 0,
        doc: /* Parse STRING as an HTML document and return the parse tree.
-If BASE-URL is non-nil, it will be used to expand relative URLs in
-the HTML document.  */)
+If BASE-URL is non-nil, it is used to expand relative URLs.  */)
   (Lisp_Object string, Lisp_Object base_url)
 {
   return parse_string (string, base_url, 1);
 }
 
-DEFUN ("xml-parse-string", Fxml_parse_string, Sxml_parse_string,
+DEFUN ("xml-parse-string-internal", Fxml_parse_string_internal,
+       Sxml_parse_string_internal,
        1, 2, 0,
        doc: /* Parse STRING as an XML document and return the parse tree.
-If BASE-URL is non-nil, it will be used to expand relative URLs in
-the XML document.  */)
+If BASE-URL is non-nil, it is used to expand relative URLs.  */)
   (Lisp_Object string, Lisp_Object base_url)
 {
   return parse_string (string, base_url, 0);
@@ -134,8 +139,8 @@
 void
 syms_of_xml (void)
 {
-  defsubr (&Shtml_parse_string);
-  defsubr (&Sxml_parse_string);
+  defsubr (&Sxml_parse_html_string_internal);
+  defsubr (&Sxml_parse_string_internal);
 }
 
 #endif /* HAVE_LIBXML2 */