diff options
| author | Stephen Berman | 2013-06-14 22:07:55 +0200 |
|---|---|---|
| committer | Stephen Berman | 2013-06-14 22:07:55 +0200 |
| commit | bd358779861f265a7acff31ead40172735af693e (patch) | |
| tree | 345217a9889dbd29b09bdc80a94265c17719d41f /src/xml.c | |
| parent | 2a97b47f0878cbda86cb6ba0e7e744924810b70e (diff) | |
| parent | f7394b12358ae453a0c8b85fc307afc1b740010d (diff) | |
| download | emacs-bd358779861f265a7acff31ead40172735af693e.tar.gz emacs-bd358779861f265a7acff31ead40172735af693e.zip | |
Merge from trunk.
Diffstat (limited to 'src/xml.c')
| -rw-r--r-- | src/xml.c | 32 |
1 files changed, 15 insertions, 17 deletions
| @@ -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 | ||
| 4 | This file is part of GNU Emacs. | 4 | This file is part of GNU Emacs. |
| 5 | 5 | ||
| @@ -20,7 +20,6 @@ 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> |
| @@ -74,7 +73,7 @@ libxml2_loaded_p (void) | |||
| 74 | #define fn_xmlCleanupParser xmlCleanupParser | 73 | #define fn_xmlCleanupParser xmlCleanupParser |
| 75 | #define fn_xmlCheckVersion xmlCheckVersion | 74 | #define fn_xmlCheckVersion xmlCheckVersion |
| 76 | 75 | ||
| 77 | static inline int | 76 | static int |
| 78 | libxml2_loaded_p (void) | 77 | libxml2_loaded_p (void) |
| 79 | { | 78 | { |
| 80 | return 1; | 79 | return 1; |
| @@ -83,7 +82,7 @@ libxml2_loaded_p (void) | |||
| 83 | #endif /* !WINDOWSNT */ | 82 | #endif /* !WINDOWSNT */ |
| 84 | 83 | ||
| 85 | static int | 84 | static int |
| 86 | init_libxml2_functions (Lisp_Object libraries) | 85 | init_libxml2_functions (void) |
| 87 | { | 86 | { |
| 88 | #ifdef WINDOWSNT | 87 | #ifdef WINDOWSNT |
| 89 | if (libxml2_loaded_p ()) | 88 | if (libxml2_loaded_p ()) |
| @@ -92,9 +91,9 @@ init_libxml2_functions (Lisp_Object libraries) | |||
| 92 | { | 91 | { |
| 93 | HMODULE library; | 92 | HMODULE library; |
| 94 | 93 | ||
| 95 | if (!(library = w32_delayed_load (libraries, Qlibxml2_dll))) | 94 | if (!(library = w32_delayed_load (Qlibxml2_dll))) |
| 96 | { | 95 | { |
| 97 | message ("%s", "libxml2 library not found"); | 96 | message1 ("libxml2 library not found"); |
| 98 | return 0; | 97 | return 0; |
| 99 | } | 98 | } |
| 100 | 99 | ||
| @@ -181,8 +180,7 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int html | |||
| 181 | xmlDoc *doc; | 180 | xmlDoc *doc; |
| 182 | Lisp_Object result = Qnil; | 181 | Lisp_Object result = Qnil; |
| 183 | const char *burl = ""; | 182 | const char *burl = ""; |
| 184 | ptrdiff_t bytes; | 183 | ptrdiff_t istart, iend, istart_byte, iend_byte; |
| 185 | ptrdiff_t istart, iend; | ||
| 186 | 184 | ||
| 187 | fn_xmlCheckVersion (LIBXML_VERSION); | 185 | fn_xmlCheckVersion (LIBXML_VERSION); |
| 188 | 186 | ||
| @@ -190,9 +188,11 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int html | |||
| 190 | 188 | ||
| 191 | istart = XINT (start); | 189 | istart = XINT (start); |
| 192 | iend = XINT (end); | 190 | iend = XINT (end); |
| 191 | istart_byte = CHAR_TO_BYTE (istart); | ||
| 192 | iend_byte = CHAR_TO_BYTE (iend); | ||
| 193 | 193 | ||
| 194 | if (istart < GPT && GPT < iend) | 194 | if (istart < GPT && GPT < iend) |
| 195 | move_gap (iend); | 195 | move_gap_both (iend, iend_byte); |
| 196 | 196 | ||
| 197 | if (! NILP (base_url)) | 197 | if (! NILP (base_url)) |
| 198 | { | 198 | { |
| @@ -200,17 +200,15 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int html | |||
| 200 | burl = SSDATA (base_url); | 200 | burl = SSDATA (base_url); |
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | bytes = CHAR_TO_BYTE (iend) - CHAR_TO_BYTE (istart); | ||
| 204 | |||
| 205 | if (htmlp) | 203 | if (htmlp) |
| 206 | doc = fn_htmlReadMemory ((char *) BYTE_POS_ADDR (CHAR_TO_BYTE (istart)), | 204 | doc = fn_htmlReadMemory ((char *) BYTE_POS_ADDR (istart_byte), |
| 207 | bytes, burl, "utf-8", | 205 | iend_byte - istart_byte, burl, "utf-8", |
| 208 | HTML_PARSE_RECOVER|HTML_PARSE_NONET| | 206 | HTML_PARSE_RECOVER|HTML_PARSE_NONET| |
| 209 | HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR| | 207 | HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR| |
| 210 | HTML_PARSE_NOBLANKS); | 208 | HTML_PARSE_NOBLANKS); |
| 211 | else | 209 | else |
| 212 | doc = fn_xmlReadMemory ((char *) BYTE_POS_ADDR (CHAR_TO_BYTE (istart)), | 210 | doc = fn_xmlReadMemory ((char *) BYTE_POS_ADDR (istart_byte), |
| 213 | bytes, burl, "utf-8", | 211 | iend_byte - istart_byte, burl, "utf-8", |
| 214 | XML_PARSE_NONET|XML_PARSE_NOWARNING| | 212 | XML_PARSE_NONET|XML_PARSE_NOWARNING| |
| 215 | XML_PARSE_NOBLANKS |XML_PARSE_NOERROR); | 213 | XML_PARSE_NOBLANKS |XML_PARSE_NOERROR); |
| 216 | 214 | ||
| @@ -258,7 +256,7 @@ DEFUN ("libxml-parse-html-region", Flibxml_parse_html_region, | |||
| 258 | If BASE-URL is non-nil, it is used to expand relative URLs. */) | 256 | If BASE-URL is non-nil, it is used to expand relative URLs. */) |
| 259 | (Lisp_Object start, Lisp_Object end, Lisp_Object base_url) | 257 | (Lisp_Object start, Lisp_Object end, Lisp_Object base_url) |
| 260 | { | 258 | { |
| 261 | if (init_libxml2_functions (Vdynamic_library_alist)) | 259 | if (init_libxml2_functions ()) |
| 262 | return parse_region (start, end, base_url, 1); | 260 | return parse_region (start, end, base_url, 1); |
| 263 | return Qnil; | 261 | return Qnil; |
| 264 | } | 262 | } |
| @@ -270,7 +268,7 @@ DEFUN ("libxml-parse-xml-region", Flibxml_parse_xml_region, | |||
| 270 | If BASE-URL is non-nil, it is used to expand relative URLs. */) | 268 | If BASE-URL is non-nil, it is used to expand relative URLs. */) |
| 271 | (Lisp_Object start, Lisp_Object end, Lisp_Object base_url) | 269 | (Lisp_Object start, Lisp_Object end, Lisp_Object base_url) |
| 272 | { | 270 | { |
| 273 | if (init_libxml2_functions (Vdynamic_library_alist)) | 271 | if (init_libxml2_functions ()) |
| 274 | return parse_region (start, end, base_url, 0); | 272 | return parse_region (start, end, base_url, 0); |
| 275 | return Qnil; | 273 | return Qnil; |
| 276 | } | 274 | } |