summaryrefslogtreecommitdiff
path: root/src/regcomp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/regcomp.c')
-rw-r--r--src/regcomp.c608
1 files changed, 319 insertions, 289 deletions
diff --git a/src/regcomp.c b/src/regcomp.c
index 8b5b206..5c0f21f 100644
--- a/src/regcomp.c
+++ b/src/regcomp.c
@@ -89,8 +89,8 @@ swap_node(Node* a, Node* b)
}
}
-static OnigDistance
-distance_add(OnigDistance d1, OnigDistance d2)
+static OnigLen
+distance_add(OnigLen d1, OnigLen d2)
{
if (d1 == ONIG_INFINITE_DISTANCE || d2 == ONIG_INFINITE_DISTANCE)
return ONIG_INFINITE_DISTANCE;
@@ -100,8 +100,8 @@ distance_add(OnigDistance d1, OnigDistance d2)
}
}
-static OnigDistance
-distance_multiply(OnigDistance d, int m)
+static OnigLen
+distance_multiply(OnigLen d, int m)
{
if (m == 0) return 0;
@@ -2021,245 +2021,6 @@ quantifiers_memory_node_info(Node* node)
}
#endif /* USE_MONOMANIAC_CHECK_CAPTURES_IN_ENDLESS_REPEAT */
-static int
-get_min_match_length(Node* node, OnigDistance *min, ScanEnv* env)
-{
- OnigDistance tmin;
- int r = 0;
-
- *min = 0;
- switch (NTYPE(node)) {
- case NT_BREF:
- {
- int i;
- int* backs;
- Node** nodes = SCANENV_MEM_NODES(env);
- BRefNode* br = NBREF(node);
- if (br->state & NST_RECURSION) break;
-
- backs = BACKREFS_P(br);
- if (backs[0] > env->num_mem) return ONIGERR_INVALID_BACKREF;
- r = get_min_match_length(nodes[backs[0]], min, env);
- if (r != 0) break;
- for (i = 1; i < br->back_num; i++) {
- if (backs[i] > env->num_mem) return ONIGERR_INVALID_BACKREF;
- r = get_min_match_length(nodes[backs[i]], &tmin, env);
- if (r != 0) break;
- if (*min > tmin) *min = tmin;
- }
- }
- break;
-
-#ifdef USE_SUBEXP_CALL
- case NT_CALL:
- if (IS_CALL_RECURSION(NCALL(node))) {
- EncloseNode* en = NENCLOSE(NCALL(node)->target);
- if (IS_ENCLOSE_MIN_FIXED(en))
- *min = en->min_len;
- }
- else
- r = get_min_match_length(NCALL(node)->target, min, env);
- break;
-#endif
-
- case NT_LIST:
- do {
- r = get_min_match_length(NCAR(node), &tmin, env);
- if (r == 0) *min += tmin;
- } while (r == 0 && IS_NOT_NULL(node = NCDR(node)));
- break;
-
- case NT_ALT:
- {
- Node *x, *y;
- y = node;
- do {
- x = NCAR(y);
- r = get_min_match_length(x, &tmin, env);
- if (r != 0) break;
- if (y == node) *min = tmin;
- else if (*min > tmin) *min = tmin;
- } while (r == 0 && IS_NOT_NULL(y = NCDR(y)));
- }
- break;
-
- case NT_STR:
- {
- StrNode* sn = NSTR(node);
- *min = sn->end - sn->s;
- }
- break;
-
- case NT_CTYPE:
- *min = 1;
- break;
-
- case NT_CCLASS:
- case NT_CANY:
- *min = 1;
- break;
-
- case NT_QTFR:
- {
- QtfrNode* qn = NQTFR(node);
-
- if (qn->lower > 0) {
- r = get_min_match_length(qn->target, min, env);
- if (r == 0)
- *min = distance_multiply(*min, qn->lower);
- }
- }
- break;
-
- case NT_ENCLOSE:
- {
- EncloseNode* en = NENCLOSE(node);
- switch (en->type) {
- case ENCLOSE_MEMORY:
-#ifdef USE_SUBEXP_CALL
- if (IS_ENCLOSE_MIN_FIXED(en))
- *min = en->min_len;
- else {
- r = get_min_match_length(en->target, min, env);
- if (r == 0) {
- en->min_len = *min;
- SET_ENCLOSE_STATUS(node, NST_MIN_FIXED);
- }
- }
- break;
-#endif
- case ENCLOSE_OPTION:
- case ENCLOSE_STOP_BACKTRACK:
- r = get_min_match_length(en->target, min, env);
- break;
- }
- }
- break;
-
- case NT_ANCHOR:
- default:
- break;
- }
-
- return r;
-}
-
-static int
-get_max_match_length(Node* node, OnigDistance *max, ScanEnv* env)
-{
- OnigDistance tmax;
- int r = 0;
-
- *max = 0;
- switch (NTYPE(node)) {
- case NT_LIST:
- do {
- r = get_max_match_length(NCAR(node), &tmax, env);
- if (r == 0)
- *max = distance_add(*max, tmax);
- } while (r == 0 && IS_NOT_NULL(node = NCDR(node)));
- break;
-
- case NT_ALT:
- do {
- r = get_max_match_length(NCAR(node), &tmax, env);
- if (r == 0 && *max < tmax) *max = tmax;
- } while (r == 0 && IS_NOT_NULL(node = NCDR(node)));
- break;
-
- case NT_STR:
- {
- StrNode* sn = NSTR(node);
- *max = sn->end - sn->s;
- }
- break;
-
- case NT_CTYPE:
- *max = ONIGENC_MBC_MAXLEN_DIST(env->enc);
- break;
-
- case NT_CCLASS:
- case NT_CANY:
- *max = ONIGENC_MBC_MAXLEN_DIST(env->enc);
- break;
-
- case NT_BREF:
- {
- int i;
- int* backs;
- Node** nodes = SCANENV_MEM_NODES(env);
- BRefNode* br = NBREF(node);
- if (br->state & NST_RECURSION) {
- *max = ONIG_INFINITE_DISTANCE;
- break;
- }
- backs = BACKREFS_P(br);
- for (i = 0; i < br->back_num; i++) {
- if (backs[i] > env->num_mem) return ONIGERR_INVALID_BACKREF;
- r = get_max_match_length(nodes[backs[i]], &tmax, env);
- if (r != 0) break;
- if (*max < tmax) *max = tmax;
- }
- }
- break;
-
-#ifdef USE_SUBEXP_CALL
- case NT_CALL:
- if (! IS_CALL_RECURSION(NCALL(node)))
- r = get_max_match_length(NCALL(node)->target, max, env);
- else
- *max = ONIG_INFINITE_DISTANCE;
- break;
-#endif
-
- case NT_QTFR:
- {
- QtfrNode* qn = NQTFR(node);
-
- if (qn->upper != 0) {
- r = get_max_match_length(qn->target, max, env);
- if (r == 0 && *max != 0) {
- if (! IS_REPEAT_INFINITE(qn->upper))
- *max = distance_multiply(*max, qn->upper);
- else
- *max = ONIG_INFINITE_DISTANCE;
- }
- }
- }
- break;
-
- case NT_ENCLOSE:
- {
- EncloseNode* en = NENCLOSE(node);
- switch (en->type) {
- case ENCLOSE_MEMORY:
-#ifdef USE_SUBEXP_CALL
- if (IS_ENCLOSE_MAX_FIXED(en))
- *max = en->max_len;
- else {
- r = get_max_match_length(en->target, max, env);
- if (r == 0) {
- en->max_len = *max;
- SET_ENCLOSE_STATUS(node, NST_MAX_FIXED);
- }
- }
- break;
-#endif
- case ENCLOSE_OPTION:
- case ENCLOSE_STOP_BACKTRACK:
- r = get_max_match_length(en->target, max, env);
- break;
- }
- }
- break;
-
- case NT_ANCHOR:
- default:
- break;
- }
-
- return r;
-}
#define GET_CHAR_LEN_VARLEN -1
#define GET_CHAR_LEN_TOP_ALT_VARLEN -2
@@ -2706,6 +2467,257 @@ check_type_tree(Node* node, int type_mask, int enclose_mask, int anchor_mask)
return r;
}
+static int
+get_min_len(Node* node, OnigLen *min, ScanEnv* env)
+{
+ OnigLen tmin;
+ int r = 0;
+
+ *min = 0;
+ switch (NTYPE(node)) {
+ case NT_BREF:
+ {
+ int i;
+ int* backs;
+ Node** nodes = SCANENV_MEM_NODES(env);
+ BRefNode* br = NBREF(node);
+ if (br->state & NST_RECURSION) break;
+
+ backs = BACKREFS_P(br);
+ if (backs[0] > env->num_mem) return ONIGERR_INVALID_BACKREF;
+ r = get_min_len(nodes[backs[0]], min, env);
+ if (r != 0) break;
+ for (i = 1; i < br->back_num; i++) {
+ if (backs[i] > env->num_mem) return ONIGERR_INVALID_BACKREF;
+ r = get_min_len(nodes[backs[i]], &tmin, env);
+ if (r != 0) break;
+ if (*min > tmin) *min = tmin;
+ }
+ }
+ break;
+
+#ifdef USE_SUBEXP_CALL
+ case NT_CALL:
+ if (IS_CALL_RECURSION(NCALL(node))) {
+ EncloseNode* en = NENCLOSE(NCALL(node)->target);
+ if (IS_ENCLOSE_MIN_FIXED(en))
+ *min = en->min_len;
+ }
+ else
+ r = get_min_len(NCALL(node)->target, min, env);
+ break;
+#endif
+
+ case NT_LIST:
+ do {
+ r = get_min_len(NCAR(node), &tmin, env);
+ if (r == 0) *min += tmin;
+ } while (r == 0 && IS_NOT_NULL(node = NCDR(node)));
+ break;
+
+ case NT_ALT:
+ {
+ Node *x, *y;
+ y = node;
+ do {
+ x = NCAR(y);
+ r = get_min_len(x, &tmin, env);
+ if (r != 0) break;
+ if (y == node) *min = tmin;
+ else if (*min > tmin) *min = tmin;
+ } while (r == 0 && IS_NOT_NULL(y = NCDR(y)));
+ }
+ break;
+
+ case NT_STR:
+ {
+ StrNode* sn = NSTR(node);
+ *min = sn->end - sn->s;
+ }
+ break;
+
+ case NT_CTYPE:
+ *min = 1;
+ break;
+
+ case NT_CCLASS:
+ case NT_CANY:
+ *min = 1;
+ break;
+
+ case NT_QTFR:
+ {
+ QtfrNode* qn = NQTFR(node);
+
+ if (qn->lower > 0) {
+ r = get_min_len(qn->target, min, env);
+ if (r == 0)
+ *min = distance_multiply(*min, qn->lower);
+ }
+ }
+ break;
+
+ case NT_ENCLOSE:
+ {
+ EncloseNode* en = NENCLOSE(node);
+ switch (en->type) {
+ case ENCLOSE_MEMORY:
+ if (IS_ENCLOSE_MIN_FIXED(en))
+ *min = en->min_len;
+ else {
+ if (IS_ENCLOSE_MARK1(NENCLOSE(node)))
+ *min = 0; // recursive
+ else {
+ SET_ENCLOSE_STATUS(node, NST_MARK1);
+ r = get_min_len(en->target, min, env);
+ CLEAR_ENCLOSE_STATUS(node, NST_MARK1);
+ if (r == 0) {
+ en->min_len = *min;
+ SET_ENCLOSE_STATUS(node, NST_MIN_FIXED);
+ }
+ }
+ }
+ break;
+
+ case ENCLOSE_OPTION:
+ case ENCLOSE_STOP_BACKTRACK:
+ r = get_min_len(en->target, min, env);
+ break;
+ }
+ }
+ break;
+
+ case NT_ANCHOR:
+ default:
+ break;
+ }
+
+ return r;
+}
+
+static int
+get_max_len(Node* node, OnigLen *max, ScanEnv* env)
+{
+ OnigLen tmax;
+ int r = 0;
+
+ *max = 0;
+ switch (NTYPE(node)) {
+ case NT_LIST:
+ do {
+ r = get_max_len(NCAR(node), &tmax, env);
+ if (r == 0)
+ *max = distance_add(*max, tmax);
+ } while (r == 0 && IS_NOT_NULL(node = NCDR(node)));
+ break;
+
+ case NT_ALT:
+ do {
+ r = get_max_len(NCAR(node), &tmax, env);
+ if (r == 0 && *max < tmax) *max = tmax;
+ } while (r == 0 && IS_NOT_NULL(node = NCDR(node)));
+ break;
+
+ case NT_STR:
+ {
+ StrNode* sn = NSTR(node);
+ *max = sn->end - sn->s;
+ }
+ break;
+
+ case NT_CTYPE:
+ *max = ONIGENC_MBC_MAXLEN_DIST(env->enc);
+ break;
+
+ case NT_CCLASS:
+ case NT_CANY:
+ *max = ONIGENC_MBC_MAXLEN_DIST(env->enc);
+ break;
+
+ case NT_BREF:
+ {
+ int i;
+ int* backs;
+ Node** nodes = SCANENV_MEM_NODES(env);
+ BRefNode* br = NBREF(node);
+ if (br->state & NST_RECURSION) {
+ *max = ONIG_INFINITE_DISTANCE;
+ break;
+ }
+ backs = BACKREFS_P(br);
+ for (i = 0; i < br->back_num; i++) {
+ if (backs[i] > env->num_mem) return ONIGERR_INVALID_BACKREF;
+ r = get_max_len(nodes[backs[i]], &tmax, env);
+ if (r != 0) break;
+ if (*max < tmax) *max = tmax;
+ }
+ }
+ break;
+
+#ifdef USE_SUBEXP_CALL
+ case NT_CALL:
+ if (! IS_CALL_RECURSION(NCALL(node)))
+ r = get_max_len(NCALL(node)->target, max, env);
+ else
+ *max = ONIG_INFINITE_DISTANCE;
+ break;
+#endif
+
+ case NT_QTFR:
+ {
+ QtfrNode* qn = NQTFR(node);
+
+ if (qn->upper != 0) {
+ r = get_max_len(qn->target, max, env);
+ if (r == 0 && *max != 0) {
+ if (! IS_REPEAT_INFINITE(qn->upper))
+ *max = distance_multiply(*max, qn->upper);
+ else
+ *max = ONIG_INFINITE_DISTANCE;
+ }
+ }
+ }
+ break;
+
+ case NT_ENCLOSE:
+ {
+ EncloseNode* en = NENCLOSE(node);
+ switch (en->type) {
+ case ENCLOSE_MEMORY:
+ if (IS_ENCLOSE_MAX_FIXED(en))
+ *max = en->max_len;
+ else {
+ if (IS_ENCLOSE_MARK1(NENCLOSE(node)))
+ *max = ONIG_INFINITE_DISTANCE;
+ else {
+ SET_ENCLOSE_STATUS(node, NST_MARK1);
+ r = get_max_len(en->target, max, env);
+ CLEAR_ENCLOSE_STATUS(node, NST_MARK1);
+ if (r == 0) {
+ en->max_len = *max;
+ SET_ENCLOSE_STATUS(node, NST_MAX_FIXED);
+ }
+ }
+ }
+ break;
+
+ case ENCLOSE_OPTION:
+ case ENCLOSE_STOP_BACKTRACK:
+ r = get_max_len(en->target, max, env);
+ break;
+ }
+ }
+ break;
+
+ case NT_ANCHOR:
+ default:
+ break;
+ }
+
+ return r;
+}
+
+
#ifdef USE_SUBEXP_CALL
#define RECURSION_EXIST 1
@@ -2722,7 +2734,7 @@ subexp_inf_recursive_check(Node* node, ScanEnv* env, int head)
case NT_LIST:
{
Node *x;
- OnigDistance min;
+ OnigLen min;
int ret;
x = node;
@@ -2731,7 +2743,7 @@ subexp_inf_recursive_check(Node* node, ScanEnv* env, int head)
if (ret < 0 || ret == RECURSION_INFINITE) return ret;
r |= ret;
if (head) {
- ret = get_min_match_length(NCAR(x), &min, env);
+ ret = get_min_len(NCAR(x), &min, env);
if (ret != 0) return ret;
if (min != 0) head = 0;
}
@@ -3094,6 +3106,8 @@ divide_look_behind_alternatives(Node* node)
AnchorNode* an = NANCHOR(node);
int anc_type = an->type;
+ /* fprintf(stderr, "divide_look_behind: %d\n", (int )node); */
+
head = an->target;
np = NCAR(head);
swap_node(node, head);
@@ -3123,6 +3137,8 @@ setup_look_behind(Node* node, regex_t* reg, ScanEnv* env)
int r, len;
AnchorNode* an = NANCHOR(node);
+ /* fprintf(stderr, "setup_look_behind: %x\n", (int )node); */
+
r = get_char_length_tree(an->target, reg, &len);
if (r == 0)
an->char_len = len;
@@ -3719,7 +3735,7 @@ setup_tree(Node* node, regex_t* reg, int state, ScanEnv* env)
case NT_QTFR:
{
- OnigDistance d;
+ OnigLen d;
QtfrNode* qn = NQTFR(node);
Node* target = qn->target;
@@ -3728,7 +3744,7 @@ setup_tree(Node* node, regex_t* reg, int state, ScanEnv* env)
}
if (IS_REPEAT_INFINITE(qn->upper) || qn->upper >= 1) {
- r = get_min_match_length(target, &d, env);
+ r = get_min_len(target, &d, env);
if (r) break;
if (d == 0) {
qn->target_empty_info = NQ_TARGET_IS_EMPTY;
@@ -3740,7 +3756,7 @@ setup_tree(Node* node, regex_t* reg, int state, ScanEnv* env)
}
#endif
#if 0
- r = get_max_match_length(target, &d, env);
+ r = get_max_len(target, &d, env);
if (r == 0 && d == 0) {
/* ()* ==> ()?, ()+ ==> () */
qn->upper = 1;
@@ -3855,8 +3871,8 @@ setup_tree(Node* node, regex_t* reg, int state, ScanEnv* env)
( BIT_NT_LIST | BIT_NT_ALT | BIT_NT_STR | BIT_NT_CCLASS | BIT_NT_CTYPE | \
BIT_NT_CANY | BIT_NT_ANCHOR | BIT_NT_ENCLOSE | BIT_NT_QTFR | BIT_NT_CALL )
-#define ALLOWED_ENCLOSE_IN_LB ( ENCLOSE_MEMORY )
-#define ALLOWED_ENCLOSE_IN_LB_NOT 0
+#define ALLOWED_ENCLOSE_IN_LB ( ENCLOSE_MEMORY | ENCLOSE_OPTION )
+#define ALLOWED_ENCLOSE_IN_LB_NOT ENCLOSE_OPTION
#define ALLOWED_ANCHOR_IN_LB \
( ANCHOR_LOOK_BEHIND | ANCHOR_BEGIN_LINE | ANCHOR_END_LINE | ANCHOR_BEGIN_BUF | ANCHOR_BEGIN_POSITION )
@@ -3869,9 +3885,9 @@ setup_tree(Node* node, regex_t* reg, int state, ScanEnv* env)
ALLOWED_ENCLOSE_IN_LB, ALLOWED_ANCHOR_IN_LB);
if (r < 0) return r;
if (r > 0) return ONIGERR_INVALID_LOOK_BEHIND_PATTERN;
- r = setup_look_behind(node, reg, env);
- if (r != 0) return r;
r = setup_tree(an->target, reg, state, env);
+ if (r != 0) return r;
+ r = setup_look_behind(node, reg, env);
}
break;
@@ -3881,9 +3897,9 @@ setup_tree(Node* node, regex_t* reg, int state, ScanEnv* env)
ALLOWED_ENCLOSE_IN_LB_NOT, ALLOWED_ANCHOR_IN_LB_NOT);
if (r < 0) return r;
if (r > 0) return ONIGERR_INVALID_LOOK_BEHIND_PATTERN;
- r = setup_look_behind(node, reg, env);
- if (r != 0) return r;
r = setup_tree(an->target, reg, (state | IN_NOT), env);
+ if (r != 0) return r;
+ r = setup_look_behind(node, reg, env);
}
break;
}
@@ -3927,8 +3943,8 @@ set_bm_skip(UChar* s, UChar* end, OnigEncoding enc ARG_UNUSED,
#define OPT_EXACT_MAXLEN 24
typedef struct {
- OnigDistance min; /* min byte length */
- OnigDistance max; /* max byte length */
+ OnigLen min; /* min byte length */
+ OnigLen max; /* max byte length */
} MinMaxLen;
typedef struct {
@@ -4052,7 +4068,7 @@ is_equal_mml(MinMaxLen* a, MinMaxLen* b)
static void
-set_mml(MinMaxLen* mml, OnigDistance min, OnigDistance max)
+set_mml(MinMaxLen* mml, OnigLen min, OnigLen max)
{
mml->min = min;
mml->max = max;
@@ -4080,7 +4096,7 @@ add_mml(MinMaxLen* to, MinMaxLen* from)
#if 0
static void
-add_len_mml(MinMaxLen* to, OnigDistance len)
+add_len_mml(MinMaxLen* to, OnigLen len)
{
to->min = distance_add(to->min, len);
to->max = distance_add(to->max, len);
@@ -4115,7 +4131,7 @@ copy_opt_anc_info(OptAncInfo* to, OptAncInfo* from)
static void
concat_opt_anc_info(OptAncInfo* to, OptAncInfo* left, OptAncInfo* right,
- OnigDistance left_len, OnigDistance right_len)
+ OnigLen left_len, OnigLen right_len)
{
clear_opt_anc_info(to);
@@ -4628,8 +4644,8 @@ optimize_node_left(Node* node, NodeOptInfo* opt, OptEnv* env)
/* no need to check ignore case. (setted in setup_tree()) */
if (IS_NOT_NULL(cc->mbuf) || IS_NCCLASS_NOT(cc)) {
- OnigDistance min = ONIGENC_MBC_MINLEN(env->enc);
- OnigDistance max = ONIGENC_MBC_MAXLEN_DIST(env->enc);
+ OnigLen min = ONIGENC_MBC_MINLEN(env->enc);
+ OnigLen max = ONIGENC_MBC_MAXLEN_DIST(env->enc);
set_mml(&opt->len, min, max);
}
@@ -4682,8 +4698,8 @@ optimize_node_left(Node* node, NodeOptInfo* opt, OptEnv* env)
case NT_CANY:
{
- OnigDistance min = ONIGENC_MBC_MINLEN(env->enc);
- OnigDistance max = ONIGENC_MBC_MAXLEN_DIST(env->enc);
+ OnigLen min = ONIGENC_MBC_MINLEN(env->enc);
+ OnigLen max = ONIGENC_MBC_MAXLEN_DIST(env->enc);
set_mml(&opt->len, min, max);
}
break;
@@ -4729,7 +4745,7 @@ optimize_node_left(Node* node, NodeOptInfo* opt, OptEnv* env)
{
int i;
int* backs;
- OnigDistance min, max, tmin, tmax;
+ OnigLen min, max, tmin, tmax;
Node** nodes = SCANENV_MEM_NODES(env->scan_env);
BRefNode* br = NBREF(node);
@@ -4738,14 +4754,14 @@ optimize_node_left(Node* node, NodeOptInfo* opt, OptEnv* env)
break;
}
backs = BACKREFS_P(br);
- r = get_min_match_length(nodes[backs[0]], &min, env->scan_env);
+ r = get_min_len(nodes[backs[0]], &min, env->scan_env);
if (r != 0) break;
- r = get_max_match_length(nodes[backs[0]], &max, env->scan_env);
+ r = get_max_len(nodes[backs[0]], &max, env->scan_env);
if (r != 0) break;
for (i = 1; i < br->back_num; i++) {
- r = get_min_match_length(nodes[backs[i]], &tmin, env->scan_env);
+ r = get_min_len(nodes[backs[i]], &tmin, env->scan_env);
if (r != 0) break;
- r = get_max_match_length(nodes[backs[i]], &tmax, env->scan_env);
+ r = get_max_len(nodes[backs[i]], &tmax, env->scan_env);
if (r != 0) break;
if (min > tmin) min = tmin;
if (max < tmax) max = tmax;
@@ -4770,7 +4786,7 @@ optimize_node_left(Node* node, NodeOptInfo* opt, OptEnv* env)
case NT_QTFR:
{
int i;
- OnigDistance min, max;
+ OnigLen min, max;
NodeOptInfo nopt;
QtfrNode* qn = NQTFR(node);
@@ -4839,7 +4855,7 @@ optimize_node_left(Node* node, NodeOptInfo* opt, OptEnv* env)
#ifdef USE_SUBEXP_CALL
en->opt_count++;
if (en->opt_count > MAX_NODE_OPT_INFO_REF_COUNT) {
- OnigDistance min, max;
+ OnigLen min, max;
min = 0;
max = ONIG_INFINITE_DISTANCE;
@@ -5059,7 +5075,7 @@ static void print_enc_string(FILE* fp, OnigEncoding enc,
}
static void
-print_distance_range(FILE* f, OnigDistance a, OnigDistance b)
+print_distance_range(FILE* f, OnigLen a, OnigLen b)
{
if (a == ONIG_INFINITE_DISTANCE)
fputs("inf", f);
@@ -5147,7 +5163,7 @@ print_optimize_info(FILE* f, regex_t* reg)
for (p = reg->exact; p < reg->exact_end; p++) {
fputc(*p, f);
}
- fprintf(f, "]: length: %d\n", (reg->exact_end - reg->exact));
+ fprintf(f, "]: length: %ld\n", (reg->exact_end - reg->exact));
}
else if (reg->optimize & ONIG_OPTIMIZE_MAP) {
int c, i, n = 0;
@@ -5431,6 +5447,8 @@ onig_reg_init(regex_t* reg, OnigOptionType option,
r = onig_initialize_encoding(enc);
if (r != 0)
return ONIGERR_FAIL_TO_INITIALIZE;
+
+ onig_warning("You didn't call onig_initialize() explicitly");
#endif
}
@@ -5935,7 +5953,7 @@ onig_print_compiled_byte_code(FILE* f, UChar* bp, UChar** nextp,
GET_POINTER_INC(cc, bp);
n = bitset_on_num(cc->bs);
- fprintf(f, ":%u:%d", (unsigned int )cc, n);
+ fprintf(f, ":%p:%d", cc, n);
}
break;
@@ -6067,9 +6085,9 @@ print_indent_tree(FILE* f, Node* node, int indent)
case NT_LIST:
case NT_ALT:
if (NTYPE(node) == NT_LIST)
- fprintf(f, "<list:%x>\n", (int )node);
+ fprintf(f, "<list:%p>\n", node);
else
- fprintf(f, "<alt:%x>\n", (int )node);
+ fprintf(f, "<alt:%p>\n", node);
print_indent_tree(f, NCAR(node), indent + add);
while (IS_NOT_NULL(node = NCDR(node))) {
@@ -6082,8 +6100,8 @@ print_indent_tree(FILE* f, Node* node, int indent)
break;
case NT_STR:
- fprintf(f, "<string%s:%x>",
- (NSTRING_IS_RAW(node) ? "-raw" : ""), (int )node);
+ fprintf(f, "<string%s:%p>",
+ (NSTRING_IS_RAW(node) ? "-raw" : ""), node);
for (p = NSTR(node)->s; p < NSTR(node)->end; p++) {
if (*p >= 0x20 && *p < 0x7f)
fputc(*p, f);
@@ -6094,7 +6112,7 @@ print_indent_tree(FILE* f, Node* node, int indent)
break;
case NT_CCLASS:
- fprintf(f, "<cclass:%x>", (int )node);
+ fprintf(f, "<cclass:%p>", node);
if (IS_NCCLASS_NOT(NCCLASS(node))) fputs(" not", f);
if (NCCLASS(node)->mbuf) {
BBuf* bbuf = NCCLASS(node)->mbuf;
@@ -6106,7 +6124,7 @@ print_indent_tree(FILE* f, Node* node, int indent)
break;
case NT_CTYPE:
- fprintf(f, "<ctype:%x> ", (int )node);
+ fprintf(f, "<ctype:%p> ", node);
switch (NCTYPE(node)->ctype) {
case ONIGENC_CTYPE_WORD:
if (NCTYPE(node)->not != 0)
@@ -6122,11 +6140,11 @@ print_indent_tree(FILE* f, Node* node, int indent)
break;
case NT_CANY:
- fprintf(f, "<anychar:%x>", (int )node);
+ fprintf(f, "<anychar:%p>", node);
break;
case NT_ANCHOR:
- fprintf(f, "<anchor:%x> ", (int )node);
+ fprintf(f, "<anchor:%p> ", node);
switch (NANCHOR(node)->type) {
case ANCHOR_BEGIN_BUF: fputs("begin buf", f); break;
case ANCHOR_END_BUF: fputs("end buf", f); break;
@@ -6141,10 +6159,22 @@ print_indent_tree(FILE* f, Node* node, int indent)
case ANCHOR_WORD_BEGIN: fputs("word begin", f); break;
case ANCHOR_WORD_END: fputs("word end", f); break;
#endif
- case ANCHOR_PREC_READ: fputs("prec read", f); break;
- case ANCHOR_PREC_READ_NOT: fputs("prec read not", f); break;
- case ANCHOR_LOOK_BEHIND: fputs("look_behind", f); break;
- case ANCHOR_LOOK_BEHIND_NOT: fputs("look_behind_not",f); break;
+ case ANCHOR_PREC_READ:
+ fprintf(f, "prec read\n");
+ print_indent_tree(f, NANCHOR(node)->target, indent + add);
+ break;
+ case ANCHOR_PREC_READ_NOT:
+ fprintf(f, "prec read not\n");
+ print_indent_tree(f, NANCHOR(node)->target, indent + add);
+ break;
+ case ANCHOR_LOOK_BEHIND:
+ fprintf(f, "look behind\n");
+ print_indent_tree(f, NANCHOR(node)->target, indent + add);
+ break;
+ case ANCHOR_LOOK_BEHIND_NOT:
+ fprintf(f, "look behind not\n");
+ print_indent_tree(f, NANCHOR(node)->target, indent + add);
+ break;
default:
fprintf(f, "ERROR: undefined anchor type.\n");
@@ -6157,7 +6187,7 @@ print_indent_tree(FILE* f, Node* node, int indent)
int* p;
BRefNode* br = NBREF(node);
p = BACKREFS_P(br);
- fprintf(f, "<backref:%x>", (int )node);
+ fprintf(f, "<backref:%p>", node);
for (i = 0; i < br->back_num; i++) {
if (i > 0) fputs(", ", f);
fprintf(f, "%d", p[i]);
@@ -6169,21 +6199,21 @@ print_indent_tree(FILE* f, Node* node, int indent)
case NT_CALL:
{
CallNode* cn = NCALL(node);
- fprintf(f, "<call:%x>", (int )node);
+ fprintf(f, "<call:%p>", node);
p_string(f, cn->name_end - cn->name, cn->name);
}
break;
#endif
case NT_QTFR:
- fprintf(f, "<quantifier:%x>{%d,%d}%s\n", (int )node,
+ fprintf(f, "<quantifier:%p>{%d,%d}%s\n", node,
NQTFR(node)->lower, NQTFR(node)->upper,
(NQTFR(node)->greedy ? "" : "?"));
print_indent_tree(f, NQTFR(node)->target, indent + add);
break;
case NT_ENCLOSE:
- fprintf(f, "<enclose:%x> ", (int )node);
+ fprintf(f, "<enclose:%p> ", node);
switch (NENCLOSE(node)->type) {
case ENCLOSE_OPTION:
fprintf(f, "option:%d", NENCLOSE(node)->option);