blob: b73d49e4a621b71e7a69705fc39d008ec17254b5 [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
59void xmlXPatherror (xmlXPathParserContextPtr ctxt,
60 const char *file,
61 int line,
62 int no);
63
64void xmlXPathDebugDumpObject (FILE *output,
65 xmlXPathObjectPtr cur,
66 int depth);
67
68/**
69 * Extending a context
70 */
71int xmlXPathRegisterFunc (xmlXPathContextPtr ctxt,
72 const xmlChar *name,
73 xmlXPathFunction f);
Daniel Veillarda5db68a2000-10-29 18:06:06 +000074int xmlXPathRegisterFuncNS (xmlXPathContextPtr ctxt,
75 const xmlChar *name,
76 const xmlChar *ns_uri,
77 xmlXPathFunction f);
Daniel Veillard29a11cc2000-10-25 13:32:39 +000078int xmlXPathRegisterVariable (xmlXPathContextPtr ctxt,
79 const xmlChar *name,
80 xmlXPathObjectPtr value);
Daniel Veillarda5db68a2000-10-29 18:06:06 +000081int xmlXPathRegisterVariableNS (xmlXPathContextPtr ctxt,
82 const xmlChar *name,
83 const xmlChar *ns_uri,
84 xmlXPathObjectPtr value);
Daniel Veillard29a11cc2000-10-25 13:32:39 +000085xmlXPathFunction xmlXPathFunctionLookup (xmlXPathContextPtr ctxt,
86 const xmlChar *name);
Daniel Veillarda5db68a2000-10-29 18:06:06 +000087xmlXPathFunction xmlXPathFunctionLookupNS (xmlXPathContextPtr ctxt,
88 const xmlChar *name,
89 const xmlChar *ns_uri);
Daniel Veillard29a11cc2000-10-25 13:32:39 +000090void xmlXPathRegisteredFuncsCleanup(xmlXPathContextPtr ctxt);
91xmlXPathObjectPtr xmlXPathVariableLookup (xmlXPathContextPtr ctxt,
92 const xmlChar *name);
Daniel Veillarda5db68a2000-10-29 18:06:06 +000093xmlXPathObjectPtr xmlXPathVariableLookupNS (xmlXPathContextPtr ctxt,
94 const xmlChar *name,
95 const xmlChar *ns_uri);
Daniel Veillard29a11cc2000-10-25 13:32:39 +000096void xmlXPathRegisteredVariablesCleanup(xmlXPathContextPtr ctxt);
97
98/**
99 * Utilities to extend XPath
100 */
101xmlXPathParserContextPtr
102 xmlXPathNewParserContext (const xmlChar *str,
103 xmlXPathContextPtr ctxt);
104void xmlXPathFreeParserContext (xmlXPathParserContextPtr ctxt);
105
106xmlXPathObjectPtr valuePop (xmlXPathParserContextPtr ctxt);
107int valuePush (xmlXPathParserContextPtr ctxt,
108 xmlXPathObjectPtr value);
109
110xmlXPathObjectPtr xmlXPathNewString (const xmlChar *val);
111xmlXPathObjectPtr xmlXPathNewCString (const char *val);
112xmlXPathObjectPtr xmlXPathNewFloat (double val);
113xmlXPathObjectPtr xmlXPathNewBoolean (int val);
114xmlXPathObjectPtr xmlXPathNewNodeSet (xmlNodePtr val);
115void xmlXPathNodeSetAdd (xmlNodeSetPtr cur,
116 xmlNodePtr val);
117
118
119void xmlXPathIdFunction (xmlXPathParserContextPtr ctxt,
120 int nargs);
121void xmlXPathRoot (xmlXPathParserContextPtr ctxt);
122void xmlXPathEvalExpr (xmlXPathParserContextPtr ctxt);
123xmlChar * xmlXPathParseName (xmlXPathParserContextPtr ctxt);
124
125/*
126 * Debug
127 */
128#ifdef LIBXML_DEBUG_ENABLED
129double xmlXPathStringEvalNumber(const xmlChar *str);
130void xmlXPathDebugDumpObject(FILE *output, xmlXPathObjectPtr cur, int depth);
131#endif
132/*
133 * Existing functions
134 */
135
136void xmlXPathInit(void);
137void xmlXPathStringFunction(xmlXPathParserContextPtr ctxt, int nargs);
138void xmlXPathRegisterAllFunctions(xmlXPathContextPtr ctxt);
139xmlNodeSetPtr xmlXPathNodeSetCreate(xmlNodePtr val);
140void xmlXPathNodeSetAdd(xmlNodeSetPtr cur, xmlNodePtr val);
141xmlNodeSetPtr xmlXPathNodeSetMerge(xmlNodeSetPtr val1, xmlNodeSetPtr val2);
142void xmlXPathNodeSetDel(xmlNodeSetPtr cur, xmlNodePtr val);
143void xmlXPathNodeSetRemove(xmlNodeSetPtr cur, int val);
144void xmlXPathFreeNodeSet(xmlNodeSetPtr obj);
145xmlXPathObjectPtr xmlXPathNewNodeSet(xmlNodePtr val);
146xmlXPathObjectPtr xmlXPathNewNodeSetList(xmlNodeSetPtr val);
147xmlXPathObjectPtr xmlXPathWrapNodeSet(xmlNodeSetPtr val);
148void xmlXPathFreeNodeSetList(xmlXPathObjectPtr obj);
149
150
151xmlXPathObjectPtr xmlXPathNewFloat(double val);
152xmlXPathObjectPtr xmlXPathNewBoolean(int val);
153xmlXPathObjectPtr xmlXPathNewString(const xmlChar *val);
154xmlXPathObjectPtr xmlXPathNewCString(const char *val);
155void xmlXPathFreeObject(xmlXPathObjectPtr obj);
156xmlXPathContextPtr xmlXPathNewContext(xmlDocPtr doc);
157void xmlXPathFreeContext(xmlXPathContextPtr ctxt);
158
159int xmlXPathEqualValues(xmlXPathParserContextPtr ctxt);
160int xmlXPathCompareValues(xmlXPathParserContextPtr ctxt, int inf, int strict);
161void xmlXPathValueFlipSign(xmlXPathParserContextPtr ctxt);
162void xmlXPathAddValues(xmlXPathParserContextPtr ctxt);
163void xmlXPathSubValues(xmlXPathParserContextPtr ctxt);
164void xmlXPathMultValues(xmlXPathParserContextPtr ctxt);
165void xmlXPathDivValues(xmlXPathParserContextPtr ctxt);
166void xmlXPathModValues(xmlXPathParserContextPtr ctxt);
167
168/*
169 * The official core of XPath functions
170 */
171void xmlXPathRoot(xmlXPathParserContextPtr ctxt);
172void xmlXPathLastFunction(xmlXPathParserContextPtr ctxt, int nargs);
173void xmlXPathPositionFunction(xmlXPathParserContextPtr ctxt, int nargs);
174void xmlXPathCountFunction(xmlXPathParserContextPtr ctxt, int nargs);
175void xmlXPathIdFunction(xmlXPathParserContextPtr ctxt, int nargs);
Daniel Veillardf6bf9212000-10-26 14:07:44 +0000176void xmlXPathLocalNameFunction(xmlXPathParserContextPtr ctxt, int nargs);
177void xmlXPathNamespaceURIFunction(xmlXPathParserContextPtr ctxt, int nargs);
Daniel Veillard29a11cc2000-10-25 13:32:39 +0000178void xmlXPathStringFunction(xmlXPathParserContextPtr ctxt, int nargs);
179void xmlXPathStringLengthFunction(xmlXPathParserContextPtr ctxt, int nargs);
180void xmlXPathConcatFunction(xmlXPathParserContextPtr ctxt, int nargs);
181void xmlXPathContainsFunction(xmlXPathParserContextPtr ctxt, int nargs);
182void xmlXPathStartsWithFunction(xmlXPathParserContextPtr ctxt, int nargs);
183void xmlXPathSubstringFunction(xmlXPathParserContextPtr ctxt, int nargs);
184void xmlXPathSubstringBeforeFunction(xmlXPathParserContextPtr ctxt, int nargs);
185void xmlXPathSubstringAfterFunction(xmlXPathParserContextPtr ctxt, int nargs);
186void xmlXPathNormalizeFunction(xmlXPathParserContextPtr ctxt, int nargs);
187void xmlXPathTranslateFunction(xmlXPathParserContextPtr ctxt, int nargs);
188void xmlXPathNotFunction(xmlXPathParserContextPtr ctxt, int nargs);
189void xmlXPathTrueFunction(xmlXPathParserContextPtr ctxt, int nargs);
190void xmlXPathFalseFunction(xmlXPathParserContextPtr ctxt, int nargs);
191void xmlXPathLangFunction(xmlXPathParserContextPtr ctxt, int nargs);
192void xmlXPathNumberFunction(xmlXPathParserContextPtr ctxt, int nargs);
193void xmlXPathSumFunction(xmlXPathParserContextPtr ctxt, int nargs);
194void xmlXPathFloorFunction(xmlXPathParserContextPtr ctxt, int nargs);
195void xmlXPathCeilingFunction(xmlXPathParserContextPtr ctxt, int nargs);
196void xmlXPathRoundFunction(xmlXPathParserContextPtr ctxt, int nargs);
197#ifdef __cplusplus
198}
199#endif
200#endif /* ! __XML_XPATH_INTERNALS_H__ */