From fc0b6f6adac16ea1bf2ca3bfe935e67d9e9fb974 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Sun, 9 Jan 2005 17:48:02 +0000 Subject: [PATCH] William noticed I forgot to add special support for xmlmodules.c define * gentest.py testapi.c: William noticed I forgot to add special support for xmlmodules.c define * xmlregexp.c include/libxml/xmlregexp.h: added terminal to xmlRegExecErrInfo() API, adding new xmlRegExecNextValues() entry point and refactored to use both code. Daniel --- ChangeLog | 8 +++ gentest.py | 1 + include/libxml/xmlregexp.h | 11 +++ testapi.c | 3 + xmlregexp.c | 137 ++++++++++++++++++++++++++++--------- 5 files changed, 129 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index 35ac9e4f..32bde04c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Sun Jan 9 18:46:32 CET 2005 Daniel Veillard + + * gentest.py testapi.c: William noticed I forgot to add special + support for xmlmodules.c define + * xmlregexp.c include/libxml/xmlregexp.h: added terminal to + xmlRegExecErrInfo() API, adding new xmlRegExecNextValues() + entry point and refactored to use both code. + Mon Jan 10 01:02:41 HKT 2006 William Brack * doc/xml.html, doc/FAQ.html: added an FAQ under Developer for diff --git a/gentest.py b/gentest.py index c48c7b93..12dd718f 100755 --- a/gentest.py +++ b/gentest.py @@ -44,6 +44,7 @@ modules_defines = { "xmlautomata" : "LIBXML_AUTOMATA_ENABLED", "xmlsave" : "LIBXML_OUTPUT_ENABLED", "DOCBparser" : "LIBXML_DOCB_ENABLED", + "xmlmodule" : "LIBXML_MODULES_ENABLED", } # diff --git a/include/libxml/xmlregexp.h b/include/libxml/xmlregexp.h index 6a9bcf1f..7c69fbb7 100644 --- a/include/libxml/xmlregexp.h +++ b/include/libxml/xmlregexp.h @@ -86,6 +86,17 @@ XMLPUBFUN int XMLCALL const xmlChar *value2, void *data); +XMLPUBFUN int XMLCALL + xmlRegExecNextValues(xmlRegExecCtxtPtr exec, + int *nbval, + xmlChar **values, + int *terminal); +XMLPUBFUN int XMLCALL + xmlRegExecErrInfo (xmlRegExecCtxtPtr exec, + const xmlChar **string, + int *nbval, + xmlChar **values, + int *terminal); #ifdef __cplusplus } #endif diff --git a/testapi.c b/testapi.c index e7a34f23..11b7071c 100644 --- a/testapi.c +++ b/testapi.c @@ -28217,6 +28217,7 @@ test_xmlerror(void) { printf("Module xmlerror: %d errors\n", test_ret); return(test_ret); } +#ifdef LIBXML_MODULES_ENABLED #define gen_nb_xmlModulePtr 1 static xmlModulePtr gen_xmlModulePtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { @@ -28224,6 +28225,8 @@ static xmlModulePtr gen_xmlModulePtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_U } static void des_xmlModulePtr(int no ATTRIBUTE_UNUSED, xmlModulePtr val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { } +#endif + static int test_xmlModuleClose(void) { diff --git a/xmlregexp.c b/xmlregexp.c index 6ef0d9eb..099f68ca 100644 --- a/xmlregexp.c +++ b/xmlregexp.c @@ -19,6 +19,8 @@ #ifdef LIBXML_REGEXP_ENABLED +#define DEBUG_ERR + #include #include #ifdef HAVE_LIMITS_H @@ -3107,37 +3109,26 @@ xmlRegExecPushString2(xmlRegExecCtxtPtr exec, const xmlChar *value, } /** - * xmlRegExecErrInfo: - * @exec: a regexp execution context generating an error - * @string: return value for the error string + * xmlRegExecGetalues: + * @exec: a regexp execution context + * @err: error extraction or normal one * @nbval: pointer to the number of accepted values IN/OUT * @values: pointer to the array of acceptable values + * @terminal: return value if this was a terminal state * - * Extract error informations from the regexp execution, the parameter - * @string will be updated with the value pushed and not accepted, - * the parameter @values must point to an array of @nbval string pointers - * on return nbval will contain the number of possible strings in that - * state and the @values array will be updated with them. The string values - * returned will be freed with the @exec context and don't need to be - * deallocated. + * Extract informations from the regexp execution, internal routine to + * implement xmlRegExecNextValues() and xmlRegExecErrInfo() * * Returns: 0 in case of success or -1 in case of error. */ -int -xmlRegExecErrInfo(xmlRegExecCtxtPtr exec, const xmlChar **string, - int *nbval, xmlChar **values) { +static int +xmlRegExecGetValues(xmlRegExecCtxtPtr exec, int err, + int *nbval, xmlChar **values, int *terminal) { int maxval; - if (exec == NULL) - return(-1); - if (string != NULL) { - if (exec->status != 0) - *string = exec->errString; - else - *string = NULL; - } - if ((nbval == NULL) || (values == NULL) || (*nbval <= 0)) + if ((exec == NULL) || (nbval == NULL) || (values == NULL) || (*nbval <= 0)) return(-1); + maxval = *nbval; *nbval = 0; if ((exec->comp != NULL) && (exec->comp->compact != NULL)) { @@ -3145,8 +3136,20 @@ xmlRegExecErrInfo(xmlRegExecCtxtPtr exec, const xmlChar **string, int target, i, state; comp = exec->comp; - if (exec->errStateNo == -1) return(-1); - state = exec->errStateNo; + + if (err) { + if (exec->errStateNo == -1) return(-1); + state = exec->errStateNo; + } else { + state = exec->index; + } + if (terminal != NULL) { + if (comp->compact[state * (comp->nbstrings + 1)] == + XML_REGEXP_FINAL_STATE) + *terminal = 1; + else + *terminal = 0; + } for (i = 0;(i < comp->nbstrings) && (*nbval < maxval);i++) { target = comp->compact[state * (comp->nbstrings + 1) + i + 1]; if ((target > 0) && (target <= comp->nbstates)) { @@ -3158,12 +3161,26 @@ xmlRegExecErrInfo(xmlRegExecCtxtPtr exec, const xmlChar **string, int transno; xmlRegTransPtr trans; xmlRegAtomPtr atom; + xmlRegStatePtr state; - if (exec->errState == NULL) return(-1); + if (terminal != NULL) { + if (exec->state->type == XML_REGEXP_FINAL_STATE) + *terminal = 1; + else + *terminal = 0; + } + + if (err) { + if (exec->errState == NULL) return(-1); + state = exec->errState; + } else { + if (exec->state == NULL) return(-1); + state = exec->state; + } for (transno = 0; - (transno < exec->errState->nbTrans) && (*nbval < maxval); + (transno < state->nbTrans) && (*nbval < maxval); transno++) { - trans = &exec->errState->trans[transno]; + trans = &state->trans[transno]; if (trans->to < 0) continue; atom = trans->atom; @@ -3177,14 +3194,17 @@ xmlRegExecErrInfo(xmlRegExecCtxtPtr exec, const xmlChar **string, xmlRegCounterPtr counter; int count; - count = exec->errCounts[trans->counter]; + if (err) + count = exec->errCounts[trans->counter]; + else + count = exec->counts[trans->counter]; counter = &exec->comp->counters[trans->counter]; if (count < counter->max) { - values[*nbval] = (const xmlChar *) atom->valuep; + values[*nbval] = (xmlChar *) atom->valuep; (*nbval)++; } } else { - values[*nbval] = (const xmlChar *) atom->valuep; + values[*nbval] = (xmlChar *) atom->valuep; (*nbval)++; } } @@ -3192,12 +3212,67 @@ xmlRegExecErrInfo(xmlRegExecCtxtPtr exec, const xmlChar **string, return(0); } +/** + * xmlRegExecNextValues: + * @exec: a regexp execution context + * @nbval: pointer to the number of accepted values IN/OUT + * @values: pointer to the array of acceptable values + * @terminal: return value if this was a terminal state + * + * Extract informations from the regexp execution, + * the parameter @values must point to an array of @nbval string pointers + * on return nbval will contain the number of possible strings in that + * state and the @values array will be updated with them. The string values + * returned will be freed with the @exec context and don't need to be + * deallocated. + * + * Returns: 0 in case of success or -1 in case of error. + */ +int +xmlRegExecNextValues(xmlRegExecCtxtPtr exec, int *nbval, xmlChar **values, + int *terminal) { + return(xmlRegExecGetValues(exec, 0, nbval, values, terminal)); +} + +/** + * xmlRegExecErrInfo: + * @exec: a regexp execution context generating an error + * @string: return value for the error string + * @nbval: pointer to the number of accepted values IN/OUT + * @values: pointer to the array of acceptable values + * @terminal: return value if this was a terminal state + * + * Extract error informations from the regexp execution, the parameter + * @string will be updated with the value pushed and not accepted, + * the parameter @values must point to an array of @nbval string pointers + * on return nbval will contain the number of possible strings in that + * state and the @values array will be updated with them. The string values + * returned will be freed with the @exec context and don't need to be + * deallocated. + * + * Returns: 0 in case of success or -1 in case of error. + */ +int +xmlRegExecErrInfo(xmlRegExecCtxtPtr exec, const xmlChar **string, + int *nbval, xmlChar **values, int *terminal) { + if (exec == NULL) + return(-1); + if (string != NULL) { + if (exec->status != 0) + *string = exec->errString; + else + *string = NULL; + } + return(xmlRegExecGetValues(exec, 1, nbval, values, terminal)); +} + #ifdef DEBUG_ERR static void testerr(xmlRegExecCtxtPtr exec) { const xmlChar *string; const xmlChar *values[5]; int nb = 5; - xmlRegExecErrInfo(exec, &string, &nb, &values[0]); + int terminal; + xmlRegExecErrInfo(exec, &string, &nb, &values[0], &terminal); } #endif