X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Fxml-support.c;h=937c6c3177213a6664b0af01662782d301b9525b;hb=8fecfbc78ac460c238a365e7369e3d65ec1c9490;hp=49a10d72d56f6974d033072831148fa4deda3fd4;hpb=05a4558a934667e0e219e95d2c898f5c069b860c;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/xml-support.c b/gdb/xml-support.c index 49a10d72d5..937c6c3177 100644 --- a/gdb/xml-support.c +++ b/gdb/xml-support.c @@ -1,12 +1,12 @@ /* Helper routines for parsing XML using Expat. - Copyright (C) 2006, 2007 Free Software Foundation, Inc. + Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc. This file is part of GDB. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,9 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. */ + along with this program. If not, see . */ #include "defs.h" #include "gdbcmd.h" @@ -546,6 +544,8 @@ gdb_xml_parse (struct gdb_xml_parser *parser, const char *buffer) enum XML_Status status; const char *error_string; + gdb_xml_debug (parser, _("Starting:\n%s"), buffer); + status = XML_Parse (parser->expat_parser, buffer, strlen (buffer), 1); if (status == XML_STATUS_OK && parser->error.reason == 0) @@ -871,8 +871,7 @@ xml_process_xincludes (const char *name, const char *text, result = xstrdup (obstack_finish (&data->obstack)); if (depth == 0) - gdb_xml_debug (parser, _("XInclude processing succeeded:\n%s"), - result); + gdb_xml_debug (parser, _("XInclude processing succeeded.")); } else result = NULL; @@ -936,6 +935,107 @@ show_debug_xml (struct ui_file *file, int from_tty, fprintf_filtered (file, _("XML debugging is %s.\n"), value); } +/* Return a malloc allocated string with special characters from TEXT + replaced by entity references. */ + +char * +xml_escape_text (const char *text) +{ + char *result; + int i, special; + + /* Compute the length of the result. */ + for (i = 0, special = 0; text[i] != '\0'; i++) + switch (text[i]) + { + case '\'': + case '\"': + special += 5; + break; + case '&': + special += 4; + break; + case '<': + case '>': + special += 3; + break; + default: + break; + } + + /* Expand the result. */ + result = xmalloc (i + special + 1); + for (i = 0, special = 0; text[i] != '\0'; i++) + switch (text[i]) + { + case '\'': + strcpy (result + i + special, "'"); + special += 5; + break; + case '\"': + strcpy (result + i + special, """); + special += 5; + break; + case '&': + strcpy (result + i + special, "&"); + special += 4; + break; + case '<': + strcpy (result + i + special, "<"); + special += 3; + break; + case '>': + strcpy (result + i + special, ">"); + special += 3; + break; + default: + result[i + special] = text[i]; + break; + } + result[i + special] = '\0'; + + return result; +} + +void +obstack_xml_printf (struct obstack *obstack, const char *format, ...) +{ + va_list ap; + const char *f; + const char *prev; + int percent = 0; + + va_start (ap, format); + + prev = format; + for (f = format; *f; f++) + { + if (percent) + { + switch (*f) + { + case 's': + { + char *p; + char *a = va_arg (ap, char *); + obstack_grow (obstack, prev, f - prev - 1); + p = xml_escape_text (a); + obstack_grow_str (obstack, p); + xfree (p); + prev = f + 1; + } + break; + } + percent = 0; + } + else if (*f == '%') + percent = 1; + } + + obstack_grow_str (obstack, prev); + va_end (ap); +} + void _initialize_xml_support (void); void