[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 3/9] dfa: use MALLOC/REALLOC always
From: |
Jim Meyering |
Subject: |
Re: [PATCH 3/9] dfa: use MALLOC/REALLOC always |
Date: |
Tue, 03 Jan 2012 18:43:34 +0100 |
Paul Eggert wrote:
> On 01/03/12 00:38, Paolo Bonzini wrote:
>> - cpp = xnrealloc(cpp, i + 2, sizeof *cpp);
>> + REALLOC(cpp, i + 2);
>
> Missing space before '('; otherwise it looks fine.
I realized that we're suffering from a problem with the commons (dfa.c)
not adhering to a consistent formatting style.
To give you an idea of how many style problems there are,
I compared the original with a consistently-indented one using
tiny script I call idiff:
#!/bin/sh
USAGE='Usage: $0 file.c ...'
diagnostic='eval echo >&2' # diagnostics to stderr
case $# in
0) $diagnostic $USAGE ; exit 2 ;;
*) ;;
esac
for i in "$@"; do
echo $i
base=`basename $i`
orig=/tmp/$base.orig
expand -i < $i > $orig
indent < $orig |sed 's/\<_ (/_(/g' | expand -i > /tmp/$base
diff -U 1 $orig /tmp/$base
rm -f $orig /tmp/$base
done
Using this ~/.indent.pro:
-l79
--dont-format-comments
--leave-preprocessor-space
--swallow-optional-blank-lines
-Tsize_t
...
I don't care about spaces before comments, but at least the
space before open-parenthesis should appear consistently.
dfa.c
--- /tmp/dfa.c.orig 2012-01-03 18:40:12.497722416 +0100
+++ /tmp/dfa.c 2012-01-03 18:40:12.513722839 +0100
@@ -48,3 +48,3 @@
-#include "mbsupport.h" /* defines MBS_SUPPORT if appropriate */
+#include "mbsupport.h" /* defines MBS_SUPPORT if appropriate */
#include <wchar.h>
@@ -91,3 +91,7 @@
errors that the cast doesn't. */
-static inline unsigned char to_uchar (char ch) { return ch; }
+static inline unsigned char
+to_uchar (char ch)
+{
+ return ch;
+}
@@ -218,5 +222,5 @@
- ANYCHAR, /* ANYCHAR is a terminal symbol that matches
- any multibyte (or single byte) characters.
- It is used only if MB_CUR_MAX > 1. */
+ ANYCHAR, /* ANYCHAR is a terminal symbol that matches
+ any multibyte (or single byte) characters.
+ It is used only if MB_CUR_MAX > 1. */
@@ -233,3 +237,2 @@
-
/* States of the recognizer correspond to sets of positions in the parse
@@ -271,6 +274,6 @@
int first_end; /* Token value of the first END in elems. */
- position_set mbps; /* Positions which can match multibyte
- characters. e.g. period.
- These staff are used only if
- MB_CUR_MAX > 1. */
+ position_set mbps; /* Positions which can match multibyte
+ characters. e.g. period.
+ These staff are used only if
+ MB_CUR_MAX > 1. */
} dfa_state;
@@ -320,10 +323,10 @@
/* The value of multibyte_prop[i] is defined by following rule.
- if tokens[i] < NOTCHAR
- bit 0 : tokens[i] is the first byte of a character, including
- single-byte characters.
- bit 1 : tokens[i] is the last byte of a character, including
- single-byte characters.
+ if tokens[i] < NOTCHAR
+ bit 0 : tokens[i] is the first byte of a character, including
+ single-byte characters.
+ bit 1 : tokens[i] is the last byte of a character, including
+ single-byte characters.
- if tokens[i] = MBCSET
- ("the index of mbcsets correspnd to this operator" << 2) + 3
+ if tokens[i] = MBCSET
+ ("the index of mbcsets correspnd to this operator" << 2) + 3
@@ -331,7 +334,7 @@
tokens
- = 'single_byte_a', 'multi_byte_A', single_byte_b'
- = 'sb_a', 'mb_A(1st byte)', 'mb_A(2nd byte)', 'mb_A(3rd byte)', 'sb_b'
+ = 'single_byte_a', 'multi_byte_A', single_byte_b'
+ = 'sb_a', 'mb_A(1st byte)', 'mb_A(2nd byte)', 'mb_A(3rd byte)', 'sb_b'
multibyte_prop
- = 3 , 1 , 0 , 2 , 3
- */
+ = 3 , 1 , 0 , 2 , 3
+ */
int nmultibyte_prop;
@@ -441,3 +444,2 @@
-
#ifdef DEBUG
@@ -450,5 +452,5 @@
if (t < 0)
- fprintf(stderr, "END");
+ fprintf (stderr, "END");
else if (t < NOTCHAR)
- fprintf(stderr, "%c", t);
+ fprintf (stderr, "%c", t);
else
@@ -457,22 +459,58 @@
{
- case EMPTY: s = "EMPTY"; break;
- case BACKREF: s = "BACKREF"; break;
- case BEGLINE: s = "BEGLINE"; break;
- case ENDLINE: s = "ENDLINE"; break;
- case BEGWORD: s = "BEGWORD"; break;
- case ENDWORD: s = "ENDWORD"; break;
- case LIMWORD: s = "LIMWORD"; break;
- case NOTLIMWORD: s = "NOTLIMWORD"; break;
- case QMARK: s = "QMARK"; break;
- case STAR: s = "STAR"; break;
- case PLUS: s = "PLUS"; break;
- case CAT: s = "CAT"; break;
- case OR: s = "OR"; break;
- case LPAREN: s = "LPAREN"; break;
- case RPAREN: s = "RPAREN"; break;
- case ANYCHAR: s = "ANYCHAR"; break;
- case MBCSET: s = "MBCSET"; break;
- default: s = "CSET"; break;
+ case EMPTY:
+ s = "EMPTY";
+ break;
+ case BACKREF:
+ s = "BACKREF";
+ break;
+ case BEGLINE:
+ s = "BEGLINE";
+ break;
+ case ENDLINE:
+ s = "ENDLINE";
+ break;
+ case BEGWORD:
+ s = "BEGWORD";
+ break;
+ case ENDWORD:
+ s = "ENDWORD";
+ break;
+ case LIMWORD:
+ s = "LIMWORD";
+ break;
+ case NOTLIMWORD:
+ s = "NOTLIMWORD";
+ break;
+ case QMARK:
+ s = "QMARK";
+ break;
+ case STAR:
+ s = "STAR";
+ break;
+ case PLUS:
+ s = "PLUS";
+ break;
+ case CAT:
+ s = "CAT";
+ break;
+ case OR:
+ s = "OR";
+ break;
+ case LPAREN:
+ s = "LPAREN";
+ break;
+ case RPAREN:
+ s = "RPAREN";
+ break;
+ case ANYCHAR:
+ s = "ANYCHAR";
+ break;
+ case MBCSET:
+ s = "MBCSET";
+ break;
+ default:
+ s = "CSET";
+ break;
}
- fprintf(stderr, "%s", s);
+ fprintf (stderr, "%s", s);
}
@@ -538,7 +576,7 @@
for (i = 0; i < dfa->cindex; ++i)
- if (equal(s, dfa->charclasses[i]))
+ if (equal (s, dfa->charclasses[i]))
return i;
- REALLOC_IF_NECESSARY(dfa->charclasses, dfa->calloc, dfa->cindex + 1);
+ REALLOC_IF_NECESSARY (dfa->charclasses, dfa->calloc, dfa->cindex + 1);
++dfa->cindex;
- copyset(s, dfa->charclasses[i]);
+ copyset (s, dfa->charclasses[i]);
return i;
@@ -598,4 +636,3 @@
abort ();
- /*NOTREACHED*/
- return false;
+ /*NOTREACHED*/ return false;
}
@@ -627,4 +664,2 @@
-
-
/* UTF-8 encoding allows some optimizations that we can't otherwise
@@ -667,11 +702,11 @@
multibyte character. */
-static unsigned char *mblen_buf;/* Correspond to the input buffer in dfaexec().
- Each element store the amount of remain
- byte of corresponding multibyte character
- in the input string. A element's value
- is 0 if corresponding character is a
- single byte chracter.
- e.g. input : 'a', <mb(0)>, <mb(1)>, <mb(2)>
- mblen_buf : 0, 3, 2, 1
- */
+static unsigned char *mblen_buf; /* Correspond to the input buffer in
dfaexec().
+ Each element store the amount of
remain
+ byte of corresponding multibyte
character
+ in the input string. A element's
value
+ is 0 if corresponding character is a
+ single byte chracter.
+ e.g. input : 'a', <mb(0)>, <mb(1)>,
<mb(2)>
+ mblen_buf : 0, 3, 2,
1
+ */
static wchar_t *inputwcs; /* Wide character representation of input
@@ -686,3 +721,2 @@
-
#if MBS_SUPPORT
@@ -748,3 +782,4 @@
the class. The leading [ has already been eaten by the lexical analyzer. */
-struct dfa_ctype {
+struct dfa_ctype
+{
const char *name;
@@ -755,18 +790,18 @@
static const struct dfa_ctype prednames[] = {
- { "alpha", isalpha, false },
- { "upper", isupper, false },
- { "lower", islower, false },
- { "digit", isdigit, true },
- { "xdigit", isxdigit, true },
- { "space", isspace, false },
- { "punct", ispunct, false },
- { "alnum", isalnum, false },
- { "print", isprint, false },
- { "graph", isgraph, false },
- { "cntrl", iscntrl, false },
- { "blank", isblank, false },
- { NULL, NULL, false }
+ {"alpha", isalpha, false},
+ {"upper", isupper, false},
+ {"lower", islower, false},
+ {"digit", isdigit, true},
+ {"xdigit", isxdigit, true},
+ {"space", isspace, false},
+ {"punct", ispunct, false},
+ {"alnum", isalnum, false},
+ {"print", isprint, false},
+ {"graph", isgraph, false},
+ {"cntrl", iscntrl, false},
+ {"blank", isblank, false},
+ {NULL, NULL, false}
};
-static const struct dfa_ctype * _GL_ATTRIBUTE_PURE
+static const struct dfa_ctype *_GL_ATTRIBUTE_PURE
find_pred (const char *str)
@@ -812,3 +847,4 @@
{
- REALLOC_IF_NECESSARY(dfa->mbcsets, dfa->mbcsets_alloc, dfa->nmbcsets +
1);
+ REALLOC_IF_NECESSARY (dfa->mbcsets, dfa->mbcsets_alloc,
+ dfa->nmbcsets + 1);
@@ -838,3 +874,3 @@
{
- c1 = EOF; /* mark c1 is not initialized". */
+ c1 = EOF; /* mark c1 is not initialized". */
colon_warning_state &= ~2;
@@ -854,4 +890,3 @@
/* TODO: handle `[[.' and `[[=' also for MB_CUR_MAX == 1. */
- || (MB_CUR_MAX > 1 && (c1 == '.' || c1 == '='))
- )
+ || (MB_CUR_MAX > 1 && (c1 == '.' || c1 == '=')))
{
@@ -877,9 +912,7 @@
char const *class
- = (case_fold && (STREQ (str, "upper")
- || STREQ (str, "lower"))
- ? "alpha"
- : str);
+ = (case_fold && (STREQ (str, "upper")
+ || STREQ (str, "lower")) ? "alpha" : str);
const struct dfa_ctype *pred = find_pred (class);
if (!pred)
- dfaerror(_("invalid character class"));
+ dfaerror (_("invalid character class"));
@@ -890,5 +923,5 @@
- REALLOC_IF_NECESSARY(work_mbc->ch_classes,
- ch_classes_al,
- work_mbc->nch_classes + 1);
+ REALLOC_IF_NECESSARY (work_mbc->ch_classes,
+ ch_classes_al,
+ work_mbc->nch_classes + 1);
work_mbc->ch_classes[work_mbc->nch_classes++] = wt;
@@ -897,3 +930,3 @@
for (c2 = 0; c2 < NOTCHAR; ++c2)
- if (pred->func(c2))
+ if (pred->func (c2))
setbit_case_fold_c (c2, ccl);
@@ -904,4 +937,4 @@
char *elem;
- MALLOC(elem, len + 1);
- strncpy(elem, str, len + 1);
+ MALLOC (elem, len + 1);
+ strncpy (elem, str, len + 1);
@@ -910,5 +943,4 @@
{
- REALLOC_IF_NECESSARY(work_mbc->equivs,
- equivs_al,
- work_mbc->nequivs + 1);
+ REALLOC_IF_NECESSARY (work_mbc->equivs,
+ equivs_al, work_mbc->nequivs + 1);
work_mbc->equivs[work_mbc->nequivs++] = elem;
@@ -919,5 +951,5 @@
{
- REALLOC_IF_NECESSARY(work_mbc->coll_elems,
- coll_elems_al,
- work_mbc->ncoll_elems + 1);
+ REALLOC_IF_NECESSARY (work_mbc->coll_elems,
+ coll_elems_al,
+ work_mbc->ncoll_elems + 1);
work_mbc->coll_elems[work_mbc->ncoll_elems++] = elem;
@@ -937,6 +969,6 @@
if (c == '\\' && (syntax_bits & RE_BACKSLASH_ESCAPE_IN_LISTS))
- FETCH_WC(c, wc, _("unbalanced ["));
+ FETCH_WC (c, wc, _("unbalanced ["));
if (c1 == EOF)
- FETCH_WC(c1, wc1, _("unbalanced ["));
+ FETCH_WC (c1, wc1, _("unbalanced ["));
@@ -945,3 +977,3 @@
{
- FETCH_WC(c2, wc2, _("unbalanced ["));
+ FETCH_WC (c2, wc2, _("unbalanced ["));
if (c2 == ']')
@@ -957,5 +989,4 @@
{
- if (c2 == '\\'
- && (syntax_bits & RE_BACKSLASH_ESCAPE_IN_LISTS))
- FETCH_WC(c2, wc2, _("unbalanced ["));
+ if (c2 == '\\' && (syntax_bits & RE_BACKSLASH_ESCAPE_IN_LISTS))
+ FETCH_WC (c2, wc2, _("unbalanced ["));
@@ -965,20 +996,20 @@
to the pair of ranges, [m-z] [M-Z]. */
- REALLOC_IF_NECESSARY(work_mbc->range_sts,
- range_sts_al, work_mbc->nranges + 1);
- REALLOC_IF_NECESSARY(work_mbc->range_ends,
- range_ends_al, work_mbc->nranges + 1);
+ REALLOC_IF_NECESSARY (work_mbc->range_sts,
+ range_sts_al, work_mbc->nranges + 1);
+ REALLOC_IF_NECESSARY (work_mbc->range_ends,
+ range_ends_al, work_mbc->nranges + 1);
work_mbc->range_sts[work_mbc->nranges] =
- case_fold ? towlower(wc) : (wchar_t)wc;
+ case_fold ? towlower (wc) : (wchar_t) wc;
work_mbc->range_ends[work_mbc->nranges++] =
- case_fold ? towlower(wc2) : (wchar_t)wc2;
+ case_fold ? towlower (wc2) : (wchar_t) wc2;
#ifndef GREP
- if (case_fold && (iswalpha(wc) || iswalpha(wc2)))
+ if (case_fold && (iswalpha (wc) || iswalpha (wc2)))
{
- REALLOC_IF_NECESSARY(work_mbc->range_sts,
- range_sts_al, work_mbc->nranges + 1);
- work_mbc->range_sts[work_mbc->nranges] = towupper(wc);
- REALLOC_IF_NECESSARY(work_mbc->range_ends,
- range_ends_al, work_mbc->nranges + 1);
- work_mbc->range_ends[work_mbc->nranges++] = towupper(wc2);
+ REALLOC_IF_NECESSARY (work_mbc->range_sts,
+ range_sts_al, work_mbc->nranges + 1);
+ work_mbc->range_sts[work_mbc->nranges] = towupper (wc);
+ REALLOC_IF_NECESSARY (work_mbc->range_ends,
+ range_ends_al, work_mbc->nranges + 1);
+ work_mbc->range_ends[work_mbc->nranges++] = towupper (wc2);
}
@@ -1017,3 +1048,3 @@
colon_warning_state |= 8;
- FETCH_WC(c1, wc1, _("unbalanced ["));
+ FETCH_WC (c1, wc1, _("unbalanced ["));
continue;
@@ -1029,9 +1060,9 @@
- if (case_fold && iswalpha(wc))
+ if (case_fold && iswalpha (wc))
{
- wc = towlower(wc);
+ wc = towlower (wc);
if (!setbit_wc (wc, ccl))
{
- REALLOC_IF_NECESSARY(work_mbc->chars, chars_al,
- work_mbc->nchars + 1);
+ REALLOC_IF_NECESSARY (work_mbc->chars, chars_al,
+ work_mbc->nchars + 1);
work_mbc->chars[work_mbc->nchars++] = wc;
@@ -1041,3 +1072,3 @@
#else
- wc = towupper(wc);
+ wc = towupper (wc);
#endif
@@ -1046,4 +1077,4 @@
{
- REALLOC_IF_NECESSARY(work_mbc->chars, chars_al,
- work_mbc->nchars + 1);
+ REALLOC_IF_NECESSARY (work_mbc->chars, chars_al,
+ work_mbc->nchars + 1);
work_mbc->chars[work_mbc->nchars++] = wc;
@@ -1060,3 +1091,3 @@
work_mbc->invert = invert;
- work_mbc->cset = equal(ccl, zeroclass) ? -1 : charclass_index(ccl);
+ work_mbc->cset = equal (ccl, zeroclass) ? -1 : charclass_index (ccl);
return MBCSET;
@@ -1066,9 +1097,9 @@
{
- assert(MB_CUR_MAX == 1);
- notset(ccl);
+ assert (MB_CUR_MAX == 1);
+ notset (ccl);
if (syntax_bits & RE_HAT_LISTS_NOT_NEWLINE)
- clrbit(eolbyte, ccl);
+ clrbit (eolbyte, ccl);
}
- return CSET + charclass_index(ccl);
+ return CSET + charclass_index (ccl);
}
@@ -1107,3 +1138,3 @@
FETCH_WC (c, wctok, NULL);
- if ((int)c == EOF)
+ if ((int) c == EOF)
goto normal_char;
@@ -1111,3 +1142,3 @@
else
- FETCH(c, NULL);
+ FETCH (c, NULL);
@@ -1119,3 +1150,3 @@
if (lexleft == 0)
- dfaerror(_("unfinished \\ escape"));
+ dfaerror (_("unfinished \\ escape"));
backslash = 1;
@@ -1127,5 +1158,3 @@
if (syntax_bits & RE_CONTEXT_INDEP_ANCHORS
- || lasttok == END
- || lasttok == LPAREN
- || lasttok == OR)
+ || lasttok == END || lasttok == LPAREN || lasttok == OR)
return lasttok = BEGLINE;
@@ -1235,3 +1264,3 @@
char const *lim = p + lexleft;
- for (; p != lim && ISASCIIDIGIT (*p); p++)
+ for (; p != lim && ISASCIIDIGIT (*p); p++)
lo = (lo < 0 ? 0 : lo * 10) + *p - '0';
@@ -1252,3 +1281,3 @@
{M,N} - M through N */
- FETCH(c, _("unfinished repeat count"));
+ FETCH (c, _("unfinished repeat count"));
if (ISASCIIDIGIT (c))
@@ -1258,4 +1287,4 @@
{
- FETCH(c, _("unfinished repeat count"));
- if (! ISASCIIDIGIT (c))
+ FETCH (c, _("unfinished repeat count"));
+ if (!ISASCIIDIGIT (c))
break;
@@ -1265,3 +1294,3 @@
else
- dfaerror(_("malformed repeat count"));
+ dfaerror (_("malformed repeat count"));
if (c == ',')
@@ -1269,3 +1298,3 @@
FETCH (c, _("unfinished repeat count"));
- if (! ISASCIIDIGIT (c))
+ if (!ISASCIIDIGIT (c))
maxrep = -1;
@@ -1277,3 +1306,3 @@
FETCH (c, _("unfinished repeat count"));
- if (! ISASCIIDIGIT (c))
+ if (!ISASCIIDIGIT (c))
break;
@@ -1290,7 +1319,7 @@
if (c != '\\')
- dfaerror(_("malformed repeat count"));
- FETCH(c, _("unfinished repeat count"));
+ dfaerror (_("malformed repeat count"));
+ FETCH (c, _("unfinished repeat count"));
}
if (c != '}')
- dfaerror(_("malformed repeat count"));
+ dfaerror (_("malformed repeat count"));
laststart = 0;
@@ -1308,4 +1337,3 @@
if (syntax_bits & RE_LIMITED_OPS
- || backslash
- || !(syntax_bits & RE_NEWLINE_ALT))
+ || backslash || !(syntax_bits & RE_NEWLINE_ALT))
goto normal_char;
@@ -1340,10 +1368,10 @@
}
- zeroset(ccl);
- notset(ccl);
+ zeroset (ccl);
+ notset (ccl);
if (!(syntax_bits & RE_DOT_NEWLINE))
- clrbit(eolbyte, ccl);
+ clrbit (eolbyte, ccl);
if (syntax_bits & RE_DOT_NOT_NULL)
- clrbit('\0', ccl);
+ clrbit ('\0', ccl);
laststart = 0;
- return lasttok = CSET + charclass_index(ccl);
+ return lasttok = CSET + charclass_index (ccl);
@@ -1353,10 +1381,10 @@
goto normal_char;
- zeroset(ccl);
+ zeroset (ccl);
for (c2 = 0; c2 < NOTCHAR; ++c2)
- if (isspace(c2))
- setbit(c2, ccl);
+ if (isspace (c2))
+ setbit (c2, ccl);
if (c == 'S')
- notset(ccl);
+ notset (ccl);
laststart = 0;
- return lasttok = CSET + charclass_index(ccl);
+ return lasttok = CSET + charclass_index (ccl);
@@ -1366,10 +1394,10 @@
goto normal_char;
- zeroset(ccl);
+ zeroset (ccl);
for (c2 = 0; c2 < NOTCHAR; ++c2)
- if (IS_WORD_CONSTITUENT(c2))
- setbit(c2, ccl);
+ if (IS_WORD_CONSTITUENT (c2))
+ setbit (c2, ccl);
if (c == 'W')
- notset(ccl);
+ notset (ccl);
laststart = 0;
- return lasttok = CSET + charclass_index(ccl);
+ return lasttok = CSET + charclass_index (ccl);
@@ -1379,3 +1407,3 @@
laststart = 0;
- return lasttok = parse_bracket_exp();
+ return lasttok = parse_bracket_exp ();
@@ -1389,7 +1417,7 @@
- if (case_fold && isalpha(c))
+ if (case_fold && isalpha (c))
{
- zeroset(ccl);
+ zeroset (ccl);
setbit_case_fold_c (c, ccl);
- return lasttok = CSET + charclass_index(ccl);
+ return lasttok = CSET + charclass_index (ccl);
}
@@ -1402,4 +1430,4 @@
and some other character. */
- abort();
- return END; /* keeps pedantic compilers happy. */
+ abort ();
+ return END; /* keeps pedantic compilers happy. */
}
@@ -1420,4 +1448,4 @@
{
- REALLOC_IF_NECESSARY(dfa->multibyte_prop, dfa->nmultibyte_prop,
- dfa->tindex + 1);
+ REALLOC_IF_NECESSARY (dfa->multibyte_prop, dfa->nmultibyte_prop,
+ dfa->tindex + 1);
dfa->multibyte_prop[dfa->tindex] = mbprop;
@@ -1425,3 +1453,3 @@
- REALLOC_IF_NECESSARY(dfa->tokens, dfa->talloc, dfa->tindex + 1);
+ REALLOC_IF_NECESSARY (dfa->tokens, dfa->talloc, dfa->tindex + 1);
dfa->tokens[dfa->tindex++] = t;
@@ -1479,3 +1507,3 @@
if (work_mbc->invert
- || (!using_utf8() && work_mbc->cset != -1)
+ || (!using_utf8 () && work_mbc->cset != -1)
|| work_mbc->nchars != 0
@@ -1483,4 +1511,3 @@
|| work_mbc->nranges != 0
- || work_mbc->nequivs != 0
- || work_mbc->ncoll_elems != 0)
+ || work_mbc->nequivs != 0 || work_mbc->ncoll_elems != 0)
{
@@ -1531,7 +1558,7 @@
- addtok_mb(buf[0], cur_mb_len == 1 ? 3 : 1);
+ addtok_mb (buf[0], cur_mb_len == 1 ? 3 : 1);
for (i = 1; i < cur_mb_len; i++)
{
- addtok_mb(buf[i], i == cur_mb_len - 1 ? 2 : 0);
- addtok(CAT);
+ addtok_mb (buf[i], i == cur_mb_len - 1 ? 2 : 0);
+ addtok (CAT);
}
@@ -1539,3 +1566,6 @@
#else
-static void addtok_wc (wint_t wc) {}
+static void
+addtok_wc (wint_t wc)
+{
+}
#endif
@@ -1547,7 +1577,7 @@
static const charclass utf8_classes[5] = {
- { 0, 0, 0, 0, ~0, ~0, 0, 0 }, /* 80-bf: non-lead bytes */
- { ~0, ~0, ~0, ~0, 0, 0, 0, 0 }, /* 00-7f: 1-byte sequence */
- { 0, 0, 0, 0, 0, 0, 0xfffffffcU, 0 }, /* c2-df: 2-byte sequence */
- { 0, 0, 0, 0, 0, 0, 0, 0xffff }, /* e0-ef: 3-byte sequence */
- { 0, 0, 0, 0, 0, 0, 0, 0xff0000 } /* f0-f7: 4-byte sequence */
+ {0, 0, 0, 0, ~0, ~0, 0, 0}, /* 80-bf: non-lead bytes */
+ {~0, ~0, ~0, ~0, 0, 0, 0, 0}, /* 00-7f: 1-byte sequence */
+ {0, 0, 0, 0, 0, 0, 0xfffffffcU, 0}, /* c2-df: 2-byte sequence */
+ {0, 0, 0, 0, 0, 0, 0, 0xffff}, /* e0-ef: 3-byte sequence */
+ {0, 0, 0, 0, 0, 0, 0, 0xff0000} /* f0-f7: 4-byte sequence */
};
@@ -1569,3 +1599,3 @@
}
- dfa->utf8_anychar_classes[i] = CSET + charclass_index(c);
+ dfa->utf8_anychar_classes[i] = CSET + charclass_index (c);
}
@@ -1574,6 +1604,6 @@
- ([0x00-0x7f]
- |[0xc2-0xdf][0x80-0xbf]
- |[0xe0-0xef[0x80-0xbf][0x80-0xbf]
- |[0xf0-f7][0x80-0xbf][0x80-0xbf][0x80-0xbf])
+ ([0x00-0x7f]
+ |[0xc2-0xdf][0x80-0xbf]
+ |[0xe0-0xef[0x80-0xbf][0x80-0xbf]
+ |[0xf0-f7][0x80-0xbf][0x80-0xbf][0x80-0xbf])
@@ -1637,7 +1667,7 @@
{
- addtok_wc (case_fold ? towlower(wctok) : wctok);
+ addtok_wc (case_fold ? towlower (wctok) : wctok);
#ifndef GREP
- if (case_fold && iswalpha(wctok))
+ if (case_fold && iswalpha (wctok))
{
- addtok_wc (towupper(wctok));
+ addtok_wc (towupper (wctok));
addtok (OR);
@@ -1646,5 +1676,5 @@
- tok = lex();
+ tok = lex ();
}
- else if (MBS_SUPPORT && tok == ANYCHAR && using_utf8())
+ else if (MBS_SUPPORT && tok == ANYCHAR && using_utf8 ())
{
@@ -1654,7 +1684,7 @@
any encoding; however, the optimization must be done manually as
- it is done above in add_utf8_anychar. So, let's start with
+ it is done above in add_utf8_anychar. So, let's start with
UTF-8: it is the most used, and the structure of the encoding
makes the correctness more obvious. */
- add_utf8_anychar();
- tok = lex();
+ add_utf8_anychar ();
+ tok = lex ();
}
@@ -1667,4 +1697,4 @@
{
- addtok(tok);
- tok = lex();
+ addtok (tok);
+ tok = lex ();
}
@@ -1672,10 +1702,10 @@
{
- tok = lex();
- regexp();
+ tok = lex ();
+ regexp ();
if (tok != RPAREN)
- dfaerror(_("unbalanced ("));
- tok = lex();
+ dfaerror (_("unbalanced ("));
+ tok = lex ();
}
else
- addtok(EMPTY);
+ addtok (EMPTY);
}
@@ -1695,7 +1725,7 @@
case PLUS:
- return 1 + nsubtoks(tindex - 1);
+ return 1 + nsubtoks (tindex - 1);
case CAT:
case OR:
- ntoks1 = nsubtoks(tindex - 1);
- return 1 + ntoks1 + nsubtoks(tindex - 1 - ntoks1);
+ ntoks1 = nsubtoks (tindex - 1);
+ return 1 + ntoks1 + nsubtoks (tindex - 1 - ntoks1);
}
@@ -1711,3 +1741,3 @@
{
- addtok(dfa->tokens[tindex + i]);
+ addtok (dfa->tokens[tindex + i]);
/* Update index into multibyte csets. */
@@ -1723,3 +1753,3 @@
- atom();
+ atom ();
while (tok == QMARK || tok == STAR || tok == PLUS || tok == REPMN)
@@ -1727,12 +1757,12 @@
{
- ntokens = nsubtoks(dfa->tindex);
+ ntokens = nsubtoks (dfa->tindex);
tindex = dfa->tindex - ntokens;
if (maxrep < 0)
- addtok(PLUS);
+ addtok (PLUS);
if (minrep == 0)
- addtok(QMARK);
+ addtok (QMARK);
for (i = 1; i < minrep; ++i)
{
- copytoks(tindex, ntokens);
- addtok(CAT);
+ copytoks (tindex, ntokens);
+ addtok (CAT);
}
@@ -1740,7 +1770,7 @@
{
- copytoks(tindex, ntokens);
- addtok(QMARK);
- addtok(CAT);
+ copytoks (tindex, ntokens);
+ addtok (QMARK);
+ addtok (CAT);
}
- tok = lex();
+ tok = lex ();
}
@@ -1748,5 +1778,5 @@
{
- dfa->tindex -= nsubtoks(dfa->tindex);
- tok = lex();
- closure();
+ dfa->tindex -= nsubtoks (dfa->tindex);
+ tok = lex ();
+ closure ();
}
@@ -1754,4 +1784,4 @@
{
- addtok(tok);
- tok = lex();
+ addtok (tok);
+ tok = lex ();
}
@@ -1762,7 +1792,7 @@
{
- closure();
+ closure ();
while (tok != RPAREN && tok != OR && tok >= 0)
{
- closure();
- addtok(CAT);
+ closure ();
+ addtok (CAT);
}
@@ -1773,8 +1803,8 @@
{
- branch();
+ branch ();
while (tok == OR)
{
- tok = lex();
- branch();
- addtok(OR);
+ tok = lex ();
+ branch ();
+ addtok (OR);
}
@@ -1800,21 +1830,21 @@
cur_mb_len = 0;
- memset(&mbs, 0, sizeof mbs);
+ memset (&mbs, 0, sizeof mbs);
}
- if (! syntax_bits_set)
- dfaerror(_("no syntax specified"));
+ if (!syntax_bits_set)
+ dfaerror (_("no syntax specified"));
- tok = lex();
+ tok = lex ();
depth = d->depth;
- regexp();
+ regexp ();
if (tok != END)
- dfaerror(_("unbalanced )"));
+ dfaerror (_("unbalanced )"));
- addtok(END - d->nregexps);
- addtok(CAT);
+ addtok (END - d->nregexps);
+ addtok (CAT);
if (d->nregexps)
- addtok(OR);
+ addtok (OR);
@@ -1827,6 +1857,6 @@
static void
-copy (position_set const *src, position_set *dst)
+copy (position_set const *src, position_set * dst)
{
- REALLOC_IF_NECESSARY(dst->elems, dst->alloc, src->nelem);
- memcpy(dst->elems, src->elems, sizeof(dst->elems[0]) * src->nelem);
+ REALLOC_IF_NECESSARY (dst->elems, dst->alloc, src->nelem);
+ memcpy (dst->elems, src->elems, sizeof (dst->elems[0]) * src->nelem);
dst->nelem = src->nelem;
@@ -1835,5 +1865,5 @@
static void
-alloc_position_set (position_set *s, size_t size)
+alloc_position_set (position_set * s, size_t size)
{
- MALLOC(s->elems, size);
+ MALLOC (s->elems, size);
s->alloc = size;
@@ -1847,3 +1877,3 @@
static void
-insert (position p, position_set *s)
+insert (position p, position_set * s)
{
@@ -1867,3 +1897,3 @@
- REALLOC_IF_NECESSARY(s->elems, s->alloc, count + 1);
+ REALLOC_IF_NECESSARY (s->elems, s->alloc, count + 1);
for (i = count; i > lo; i--)
@@ -1877,3 +1907,3 @@
static void
-merge (position_set const *s1, position_set const *s2, position_set *m)
+merge (position_set const *s1, position_set const *s2, position_set * m)
{
@@ -1881,3 +1911,3 @@
- REALLOC_IF_NECESSARY(m->elems, m->alloc, s1->nelem + s2->nelem);
+ REALLOC_IF_NECESSARY (m->elems, m->alloc, s1->nelem + s2->nelem);
m->nelem = 0;
@@ -1901,3 +1931,3 @@
static void
-delete (position p, position_set *s)
+delete (position p, position_set * s)
{
@@ -1946,6 +1976,6 @@
/* We'll have to create a new state. */
- REALLOC_IF_NECESSARY(d->states, d->salloc, d->sindex + 1);
+ REALLOC_IF_NECESSARY (d->states, d->salloc, d->sindex + 1);
d->states[i].hash = hash;
- alloc_position_set(&d->states[i].elems, s->nelem);
- copy(s, &d->states[i].elems);
+ alloc_position_set (&d->states[i].elems, s->nelem);
+ copy (s, &d->states[i].elems);
d->states[i].newline = newline;
@@ -1964,8 +1994,8 @@
constraint = s->elems[j].constraint;
- if (SUCCEEDS_IN_CONTEXT(constraint, newline, 0, letter, 0)
- || SUCCEEDS_IN_CONTEXT(constraint, newline, 0, letter, 1)
- || SUCCEEDS_IN_CONTEXT(constraint, newline, 1, letter, 0)
- || SUCCEEDS_IN_CONTEXT(constraint, newline, 1, letter, 1))
+ if (SUCCEEDS_IN_CONTEXT (constraint, newline, 0, letter, 0)
+ || SUCCEEDS_IN_CONTEXT (constraint, newline, 0, letter, 1)
+ || SUCCEEDS_IN_CONTEXT (constraint, newline, 1, letter, 0)
+ || SUCCEEDS_IN_CONTEXT (constraint, newline, 1, letter, 1))
d->states[i].constraint |= constraint;
- if (! d->states[i].first_end)
+ if (!d->states[i].first_end)
d->states[i].first_end = d->tokens[s->elems[j].index];
@@ -1989,9 +2019,9 @@
static void
-epsclosure (position_set *s, struct dfa const *d)
+epsclosure (position_set * s, struct dfa const *d)
{
int i, j;
- char *visited; /* array of booleans, enough to use char, not int */
+ char *visited; /* array of booleans, enough to use char, not
int */
position p, old;
- CALLOC(visited, d->tindex);
+ CALLOC (visited, d->tindex);
@@ -2008,3 +2038,3 @@
p.constraint = old.constraint;
- delete(s->elems[i], s);
+ delete (s->elems[i], s);
if (visited[old.index])
@@ -2041,3 +2071,3 @@
p.index = d->follows[old.index].elems[j].index;
- insert(p, s);
+ insert (p, s);
}
@@ -2047,3 +2077,3 @@
- free(visited);
+ free (visited);
}
@@ -2120,9 +2150,9 @@
#ifdef DEBUG
- fprintf(stderr, "dfaanalyze:\n");
+ fprintf (stderr, "dfaanalyze:\n");
for (i = 0; i < d->tindex; ++i)
{
- fprintf(stderr, " %d:", i);
- prtok(d->tokens[i]);
+ fprintf (stderr, " %d:", i);
+ prtok (d->tokens[i]);
}
- putc('\n', stderr);
+ putc ('\n', stderr);
#endif
@@ -2131,15 +2161,15 @@
- MALLOC(nullable, d->depth);
+ MALLOC (nullable, d->depth);
o_nullable = nullable;
- MALLOC(nfirstpos, d->depth);
+ MALLOC (nfirstpos, d->depth);
o_nfirst = nfirstpos;
- MALLOC(firstpos, d->nleaves);
+ MALLOC (firstpos, d->nleaves);
o_firstpos = firstpos, firstpos += d->nleaves;
- MALLOC(nlastpos, d->depth);
+ MALLOC (nlastpos, d->depth);
o_nlast = nlastpos;
- MALLOC(lastpos, d->nleaves);
+ MALLOC (lastpos, d->nleaves);
o_lastpos = lastpos, lastpos += d->nleaves;
- alloc_position_set(&merged, d->nleaves);
+ alloc_position_set (&merged, d->nleaves);
- CALLOC(d->follows, d->tindex);
+ CALLOC (d->follows, d->tindex);
@@ -2147,121 +2177,121 @@
{
- switch (d->tokens[i])
- {
- case EMPTY:
- /* The empty set is nullable. */
- *nullable++ = 1;
+ switch (d->tokens[i])
+ {
+ case EMPTY:
+ /* The empty set is nullable. */
+ *nullable++ = 1;
- /* The firstpos and lastpos of the empty leaf are both empty. */
- *nfirstpos++ = *nlastpos++ = 0;
- break;
+ /* The firstpos and lastpos of the empty leaf are both empty. */
+ *nfirstpos++ = *nlastpos++ = 0;
+ break;
- case STAR:
- case PLUS:
- /* Every element in the firstpos of the argument is in the follow
- of every element in the lastpos. */
- tmp.nelem = nfirstpos[-1];
- tmp.elems = firstpos;
- pos = lastpos;
- for (j = 0; j < nlastpos[-1]; ++j)
- {
- merge(&tmp, &d->follows[pos[j].index], &merged);
- copy(&merged, &d->follows[pos[j].index]);
- }
+ case STAR:
+ case PLUS:
+ /* Every element in the firstpos of the argument is in the follow
+ of every element in the lastpos. */
+ tmp.nelem = nfirstpos[-1];
+ tmp.elems = firstpos;
+ pos = lastpos;
+ for (j = 0; j < nlastpos[-1]; ++j)
+ {
+ merge (&tmp, &d->follows[pos[j].index], &merged);
+ copy (&merged, &d->follows[pos[j].index]);
+ }
- case QMARK:
- /* A QMARK or STAR node is automatically nullable. */
- if (d->tokens[i] != PLUS)
- nullable[-1] = 1;
- break;
+ case QMARK:
+ /* A QMARK or STAR node is automatically nullable. */
+ if (d->tokens[i] != PLUS)
+ nullable[-1] = 1;
+ break;
- case CAT:
- /* Every element in the firstpos of the second argument is in the
- follow of every element in the lastpos of the first argument. */
- tmp.nelem = nfirstpos[-1];
- tmp.elems = firstpos;
- pos = lastpos + nlastpos[-1];
- for (j = 0; j < nlastpos[-2]; ++j)
- {
- merge(&tmp, &d->follows[pos[j].index], &merged);
- copy(&merged, &d->follows[pos[j].index]);
- }
+ case CAT:
+ /* Every element in the firstpos of the second argument is in the
+ follow of every element in the lastpos of the first argument. */
+ tmp.nelem = nfirstpos[-1];
+ tmp.elems = firstpos;
+ pos = lastpos + nlastpos[-1];
+ for (j = 0; j < nlastpos[-2]; ++j)
+ {
+ merge (&tmp, &d->follows[pos[j].index], &merged);
+ copy (&merged, &d->follows[pos[j].index]);
+ }
- /* The firstpos of a CAT node is the firstpos of the first argument,
- union that of the second argument if the first is nullable. */
- if (nullable[-2])
+ /* The firstpos of a CAT node is the firstpos of the first argument,
+ union that of the second argument if the first is nullable. */
+ if (nullable[-2])
+ nfirstpos[-2] += nfirstpos[-1];
+ else
+ firstpos += nfirstpos[-1];
+ --nfirstpos;
+
+ /* The lastpos of a CAT node is the lastpos of the second argument,
+ union that of the first argument if the second is nullable. */
+ if (nullable[-1])
+ nlastpos[-2] += nlastpos[-1];
+ else
+ {
+ pos = lastpos + nlastpos[-2];
+ for (j = nlastpos[-1] - 1; j >= 0; --j)
+ pos[j] = lastpos[j];
+ lastpos += nlastpos[-2];
+ nlastpos[-2] = nlastpos[-1];
+ }
+ --nlastpos;
+
+ /* A CAT node is nullable if both arguments are nullable. */
+ nullable[-2] = nullable[-1] && nullable[-2];
+ --nullable;
+ break;
+
+ case OR:
+ /* The firstpos is the union of the firstpos of each argument. */
nfirstpos[-2] += nfirstpos[-1];
- else
- firstpos += nfirstpos[-1];
- --nfirstpos;
-
- /* The lastpos of a CAT node is the lastpos of the second argument,
- union that of the first argument if the second is nullable. */
- if (nullable[-1])
- nlastpos[-2] += nlastpos[-1];
- else
- {
- pos = lastpos + nlastpos[-2];
- for (j = nlastpos[-1] - 1; j >= 0; --j)
- pos[j] = lastpos[j];
- lastpos += nlastpos[-2];
- nlastpos[-2] = nlastpos[-1];
- }
- --nlastpos;
+ --nfirstpos;
- /* A CAT node is nullable if both arguments are nullable. */
- nullable[-2] = nullable[-1] && nullable[-2];
- --nullable;
- break;
+ /* The lastpos is the union of the lastpos of each argument. */
+ nlastpos[-2] += nlastpos[-1];
+ --nlastpos;
- case OR:
- /* The firstpos is the union of the firstpos of each argument. */
- nfirstpos[-2] += nfirstpos[-1];
- --nfirstpos;
-
- /* The lastpos is the union of the lastpos of each argument. */
- nlastpos[-2] += nlastpos[-1];
- --nlastpos;
-
- /* An OR node is nullable if either argument is nullable. */
- nullable[-2] = nullable[-1] || nullable[-2];
- --nullable;
- break;
+ /* An OR node is nullable if either argument is nullable. */
+ nullable[-2] = nullable[-1] || nullable[-2];
+ --nullable;
+ break;
- default:
- /* Anything else is a nonempty position. (Note that special
- constructs like \< are treated as nonempty strings here;
- an "epsilon closure" effectively makes them nullable later.
- Backreferences have to get a real position so we can detect
- transitions on them later. But they are nullable. */
- *nullable++ = d->tokens[i] == BACKREF;
-
- /* This position is in its own firstpos and lastpos. */
- *nfirstpos++ = *nlastpos++ = 1;
- --firstpos, --lastpos;
- firstpos->index = lastpos->index = i;
- firstpos->constraint = lastpos->constraint = NO_CONSTRAINT;
+ default:
+ /* Anything else is a nonempty position. (Note that special
+ constructs like \< are treated as nonempty strings here;
+ an "epsilon closure" effectively makes them nullable later.
+ Backreferences have to get a real position so we can detect
+ transitions on them later. But they are nullable. */
+ *nullable++ = d->tokens[i] == BACKREF;
+
+ /* This position is in its own firstpos and lastpos. */
+ *nfirstpos++ = *nlastpos++ = 1;
+ --firstpos, --lastpos;
+ firstpos->index = lastpos->index = i;
+ firstpos->constraint = lastpos->constraint = NO_CONSTRAINT;
- /* Allocate the follow set for this position. */
- alloc_position_set(&d->follows[i], 1);
- break;
- }
+ /* Allocate the follow set for this position. */
+ alloc_position_set (&d->follows[i], 1);
+ break;
+ }
#ifdef DEBUG
- /* ... balance the above nonsyntactic #ifdef goo... */
- fprintf(stderr, "node %d:", i);
- prtok(d->tokens[i]);
- putc('\n', stderr);
- fprintf(stderr, nullable[-1] ? " nullable: yes\n" : " nullable: no\n");
- fprintf(stderr, " firstpos:");
+ /* ... balance the above nonsyntactic #ifdef goo... */
+ fprintf (stderr, "node %d:", i);
+ prtok (d->tokens[i]);
+ putc ('\n', stderr);
+ fprintf (stderr, nullable[-1] ? " nullable: yes\n" : " nullable: no\n");
+ fprintf (stderr, " firstpos:");
for (j = nfirstpos[-1] - 1; j >= 0; --j)
{
- fprintf(stderr, " %d:", firstpos[j].index);
- prtok(d->tokens[firstpos[j].index]);
+ fprintf (stderr, " %d:", firstpos[j].index);
+ prtok (d->tokens[firstpos[j].index]);
}
- fprintf(stderr, "\n lastpos:");
+ fprintf (stderr, "\n lastpos:");
for (j = nlastpos[-1] - 1; j >= 0; --j)
{
- fprintf(stderr, " %d:", lastpos[j].index);
- prtok(d->tokens[lastpos[j].index]);
+ fprintf (stderr, " %d:", lastpos[j].index);
+ prtok (d->tokens[lastpos[j].index]);
}
- putc('\n', stderr);
+ putc ('\n', stderr);
#endif
@@ -2274,4 +2304,3 @@
#if MBS_SUPPORT
- || d->tokens[i] == ANYCHAR
- || d->tokens[i] == MBCSET
+ || d->tokens[i] == ANYCHAR || d->tokens[i] == MBCSET
#endif
@@ -2280,15 +2309,15 @@
#ifdef DEBUG
- fprintf(stderr, "follows(%d:", i);
- prtok(d->tokens[i]);
- fprintf(stderr, "):");
+ fprintf (stderr, "follows(%d:", i);
+ prtok (d->tokens[i]);
+ fprintf (stderr, "):");
for (j = d->follows[i].nelem - 1; j >= 0; --j)
{
- fprintf(stderr, " %d:", d->follows[i].elems[j].index);
- prtok(d->tokens[d->follows[i].elems[j].index]);
+ fprintf (stderr, " %d:", d->follows[i].elems[j].index);
+ prtok (d->tokens[d->follows[i].elems[j].index]);
}
- putc('\n', stderr);
+ putc ('\n', stderr);
#endif
- copy(&d->follows[i], &merged);
- epsclosure(&merged, d);
- copy(&merged, &d->follows[i]);
+ copy (&d->follows[i], &merged);
+ epsclosure (&merged, d);
+ copy (&merged, &d->follows[i]);
}
@@ -2299,4 +2328,4 @@
for (i = 0; i < nfirstpos[-1]; ++i)
- insert(firstpos[i], &merged);
- epsclosure(&merged, d);
+ insert (firstpos[i], &merged);
+ epsclosure (&merged, d);
@@ -2305,3 +2334,3 @@
for (i = 0; i < merged.nelem; ++i)
- if (PREV_NEWLINE_DEPENDENT(merged.elems[i].constraint))
+ if (PREV_NEWLINE_DEPENDENT (merged.elems[i].constraint))
wants_newline = 1;
@@ -2311,11 +2340,11 @@
d->sindex = 0;
- MALLOC(d->states, d->salloc);
- state_index(d, &merged, wants_newline, 0);
+ MALLOC (d->states, d->salloc);
+ state_index (d, &merged, wants_newline, 0);
- free(o_nullable);
- free(o_nfirst);
- free(o_firstpos);
- free(o_nlast);
- free(o_lastpos);
- free(merged.elems);
+ free (o_nullable);
+ free (o_nfirst);
+ free (o_firstpos);
+ free (o_nlast);
+ free (o_lastpos);
+ free (merged.elems);
}
@@ -2382,3 +2411,3 @@
/* Initialize the set of letters, if necessary. */
- if (! initialized)
+ if (!initialized)
{
@@ -2386,8 +2415,8 @@
for (i = 0; i < NOTCHAR; ++i)
- if (IS_WORD_CONSTITUENT(i))
- setbit(i, letters);
- setbit(eolbyte, newline);
+ if (IS_WORD_CONSTITUENT (i))
+ setbit (i, letters);
+ setbit (eolbyte, newline);
}
- zeroset(matches);
+ zeroset (matches);
@@ -2397,5 +2426,5 @@
if (d->tokens[pos.index] >= 0 && d->tokens[pos.index] < NOTCHAR)
- setbit(d->tokens[pos.index], matches);
+ setbit (d->tokens[pos.index], matches);
else if (d->tokens[pos.index] >= CSET)
- copyset(d->charclasses[d->tokens[pos.index] - CSET], matches);
+ copyset (d->charclasses[d->tokens[pos.index] - CSET], matches);
else if (MBS_SUPPORT
@@ -2409,4 +2438,4 @@
if (d->states[s].mbps.nelem == 0)
- alloc_position_set(&d->states[s].mbps, 1);
- insert(pos, &(d->states[s].mbps));
+ alloc_position_set (&d->states[s].mbps, 1);
+ insert (pos, &(d->states[s].mbps));
continue;
@@ -2420,15 +2449,13 @@
{
- if (! MATCHES_NEWLINE_CONTEXT(pos.constraint,
- d->states[s].newline, 1))
- clrbit(eolbyte, matches);
- if (! MATCHES_NEWLINE_CONTEXT(pos.constraint,
- d->states[s].newline, 0))
+ if (!MATCHES_NEWLINE_CONTEXT (pos.constraint,
+ d->states[s].newline, 1))
+ clrbit (eolbyte, matches);
+ if (!MATCHES_NEWLINE_CONTEXT (pos.constraint,
+ d->states[s].newline, 0))
for (j = 0; j < CHARCLASS_INTS; ++j)
matches[j] &= newline[j];
- if (! MATCHES_LETTER_CONTEXT(pos.constraint,
- d->states[s].letter, 1))
+ if (!MATCHES_LETTER_CONTEXT (pos.constraint, d->states[s].letter, 1))
for (j = 0; j < CHARCLASS_INTS; ++j)
matches[j] &= ~letters[j];
- if (! MATCHES_LETTER_CONTEXT(pos.constraint,
- d->states[s].letter, 0))
+ if (!MATCHES_LETTER_CONTEXT (pos.constraint, d->states[s].letter, 0))
for (j = 0; j < CHARCLASS_INTS; ++j)
@@ -2449,3 +2476,3 @@
if (d->tokens[pos.index] >= 0 && d->tokens[pos.index] < NOTCHAR
- && !tstbit(d->tokens[pos.index], labels[j]))
+ && !tstbit (d->tokens[pos.index], labels[j]))
continue;
@@ -2457,3 +2484,3 @@
(intersect[k] = matches[k] & labels[j][k]) ? (intersectf = 1) : 0;
- if (! intersectf)
+ if (!intersectf)
continue;
@@ -2474,7 +2501,7 @@
{
- copyset(leftovers, labels[ngrps]);
- copyset(intersect, labels[j]);
- MALLOC(grps[ngrps].elems, d->nleaves);
- memcpy(grps[ngrps].elems, grps[j].elems,
- sizeof (grps[j].elems[0]) * grps[j].nelem);
+ copyset (leftovers, labels[ngrps]);
+ copyset (intersect, labels[j]);
+ MALLOC (grps[ngrps].elems, d->nleaves);
+ memcpy (grps[ngrps].elems, grps[j].elems,
+ sizeof (grps[j].elems[0]) * grps[j].nelem);
grps[ngrps].nelem = grps[j].nelem;
@@ -2489,3 +2516,3 @@
accounted for, we're done. */
- if (! matchesf)
+ if (!matchesf)
break;
@@ -2497,5 +2524,5 @@
{
- copyset(matches, labels[ngrps]);
- zeroset(matches);
- MALLOC(grps[ngrps].elems, d->nleaves);
+ copyset (matches, labels[ngrps]);
+ zeroset (matches);
+ MALLOC (grps[ngrps].elems, d->nleaves);
grps[ngrps].nelem = 1;
@@ -2506,4 +2533,4 @@
- alloc_position_set(&follows, d->nleaves);
- alloc_position_set(&tmp, d->nleaves);
+ alloc_position_set (&follows, d->nleaves);
+ alloc_position_set (&tmp, d->nleaves);
@@ -2518,11 +2545,11 @@
{
- if (PREV_NEWLINE_DEPENDENT(d->states[0].elems.elems[i].constraint))
+ if (PREV_NEWLINE_DEPENDENT (d->states[0].elems.elems[i].constraint))
wants_newline = 1;
- if (PREV_LETTER_DEPENDENT(d->states[0].elems.elems[i].constraint))
+ if (PREV_LETTER_DEPENDENT (d->states[0].elems.elems[i].constraint))
wants_letter = 1;
}
- copy(&d->states[0].elems, &follows);
- state = state_index(d, &follows, 0, 0);
+ copy (&d->states[0].elems, &follows);
+ state = state_index (d, &follows, 0, 0);
if (wants_newline)
- state_newline = state_index(d, &follows, 1, 0);
+ state_newline = state_index (d, &follows, 1, 0);
else
@@ -2530,3 +2557,3 @@
if (wants_letter)
- state_letter = state_index(d, &follows, 0, 1);
+ state_letter = state_index (d, &follows, 0, 1);
else
@@ -2534,3 +2561,3 @@
for (i = 0; i < NOTCHAR; ++i)
- trans[i] = (IS_WORD_CONSTITUENT(i)) ? state_letter : state;
+ trans[i] = (IS_WORD_CONSTITUENT (i)) ? state_letter : state;
trans[eolbyte] = state_newline;
@@ -2549,3 +2576,3 @@
for (k = 0; k < d->follows[grps[i].elems[j]].nelem; ++k)
- insert(d->follows[grps[i].elems[j]].elems[k], &follows);
+ insert (d->follows[grps[i].elems[j]].elems[k], &follows);
@@ -2585,6 +2612,5 @@
if (d->searchflag
- && (! MBS_SUPPORT
- || (d->mb_cur_max == 1 || !next_isnt_1st_byte)))
+ && (!MBS_SUPPORT || (d->mb_cur_max == 1 || !next_isnt_1st_byte)))
for (j = 0; j < d->states[0].elems.nelem; ++j)
- insert(d->states[0].elems.elems[j], &follows);
+ insert (d->states[0].elems.elems[j], &follows);
@@ -2592,5 +2618,5 @@
wants_newline = 0;
- if (tstbit(eolbyte, labels[i]))
+ if (tstbit (eolbyte, labels[i]))
for (j = 0; j < follows.nelem; ++j)
- if (PREV_NEWLINE_DEPENDENT(follows.elems[j].constraint))
+ if (PREV_NEWLINE_DEPENDENT (follows.elems[j].constraint))
wants_newline = 1;
@@ -2603,3 +2629,3 @@
for (j = 0; j < follows.nelem; ++j)
- if (PREV_LETTER_DEPENDENT(follows.elems[j].constraint))
+ if (PREV_LETTER_DEPENDENT (follows.elems[j].constraint))
wants_letter = 1;
@@ -2607,5 +2633,5 @@
/* Find the state(s) corresponding to the union of the follows. */
- state = state_index(d, &follows, 0, 0);
+ state = state_index (d, &follows, 0, 0);
if (wants_newline)
- state_newline = state_index(d, &follows, 1, 0);
+ state_newline = state_index (d, &follows, 1, 0);
else
@@ -2613,3 +2639,3 @@
if (wants_letter)
- state_letter = state_index(d, &follows, 0, 1);
+ state_letter = state_index (d, &follows, 0, 1);
else
@@ -2626,3 +2652,3 @@
trans[c] = state_newline;
- else if (IS_WORD_CONSTITUENT(c))
+ else if (IS_WORD_CONSTITUENT (c))
trans[c] = state_letter;
@@ -2634,7 +2660,7 @@
for (i = 0; i < ngrps; ++i)
- free(grps[i].elems);
- free(follows.elems);
- free(tmp.elems);
- free(grps);
- free(labels);
+ free (grps[i].elems);
+ free (follows.elems);
+ free (tmp.elems);
+ free (grps);
+ free (labels);
}
@@ -2662,4 +2688,4 @@
{
- free(d->trans[i]);
- free(d->fails[i]);
+ free (d->trans[i]);
+ free (d->fails[i]);
d->trans[i] = d->fails[i] = NULL;
@@ -2673,14 +2699,14 @@
d->success[s] = 0;
- if (ACCEPTS_IN_CONTEXT(d->states[s].newline, 1, d->states[s].letter, 0,
- s, *d))
+ if (ACCEPTS_IN_CONTEXT (d->states[s].newline, 1, d->states[s].letter, 0,
+ s, *d))
d->success[s] |= 4;
- if (ACCEPTS_IN_CONTEXT(d->states[s].newline, 0, d->states[s].letter, 1,
- s, *d))
+ if (ACCEPTS_IN_CONTEXT (d->states[s].newline, 0, d->states[s].letter, 1,
+ s, *d))
d->success[s] |= 2;
- if (ACCEPTS_IN_CONTEXT(d->states[s].newline, 0, d->states[s].letter, 0,
- s, *d))
+ if (ACCEPTS_IN_CONTEXT (d->states[s].newline, 0, d->states[s].letter, 0,
+ s, *d))
d->success[s] |= 1;
- MALLOC(trans, NOTCHAR);
- dfastate(s, d, trans);
+ MALLOC (trans, NOTCHAR);
+ dfastate (s, d, trans);
@@ -2696,7 +2722,7 @@
d->tralloc *= 2;
- REALLOC(d->realtrans, d->tralloc + 1);
+ REALLOC (d->realtrans, d->tralloc + 1);
d->trans = d->realtrans + 1;
- REALLOC(d->fails, d->tralloc);
- REALLOC(d->success, d->tralloc);
- REALLOC(d->newlines, d->tralloc);
+ REALLOC (d->fails, d->tralloc);
+ REALLOC (d->success, d->tralloc);
+ REALLOC (d->newlines, d->tralloc);
while (oldalloc < d->tralloc)
@@ -2713,3 +2739,3 @@
- if (ACCEPTING(s, *d))
+ if (ACCEPTING (s, *d))
d->fails[s] = trans;
@@ -2724,8 +2750,8 @@
d->trcount = 0;
- CALLOC(d->realtrans, d->tralloc + 1);
+ CALLOC (d->realtrans, d->tralloc + 1);
d->trans = d->realtrans + 1;
- CALLOC(d->fails, d->tralloc);
- MALLOC(d->success, d->tralloc);
- MALLOC(d->newlines, d->tralloc);
- build_state(0, d);
+ CALLOC (d->fails, d->tralloc);
+ MALLOC (d->success, d->tralloc);
+ MALLOC (d->newlines, d->tralloc);
+ build_state (0, d);
}
@@ -2758,3 +2784,3 @@
static void
-realloc_trans_if_necessary(struct dfa *d, int new_state)
+realloc_trans_if_necessary (struct dfa *d, int new_state)
{
@@ -2768,7 +2794,7 @@
d->tralloc *= 2;
- REALLOC(d->realtrans, d->tralloc + 1);
+ REALLOC (d->realtrans, d->tralloc + 1);
d->trans = d->realtrans + 1;
- REALLOC(d->fails, d->tralloc);
- REALLOC(d->success, d->tralloc);
- REALLOC(d->newlines, d->tralloc);
+ REALLOC (d->fails, d->tralloc);
+ REALLOC (d->success, d->tralloc);
+ REALLOC (d->newlines, d->tralloc);
while (oldalloc < d->tralloc)
@@ -2796,3 +2822,3 @@
transit_state_singlebyte (struct dfa *d, int s, unsigned char const *p,
- int *next_state)
+ int *next_state)
{
@@ -2828,3 +2854,3 @@
{
- build_state(works, d);
+ build_state (works, d);
}
@@ -2847,6 +2873,6 @@
wc = inputwcs[idx];
- mbclen = (mblen_buf[idx] == 0)? 1 : mblen_buf[idx];
+ mbclen = (mblen_buf[idx] == 0) ? 1 : mblen_buf[idx];
/* Check context. */
- if (wc == (wchar_t)eolbyte)
+ if (wc == (wchar_t) eolbyte)
{
@@ -2856,3 +2882,3 @@
}
- else if (wc == (wchar_t)'\0')
+ else if (wc == (wchar_t) '\0')
{
@@ -2863,7 +2889,7 @@
- if (iswalnum(wc) || wc == L'_')
+ if (iswalnum (wc) || wc == L'_')
letter = 1;
- if (!SUCCEEDS_IN_CONTEXT(pos.constraint, d->states[s].newline,
- newline, d->states[s].letter, letter))
+ if (!SUCCEEDS_IN_CONTEXT (pos.constraint, d->states[s].newline,
+ newline, d->states[s].letter, letter))
return 0;
@@ -2881,6 +2907,6 @@
int i;
- int match; /* Flag which represent that matching succeed. */
- int match_len; /* Length of the character (or collating element)
- with which this operator match. */
- int op_len; /* Length of the operator. */
+ int match; /* Flag which represent that matching succeed.
*/
+ int match_len; /* Length of the character (or collating
element)
+ with which this operator match. */
+ int op_len; /* Length of the operator. */
char buffer[128];
@@ -2893,3 +2919,3 @@
int letter = 0;
- wchar_t wc; /* Current refering character. */
+ wchar_t wc; /* Current refering character. */
@@ -2898,3 +2924,3 @@
/* Check context. */
- if (wc == (wchar_t)eolbyte)
+ if (wc == (wchar_t) eolbyte)
{
@@ -2904,3 +2930,3 @@
}
- else if (wc == (wchar_t)'\0')
+ else if (wc == (wchar_t) '\0')
{
@@ -2910,6 +2936,6 @@
}
- if (iswalnum(wc) || wc == L'_')
+ if (iswalnum (wc) || wc == L'_')
letter = 1;
- if (!SUCCEEDS_IN_CONTEXT(pos.constraint, d->states[s].newline,
- newline, d->states[s].letter, letter))
+ if (!SUCCEEDS_IN_CONTEXT (pos.constraint, d->states[s].newline,
+ newline, d->states[s].letter, letter))
return 0;
@@ -2919,3 +2945,3 @@
match = !work_mbc->invert;
- match_len = (mblen_buf[idx] == 0)? 1 : mblen_buf[idx];
+ match_len = (mblen_buf[idx] == 0) ? 1 : mblen_buf[idx];
@@ -2923,3 +2949,3 @@
if (wc < NOTCHAR && work_mbc->cset != -1
- && tstbit((unsigned char)wc, d->charclasses[work_mbc->cset]))
+ && tstbit ((unsigned char) wc, d->charclasses[work_mbc->cset]))
goto charset_matched;
@@ -2927,5 +2953,5 @@
/* match with a character class? */
- for (i = 0; i<work_mbc->nch_classes; i++)
+ for (i = 0; i < work_mbc->nch_classes; i++)
{
- if (iswctype((wint_t)wc, work_mbc->ch_classes[i]))
+ if (iswctype ((wint_t) wc, work_mbc->ch_classes[i]))
goto charset_matched;
@@ -2933,3 +2959,3 @@
- strncpy(buffer, (char const *) buf_begin + idx, match_len);
+ strncpy (buffer, (char const *) buf_begin + idx, match_len);
buffer[match_len] = '\0';
@@ -2937,8 +2963,8 @@
/* match with an equivalent class? */
- for (i = 0; i<work_mbc->nequivs; i++)
+ for (i = 0; i < work_mbc->nequivs; i++)
{
- op_len = strlen(work_mbc->equivs[i]);
- strncpy(buffer, (char const *) buf_begin + idx, op_len);
+ op_len = strlen (work_mbc->equivs[i]);
+ strncpy (buffer, (char const *) buf_begin + idx, op_len);
buffer[op_len] = '\0';
- if (strcoll(work_mbc->equivs[i], buffer) == 0)
+ if (strcoll (work_mbc->equivs[i], buffer) == 0)
{
@@ -2950,9 +2976,9 @@
/* match with a collating element? */
- for (i = 0; i<work_mbc->ncoll_elems; i++)
+ for (i = 0; i < work_mbc->ncoll_elems; i++)
{
- op_len = strlen(work_mbc->coll_elems[i]);
- strncpy(buffer, (char const *) buf_begin + idx, op_len);
+ op_len = strlen (work_mbc->coll_elems[i]);
+ strncpy (buffer, (char const *) buf_begin + idx, op_len);
buffer[op_len] = '\0';
- if (strcoll(work_mbc->coll_elems[i], buffer) == 0)
+ if (strcoll (work_mbc->coll_elems[i], buffer) == 0)
{
@@ -2967,3 +2993,3 @@
/* match with a range? */
- for (i = 0; i<work_mbc->nranges; i++)
+ for (i = 0; i < work_mbc->nranges; i++)
{
@@ -2972,4 +2998,3 @@
- if (wcscoll(wcbuf, wcbuf+2) >= 0 &&
- wcscoll(wcbuf+4, wcbuf) >= 0)
+ if (wcscoll (wcbuf, wcbuf + 2) >= 0 && wcscoll (wcbuf + 4, wcbuf) >= 0)
goto charset_matched;
@@ -2978,3 +3003,3 @@
/* match with a character? */
- for (i = 0; i<work_mbc->nchars; i++)
+ for (i = 0; i < work_mbc->nchars; i++)
{
@@ -2986,3 +3011,3 @@
- charset_matched:
+charset_matched:
return match ? match_len : 0;
@@ -2997,3 +3022,3 @@
Caller MUST free the array which this function return. */
-static int*
+static int *
check_matching_with_multibyte_ops (struct dfa *d, int s, int idx)
@@ -3001,5 +3026,5 @@
int i;
- int* rarray;
+ int *rarray;
- MALLOC(rarray, d->states[s].mbps.nelem);
+ MALLOC (rarray, d->states[s].mbps.nelem);
for (i = 0; i < d->states[s].mbps.nelem; ++i)
@@ -3007,12 +3032,12 @@
position pos = d->states[s].mbps.elems[i];
- switch(d->tokens[pos.index])
+ switch (d->tokens[pos.index])
{
case ANYCHAR:
- rarray[i] = match_anychar(d, s, pos, idx);
+ rarray[i] = match_anychar (d, s, pos, idx);
break;
case MBCSET:
- rarray[i] = match_mb_charset(d, s, pos, idx);
+ rarray[i] = match_mb_charset (d, s, pos, idx);
break;
default:
- break; /* cannot happen. */
+ break; /* cannot happen. */
}
@@ -3030,3 +3055,3 @@
transit_state_consume_1char (struct dfa *d, int s, unsigned char const **pp,
- int *match_lens, int *mbclen, position_set *pps)
+ int *match_lens, int *mbclen, position_set * pps)
{
@@ -3034,3 +3059,3 @@
int s1, s2;
- int* work_mbls;
+ int *work_mbls;
status_transit_state rs = TRANSIT_STATE_DONE;
@@ -3039,4 +3064,3 @@
to which p points. */
- *mbclen = (mblen_buf[*pp - buf_begin] == 0)? 1
- : mblen_buf[*pp - buf_begin];
+ *mbclen = (mblen_buf[*pp - buf_begin] == 0) ? 1 : mblen_buf[*pp - buf_begin];
@@ -3048,6 +3072,6 @@
s2 = s1;
- rs = transit_state_singlebyte(d, s2, (*pp)++, &s1);
+ rs = transit_state_singlebyte (d, s2, (*pp)++, &s1);
}
/* Copy the positions contained by `s1' to the set `pps'. */
- copy(&(d->states[s1].elems), pps);
+ copy (&(d->states[s1].elems), pps);
@@ -3055,3 +3079,3 @@
if (match_lens == NULL && d->states[s].mbps.nelem != 0)
- work_mbls = check_matching_with_multibyte_ops(d, s, *pp - buf_begin);
+ work_mbls = check_matching_with_multibyte_ops (d, s, *pp - buf_begin);
else
@@ -3061,4 +3085,4 @@
a single character. */
- for (i = 0; i < d->states[s].mbps.nelem ; i++)
- {
+ for (i = 0; i < d->states[s].mbps.nelem; i++)
+ {
if (work_mbls[i] == *mbclen)
@@ -3066,4 +3090,3 @@
j++)
- insert(d->follows[d->states[s].mbps.elems[i].index].elems[j],
- pps);
+ insert (d->follows[d->states[s].mbps.elems[i].index].elems[j], pps);
}
@@ -3071,3 +3094,3 @@
if (match_lens == NULL && work_mbls != NULL)
- free(work_mbls);
+ free (work_mbls);
return rs;
@@ -3082,3 +3105,3 @@
int s1;
- int mbclen; /* The length of current input multibyte character. */
+ int mbclen; /* The length of current input multibyte
character. */
int maxlen = 0;
@@ -3086,3 +3109,3 @@
int *match_lens = NULL;
- int nelem = d->states[s].mbps.nelem; /* Just a alias. */
+ int nelem = d->states[s].mbps.nelem; /* Just a alias. */
position_set follows;
@@ -3096,3 +3119,3 @@
/* Note: caller must free the return value of this function. */
- match_lens = check_matching_with_multibyte_ops(d, s, *pp - buf_begin);
+ match_lens = check_matching_with_multibyte_ops (d, s, *pp - buf_begin);
@@ -3112,3 +3135,3 @@
status_transit_state rs;
- rs = transit_state_singlebyte(d, s, *pp, &s1);
+ rs = transit_state_singlebyte (d, s, *pp, &s1);
@@ -3116,5 +3139,5 @@
if (rs == TRANSIT_STATE_DONE)
- ++*pp;
+ ++ * pp;
- free(match_lens);
+ free (match_lens);
return s1;
@@ -3123,3 +3146,3 @@
/* This state has some operators which can match a multibyte character. */
- alloc_position_set(&follows, d->nleaves);
+ alloc_position_set (&follows, d->nleaves);
@@ -3129,7 +3152,7 @@
`maxlen' bytes. */
- transit_state_consume_1char(d, s, pp, match_lens, &mbclen, &follows);
+ transit_state_consume_1char (d, s, pp, match_lens, &mbclen, &follows);
wc = inputwcs[*pp - mbclen - buf_begin];
- s1 = state_index(d, &follows, wc == L'\n', iswalnum(wc));
- realloc_trans_if_necessary(d, s1);
+ s1 = state_index (d, &follows, wc == L'\n', iswalnum (wc));
+ realloc_trans_if_necessary (d, s1);
@@ -3137,5 +3160,5 @@
{
- transit_state_consume_1char(d, s1, pp, NULL, &mbclen, &follows);
+ transit_state_consume_1char (d, s1, pp, NULL, &mbclen, &follows);
- for (i = 0; i < nelem ; i++)
+ for (i = 0; i < nelem; i++)
{
@@ -3144,4 +3167,4 @@
j < d->follows[d->states[s1].mbps.elems[i].index].nelem; j++)
- insert(d->follows[d->states[s1].mbps.elems[i].index].elems[j],
- &follows);
+ insert (d->follows[d->states[s1].mbps.elems[i].index].elems[j],
+ &follows);
}
@@ -3149,7 +3172,7 @@
wc = inputwcs[*pp - mbclen - buf_begin];
- s1 = state_index(d, &follows, wc == L'\n', iswalnum(wc));
- realloc_trans_if_necessary(d, s1);
+ s1 = state_index (d, &follows, wc == L'\n', iswalnum (wc));
+ realloc_trans_if_necessary (d, s1);
}
- free(match_lens);
- free(follows.elems);
+ free (match_lens);
+ free (follows.elems);
return s1;
@@ -3157,3 +3180,2 @@
-
/* Initialize mblen_buf and inputwcs with data from the next line. */
@@ -3175,3 +3197,3 @@
remain_bytes
- = mbrtowc(inputwcs + i, begin + i, end - begin - i + 1, &mbs);
+ = mbrtowc (inputwcs + i, begin + i, end - begin - i + 1, &mbs);
if (remain_bytes < 1
@@ -3179,6 +3201,6 @@
|| remain_bytes == (size_t) -2
- || (remain_bytes == 1 && inputwcs[i] == (wchar_t)begin[i]))
+ || (remain_bytes == 1 && inputwcs[i] == (wchar_t) begin[i]))
{
remain_bytes = 0;
- inputwcs[i] = (wchar_t)begin[i];
+ inputwcs[i] = (wchar_t) begin[i];
mblen_buf[i] = 0;
@@ -3203,3 +3225,3 @@
mblen_buf[i] = 0;
- inputwcs[i] = 0; /* sentinel */
+ inputwcs[i] = 0; /* sentinel */
#endif /* MBS_SUPPORT */
@@ -3223,5 +3245,5 @@
{
- int s, s1; /* Current state. */
- unsigned char const *p; /* Current input character. */
- int **trans, *t; /* Copy of d->trans so it can be optimized
+ int s, s1; /* Current state. */
+ unsigned char const *p; /* Current input character. */
+ int **trans, *t; /* Copy of d->trans so it can be optimized
into a register. */
@@ -3232,3 +3254,3 @@
- if (! sbit_init)
+ if (!sbit_init)
{
@@ -3238,3 +3260,3 @@
for (i = 0; i < NOTCHAR; ++i)
- sbit[i] = (IS_WORD_CONSTITUENT(i)) ? 2 : 1;
+ sbit[i] = (IS_WORD_CONSTITUENT (i)) ? 2 : 1;
sbit[eol] = 4;
@@ -3242,4 +3264,4 @@
- if (! d->tralloc)
- build_state_zero(d);
+ if (!d->tralloc)
+ build_state_zero (d);
@@ -3253,5 +3275,5 @@
{
- MALLOC(mblen_buf, end - begin + 2);
- MALLOC(inputwcs, end - begin + 2);
- memset(&mbs, 0, sizeof(mbstate_t));
+ MALLOC (mblen_buf, end - begin + 2);
+ MALLOC (inputwcs, end - begin + 2);
+ memset (&mbs, 0, sizeof (mbstate_t));
prepare_wc_buf ((const char *) p, end);
@@ -3267,3 +3289,3 @@
s1 = s;
- SKIP_REMAINS_MB_IF_INITIAL_STATE(s, p);
+ SKIP_REMAINS_MB_IF_INITIAL_STATE (s, p);
@@ -3282,4 +3304,4 @@
*backref = 1;
- free(mblen_buf);
- free(inputwcs);
+ free (mblen_buf);
+ free (inputwcs);
*end = saved_end;
@@ -3290,3 +3312,3 @@
collating element). Transition table might be updated. */
- s = transit_state(d, s, &p);
+ s = transit_state (d, s, &p);
trans = d->trans;
@@ -3300,3 +3322,5 @@
{
- int tmp = s; s = s1; s1 = tmp; /* swap */
+ int tmp = s;
+ s = s1;
+ s1 = tmp; /* swap */
break;
@@ -3315,4 +3339,4 @@
{
- free(mblen_buf);
- free(inputwcs);
+ free (mblen_buf);
+ free (inputwcs);
}
@@ -3327,3 +3351,3 @@
collating element). Transition table might be updated. */
- s = transit_state(d, s, &p);
+ s = transit_state (d, s, &p);
trans = d->trans;
@@ -3339,3 +3363,3 @@
if (count)
- ++*count;
+ ++ * count;
@@ -3350,4 +3374,4 @@
{
- free(mblen_buf);
- free(inputwcs);
+ free (mblen_buf);
+ free (inputwcs);
}
@@ -3359,3 +3383,3 @@
{
- build_state(s, d);
+ build_state (s, d);
trans = d->trans;
@@ -3379,3 +3403,3 @@
- free(d->multibyte_prop);
+ free (d->multibyte_prop);
d->multibyte_prop = NULL;
@@ -3386,17 +3410,17 @@
struct mb_char_classes *p = &(d->mbcsets[i]);
- free(p->chars);
- free(p->ch_classes);
- free(p->range_sts);
- free(p->range_ends);
+ free (p->chars);
+ free (p->ch_classes);
+ free (p->range_sts);
+ free (p->range_ends);
for (j = 0; j < p->nequivs; ++j)
- free(p->equivs[j]);
- free(p->equivs);
+ free (p->equivs[j]);
+ free (p->equivs);
for (j = 0; j < p->ncoll_elems; ++j)
- free(p->coll_elems[j]);
- free(p->coll_elems);
+ free (p->coll_elems[j]);
+ free (p->coll_elems);
}
- free(d->mbcsets);
+ free (d->mbcsets);
d->mbcsets = NULL;
@@ -3413,6 +3437,6 @@
d->calloc = 1;
- MALLOC(d->charclasses, d->calloc);
+ MALLOC (d->charclasses, d->calloc);
d->talloc = 1;
- MALLOC(d->tokens, d->talloc);
+ MALLOC (d->tokens, d->talloc);
@@ -3423,5 +3447,5 @@
d->nmultibyte_prop = 1;
- MALLOC(d->multibyte_prop, d->nmultibyte_prop);
+ MALLOC (d->multibyte_prop, d->nmultibyte_prop);
d->mbcsets_alloc = 1;
- MALLOC(d->mbcsets, d->mbcsets_alloc);
+ MALLOC (d->mbcsets, d->mbcsets_alloc);
}
@@ -3434,3 +3458,3 @@
- if (!MBS_SUPPORT || !using_utf8())
+ if (!MBS_SUPPORT || !using_utf8 ())
return;
@@ -3439,3 +3463,3 @@
{
- switch(d->tokens[i])
+ switch (d->tokens[i])
{
@@ -3460,7 +3484,7 @@
{
- dfainit(d);
- dfaparse(s, len, d);
- dfamust(d);
- dfaoptimize(d);
- dfaanalyze(d, searchflag);
+ dfainit (d);
+ dfaparse (s, len, d);
+ dfamust (d);
+ dfaoptimize (d);
+ dfaanalyze (d, searchflag);
}
@@ -3474,26 +3498,27 @@
- free(d->charclasses);
- free(d->tokens);
+ free (d->charclasses);
+ free (d->tokens);
if (d->mb_cur_max > 1)
- free_mbdata(d);
+ free_mbdata (d);
- for (i = 0; i < d->sindex; ++i) {
- free(d->states[i].elems.elems);
- if (MBS_SUPPORT)
- free(d->states[i].mbps.elems);
- }
- free(d->states);
+ for (i = 0; i < d->sindex; ++i)
+ {
+ free (d->states[i].elems.elems);
+ if (MBS_SUPPORT)
+ free (d->states[i].mbps.elems);
+ }
+ free (d->states);
for (i = 0; i < d->tindex; ++i)
- free(d->follows[i].elems);
- free(d->follows);
+ free (d->follows[i].elems);
+ free (d->follows);
for (i = 0; i < d->tralloc; ++i)
{
- free(d->trans[i]);
- free(d->fails[i]);
+ free (d->trans[i]);
+ free (d->fails[i]);
}
- free(d->realtrans);
- free(d->fails);
- free(d->newlines);
- free(d->success);
+ free (d->realtrans);
+ free (d->fails);
+ free (d->newlines);
+ free (d->success);
for (dm = d->musts; dm; dm = ndm)
@@ -3501,4 +3526,4 @@
ndm = dm->next;
- free(dm->must);
- free(dm);
+ free (dm->must);
+ free (dm);
}
@@ -3609,3 +3634,3 @@
-static char * _GL_ATTRIBUTE_PURE
+static char *_GL_ATTRIBUTE_PURE
istrstr (char const *lookin, char const *lookfor)
@@ -3615,5 +3640,5 @@
- len = strlen(lookfor);
+ len = strlen (lookfor);
for (cp = lookin; *cp != '\0'; ++cp)
- if (strncmp(cp, lookfor, len) == 0)
+ if (strncmp (cp, lookfor, len) == 0)
return (char *) cp;
@@ -3631,3 +3656,3 @@
{
- free(cpp[i]);
+ free (cpp[i]);
cpp[i] = NULL;
@@ -3643,5 +3668,5 @@
return NULL;
- if ((new = icpyalloc(new)) == NULL)
+ if ((new = icpyalloc (new)) == NULL)
{
- freelist(cpp);
+ freelist (cpp);
return NULL;
@@ -3651,5 +3676,5 @@
for (i = 0; cpp[i] != NULL; ++i)
- if (istrstr(cpp[i], new) != NULL)
+ if (istrstr (cpp[i], new) != NULL)
{
- free(new);
+ free (new);
return cpp;
@@ -3659,3 +3684,3 @@
while (cpp[j] != NULL)
- if (istrstr(new, cpp[j]) == NULL)
+ if (istrstr (new, cpp[j]) == NULL)
++j;
@@ -3663,3 +3688,3 @@
{
- free(cpp[j]);
+ free (cpp[j]);
if (--i == j)
@@ -3670,3 +3695,3 @@
/* Add the new string. */
- REALLOC(cpp, i + 2);
+ REALLOC (cpp, i + 2);
cpp[i] = new;
@@ -3689,3 +3714,3 @@
return NULL;
- cpp = malloc(sizeof *cpp);
+ cpp = malloc (sizeof *cpp);
if (cpp == NULL)
@@ -3730,3 +3755,3 @@
{
- old = enlist(old, new[i], strlen(new[i]));
+ old = enlist (old, new[i], strlen (new[i]));
if (old == NULL)
@@ -3748,3 +3773,3 @@
return NULL;
- both = malloc(sizeof *both);
+ both = malloc (sizeof *both);
if (both == NULL)
@@ -3756,11 +3781,11 @@
{
- temp = comsubs(left[lnum], right[rnum]);
+ temp = comsubs (left[lnum], right[rnum]);
if (temp == NULL)
{
- freelist(both);
+ freelist (both);
return NULL;
}
- both = addlists(both, temp);
- freelist(temp);
- free(temp);
+ both = addlists (both, temp);
+ freelist (temp);
+ free (temp);
if (both == NULL)
@@ -3781,6 +3806,6 @@
static void
-resetmust (must *mp)
+resetmust (must * mp)
{
mp->left[0] = mp->right[0] = mp->is[0] = '\0';
- freelist(mp->in);
+ freelist (mp->in);
}
@@ -3809,6 +3834,6 @@
{
- mp[i].in = xmalloc(sizeof *mp[i].in);
- mp[i].left = xmalloc(2);
- mp[i].right = xmalloc(2);
- mp[i].is = xmalloc(2);
+ mp[i].in = xmalloc (sizeof *mp[i].in);
+ mp[i].left = xmalloc (2);
+ mp[i].right = xmalloc (2);
+ mp[i].is = xmalloc (2);
mp[i].left[0] = mp[i].right[0] = mp[i].is[0] = '\0';
@@ -3817,9 +3842,9 @@
#ifdef DEBUG
- fprintf(stderr, "dfamust:\n");
+ fprintf (stderr, "dfamust:\n");
for (i = 0; i < d->tindex; ++i)
{
- fprintf(stderr, " %d:", i);
- prtok(d->tokens[i]);
+ fprintf (stderr, " %d:", i);
+ prtok (d->tokens[i]);
}
- putc('\n', stderr);
+ putc ('\n', stderr);
#endif
@@ -3840,3 +3865,3 @@
case BACKREF:
- resetmust(mp);
+ resetmust (mp);
break;
@@ -3846,3 +3871,3 @@
--mp;
- resetmust(mp);
+ resetmust (mp);
break;
@@ -3867,4 +3892,4 @@
/* Right side */
- ln = strlen(lmp->right);
- rn = strlen(rmp->right);
+ ln = strlen (lmp->right);
+ rn = strlen (rmp->right);
n = ln;
@@ -3878,7 +3903,7 @@
lmp->right[j] = '\0';
- new = inboth(lmp->in, rmp->in);
+ new = inboth (lmp->in, rmp->in);
if (new == NULL)
goto done;
- freelist(lmp->in);
- free(lmp->in);
+ freelist (lmp->in);
+ free (lmp->in);
lmp->in = new;
@@ -3894,3 +3919,3 @@
for (i = 0; musts[0].in[i] != NULL; ++i)
- if (strlen(musts[0].in[i]) > strlen(result))
+ if (strlen (musts[0].in[i]) > strlen (result))
result = musts[0].in[i];
@@ -3910,7 +3935,6 @@
left's right and right's left. */
- lmp->in = addlists(lmp->in, rmp->in);
+ lmp->in = addlists (lmp->in, rmp->in);
if (lmp->in == NULL)
goto done;
- if (lmp->right[0] != '\0' &&
- rmp->left[0] != '\0')
+ if (lmp->right[0] != '\0' && rmp->left[0] != '\0')
{
@@ -3918,6 +3942,6 @@
- tp = icpyalloc(lmp->right);
- tp = icatalloc(tp, rmp->left);
- lmp->in = enlist(lmp->in, tp, strlen(tp));
- free(tp);
+ tp = icpyalloc (lmp->right);
+ tp = icatalloc (tp, rmp->left);
+ lmp->in = enlist (lmp->in, tp, strlen (tp));
+ free (tp);
if (lmp->in == NULL)
@@ -3928,4 +3952,3 @@
{
- lmp->left = icatalloc(lmp->left,
- rmp->left);
+ lmp->left = icatalloc (lmp->left, rmp->left);
if (lmp->left == NULL)
@@ -3936,3 +3959,3 @@
lmp->right[0] = '\0';
- lmp->right = icatalloc(lmp->right, rmp->right);
+ lmp->right = icatalloc (lmp->right, rmp->right);
if (lmp->right == NULL)
@@ -3942,3 +3965,3 @@
{
- lmp->is = icatalloc(lmp->is, rmp->is);
+ lmp->is = icatalloc (lmp->is, rmp->is);
if (lmp->is == NULL)
@@ -3960,10 +3983,6 @@
}
- else if (t >= CSET
- || !MBS_SUPPORT
- || t == ANYCHAR
- || t == MBCSET
- )
+ else if (t >= CSET || !MBS_SUPPORT || t == ANYCHAR || t == MBCSET)
{
/* easy enough */
- resetmust(mp);
+ resetmust (mp);
}
@@ -3972,6 +3991,6 @@
/* plain character */
- resetmust(mp);
+ resetmust (mp);
mp->is[0] = mp->left[0] = mp->right[0] = t;
mp->is[1] = mp->left[1] = mp->right[1] = '\0';
- mp->in = enlist(mp->in, mp->is, (size_t)1);
+ mp->in = enlist (mp->in, mp->is, (size_t) 1);
if (mp->in == NULL)
@@ -3982,10 +4001,10 @@
#ifdef DEBUG
- fprintf(stderr, " node: %d:", ri);
- prtok(d->tokens[ri]);
- fprintf(stderr, "\n in:");
+ fprintf (stderr, " node: %d:", ri);
+ prtok (d->tokens[ri]);
+ fprintf (stderr, "\n in:");
for (i = 0; mp->in[i]; ++i)
- fprintf(stderr, " \"%s\"", mp->in[i]);
- fprintf(stderr, "\n is: \"%s\"\n", mp->is);
- fprintf(stderr, " left: \"%s\"\n", mp->left);
- fprintf(stderr, " right: \"%s\"\n", mp->right);
+ fprintf (stderr, " \"%s\"", mp->in[i]);
+ fprintf (stderr, "\n is: \"%s\"\n", mp->is);
+ fprintf (stderr, " left: \"%s\"\n", mp->left);
+ fprintf (stderr, " right: \"%s\"\n", mp->right);
#endif
@@ -3993,9 +4012,9 @@
}
- done:
- if (strlen(result))
+done:
+ if (strlen (result))
{
- MALLOC(dm, 1);
+ MALLOC (dm, 1);
dm->exact = exact;
- MALLOC(dm->must, strlen(result) + 1);
- strcpy(dm->must, result);
+ MALLOC (dm->must, strlen (result) + 1);
+ strcpy (dm->must, result);
dm->next = d->musts;
@@ -4006,9 +4025,9 @@
{
- freelist(mp[i].in);
- free(mp[i].in);
- free(mp[i].left);
- free(mp[i].right);
- free(mp[i].is);
+ freelist (mp[i].in);
+ free (mp[i].in);
+ free (mp[i].left);
+ free (mp[i].right);
+ free (mp[i].is);
}
- free(mp);
+ free (mp);
}
@@ -4021,3 +4040,3 @@
-struct dfamust * _GL_ATTRIBUTE_PURE
+struct dfamust *_GL_ATTRIBUTE_PURE
dfamusts (struct dfa const *d)
- [PATCH 0/9] dfa refactorings, Paolo Bonzini, 2012/01/03
- [PATCH 1/9] dfa: x2nrealloc starting from a NULL pointer works, Paolo Bonzini, 2012/01/03
- [PATCH 2/9] dfa: remove unnecessary braces, Paolo Bonzini, 2012/01/03
- [PATCH 3/9] dfa: use MALLOC/REALLOC always, Paolo Bonzini, 2012/01/03
- [PATCH 4/9] dfa: use a separate data type for grps, Paolo Bonzini, 2012/01/03
- [PATCH 5/9] dfa: introduce alloc_posset, Paolo Bonzini, 2012/01/03
- [PATCH 6/9] dfa: remove dead assignment, Paolo Bonzini, 2012/01/03
- [PATCH 7/9] dfa: move nalloc to position_set structure, Paolo Bonzini, 2012/01/03
- [PATCH 8/9] dfa: change position_set nelem to size_t, Paolo Bonzini, 2012/01/03