Incorporate most recent changes from upstream tre-regex repository
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
6b5f58dbf8
commit
52dadacdbe
|
@ -31,23 +31,27 @@
|
|||
#define _(String) dgettext(PACKAGE, String)
|
||||
#define gettext_noop(String) String
|
||||
|
||||
#define xstr(s) str(s)
|
||||
#define str(s) #s
|
||||
|
||||
/* Error message strings for error codes listed in `tre.h'. This list
|
||||
needs to be in sync with the codes listed there, naturally. */
|
||||
static const char *tre_error_messages[] =
|
||||
{ gettext_noop("No error"), /* REG_OK */
|
||||
gettext_noop("No match"), /* REG_NOMATCH */
|
||||
gettext_noop("Invalid regexp"), /* REG_BADPAT */
|
||||
gettext_noop("Unknown collating element"), /* REG_ECOLLATE */
|
||||
gettext_noop("Unknown character class name"), /* REG_ECTYPE */
|
||||
gettext_noop("Trailing backslash"), /* REG_EESCAPE */
|
||||
gettext_noop("Invalid back reference"), /* REG_ESUBREG */
|
||||
gettext_noop("Missing ']'"), /* REG_EBRACK */
|
||||
gettext_noop("Missing ')'"), /* REG_EPAREN */
|
||||
gettext_noop("Missing '}'"), /* REG_EBRACE */
|
||||
gettext_noop("Invalid contents of {}"), /* REG_BADBR */
|
||||
gettext_noop("Invalid character range"), /* REG_ERANGE */
|
||||
gettext_noop("Out of memory"), /* REG_ESPACE */
|
||||
gettext_noop("Invalid use of repetition operators") /* REG_BADRPT */
|
||||
{ gettext_noop("No error"), /* REG_OK */
|
||||
gettext_noop("No match"), /* REG_NOMATCH */
|
||||
gettext_noop("Invalid regexp"), /* REG_BADPAT */
|
||||
gettext_noop("Unknown collating element"), /* REG_ECOLLATE */
|
||||
gettext_noop("Unknown character class name"), /* REG_ECTYPE */
|
||||
gettext_noop("Trailing backslash"), /* REG_EESCAPE */
|
||||
gettext_noop("Invalid back reference"), /* REG_ESUBREG */
|
||||
gettext_noop("Missing ']'"), /* REG_EBRACK */
|
||||
gettext_noop("Missing ')'"), /* REG_EPAREN */
|
||||
gettext_noop("Missing '}'"), /* REG_EBRACE */
|
||||
gettext_noop("Invalid contents of {}"), /* REG_BADBR */
|
||||
gettext_noop("Invalid character range"), /* REG_ERANGE */
|
||||
gettext_noop("Out of memory"), /* REG_ESPACE */
|
||||
gettext_noop("Invalid use of repetition operators"), /* REG_BADRPT */
|
||||
gettext_noop("Maximum repetition in {} larger than " xstr(RE_DUP_MAX)), /* REG_BADMAX */
|
||||
};
|
||||
|
||||
size_t
|
||||
|
|
|
@ -6,9 +6,6 @@
|
|||
|
||||
*/
|
||||
|
||||
#include "tre-config.h"
|
||||
#include "tre-internal.h"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
@ -765,10 +762,10 @@ tre_tnfa_run_approx(const tre_tnfa_t *tnfa, const void *string, int len,
|
|||
default_params);
|
||||
|
||||
/* Set the costs after this transition. */
|
||||
memcpy(&reach_next[dest_id].costs,
|
||||
reach[id].costs,
|
||||
sizeof(reach[id].costs[0][0])
|
||||
* TRE_M_LAST * (depth + 1));
|
||||
memcpy(&reach_next[dest_id].costs,
|
||||
reach[id].costs,
|
||||
sizeof(reach[id].costs[0][0])
|
||||
* TRE_M_LAST * (depth + 1));
|
||||
reach_next[dest_id].costs[depth][TRE_M_COST] = cost;
|
||||
reach_next[dest_id].costs[depth][TRE_M_NUM_SUBST] += err;
|
||||
reach_next[dest_id].costs[depth][TRE_M_NUM_ERR] += err;
|
||||
|
|
|
@ -29,9 +29,6 @@
|
|||
|
||||
*/
|
||||
|
||||
#include "tre-config.h"
|
||||
#include "tre-internal.h"
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
|
@ -117,11 +114,13 @@ typedef struct tre_backtrack_struct {
|
|||
#ifdef TRE_USE_ALLOCA
|
||||
#define tre_bt_mem_new tre_mem_newa
|
||||
#define tre_bt_mem_alloc tre_mem_alloca
|
||||
#define tre_bt_mem_destroy(obj) do { } while (0,0)
|
||||
#define tre_bt_mem_destroy(obj) do { } while (0)
|
||||
#define xafree(obj) /* do nothing, obj was obtained with alloca() */
|
||||
#else /* !TRE_USE_ALLOCA */
|
||||
#define tre_bt_mem_new tre_mem_new
|
||||
#define tre_bt_mem_alloc tre_mem_alloc
|
||||
#define tre_bt_mem_destroy tre_mem_destroy
|
||||
#define xafree(obj) xfree(obj)
|
||||
#endif /* !TRE_USE_ALLOCA */
|
||||
|
||||
|
||||
|
@ -137,11 +136,11 @@ typedef struct tre_backtrack_struct {
|
|||
{ \
|
||||
tre_bt_mem_destroy(mem); \
|
||||
if (tags) \
|
||||
xfree(tags); \
|
||||
xafree(tags); \
|
||||
if (pmatch) \
|
||||
xfree(pmatch); \
|
||||
xafree(pmatch); \
|
||||
if (states_seen) \
|
||||
xfree(states_seen); \
|
||||
xafree(states_seen); \
|
||||
return REG_ESPACE; \
|
||||
} \
|
||||
s->prev = stack; \
|
||||
|
@ -152,11 +151,11 @@ typedef struct tre_backtrack_struct {
|
|||
{ \
|
||||
tre_bt_mem_destroy(mem); \
|
||||
if (tags) \
|
||||
xfree(tags); \
|
||||
xafree(tags); \
|
||||
if (pmatch) \
|
||||
xfree(pmatch); \
|
||||
xafree(pmatch); \
|
||||
if (states_seen) \
|
||||
xfree(states_seen); \
|
||||
xafree(states_seen); \
|
||||
return REG_ESPACE; \
|
||||
} \
|
||||
stack->next = s; \
|
||||
|
@ -427,7 +426,7 @@ tre_tnfa_run_backtrack(const tre_tnfa_t *tnfa, const void *string,
|
|||
DPRINT((" should match back reference %d\n", bt));
|
||||
/* Get the substring we need to match against. Remember to
|
||||
turn off REG_NOSUB temporarily. */
|
||||
tre_fill_pmatch(bt + 1, pmatch, tnfa->cflags & /*LINTED*/!REG_NOSUB,
|
||||
tre_fill_pmatch(bt + 1, pmatch, tnfa->cflags & ~REG_NOSUB,
|
||||
tnfa, tags, pos);
|
||||
so = pmatch[bt].rm_so;
|
||||
eo = pmatch[bt].rm_eo;
|
||||
|
@ -603,7 +602,7 @@ tre_tnfa_run_backtrack(const tre_tnfa_t *tnfa, const void *string,
|
|||
if (stack->prev)
|
||||
{
|
||||
DPRINT((" backtracking\n"));
|
||||
if (stack->item.state->assertions && ASSERT_BACKREF)
|
||||
if (stack->item.state->assertions & ASSERT_BACKREF)
|
||||
{
|
||||
DPRINT((" states_seen[%d] = 0\n",
|
||||
stack->item.state_id));
|
||||
|
@ -658,11 +657,11 @@ tre_tnfa_run_backtrack(const tre_tnfa_t *tnfa, const void *string,
|
|||
tre_bt_mem_destroy(mem);
|
||||
#ifndef TRE_USE_ALLOCA
|
||||
if (tags)
|
||||
xfree(tags);
|
||||
xafree(tags);
|
||||
if (pmatch)
|
||||
xfree(pmatch);
|
||||
xafree(pmatch);
|
||||
if (states_seen)
|
||||
xfree(states_seen);
|
||||
xafree(states_seen);
|
||||
#endif /* !TRE_USE_ALLOCA */
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -628,8 +628,10 @@ tre_parse_bound(tre_parse_ctx_t *ctx, tre_ast_node_t **result)
|
|||
}
|
||||
|
||||
/* Check that the repeat counts are sane. */
|
||||
if ((max >= 0 && min > max) || max > RE_DUP_MAX)
|
||||
if (max >= 0 && min > max)
|
||||
return REG_BADBR;
|
||||
if (max > RE_DUP_MAX)
|
||||
return REG_BADMAX;
|
||||
|
||||
|
||||
/*
|
||||
|
@ -1340,8 +1342,8 @@ tre_parse(tre_parse_ctx_t *ctx)
|
|||
break;
|
||||
|
||||
case CHAR_RPAREN: /* end of current subexpression */
|
||||
if ((ctx->cflags & REG_EXTENDED && depth > 0)
|
||||
|| (ctx->re > ctx->re_start
|
||||
if (((ctx->cflags & REG_EXTENDED) && depth > 0)
|
||||
|| (!(ctx->cflags & REG_EXTENDED) && ctx->re > ctx->re_start
|
||||
&& *(ctx->re - 1) == CHAR_BACKSLASH))
|
||||
{
|
||||
DPRINT(("tre_parse: empty: '%.*" STRF "'\n",
|
||||
|
|
|
@ -54,6 +54,8 @@ typedef int reg_errcode_t;
|
|||
#define REG_RIGHT_ASSOC (REG_LITERAL << 1)
|
||||
#define REG_UNGREEDY (REG_RIGHT_ASSOC << 1)
|
||||
|
||||
#define REG_USEBYTES (REG_UNGREEDY << 1)
|
||||
|
||||
/* Extra tre_regexec() flags. */
|
||||
#define REG_APPROX_MATCHER 0x1000
|
||||
#define REG_BACKTRACKING_MATCHER (REG_APPROX_MATCHER << 1)
|
||||
|
@ -91,7 +93,8 @@ typedef enum {
|
|||
REG_BADBR, /* Invalid content of {} */
|
||||
REG_ERANGE, /* Invalid use of range operator */
|
||||
REG_ESPACE, /* Out of memory. */
|
||||
REG_BADRPT /* Invalid use of repetition operators. */
|
||||
REG_BADRPT, /* Invalid use of repetition operators. */
|
||||
REG_BADMAX, /* Maximum repetition in {} too large */
|
||||
} reg_errcode_t;
|
||||
|
||||
/* POSIX tre_regcomp() flags. */
|
||||
|
@ -105,7 +108,6 @@ typedef enum {
|
|||
#define REG_LITERAL (REG_NOSUB << 1)
|
||||
#define REG_RIGHT_ASSOC (REG_LITERAL << 1)
|
||||
#define REG_UNGREEDY (REG_RIGHT_ASSOC << 1)
|
||||
|
||||
#define REG_USEBYTES (REG_UNGREEDY << 1)
|
||||
|
||||
/* POSIX tre_regexec() flags. */
|
||||
|
|
Loading…
Reference in New Issue