From 43297a649ff42404261ab1e16d4d04101af8fde4 Mon Sep 17 00:00:00 2001 From: Norihiro Tanaka Date: Sat, 18 Oct 2014 23:57:33 +0900 Subject: [PATCH 1/2] dfa: prefer bool at DFA interfaces * (src/dfa.c) dfasyntax: Use bool for `fold'. dfaanalyze, dfacomp: Use bool for `searchflag'. dfaexec_main, dfaexec_mb, dfaexec_sb, dfaexec: IUse bool for `allow_nl'. * (src/dfa.h): Update prototype. --- src/dfa.c | 18 +++++++++--------- src/dfa.h | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/dfa.c b/src/dfa.c index 58a4b83..f0dc74c 100644 --- a/src/dfa.c +++ b/src/dfa.c @@ -720,13 +720,13 @@ 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, bool fold, unsigned char eol) { unsigned int i; syntax_bits_set = 1; syntax_bits = bits; - case_fold = fold != 0; + case_fold = fold; eolbyte = eol; for (i = 0; i < NOTCHAR; ++i) @@ -2320,7 +2320,7 @@ state_separate_contexts (position_set const *s) scheme; the number of elements in each set deeper in the stack can be used to determine the address of a particular set's array. */ void -dfaanalyze (struct dfa *d, int searchflag) +dfaanalyze (struct dfa *d, bool searchflag) { /* Array allocated to hold position sets. */ position *posalloc = xnmalloc (d->nleaves, 2 * sizeof *posalloc); @@ -2356,7 +2356,7 @@ dfaanalyze (struct dfa *d, int searchflag) putc ('\n', stderr); #endif - d->searchflag = searchflag != 0; + d->searchflag = searchflag; alloc_position_set (&merged, d->nleaves); d->follows = xcalloc (d->tindex, sizeof *d->follows); @@ -3276,7 +3276,7 @@ skip_remains_mb (struct dfa *d, unsigned char const *p, characters. */ static inline char * dfaexec_main (struct dfa *d, char const *begin, char *end, - int allow_nl, size_t *count, int *backref, bool multibyte) + bool allow_nl, size_t *count, int *backref, bool multibyte) { state_num s, s1; /* Current state. */ unsigned char const *p, *mbp; /* Current input character. */ @@ -3466,14 +3466,14 @@ dfaexec_main (struct dfa *d, char const *begin, char *end, static char * dfaexec_mb (struct dfa *d, char const *begin, char *end, - int allow_nl, size_t *count, int *backref) + bool allow_nl, size_t *count, int *backref) { return dfaexec_main (d, begin, end, allow_nl, count, backref, true); } static char * dfaexec_sb (struct dfa *d, char const *begin, char *end, - int allow_nl, size_t *count, int *backref) + bool allow_nl, size_t *count, int *backref) { return dfaexec_main (d, begin, end, allow_nl, count, backref, false); } @@ -3483,7 +3483,7 @@ dfaexec_sb (struct dfa *d, char const *begin, char *end, char * dfaexec (struct dfa *d, char const *begin, char *end, - int allow_nl, size_t *count, int *backref) + bool allow_nl, size_t *count, int *backref) { return d->dfaexec (d, begin, end, allow_nl, count, backref); } @@ -3663,7 +3663,7 @@ dfassbuild (struct dfa *d) /* Parse and analyze a single string of the given length. */ void -dfacomp (char const *s, size_t len, struct dfa *d, int searchflag) +dfacomp (char const *s, size_t len, struct dfa *d, bool searchflag) { dfainit (d); dfambcache (d); diff --git a/src/dfa.h b/src/dfa.h index f30c3cb..ab2e8ea 100644 --- a/src/dfa.h +++ b/src/dfa.h @@ -49,12 +49,12 @@ extern struct dfamust *dfamusts (struct dfa const *); /* dfasyntax() takes three arguments; the first sets the syntax bits described earlier in this file, the second sets the case-folding flag, and the third specifies the line terminator. */ -extern void dfasyntax (reg_syntax_t, int, unsigned char); +extern void dfasyntax (reg_syntax_t, bool, unsigned char); /* Compile the given string of the given length into the given struct dfa. Final argument is a flag specifying whether to build a searching or an exact matcher. */ -extern void dfacomp (char const *, size_t, struct dfa *, int); +extern void dfacomp (char const *, size_t, struct dfa *, bool); /* Search through a buffer looking for a match to the given struct dfa. Find the first occurrence of a string matching the regexp in the @@ -63,13 +63,13 @@ extern void dfacomp (char const *, size_t, struct dfa *, int); 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 ALLOW_NL is true, newlines 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 to decide whether to fall back on a backtracking matcher. */ extern char *dfaexec (struct dfa *d, char const *begin, char *end, - int newline, size_t *count, int *backref); + bool allow_nl, size_t *count, int *backref); /* Return a superset for D. The superset matches everything that D matches, along with some other strings (though the latter should be -- 2.1.1