rngparser.c
来自「图片显示,电脑光于望技术湖连望键往,网络」· C语言 代码 · 共 1,594 行 · 第 1/4 页
C
1,594 行
* * Returns -1 in case of error and 0 otherwise */static intxmlParseCRNGDropTokens(xmlCRelaxNGParserCtxtPtr ctxt, int nr) { if ((nr <= 0) || (nr >= MAX_TOKEN)) return(-1); while ((ctxt->nbTokens >0) && (nr > 0)) { ctxt->firstToken++; nr--; ctxt->nbTokens--; ctxt->totalToken++; if (ctxt->totalToken == 384) fprintf(stderr, "found\n"); } ctxt->firstToken = ctxt->firstToken % MAX_TOKEN; return(0);}static voidxmlParseCRNGTokenize(xmlCRelaxNGParserCtxtPtr ctxt) { tokenPtr token; token = xmlParseCRNGGetToken(ctxt, 1); while (token != NULL) { switch (token->toktype) { case CRNG_NONE: printf("none"); break; case CRNG_OP: printf("op"); break; case CRNG_KEYWORD: printf("keyword"); break; case CRNG_IDENTIFIER: printf("identifier"); break; case CRNG_LITERAL_SEGMENT: printf("literal"); break; case CRNG_CNAME: printf("cname"); break; case CRNG_QNAME: printf("qname"); break; case CRNG_NSNAME: printf("nsname"); break; case CRNG_DOCUMENTATION: printf("doc"); break; } printf(":%s\n", token->token); xmlParseCRNGDropTokens(ctxt, 1); token = xmlParseCRNGGetToken(ctxt, 1); }}/** * xmlParseCRNG_attribute: * @ctxt: a compact RNG parser context * @name: the attribute name * @ns: the attribute namespace * @value: the attribute value * * implements attribute of the RELAX NG Compact Syntax Appendix A * * Returns 0 in case of success and -1 in case of error */static intxmlParseCRNG_attribute(xmlCRelaxNGParserCtxtPtr ctxt, const xmlChar *name, xmlNsPtr ns, const xmlChar *value){ xmlAttrPtr attr; attr = xmlNewNsPropEatName(NULL, ns, (xmlChar *) name, value); if (attr == NULL) CRNG_MEM_ERROR0(); attr->next = ctxt->attrs; if (ctxt->attrs != NULL) ctxt->attrs->prev = attr; ctxt->attrs = attr; return(0);}/** * xmlParseCRNG_bindPrefix: * @ctxt: a compact RNG parser context * @prefix: the namespace prefix or NULL * @namespace: the namespace name * * implements bindPrefix of the RELAX NG Compact Syntax Appendix A * * Returns 0 in case of success and -1 in case of error */static intxmlParseCRNG_bindPrefix(xmlCRelaxNGParserCtxtPtr ctxt, const xmlChar *prefix, const xmlChar *namespace){ int ret; if ((prefix != NULL) && (xmlStrEqual(prefix, BAD_CAST "xml")) && (!xmlStrEqual(namespace, XML_XML_NAMESPACE))) { ERROR("The \"xml\" prefix must be bound to \"http://www.w3.org/XML/1998/namespace\""); return(-1); } else if ((xmlStrEqual(namespace, XML_XML_NAMESPACE)) && (!xmlStrEqual(prefix, BAD_CAST "xml"))) { ERROR("The \"http://www.w3.org/XML/1998/namespace\" name must be bound to \"xml\" prefix"); return(-1); } if (ctxt->namespaces == NULL) ctxt->namespaces = xmlHashCreate(10); if (ctxt->namespaces == NULL) { ERROR("Failed to create namespace hash table"); return(-1); } if (prefix == NULL) ret = xmlHashAddEntry(ctxt->namespaces, xmlCRelaxNGDefault, (void *) namespace); else ret = xmlHashAddEntry(ctxt->namespaces, prefix, (void *) namespace); if (ret < 0) { if (prefix == NULL) { ERROR("Redefinition of default namespace"); } else { ERROR("Redefinition of namespace"); } return(-1); } return(0);}/** * xmlParseCRNG_bindDatatypePrefix: * @ctxt: a compact RNG parser context * @prefix: the datatype prefix * @namespace: the datatype identifier * * implements bindDatatypePrefix of the RELAX NG Compact Syntax Appendix A * * Returns 0 in case of success and -1 in case of error */static intxmlParseCRNG_bindDatatypePrefix(xmlCRelaxNGParserCtxtPtr ctxt ATTRIBUTE_UNUSED, const xmlChar *prefix, const xmlChar *namespace){ int ret; if ((prefix != NULL) && (xmlStrEqual(prefix, BAD_CAST "xsd")) && (!xmlStrEqual(namespace, BAD_CAST "http://www.w3.org/2001/XMLSchema-datatypes"))) { ERROR("The \"xsd\" prefix must be bound to \"http://www.w3.org/2001/XMLSchema-datatypes\""); return(-1); } if (ctxt->datatypes == NULL) ctxt->datatypes = xmlHashCreate(10); if (ctxt->datatypes == NULL) { ERROR("Failed to create namespace hash table"); return(-1); } ret = xmlHashAddEntry(ctxt->datatypes, prefix, (void *) namespace); if (ret < 0) { ERROR("Redefinition of datatype"); return(-1); } return(0);}/** * xmlParseCRNG_lookupPrefix: * @ctxt: a compact RNG parser context * @prefix: the namespace prefix or NULL * * implements lookupPrefix of the RELAX NG Compact Syntax Appendix A * * Returns the prefix in case of success or NULL in case of error */static const xmlChar *xmlParseCRNG_lookupPrefix(xmlCRelaxNGParserCtxtPtr ctxt ATTRIBUTE_UNUSED, const xmlChar *prefix){ const xmlChar *ret; if (prefix == NULL) ret = xmlHashLookup(ctxt->namespaces, xmlCRelaxNGDefault); else ret = xmlHashLookup(ctxt->namespaces, prefix); return(ret);}/** * xmlParseCRNG_lookupDatatypePrefix: * @ctxt: a compact RNG parser context * @prefix: the namespace prefix or NULL * * implements lookupDatatypePrefix of the RELAX NG Compact Syntax Appendix A * * Returns the prefix in case of success or NULL in case of error */static const xmlChar *xmlParseCRNG_lookupDatatypePrefix(xmlCRelaxNGParserCtxtPtr ctxt ATTRIBUTE_UNUSED, const xmlChar *prefix){ const xmlChar *ret; ret = xmlHashLookup(ctxt->datatypes, prefix); return(ret);}/** * xmlParseCRNG_datatypeAttributes: * @ctxt: a compact RNG parser context * @prefix: the namespace prefix or NULL * * implements lookupPrefix of the RELAX NG Compact Syntax Appendix A * * Returns the prefix in case of success or NULL in case of error */static xmlAttrPtrxmlParseCRNG_datatypeAttributes(xmlCRelaxNGParserCtxtPtr ctxt ATTRIBUTE_UNUSED, const xmlChar *library, const xmlChar *type){ xmlAttrPtr lib, typ; lib = xmlNewNsProp(NULL, NULL, BAD_CAST "datatypeLibrary", library); if (lib == NULL) { CRNG_MEM_ERROR(); return(NULL); } typ = xmlNewNsProp(NULL, NULL, BAD_CAST "type", type); if (typ == NULL) { CRNG_MEM_ERROR(); return(lib); } lib->next = typ; return(lib);}/** * xmlParseCRNG_XXX: * @ctxt: a compact RNG parser context * * Parse XXX of the RELAX NG Compact Syntax Appendix A * * Returns 0 in case of success and -1 in case of error */static intxmlParseCRNG_XXX(xmlCRelaxNGParserCtxtPtr ctxt ATTRIBUTE_UNUSED){ return(0);}static int xmlParseCRNG_pattern(xmlCRelaxNGParserCtxtPtr ctxt);static int xmlParseCRNG_nameClass(xmlCRelaxNGParserCtxtPtr ctxt);/** * xmlParseCRNG_params: * @ctxt: a compact RNG parser context * * Parse params of the RELAX NG Compact Syntax Appendix A * * Returns 0 in case of success and -1 in case of error */static intxmlParseCRNG_params(xmlCRelaxNGParserCtxtPtr ctxt ATTRIBUTE_UNUSED){ TODO return(0);}/** * xmlParseCRNG_exceptNameClass: * @ctxt: a compact RNG parser context * * Parse exceptNameClass of the RELAX NG Compact Syntax Appendix A * * Returns 0 in case of success and -1 in case of error */static intxmlParseCRNG_exceptNameClass(xmlCRelaxNGParserCtxtPtr ctxt ATTRIBUTE_UNUSED){ tokenPtr token; xmlNodePtr insert = ctxt->insert, cur; token = xmlParseCRNGGetToken(ctxt, 1); if ((token->toktype == CRNG_OP) && (token->token[0] == '-') && (token->token[1] == 0)) { xmlParseCRNGDropTokens(ctxt, 1); cur = xmlNewNode(NULL, BAD_CAST "except"); if (cur == NULL) CRNG_MEM_ERROR0(); if (ctxt->insert != NULL) xmlAddChild(ctxt->insert, cur); ctxt->insert = cur; xmlParseCRNG_nameClass(ctxt); } ctxt->insert = insert; return(0);}/** * xmlParseCRNG_innerNameClass: * @ctxt: a compact RNG parser context * * Parse innerNameClass of the RELAX NG Compact Syntax Appendix A * * Returns 0 in case of success and -1 in case of error */static intxmlParseCRNG_innerNameClass(xmlCRelaxNGParserCtxtPtr ctxt){ tokenPtr token; xmlNodePtr cur; token = xmlParseCRNGGetToken(ctxt, 1); if (token->toktype == CRNG_OP) { if ((token->token[0] == '(') && (token->token[1] == 0)) { xmlParseCRNGDropTokens(ctxt, 1); xmlParseCRNG_nameClass(ctxt); token = xmlParseCRNGGetToken(ctxt, 1); if ((token->toktype != CRNG_OP) || (token->token[0] != ')') || (token->token[1] != 0)) { ERROR("Expecting \")\" here"); } xmlParseCRNGDropTokens(ctxt, 1); } else if ((token->token[0] == '*') && (token->token[1] == 0)) { xmlParseCRNGDropTokens(ctxt, 1); cur = xmlNewNode(NULL, BAD_CAST "anyName"); if (cur == NULL) CRNG_MEM_ERROR0(); if (ctxt->insert != NULL) xmlAddChild(ctxt->insert, cur); ctxt->insert = cur; xmlParseCRNG_exceptNameClass(ctxt); } else { TODO } } else if ((token->toktype == CRNG_IDENTIFIER) || (token->toktype == CRNG_KEYWORD)) { cur = xmlNewNode(NULL, BAD_CAST "name"); if (cur == NULL) CRNG_MEM_ERROR0(); if (ctxt->isElem) { xmlSetProp(cur, BAD_CAST "ns", xmlParseCRNG_lookupPrefix(ctxt, NULL)); } else { xmlSetProp(cur, BAD_CAST "ns", BAD_CAST ""); } xmlNodeAddContent(cur, token->token); if (ctxt->insert != NULL) xmlAddChild(ctxt->insert, cur); ctxt->insert = cur; xmlParseCRNGDropTokens(ctxt, 1); } else if (token->toktype == CRNG_CNAME) { TODO } else if (token->toktype == CRNG_NSNAME) { cur = xmlNewNode(NULL, BAD_CAST "nsName"); if (cur == NULL) CRNG_MEM_ERROR0(); xmlSetProp(cur, BAD_CAST "ns", xmlParseCRNG_lookupPrefix(ctxt, token->token)); if (ctxt->insert != NULL) xmlAddChild(ctxt->insert, cur); ctxt->insert = cur; xmlParseCRNGDropTokens(ctxt, 1); xmlParseCRNG_exceptNameClass(ctxt); } else { TODO /* probably an error */ } return(0);}/** * xmlParseCRNG_nameClass: * @ctxt: a compact RNG parser context * * Parse nameClass of the RELAX NG Compact Syntax Appendix A * * Returns 0 in case of success and -1 in case of error */static intxmlParseCRNG_nameClass(xmlCRelaxNGParserCtxtPtr ctxt){ tokenPtr token; xmlNodePtr insert = ctxt->insert, last, choice; ctxt->insert = NULL; xmlParseCRNG_innerNameClass(ctxt); last = ctxt->insert; token = xmlParseCRNGGetToken(ctxt, 1); while ((token->toktype == CRNG_OP) && (token->token[0] == '|') && (token->token[1] == 0)) { choice = xmlNewNodeEatName(NULL, (xmlChar *) ctxt->key_choice); xmlParseCRNGDropTokens(ctxt, 1); if (choice == NULL) CRNG_MEM_ERROR0(); ctxt->insert = NULL; xmlParseCRNG_innerNameClass(ctxt); xmlAddChild(choice, last); xmlAddChild(choice, ctxt->insert); last = choice; token = xmlParseCRNGGetToken(ctxt, 1); } xmlAddChild(insert, last); ctxt->insert = insert; return(0);}/** * xmlParseCRNG_patternBlock: * @ctxt: a compact RNG parser context * * Parse a pattern block of the RELAX NG Compact Syntax Appendix A
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?