Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Contents of /trunk/src/xmlparse.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 791 - (show annotations) (download) (as text)
Sat Jun 18 18:36:40 2011 UTC (13 years, 9 months ago) by amb
File MIME type: text/x-chdr
File size: 4273 byte(s)
Don't use the flex yylineno but keep track with an unsigned long long line
counter instead (if there are more than 2^31 nodes then there are more than 2^31
lines as well).

1 /***************************************
2 A simple XML parser
3
4 Part of the Routino routing software.
5 ******************/ /******************
6 This file Copyright 2010-2011 Andrew M. Bishop
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Affero General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
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 Affero General Public License for more details.
17
18 You should have received a copy of the GNU Affero General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ***************************************/
21
22
23 #ifndef XMLPARSE_H
24 #define XMLPARSE_H /*+ To stop multiple inclusions. +*/
25
26 #include <stdio.h>
27
28
29 /*+ The maximum number of attributes per tag. +*/
30 #define XMLPARSE_MAX_ATTRS 16
31
32 /*+ The maximum number of subtags per tag. +*/
33 #define XMLPARSE_MAX_SUBTAGS 16
34
35 /*+ A flag to indicate the start and/or end of a tag. +*/
36 #define XMLPARSE_TAG_START 1
37 #define XMLPARSE_TAG_END 2
38
39
40 /*+ A forward definition of the xmltag +*/
41 typedef struct _xmltag xmltag;
42
43
44 /*+ A structure to hold the definition of a tag. +*/
45 struct _xmltag
46 {
47 char *name; /*+ The name of the tag. +*/
48
49 int nattributes; /*+ The number of valid attributes for the tag. +*/
50 char *attributes[XMLPARSE_MAX_ATTRS]; /*+ The valid attributes for the tag. +*/
51
52 int (*callback)(); /*+ The callback function when the tag is seen. +*/
53
54 xmltag *subtags[XMLPARSE_MAX_SUBTAGS]; /*+ The list of valid tags contained within this one (null terminated). +*/
55 };
56
57
58 /* XML Parser options */
59
60 #define XMLPARSE_UNKNOWN_ATTRIBUTES 0x0003
61 #define XMLPARSE_UNKNOWN_ATTR_ERROR 0x0000 /* Flag an error and exit. */
62 #define XMLPARSE_UNKNOWN_ATTR_ERRNONAME 0x0001 /* Flag an error and exit unless a namespace is specified. */
63 #define XMLPARSE_UNKNOWN_ATTR_WARN 0x0002 /* Warn about the problem and continue. */
64 #define XMLPARSE_UNKNOWN_ATTR_IGNORE 0x0003 /* Ignore the potential problem. */
65
66 #define XMLPARSE_RETURN_ATTR_ENCODED 0x0004 /* Return the XML attribute strings without decoding them. */
67
68
69 /* XML parser functions */
70
71 int ParseXML(FILE *file,xmltag **tags,int options);
72
73 unsigned long long ParseXML_LineNumber(void);
74
75 char *ParseXML_Decode_Entity_Ref(const char *string);
76 char *ParseXML_Decode_Char_Ref(const char *string);
77 char *ParseXML_Encode_Safe_XML(const char *string);
78
79 int ParseXML_IsInteger(const char *string);
80 int ParseXML_IsFloating(const char *string);
81
82 /* Macros to simplify the callback functions */
83
84 #define XMLPARSE_MESSAGE(tag,message) \
85 do \
86 { \
87 fprintf(stderr,"XML Parser: Error on line %llu: " message " in <%s> tag.\n",ParseXML_LineNumber(),tag); \
88 return(1); \
89 } \
90 while(0)
91
92 #define XMLPARSE_INVALID(tag,attribute) \
93 do \
94 { \
95 fprintf(stderr,"XML Parser: Error on line %llu: Invalid value for '" #attribute "' attribute in <%s> tag.\n",ParseXML_LineNumber(),tag); \
96 return(1); \
97 } \
98 while(0)
99
100 #define XMLPARSE_ASSERT_STRING(tag,attribute) \
101 do \
102 { \
103 if(!attribute) \
104 { \
105 fprintf(stderr,"XML Parser: Error on line %llu: '" #attribute "' attribute must be specified in <%s> tag.\n",ParseXML_LineNumber(),tag); \
106 return(1); \
107 } \
108 } \
109 while(0)
110
111 #define XMLPARSE_ASSERT_INTEGER(tag,attribute) \
112 do \
113 { \
114 if(!attribute || !*attribute || !ParseXML_IsInteger(attribute)) \
115 { \
116 fprintf(stderr,"XML Parser: Error on line %llu: '" #attribute "' attribute must be a integer in <%s> tag.\n",ParseXML_LineNumber(),tag); \
117 return(1); \
118 } \
119 } \
120 while(0)
121
122 #define XMLPARSE_ASSERT_FLOATING(tag,attribute) \
123 do \
124 { \
125 if(!attribute || !*attribute || !ParseXML_IsFloating(attribute)) \
126 { \
127 fprintf(stderr,"XML Parser: Error on line %llu: '" #attribute "' attribute must be a number in <%s> tag.\n",ParseXML_LineNumber(),tag); \
128 return(1); \
129 } \
130 } \
131 while(0)
132
133
134 #endif /* XMLPARSE_H */

Properties

Name Value
cvs:description A simple generic XML parser (header file).