aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog27
-rw-r--r--src/Makefile.in10
-rw-r--r--src/config.in3
-rw-r--r--src/emacs.c4
-rw-r--r--src/fileio.c2
-rw-r--r--src/fns.c141
-rw-r--r--src/lisp.h6
-rw-r--r--src/xml.c141
8 files changed, 185 insertions, 149 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 4b4f82aa4c8..87b54529f2e 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,24 @@
12010-09-12 Lars Magne Ingebrigtsen <larsi@gnus.org>
2
3 * xml.c (Fhtml_parse_string, Fxml_parse_string): Mention BASE-URL.
4
52010-09-12 Stefan Monnier <monnier@iro.umontreal.ca>
6
7 * fns.c (Fy_or_n_p): Move to lisp/subr.el.
8 (syms_of_fns): Don't defsubr Sy_or_n_p.
9 * lisp.h: Don't declare Fy_or_n_p.
10 * fileio.c (barf_or_query_if_file_exists): Fy_or_n_p -> y-or-n-p.
11
122010-09-09 Lars Magne Ingebrigtsen <larsi@gnus.org>
13
14 * xml.c (Fxml_parse_buffer): New function to parse XML files.
15
162010-09-08 Lars Magne Ingebrigtsen <larsi@gnus.org>
17
18 * xml.c: New file.
19 (Fhtml_parse_buffer): New function to interface to the libxml2
20 html parsing function.
21
12010-09-05 Juanma Barranquero <lekktu@gmail.com> 222010-09-05 Juanma Barranquero <lekktu@gmail.com>
2 23
3 * biditype.h: Regenerate. 24 * biditype.h: Regenerate.
@@ -60,8 +81,8 @@
60 characters. 81 characters.
61 82
62 * term.c (encode_terminal_code): Fix the previous change. 83 * term.c (encode_terminal_code): Fix the previous change.
63 (produce_glyphs): Don't set it->char_to_display here. Don't 84 (produce_glyphs): Don't set it->char_to_display here.
64 handle unibyte-display-via-language-environment here. 85 Don't handle unibyte-display-via-language-environment here.
65 (produce_special_glyphs): Set temp_it.char_to_display before 86 (produce_special_glyphs): Set temp_it.char_to_display before
66 calling produce_glyphs. 87 calling produce_glyphs.
67 88
@@ -104,7 +125,7 @@
1042010-08-29 Kenichi Handa <handa@m17n.org> 1252010-08-29 Kenichi Handa <handa@m17n.org>
105 126
106 * term.c (encode_terminal_code): Encode byte chars to the 127 * term.c (encode_terminal_code): Encode byte chars to the
107 correspnding bytes. 128 corresponding bytes.
108 129
1092010-08-29 Jan Djärv <jan.h.d@swipnet.se> 1302010-08-29 Jan Djärv <jan.h.d@swipnet.se>
110 131
diff --git a/src/Makefile.in b/src/Makefile.in
index b086e18ae13..278ae5972ad 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 xwidget.o \ 356 xwidget.o \
354 $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ) 357 $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ)
355 358
@@ -597,7 +600,8 @@ SOME_MACHINE_LISP = ../lisp/mouse.elc \
597## duplicated symbols. If the standard libraries were compiled 600## duplicated symbols. If the standard libraries were compiled
598## with GCC, we might need LIB_GCC again after them. 601## with GCC, we might need LIB_GCC again after them.
599LIBES = $(LIBS) $(LIBX_BASE) $(LIBX_OTHER) $(LIBSOUND) \ 602LIBES = $(LIBS) $(LIBX_BASE) $(LIBX_OTHER) $(LIBSOUND) \
600 $(RSVG_LIBS) ${IMAGEMAGICK_LIBS} $(DBUS_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \ 603 $(RSVG_LIBS) ${IMAGEMAGICK_LIBS} $(DBUS_LIBS) \
604 ${LIBXML2_LIBS} $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \
601 $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) ${GCONF_LIBS} ${LIBSELINUX_LIBS} \ 605 $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) ${GCONF_LIBS} ${LIBSELINUX_LIBS} \
602 $(FREETYPE_LIBS) $(FONTCONFIG_LIBS) $(LIBOTF_LIBS) $(M17N_FLT_LIBS) \ 606 $(FREETYPE_LIBS) $(FONTCONFIG_LIBS) $(LIBOTF_LIBS) $(M17N_FLT_LIBS) \
603 $(LIB_GCC) $(LIB_MATH) $(LIB_STANDARD) $(LIB_GCC) 607 $(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 debf9f2305f..297b2bc20af 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1547,6 +1547,10 @@ main (int argc, char **argv)
1547#endif 1547#endif
1548#endif /* HAVE_X_WINDOWS */ 1548#endif /* HAVE_X_WINDOWS */
1549 1549
1550#ifdef HAVE_LIBXML2
1551 syms_of_xml ();
1552#endif
1553
1550 syms_of_menu (); 1554 syms_of_menu ();
1551 1555
1552#ifdef HAVE_NTGUI 1556#ifdef HAVE_NTGUI
diff --git a/src/fileio.c b/src/fileio.c
index a04cd4e76f5..3d08e881e8f 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -1842,7 +1842,7 @@ barf_or_query_if_file_exists (Lisp_Object absname, const unsigned char *querystr
1842 tem = format2 ("File %s already exists; %s anyway? ", 1842 tem = format2 ("File %s already exists; %s anyway? ",
1843 absname, build_string (querystring)); 1843 absname, build_string (querystring));
1844 if (quick) 1844 if (quick)
1845 tem = Fy_or_n_p (tem); 1845 tem = call1 (intern ("y-or-n-p"), tem);
1846 else 1846 else
1847 tem = do_yes_or_no_p (tem); 1847 tem = do_yes_or_no_p (tem);
1848 UNGCPRO; 1848 UNGCPRO;
diff --git a/src/fns.c b/src/fns.c
index 12d13186ce7..19590a2140d 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -2444,146 +2444,6 @@ SEQUENCE may be a list, a vector, a bool-vector, or a string. */)
2444 return sequence; 2444 return sequence;
2445} 2445}
2446 2446
2447/* Anything that calls this function must protect from GC! */
2448
2449DEFUN ("y-or-n-p", Fy_or_n_p, Sy_or_n_p, 1, 1, 0,
2450 doc: /* Ask user a "y or n" question. Return t if answer is "y".
2451Takes one argument, which is the string to display to ask the question.
2452It should end in a space; `y-or-n-p' adds `(y or n) ' to it.
2453No confirmation of the answer is requested; a single character is enough.
2454Also accepts Space to mean yes, or Delete to mean no. \(Actually, it uses
2455the bindings in `query-replace-map'; see the documentation of that variable
2456for more information. In this case, the useful bindings are `act', `skip',
2457`recenter', and `quit'.\)
2458
2459Under a windowing system a dialog box will be used if `last-nonmenu-event'
2460is nil and `use-dialog-box' is non-nil. */)
2461 (Lisp_Object prompt)
2462{
2463 register Lisp_Object obj, key, def, map;
2464 register int answer;
2465 Lisp_Object xprompt;
2466 Lisp_Object args[2];
2467 struct gcpro gcpro1, gcpro2;
2468 int count = SPECPDL_INDEX ();
2469
2470 specbind (Qcursor_in_echo_area, Qt);
2471
2472 map = Fsymbol_value (intern ("query-replace-map"));
2473
2474 CHECK_STRING (prompt);
2475 xprompt = prompt;
2476 GCPRO2 (prompt, xprompt);
2477
2478#ifdef HAVE_WINDOW_SYSTEM
2479 if (display_hourglass_p)
2480 cancel_hourglass ();
2481#endif
2482
2483 while (1)
2484 {
2485
2486#ifdef HAVE_MENUS
2487 if (FRAME_WINDOW_P (SELECTED_FRAME ())
2488 && (NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
2489 && use_dialog_box
2490 && have_menus_p ())
2491 {
2492 Lisp_Object pane, menu;
2493 redisplay_preserve_echo_area (3);
2494 pane = Fcons (Fcons (build_string ("Yes"), Qt),
2495 Fcons (Fcons (build_string ("No"), Qnil),
2496 Qnil));
2497 menu = Fcons (prompt, pane);
2498 obj = Fx_popup_dialog (Qt, menu, Qnil);
2499 answer = !NILP (obj);
2500 break;
2501 }
2502#endif /* HAVE_MENUS */
2503 cursor_in_echo_area = 1;
2504 choose_minibuf_frame ();
2505
2506 {
2507 Lisp_Object pargs[3];
2508
2509 /* Colorize prompt according to `minibuffer-prompt' face. */
2510 pargs[0] = build_string ("%s(y or n) ");
2511 pargs[1] = intern ("face");
2512 pargs[2] = intern ("minibuffer-prompt");
2513 args[0] = Fpropertize (3, pargs);
2514 args[1] = xprompt;
2515 Fmessage (2, args);
2516 }
2517
2518 if (minibuffer_auto_raise)
2519 {
2520 Lisp_Object mini_frame;
2521
2522 mini_frame = WINDOW_FRAME (XWINDOW (minibuf_window));
2523
2524 Fraise_frame (mini_frame);
2525 }
2526
2527 temporarily_switch_to_single_kboard (SELECTED_FRAME ());
2528 obj = read_filtered_event (1, 0, 0, 0, Qnil);
2529 cursor_in_echo_area = 0;
2530 /* If we need to quit, quit with cursor_in_echo_area = 0. */
2531 QUIT;
2532
2533 key = Fmake_vector (make_number (1), obj);
2534 def = Flookup_key (map, key, Qt);
2535
2536 if (EQ (def, intern ("skip")))
2537 {
2538 answer = 0;
2539 break;
2540 }
2541 else if (EQ (def, intern ("act")))
2542 {
2543 answer = 1;
2544 break;
2545 }
2546 else if (EQ (def, intern ("recenter")))
2547 {
2548 Frecenter (Qnil);
2549 xprompt = prompt;
2550 continue;
2551 }
2552 else if (EQ (def, intern ("quit")))
2553 Vquit_flag = Qt;
2554 /* We want to exit this command for exit-prefix,
2555 and this is the only way to do it. */
2556 else if (EQ (def, intern ("exit-prefix")))
2557 Vquit_flag = Qt;
2558
2559 QUIT;
2560
2561 /* If we don't clear this, then the next call to read_char will
2562 return quit_char again, and we'll enter an infinite loop. */
2563 Vquit_flag = Qnil;
2564
2565 Fding (Qnil);
2566 Fdiscard_input ();
2567 if (EQ (xprompt, prompt))
2568 {
2569 args[0] = build_string ("Please answer y or n. ");
2570 args[1] = prompt;
2571 xprompt = Fconcat (2, args);
2572 }
2573 }
2574 UNGCPRO;
2575
2576 if (! noninteractive)
2577 {
2578 cursor_in_echo_area = -1;
2579 message_with_string (answer ? "%s(y or n) y" : "%s(y or n) n",
2580 xprompt, 0);
2581 }
2582
2583 unbind_to (count, Qnil);
2584 return answer ? Qt : Qnil;
2585}
2586
2587/* This is how C code calls `yes-or-no-p' and allows the user 2447/* This is how C code calls `yes-or-no-p' and allows the user
2588 to redefined it. 2448 to redefined it.
2589 2449
@@ -5058,7 +4918,6 @@ this variable. */);
5058 defsubr (&Smapcar); 4918 defsubr (&Smapcar);
5059 defsubr (&Smapc); 4919 defsubr (&Smapc);
5060 defsubr (&Smapconcat); 4920 defsubr (&Smapconcat);
5061 defsubr (&Sy_or_n_p);
5062 defsubr (&Syes_or_no_p); 4921 defsubr (&Syes_or_no_p);
5063 defsubr (&Sload_average); 4922 defsubr (&Sload_average);
5064 defsubr (&Sfeaturep); 4923 defsubr (&Sfeaturep);
diff --git a/src/lisp.h b/src/lisp.h
index 89514bf9ecb..781261d9779 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2516,7 +2516,6 @@ EXFUN (Ffillarray, 2);
2516EXFUN (Fnconc, MANY); 2516EXFUN (Fnconc, MANY);
2517EXFUN (Fmapcar, 2); 2517EXFUN (Fmapcar, 2);
2518EXFUN (Fmapconcat, 3); 2518EXFUN (Fmapconcat, 3);
2519EXFUN (Fy_or_n_p, 1);
2520extern Lisp_Object do_yes_or_no_p (Lisp_Object); 2519extern Lisp_Object do_yes_or_no_p (Lisp_Object);
2521EXFUN (Frequire, 3); 2520EXFUN (Frequire, 3);
2522EXFUN (Fprovide, 2); 2521EXFUN (Fprovide, 2);
@@ -3577,6 +3576,11 @@ extern char *x_get_keysym_name (int);
3577EXFUN (Fmsdos_downcase_filename, 1); 3576EXFUN (Fmsdos_downcase_filename, 1);
3578#endif 3577#endif
3579 3578
3579#ifdef HAVE_LIBXML2
3580/* Defined in xml.c */
3581extern void syms_of_xml (void);
3582#endif
3583
3580#ifdef HAVE_MENUS 3584#ifdef HAVE_MENUS
3581/* Defined in (x|w32)fns.c, nsfns.m... */ 3585/* Defined in (x|w32)fns.c, nsfns.m... */
3582extern int have_menus_p (void); 3586extern int have_menus_p (void);
diff --git a/src/xml.c b/src/xml.c
new file mode 100644
index 00000000000..c1098b15a20
--- /dev/null
+++ b/src/xml.c
@@ -0,0 +1,141 @@
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.
113If BASE-URL is non-nil, it will be used to expand relative URLs in
114the HTML document.*/)
115 (Lisp_Object string, Lisp_Object base_url)
116{
117 return parse_buffer (string, base_url, 1);
118}
119
120DEFUN ("xml-parse-string", Fxml_parse_string, Sxml_parse_string,
121 0, 2, 0,
122 doc: /* Parse the string as an XML document and return the parse tree.
123If BASE-URL is non-nil, it will be used to expand relative URLs in
124the XML document.*/)
125 (Lisp_Object string, Lisp_Object base_url)
126{
127 return parse_buffer (string, base_url, 0);
128}
129
130
131/***********************************************************************
132 Initialization
133 ***********************************************************************/
134void
135syms_of_xml (void)
136{
137 defsubr (&Shtml_parse_string);
138 defsubr (&Sxml_parse_string);
139}
140
141#endif /* HAVE_LIBXML2 */