[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 09/11] dfa: rename "newline" to "buffer delimiter"
From: |
Paolo Bonzini |
Subject: |
[PATCH 09/11] dfa: rename "newline" to "buffer delimiter" |
Date: |
Wed, 4 Jan 2012 11:59:50 +0100 |
The newline character is always '\n'. What changes is the buffer
delimiter, which can be '\n' or '\0'.
* src/dfa.c (bufdelim): New name of eolbyte.
(newlines): Rename to bufdelims.
---
src/dfa.c | 60 ++++++++++++++++++++++++++++++------------------------------
1 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/src/dfa.c b/src/dfa.c
index d2bfba8..cc5caf2 100644
--- a/src/dfa.c
+++ b/src/dfa.c
@@ -393,11 +393,11 @@ struct dfa
on a state that potentially could do so. */
int *success; /* Table of acceptance conditions used
in
dfaexec and computed in build_state. */
- int *newlines; /* Transitions on newlines. The entry for a
- newline in any transition table is always
+ int *bufdelims; /* Transitions on delimiters. The entry for a
+ delimiter in any transition table is always
-1 so we can count lines without wasting
too many cycles. The transition for a
- newline is stored separately and handled
+ delimiter is stored separately and handled
as a special case. Newline is also used
as a sentinel at the end of the buffer. */
struct dfamust *musts; /* List of strings, at least one of which
@@ -564,7 +564,7 @@ static reg_syntax_t syntax_bits, syntax_bits_set;
static int case_fold;
/* End-of-line byte in data. */
-static unsigned char eolbyte;
+static unsigned char bufdelim;
/* Cache of char-context values. */
static int sbit[NOTCHAR];
@@ -591,7 +591,7 @@ static charclass newline;
static int
char_context(unsigned char c)
{
- if (c == eolbyte || c == 0)
+ if (c == bufdelim || c == 0)
return CTX_NEWLINE;
if (IS_WORD_CONSTITUENT (c))
return CTX_LETTER;
@@ -601,7 +601,7 @@ char_context(unsigned char c)
static int
wchar_context(wint_t wc)
{
- if (wc == (wchar_t)eolbyte || wc == 0)
+ if (wc == (wchar_t)bufdelim || wc == 0)
return CTX_NEWLINE;
if (wc == L'_' || iswalnum (wc))
return CTX_LETTER;
@@ -610,14 +610,14 @@ wchar_context(wint_t wc)
/* Entry point to set syntax options. */
void
-dfasyntax (reg_syntax_t bits, int fold, unsigned char eol)
+dfasyntax (reg_syntax_t bits, int fold, unsigned char delim)
{
unsigned int i;
syntax_bits_set = 1;
syntax_bits = bits;
case_fold = fold;
- eolbyte = eol;
+ bufdelim = delim;
for (i = 0; i < NOTCHAR; ++i)
{
@@ -1138,7 +1138,7 @@ parse_bracket_exp (void)
assert(MB_CUR_MAX == 1);
notset(ccl);
if (syntax_bits & RE_HAT_LISTS_NOT_NEWLINE)
- clrbit(eolbyte, ccl);
+ clrbit(bufdelim, ccl);
}
return CSET + charclass_index(ccl);
@@ -1399,7 +1399,7 @@ lex (void)
zeroset(ccl);
notset(ccl);
if (!(syntax_bits & RE_DOT_NEWLINE))
- clrbit(eolbyte, ccl);
+ clrbit(bufdelim, ccl);
if (syntax_bits & RE_DOT_NOT_NULL)
clrbit('\0', ccl);
laststart = 0;
@@ -1621,7 +1621,7 @@ add_utf8_anychar (void)
if (i == 1)
{
if (!(syntax_bits & RE_DOT_NEWLINE))
- clrbit (eolbyte, c);
+ clrbit (bufdelim, c);
if (syntax_bits & RE_DOT_NOT_NULL)
clrbit ('\0', c);
}
@@ -2107,7 +2107,7 @@ charclass_context(charclass c)
int context = 0;
int j;
- if (tstbit(eolbyte, c))
+ if (tstbit(bufdelim, c))
context |= CTX_NEWLINE;
for (j = 0; j < CHARCLASS_INTS; ++j)
@@ -2603,7 +2603,7 @@ dfastate (int s, struct dfa *d, int trans[])
for (i = 0; i < NOTCHAR; ++i)
trans[i] = (IS_WORD_CONSTITUENT(i)) ? state_letter : state;
- trans[eolbyte] = state_newline;
+ trans[bufdelim] = state_newline;
}
else
for (i = 0; i < NOTCHAR; ++i)
@@ -2680,7 +2680,7 @@ dfastate (int s, struct dfa *d, int trans[])
{
int c = j * INTBITS + k;
- if (c == eolbyte)
+ if (c == bufdelim)
trans[c] = state_newline;
else if (IS_WORD_CONSTITUENT(c))
trans[c] = state_letter;
@@ -2753,7 +2753,7 @@ build_state (int s, struct dfa *d)
d->trans = d->realtrans + 1;
REALLOC(d->fails, d->tralloc);
REALLOC(d->success, d->tralloc);
- REALLOC(d->newlines, d->tralloc);
+ REALLOC(d->bufdelims, d->tralloc);
while (oldalloc < d->tralloc)
{
d->trans[oldalloc] = NULL;
@@ -2763,8 +2763,8 @@ build_state (int s, struct dfa *d)
/* Keep the newline transition in a special place so we can use it as
a sentinel. */
- d->newlines[s] = trans[eolbyte];
- trans[eolbyte] = -1;
+ d->bufdelims[s] = trans[bufdelim];
+ trans[bufdelim] = -1;
if (ACCEPTING(s, *d))
d->fails[s] = trans;
@@ -2781,7 +2781,7 @@ build_state_zero (struct dfa *d)
d->trans = d->realtrans + 1;
CALLOC(d->fails, d->tralloc);
MALLOC(d->success, d->tralloc);
- MALLOC(d->newlines, d->tralloc);
+ MALLOC(d->bufdelims, d->tralloc);
build_state(0, d);
}
@@ -2825,7 +2825,7 @@ realloc_trans_if_necessary(struct dfa *d, int new_state)
d->trans = d->realtrans + 1;
REALLOC(d->fails, d->tralloc);
REALLOC(d->success, d->tralloc);
- REALLOC(d->newlines, d->tralloc);
+ REALLOC(d->bufdelims, d->tralloc);
while (oldalloc < d->tralloc)
{
d->trans[oldalloc] = NULL;
@@ -2902,7 +2902,7 @@ match_anychar (struct dfa *d, int s, position pos, int
idx)
mbclen = (mblen_buf[idx] == 0)? 1 : mblen_buf[idx];
/* Check syntax bits. */
- if (wc == (wchar_t)eolbyte)
+ if (wc == (wchar_t)bufdelim)
{
if (!(syntax_bits & RE_DOT_NEWLINE))
return 0;
@@ -2944,7 +2944,7 @@ match_mb_charset (struct dfa *d, int s, position pos, int
idx)
wc = inputwcs[idx];
/* Check syntax bits. */
- if (wc == (wchar_t)eolbyte)
+ if (wc == (wchar_t)bufdelim)
{
if (!(syntax_bits & RE_DOT_NEWLINE))
return 0;
@@ -3207,7 +3207,7 @@ static void
prepare_wc_buf (const char *begin, const char *end)
{
#if MBS_SUPPORT
- unsigned char eol = eolbyte;
+ unsigned char delim = bufdelim;
size_t remain_bytes, i;
buf_begin = (unsigned char *) begin;
@@ -3227,7 +3227,7 @@ prepare_wc_buf (const char *begin, const char *end)
remain_bytes = 0;
inputwcs[i] = (wchar_t)begin[i];
mblen_buf[i] = 0;
- if (begin[i] == eol)
+ if (begin[i] == delim)
break;
}
else
@@ -3257,7 +3257,7 @@ prepare_wc_buf (const char *begin, const char *end)
points to the beginning of the buffer, and END points to the first byte
after its end. Note however that we store a sentinel byte (usually
newline) in *END, so the actual buffer must be one byte longer.
- When NEWLINE is nonzero, newlines may appear in the matching string.
+ When NEWLINE is nonzero, buffer delimiters may appear in the matching
string.
If COUNT is non-NULL, increment *COUNT once for each newline processed.
Finally, if BACKREF is non-NULL set *BACKREF to indicate whether we
encountered a back-reference (1) or not (0). The caller may use this
@@ -3270,7 +3270,7 @@ dfaexec (struct dfa *d, char const *begin, char *end,
unsigned char const *p; /* Current input character. */
int **trans, *t; /* Copy of d->trans so it can be optimized
into a register. */
- unsigned char eol = eolbyte; /* Likewise for eolbyte. */
+ unsigned char delim = bufdelim; /* Likewise for bufdelim. */
unsigned char saved_end;
if (! d->tralloc)
@@ -3280,7 +3280,7 @@ dfaexec (struct dfa *d, char const *begin, char *end,
p = (unsigned char const *) begin;
trans = d->trans;
saved_end = *(unsigned char *) end;
- *end = eol;
+ *end = delim;
if (d->mb_cur_max > 1)
{
@@ -3367,7 +3367,7 @@ dfaexec (struct dfa *d, char const *begin, char *end,
}
/* If the previous character was a newline, count it. */
- if ((char *) p <= end && p[-1] == eol)
+ if ((char *) p <= end && p[-1] == delim)
{
if (count)
++*count;
@@ -3395,9 +3395,9 @@ dfaexec (struct dfa *d, char const *begin, char *end,
continue;
}
- if (p[-1] == eol && newline)
+ if (p[-1] == delim && newline)
{
- s = d->newlines[s1];
+ s = d->bufdelims[s1];
continue;
}
@@ -3527,7 +3527,7 @@ dfafree (struct dfa *d)
}
free(d->realtrans);
free(d->fails);
- free(d->newlines);
+ free(d->bufdelims);
free(d->success);
for (dm = d->musts; dm; dm = ndm)
{
--
1.7.7.1
- [PATCH 01/11] dfa: fix corner case with anchors, (continued)
- [PATCH 01/11] dfa: fix corner case with anchors, Paolo Bonzini, 2012/01/04
- [PATCH 02/11] dfa: introduce contexts for the values in d->success, Paolo Bonzini, 2012/01/04
- [PATCH 04/11] dfa: refactor common context computations, Paolo Bonzini, 2012/01/04
- [PATCH 03/11] dfa: change newline/letter to a single context value, Paolo Bonzini, 2012/01/04
- [PATCH 05/11] dfa: change meaning of a state context, Paolo Bonzini, 2012/01/04
- [PATCH 06/11] dfa: remove useless check, Paolo Bonzini, 2012/01/04
- [PATCH 07/11] dfa: make repetitive code *really* repetitive, Paolo Bonzini, 2012/01/04
- [PATCH 08/11] dfa: remove redundant line constraints, Paolo Bonzini, 2012/01/04
- [PATCH 11/11] dfa: introduce BEGBUF/ENDBUF, Paolo Bonzini, 2012/01/04
- [PATCH 09/11] dfa: rename "newline" to "buffer delimiter",
Paolo Bonzini <=
- [PATCH 10/11] dfa: introduce bufdelim context, Paolo Bonzini, 2012/01/04
- Re: [RFC/RFT PATCH 00/11] Differentiate ^/$ from \` and \' in grep -z mode, Jim Meyering, 2012/01/04