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