[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Changes to grep/src/dfa.c
From: |
Stepan Kasal |
Subject: |
Changes to grep/src/dfa.c |
Date: |
Fri, 19 Nov 2004 11:44:40 -0500 |
Index: grep/src/dfa.c
diff -u grep/src/dfa.c:1.25 grep/src/dfa.c:1.26
--- grep/src/dfa.c:1.25 Fri Nov 19 16:38:52 2004
+++ grep/src/dfa.c Fri Nov 19 16:48:15 2004
@@ -407,7 +407,6 @@
And inputwcs[i] is the codepoint. */
static unsigned char const *buf_begin; /* reference to begin in dfaexec(). */
static unsigned char const *buf_end; /* reference to end in dfaexec(). */
-static unsigned long buf_offset; /* Go fast. */
#endif /* MBS_SUPPORT */
#ifdef MBS_SUPPORT
@@ -2374,12 +2373,14 @@
#define SKIP_REMAINS_MB_IF_INITIAL_STATE(s, p) \
if (s == 0) \
{ \
- while (inputwcs[p - buf_begin + buf_offset] == 0 \
- && mblen_buf[p - buf_begin + buf_offset] > 0\
+ while (inputwcs[p - buf_begin] == 0 \
+ && mblen_buf[p - buf_begin] > 0 \
&& p < buf_end) \
++p; \
if (p >= end) \
{ \
+ free(mblen_buf); \
+ free(inputwcs); \
return (size_t) -1; \
} \
}
@@ -2472,8 +2473,8 @@
wchar_t wc;
int mbclen;
- wc = inputwcs[index + buf_offset];
- mbclen = (mblen_buf[index + buf_offset] == 0)? 1 : mblen_buf[index +
buf_offset];
+ wc = inputwcs[index];
+ mbclen = (mblen_buf[index] == 0)? 1 : mblen_buf[index];
/* Check context. */
if (wc == (wchar_t)eolbyte)
@@ -2522,7 +2523,7 @@
int letter = 0;
wchar_t wc; /* Current refering character. */
- wc = inputwcs[index + buf_offset];
+ wc = inputwcs[index];
/* Check context. */
if (wc == (wchar_t)eolbyte)
@@ -2546,7 +2547,7 @@
/* Assign the current refering operator to work_mbc. */
work_mbc = &(d->mbcsets[(d->multibyte_prop[pos.index]) >> 2]);
match = !work_mbc->invert;
- match_len = (mblen_buf[index + buf_offset] == 0)? 1 : mblen_buf[index +
buf_offset];
+ match_len = (mblen_buf[index] == 0)? 1 : mblen_buf[index];
/* match with a character class? */
for (i = 0; i<work_mbc->nch_classes; i++)
@@ -2661,8 +2662,8 @@
/* Calculate the length of the (single/multi byte) character
to which p points. */
- *mbclen = (mblen_buf[*pp - buf_begin + buf_offset] == 0)? 1
- : mblen_buf[*pp - buf_begin + buf_offset];
+ *mbclen = (mblen_buf[*pp - buf_begin] == 0)? 1
+ : mblen_buf[*pp - buf_begin];
/* Calculate the state which can be reached from the state `s' by
consuming `*mbclen' single bytes from the buffer. */
@@ -2756,7 +2757,7 @@
`maxlen' bytes. */
rs = transit_state_consume_1char(d, s, pp, match_lens, &mbclen, &follows);
- wc = inputwcs[*pp - mbclen - buf_begin + buf_offset];
+ wc = inputwcs[*pp - mbclen - buf_begin];
s1 = state_index(d, &follows, wc == L'\n', iswalnum(wc));
realloc_trans_if_necessary(d, s1);
@@ -2774,7 +2775,7 @@
&follows);
}
- wc = inputwcs[*pp - mbclen - buf_begin + buf_offset];
+ wc = inputwcs[*pp - mbclen - buf_begin];
s1 = state_index(d, &follows, wc == L'\n', iswalnum(wc));
realloc_trans_if_necessary(d, s1);
}
@@ -2828,21 +2829,12 @@
if (MB_CUR_MAX > 1)
{
int remain_bytes, i;
- buf_begin -= buf_offset;
- if (buf_begin <= (unsigned char const *)begin && end <= buf_end) {
- buf_offset = (unsigned char const *)begin - buf_begin;
- buf_begin = begin;
- buf_end = end;
- goto go_fast;
- }
-
- buf_offset = 0;
buf_begin = begin;
buf_end = end;
/* initialize mblen_buf, and inputwcs. */
- REALLOC(mblen_buf, unsigned char, end - (unsigned char const *)begin +
2);
- REALLOC(inputwcs, wchar_t, end - (unsigned char const *)begin + 2);
+ MALLOC(mblen_buf, unsigned char, end - (unsigned char const *)begin + 2);
+ MALLOC(inputwcs, wchar_t, end - (unsigned char const *)begin + 2);
memset(&mbs, 0, sizeof(mbstate_t));
remain_bytes = 0;
for (i = 0; i < end - (unsigned char const *)begin + 1; i++)
@@ -2874,7 +2866,6 @@
mblen_buf[i] = 0;
inputwcs[i] = 0; /* sentinel */
}
-go_fast:
#endif /* MBS_SUPPORT */
for (;;)
@@ -2913,6 +2904,13 @@
{
if (p == end)
{
+#ifdef MBS_SUPPORT
+ if (MB_CUR_MAX > 1)
+ {
+ free(mblen_buf);
+ free(inputwcs);
+ }
+#endif /* MBS_SUPPORT */
return (size_t) -1;
}
s = 0;
@@ -2923,6 +2921,13 @@
{
if (backref)
*backref = (d->states[s].backref != 0);
+#ifdef MBS_SUPPORT
+ if (MB_CUR_MAX > 1)
+ {
+ free(mblen_buf);
+ free(inputwcs);
+ }
+#endif /* MBS_SUPPORT */
return (char const *) p - begin;
}