blob: 110e5ade95635a214d6ce50e7be132459d3e8f5d [file] [log] [blame]
Daniel Veillard29a11cc2000-10-25 13:32:39 +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)) \
Daniel Veillarda5db68a2000-10-29 18:06:06 +000041 XP_ERROR(XPATH_INVALID_TYPE)
Daniel Veillard29a11cc2000-10-25 13:32:39 +000042
43#define CHECK_ARITY(x) \
Daniel Veillarda5db68a2000-10-29 18:06:06 +000044 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);
Daniel Veillard29a11cc2000-10-25 13:32:39 +000058
Daniel Veillard8f4d9752001-01-19 05:32:34 +000059/*
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 */
Daniel Veillard29a11cc2000-10-25 13:32:39 +000074void 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 */
Daniel Veillard8f4d9752001-01-19 05:32:34 +000086
Daniel Veillarda6d8eb62000-12-27 10:46:47 +000087int 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
Daniel Veillard29a11cc2000-10-25 13:32:39 +000094int xmlXPathRegisterFunc (xmlXPathContextPtr ctxt,
95 const xmlChar *name,
96 xmlXPathFunction f);
Daniel Veillarda5db68a2000-10-29 18:06:06 +000097int xmlXPathRegisterFuncNS (xmlXPathContextPtr ctxt,
98 const xmlChar *name,
99 const xmlChar *ns_uri,
100 xmlXPathFunction f);
Daniel Veillard29a11cc2000-10-25 13:32:39 +0000101int xmlXPathRegisterVariable (xmlXPathContextPtr ctxt,
102 const xmlChar *name,
103 xmlXPathObjectPtr value);
Daniel Veillarda5db68a2000-10-29 18:06:06 +0000104int xmlXPathRegisterVariableNS (xmlXPathContextPtr ctxt,
105 const xmlChar *name,
106 const xmlChar *ns_uri,
107 xmlXPathObjectPtr value);
Daniel Veillard29a11cc2000-10-25 13:32:39 +0000108xmlXPathFunction xmlXPathFunctionLookup (xmlXPathContextPtr ctxt,
109 const xmlChar *name);
Daniel Veillarda5db68a2000-10-29 18:06:06 +0000110xmlXPathFunction xmlXPathFunctionLookupNS (xmlXPathContextPtr ctxt,
111 const xmlChar *name,
112 const xmlChar *ns_uri);
Daniel Veillard29a11cc2000-10-25 13:32:39 +0000113void xmlXPathRegisteredFuncsCleanup(xmlXPathContextPtr ctxt);
114xmlXPathObjectPtr xmlXPathVariableLookup (xmlXPathContextPtr ctxt,
115 const xmlChar *name);
Daniel Veillarda5db68a2000-10-29 18:06:06 +0000116xmlXPathObjectPtr xmlXPathVariableLookupNS (xmlXPathContextPtr ctxt,
117 const xmlChar *name,
118 const xmlChar *ns_uri);
Daniel Veillard29a11cc2000-10-25 13:32:39 +0000119void 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
Daniel Veillard389e6b72001-01-15 19:41:13 +0000129/* TODO: remap to xmlXPathValuePop and Push */
Daniel Veillard29a11cc2000-10-25 13:32:39 +0000130xmlXPathObjectPtr 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);
Daniel Veillarde4566462001-01-22 09:58:39 +0000139xmlXPathObjectPtr xmlXPathNewValueTree (xmlNodePtr val);
Daniel Veillard29a11cc2000-10-25 13:32:39 +0000140void 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);
Daniel Veillarda6d8eb62000-12-27 10:46:47 +0000149xmlChar * xmlXPathParseNCName (xmlXPathParserContextPtr ctxt);
Daniel Veillard29a11cc2000-10-25 13:32:39 +0000150
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
Daniel Veillardf62ceff2000-11-24 23:36:01 +0000162int xmlXPathEvaluatePredicateResult(xmlXPathParserContextPtr ctxt,
163 xmlXPathObjectPtr res);
Daniel Veillard29a11cc2000-10-25 13:32:39 +0000164void 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 * The official core of XPath functions
198 */
199void xmlXPathRoot(xmlXPathParserContextPtr ctxt);
200void xmlXPathLastFunction(xmlXPathParserContextPtr ctxt, int nargs);
201void xmlXPathPositionFunction(xmlXPathParserContextPtr ctxt, int nargs);
202void xmlXPathCountFunction(xmlXPathParserContextPtr ctxt, int nargs);
203void xmlXPathIdFunction(xmlXPathParserContextPtr ctxt, int nargs);
Daniel Veillardf6bf9212000-10-26 14:07:44 +0000204void xmlXPathLocalNameFunction(xmlXPathParserContextPtr ctxt, int nargs);
205void xmlXPathNamespaceURIFunction(xmlXPathParserContextPtr ctxt, int nargs);
Daniel Veillard29a11cc2000-10-25 13:32:39 +0000206void xmlXPathStringFunction(xmlXPathParserContextPtr ctxt, int nargs);
207void xmlXPathStringLengthFunction(xmlXPathParserContextPtr ctxt, int nargs);
208void xmlXPathConcatFunction(xmlXPathParserContextPtr ctxt, int nargs);
209void xmlXPathContainsFunction(xmlXPathParserContextPtr ctxt, int nargs);
210void xmlXPathStartsWithFunction(xmlXPathParserContextPtr ctxt, int nargs);
211void xmlXPathSubstringFunction(xmlXPathParserContextPtr ctxt, int nargs);
212void xmlXPathSubstringBeforeFunction(xmlXPathParserContextPtr ctxt, int nargs);
213void xmlXPathSubstringAfterFunction(xmlXPathParserContextPtr ctxt, int nargs);
214void xmlXPathNormalizeFunction(xmlXPathParserContextPtr ctxt, int nargs);
215void xmlXPathTranslateFunction(xmlXPathParserContextPtr ctxt, int nargs);
216void xmlXPathNotFunction(xmlXPathParserContextPtr ctxt, int nargs);
217void xmlXPathTrueFunction(xmlXPathParserContextPtr ctxt, int nargs);
218void xmlXPathFalseFunction(xmlXPathParserContextPtr ctxt, int nargs);
219void xmlXPathLangFunction(xmlXPathParserContextPtr ctxt, int nargs);
220void xmlXPathNumberFunction(xmlXPathParserContextPtr ctxt, int nargs);
221void xmlXPathSumFunction(xmlXPathParserContextPtr ctxt, int nargs);
222void xmlXPathFloorFunction(xmlXPathParserContextPtr ctxt, int nargs);
223void xmlXPathCeilingFunction(xmlXPathParserContextPtr ctxt, int nargs);
224void xmlXPathRoundFunction(xmlXPathParserContextPtr ctxt, int nargs);
Daniel Veillard389e6b72001-01-15 19:41:13 +0000225void xmlXPathBooleanFunction(xmlXPathParserContextPtr ctxt, int nargs);
Daniel Veillard29a11cc2000-10-25 13:32:39 +0000226#ifdef __cplusplus
227}
228#endif
229#endif /* ! __XML_XPATH_INTERNALS_H__ */