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

📄 types.c

📁 libxml,在UNIX/LINUX下非常重要的一个库,为XML相关应用提供方便.目前上载的是最新版本,若要取得最新版本,请参考里面的readme.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * types.c: converter functions between the internal representation *          and the Python objects * * See Copyright for the status of this software. * * daniel@veillard.com */#include "libxml_wrap.h"PyObject *libxml_intWrap(int val){    PyObject *ret;#ifdef DEBUG    printf("libxml_intWrap: val = %d\n", val);#endif    ret = PyInt_FromLong((long) val);    return (ret);}PyObject *libxml_longWrap(long val){    PyObject *ret;#ifdef DEBUG    printf("libxml_longWrap: val = %ld\n", val);#endif    ret = PyInt_FromLong(val);    return (ret);}PyObject *libxml_doubleWrap(double val){    PyObject *ret;#ifdef DEBUG    printf("libxml_doubleWrap: val = %f\n", val);#endif    ret = PyFloat_FromDouble((double) val);    return (ret);}PyObject *libxml_charPtrWrap(char *str){    PyObject *ret;#ifdef DEBUG    printf("libxml_xmlcharPtrWrap: str = %s\n", str);#endif    if (str == NULL) {        Py_INCREF(Py_None);        return (Py_None);    }    /* TODO: look at deallocation */    ret = PyString_FromString(str);    xmlFree(str);    return (ret);}PyObject *libxml_charPtrConstWrap(const char *str){    PyObject *ret;#ifdef DEBUG    printf("libxml_xmlcharPtrWrap: str = %s\n", str);#endif    if (str == NULL) {        Py_INCREF(Py_None);        return (Py_None);    }    /* TODO: look at deallocation */    ret = PyString_FromString(str);    return (ret);}PyObject *libxml_xmlCharPtrWrap(xmlChar * str){    PyObject *ret;#ifdef DEBUG    printf("libxml_xmlCharPtrWrap: str = %s\n", str);#endif    if (str == NULL) {        Py_INCREF(Py_None);        return (Py_None);    }    /* TODO: look at deallocation */    ret = PyString_FromString((char *) str);    xmlFree(str);    return (ret);}PyObject *libxml_xmlCharPtrConstWrap(const xmlChar * str){    PyObject *ret;#ifdef DEBUG    printf("libxml_xmlCharPtrWrap: str = %s\n", str);#endif    if (str == NULL) {        Py_INCREF(Py_None);        return (Py_None);    }    /* TODO: look at deallocation */    ret = PyString_FromString((char *) str);    return (ret);}PyObject *libxml_constcharPtrWrap(const char *str){    PyObject *ret;#ifdef DEBUG    printf("libxml_xmlcharPtrWrap: str = %s\n", str);#endif    if (str == NULL) {        Py_INCREF(Py_None);        return (Py_None);    }    /* TODO: look at deallocation */    ret = PyString_FromString(str);    return (ret);}PyObject *libxml_constxmlCharPtrWrap(const xmlChar * str){    PyObject *ret;#ifdef DEBUG    printf("libxml_xmlCharPtrWrap: str = %s\n", str);#endif    if (str == NULL) {        Py_INCREF(Py_None);        return (Py_None);    }    /* TODO: look at deallocation */    ret = PyString_FromString((char *) str);    return (ret);}PyObject *libxml_xmlDocPtrWrap(xmlDocPtr doc){    PyObject *ret;#ifdef DEBUG    printf("libxml_xmlDocPtrWrap: doc = %p\n", doc);#endif    if (doc == NULL) {        Py_INCREF(Py_None);        return (Py_None);    }    /* TODO: look at deallocation */    ret =        PyCObject_FromVoidPtrAndDesc((void *) doc, (char *) "xmlDocPtr",                                     NULL);    return (ret);}PyObject *libxml_xmlNodePtrWrap(xmlNodePtr node){    PyObject *ret;#ifdef DEBUG    printf("libxml_xmlNodePtrWrap: node = %p\n", node);#endif    if (node == NULL) {        Py_INCREF(Py_None);        return (Py_None);    }    ret =        PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "xmlNodePtr",                                     NULL);    return (ret);}PyObject *libxml_xmlURIPtrWrap(xmlURIPtr uri){    PyObject *ret;#ifdef DEBUG    printf("libxml_xmlURIPtrWrap: uri = %p\n", uri);#endif    if (uri == NULL) {        Py_INCREF(Py_None);        return (Py_None);    }    ret =        PyCObject_FromVoidPtrAndDesc((void *) uri, (char *) "xmlURIPtr",                                     NULL);    return (ret);}PyObject *libxml_xmlNsPtrWrap(xmlNsPtr ns){    PyObject *ret;#ifdef DEBUG    printf("libxml_xmlNsPtrWrap: node = %p\n", ns);#endif    if (ns == NULL) {        Py_INCREF(Py_None);        return (Py_None);    }    ret =        PyCObject_FromVoidPtrAndDesc((void *) ns, (char *) "xmlNsPtr",                                     NULL);    return (ret);}PyObject *libxml_xmlAttrPtrWrap(xmlAttrPtr attr){    PyObject *ret;#ifdef DEBUG    printf("libxml_xmlAttrNodePtrWrap: attr = %p\n", attr);#endif    if (attr == NULL) {        Py_INCREF(Py_None);        return (Py_None);    }    ret =        PyCObject_FromVoidPtrAndDesc((void *) attr, (char *) "xmlAttrPtr",                                     NULL);    return (ret);}PyObject *libxml_xmlAttributePtrWrap(xmlAttributePtr attr){    PyObject *ret;#ifdef DEBUG    printf("libxml_xmlAttributePtrWrap: attr = %p\n", attr);#endif    if (attr == NULL) {        Py_INCREF(Py_None);        return (Py_None);    }    ret =        PyCObject_FromVoidPtrAndDesc((void *) attr,                                     (char *) "xmlAttributePtr", NULL);    return (ret);}PyObject *libxml_xmlElementPtrWrap(xmlElementPtr elem){    PyObject *ret;#ifdef DEBUG    printf("libxml_xmlElementNodePtrWrap: elem = %p\n", elem);#endif    if (elem == NULL) {        Py_INCREF(Py_None);        return (Py_None);    }    ret =        PyCObject_FromVoidPtrAndDesc((void *) elem,                                     (char *) "xmlElementPtr", NULL);    return (ret);}PyObject *libxml_xmlXPathContextPtrWrap(xmlXPathContextPtr ctxt){    PyObject *ret;#ifdef DEBUG    printf("libxml_xmlXPathContextPtrWrap: ctxt = %p\n", ctxt);#endif    if (ctxt == NULL) {        Py_INCREF(Py_None);        return (Py_None);    }    ret =        PyCObject_FromVoidPtrAndDesc((void *) ctxt,                                     (char *) "xmlXPathContextPtr", NULL);    return (ret);}PyObject *libxml_xmlXPathParserContextPtrWrap(xmlXPathParserContextPtr ctxt){    PyObject *ret;#ifdef DEBUG    printf("libxml_xmlXPathParserContextPtrWrap: ctxt = %p\n", ctxt);#endif    if (ctxt == NULL) {        Py_INCREF(Py_None);        return (Py_None);    }    ret = PyCObject_FromVoidPtrAndDesc((void *) ctxt,                                       (char *) "xmlXPathParserContextPtr",                                       NULL);    return (ret);}PyObject *libxml_xmlParserCtxtPtrWrap(xmlParserCtxtPtr ctxt){    PyObject *ret;#ifdef DEBUG    printf("libxml_xmlParserCtxtPtrWrap: ctxt = %p\n", ctxt);#endif    if (ctxt == NULL) {        Py_INCREF(Py_None);        return (Py_None);    }    ret =        PyCObject_FromVoidPtrAndDesc((void *) ctxt,                                     (char *) "xmlParserCtxtPtr", NULL);    return (ret);}PyObject *libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj){    PyObject *ret;#ifdef DEBUG    printf("libxml_xmlXPathObjectPtrWrap: ctxt = %p\n", obj);#endif    if (obj == NULL) {        Py_INCREF(Py_None);        return (Py_None);    }    switch (obj->type) {        case XPATH_XSLT_TREE: {            if ((obj->nodesetval == NULL) ||		(obj->nodesetval->nodeNr == 0) ||		(obj->nodesetval->nodeTab == NULL)) {                ret = PyList_New(0);	    } else {		int i, len = 0;		xmlNodePtr node;		node = obj->nodesetval->nodeTab[0]->children;		while (node != NULL) {		    len++;		    node = node->next;		}		ret = PyList_New(len);		node = obj->nodesetval->nodeTab[0]->children;		for (i = 0;i < len;i++) {                    PyList_SetItem(ret, i, libxml_xmlNodePtrWrap(node));		    node = node->next;		}	    }	    /*	     * Return now, do not free the object passed down	     */	    return (ret);

⌨️ 快捷键说明

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