blob: e277ad059ffe61a444e27a783f18048660736fae [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);
139void xmlXPathNodeSetAdd (xmlNodeSetPtr cur,
140 xmlNodePtr val);
141
142
143void xmlXPathIdFunction (xmlXPathParserContextPtr ctxt,
144 int nargs);
145void xmlXPathRoot (xmlXPathParserContextPtr ctxt);
146void xmlXPathEvalExpr (xmlXPathParserContextPtr ctxt);
147xmlChar * xmlXPathParseName (xmlXPathParserContextPtr ctxt);
Daniel Veillarda6d8eb62000-12-27 10:46:47 +0000148xmlChar * xmlXPathParseNCName (xmlXPathParserContextPtr ctxt);
Daniel Veillard29a11cc2000-10-25 13:32:39 +0000149
150/*
151 * Debug
152 */
153#ifdef LIBXML_DEBUG_ENABLED
154double xmlXPathStringEvalNumber(const xmlChar *str);
155void xmlXPathDebugDumpObject(FILE *output, xmlXPathObjectPtr cur, int depth);
156#endif
157/*
158 * Existing functions
159 */
160
Daniel Veillardf62ceff2000-11-24 23:36:01 +0000161int xmlXPathEvaluatePredicateResult(xmlXPathParserContextPtr ctxt,
162 xmlXPathObjectPtr res);
Daniel Veillard29a11cc2000-10-25 13:32:39 +0000163void xmlXPathInit(void);
164void xmlXPathStringFunction(xmlXPathParserContextPtr ctxt, int nargs);
165void xmlXPathRegisterAllFunctions(xmlXPathContextPtr ctxt);
166xmlNodeSetPtr xmlXPathNodeSetCreate(xmlNodePtr val);
167void xmlXPathNodeSetAdd(xmlNodeSetPtr cur, xmlNodePtr val);
168xmlNodeSetPtr xmlXPathNodeSetMerge(xmlNodeSetPtr val1, xmlNodeSetPtr val2);
169void xmlXPathNodeSetDel(xmlNodeSetPtr cur, xmlNodePtr val);
170void xmlXPathNodeSetRemove(xmlNodeSetPtr cur, int val);
171void xmlXPathFreeNodeSet(xmlNodeSetPtr obj);
172xmlXPathObjectPtr xmlXPathNewNodeSet(xmlNodePtr val);
173xmlXPathObjectPtr xmlXPathNewNodeSetList(xmlNodeSetPtr val);
174xmlXPathObjectPtr xmlXPathWrapNodeSet(xmlNodeSetPtr val);
175void xmlXPathFreeNodeSetList(xmlXPathObjectPtr obj);
176
177
178xmlXPathObjectPtr xmlXPathNewFloat(double val);
179xmlXPathObjectPtr xmlXPathNewBoolean(int val);
180xmlXPathObjectPtr xmlXPathNewString(const xmlChar *val);
181xmlXPathObjectPtr xmlXPathNewCString(const char *val);
182void xmlXPathFreeObject(xmlXPathObjectPtr obj);
183xmlXPathContextPtr xmlXPathNewContext(xmlDocPtr doc);
184void xmlXPathFreeContext(xmlXPathContextPtr ctxt);
185
186int xmlXPathEqualValues(xmlXPathParserContextPtr ctxt);
187int xmlXPathCompareValues(xmlXPathParserContextPtr ctxt, int inf, int strict);
188void xmlXPathValueFlipSign(xmlXPathParserContextPtr ctxt);
189void xmlXPathAddValues(xmlXPathParserContextPtr ctxt);
190void xmlXPathSubValues(xmlXPathParserContextPtr ctxt);
191void xmlXPathMultValues(xmlXPathParserContextPtr ctxt);
192void xmlXPathDivValues(xmlXPathParserContextPtr ctxt);
193void xmlXPathModValues(xmlXPathParserContextPtr ctxt);
194
195/*
196 * The official core of XPath functions
197 */
198void xmlXPathRoot(xmlXPathParserContextPtr ctxt);
199void xmlXPathLastFunction(xmlXPathParserContextPtr ctxt, int nargs);
200void xmlXPathPositionFunction(xmlXPathParserContextPtr ctxt, int nargs);
201void xmlXPathCountFunction(xmlXPathParserContextPtr ctxt, int nargs);
202void xmlXPathIdFunction(xmlXPathParserContextPtr ctxt, int nargs);
Daniel Veillardf6bf9212000-10-26 14:07:44 +0000203void xmlXPathLocalNameFunction(xmlXPathParserContextPtr ctxt, int nargs);
204void xmlXPathNamespaceURIFunction(xmlXPathParserContextPtr ctxt, int nargs);
Daniel Veillard29a11cc2000-10-25 13:32:39 +0000205void xmlXPathStringFunction(xmlXPathParserContextPtr ctxt, int nargs);
206void xmlXPathStringLengthFunction(xmlXPathParserContextPtr ctxt, int nargs);
207void xmlXPathConcatFunction(xmlXPathParserContextPtr ctxt, int nargs);
208void xmlXPathContainsFunction(xmlXPathParserContextPtr ctxt, int nargs);
209void xmlXPathStartsWithFunction(xmlXPathParserContextPtr ctxt, int nargs);
210void xmlXPathSubstringFunction(xmlXPathParserContextPtr ctxt, int nargs);
211void xmlXPathSubstringBeforeFunction(xmlXPathParserContextPtr ctxt, int nargs);
212void xmlXPathSubstringAfterFunction(xmlXPathParserContextPtr ctxt, int nargs);
213void xmlXPathNormalizeFunction(xmlXPathParserContextPtr ctxt, int nargs);
214void xmlXPathTranslateFunction(xmlXPathParserContextPtr ctxt, int nargs);
215void xmlXPathNotFunction(xmlXPathParserContextPtr ctxt, int nargs);
216void xmlXPathTrueFunction(xmlXPathParserContextPtr ctxt, int nargs);
217void xmlXPathFalseFunction(xmlXPathParserContextPtr ctxt, int nargs);
218void xmlXPathLangFunction(xmlXPathParserContextPtr ctxt, int nargs);
219void xmlXPathNumberFunction(xmlXPathParserContextPtr ctxt, int nargs);
220void xmlXPathSumFunction(xmlXPathParserContextPtr ctxt, int nargs);
221void xmlXPathFloorFunction(xmlXPathParserContextPtr ctxt, int nargs);
222void xmlXPathCeilingFunction(xmlXPathParserContextPtr ctxt, int nargs);
223void xmlXPathRoundFunction(xmlXPathParserContextPtr ctxt, int nargs);
Daniel Veillard389e6b72001-01-15 19:41:13 +0000224void xmlXPathBooleanFunction(xmlXPathParserContextPtr ctxt, int nargs);
Daniel Veillard29a11cc2000-10-25 13:32:39 +0000225#ifdef __cplusplus
226}
227#endif
228#endif /* ! __XML_XPATH_INTERNALS_H__ */