From 6be79014d7d957f1d73eee251ef0443a37481f16 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Mon, 15 Jul 2024 14:18:26 +0200 Subject: [PATCH] Remove unused code --- debugXML.c | 6 - doc/apibuild.py | 1 - nanohttp.c | 34 - parser.c | 5 - pattern.c | 144 ----- rngparser.c | 1588 ----------------------------------------------- schematron.c | 43 -- valid.c | 31 +- xinclude.c | 5 - xmlreader.c | 269 -------- xmlregexp.c | 153 ----- xmlwriter.c | 7 +- xpath.c | 121 ---- 13 files changed, 5 insertions(+), 2402 deletions(-) delete mode 100644 rngparser.c diff --git a/debugXML.c b/debugXML.c index 6ac33b94..f5ffe60c 100644 --- a/debugXML.c +++ b/debugXML.c @@ -267,12 +267,6 @@ xmlCtxtGenericNodeCheck(xmlDebugCtxtPtr ctxt, xmlNodePtr node) { } else { dict = doc->dict; if ((dict == NULL) && (ctxt->nodict == 0)) { -#if 0 - /* deactivated right now as it raises too many errors */ - if (doc->type == XML_DOCUMENT_NODE) - xmlDebugErr(ctxt, XML_CHECK_NO_DICT, - "Document has no dictionary\n"); -#endif ctxt->nodict = 1; } if (ctxt->doc == NULL) diff --git a/doc/apibuild.py b/doc/apibuild.py index 0bc7edbd..a59b39d8 100755 --- a/doc/apibuild.py +++ b/doc/apibuild.py @@ -21,7 +21,6 @@ debugsym=None ignored_files = { "config.h": "generated portability layer", "libxml.h": "internal only", - "rngparser.c": "not yet integrated", "testModule.c": "test tool", "testapi.c": "generated regression tests", "runtest.c": "regression tests program", diff --git a/nanohttp.c b/nanohttp.c index 21aabafc..e8c73c07 100644 --- a/nanohttp.c +++ b/nanohttp.c @@ -90,11 +90,6 @@ #define GETHOSTBYNAME_ARG_CAST (char *) #define SEND_ARG2_CAST (char *) -#ifdef STANDALONE -#define xmlStrncasecmp(a, b, n) strncasecmp((char *)a, (char *)b, n) -#define xmlStrcasecmpi(a, b) strcasecmp((char *)a, (char *)b) -#endif - #define XML_NANO_HTTP_MAX_REDIR 10 #define XML_NANO_HTTP_CHUNK 4096 @@ -1825,33 +1820,4 @@ xmlNanoHTTPFetchContent( void * ctx, char ** ptr, int * len ) { return ( rc ); } -#ifdef STANDALONE -int main(int argc, char **argv) { - char *contentType = NULL; - - if (argv[1] != NULL) { - if (argv[2] != NULL) - xmlNanoHTTPFetch(argv[1], argv[2], &contentType); - else - xmlNanoHTTPFetch(argv[1], "-", &contentType); - if (contentType != NULL) xmlFree(contentType); - } else { - fprintf(stderr, - "%s: minimal HTTP GET implementation\n", argv[0]); - fprintf(stderr, - "\tusage %s [ URL [ filename ] ]\n", argv[0]); - } - xmlNanoHTTPCleanup(); - return(0); -} -#endif /* STANDALONE */ -#else /* !LIBXML_HTTP_ENABLED */ -#ifdef STANDALONE -#include -int main(int argc, char **argv) { - fprintf(stderr, - "%s : HTTP support not compiled in\n", argv[0]); - return(0); -} -#endif /* STANDALONE */ #endif /* LIBXML_HTTP_ENABLED */ diff --git a/parser.c b/parser.c index 14562bbb..e52392ce 100644 --- a/parser.c +++ b/parser.c @@ -13405,11 +13405,6 @@ xmlCtxtReset(xmlParserCtxtPtr ctxt) ctxt->nsWellFormed = 1; ctxt->disableSAX = 0; ctxt->valid = 1; -#if 0 - ctxt->vctxt.userData = ctxt; - ctxt->vctxt.error = xmlParserValidityError; - ctxt->vctxt.warning = xmlParserValidityWarning; -#endif ctxt->record_info = 0; ctxt->checkIndex = 0; ctxt->endCheckState = 0; diff --git a/pattern.c b/pattern.c index e969a1ef..42b20fe6 100644 --- a/pattern.c +++ b/pattern.c @@ -367,35 +367,6 @@ xmlPatternAdd(xmlPatParserContextPtr ctxt, xmlPatternPtr comp, return (0); } -#if 0 -/** - * xsltSwapTopPattern: - * @comp: the compiled match expression - * - * reverse the two top steps. - */ -static void -xsltSwapTopPattern(xmlPatternPtr comp) { - int i; - int j = comp->nbStep - 1; - - if (j > 0) { - register const xmlChar *tmp; - register xmlPatOp op; - i = j - 1; - tmp = comp->steps[i].value; - comp->steps[i].value = comp->steps[j].value; - comp->steps[j].value = tmp; - tmp = comp->steps[i].value2; - comp->steps[i].value2 = comp->steps[j].value2; - comp->steps[j].value2 = tmp; - op = comp->steps[i].op; - comp->steps[i].op = comp->steps[j].op; - comp->steps[j].op = op; - } -} -#endif - /** * xmlReversePattern: * @comp: the compiled match expression @@ -479,9 +450,6 @@ xmlPatPushState(xmlStepStates *states, int step, xmlNodePtr node) { } states->states[states->nbstates].step = step; states->states[states->nbstates++].node = node; -#if 0 - fprintf(stderr, "Push: %d, %s\n", step, node->name); -#endif return(0); } @@ -685,9 +653,6 @@ rollback: states.nbstates--; i = states.states[states.nbstates].step; node = states.states[states.nbstates].node; -#if 0 - fprintf(stderr, "Pop: %d, %s\n", i, node->name); -#endif goto restart; } @@ -713,73 +678,6 @@ rollback: #define PUSH(op, val, val2) \ if (xmlPatternAdd(ctxt, ctxt->comp, (op), (val), (val2))) goto error; -#if 0 -/** - * xmlPatScanLiteral: - * @ctxt: the XPath Parser context - * - * Parse an XPath Literal: - * - * [29] Literal ::= '"' [^"]* '"' - * | "'" [^']* "'" - * - * Returns the Literal parsed or NULL - */ - -static xmlChar * -xmlPatScanLiteral(xmlPatParserContextPtr ctxt) { - const xmlChar *q, *cur; - xmlChar *ret = NULL; - int val, len; - - SKIP_BLANKS; - if (CUR == '"') { - NEXT; - cur = q = CUR_PTR; - val = xmlStringCurrentChar(NULL, cur, &len); - while ((IS_CHAR(val)) && (val != '"')) { - cur += len; - val = xmlStringCurrentChar(NULL, cur, &len); - } - if (!IS_CHAR(val)) { - ctxt->error = 1; - return(NULL); - } else { - if (ctxt->dict) - ret = (xmlChar *) xmlDictLookup(ctxt->dict, q, cur - q); - else - ret = xmlStrndup(q, cur - q); - } - cur += len; - CUR_PTR = cur; - } else if (CUR == '\'') { - NEXT; - cur = q = CUR_PTR; - val = xmlStringCurrentChar(NULL, cur, &len); - while ((IS_CHAR(val)) && (val != '\'')) { - cur += len; - val = xmlStringCurrentChar(NULL, cur, &len); - } - if (!IS_CHAR(val)) { - ctxt->error = 1; - return(NULL); - } else { - if (ctxt->dict) - ret = (xmlChar *) xmlDictLookup(ctxt->dict, q, cur - q); - else - ret = xmlStrndup(q, cur - q); - } - cur += len; - CUR_PTR = cur; - } else { - /* XP_ERROR(XPATH_START_LITERAL_ERROR); */ - ctxt->error = 1; - return(NULL); - } - return(ret); -} -#endif - /** * xmlPatScanName: * @ctxt: the XPath Parser context @@ -863,32 +761,6 @@ xmlPatScanNCName(xmlPatParserContextPtr ctxt) { return(ret); } -#if 0 -/** - * xmlPatScanQName: - * @ctxt: the XPath Parser context - * @prefix: the place to store the prefix - * - * Parse a qualified name - * - * Returns the Name parsed or NULL - */ - -static xmlChar * -xmlPatScanQName(xmlPatParserContextPtr ctxt, xmlChar **prefix) { - xmlChar *ret = NULL; - - *prefix = NULL; - ret = xmlPatScanNCName(ctxt); - if (CUR == ':') { - *prefix = ret; - NEXT; - ret = xmlPatScanNCName(ctxt); - } - return(ret); -} -#endif - /** * xmlCompileAttributeTest: * @ctxt: the compilation context @@ -1950,22 +1822,6 @@ xmlStreamPushInternal(xmlStreamCtxtPtr stream, { match = 1; } -#if 0 -/* -* TODO: Pointer comparison won't work, since not guaranteed that the given -* values are in the same dict; especially if it's the namespace name, -* normally coming from ns->href. We need a namespace dict mechanism ! -*/ - } else if (comp->dict) { - if (step.name == NULL) { - if (step.ns == NULL) - match = 1; - else - match = (step.ns == ns); - } else { - match = ((step.name == name) && (step.ns == ns)); - } -#endif /* if 0 ------------------------------------------------------- */ if (match) { final = step.flags & XML_STREAM_STEP_FINAL; if (final) { diff --git a/rngparser.c b/rngparser.c deleted file mode 100644 index 799a60e6..00000000 --- a/rngparser.c +++ /dev/null @@ -1,1588 +0,0 @@ -/** - * rngparser.c: parser for the Relax-NG compact syntax. - * - * Based on: - * RELAX NG Compact Syntax - * Committee Specification 21 November 2002 - * http://www.oasis-open.org/committees/relax-ng/compact-20021121.html - * - * See Copyright for the status of this software. - * - * Daniel Veillard - */ - -#include - -#include -#include -#include -#include - -#define MAX_TOKEN 10 - -typedef enum { - CRNG_NONE = 0, - CRNG_OP = 1, - CRNG_KEYWORD, - CRNG_IDENTIFIER, - CRNG_LITERAL_SEGMENT, - CRNG_CNAME, - CRNG_QNAME, - CRNG_NSNAME, - CRNG_DOCUMENTATION -} xmlCRNGTokType; - -typedef enum { - CRNG_OKAY = 0, - CRNG_MEMORY_ERROR, - CRNG_INVALID_CHAR_ERROR, - CRNG_END_ERROR, - CRNG_ENCODING_ERROR -} xmlCRNGError; - -typedef enum { - XML_CRNG_ERROR = -1, - XML_CRNG_OK = 0, - XML_CRNG_EOF = 1 -} xmlCRelaxNGParserState; - -typedef struct _token _token; -typedef _token *tokenPtr; -struct _token { - xmlCRNGTokType toktype; - int toklen; - const xmlChar *token; - const xmlChar *prefix; -}; - -typedef struct _xmlCRelaxNGParserCtxt xmlCRelaxNGParserCtxt; -typedef xmlCRelaxNGParserCtxt *xmlCRelaxNGParserCtxtPtr; -struct _xmlCRelaxNGParserCtxt { - void *userData; /* user specific data block */ - xmlRelaxNGValidityErrorFunc error; /* the callback in case of errors */ - xmlRelaxNGValidityWarningFunc warning;/* the callback in case of warning */ - xmlRelaxNGValidErr err; - - const xmlChar *compact; - const xmlChar *end; - const xmlChar *cur; - int isElem; - int lineno; - const xmlChar *linestart; - const char *filename; - - int nbTokens; - int firstToken; - _token tokens[MAX_TOKEN]; - int totalToken; - - xmlCRelaxNGParserState state; - - int nbErrors; - - xmlDocPtr res; /* the result */ - xmlNodePtr ins; /* the current insertion node */ - - xmlNsPtr nsDef; - tokenPtr token; - - xmlHashTablePtr namespaces; - xmlHashTablePtr datatypes; - - /* - * dictionary and keywords - */ - xmlDictPtr dict; - const xmlChar *key_attribute; - const xmlChar *key_default; - const xmlChar *key_datatypes; - const xmlChar *key_div; - const xmlChar *key_element; - const xmlChar *key_empty; - const xmlChar *key_external; - const xmlChar *key_grammar; - const xmlChar *key_include; - const xmlChar *key_inherit; - const xmlChar *key_list; - const xmlChar *key_mixed; - const xmlChar *key_namespace; - const xmlChar *key_notAllowed; - const xmlChar *key_parent; - const xmlChar *key_start; - const xmlChar *key_string; - const xmlChar *key_text; - const xmlChar *key_token; - const xmlChar *key_equal; - const xmlChar *key_orequal; - const xmlChar *key_andequal; - const xmlChar *key_combine; - const xmlChar *key_or; - const xmlChar *key_comma; - const xmlChar *key_and; - const xmlChar *key_choice; - const xmlChar *key_group; - const xmlChar *key_interleave; - const xmlChar *key_ref; - const xmlChar *key_define; - - /* results */ - xmlDocPtr doc; /* the resulting doc */ - xmlNodePtr insert; /* the insertion point */ - xmlAttrPtr attrs; /* pending attributes */ -}; - -static const xmlChar *xmlCRelaxNGInherit = BAD_CAST "Inherit string"; -static const xmlChar *xmlCRelaxNGDefault = BAD_CAST "Default string"; - -#define CUR_CHAR(l) xmlXPathCurrentChar(ctxt, &l) -/** - * IS_BLANK: - * @c: an UNICODE value (int) - * - * Macro to check the following production in the XML spec: - * - * [3] S ::= (#x20 | #x9 | #xD | #xA)+ - */ -#ifndef IS_BLANK -#define IS_BLANK(c) (((c) == 0x20) || ((c) == 0x09) || ((c) == 0xA) || \ - ((c) == 0x0D)) -#endif -#define IS_SEPARATOR(c) (((c) == 0x20) || ((c) == 0x09) || ((c) == 0xA) || \ - ((c) == 0x0D) || (c == '#')) - -#define CRNG_ERROR0(X) \ - { xmlCRNGErr(ctxt, X, NULL); return(0); } -#define CRNG_ERROR(X) \ - { xmlCRNGErr(ctxt, X, NULL); } - -#define CRNG_MEM_ERROR0() \ - { xmlCRNGErr(ctxt, CRNG_MEMORY_ERROR, NULL); return(0); } -#define CRNG_MEM_ERROR() \ - { xmlCRNGErr(ctxt, CRNG_MEMORY_ERROR, NULL); } - -#define ERROR(str) xmlCRNGErr(ctxt, 0, str); - -static void -xmlCRNGErr(xmlCRelaxNGParserCtxtPtr ctxt, int err_no, const char *err_msg) { - const xmlChar *cur; - xmlChar buffer[150]; - int i, l; - - if (ctxt != NULL) { - if (ctxt->filename != NULL) - fprintf(stderr, "%s:%d ", ctxt->filename, ctxt->lineno); - } - if (err_msg != NULL) { - fprintf(stderr, "error: %s\n", err_msg); - } else if (err_no != 0) - fprintf(stderr, "error %d\n", err_no); - cur = ctxt->cur; - while ((*cur != '\n') && (*cur != '\r') && (ctxt->cur - cur < 80)) cur--; - l = ctxt->cur - cur; - cur++; - for (i = 0; i < 100;i++) { - if ((*cur == '\n') || (*cur == '\r')) break; - buffer[i] = *cur++; - } - buffer[i] = 0; - fprintf(stderr, "%s\n", buffer); - for (i = 0; i < l;i++) buffer[i] = ' '; - buffer[i++] = '^'; - buffer[i++] = 0; - fprintf(stderr, "%s\n", buffer); -} - -/** - * IS_OP - * @c: an UNICODE value (int) - * - * Macro to check for operator value - */ -#ifndef IS_OP -#define IS_OP(c) (((c) == ',') || ((c) == '&') || ((c) == '|') || \ - ((c) == '?') || ((c) == '-') || ((c) == '*') || \ - ((c) == '{') || ((c) == '}') || ((c) == '(') || \ - ((c) == ')') || ((c) == '+') || ((c) == '=') || \ - ((c) == ':')) -#endif - -static int -xmlCRNGIsKeyword(xmlCRelaxNGParserCtxtPtr ctxt, const xmlChar *str) { - if ((str == ctxt->key_attribute) || - (str == ctxt->key_default) || - (str == ctxt->key_datatypes) || - (str == ctxt->key_div) || - (str == ctxt->key_element) || - (str == ctxt->key_empty) || - (str == ctxt->key_external) || - (str == ctxt->key_grammar) || - (str == ctxt->key_include) || - (str == ctxt->key_inherit) || - (str == ctxt->key_list) || - (str == ctxt->key_mixed) || - (str == ctxt->key_namespace) || - (str == ctxt->key_notAllowed) || - (str == ctxt->key_parent) || - (str == ctxt->key_start) || - (str == ctxt->key_string) || - (str == ctxt->key_text) || - (str == ctxt->key_token)) - return(1); - return(0); - -} - -/* - * xmlCRNGNextToken: - * ctxt: a compact RNG parser context - * - * Scan the schema to get the next token - * - * Return 0 if success and -1 in case of error - */ - -static int -xmlCRNGNextToken(xmlCRelaxNGParserCtxtPtr ctxt) { - const xmlChar *cur; - tokenPtr token; - - if (ctxt == NULL) return(-1); - if (ctxt->nbTokens >= MAX_TOKEN) return(-1); - token = &(ctxt->tokens[(ctxt->firstToken + ctxt->nbTokens) % MAX_TOKEN]); - token->toktype = CRNG_NONE; - - if (ctxt->cur == NULL) { - ctxt->cur = ctxt->compact; - } -retry: - if (ctxt->cur >= ctxt->end) { - ctxt->state = XML_CRNG_EOF; - return(-1); - } - while ((ctxt->cur < ctxt->end) && - (IS_BLANK(*ctxt->cur))) ctxt->cur++; - if (ctxt->cur >= ctxt->end) { - ctxt->state = XML_CRNG_EOF; - return(-1); - } - if (*ctxt->cur == '#') { - cur = ctxt->cur; - cur++; - while ((cur < ctxt->end) && (*cur != '\n') && (*cur != '\r')) - cur++; - ctxt->cur = cur; - goto retry; - } else if (*ctxt->cur == '"') { - /* string, check for '"""' */ - ctxt->cur++; - if (ctxt->cur >= ctxt->end) goto eof; - cur = ctxt->cur; - if ((ctxt->end - ctxt->end > 2) && - (*cur == '"') && (cur[1] == '"')) { - /* TODO */ - } else { - while ((cur < ctxt->end) && (*cur != '"')) cur++; - if (cur >= ctxt->end) goto eof; - token->toklen = cur - ctxt->cur; - token->token = xmlDictLookup(ctxt->dict, ctxt->cur, token->toklen); - token->toktype = CRNG_LITERAL_SEGMENT; - token->prefix = NULL; - cur++; - ctxt->cur = cur; - } - } else if (*ctxt->cur == '\'') { - /* string, check for "'''" */ - /* TODO */ - } else if ((IS_OP(*ctxt->cur)) || (*ctxt->cur == ':')) { - cur = ctxt->cur; - cur++; - if ((cur < ctxt->end) && - (((*cur == '=') && - ((*ctxt->cur == '|') || (*ctxt->cur == '&'))) || - ((*cur == '*') && (*ctxt->cur == ':')))) { - token->toklen = 2; - } else { - token->toklen = 1; - } - token->token = xmlDictLookup(ctxt->dict, ctxt->cur, token->toklen); - token->toktype = CRNG_OP; - token->prefix = NULL; - ctxt->cur += token->toklen; - } else { - int escape = 0; - - cur = ctxt->cur; - if (*cur == '\\') { - escape = 1; - cur++; - ctxt->cur++; - } - while ((cur < ctxt->end) && - (!(IS_SEPARATOR(*cur))) && (!(IS_OP(*cur)))) cur++; - - token->toklen = cur - ctxt->cur; - token->token = xmlDictLookup(ctxt->dict, ctxt->cur, token->toklen); - token->prefix = NULL; - ctxt->cur = cur; - if ((escape == 0) && (xmlCRNGIsKeyword(ctxt, token->token))) - token->toktype = CRNG_KEYWORD; - else { - token->toktype = CRNG_IDENTIFIER; - } - if (*ctxt->cur == ':') { - ctxt->cur++; - if (*ctxt->cur == '*') { - ctxt->cur++; - token->toktype = CRNG_NSNAME; - } else { - cur = ctxt->cur; - while ((cur < ctxt->end) && - (!(IS_SEPARATOR(*cur))) && (!(IS_OP(*cur)))) cur++; - token->prefix = token->token; - token->toklen = cur - ctxt->cur; - token->token = xmlDictLookup(ctxt->dict, ctxt->cur, - token->toklen); - ctxt->cur = cur; - if (xmlValidateNCName(token->token, 0) == 0) - token->toktype = CRNG_QNAME; - else { - /* TODO: sounds like an error ! */ - token->toktype = CRNG_IDENTIFIER; - } - } - } - } - ctxt->nbTokens++; - return(0); -eof: - ctxt->state = XML_CRNG_EOF; - CRNG_ERROR(CRNG_END_ERROR); - return(-1); -} - -/** - * xmlParseCRNGGetToken: - * @ctxt: a compact RNG parser context - * @no: the number of the token from 1 for the first one - * and 2, 3 ... for read-ahead - * - * Token reading interface - * - * returns a pointer to the new token, or NULL in case of error or EOF - */ -static tokenPtr -xmlParseCRNGGetToken(xmlCRelaxNGParserCtxtPtr ctxt, int no) { - tokenPtr ret; - int res; - - if ((no <= 0) || (no >= MAX_TOKEN)) return(NULL); - no--; - while (ctxt->nbTokens <= no) { - res = xmlCRNGNextToken(ctxt); - if (res < 0) - return(NULL); - } - ret = &(ctxt->tokens[(ctxt->firstToken + no) % MAX_TOKEN]); - return(ret); -} - -/** - * xmlParseCRNGDropTokens: - * @ctxt: a compact RNG parser context - * @nr: the number of token marked as read - * - * mark a number of token as read and consumed. - * - * Returns -1 in case of error and 0 otherwise - */ -static int -xmlParseCRNGDropTokens(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 void -xmlParseCRNGTokenize(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 int -xmlParseCRNG_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 int -xmlParseCRNG_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 int -xmlParseCRNG_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 xmlAttrPtr -xmlParseCRNG_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 int -xmlParseCRNG_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 int -xmlParseCRNG_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 int -xmlParseCRNG_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 int -xmlParseCRNG_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 int -xmlParseCRNG_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 - * - * Returns 0 in case of success and -1 in case of error - */ -static int -xmlParseCRNG_patternBlock(xmlCRelaxNGParserCtxtPtr ctxt) -{ - tokenPtr token; - - token = xmlParseCRNGGetToken(ctxt, 1); - if ((token->toktype != CRNG_OP) || - (token->token[0] != '{') || (token->token[1] != 0)) { - ERROR("Expecting \"{\" here"); - } - xmlParseCRNGDropTokens(ctxt, 1); - xmlParseCRNG_pattern(ctxt); - token = xmlParseCRNGGetToken(ctxt, 1); - if ((token->toktype != CRNG_OP) || - (token->token[0] != '}') || (token->token[1] != 0)) { - ERROR("Expecting \"}\" here"); - } - xmlParseCRNGDropTokens(ctxt, 1); - return(0); -} - -/** - * xmlParseCRNG_datatype: - * @ctxt: a compact RNG parser context - * - * Parse datatype of the RELAX NG Compact Syntax Appendix A - * - * Returns 0 in case of success and -1 in case of error - */ -static int -xmlParseCRNG_datatype(xmlCRelaxNGParserCtxtPtr ctxt ATTRIBUTE_UNUSED) -{ - tokenPtr token; - xmlAttrPtr attrs = NULL; - - token = xmlParseCRNGGetToken(ctxt, 1); - if (token->toktype == CRNG_KEYWORD) { - if (token->token == ctxt->key_string) { - attrs = xmlParseCRNG_datatypeAttributes(ctxt, BAD_CAST "", - token->token); - xmlParseCRNGDropTokens(ctxt, 1); - } else if (token->token == ctxt->key_token) { - attrs = xmlParseCRNG_datatypeAttributes(ctxt, BAD_CAST "", - token->token); - xmlParseCRNGDropTokens(ctxt, 1); - } else { - /* TODO: probably an error */ - } - } else if (token->toktype == CRNG_LITERAL_SEGMENT) { - ctxt->insert = xmlNewNode(NULL, BAD_CAST "value"); - xmlParseCRNGDropTokens(ctxt, 1); - if (ctxt->insert == NULL) CRNG_MEM_ERROR0(); - xmlNodeAddContent(ctxt->insert, token->token); - } else if (token->toktype == CRNG_QNAME) { - attrs = xmlParseCRNG_datatypeAttributes(ctxt, - xmlParseCRNG_lookupDatatypePrefix(ctxt, token->prefix), - token->token); - } else { - /* TODO */ - } - if (attrs != NULL) { - token = xmlParseCRNGGetToken(ctxt, 1); - if (token->toktype == CRNG_LITERAL_SEGMENT) { - ctxt->insert = xmlNewNode(NULL, BAD_CAST "value"); - xmlParseCRNGDropTokens(ctxt, 1); - if (ctxt->insert == NULL) { - xmlFreePropList(attrs); - CRNG_MEM_ERROR0(); - } - ctxt->insert->properties = attrs; - xmlNodeAddContent(ctxt->insert, token->token); - } else if ((token->toktype == CRNG_OP) && - (token->token[0] == '{') && (token->token[0] == 0)) { - ctxt->insert = xmlNewNode(NULL, BAD_CAST "data"); - xmlParseCRNGDropTokens(ctxt, 1); - if (ctxt->insert == NULL) { - xmlFreePropList(attrs); - CRNG_MEM_ERROR0(); - } - ctxt->insert->properties = attrs; - xmlParseCRNG_params(ctxt); - } else { - ctxt->insert = xmlNewNode(NULL, BAD_CAST "data"); - xmlParseCRNGDropTokens(ctxt, 1); - if (ctxt->insert == NULL) { - xmlFreePropList(attrs); - CRNG_MEM_ERROR0(); - } - ctxt->insert->properties = attrs; - xmlNodeAddContent(ctxt->insert, token->token); - } - } - return(0); -} - -/** - * xmlParseCRNG_primary: - * @ctxt: a compact RNG parser context - * - * Parse primary of the RELAX NG Compact Syntax Appendix A - * - * Returns 0 in case of success and -1 in case of error - */ -static int -xmlParseCRNG_primary(xmlCRelaxNGParserCtxtPtr ctxt ATTRIBUTE_UNUSED) -{ - tokenPtr token; - - token = xmlParseCRNGGetToken(ctxt, 1); - if (token == NULL) - return(0); - if (token->toktype == CRNG_KEYWORD) { - if (token->token == ctxt->key_element) { - ctxt->insert = xmlNewNodeEatName(NULL, (xmlChar *) token->token); - xmlParseCRNGDropTokens(ctxt, 1); - if (ctxt->insert == NULL) CRNG_MEM_ERROR0(); - ctxt->isElem = 1; - xmlParseCRNG_nameClass(ctxt); - xmlParseCRNG_patternBlock(ctxt); - } else if (token->token == ctxt->key_attribute) { - ctxt->insert = xmlNewNodeEatName(NULL, (xmlChar *) token->token); - xmlParseCRNGDropTokens(ctxt, 1); - if (ctxt->insert == NULL) CRNG_MEM_ERROR0(); - ctxt->isElem = 0; - xmlParseCRNG_nameClass(ctxt); - xmlParseCRNG_patternBlock(ctxt); - } else if (token->token == ctxt->key_mixed) { - ctxt->insert = xmlNewNodeEatName(NULL, (xmlChar *) token->token); - xmlParseCRNGDropTokens(ctxt, 1); - if (ctxt->insert == NULL) CRNG_MEM_ERROR0(); - xmlParseCRNG_patternBlock(ctxt); - } else if (token->token == ctxt->key_list) { - ctxt->insert = xmlNewNodeEatName(NULL, (xmlChar *) token->token); - xmlParseCRNGDropTokens(ctxt, 1); - if (ctxt->insert == NULL) CRNG_MEM_ERROR0(); - xmlParseCRNG_patternBlock(ctxt); - } else if (token->token == ctxt->key_empty) { - ctxt->insert = xmlNewNodeEatName(NULL, (xmlChar *) token->token); - xmlParseCRNGDropTokens(ctxt, 1); - if (ctxt->insert == NULL) CRNG_MEM_ERROR0(); - } else if (token->token == ctxt->key_notAllowed) { - ctxt->insert = xmlNewNodeEatName(NULL, (xmlChar *) token->token); - xmlParseCRNGDropTokens(ctxt, 1); - if (ctxt->insert == NULL) CRNG_MEM_ERROR0(); - } else if (token->token == ctxt->key_text) { - ctxt->insert = xmlNewNodeEatName(NULL, (xmlChar *) token->token); - xmlParseCRNGDropTokens(ctxt, 1); - if (ctxt->insert == NULL) CRNG_MEM_ERROR0(); - } else if (token->token == ctxt->key_parent) { - ctxt->insert = xmlNewNodeEatName(NULL, (xmlChar *) token->token); - xmlParseCRNGDropTokens(ctxt, 1); - if (ctxt->insert == NULL) CRNG_MEM_ERROR0(); - /* TODO */ - } else if (token->token == ctxt->key_grammar) { - ctxt->insert = xmlNewNodeEatName(NULL, (xmlChar *) token->token); - xmlParseCRNGDropTokens(ctxt, 1); - if (ctxt->insert == NULL) CRNG_MEM_ERROR0(); - /* TODO */ - } else if (token->token == ctxt->key_external) { - ctxt->insert = xmlNewNode(NULL, BAD_CAST "externalRef"); - xmlParseCRNGDropTokens(ctxt, 1); - if (ctxt->insert == NULL) CRNG_MEM_ERROR0(); - /* TODO */ - } else { - /* TODO */ - } - } else if (token->toktype == CRNG_IDENTIFIER) { - ctxt->insert = xmlNewNodeEatName(NULL, (xmlChar *) ctxt->key_ref); - if (ctxt->insert == NULL) CRNG_MEM_ERROR0(); - xmlSetProp(ctxt->insert, BAD_CAST "name", token->token); - xmlParseCRNGDropTokens(ctxt, 1); - } else if (token->toktype == CRNG_QNAME) { - xmlParseCRNG_datatype(ctxt); - } else if (token->toktype == CRNG_LITERAL_SEGMENT) { - xmlParseCRNG_datatype(ctxt); - } else if ((token->toktype == CRNG_OP) && - (token->token[0] == '(') && (token->token[1] == 0)) { - xmlParseCRNGDropTokens(ctxt, 1); - xmlParseCRNG_pattern(ctxt); - token = xmlParseCRNGGetToken(ctxt, 1); - if ((token->toktype != CRNG_OP) || - (token->token[0] != ')') || (token->token[1] != 0)) { - ERROR("Expecting \")\" here"); - } - xmlParseCRNGDropTokens(ctxt, 1); - } - return(0); -} - -/** - * xmlParseCRNG_particle: - * @ctxt: a compact RNG parser context - * - * Parse particle of the RELAX NG Compact Syntax Appendix A - * - * Returns 0 in case of success and -1 in case of error - */ -static int -xmlParseCRNG_particle(xmlCRelaxNGParserCtxtPtr ctxt) -{ - tokenPtr token; - xmlNodePtr insert = ctxt->insert, res, tmp = NULL; - - ctxt->insert = NULL; - xmlParseCRNG_primary(ctxt); - res = ctxt->insert; - token = xmlParseCRNGGetToken(ctxt, 1); - if ((token != NULL) && (token->toktype == CRNG_OP)) { - if ((token->token[0] == '*') && (token->token[1] == 0)) { - tmp = xmlNewNode(NULL, BAD_CAST "zeroOrMore"); - if (tmp == NULL) CRNG_MEM_ERROR0(); - } else if ((token->token[0] == '+') && (token->token[1] == 0)) { - tmp = xmlNewNode(NULL, BAD_CAST "oneOrMore"); - if (tmp == NULL) CRNG_MEM_ERROR0(); - } else if ((token->token[0] == '?') && (token->token[1] == 0)) { - tmp = xmlNewNode(NULL, BAD_CAST "optional"); - if (tmp == NULL) CRNG_MEM_ERROR0(); - } - if (tmp != NULL) { - xmlAddChild(tmp, res); - res = tmp; - xmlParseCRNGDropTokens(ctxt, 1); - } - } - if (insert != NULL) { - xmlAddChild(insert, res); - ctxt->insert = insert; - } else - ctxt->insert = res; - return(0); -} - -/** - * xmlParseCRNG_pattern: - * @ctxt: a compact RNG parser context - * - * Parse pattern of the RELAX NG Compact Syntax Appendix A - * - * Returns 0 in case of success and -1 in case of error - */ -static int -xmlParseCRNG_pattern(xmlCRelaxNGParserCtxtPtr ctxt) -{ - tokenPtr token; - xmlNodePtr insert = ctxt->insert, prev, grp; - - ctxt->insert = NULL; - xmlParseCRNG_particle(ctxt); - prev = ctxt->insert; - token = xmlParseCRNGGetToken(ctxt, 1); - while ((prev != NULL) && (token != NULL) && (token->toktype == CRNG_OP)) { - if (token->token == ctxt->key_or) { - grp = xmlNewNodeEatName(NULL, (xmlChar *) ctxt->key_choice); - if (grp == NULL) CRNG_MEM_ERROR0(); - } else if (token->token == ctxt->key_and) { - grp = xmlNewNodeEatName(NULL, (xmlChar *) ctxt->key_interleave); - if (grp == NULL) CRNG_MEM_ERROR0(); - } else if (token->token == ctxt->key_comma) { - grp = xmlNewNodeEatName(NULL, (xmlChar *) ctxt->key_group); - if (grp == NULL) CRNG_MEM_ERROR0(); - } else - break; - xmlParseCRNGDropTokens(ctxt, 1); - ctxt->insert = NULL; - xmlParseCRNG_particle(ctxt); - xmlAddChild(grp, prev); - xmlAddChild(grp, ctxt->insert); - prev = grp; - token = xmlParseCRNGGetToken(ctxt, 1); - } - if (insert != NULL) { - xmlAddChild(insert, prev); - ctxt->insert = insert; - } else { - ctxt->insert = prev; - } - - return(0); -} - -/** - * xmlParseCRNG_component: - * @ctxt: a compact RNG parser context - * - * Parse component of the RELAX NG Compact Syntax Appendix A - * - * Returns 0 in case of success and -1 in case of error - */ -static int -xmlParseCRNG_component(xmlCRelaxNGParserCtxtPtr ctxt) -{ - tokenPtr token, tok2; - xmlNodePtr insert = ctxt->insert; - - token = xmlParseCRNGGetToken(ctxt, 1); - if (token == NULL) - return(0); - if (token->toktype == CRNG_KEYWORD) { - if (token->token == ctxt->key_start) { - xmlNodePtr start; - - start = xmlNewNodeEatName(NULL, (xmlChar *) ctxt->key_start); - if (start == NULL) CRNG_MEM_ERROR0(); - if (ctxt->insert != NULL) - xmlAddChild(ctxt->insert, start); - ctxt->insert = start; - xmlParseCRNGDropTokens(ctxt, 1); - token = xmlParseCRNGGetToken(ctxt, 1); - - if ((token->toktype == CRNG_OP) && - (token->token == ctxt->key_equal)) { - } else if ((token->toktype == CRNG_OP) && - (token->token == ctxt->key_orequal)) { - xmlParseCRNG_attribute(ctxt, ctxt->key_combine, NULL, - BAD_CAST "choice"); - } else if ((token->toktype == CRNG_OP) && - (token->token == ctxt->key_andequal)) { - xmlParseCRNG_attribute(ctxt, ctxt->key_combine, NULL, - BAD_CAST "interleave"); - } else { - ERROR("expecting \"=\" or \"&=\" or \"|=\" here") - return(-1); - } - start->properties = ctxt->attrs; - ctxt->attrs = NULL; - xmlParseCRNGDropTokens(ctxt, 1); - xmlParseCRNG_pattern(ctxt); - - } else if (token->token == ctxt->key_include) { - /* TODO */ - } else if (token->token == ctxt->key_div) { - /* TODO */ - } else { - return(-1); - } - } else if (token->toktype == CRNG_IDENTIFIER) { - xmlNodePtr define; - const xmlChar *identifier; - - identifier = token->token; - tok2 = xmlParseCRNGGetToken(ctxt, 2); - if ((tok2->toktype == CRNG_OP) && - (tok2->token == ctxt->key_equal)) { - } else if ((tok2->toktype == CRNG_OP) && - (tok2->token == ctxt->key_orequal)) { - xmlParseCRNG_attribute(ctxt, ctxt->key_combine, NULL, - BAD_CAST "choice"); - } else if ((tok2->toktype == CRNG_OP) && - (tok2->token == ctxt->key_andequal)) { - xmlParseCRNG_attribute(ctxt, ctxt->key_combine, NULL, - BAD_CAST "interleave"); - } else { - ERROR("expecting \"=\" or \"&=\" or \"|=\" here") - return(-1); - } - xmlParseCRNGDropTokens(ctxt, 2); - - define = xmlNewNodeEatName(NULL, (xmlChar *) ctxt->key_define); - if (define == NULL) CRNG_MEM_ERROR0(); - define->properties = ctxt->attrs; - ctxt->attrs = NULL; - xmlSetProp(define, BAD_CAST "name", identifier); - if (ctxt->insert != NULL) - xmlAddChild(ctxt->insert, define); - ctxt->insert = define; - xmlParseCRNG_pattern(ctxt); - } else { - return(-1); - } - ctxt->insert = insert; - return(0); -} - -/** - * xmlParseCRNG_grammar: - * @ctxt: a compact RNG parser context - * - * Parse grammar of the RELAX NG Compact Syntax Appendix A - * - * Returns 0 in case of success and -1 in case of error - */ -static int -xmlParseCRNG_grammar(xmlCRelaxNGParserCtxtPtr ctxt ATTRIBUTE_UNUSED) -{ - tokenPtr token; - int ret; - - token = xmlParseCRNGGetToken(ctxt, 1); - while (token != NULL) { - ret = xmlParseCRNG_component(ctxt); - if (ret != 0) - break; - token = xmlParseCRNGGetToken(ctxt, 1); - } - return(0); -} - -/** - * xmlParseCRNG_topLevelBody: - * @ctxt: a compact RNG parser context - * - * Parse topLevelBody of the RELAX NG Compact Syntax Appendix A - * - * Returns 0 in case of success and -1 in case of error - */ -static int -xmlParseCRNG_topLevelBody(xmlCRelaxNGParserCtxtPtr ctxt) -{ - tokenPtr token, tok2; - - token = xmlParseCRNGGetToken(ctxt, 1); - if (token->toktype == CRNG_KEYWORD) { - if ((token->token == ctxt->key_start) || - (token->token == ctxt->key_include) || - (token->token == ctxt->key_div)) { - xmlNodePtr grammar; - - grammar = xmlNewNodeEatName(NULL, (xmlChar *) ctxt->key_grammar); - if (grammar == NULL) CRNG_MEM_ERROR0(); - xmlDocSetRootElement(ctxt->doc, grammar); - ctxt->insert = grammar; - - xmlParseCRNG_grammar(ctxt); - } else { - xmlParseCRNG_pattern(ctxt); - } - } else { - tok2 = xmlParseCRNGGetToken(ctxt, 2); - if ((tok2->toktype == CRNG_OP) && - ((tok2->token == ctxt->key_equal) || - (tok2->token == ctxt->key_orequal) || - (tok2->token == ctxt->key_andequal))) { - xmlNodePtr grammar; - - grammar = xmlNewNodeEatName(NULL, (xmlChar *) ctxt->key_grammar); - if (grammar == NULL) CRNG_MEM_ERROR0(); - xmlDocSetRootElement(ctxt->doc, grammar); - ctxt->insert = grammar; - - xmlParseCRNG_grammar(ctxt); - } else { - xmlParseCRNG_pattern(ctxt); - } - } - return(0); -} - -/** - * xmlParseCRNG_namespacePrefix: - * @ctxt: a compact RNG parser context - * - * Parse namespacePrefix of the RELAX NG Compact Syntax Appendix A - * - * Returns the prefix or NULL in case of error - */ -static const xmlChar * -xmlParseCRNG_namespacePrefix(xmlCRelaxNGParserCtxtPtr ctxt) -{ - tokenPtr token; - const xmlChar *prefix = NULL; - - token = xmlParseCRNGGetToken(ctxt, 1); - if (token->toktype == CRNG_IDENTIFIER) { - prefix = token->token; - } else if (token->toktype == CRNG_OP) { - if ((token->token[0] == '=') && (token->token[1] == 0)) - return(NULL); - prefix = token->token; - } else { - ERROR("Expecting a namespace prefix"); - return(NULL); - } - xmlParseCRNGDropTokens(ctxt, 1); - - if (xmlStrEqual(prefix, BAD_CAST "xmlns")) { - ERROR("Namespace prefix \"xmlns\" is forbidden"); - } - return(prefix); -} - -/** - * xmlParseCRNG_decl: - * @ctxt: a compact RNG parser context - * - * Parse decl of the RELAX NG Compact Syntax Appendix A - * - * Returns 0 in case of success and -1 in case of error - */ -static int -xmlParseCRNG_decl(xmlCRelaxNGParserCtxtPtr ctxt) -{ - const xmlChar *prefix = NULL; - const xmlChar *namespace = NULL; - tokenPtr token; - - token = xmlParseCRNGGetToken(ctxt, 1); - if (token->toktype != CRNG_KEYWORD) return(-1); - if (token->token == ctxt->key_default) { - xmlParseCRNGDropTokens(ctxt, 1); - token = xmlParseCRNGGetToken(ctxt, 1); - if ((token->toktype != CRNG_KEYWORD) || - (token->token != ctxt->key_namespace)) { - ERROR("Expecting keyword \"namespace\" after \"default\""); - } - xmlParseCRNGDropTokens(ctxt, 1); - prefix = xmlParseCRNG_namespacePrefix(ctxt); - token = xmlParseCRNGGetToken(ctxt, 1); - if ((token->toktype != CRNG_OP) || - (token->token[0] != '=') || (token->token[1] != 0)) { - ERROR("Expecting keyword \"=\" here"); - } - xmlParseCRNGDropTokens(ctxt, 1); - token = xmlParseCRNGGetToken(ctxt, 1); - if ((token->toktype == CRNG_KEYWORD) && - (token->token == ctxt->key_inherit)) { - namespace = xmlCRelaxNGInherit; - } else if (token->toktype == CRNG_LITERAL_SEGMENT) { - namespace = token->token; - } else { - ERROR("Expecting an URI or \"inherit\" value"); - } - xmlParseCRNGDropTokens(ctxt, 1); - if (namespace != NULL) { - if (prefix != NULL) - xmlParseCRNG_bindPrefix(ctxt, prefix, namespace); - xmlParseCRNG_bindPrefix(ctxt, NULL, namespace); - } - } else if (token->token == ctxt->key_namespace) { - xmlParseCRNGDropTokens(ctxt, 1); - prefix = xmlParseCRNG_namespacePrefix(ctxt); - token = xmlParseCRNGGetToken(ctxt, 1); - if ((token->toktype != CRNG_OP) || - (token->token[0] != '=') || (token->token[1] != 0)) { - ERROR("Expecting keyword \"=\" here"); - } - xmlParseCRNGDropTokens(ctxt, 1); - token = xmlParseCRNGGetToken(ctxt, 1); - if ((token->toktype == CRNG_KEYWORD) && - (token->token == ctxt->key_inherit)) { - namespace = xmlCRelaxNGInherit; - } else if (token->toktype == CRNG_LITERAL_SEGMENT) { - namespace = token->token; - } else { - ERROR("Expecting an URI or \"inherit\" value"); - } - xmlParseCRNGDropTokens(ctxt, 1); - if (namespace != NULL) - xmlParseCRNG_bindPrefix(ctxt, prefix, namespace); - } else if (token->token == ctxt->key_datatypes) { - xmlParseCRNGDropTokens(ctxt, 1); - - token = xmlParseCRNGGetToken(ctxt, 1); - if ((token->toktype != CRNG_KEYWORD) && - (token->toktype != CRNG_IDENTIFIER)) { - ERROR("Expecting a datatype prefix identifier here"); - } else - prefix = token->token; - xmlParseCRNGDropTokens(ctxt, 1); - token = xmlParseCRNGGetToken(ctxt, 1); - if ((token->toktype != CRNG_OP) || - (token->token[0] != '=') || (token->token[1] != 0)) { - ERROR("Expecting keyword \"=\" here"); - } - xmlParseCRNGDropTokens(ctxt, 1); - token = xmlParseCRNGGetToken(ctxt, 1); - if (token->toktype == CRNG_LITERAL_SEGMENT) { - namespace = token->token; - } else { - ERROR("Expecting a literal value for the datatype identifier"); - } - xmlParseCRNGDropTokens(ctxt, 1); - if ((namespace != NULL) && (prefix != NULL)) - xmlParseCRNG_bindDatatypePrefix(ctxt, prefix, namespace); - } - - return(0); -} - -/** - * xmlParseCRNG_preamble: - * @ctxt: a compact RNG parser context - * - * Parse preamble of the RELAX NG Compact Syntax Appendix A - * - * Returns 0 in case of success and -1 in case of error - */ -static int -xmlParseCRNG_preamble(xmlCRelaxNGParserCtxtPtr ctxt) -{ - tokenPtr token; - - token = xmlParseCRNGGetToken(ctxt, 1); - while (token != NULL) { - if (token == NULL) return(-1); - if ((token->toktype == CRNG_KEYWORD) && - ((token->token == ctxt->key_default) || - (token->token == ctxt->key_namespace) || - (token->token == ctxt->key_datatypes))) { - xmlParseCRNG_decl(ctxt); - } else - break; - token = xmlParseCRNGGetToken(ctxt, 1); - } - return(0); -} - -/** - * xmlParseCRNG_topLevel: - * @ctxt: a compact RNG parser context - * - * Parse topLevel of the RELAX NG Compact Syntax Appendix A - * - * Returns 0 in case of success and -1 in case of error - */ -static int -xmlParseCRNG_topLevel(xmlCRelaxNGParserCtxtPtr ctxt) -{ - xmlParseCRNG_preamble(ctxt); - xmlParseCRNG_topLevelBody(ctxt); - return(0); -} - -/** - * xmlConvertCRNG: - * @schemas: pointer to the text of the compact schemas - * @len: length of the schemas in bytes (or 0) - * @encoding: encoding indicated by the context or NULL - * - * Compiles the schemas into the equivalent Relax-NG XML structure - * - * Returns the xmlDocPtr resulting from the compilation or - * NULL in case of error - */ -xmlDocPtr -xmlConvertCRNG(const char *schemas, int len, const char *encoding) { - struct _xmlCRelaxNGParserCtxt ctxt; - xmlDocPtr ret = NULL; - - if (schemas == NULL) return(NULL); - if (len <= 5) len = xmlStrlen((const unsigned char *) schemas); - if (len <= 0) return(NULL); - - memset(&ctxt, 0, sizeof(ctxt)); - ctxt.compact = (const unsigned char *) schemas; - ctxt.cur = (const unsigned char *) schemas; - ctxt.end = (const unsigned char *) &schemas[len]; - ctxt.dict = xmlDictCreate(); - if (ctxt.dict == NULL) - return(NULL); - ctxt.doc = xmlNewDoc(NULL); - if (ctxt.doc == NULL) { - xmlDictFree(ctxt.dict); - return(NULL); - } - ctxt.doc->dict = ctxt.dict; - xmlDictReference(ctxt.dict); - - ctxt.nbTokens = 0; - ctxt.firstToken = 0; - ctxt.key_attribute = xmlDictLookup(ctxt.dict, BAD_CAST "attribute", -1); - ctxt.key_default = xmlDictLookup(ctxt.dict, BAD_CAST "default", -1); - ctxt.key_datatypes = xmlDictLookup(ctxt.dict, BAD_CAST "datatypes", -1); - ctxt.key_div = xmlDictLookup(ctxt.dict, BAD_CAST "div", -1); - ctxt.key_element = xmlDictLookup(ctxt.dict, BAD_CAST "element", -1); - ctxt.key_empty = xmlDictLookup(ctxt.dict, BAD_CAST "empty", -1); - ctxt.key_external = xmlDictLookup(ctxt.dict, BAD_CAST "external", -1); - ctxt.key_grammar = xmlDictLookup(ctxt.dict, BAD_CAST "grammar", -1); - ctxt.key_include = xmlDictLookup(ctxt.dict, BAD_CAST "include", -1); - ctxt.key_inherit = xmlDictLookup(ctxt.dict, BAD_CAST "inherit", -1); - ctxt.key_list = xmlDictLookup(ctxt.dict, BAD_CAST "list", -1); - ctxt.key_mixed = xmlDictLookup(ctxt.dict, BAD_CAST "mixed", -1); - ctxt.key_namespace = xmlDictLookup(ctxt.dict, BAD_CAST "namespace", -1); - ctxt.key_notAllowed = xmlDictLookup(ctxt.dict, BAD_CAST "notAllowed", -1); - ctxt.key_parent = xmlDictLookup(ctxt.dict, BAD_CAST "parent", -1); - ctxt.key_start = xmlDictLookup(ctxt.dict, BAD_CAST "start", -1); - ctxt.key_string = xmlDictLookup(ctxt.dict, BAD_CAST "string", -1); - ctxt.key_text = xmlDictLookup(ctxt.dict, BAD_CAST "text", -1); - ctxt.key_token = xmlDictLookup(ctxt.dict, BAD_CAST "token", -1); - ctxt.key_equal = xmlDictLookup(ctxt.dict, BAD_CAST "=", 1); - ctxt.key_orequal = xmlDictLookup(ctxt.dict, BAD_CAST "|=", 2); - ctxt.key_andequal = xmlDictLookup(ctxt.dict, BAD_CAST "&=", 2); - ctxt.key_combine = xmlDictLookup(ctxt.dict, BAD_CAST "&=", 2); - ctxt.key_or = xmlDictLookup(ctxt.dict, BAD_CAST "|", 1); - ctxt.key_comma = xmlDictLookup(ctxt.dict, BAD_CAST ",", 1); - ctxt.key_and = xmlDictLookup(ctxt.dict, BAD_CAST "&", 1); - ctxt.key_choice = xmlDictLookup(ctxt.dict, BAD_CAST "choice", -1); - ctxt.key_group = xmlDictLookup(ctxt.dict, BAD_CAST "group", -1); - ctxt.key_interleave = xmlDictLookup(ctxt.dict, BAD_CAST "interleave", -1); - ctxt.key_ref = xmlDictLookup(ctxt.dict, BAD_CAST "ref", 3); - ctxt.key_define = xmlDictLookup(ctxt.dict, BAD_CAST "define", 6); - - /* xmlConvertCRNGTokenize(&ctxt); */ - xmlConvertCRNG_topLevel(&ctxt); - - xmlDictFree(ctxt.dict); - - ret = ctxt.doc; - return(ret); -} - -/** - * xmlConvertCRNGFile: - * @URL: URL or filename for the resource - * @encoding: encoding indicated by the context or NULL - * - * Compiles the schemas into the equivalent Relax-NG XML structure - * - * Returns the xmlDocPtr resulting from the compilation or - * NULL in case of error - */ -xmlDocPtr -xmlConvertCRNGFile(const char *URL, const char *encoding) { -} - -#ifdef STANDALONE -const xmlChar *schemas = -"# RELAX NG XML syntax specified in compact syntax.\n\ -\n\ -default namespace rng = \"http://relaxng.org/ns/structure/1.0\"\n\ -namespace local = \"\"\n\ -datatypes xsd = \"http://www.w3.org/2001/XMLSchema-datatypes\"\n\ -\n\ -start = pattern\n\ -\n\ -pattern =\n\ - element element { (nameQName | nameClass), (common & pattern+) }\n\ - | element attribute { (nameQName | nameClass), (common & pattern?) }\n\ - | element group|interleave|choice|optional\n\ - |zeroOrMore|oneOrMore|list|mixed { common & pattern+ }\n\ - | element ref|parentRef { nameNCName, common }\n\ - | element empty|notAllowed|text { common }\n\ - | element data { type, param*, (common & exceptPattern?) }\n\ - | element value { commonAttributes, type?, xsd:string }\n\ - | element externalRef { href, common }\n\ - | element grammar { common & grammarContent* }\n\ -\n\ -param = element param { commonAttributes, nameNCName, xsd:string }\n\ -\n\ -exceptPattern = element except { common & pattern+ }\n\ -\n\ -grammarContent =\n\ - definition\n\ - | element div { common & grammarContent* }\n\ - | element include { href, (common & includeContent*) }\n\ -\n\ -includeContent =\n\ - definition\n\ - | element div { common & includeContent* }\n\ -\n\ -definition =\n\ - element start { combine?, (common & pattern+) }\n\ - | element define { nameNCName, combine?, (common & pattern+) }\n\ -\n\ -combine = attribute combine { \"choice\" | \"interleave\" }\n\ -\n\ -nameClass =\n\ - element name { commonAttributes, xsd:QName }\n\ - | element anyName { common & exceptNameClass? }\n\ - | element nsName { common & exceptNameClass? }\n\ - | element choice { common & nameClass+ }\n\ -\n\ -exceptNameClass = element except { common & nameClass+ }\n\ -\n\ -nameQName = attribute name { xsd:QName }\n\ -nameNCName = attribute name { xsd:NCName }\n\ -href = attribute href { xsd:anyURI }\n\ -type = attribute type { xsd:NCName }\n\ -\n\ -common = commonAttributes, foreignElement*\n\ -\n\ -commonAttributes =\n\ - attribute ns { xsd:string }?,\n\ - attribute datatypeLibrary { xsd:anyURI }?,\n\ - foreignAttribute*\n\ -\n\ -foreignElement = element * - rng:* { (anyAttribute | text | anyElement)* }\n\ -foreignAttribute = attribute * - (rng:*|local:*) { text }\n\ -anyElement = element * { (anyAttribute | text | anyElement)* }\n\ -anyAttribute = attribute * { text }\n\ -"; - -int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) { - xmlDocPtr res; - - res = xmlConvertCRNG(schemas, -1); - if (res != NULL) { - xmlDocFormatDump(stdout, res, 1); - xmlFreeDoc(res); - } - return(0); -} -#endif diff --git a/schematron.c b/schematron.c index e02de230..ac0c71fc 100644 --- a/schematron.c +++ b/schematron.c @@ -2046,47 +2046,4 @@ xmlSchematronValidateDoc(xmlSchematronValidCtxtPtr ctxt, xmlDocPtr instance) return(ctxt->nberrors); } -#ifdef STANDALONE -int -main(void) -{ - int ret; - xmlDocPtr instance; - xmlSchematronParserCtxtPtr pctxt; - xmlSchematronValidCtxtPtr vctxt; - xmlSchematronPtr schema = NULL; - - pctxt = xmlSchematronNewParserCtxt("tst.sct"); - if (pctxt == NULL) { - fprintf(stderr, "failed to build schematron parser\n"); - } else { - schema = xmlSchematronParse(pctxt); - if (schema == NULL) { - fprintf(stderr, "failed to compile schematron\n"); - } - xmlSchematronFreeParserCtxt(pctxt); - } - instance = xmlReadFile("tst.sct", NULL, - XML_PARSE_NOENT | XML_PARSE_NOCDATA); - if (instance == NULL) { - fprintf(stderr, "failed to parse instance\n"); - } - if ((schema != NULL) && (instance != NULL)) { - vctxt = xmlSchematronNewValidCtxt(schema); - if (vctxt == NULL) { - fprintf(stderr, "failed to build schematron validator\n"); - } else { - ret = xmlSchematronValidateDoc(vctxt, instance); - xmlSchematronFreeValidCtxt(vctxt); - } - } - xmlSchematronFree(schema); - xmlFreeDoc(instance); - - xmlCleanupParser(); - - return (0); -} -#endif - #endif /* LIBXML_SCHEMATRON_ENABLED */ diff --git a/valid.c b/valid.c index de95987e..ee5f0515 100644 --- a/valid.c +++ b/valid.c @@ -4101,13 +4101,6 @@ xmlValidateElementDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc, if (elem == NULL) return(1); -#if 0 -#ifdef LIBXML_REGEXP_ENABLED - /* Build the regexp associated to the content model */ - ret = xmlValidBuildContentModel(ctxt, elem); -#endif -#endif - /* No Duplicate Types */ if (elem->etype == XML_ELEMENT_TYPE_MIXED) { xmlElementContentPtr cur, next; @@ -4499,25 +4492,6 @@ xmlNodePtr elem, const xmlChar *prefix, xmlNsPtr ns, const xmlChar *value) { } } - /* - * Casting ns to xmlAttrPtr is wrong. We'd need separate functions - * xmlAddID and xmlAddRef for namespace declarations, but it makes - * no practical sense to use ID types anyway. - */ -#if 0 - /* Validity Constraint: ID uniqueness */ - if (attrDecl->atype == XML_ATTRIBUTE_ID) { - if (xmlAddID(ctxt, doc, value, (xmlAttrPtr) ns) == NULL) - ret = 0; - } - - if ((attrDecl->atype == XML_ATTRIBUTE_IDREF) || - (attrDecl->atype == XML_ATTRIBUTE_IDREFS)) { - if (xmlAddRef(ctxt, doc, value, (xmlAttrPtr) ns) == NULL) - ret = 0; - } -#endif - /* Validity Constraint: Notation Attributes */ if (attrDecl->atype == XML_ATTRIBUTE_NOTATION) { xmlEnumerationPtr tree = attrDecl->tree; @@ -5575,7 +5549,7 @@ xmlValidatePushElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc, if (ctxt == NULL) return(0); -/* printf("PushElem %s\n", qname); */ + if ((ctxt->vstateNr > 0) && (ctxt->vstate != NULL)) { xmlValidStatePtr state = ctxt->vstate; xmlElementPtr elemDecl; @@ -5669,7 +5643,6 @@ int xmlValidatePushCData(xmlValidCtxtPtr ctxt, const xmlChar *data, int len) { int ret = 1; -/* printf("CDATA %s %d\n", data, len); */ if (ctxt == NULL) return(0); if (len <= 0) @@ -5748,7 +5721,7 @@ xmlValidatePopElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc ATTRIBUTE_UNUSED, if (ctxt == NULL) return(0); -/* printf("PopElem %s\n", qname); */ + if ((ctxt->vstateNr > 0) && (ctxt->vstate != NULL)) { xmlValidStatePtr state = ctxt->vstate; xmlElementPtr elemDecl; diff --git a/xinclude.c b/xinclude.c index 2c0fb646..14729e3f 100644 --- a/xinclude.c +++ b/xinclude.c @@ -1817,11 +1817,6 @@ xmlXIncludeTestNode(xmlXIncludeCtxtPtr ctxt, xmlNodePtr node) { (xmlStrEqual(node->ns->href, XINCLUDE_OLD_NS))) { if (xmlStrEqual(node->ns->href, XINCLUDE_OLD_NS)) { if (ctxt->legacy == 0) { -#if 0 /* wait for the XML Core Working Group to get something stable ! */ - xmlXIncludeWarn(ctxt, node, XML_XINCLUDE_DEPRECATED_NS, - "Deprecated XInclude namespace found, use %s", - XINCLUDE_NS); -#endif ctxt->legacy = 1; } } diff --git a/xmlreader.c b/xmlreader.c index 2fad37ce..3d3f7bda 100644 --- a/xmlreader.c +++ b/xmlreader.c @@ -1812,66 +1812,6 @@ done: return(ret); } -#if 0 -/** - * xmlTextReaderReadBase64: - * @reader: the xmlTextReaderPtr used - * @array: a byte array to store the content. - * @offset: the zero-based index into array where the method should - * begin to write. - * @len: the number of bytes to write. - * - * Reads and decodes the Base64 encoded contents of an element and - * stores the result in a byte buffer. - * - * Returns the number of bytes written to array, or zero if the current - * instance is not positioned on an element or -1 in case of error. - */ -int -xmlTextReaderReadBase64(xmlTextReaderPtr reader, - unsigned char *array ATTRIBUTE_UNUSED, - int offset ATTRIBUTE_UNUSED, - int len ATTRIBUTE_UNUSED) { - if ((reader == NULL) || (reader->ctxt == NULL)) - return(-1); - if (reader->ctxt->wellFormed != 1) - return(-1); - - if ((reader->node == NULL) || (reader->node->type == XML_ELEMENT_NODE)) - return(0); - return(0); -} - -/** - * xmlTextReaderReadBinHex: - * @reader: the xmlTextReaderPtr used - * @array: a byte array to store the content. - * @offset: the zero-based index into array where the method should - * begin to write. - * @len: the number of bytes to write. - * - * Reads and decodes the BinHex encoded contents of an element and - * stores the result in a byte buffer. - * - * Returns the number of bytes written to array, or zero if the current - * instance is not positioned on an element or -1 in case of error. - */ -int -xmlTextReaderReadBinHex(xmlTextReaderPtr reader, - unsigned char *array ATTRIBUTE_UNUSED, - int offset ATTRIBUTE_UNUSED, - int len ATTRIBUTE_UNUSED) { - if ((reader == NULL) || (reader->ctxt == NULL)) - return(-1); - if (reader->ctxt->wellFormed != 1) - return(-1); - - if ((reader->node == NULL) || (reader->node->type == XML_ELEMENT_NODE)) - return(0); - return(0); -} -#endif - /************************************************************************ * * * Operating on a preparsed tree * @@ -5547,213 +5487,4 @@ xmlReaderNewIO(xmlTextReaderPtr reader, xmlInputReadCallback ioread, return (xmlTextReaderSetup(reader, input, URL, encoding, options)); } -/************************************************************************ - * * - * Utilities * - * * - ************************************************************************/ -#ifdef NOT_USED_YET - -/** - * xmlBase64Decode: - * @in: the input buffer - * @inlen: the size of the input (in), the size read from it (out) - * @to: the output buffer - * @tolen: the size of the output (in), the size written to (out) - * - * Base64 decoder, reads from @in and save in @to - * TODO: tell jody when this is actually exported - * - * Returns 0 if all the input was consumer, 1 if the Base64 end was reached, - * 2 if there wasn't enough space on the output or -1 in case of error. - */ -static int -xmlBase64Decode(const unsigned char *in, unsigned long *inlen, - unsigned char *to, unsigned long *tolen) -{ - unsigned long incur; /* current index in in[] */ - - unsigned long inblk; /* last block index in in[] */ - - unsigned long outcur; /* current index in out[] */ - - unsigned long inmax; /* size of in[] */ - - unsigned long outmax; /* size of out[] */ - - unsigned char cur; /* the current value read from in[] */ - - unsigned char intmp[4], outtmp[4]; /* temporary buffers for the convert */ - - int nbintmp; /* number of byte in intmp[] */ - - int is_ignore; /* cur should be ignored */ - - int is_end = 0; /* the end of the base64 was found */ - - int retval = 1; - - int i; - - if ((in == NULL) || (inlen == NULL) || (to == NULL) || (tolen == NULL)) - return (-1); - - incur = 0; - inblk = 0; - outcur = 0; - inmax = *inlen; - outmax = *tolen; - nbintmp = 0; - - while (1) { - if (incur >= inmax) - break; - cur = in[incur++]; - is_ignore = 0; - if ((cur >= 'A') && (cur <= 'Z')) - cur = cur - 'A'; - else if ((cur >= 'a') && (cur <= 'z')) - cur = cur - 'a' + 26; - else if ((cur >= '0') && (cur <= '9')) - cur = cur - '0' + 52; - else if (cur == '+') - cur = 62; - else if (cur == '/') - cur = 63; - else if (cur == '.') - cur = 0; - else if (cur == '=') /*no op , end of the base64 stream */ - is_end = 1; - else { - is_ignore = 1; - if (nbintmp == 0) - inblk = incur; - } - - if (!is_ignore) { - int nbouttmp = 3; - - int is_break = 0; - - if (is_end) { - if (nbintmp == 0) - break; - if ((nbintmp == 1) || (nbintmp == 2)) - nbouttmp = 1; - else - nbouttmp = 2; - nbintmp = 3; - is_break = 1; - } - intmp[nbintmp++] = cur; - /* - * if intmp is full, push the 4byte sequence as a 3 byte - * sequence out - */ - if (nbintmp == 4) { - nbintmp = 0; - outtmp[0] = (intmp[0] << 2) | ((intmp[1] & 0x30) >> 4); - outtmp[1] = - ((intmp[1] & 0x0F) << 4) | ((intmp[2] & 0x3C) >> 2); - outtmp[2] = ((intmp[2] & 0x03) << 6) | (intmp[3] & 0x3F); - if (outcur + 3 >= outmax) { - retval = 2; - break; - } - - for (i = 0; i < nbouttmp; i++) - to[outcur++] = outtmp[i]; - inblk = incur; - } - - if (is_break) { - retval = 0; - break; - } - } - } - - *tolen = outcur; - *inlen = inblk; - return (retval); -} - -/* - * Test routine for the xmlBase64Decode function - */ -#if 0 -int -main(int argc, char **argv) -{ - char *input = " VW4 gcGV0 \n aXQgdGVzdCAuCg== "; - - char output[100]; - - char output2[100]; - - char output3[100]; - - unsigned long inlen = strlen(input); - - unsigned long outlen = 100; - - int ret; - - unsigned long cons, tmp, tmp2, prod; - - /* - * Direct - */ - ret = xmlBase64Decode(input, &inlen, output, &outlen); - - output[outlen] = 0; - printf("ret: %d, inlen: %ld , outlen: %ld, output: '%s'\n", ret, inlen, - outlen, output)indent: Standard input:179: Error:Unmatched #endif -; - - /* - * output chunking - */ - cons = 0; - prod = 0; - while (cons < inlen) { - tmp = 5; - tmp2 = inlen - cons; - - printf("%ld %ld\n", cons, prod); - ret = xmlBase64Decode(&input[cons], &tmp2, &output2[prod], &tmp); - cons += tmp2; - prod += tmp; - printf("%ld %ld\n", cons, prod); - } - output2[outlen] = 0; - printf("ret: %d, cons: %ld , prod: %ld, output: '%s'\n", ret, cons, - prod, output2); - - /* - * input chunking - */ - cons = 0; - prod = 0; - while (cons < inlen) { - tmp = 100 - prod; - tmp2 = inlen - cons; - if (tmp2 > 5) - tmp2 = 5; - - printf("%ld %ld\n", cons, prod); - ret = xmlBase64Decode(&input[cons], &tmp2, &output3[prod], &tmp); - cons += tmp2; - prod += tmp; - printf("%ld %ld\n", cons, prod); - } - output3[outlen] = 0; - printf("ret: %d, cons: %ld , prod: %ld, output: '%s'\n", ret, cons, - prod, output3); - return (0); - -} -#endif -#endif /* NOT_USED_YET */ - #endif /* LIBXML_READER_ENABLED */ diff --git a/xmlregexp.c b/xmlregexp.c index 94dbd1eb..ed7f69cf 100644 --- a/xmlregexp.c +++ b/xmlregexp.c @@ -611,10 +611,6 @@ xmlRegEpxFromParse(xmlRegParserCtxtPtr ctxt) { goto not_determ; } } else { -#if 0 - printf("State %d trans %d: atom %d to %d : %d to %d\n", - i, j, trans->atom->no, trans->to, atomno, targetno); -#endif transitions[stateno * (nbatoms + 1) + atomno + 1] = targetno + 1; /* to avoid 0 */ if (transdata != NULL) @@ -2964,7 +2960,6 @@ xmlRegCheckCharacter(xmlRegAtomPtr atom, int codepoint) { return(accept); } case XML_REGEXP_STRING: - printf("TODO: XML_REGEXP_STRING\n"); return(-1); case XML_REGEXP_ANYCHAR: case XML_REGEXP_ANYSPACE: @@ -4274,150 +4269,6 @@ xmlRegExecErrInfo(xmlRegExecCtxtPtr exec, const xmlChar **string, return(xmlRegExecGetValues(exec, 1, nbval, nbneg, values, terminal)); } -#if 0 -static int -xmlRegExecPushChar(xmlRegExecCtxtPtr exec, int UCS) { - xmlRegTransPtr trans; - xmlRegAtomPtr atom; - int ret; - int codepoint, len; - - if (exec == NULL) - return(-1); - if (exec->status != XML_REGEXP_OK) - return(exec->status); - - while ((exec->status == XML_REGEXP_OK) && - ((exec->inputString[exec->index] != 0) || - (exec->state->type != XML_REGEXP_FINAL_STATE))) { - - /* - * End of input on non-terminal state, rollback, however we may - * still have epsilon like transition for counted transitions - * on counters, in that case don't break too early. - */ - if ((exec->inputString[exec->index] == 0) && (exec->counts == NULL)) - goto rollback; - - exec->transcount = 0; - for (;exec->transno < exec->state->nbTrans;exec->transno++) { - trans = &exec->state->trans[exec->transno]; - if (trans->to < 0) - continue; - atom = trans->atom; - ret = 0; - if (trans->count >= 0) { - int count; - xmlRegCounterPtr counter; - - /* - * A counted transition. - */ - - count = exec->counts[trans->count]; - counter = &exec->comp->counters[trans->count]; - ret = ((count >= counter->min) && (count <= counter->max)); - } else if (atom == NULL) { - fprintf(stderr, "epsilon transition left at runtime\n"); - exec->status = XML_REGEXP_INTERNAL_ERROR; - break; - } else if (exec->inputString[exec->index] != 0) { - codepoint = CUR_SCHAR(&(exec->inputString[exec->index]), len); - ret = xmlRegCheckCharacter(atom, codepoint); - if ((ret == 1) && (atom->min > 0) && (atom->max > 0)) { - xmlRegStatePtr to = exec->comp->states[trans->to]; - - /* - * this is a multiple input sequence - */ - if (exec->state->nbTrans > exec->transno + 1) { - xmlFARegExecSave(exec); - } - exec->transcount = 1; - do { - /* - * Try to progress as much as possible on the input - */ - if (exec->transcount == atom->max) { - break; - } - exec->index += len; - /* - * End of input: stop here - */ - if (exec->inputString[exec->index] == 0) { - exec->index -= len; - break; - } - if (exec->transcount >= atom->min) { - int transno = exec->transno; - xmlRegStatePtr state = exec->state; - - /* - * The transition is acceptable save it - */ - exec->transno = -1; /* trick */ - exec->state = to; - xmlFARegExecSave(exec); - exec->transno = transno; - exec->state = state; - } - codepoint = CUR_SCHAR(&(exec->inputString[exec->index]), - len); - ret = xmlRegCheckCharacter(atom, codepoint); - exec->transcount++; - } while (ret == 1); - if (exec->transcount < atom->min) - ret = 0; - - /* - * If the last check failed but one transition was found - * possible, rollback - */ - if (ret < 0) - ret = 0; - if (ret == 0) { - goto rollback; - } - } - } - if (ret == 1) { - if (exec->state->nbTrans > exec->transno + 1) { - xmlFARegExecSave(exec); - } - /* - * restart count for expressions like this ((abc){2})* - */ - if (trans->count >= 0) { - exec->counts[trans->count] = 0; - } - if (trans->counter >= 0) { - exec->counts[trans->counter]++; - } - exec->state = exec->comp->states[trans->to]; - exec->transno = 0; - if (trans->atom != NULL) { - exec->index += len; - } - goto progress; - } else if (ret < 0) { - exec->status = XML_REGEXP_INTERNAL_ERROR; - break; - } - } - if ((exec->transno != 0) || (exec->state->nbTrans == 0)) { -rollback: - /* - * Failed to find a way out - */ - exec->determinist = 0; - xmlFARegExecRollBack(exec); - } -progress: - continue; - } -} -#endif /************************************************************************ * * * Parser for the Schemas Datatype Regular Expressions * @@ -7299,10 +7150,6 @@ xmlExpCheckCard(xmlExpNodePtr exp, xmlExpNodePtr sub) { } else if ((exp->c_max >= 0) && (exp->c_max < sub->c_max)) { ret = 0; } -#if 0 - if ((IS_NILLABLE(sub)) && (!IS_NILLABLE(exp))) - ret = 0; -#endif return(ret); } diff --git a/xmlwriter.c b/xmlwriter.c index aa1748ce..e07dbefc 100644 --- a/xmlwriter.c +++ b/xmlwriter.c @@ -1484,10 +1484,9 @@ xmlTextWriterWriteString(xmlTextWriterPtr writer, const xmlChar * content) switch (p->state) { case XML_TEXTWRITER_NAME: case XML_TEXTWRITER_TEXT: -#if 0 - buf = NULL; - xmlOutputBufferWriteEscape(writer->out, content, NULL); -#endif + /* + * TODO: Use xmlSerializeText + */ buf = xmlEncodeSpecialChars(NULL, content); break; case XML_TEXTWRITER_ATTRIBUTE: diff --git a/xpath.c b/xpath.c index 79a4121c..35734cfd 100644 --- a/xpath.c +++ b/xpath.c @@ -2130,11 +2130,6 @@ xmlXPathPopNodeSet (xmlXPathParserContextPtr ctxt) { } obj = valuePop(ctxt); ret = obj->nodesetval; -#if 0 - /* to fix memory leak of not clearing obj->user */ - if (obj->boolval && obj->user != NULL) - xmlFreeNodeList((xmlNodePtr) obj->user); -#endif obj->nodesetval = NULL; xmlXPathReleaseObject(ctxt->context, obj); return(ret); @@ -4386,38 +4381,6 @@ xmlXPathObjectCopy(xmlXPathObjectPtr val) { } break; case XPATH_XSLT_TREE: -#if 0 -/* - Removed 11 July 2004 - the current handling of xslt tmpRVT nodes means that - this previous handling is no longer correct, and can cause some serious - problems (ref. bug 145547) -*/ - if ((val->nodesetval != NULL) && - (val->nodesetval->nodeTab != NULL)) { - xmlNodePtr cur, tmp; - xmlDocPtr top; - - ret->boolval = 1; - top = xmlNewDoc(NULL); - top->name = (char *) - xmlStrdup(val->nodesetval->nodeTab[0]->name); - ret->user = top; - if (top != NULL) { - top->doc = top; - cur = val->nodesetval->nodeTab[0]->children; - while (cur != NULL) { - tmp = xmlDocCopyNode(cur, top, 1); - xmlAddChild((xmlNodePtr) top, tmp); - cur = cur->next; - } - } - - ret->nodesetval = xmlXPathNodeSetCreate((xmlNodePtr) top); - } else - ret->nodesetval = xmlXPathNodeSetCreate(NULL); - /* Deallocate the copied tree value */ - break; -#endif case XPATH_NODESET: ret->nodesetval = xmlXPathNodeSetMerge(NULL, val->nodesetval); if (ret->nodesetval == NULL) { @@ -6554,78 +6517,6 @@ xmlXPathNextChildElement(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { return(NULL); } -#if 0 -/** - * xmlXPathNextDescendantOrSelfElemParent: - * @ctxt: the XPath Parser context - * @cur: the current node in the traversal - * - * Traversal function for the "descendant-or-self" axis. - * Additionally it returns only nodes which can be parents of - * element nodes. - * - * - * Returns the next element following that axis - */ -static xmlNodePtr -xmlXPathNextDescendantOrSelfElemParent(xmlNodePtr cur, - xmlNodePtr contextNode) -{ - if (cur == NULL) { - if (contextNode == NULL) - return(NULL); - switch (contextNode->type) { - case XML_ELEMENT_NODE: - case XML_XINCLUDE_START: - case XML_DOCUMENT_FRAG_NODE: - case XML_DOCUMENT_NODE: - case XML_HTML_DOCUMENT_NODE: - return(contextNode); - default: - return(NULL); - } - return(NULL); - } else { - xmlNodePtr start = cur; - - while (cur != NULL) { - switch (cur->type) { - case XML_ELEMENT_NODE: - /* TODO: OK to have XInclude here? */ - case XML_XINCLUDE_START: - case XML_DOCUMENT_FRAG_NODE: - if (cur != start) - return(cur); - if (cur->children != NULL) { - cur = cur->children; - continue; - } - break; - /* Not sure if we need those here. */ - case XML_DOCUMENT_NODE: - case XML_HTML_DOCUMENT_NODE: - if (cur != start) - return(cur); - return(xmlDocGetRootElement((xmlDocPtr) cur)); - default: - break; - } - -next_sibling: - if ((cur == NULL) || (cur == contextNode)) - return(NULL); - if (cur->next != NULL) { - cur = cur->next; - } else { - cur = cur->parent; - goto next_sibling; - } - } - } - return(NULL); -} -#endif - /** * xmlXPathNextDescendant: * @ctxt: the XPath Parser context @@ -9945,16 +9836,7 @@ xmlXPathCompNodeTest(xmlXPathParserContextPtr ctxt, xmlXPathTestVal *test, * only at evaluation time. The compilation is done * outside of any context. */ -#if 0 - *prefix = xmlXPathNsLookup(ctxt->context, name); - if (name != NULL) - xmlFree(name); - if (*prefix == NULL) { - XP_ERROR0(XPATH_UNDEF_PREFIX_ERROR); - } -#else *prefix = name; -#endif if (CUR == '*') { /* @@ -11969,9 +11851,6 @@ xmlXPathRunStreamEval(xmlXPathParserContextPtr pctxt, xmlPatternPtr comp, from_root = xmlPatternFromRoot(comp); if (from_root < 0) return(-1); -#if 0 - printf("stream eval: depth %d from root %d\n", max_depth, from_root); -#endif if (! toBool) { if (resultSeq == NULL)