Debian Codegraph @

src/main/mxml-search.c

raw symbols SCIP
1 /*
2 * Search/navigation functions for mini-XML, a small XML-like file
3 * parsing library.
4 *
5 * Copyright 2003 by Michael Sweet.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * Contents:
18 *
19 * stp_mxmlFindElement() - Find the named element.
20 * stp_mxmlWalkNext() - Walk to the next logical node in the tree.
21 * stp_mxmlWalkPrev() - Walk to the previous logical node in the tree.
22 */
23
24 /*
25 * Include necessary headers...
26 */
27
28 #include <gutenprint/mxml.h>cxx . . $ `<file>/include/gutenprint/mxml.h`/
29 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:411:9`!
30 #include "config.h"cxx . . $ `<file>/config.h`/
31 #endif
32
33
34 /*
35 * 'stp_mxmlFindElement()' - Find the named element.
36 *
37 * The search is constrained by the name, attribute name, and value; any
38 * NULL names or values are treated as wildcards, so different kinds of
39 * searches can be implemented by looking for all elements of a given name
40 * or all elements with a specific attribute. The descend argument determines
41 * whether the search descends into child nodes; normally you will use
42 * STP_MXML_DESCEND_FIRST for the initial search and STP_MXML_NO_DESCEND to find
43 * additional direct descendents of the node. The top node argument
44 * constrains the search to a particular node's children.
45 */
46
47 stp_mxml_node_tcxx . . $ stp_mxml_node_t# * /* O - Element node or NULL */
48 stp_mxmlFindElementcxx . . $ stp_mxmlFindElement(9d3a1ee0d733a1fa).(stp_mxml_node_tcxx . . $ stp_mxml_node_t# *node, /* I - Current node */
49 stp_mxml_node_tcxx . . $ stp_mxml_node_t# *top, /* I - Top node */
50 const char *name, /* I - Element name or NULL for any */
51 const char *attr, /* I - Attribute name, or NULL for none */
52 const char *value, /* I - Attribute value, or NULL for any */
53 int descend) /* I - Descend into tree - STP_MXML_DESCEND, STP_MXML_NO_DESCEND, or STP_MXML_DESCEND_FIRST */
54 {
55 const char *temp; /* Current attribute value */
56
57
58 /*
59 * Range check input...
60 */
61
62 if (!node || !top || (!attr && value))
63 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
64
65 /*
66 * Start with the next node...
67 */
68
69 node = stp_mxmlWalkNextcxx . . $ stp_mxmlWalkNext(dc8e7a4515fe7c1a).(node, top, descend);
70
71 /*
72 * Loop until we find a matching element...
73 */
74
75 while (node != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
76 {
77 /*
78 * See if this node matches...
79 */
80
81 if (node->typecxx . . $ stp_mxml_node_s#type. == STP_MXML_ELEMENTcxx . . $ STP_MXML_ELEMENT. &&
82 node->valuecxx . . $ stp_mxml_node_s#value..elementcxx . . $ stp_mxml_value_u#element..namecxx . . $ stp_mxml_value_s#name. &&
83 (!name || !strcmpcxx . . $ strcmp(5ae29d726ae57f88).(node->valuecxx . . $ stp_mxml_node_s#value..elementcxx . . $ stp_mxml_value_u#element..namecxx . . $ stp_mxml_value_s#name., name)))
84 {
85 /*
86 * See if we need to check for an attribute...
87 */
88
89 if (!attr)
90 return (node); /* No attribute search, return it... */
91
92 /*
93 * Check for the attribute...
94 */
95
96 if ((temp = stp_mxmlElementGetAttrcxx . . $ stp_mxmlElementGetAttr(42933e0d82869bb1).(node, attr)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
97 {
98 /*
99 * OK, we have the attribute, does it match?
100 */
101
102 if (!value || !strcmpcxx . . $ strcmp(5ae29d726ae57f88).(value, temp))
103 return (node); /* Yes, return it... */
104 }
105 }
106
107 /*
108 * No match, move on to the next node...
109 */
110
111 if (descend == STP_MXML_DESCENDcxx . . $ `include/gutenprint/mxml.h:51:11`!)
112 node = stp_mxmlWalkNextcxx . . $ stp_mxmlWalkNext(dc8e7a4515fe7c1a).(node, top, STP_MXML_DESCENDcxx . . $ `include/gutenprint/mxml.h:51:11`!);
113 else
114 node = node->nextcxx . . $ stp_mxml_node_s#next.;
115 }
116
117 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
118 }
119
120
121 /*
122 * 'stp_mxmlWalkNext()' - Walk to the next logical node in the tree.
123 *
124 * The descend argument controls whether the first child is considered
125 * to be the next node. The top node argument constrains the walk to
126 * the node's children.
127 */
128
129 stp_mxml_node_tcxx . . $ stp_mxml_node_t# * /* O - Next node or NULL */
130 stp_mxmlWalkNextcxx . . $ stp_mxmlWalkNext(dc8e7a4515fe7c1a).(stp_mxml_node_tcxx . . $ stp_mxml_node_t# *node, /* I - Current node */
131 stp_mxml_node_tcxx . . $ stp_mxml_node_t# *top, /* I - Top node */
132 int descend) /* I - Descend into tree - STP_MXML_DESCEND, STP_MXML_NO_DESCEND, or STP_MXML_DESCEND_FIRST */
133 {
134 if (!node)
135 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
136 else if (node->childcxx . . $ stp_mxml_node_s#child. && descend)
137 return (node->childcxx . . $ stp_mxml_node_s#child.);
138 else if (node->nextcxx . . $ stp_mxml_node_s#next.)
139 return (node->nextcxx . . $ stp_mxml_node_s#next.);
140 else if (node->parentcxx . . $ stp_mxml_node_s#parent. && node->parentcxx . . $ stp_mxml_node_s#parent. != top)
141 {
142 node = node->parentcxx . . $ stp_mxml_node_s#parent.;
143
144 while (!node->nextcxx . . $ stp_mxml_node_s#next.)
145 if (node->parentcxx . . $ stp_mxml_node_s#parent. == top || !node->parentcxx . . $ stp_mxml_node_s#parent.)
146 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
147 else
148 node = node->parentcxx . . $ stp_mxml_node_s#parent.;
149
150 return (node->nextcxx . . $ stp_mxml_node_s#next.);
151 }
152 else
153 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
154 }
155
156
157 /*
158 * 'stp_mxmlWalkPrev()' - Walk to the previous logical node in the tree.
159 *
160 * The descend argument controls whether the previous node's last child
161 * is considered to be the previous node. The top node argument constrains
162 * the walk to the node's children.
163 */
164
165 stp_mxml_node_tcxx . . $ stp_mxml_node_t# * /* O - Previous node or NULL */
166 stp_mxmlWalkPrevcxx . . $ stp_mxmlWalkPrev(dc8e7a4515fe7c1a).(stp_mxml_node_tcxx . . $ stp_mxml_node_t# *node, /* I - Current node */
167 stp_mxml_node_tcxx . . $ stp_mxml_node_t# *top, /* I - Top node */
168 int descend) /* I - Descend into tree - STP_MXML_DESCEND, STP_MXML_NO_DESCEND, or STP_MXML_DESCEND_FIRST */
169 {
170 if (!node)
171 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
172 else if (node->prevcxx . . $ stp_mxml_node_s#prev.)
173 {
174 if (node->prevcxx . . $ stp_mxml_node_s#prev.->last_childcxx . . $ stp_mxml_node_s#last_child. && descend)
175 {
176 /*
177 * Find the last child under the previous node...
178 */
179
180 node = node->prevcxx . . $ stp_mxml_node_s#prev.->last_childcxx . . $ stp_mxml_node_s#last_child.;
181
182 while (node->last_childcxx . . $ stp_mxml_node_s#last_child.)
183 node = node->last_childcxx . . $ stp_mxml_node_s#last_child.;
184
185 return (node);
186 }
187 else
188 return (node->prevcxx . . $ stp_mxml_node_s#prev.);
189 }
190 else if (node->parentcxx . . $ stp_mxml_node_s#parent. != top)
191 return (node->parentcxx . . $ stp_mxml_node_s#parent.);
192 else
193 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
194 }