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

📄 relaxng.c.svn-base

📁 这是一个用于解析xml文件的类库。使用这个类库
💻 SVN-BASE
📖 第 1 页 / 共 5 页
字号:
    if (grammar->next != NULL) {        xmlRelaxNGFreeGrammar(grammar->next);    }    if (grammar->refs != NULL) {        xmlHashFree(grammar->refs, NULL);    }    if (grammar->defs != NULL) {        xmlHashFree(grammar->defs, NULL);    }    xmlFree(grammar);}/** * xmlRelaxNGNewDefine: * @ctxt:  a Relax-NG validation context * @node:  the node in the input document. * * Allocate a new RelaxNG define. * * Returns the newly allocated structure or NULL in case or error */static xmlRelaxNGDefinePtrxmlRelaxNGNewDefine(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node){    xmlRelaxNGDefinePtr ret;    if (ctxt->defMax == 0) {        ctxt->defMax = 16;        ctxt->defNr = 0;        ctxt->defTab = (xmlRelaxNGDefinePtr *)            xmlMalloc(ctxt->defMax * sizeof(xmlRelaxNGDefinePtr));        if (ctxt->defTab == NULL) {            xmlRngPErrMemory(ctxt, "allocating define\n");            return (NULL);        }    } else if (ctxt->defMax <= ctxt->defNr) {        xmlRelaxNGDefinePtr *tmp;        ctxt->defMax *= 2;        tmp = (xmlRelaxNGDefinePtr *) xmlRealloc(ctxt->defTab,                                                 ctxt->defMax *                                                 sizeof                                                 (xmlRelaxNGDefinePtr));        if (tmp == NULL) {            xmlRngPErrMemory(ctxt, "allocating define\n");            return (NULL);        }        ctxt->defTab = tmp;    }    ret = (xmlRelaxNGDefinePtr) xmlMalloc(sizeof(xmlRelaxNGDefine));    if (ret == NULL) {        xmlRngPErrMemory(ctxt, "allocating define\n");        return (NULL);    }    memset(ret, 0, sizeof(xmlRelaxNGDefine));    ctxt->defTab[ctxt->defNr++] = ret;    ret->node = node;    ret->depth = -1;    return (ret);}/** * xmlRelaxNGFreePartition: * @partitions:  a partition set structure * * Deallocate RelaxNG partition set structures. */static voidxmlRelaxNGFreePartition(xmlRelaxNGPartitionPtr partitions){    xmlRelaxNGInterleaveGroupPtr group;    int j;    if (partitions != NULL) {        if (partitions->groups != NULL) {            for (j = 0; j < partitions->nbgroups; j++) {                group = partitions->groups[j];                if (group != NULL) {                    if (group->defs != NULL)                        xmlFree(group->defs);                    if (group->attrs != NULL)                        xmlFree(group->attrs);                    xmlFree(group);                }            }            xmlFree(partitions->groups);        }        if (partitions->triage != NULL) {            xmlHashFree(partitions->triage, NULL);        }        xmlFree(partitions);    }}/** * xmlRelaxNGFreeDefine: * @define:  a define structure * * Deallocate a RelaxNG define structure. */static voidxmlRelaxNGFreeDefine(xmlRelaxNGDefinePtr define){    if (define == NULL)        return;    if ((define->type == XML_RELAXNG_VALUE) && (define->attrs != NULL)) {        xmlRelaxNGTypeLibraryPtr lib;        lib = (xmlRelaxNGTypeLibraryPtr) define->data;        if ((lib != NULL) && (lib->freef != NULL))            lib->freef(lib->data, (void *) define->attrs);    }    if ((define->data != NULL) && (define->type == XML_RELAXNG_INTERLEAVE))        xmlRelaxNGFreePartition((xmlRelaxNGPartitionPtr) define->data);    if ((define->data != NULL) && (define->type == XML_RELAXNG_CHOICE))        xmlHashFree((xmlHashTablePtr) define->data, NULL);    if (define->name != NULL)        xmlFree(define->name);    if (define->ns != NULL)        xmlFree(define->ns);    if (define->value != NULL)        xmlFree(define->value);    if (define->contModel != NULL)        xmlRegFreeRegexp(define->contModel);    xmlFree(define);}/** * xmlRelaxNGNewStates: * @ctxt:  a Relax-NG validation context * @size:  the default size for the container * * Allocate a new RelaxNG validation state container * * Returns the newly allocated structure or NULL in case or error */static xmlRelaxNGStatesPtrxmlRelaxNGNewStates(xmlRelaxNGValidCtxtPtr ctxt, int size){    xmlRelaxNGStatesPtr ret;    if ((ctxt != NULL) &&        (ctxt->freeState != NULL) && (ctxt->freeStatesNr > 0)) {        ctxt->freeStatesNr--;        ret = ctxt->freeStates[ctxt->freeStatesNr];        ret->nbState = 0;        return (ret);    }    if (size < 16)        size = 16;    ret = (xmlRelaxNGStatesPtr) xmlMalloc(sizeof(xmlRelaxNGStates) +                                          (size -                                           1) *                                          sizeof(xmlRelaxNGValidStatePtr));    if (ret == NULL) {        xmlRngVErrMemory(ctxt, "allocating states\n");        return (NULL);    }    ret->nbState = 0;    ret->maxState = size;    ret->tabState = (xmlRelaxNGValidStatePtr *) xmlMalloc((size) *                                                          sizeof                                                          (xmlRelaxNGValidStatePtr));    if (ret->tabState == NULL) {        xmlRngVErrMemory(ctxt, "allocating states\n");        xmlFree(ret);        return (NULL);    }    return (ret);}/** * xmlRelaxNGAddStateUniq: * @ctxt:  a Relax-NG validation context * @states:  the states container * @state:  the validation state * * Add a RelaxNG validation state to the container without checking * for unicity. * * Return 1 in case of success and 0 if this is a duplicate and -1 on error */static intxmlRelaxNGAddStatesUniq(xmlRelaxNGValidCtxtPtr ctxt,                        xmlRelaxNGStatesPtr states,                        xmlRelaxNGValidStatePtr state){    if (state == NULL) {        return (-1);    }    if (states->nbState >= states->maxState) {        xmlRelaxNGValidStatePtr *tmp;        int size;        size = states->maxState * 2;        tmp = (xmlRelaxNGValidStatePtr *) xmlRealloc(states->tabState,                                                     (size) *                                                     sizeof                                                     (xmlRelaxNGValidStatePtr));        if (tmp == NULL) {            xmlRngVErrMemory(ctxt, "adding states\n");            return (-1);        }        states->tabState = tmp;        states->maxState = size;    }    states->tabState[states->nbState++] = state;    return (1);}/** * xmlRelaxNGAddState: * @ctxt:  a Relax-NG validation context * @states:  the states container * @state:  the validation state * * Add a RelaxNG validation state to the container * * Return 1 in case of success and 0 if this is a duplicate and -1 on error */static intxmlRelaxNGAddStates(xmlRelaxNGValidCtxtPtr ctxt,                    xmlRelaxNGStatesPtr states,                    xmlRelaxNGValidStatePtr state){    int i;    if (state == NULL) {        return (-1);    }    if (states->nbState >= states->maxState) {        xmlRelaxNGValidStatePtr *tmp;        int size;        size = states->maxState * 2;        tmp = (xmlRelaxNGValidStatePtr *) xmlRealloc(states->tabState,                                                     (size) *                                                     sizeof                                                     (xmlRelaxNGValidStatePtr));        if (tmp == NULL) {            xmlRngVErrMemory(ctxt, "adding states\n");            return (-1);        }        states->tabState = tmp;        states->maxState = size;    }    for (i = 0; i < states->nbState; i++) {        if (xmlRelaxNGEqualValidState(ctxt, state, states->tabState[i])) {            xmlRelaxNGFreeValidState(ctxt, state);            return (0);        }    }    states->tabState[states->nbState++] = state;    return (1);}/** * xmlRelaxNGFreeStates: * @ctxt:  a Relax-NG validation context * @states:  teh container * * Free a RelaxNG validation state container */static voidxmlRelaxNGFreeStates(xmlRelaxNGValidCtxtPtr ctxt,                     xmlRelaxNGStatesPtr states){    if (states == NULL)        return;    if ((ctxt != NULL) && (ctxt->freeStates == NULL)) {        ctxt->freeStatesMax = 40;        ctxt->freeStatesNr = 0;        ctxt->freeStates = (xmlRelaxNGStatesPtr *)            xmlMalloc(ctxt->freeStatesMax * sizeof(xmlRelaxNGStatesPtr));        if (ctxt->freeStates == NULL) {            xmlRngVErrMemory(ctxt, "storing states\n");        }    } else if ((ctxt != NULL)               && (ctxt->freeStatesNr >= ctxt->freeStatesMax)) {        xmlRelaxNGStatesPtr *tmp;        tmp = (xmlRelaxNGStatesPtr *) xmlRealloc(ctxt->freeStates,                                                 2 * ctxt->freeStatesMax *                                                 sizeof                                                 (xmlRelaxNGStatesPtr));        if (tmp == NULL) {            xmlRngVErrMemory(ctxt, "storing states\n");            xmlFree(states->tabState);            xmlFree(states);            return;        }        ctxt->freeStates = tmp;        ctxt->freeStatesMax *= 2;    }    if ((ctxt == NULL) || (ctxt->freeState == NULL)) {        xmlFree(states->tabState);        xmlFree(states);    } else {        ctxt->freeStates[ctxt->freeStatesNr++] = states;    }}/** * xmlRelaxNGNewValidState: * @ctxt:  a Relax-NG validation context * @node:  the current node or NULL for the document * * Allocate a new RelaxNG validation state * * Returns the newly allocated structure or NULL in case or error */static xmlRelaxNGValidStatePtrxmlRelaxNGNewValidState(xmlRelaxNGValidCtxtPtr ctxt, xmlNodePtr node){    xmlRelaxNGValidStatePtr ret;    xmlAttrPtr attr;    xmlAttrPtr attrs[MAX_ATTR];    int nbAttrs = 0;    xmlNodePtr root = NULL;    if (node == NULL) {        root = xmlDocGetRootElement(ctxt->doc);        if (root == NULL)            return (NULL);    } else {        attr = node->properties;        while (attr != NULL) {            if (nbAttrs < MAX_ATTR)                attrs[nbAttrs++] = attr;            else                nbAttrs++;            attr = attr->next;        }    }    if ((ctxt->freeState != NULL) && (ctxt->freeState->nbState > 0)) {        ctxt->freeState->nbState--;        ret = ctxt->freeState->tabState[ctxt->freeState->nbState];    } else {        ret =            (xmlRelaxNGValidStatePtr)            xmlMalloc(sizeof(xmlRelaxNGValidState));        if (ret == NULL) {            xmlRngVErrMemory(ctxt, "allocating states\n");            return (NULL);        }        memset(ret, 0, sizeof(xmlRelaxNGValidState));    }    ret->value = NULL;    ret->endvalue = NULL;    if (node == NULL) {        ret->node = (xmlNodePtr) ctxt->doc;        ret->seq = root;    } else {        ret->node = node;        ret->seq = node->children;    }    ret->nbAttrs = 0;    if (nbAttrs > 0) {        if (ret->attrs == NULL) {            if (nbAttrs < 4)                ret->maxAttrs = 4;            else                ret->maxAttrs = nbAttrs;            ret->attrs = (xmlAttrPtr *) xmlMalloc(ret->maxAttrs *                                                  sizeof(xmlAttrPtr));            if (ret->attrs == NULL) {                xmlRngVErrMemory(ctxt, "allocating states\n");                return (ret);            }        } else if (ret->maxAttrs < nbAttrs) {            xmlAttrPtr *tmp;            tmp = (xmlAttrPtr *) xmlRealloc(ret->attrs, nbAttrs *                                            sizeof(xmlAttrPtr));            if (tmp == NULL) {                xmlRngVErrMemory(ctxt, "allocating states\n");                return (ret);            }            ret->attrs = tmp;            ret->maxAttrs = nbAttrs;        }        ret->nbAttrs = nbAttrs;        if (nbAttrs < MAX_ATTR) {            memcpy(ret->attrs, attrs, sizeof(xmlAttrPtr) * nbAttrs);        } else {            attr = node->properties;            nbAttrs = 0;            while (attr != NULL) {                ret->attrs[nbAttrs++] = attr;                attr = attr->next;            }        }    }    ret->nbAttrLeft = ret->nbAttrs;    return (ret);}/** * xmlRelaxNGCopyValidState: * @ctxt:  a Relax-NG validation context * @state:  a validation state * * Copy the validation state * * Returns the newly allocated structure or NULL in case or error */static xmlRelaxNGValidStatePtrxmlRelaxNGCopyValidState(xmlRelaxNGValidCtxtPtr ctxt,                         xmlRelaxNGValidStatePtr state){    xmlRelaxNGValidStatePtr ret;    unsigned int maxAttrs;    xmlAttrPtr *attrs;    if (state == NULL)        return (NULL);    if ((ctxt->freeState != NULL) && (ctxt->freeState->nbState > 0)) {        ctxt->freeState->nbState--;        ret = ctxt->freeState->tabState[ctxt->freeState->nbState];    } else {        ret =            (xmlRelaxNGValidStatePtr)            xmlMalloc(sizeof(xmlRelaxNGValidState));

⌨️ 快捷键说明

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