aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Magne Ingebrigtsen2010-09-10 18:44:35 +0200
committerLars Magne Ingebrigtsen2010-09-10 18:44:35 +0200
commit381408e2192b8fd606babaa8c9a103186589d708 (patch)
tree488a49b786d5cffcd0b068a527ec1ebe8339114a /src
parent36f7d3666905e1447a2e80957735a1ade23c894c (diff)
downloademacs-381408e2192b8fd606babaa8c9a103186589d708.tar.gz
emacs-381408e2192b8fd606babaa8c9a103186589d708.zip
Add support for the libxml2 library.
This adds the html-parse-string and xml-parse-string functions in the new file src/xml.c, as well as autoconf detection of the library.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog10
-rw-r--r--src/Makefile.in10
-rw-r--r--src/config.in3
-rw-r--r--src/emacs.c4
-rw-r--r--src/lisp.h5
-rw-r--r--src/xml.c137
6 files changed, 166 insertions, 3 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 4b4f82aa4c8..9578130afd5 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,13 @@
12010-09-09 Lars Magne Ingebrigtsen <larsi@gnus.org>
2
3 * xml.c (Fxml_parse_buffer): New function to parse XML files.
4
52010-09-08 Lars Magne Ingebrigtsen <larsi@gnus.org>
6
7 * xml.c: New file.
8 (Fhtml_parse_buffer): New function to interface to the libxml2
9 html parsing function.
10
12010-09-05 Juanma Barranquero <lekktu@gmail.com> 112010-09-05 Juanma Barranquero <lekktu@gmail.com>
2 12
3 * biditype.h: Regenerate. 13 * biditype.h: Regenerate.
diff --git a/src/Makefile.in b/src/Makefile.in
index 9ee5631ef70..d91b95d86e3 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -226,6 +226,8 @@ RSVG_CFLAGS= @RSVG_CFLAGS@
226IMAGEMAGICK_LIBS= @IMAGEMAGICK_LIBS@ 226IMAGEMAGICK_LIBS= @IMAGEMAGICK_LIBS@
227IMAGEMAGICK_CFLAGS= @IMAGEMAGICK_CFLAGS@ 227IMAGEMAGICK_CFLAGS= @IMAGEMAGICK_CFLAGS@
228 228
229LIBXML2_LIBS = @LIBXML2_LIBS@
230LIBXML2_CFLAGS = @LIBXML2_CFLAGS@
229 231
230## widget.o if USE_X_TOOLKIT, otherwise empty. 232## widget.o if USE_X_TOOLKIT, otherwise empty.
231WIDGET_OBJ=@WIDGET_OBJ@ 233WIDGET_OBJ=@WIDGET_OBJ@
@@ -320,7 +322,8 @@ MKDEPDIR=@MKDEPDIR@
320## FIXME? MYCPPFLAGS only referenced in etc/DEBUG. 322## FIXME? MYCPPFLAGS only referenced in etc/DEBUG.
321ALL_CFLAGS=-Demacs -DHAVE_CONFIG_H $(MYCPPFLAGS) -I. -I${srcdir} \ 323ALL_CFLAGS=-Demacs -DHAVE_CONFIG_H $(MYCPPFLAGS) -I. -I${srcdir} \
322 ${C_SWITCH_MACHINE} ${C_SWITCH_SYSTEM} ${C_SWITCH_X_SITE} \ 324 ${C_SWITCH_MACHINE} ${C_SWITCH_SYSTEM} ${C_SWITCH_X_SITE} \
323 ${C_SWITCH_X_SYSTEM} ${CFLAGS_SOUND} ${RSVG_CFLAGS} ${IMAGEMAGICK_CFLAGS} ${DBUS_CFLAGS} \ 325 ${C_SWITCH_X_SYSTEM} ${CFLAGS_SOUND} ${RSVG_CFLAGS} ${IMAGEMAGICK_CFLAGS} \
326 ${LIBXML2_CFLAGS} ${DBUS_CFLAGS} \
324 ${GCONF_CFLAGS} ${FREETYPE_CFLAGS} ${FONTCONFIG_CFLAGS} \ 327 ${GCONF_CFLAGS} ${FREETYPE_CFLAGS} ${FONTCONFIG_CFLAGS} \
325 ${LIBOTF_CFLAGS} ${M17N_FLT_CFLAGS} ${DEPFLAGS} ${PROFILING_CFLAGS} \ 328 ${LIBOTF_CFLAGS} ${M17N_FLT_CFLAGS} ${DEPFLAGS} ${PROFILING_CFLAGS} \
326 ${C_WARNINGS_SWITCH} ${CFLAGS} 329 ${C_WARNINGS_SWITCH} ${CFLAGS}
@@ -349,7 +352,7 @@ obj= dispnew.o frame.o scroll.o xdisp.o menu.o $(XMENU_OBJ) window.o \
349 syntax.o $(UNEXEC_OBJ) bytecode.o \ 352 syntax.o $(UNEXEC_OBJ) bytecode.o \
350 process.o callproc.o \ 353 process.o callproc.o \
351 region-cache.o sound.o atimer.o \ 354 region-cache.o sound.o atimer.o \
352 doprnt.o strftime.o intervals.o textprop.o composite.o md5.o \ 355 doprnt.o strftime.o intervals.o textprop.o composite.o md5.o xml.o \
353 $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ) 356 $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ)
354 357
355## Object files used on some machine or other. 358## Object files used on some machine or other.
@@ -595,7 +598,8 @@ SOME_MACHINE_LISP = ../lisp/mouse.elc \
595## duplicated symbols. If the standard libraries were compiled 598## duplicated symbols. If the standard libraries were compiled
596## with GCC, we might need LIB_GCC again after them. 599## with GCC, we might need LIB_GCC again after them.
597LIBES = $(LIBS) $(LIBX_BASE) $(LIBX_OTHER) $(LIBSOUND) \ 600LIBES = $(LIBS) $(LIBX_BASE) $(LIBX_OTHER) $(LIBSOUND) \
598 $(RSVG_LIBS) ${IMAGEMAGICK_LIBS} $(DBUS_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \ 601 $(RSVG_LIBS) ${IMAGEMAGICK_LIBS} $(DBUS_LIBS) \
602 ${LIBXML2_LIBS} $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \
599 $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) ${GCONF_LIBS} ${LIBSELINUX_LIBS} \ 603 $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) ${GCONF_LIBS} ${LIBSELINUX_LIBS} \
600 $(FREETYPE_LIBS) $(FONTCONFIG_LIBS) $(LIBOTF_LIBS) $(M17N_FLT_LIBS) \ 604 $(FREETYPE_LIBS) $(FONTCONFIG_LIBS) $(LIBOTF_LIBS) $(M17N_FLT_LIBS) \
601 $(LIB_GCC) $(LIB_MATH) $(LIB_STANDARD) $(LIB_GCC) 605 $(LIB_GCC) $(LIB_MATH) $(LIB_STANDARD) $(LIB_GCC)
diff --git a/src/config.in b/src/config.in
index 604a737a8b0..199afbd78ba 100644
--- a/src/config.in
+++ b/src/config.in
@@ -813,6 +813,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
813/* Define to 1 if you have the SM library (-lSM). */ 813/* Define to 1 if you have the SM library (-lSM). */
814#undef HAVE_X_SM 814#undef HAVE_X_SM
815 815
816/* Define to 1 if you have the libxml2 library (-lxml2). */
817#undef HAVE_LIBXML2
818
816/* Define to 1 if you want to use the X window system. */ 819/* Define to 1 if you want to use the X window system. */
817#undef HAVE_X_WINDOWS 820#undef HAVE_X_WINDOWS
818 821
diff --git a/src/emacs.c b/src/emacs.c
index 397d3d9ad27..33e0d60630b 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1544,6 +1544,10 @@ main (int argc, char **argv)
1544#endif 1544#endif
1545#endif /* HAVE_X_WINDOWS */ 1545#endif /* HAVE_X_WINDOWS */
1546 1546
1547#ifdef HAVE_LIBXML2
1548 syms_of_xml ();
1549#endif
1550
1547 syms_of_menu (); 1551 syms_of_menu ();
1548 1552
1549#ifdef HAVE_NTGUI 1553#ifdef HAVE_NTGUI
diff --git a/src/lisp.h b/src/lisp.h
index 89514bf9ecb..fc9198a5ff7 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3577,6 +3577,11 @@ extern char *x_get_keysym_name (int);
3577EXFUN (Fmsdos_downcase_filename, 1); 3577EXFUN (Fmsdos_downcase_filename, 1);
3578#endif 3578#endif
3579 3579
3580#ifdef HAVE_LIBXML2
3581/* Defined in xml.c */
3582extern void syms_of_xml (void);
3583#endif
3584
3580#ifdef HAVE_MENUS 3585#ifdef HAVE_MENUS
3581/* Defined in (x|w32)fns.c, nsfns.m... */ 3586/* Defined in (x|w32)fns.c, nsfns.m... */
3582extern int have_menus_p (void); 3587extern int have_menus_p (void);
diff --git a/src/xml.c b/src/xml.c
new file mode 100644
index 00000000000..92066067d73
--- /dev/null
+++ b/src/xml.c
@@ -0,0 +1,137 @@
1/* Interface to libxml2.
2 Copyright (C) 2010 Free Software Foundation, Inc.
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
18
19#include <config.h>
20
21#ifdef HAVE_LIBXML2
22
23#include <setjmp.h>
24#include <libxml/tree.h>
25#include <libxml/parser.h>
26#include <libxml/HTMLparser.h>
27
28#include "lisp.h"
29#include "buffer.h"
30
31Lisp_Object make_dom (xmlNode *node)
32{
33 if (node->type == XML_ELEMENT_NODE) {
34 Lisp_Object result = Fcons (intern (node->name), Qnil);
35 xmlNode *child;
36 xmlAttr *property;
37
38 /* First add the attributes. */
39 property = node->properties;
40 while (property != NULL) {
41 if (property->children &&
42 property->children->content) {
43 char *pname = xmalloc (strlen (property->name) + 2);
44 *pname = ':';
45 strcpy(pname + 1, property->name);
46 result = Fcons (Fcons (intern (pname),
47 build_string(property->children->content)),
48 result);
49 xfree (pname);
50 }
51 property = property->next;
52 }
53 /* Then add the children of the node. */
54 child = node->children;
55 while (child != NULL) {
56 result = Fcons (make_dom (child), result);
57 child = child->next;
58 }
59 return Fnreverse (result);
60 } else if (node->type == XML_TEXT_NODE) {
61 Lisp_Object content = Qnil;
62
63 if (node->content)
64 content = build_string (node->content);
65
66 return Fcons (intern (node->name), content);
67 } else
68 return Qnil;
69}
70
71static Lisp_Object
72parse_buffer (Lisp_Object string, Lisp_Object base_url, int htmlp)
73{
74 xmlDoc *doc;
75 xmlNode *node;
76 Lisp_Object result;
77 int ibeg, iend;
78 char *burl = "";
79
80 LIBXML_TEST_VERSION;
81
82 CHECK_STRING (string);
83
84 if (! NILP (base_url)) {
85 CHECK_STRING (base_url);
86 burl = SDATA (base_url);
87 }
88
89 if (htmlp)
90 doc = htmlReadMemory (SDATA (string), SBYTES (string), burl, "utf-8",
91 HTML_PARSE_RECOVER|HTML_PARSE_NONET|
92 HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR);
93 else
94 doc = xmlReadMemory (SDATA (string), SBYTES (string), burl, "utf-8",
95 XML_PARSE_NONET|XML_PARSE_NOWARNING|
96 XML_PARSE_NOERROR);
97
98 if (doc != NULL) {
99 node = xmlDocGetRootElement (doc);
100 if (node != NULL)
101 result = make_dom (node);
102
103 xmlFreeDoc (doc);
104 xmlCleanupParser ();
105 }
106
107 return result;
108}
109
110DEFUN ("html-parse-string", Fhtml_parse_string, Shtml_parse_string,
111 0, 2, 0,
112 doc: /* Parse the string as an HTML document and return the parse tree.*/)
113 (Lisp_Object string, Lisp_Object base_url)
114{
115 return parse_buffer (string, base_url, 1);
116}
117
118DEFUN ("xml-parse-string", Fxml_parse_string, Sxml_parse_string,
119 0, 2, 0,
120 doc: /* Parse the string as an XML document and return the parse tree.*/)
121 (Lisp_Object string, Lisp_Object base_url)
122{
123 return parse_buffer (string, base_url, 0);
124}
125
126
127/***********************************************************************
128 Initialization
129 ***********************************************************************/
130void
131syms_of_xml (void)
132{
133 defsubr (&Shtml_parse_string);
134 defsubr (&Sxml_parse_string);
135}
136
137#endif /* HAVE_LIBXML2 */