aboutsummaryrefslogtreecommitdiffstats
path: root/src/xml.c
diff options
context:
space:
mode:
authorEli Zaretskii2013-09-05 11:01:04 +0300
committerEli Zaretskii2013-09-05 11:01:04 +0300
commit41306318777a942420bc4feadbfacf662ea179dc (patch)
tree669e5cca02f95d6064ce73c0d3fbbf91b8c8b563 /src/xml.c
parent141f1ff7a40cda10f0558e891dd196a943a5082e (diff)
parent257b3b03cb1cff917e0b3b7832ad3eab5b59f257 (diff)
downloademacs-41306318777a942420bc4feadbfacf662ea179dc.tar.gz
emacs-41306318777a942420bc4feadbfacf662ea179dc.zip
Merge from trunk after a lot of time.
Diffstat (limited to 'src/xml.c')
-rw-r--r--src/xml.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/xml.c b/src/xml.c
index e462a1adf57..c330dce4a4a 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -1,5 +1,5 @@
1/* Interface to libxml2. 1/* Interface to libxml2.
2 Copyright (C) 2010-2012 Free Software Foundation, Inc. 2 Copyright (C) 2010-2013 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -20,12 +20,12 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 20
21#ifdef HAVE_LIBXML2 21#ifdef HAVE_LIBXML2
22 22
23#include <setjmp.h>
24#include <libxml/tree.h> 23#include <libxml/tree.h>
25#include <libxml/parser.h> 24#include <libxml/parser.h>
26#include <libxml/HTMLparser.h> 25#include <libxml/HTMLparser.h>
27 26
28#include "lisp.h" 27#include "lisp.h"
28#include "character.h"
29#include "buffer.h" 29#include "buffer.h"
30 30
31 31
@@ -73,7 +73,7 @@ libxml2_loaded_p (void)
73#define fn_xmlCleanupParser xmlCleanupParser 73#define fn_xmlCleanupParser xmlCleanupParser
74#define fn_xmlCheckVersion xmlCheckVersion 74#define fn_xmlCheckVersion xmlCheckVersion
75 75
76static inline int 76static int
77libxml2_loaded_p (void) 77libxml2_loaded_p (void)
78{ 78{
79 return 1; 79 return 1;
@@ -82,7 +82,7 @@ libxml2_loaded_p (void)
82#endif /* !WINDOWSNT */ 82#endif /* !WINDOWSNT */
83 83
84static int 84static int
85init_libxml2_functions (Lisp_Object libraries) 85init_libxml2_functions (void)
86{ 86{
87#ifdef WINDOWSNT 87#ifdef WINDOWSNT
88 if (libxml2_loaded_p ()) 88 if (libxml2_loaded_p ())
@@ -91,9 +91,9 @@ init_libxml2_functions (Lisp_Object libraries)
91 { 91 {
92 HMODULE library; 92 HMODULE library;
93 93
94 if (!(library = w32_delayed_load (libraries, Qlibxml2_dll))) 94 if (!(library = w32_delayed_load (Qlibxml2_dll)))
95 { 95 {
96 message ("%s", "libxml2 library not found"); 96 message1 ("libxml2 library not found");
97 return 0; 97 return 0;
98 } 98 }
99 99
@@ -124,7 +124,7 @@ make_dom (xmlNode *node)
124{ 124{
125 if (node->type == XML_ELEMENT_NODE) 125 if (node->type == XML_ELEMENT_NODE)
126 { 126 {
127 Lisp_Object result = Fcons (intern ((char *) node->name), Qnil); 127 Lisp_Object result = list1 (intern ((char *) node->name));
128 xmlNode *child; 128 xmlNode *child;
129 xmlAttr *property; 129 xmlAttr *property;
130 Lisp_Object plist = Qnil; 130 Lisp_Object plist = Qnil;
@@ -180,8 +180,7 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int html
180 xmlDoc *doc; 180 xmlDoc *doc;
181 Lisp_Object result = Qnil; 181 Lisp_Object result = Qnil;
182 const char *burl = ""; 182 const char *burl = "";
183 ptrdiff_t bytes; 183 ptrdiff_t istart, iend, istart_byte, iend_byte;
184 ptrdiff_t istart, iend;
185 184
186 fn_xmlCheckVersion (LIBXML_VERSION); 185 fn_xmlCheckVersion (LIBXML_VERSION);
187 186
@@ -189,9 +188,11 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int html
189 188
190 istart = XINT (start); 189 istart = XINT (start);
191 iend = XINT (end); 190 iend = XINT (end);
191 istart_byte = CHAR_TO_BYTE (istart);
192 iend_byte = CHAR_TO_BYTE (iend);
192 193
193 if (istart < GPT && GPT < iend) 194 if (istart < GPT && GPT < iend)
194 move_gap (iend); 195 move_gap_both (iend, iend_byte);
195 196
196 if (! NILP (base_url)) 197 if (! NILP (base_url))
197 { 198 {
@@ -199,17 +200,15 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int html
199 burl = SSDATA (base_url); 200 burl = SSDATA (base_url);
200 } 201 }
201 202
202 bytes = CHAR_TO_BYTE (iend) - CHAR_TO_BYTE (istart);
203
204 if (htmlp) 203 if (htmlp)
205 doc = fn_htmlReadMemory ((char *) BYTE_POS_ADDR (CHAR_TO_BYTE (istart)), 204 doc = fn_htmlReadMemory ((char *) BYTE_POS_ADDR (istart_byte),
206 bytes, burl, "utf-8", 205 iend_byte - istart_byte, burl, "utf-8",
207 HTML_PARSE_RECOVER|HTML_PARSE_NONET| 206 HTML_PARSE_RECOVER|HTML_PARSE_NONET|
208 HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR| 207 HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR|
209 HTML_PARSE_NOBLANKS); 208 HTML_PARSE_NOBLANKS);
210 else 209 else
211 doc = fn_xmlReadMemory ((char *) BYTE_POS_ADDR (CHAR_TO_BYTE (istart)), 210 doc = fn_xmlReadMemory ((char *) BYTE_POS_ADDR (istart_byte),
212 bytes, burl, "utf-8", 211 iend_byte - istart_byte, burl, "utf-8",
213 XML_PARSE_NONET|XML_PARSE_NOWARNING| 212 XML_PARSE_NONET|XML_PARSE_NOWARNING|
214 XML_PARSE_NOBLANKS |XML_PARSE_NOERROR); 213 XML_PARSE_NOBLANKS |XML_PARSE_NOERROR);
215 214
@@ -257,7 +256,7 @@ DEFUN ("libxml-parse-html-region", Flibxml_parse_html_region,
257If BASE-URL is non-nil, it is used to expand relative URLs. */) 256If BASE-URL is non-nil, it is used to expand relative URLs. */)
258 (Lisp_Object start, Lisp_Object end, Lisp_Object base_url) 257 (Lisp_Object start, Lisp_Object end, Lisp_Object base_url)
259{ 258{
260 if (init_libxml2_functions (Vdynamic_library_alist)) 259 if (init_libxml2_functions ())
261 return parse_region (start, end, base_url, 1); 260 return parse_region (start, end, base_url, 1);
262 return Qnil; 261 return Qnil;
263} 262}
@@ -269,7 +268,7 @@ DEFUN ("libxml-parse-xml-region", Flibxml_parse_xml_region,
269If BASE-URL is non-nil, it is used to expand relative URLs. */) 268If BASE-URL is non-nil, it is used to expand relative URLs. */)
270 (Lisp_Object start, Lisp_Object end, Lisp_Object base_url) 269 (Lisp_Object start, Lisp_Object end, Lisp_Object base_url)
271{ 270{
272 if (init_libxml2_functions (Vdynamic_library_alist)) 271 if (init_libxml2_functions ())
273 return parse_region (start, end, base_url, 0); 272 return parse_region (start, end, base_url, 0);
274 return Qnil; 273 return Qnil;
275} 274}