VirtualBox

source: vbox/trunk/src/libs/libxslt-1.1.22/libexslt/sets.c@ 33944

Last change on this file since 33944 was 7299, checked in by vboxsync, 17 years ago

Added vboxconfig.h for linux builds.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 6.4 KB
Line 
1#define IN_LIBEXSLT
2#include "libexslt/libexslt.h"
3
4#if defined(WIN32) && !defined (__CYGWIN__) && (!__MINGW32__)
5#include <win32config.h>
6#elif defined(VBOX)
7#include "vboxconfig.h"
8#else
9#include "config.h"
10#endif
11
12#include <libxml/tree.h>
13#include <libxml/xpath.h>
14#include <libxml/xpathInternals.h>
15
16#include <libxslt/xsltutils.h>
17#include <libxslt/xsltInternals.h>
18#include <libxslt/extensions.h>
19
20#include "exslt.h"
21
22/**
23 * exsltSetsDifferenceFunction:
24 * @ctxt: an XPath parser context
25 * @nargs: the number of arguments
26 *
27 * Wraps #xmlXPathDifference for use by the XPath processor
28 */
29static void
30exsltSetsDifferenceFunction (xmlXPathParserContextPtr ctxt, int nargs) {
31 xmlNodeSetPtr arg1, arg2, ret;
32
33 if (nargs != 2) {
34 xmlXPathSetArityError(ctxt);
35 return;
36 }
37
38 arg2 = xmlXPathPopNodeSet(ctxt);
39 if (xmlXPathCheckError(ctxt)) {
40 xmlXPathSetTypeError(ctxt);
41 return;
42 }
43
44 arg1 = xmlXPathPopNodeSet(ctxt);
45 if (xmlXPathCheckError(ctxt)) {
46 xmlXPathSetTypeError(ctxt);
47 return;
48 }
49
50 ret = xmlXPathDifference(arg1, arg2);
51
52 if (ret != arg1)
53 xmlXPathFreeNodeSet(arg1);
54 xmlXPathFreeNodeSet(arg2);
55
56 xmlXPathReturnNodeSet(ctxt, ret);
57}
58
59/**
60 * exsltSetsIntersectionFunction:
61 * @ctxt: an XPath parser context
62 * @nargs: the number of arguments
63 *
64 * Wraps #xmlXPathIntersection for use by the XPath processor
65 */
66static void
67exsltSetsIntersectionFunction (xmlXPathParserContextPtr ctxt, int nargs) {
68 xmlNodeSetPtr arg1, arg2, ret;
69
70 if (nargs != 2) {
71 xmlXPathSetArityError(ctxt);
72 return;
73 }
74
75 arg2 = xmlXPathPopNodeSet(ctxt);
76 if (xmlXPathCheckError(ctxt)) {
77 xmlXPathSetTypeError(ctxt);
78 return;
79 }
80
81 arg1 = xmlXPathPopNodeSet(ctxt);
82 if (xmlXPathCheckError(ctxt)) {
83 xmlXPathSetTypeError(ctxt);
84 return;
85 }
86
87 ret = xmlXPathIntersection(arg1, arg2);
88
89 xmlXPathFreeNodeSet(arg1);
90 xmlXPathFreeNodeSet(arg2);
91
92 xmlXPathReturnNodeSet(ctxt, ret);
93}
94
95/**
96 * exsltSetsDistinctFunction:
97 * @ctxt: an XPath parser context
98 * @nargs: the number of arguments
99 *
100 * Wraps #xmlXPathDistinct for use by the XPath processor
101 */
102static void
103exsltSetsDistinctFunction (xmlXPathParserContextPtr ctxt, int nargs) {
104 xmlXPathObjectPtr obj;
105 xmlNodeSetPtr ns, ret;
106 int boolval = 0;
107 void *user = NULL;
108
109 if (nargs != 1) {
110 xmlXPathSetArityError(ctxt);
111 return;
112 }
113
114 if (ctxt->value != NULL) {
115 boolval = ctxt->value->boolval;
116 user = ctxt->value->user;
117 ctxt->value->boolval = 0;
118 ctxt->value->user = NULL;
119 }
120 ns = xmlXPathPopNodeSet(ctxt);
121 if (xmlXPathCheckError(ctxt))
122 return;
123
124 /* !!! must be sorted !!! */
125 ret = xmlXPathDistinctSorted(ns);
126
127 if (ret != ns)
128 xmlXPathFreeNodeSet(ns);
129
130 obj = xmlXPathWrapNodeSet(ret);
131 obj->user = user;
132 obj->boolval = boolval;
133 valuePush((ctxt), obj);
134}
135
136/**
137 * exsltSetsHasSameNodesFunction:
138 * @ctxt: an XPath parser context
139 * @nargs: the number of arguments
140 *
141 * Wraps #xmlXPathHasSameNodes for use by the XPath processor
142 */
143static void
144exsltSetsHasSameNodesFunction (xmlXPathParserContextPtr ctxt,
145 int nargs) {
146 xmlNodeSetPtr arg1, arg2;
147 int ret;
148
149 if (nargs != 2) {
150 xmlXPathSetArityError(ctxt);
151 return;
152 }
153
154 arg2 = xmlXPathPopNodeSet(ctxt);
155 if (xmlXPathCheckError(ctxt)) {
156 xmlXPathSetTypeError(ctxt);
157 return;
158 }
159
160 arg1 = xmlXPathPopNodeSet(ctxt);
161 if (xmlXPathCheckError(ctxt)) {
162 xmlXPathSetTypeError(ctxt);
163 return;
164 }
165
166 ret = xmlXPathHasSameNodes(arg1, arg2);
167
168 xmlXPathFreeNodeSet(arg1);
169 xmlXPathFreeNodeSet(arg2);
170
171 xmlXPathReturnBoolean(ctxt, ret);
172}
173
174/**
175 * exsltSetsLeadingFunction:
176 * @ctxt: an XPath parser context
177 * @nargs: the number of arguments
178 *
179 * Wraps #xmlXPathLeading for use by the XPath processor
180 */
181static void
182exsltSetsLeadingFunction (xmlXPathParserContextPtr ctxt, int nargs) {
183 xmlNodeSetPtr arg1, arg2, ret;
184
185 if (nargs != 2) {
186 xmlXPathSetArityError(ctxt);
187 return;
188 }
189
190 arg2 = xmlXPathPopNodeSet(ctxt);
191 if (xmlXPathCheckError(ctxt)) {
192 xmlXPathSetTypeError(ctxt);
193 return;
194 }
195
196 arg1 = xmlXPathPopNodeSet(ctxt);
197 if (xmlXPathCheckError(ctxt)) {
198 xmlXPathSetTypeError(ctxt);
199 return;
200 }
201
202 /* If the second node set is empty, then the first node set is
203 * returned.
204 */
205 if (xmlXPathNodeSetIsEmpty(arg2)) {
206 xmlXPathReturnNodeSet(ctxt, arg1);
207
208 xmlXPathFreeNodeSet(arg2);
209
210 return;
211 }
212 /* !!! must be sorted */
213 ret = xmlXPathNodeLeadingSorted(arg1, xmlXPathNodeSetItem(arg2, 0));
214
215 xmlXPathFreeNodeSet(arg1);
216 xmlXPathFreeNodeSet(arg2);
217
218 xmlXPathReturnNodeSet(ctxt, ret);
219}
220
221/**
222 * exsltSetsTrailingFunction:
223 * @ctxt: an XPath parser context
224 * @nargs: the number of arguments
225 *
226 * Wraps #xmlXPathTrailing for use by the XPath processor
227 */
228static void
229exsltSetsTrailingFunction (xmlXPathParserContextPtr ctxt, int nargs) {
230 xmlNodeSetPtr arg1, arg2, ret;
231
232 if (nargs != 2) {
233 xmlXPathSetArityError(ctxt);
234 return;
235 }
236
237 arg2 = xmlXPathPopNodeSet(ctxt);
238 if (xmlXPathCheckError(ctxt)) {
239 xmlXPathSetTypeError(ctxt);
240 return;
241 }
242
243 arg1 = xmlXPathPopNodeSet(ctxt);
244 if (xmlXPathCheckError(ctxt)) {
245 xmlXPathSetTypeError(ctxt);
246 return;
247 }
248
249 /* If the second node set is empty, then the first node set is
250 * returned.
251 */
252 if (xmlXPathNodeSetIsEmpty(arg2)) {
253 xmlXPathReturnNodeSet(ctxt, arg1);
254
255 xmlXPathFreeNodeSet(arg2);
256
257 return;
258 }
259 /* !!! mist be sorted */
260 ret = xmlXPathNodeTrailingSorted(arg1, xmlXPathNodeSetItem(arg2, 0));
261
262 xmlXPathFreeNodeSet(arg1);
263 xmlXPathFreeNodeSet(arg2);
264
265 xmlXPathReturnNodeSet(ctxt, ret);
266}
267
268/**
269 * exsltSetsRegister:
270 *
271 * Registers the EXSLT - Sets module
272 */
273
274void
275exsltSetsRegister (void) {
276 xsltRegisterExtModuleFunction ((const xmlChar *) "difference",
277 EXSLT_SETS_NAMESPACE,
278 exsltSetsDifferenceFunction);
279 xsltRegisterExtModuleFunction ((const xmlChar *) "intersection",
280 EXSLT_SETS_NAMESPACE,
281 exsltSetsIntersectionFunction);
282 xsltRegisterExtModuleFunction ((const xmlChar *) "distinct",
283 EXSLT_SETS_NAMESPACE,
284 exsltSetsDistinctFunction);
285 xsltRegisterExtModuleFunction ((const xmlChar *) "has-same-node",
286 EXSLT_SETS_NAMESPACE,
287 exsltSetsHasSameNodesFunction);
288 xsltRegisterExtModuleFunction ((const xmlChar *) "leading",
289 EXSLT_SETS_NAMESPACE,
290 exsltSetsLeadingFunction);
291 xsltRegisterExtModuleFunction ((const xmlChar *) "trailing",
292 EXSLT_SETS_NAMESPACE,
293 exsltSetsTrailingFunction);
294}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette