1 /* Helper routines for parsing XML using Expat.
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
25 /* The contents of this file are only useful if XML support is
29 #include "exceptions.h"
30 #include "xml-support.h"
32 #include "gdb_expat.h"
33 #include "gdb_string.h"
35 /* Returns the value of attribute ATTR from expat attribute list
36 ATTRLIST. If not found, throws an exception. */
39 xml_get_required_attribute (const XML_Char
**attrs
,
43 for (p
= attrs
; *p
; p
+= 2)
45 const char *name
= p
[0];
46 const char *val
= p
[1];
48 if (strcmp (name
, attr
) == 0)
51 throw_error (XML_PARSE_ERROR
, _("Can't find attribute %s"), attr
);
54 /* Parse a field VALSTR that we expect to contain an integer value.
55 The integer is returned in *VALP. The string is parsed with an
56 equivalent to strtoul.
58 Returns 0 for success, -1 for error. */
61 xml_parse_unsigned_integer (const char *valstr
, ULONGEST
*valp
)
69 result
= strtoulst (valstr
, &endptr
, 0);
77 /* Gets the value of an integer attribute named ATTR, if it's present.
78 If the attribute is not found, or can't be parsed as integer,
79 throws an exception. */
82 xml_get_integer_attribute (const XML_Char
**attrs
,
86 const XML_Char
*value
= xml_get_required_attribute (attrs
, attr
);
88 if (xml_parse_unsigned_integer (value
, &result
) != 0)
90 throw_error (XML_PARSE_ERROR
,
91 _("Can't convert value of attribute %s, %s, to integer"),
97 /* Obtains a value of attribute with enumerated type. In XML, enumerated
98 attributes have string as a value, and in C, they are represented as
99 values of enumerated type. This function maps the attribute onto
100 an integer value that can be immediately converted into enumerated
103 First, obtains the string value of ATTR in ATTRS.
104 Then, finds the index of that value in XML_NAMES, which is a zero-terminated
105 array of strings. If found, returns the element of VALUES with that index.
109 xml_get_enum_value (const XML_Char
**attrs
,
110 const XML_Char
*attr
,
111 const XML_Char
**xml_names
,
114 const XML_Char
*value
= xml_get_required_attribute (attrs
, attr
);
117 for (i
= 0; xml_names
[i
]; ++i
)
119 if (strcmp (xml_names
[i
], value
) == 0)
122 throw_error (XML_PARSE_ERROR
,
123 _("Invalid enumerated value in XML: %s"), value
);
126 /* Cleanup wrapper for XML_ParserFree, with the correct type
130 free_xml_parser (void *parser
)
132 XML_ParserFree (parser
);
135 /* Register a cleanup to release PARSER. Only the parser itself
136 is freed; another cleanup may be necessary to discard any
137 associated user data. */
140 make_cleanup_free_xml_parser (XML_Parser parser
)
142 make_cleanup (free_xml_parser
, parser
);
145 #endif /* HAVE_LIBEXPAT */
This page took 0.032202 seconds and 4 git commands to generate.