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"
34 #include "gdb_string.h"
36 /* Returns the value of attribute ATTR from expat attribute list
37 ATTRLIST. If not found, throws an exception. */
40 xml_get_required_attribute (const XML_Char
**attrs
,
44 for (p
= attrs
; *p
; p
+= 2)
46 const char *name
= p
[0];
47 const char *val
= p
[1];
49 if (strcmp (name
, attr
) == 0)
52 throw_error (XML_PARSE_ERROR
, _("Can't find attribute %s"), attr
);
55 /* Parse a field VALSTR that we expect to contain an integer value.
56 The integer is returned in *VALP. The string is parsed with an
57 equivalent to strtoul.
59 Returns 0 for success, -1 for error. */
62 xml_parse_unsigned_integer (const char *valstr
, ULONGEST
*valp
)
70 result
= strtoulst (valstr
, &endptr
, 0);
78 /* Gets the value of an integer attribute named ATTR, if it's present.
79 If the attribute is not found, or can't be parsed as integer,
80 throws an exception. */
83 xml_get_integer_attribute (const XML_Char
**attrs
,
87 const XML_Char
*value
= xml_get_required_attribute (attrs
, attr
);
89 if (xml_parse_unsigned_integer (value
, &result
) != 0)
91 throw_error (XML_PARSE_ERROR
,
92 _("Can't convert value of attribute %s, %s, to integer"),
98 /* Obtains a value of attribute with enumerated type. In XML, enumerated
99 attributes have string as a value, and in C, they are represented as
100 values of enumerated type. This function maps the attribute onto
101 an integer value that can be immediately converted into enumerated
104 First, obtains the string value of ATTR in ATTRS.
105 Then, finds the index of that value in XML_NAMES, which is a zero-terminated
106 array of strings. If found, returns the element of VALUES with that index.
110 xml_get_enum_value (const XML_Char
**attrs
,
111 const XML_Char
*attr
,
112 const XML_Char
**xml_names
,
115 const XML_Char
*value
= xml_get_required_attribute (attrs
, attr
);
118 for (i
= 0; xml_names
[i
]; ++i
)
120 if (strcmp (xml_names
[i
], value
) == 0)
123 throw_error (XML_PARSE_ERROR
,
124 _("Invalid enumerated value in XML: %s"), value
);
127 /* Cleanup wrapper for XML_ParserFree, with the correct type
131 free_xml_parser (void *parser
)
133 XML_ParserFree (parser
);
136 /* Register a cleanup to release PARSER. Only the parser itself
137 is freed; another cleanup may be necessary to discard any
138 associated user data. */
141 make_cleanup_free_xml_parser (XML_Parser parser
)
143 make_cleanup (free_xml_parser
, parser
);
146 #endif /* HAVE_LIBEXPAT */
This page took 0.03349 seconds and 4 git commands to generate.