⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xpath.c

📁 SIP 1.5.0源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
    if (i >= cur->nodeNr) {#ifdef DEBUG        fprintf(xmlXPathDebug, 	        "xmlXPathNodeSetDel: Node %s wasn't found in NodeList\n",		val->name);#endif        return;    }    cur->nodeNr--;    for (;i < cur->nodeNr;i++)        cur->nodeTab[i] = cur->nodeTab[i + 1];    cur->nodeTab[cur->nodeNr] = NULL;}/** * xmlXPathNodeSetRemove: * @cur:  the initial node set * @val:  the index to remove * * Removes an entry from an existing NodeSet list. */voidxmlXPathNodeSetRemove(xmlNodeSetPtr cur, int val) {    if (cur == NULL) return;    if (val >= cur->nodeNr) return;    cur->nodeNr--;    for (;val < cur->nodeNr;val++)        cur->nodeTab[val] = cur->nodeTab[val + 1];    cur->nodeTab[cur->nodeNr] = NULL;}/** * xmlXPathFreeNodeSet: * @obj:  the xmlNodeSetPtr to free * * Free the NodeSet compound (not the actual nodes !). */voidxmlXPathFreeNodeSet(xmlNodeSetPtr obj) {    if (obj == NULL) return;    if (obj->nodeTab != NULL) {#ifdef DEBUG	memset(obj->nodeTab, 0xB , (size_t) sizeof(xmlNodePtr) * obj->nodeMax);#endif	xmlFree(obj->nodeTab);    }#ifdef DEBUG    memset(obj, 0xB , (size_t) sizeof(xmlNodeSet));#endif    xmlFree(obj);}#if defined(DEBUG) || defined(DEBUG_STEP)/** * xmlXPathDebugNodeSet: * @output:  a FILE * for the output * @obj:  the xmlNodeSetPtr to free * * Quick display of a NodeSet */voidxmlXPathDebugNodeSet(FILE *output, xmlNodeSetPtr obj) {    int i;    if (output == NULL) output = xmlXPathDebug;    if (obj == NULL)  {        fprintf(output, "NodeSet == NULL !\n");	return;    }    if (obj->nodeNr == 0) {        fprintf(output, "NodeSet is empty\n");	return;    }    if (obj->nodeTab == NULL) {	fprintf(output, " nodeTab == NULL !\n");	return;    }    for (i = 0; i < obj->nodeNr; i++) {        if (obj->nodeTab[i] == NULL) {	    fprintf(output, " NULL !\n");	    return;        }	if ((obj->nodeTab[i]->type == XML_DOCUMENT_NODE) ||	    (obj->nodeTab[i]->type == XML_HTML_DOCUMENT_NODE))	    fprintf(output, " /");	else if (obj->nodeTab[i]->name == NULL)	    fprintf(output, " noname!");	else fprintf(output, " %s", obj->nodeTab[i]->name);    }    fprintf(output, "\n");}#endif/************************************************************************ *									* *			Routines to handle Variable			* *									* *			UNIMPLEMENTED CURRENTLY				* *									* ************************************************************************//** * xmlXPathVariablelookup: * @ctxt:  the XPath Parser context * @prefix:  the variable name namespace if any * @name:  the variable name * * Search in the Variable array of the context for the given * variable value. * * UNIMPLEMENTED: always return NULL. * * Returns the value or NULL if not found */xmlXPathObjectPtrxmlXPathVariablelookup(xmlXPathParserContextPtr ctxt,                       const xmlChar *prefix, const xmlChar *name) {    return(NULL);}/************************************************************************ *									* *			Routines to handle Values			* *									* ************************************************************************//* Allocations are terrible, one need to optimize all this !!! *//** * xmlXPathNewFloat: * @val:  the double value * * Create a new xmlXPathObjectPtr of type double and of value @val * * Returns the newly created object. */xmlXPathObjectPtrxmlXPathNewFloat(double val) {    xmlXPathObjectPtr ret;    ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));    if (ret == NULL) {        fprintf(xmlXPathDebug, "xmlXPathNewFloat: out of memory\n");	return(NULL);    }    memset(ret, 0 , (size_t) sizeof(xmlXPathObject));    ret->type = XPATH_NUMBER;    ret->floatval = val;    return(ret);}/** * xmlXPathNewBoolean: * @val:  the boolean value * * Create a new xmlXPathObjectPtr of type boolean and of value @val * * Returns the newly created object. */xmlXPathObjectPtrxmlXPathNewBoolean(int val) {    xmlXPathObjectPtr ret;    ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));    if (ret == NULL) {        fprintf(xmlXPathDebug, "xmlXPathNewFloat: out of memory\n");	return(NULL);    }    memset(ret, 0 , (size_t) sizeof(xmlXPathObject));    ret->type = XPATH_BOOLEAN;    ret->boolval = (val != 0);    return(ret);}/** * xmlXPathNewString: * @val:  the xmlChar * value * * Create a new xmlXPathObjectPtr of type string and of value @val * * Returns the newly created object. */xmlXPathObjectPtrxmlXPathNewString(const xmlChar *val) {    xmlXPathObjectPtr ret;    ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));    if (ret == NULL) {        fprintf(xmlXPathDebug, "xmlXPathNewFloat: out of memory\n");	return(NULL);    }    memset(ret, 0 , (size_t) sizeof(xmlXPathObject));    ret->type = XPATH_STRING;    ret->stringval = xmlStrdup(val);    return(ret);}/** * xmlXPathNewCString: * @val:  the char * value * * Create a new xmlXPathObjectPtr of type string and of value @val * * Returns the newly created object. */xmlXPathObjectPtrxmlXPathNewCString(const char *val) {    xmlXPathObjectPtr ret;    ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));    if (ret == NULL) {        fprintf(xmlXPathDebug, "xmlXPathNewFloat: out of memory\n");	return(NULL);    }    memset(ret, 0 , (size_t) sizeof(xmlXPathObject));    ret->type = XPATH_STRING;    ret->stringval = xmlStrdup(BAD_CAST val);    return(ret);}/** * xmlXPathNewNodeSet: * @val:  the NodePtr value * * Create a new xmlXPathObjectPtr of type NodeSet and initialize * it with the single Node @val * * Returns the newly created object. */xmlXPathObjectPtrxmlXPathNewNodeSet(xmlNodePtr val) {    xmlXPathObjectPtr ret;    ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));    if (ret == NULL) {        fprintf(xmlXPathDebug, "xmlXPathNewFloat: out of memory\n");	return(NULL);    }    memset(ret, 0 , (size_t) sizeof(xmlXPathObject));    ret->type = XPATH_NODESET;    ret->nodesetval = xmlXPathNodeSetCreate(val);    return(ret);}/** * xmlXPathNewNodeSetList: * @val:  an existing NodeSet * * Create a new xmlXPathObjectPtr of type NodeSet and initialize * it with the Nodeset @val * * Returns the newly created object. */xmlXPathObjectPtrxmlXPathNewNodeSetList(xmlNodeSetPtr val) {    xmlXPathObjectPtr ret;    ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));    if (ret == NULL) {        fprintf(xmlXPathDebug, "xmlXPathNewFloat: out of memory\n");	return(NULL);    }    memset(ret, 0 , (size_t) sizeof(xmlXPathObject));    ret->type = XPATH_NODESET;    ret->nodesetval = val;    return(ret);}/** * xmlXPathFreeNodeSetList: * @obj:  an existing NodeSetList object * * Free up the xmlXPathObjectPtr @obj but don't deallocate the objects in * the list contrary to xmlXPathFreeObject(). */voidxmlXPathFreeNodeSetList(xmlXPathObjectPtr obj) {    if (obj == NULL) return;#ifdef DEBUG    memset(obj, 0xB , (size_t) sizeof(xmlXPathObject));#endif    xmlFree(obj);}/** * xmlXPathFreeObject: * @obj:  the object to free * * Free up an xmlXPathObjectPtr object. */voidxmlXPathFreeObject(xmlXPathObjectPtr obj) {    if (obj == NULL) return;    if (obj->nodesetval != NULL)        xmlXPathFreeNodeSet(obj->nodesetval);    if (obj->stringval != NULL)        xmlFree(obj->stringval);#ifdef DEBUG    memset(obj, 0xB , (size_t) sizeof(xmlXPathObject));#endif    xmlFree(obj);}/************************************************************************ *									* *		Routines to handle XPath contexts			* *									* ************************************************************************//** * xmlXPathNewContext: * @doc:  the XML document * * Create a new xmlXPathContext * * Returns the xmlXPathContext just allocated. */xmlXPathContextPtrxmlXPathNewContext(xmlDocPtr doc) {    xmlXPathContextPtr ret;    ret = (xmlXPathContextPtr) xmlMalloc(sizeof(xmlXPathContext));    if (ret == NULL) {        fprintf(xmlXPathDebug, "xmlXPathNewContext: out of memory\n");	return(NULL);    }    memset(ret, 0 , (size_t) sizeof(xmlXPathContext));    ret->doc = doc; /***********       ret->node = (xmlNodePtr) doc;    ret->nodelist = xmlXPathNodeSetCreate(ret->node);  ***********/      ret->node = NULL;    ret->nodelist = NULL;    ret->nb_variables = 0;    ret->max_variables = 0;    ret->variables = NULL;    ret->nb_types = 0;    ret->max_types = 0;    ret->types = NULL;    ret->nb_funcs = 0;    ret->max_funcs = 0;    ret->funcs = NULL;    ret->nb_axis = 0;    ret->max_axis = 0;    ret->axis = NULL;    ret->namespaces = NULL;    ret->user = NULL;    ret->nsNr = 0;    return(ret);}/** * xmlXPathFreeContext: * @ctxt:  the context to free * * Free up an xmlXPathContext */voidxmlXPathFreeContext(xmlXPathContextPtr ctxt) {    if (ctxt->namespaces != NULL)        xmlFree(ctxt->namespaces); /***********       if (ctxt->nodelist != NULL)         xmlXPathFreeNodeSet(ctxt->nodelist);  ***********/  #ifdef DEBUG    memset(ctxt, 0xB , (size_t) sizeof(xmlXPathContext));#endif    xmlFree(ctxt);}/************************************************************************ *									* *		Routines to handle XPath parser contexts		* *									* ************************************************************************/#define CHECK_CTXT							\    if (ctxt == NULL) { 						\        fprintf(xmlXPathDebug, "%s:%d Internal error: ctxt == NULL\n",	\	        __FILE__, __LINE__);					\    }									\#define CHECK_CONTEXT							\    if (ctxt == NULL) { 						\        fprintf(xmlXPathDebug, "%s:%d Internal error: no context\n",	\	        __FILE__, __LINE__);					\    }									\    if (ctxt->doc == NULL) { 						\        fprintf(xmlXPathDebug, "%s:%d Internal error: no document\n",	\	        __FILE__, __LINE__);					\    }									\    if (ctxt->doc->children == NULL) { 					\        fprintf(xmlXPathDebug,						\	        "%s:%d Internal error: document without root\n",	\	        __FILE__, __LINE__);					\    }									\/** * xmlXPathNewParserContext: * @str:  the XPath expression * @ctxt:  the XPath context * * Create a new xmlXPathParserContext * * Returns the xmlXPathParserContext just allocated. */xmlXPathParserContextPtrxmlXPathNewParserContext(const xmlChar *str, xmlXPathContextPtr ctxt) {    xmlXPathParserContextPtr ret;    ret = (xmlXPathParserContextPtr) xmlMalloc(sizeof(xmlXPathParserContext));    if (ret == NULL) {        fprintf(xmlXPathDebug, "xmlXPathNewParserContext: out of memory\n");	return(NULL);    }    memset(ret, 0 , (size_t) sizeof(xmlXPathParserContext));    ret->cur = ret->base = str;    ret->context = ctxt;    /* Allocate the value stack */    ret->valueTab = (xmlXPathObjectPtr *)                      xmlMalloc(10 * sizeof(xmlXPathObjectPtr));    ret->valueNr = 0;    ret->valueMax = 10;    ret->value = NULL;    return(ret);}/** * xmlXPathFreeParserContext: * @ctxt:  the context to free * * Free up an xmlXPathParserContext */voidxmlXPathFreeParserContext(xmlXPathParserContextPtr ctxt) {    if (ctxt->valueTab != NULL) {#ifdef DEBUG        memset(ctxt->valueTab, 0xB , 10 * (size_t) sizeof(xmlXPathObjectPtr));#endif        xmlFree(ctxt->valueTab);    }#ifdef DEBUG    memset(ctxt, 0xB , (size_t) sizeof(xmlXPathParserContext));#endif    xmlFree(ctxt);}/************************************************************************ *									* *		The implicit core function library			* *									* ************************************************************************//* * Auto-pop and cast to a number */void xmlXPathNumberFunction(xmlXPathParserContextPtr ctxt, int nargs);#define CHECK_ARITY(x)						\    if (nargs != (x)) {						\        ERROR(XPATH_INVALID_ARITY);				\    }								\#define POP_FLOAT						\    arg = valuePop(ctxt);					\    if (arg == NULL) {						\	ERROR(XPATH_INVALID_OPERAND);				\    }								\    if (arg->type != XPATH_NUMBER) {				\

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -