blob: 51f6ad55ea7bd22f4d21d0bdf5609abe5ed75b86 [file] [log] [blame]
Owen Taylor3473f882001-02-23 17:55:21 +00001/*
2 * xpath.c: internal interfaces for XML Path Language implementation
3 * used to build new modules on top of XPath
4 *
5 * See COPYRIGHT for the status of this software
6 *
7 * Author: Daniel.Veillard@w3.org
8 */
9
10#ifndef __XML_XPATH_INTERNALS_H__
11#define __XML_XPATH_INTERNALS_H__
12
13#include <libxml/xpath.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19/************************************************************************
20 * *
21 * Helpers *
22 * *
23 ************************************************************************/
24
25#define CHECK_ERROR \
26 if (ctxt->error != XPATH_EXPRESSION_OK) return
27
28#define CHECK_ERROR0 \
29 if (ctxt->error != XPATH_EXPRESSION_OK) return(0)
30
31#define XP_ERROR(X) \
32 { xmlXPatherror(ctxt, __FILE__, __LINE__, X); \
33 ctxt->error = (X); return; }
34
35#define XP_ERROR0(X) \
36 { xmlXPatherror(ctxt, __FILE__, __LINE__, X); \
37 ctxt->error = (X); return(0); }
38
39#define CHECK_TYPE(typeval) \
40 if ((ctxt->value == NULL) || (ctxt->value->type != typeval)) \
41 XP_ERROR(XPATH_INVALID_TYPE)
42
43#define CHECK_ARITY(x) \
44 if (nargs != (x)) \
45 XP_ERROR(XPATH_INVALID_ARITY);
46
47#define CAST_TO_STRING \
48 if ((ctxt->value != NULL) && (ctxt->value->type != XPATH_STRING)) \
49 xmlXPathStringFunction(ctxt, 1);
50
51#define CAST_TO_NUMBER \
52 if ((ctxt->value != NULL) && (ctxt->value->type != XPATH_NUMBER)) \
53 xmlXPathNumberFunction(ctxt, 1);
54
55#define CAST_TO_BOOLEAN \
56 if ((ctxt->value != NULL) && (ctxt->value->type != XPATH_BOOLEAN)) \
57 xmlXPathBooleanFunction(ctxt, 1);
58
59/*
60 * Varibale Lookup forwarding
61 */
62typedef xmlXPathObjectPtr
63 (*xmlXPathVariableLookupFunc) (void *ctxt,
64 const xmlChar *name,
65 const xmlChar *ns_uri);
66
67void xmlXPathRegisterVariableLookup (xmlXPathContextPtr ctxt,
68 xmlXPathVariableLookupFunc f,
69 void *varCtxt);
70
71/*
72 * Error reporting
73 */
74void xmlXPatherror (xmlXPathParserContextPtr ctxt,
75 const char *file,
76 int line,
77 int no);
78
79void xmlXPathDebugDumpObject (FILE *output,
80 xmlXPathObjectPtr cur,
81 int depth);
82
83/**
84 * Extending a context
85 */
86
87int xmlXPathRegisterNs (xmlXPathContextPtr ctxt,
88 const xmlChar *prefix,
89 const xmlChar *ns_uri);
90const xmlChar * xmlXPathNsLookup (xmlXPathContextPtr ctxt,
91 const xmlChar *ns_uri);
92void xmlXPathRegisteredNsCleanup (xmlXPathContextPtr ctxt);
93
94int xmlXPathRegisterFunc (xmlXPathContextPtr ctxt,
95 const xmlChar *name,
96 xmlXPathFunction f);
97int xmlXPathRegisterFuncNS (xmlXPathContextPtr ctxt,
98 const xmlChar *name,
99 const xmlChar *ns_uri,
100 xmlXPathFunction f);
101int xmlXPathRegisterVariable (xmlXPathContextPtr ctxt,
102 const xmlChar *name,
103 xmlXPathObjectPtr value);
104int xmlXPathRegisterVariableNS (xmlXPathContextPtr ctxt,
105 const xmlChar *name,
106 const xmlChar *ns_uri,
107 xmlXPathObjectPtr value);
108xmlXPathFunction xmlXPathFunctionLookup (xmlXPathContextPtr ctxt,
109 const xmlChar *name);
110xmlXPathFunction xmlXPathFunctionLookupNS (xmlXPathContextPtr ctxt,
111 const xmlChar *name,
112 const xmlChar *ns_uri);
113void xmlXPathRegisteredFuncsCleanup(xmlXPathContextPtr ctxt);
114xmlXPathObjectPtr xmlXPathVariableLookup (xmlXPathContextPtr ctxt,
115 const xmlChar *name);
116xmlXPathObjectPtr xmlXPathVariableLookupNS (xmlXPathContextPtr ctxt,
117 const xmlChar *name,
118 const xmlChar *ns_uri);
119void xmlXPathRegisteredVariablesCleanup(xmlXPathContextPtr ctxt);
120
121/**
122 * Utilities to extend XPath
123 */
124xmlXPathParserContextPtr
125 xmlXPathNewParserContext (const xmlChar *str,
126 xmlXPathContextPtr ctxt);
127void xmlXPathFreeParserContext (xmlXPathParserContextPtr ctxt);
128
129/* TODO: remap to xmlXPathValuePop and Push */
130xmlXPathObjectPtr valuePop (xmlXPathParserContextPtr ctxt);
131int valuePush (xmlXPathParserContextPtr ctxt,
132 xmlXPathObjectPtr value);
133
134xmlXPathObjectPtr xmlXPathNewString (const xmlChar *val);
135xmlXPathObjectPtr xmlXPathNewCString (const char *val);
136xmlXPathObjectPtr xmlXPathNewFloat (double val);
137xmlXPathObjectPtr xmlXPathNewBoolean (int val);
138xmlXPathObjectPtr xmlXPathNewNodeSet (xmlNodePtr val);
139xmlXPathObjectPtr xmlXPathNewValueTree (xmlNodePtr val);
140void xmlXPathNodeSetAdd (xmlNodeSetPtr cur,
141 xmlNodePtr val);
142
143
144void xmlXPathIdFunction (xmlXPathParserContextPtr ctxt,
145 int nargs);
146void xmlXPathRoot (xmlXPathParserContextPtr ctxt);
147void xmlXPathEvalExpr (xmlXPathParserContextPtr ctxt);
148xmlChar * xmlXPathParseName (xmlXPathParserContextPtr ctxt);
149xmlChar * xmlXPathParseNCName (xmlXPathParserContextPtr ctxt);
150
151/*
152 * Debug
153 */
154#ifdef LIBXML_DEBUG_ENABLED
155double xmlXPathStringEvalNumber(const xmlChar *str);
156void xmlXPathDebugDumpObject(FILE *output, xmlXPathObjectPtr cur, int depth);
157#endif
158/*
159 * Existing functions
160 */
161
162int xmlXPathEvaluatePredicateResult(xmlXPathParserContextPtr ctxt,
163 xmlXPathObjectPtr res);
164void xmlXPathInit(void);
165void xmlXPathStringFunction(xmlXPathParserContextPtr ctxt, int nargs);
166void xmlXPathRegisterAllFunctions(xmlXPathContextPtr ctxt);
167xmlNodeSetPtr xmlXPathNodeSetCreate(xmlNodePtr val);
168void xmlXPathNodeSetAdd(xmlNodeSetPtr cur, xmlNodePtr val);
169xmlNodeSetPtr xmlXPathNodeSetMerge(xmlNodeSetPtr val1, xmlNodeSetPtr val2);
170void xmlXPathNodeSetDel(xmlNodeSetPtr cur, xmlNodePtr val);
171void xmlXPathNodeSetRemove(xmlNodeSetPtr cur, int val);
172void xmlXPathFreeNodeSet(xmlNodeSetPtr obj);
173xmlXPathObjectPtr xmlXPathNewNodeSet(xmlNodePtr val);
174xmlXPathObjectPtr xmlXPathNewNodeSetList(xmlNodeSetPtr val);
175xmlXPathObjectPtr xmlXPathWrapNodeSet(xmlNodeSetPtr val);
176void xmlXPathFreeNodeSetList(xmlXPathObjectPtr obj);
177
178
179xmlXPathObjectPtr xmlXPathNewFloat(double val);
180xmlXPathObjectPtr xmlXPathNewBoolean(int val);
181xmlXPathObjectPtr xmlXPathNewString(const xmlChar *val);
182xmlXPathObjectPtr xmlXPathNewCString(const char *val);
183void xmlXPathFreeObject(xmlXPathObjectPtr obj);
184xmlXPathContextPtr xmlXPathNewContext(xmlDocPtr doc);
185void xmlXPathFreeContext(xmlXPathContextPtr ctxt);
186
187int xmlXPathEqualValues(xmlXPathParserContextPtr ctxt);
188int xmlXPathCompareValues(xmlXPathParserContextPtr ctxt, int inf, int strict);
189void xmlXPathValueFlipSign(xmlXPathParserContextPtr ctxt);
190void xmlXPathAddValues(xmlXPathParserContextPtr ctxt);
191void xmlXPathSubValues(xmlXPathParserContextPtr ctxt);
192void xmlXPathMultValues(xmlXPathParserContextPtr ctxt);
193void xmlXPathDivValues(xmlXPathParserContextPtr ctxt);
194void xmlXPathModValues(xmlXPathParserContextPtr ctxt);
195
196
197/*
198 * Some of the axis navigation routines
199 */
200xmlNodePtr xmlXPathNextPreceding(xmlXPathParserContextPtr ctxt, xmlNodePtr cur);
201xmlNodePtr xmlXPathNextAncestor(xmlXPathParserContextPtr ctxt, xmlNodePtr cur);
202xmlNodePtr xmlXPathNextPrecedingSibling(xmlXPathParserContextPtr ctxt, xmlNodePtr cur);
203/*
204 * The official core of XPath functions
205 */
206void xmlXPathRoot(xmlXPathParserContextPtr ctxt);
207void xmlXPathLastFunction(xmlXPathParserContextPtr ctxt, int nargs);
208void xmlXPathPositionFunction(xmlXPathParserContextPtr ctxt, int nargs);
209void xmlXPathCountFunction(xmlXPathParserContextPtr ctxt, int nargs);
210void xmlXPathIdFunction(xmlXPathParserContextPtr ctxt, int nargs);
211void xmlXPathLocalNameFunction(xmlXPathParserContextPtr ctxt, int nargs);
212void xmlXPathNamespaceURIFunction(xmlXPathParserContextPtr ctxt, int nargs);
213void xmlXPathStringFunction(xmlXPathParserContextPtr ctxt, int nargs);
214void xmlXPathStringLengthFunction(xmlXPathParserContextPtr ctxt, int nargs);
215void xmlXPathConcatFunction(xmlXPathParserContextPtr ctxt, int nargs);
216void xmlXPathContainsFunction(xmlXPathParserContextPtr ctxt, int nargs);
217void xmlXPathStartsWithFunction(xmlXPathParserContextPtr ctxt, int nargs);
218void xmlXPathSubstringFunction(xmlXPathParserContextPtr ctxt, int nargs);
219void xmlXPathSubstringBeforeFunction(xmlXPathParserContextPtr ctxt, int nargs);
220void xmlXPathSubstringAfterFunction(xmlXPathParserContextPtr ctxt, int nargs);
221void xmlXPathNormalizeFunction(xmlXPathParserContextPtr ctxt, int nargs);
222void xmlXPathTranslateFunction(xmlXPathParserContextPtr ctxt, int nargs);
223void xmlXPathNotFunction(xmlXPathParserContextPtr ctxt, int nargs);
224void xmlXPathTrueFunction(xmlXPathParserContextPtr ctxt, int nargs);
225void xmlXPathFalseFunction(xmlXPathParserContextPtr ctxt, int nargs);
226void xmlXPathLangFunction(xmlXPathParserContextPtr ctxt, int nargs);
227void xmlXPathNumberFunction(xmlXPathParserContextPtr ctxt, int nargs);
228void xmlXPathSumFunction(xmlXPathParserContextPtr ctxt, int nargs);
229void xmlXPathFloorFunction(xmlXPathParserContextPtr ctxt, int nargs);
230void xmlXPathCeilingFunction(xmlXPathParserContextPtr ctxt, int nargs);
231void xmlXPathRoundFunction(xmlXPathParserContextPtr ctxt, int nargs);
232void xmlXPathBooleanFunction(xmlXPathParserContextPtr ctxt, int nargs);
233#ifdef __cplusplus
234}
235#endif
236#endif /* ! __XML_XPATH_INTERNALS_H__ */