summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitmodules4
-rw-r--r--COPYING12
-rw-r--r--NEWS2
-rw-r--r--README4
-rw-r--r--README.DOS20
-rw-r--r--gl/lib/regcomp.c.diff6
-rw-r--r--gl/lib/regex_internal.c.diff4
-rw-r--r--gl/lib/regexec.c.diff2
-rw-r--r--grep.spec2
-rw-r--r--lib/savedir.c90
-rw-r--r--lib/savedir.h4
-rw-r--r--m4/pcre.m46
-rw-r--r--src/dfa.c2552
-rw-r--r--src/dfa.h2
-rw-r--r--src/dfasearch.c334
-rw-r--r--src/dosbuf.c4
-rw-r--r--src/grep.c6
-rw-r--r--src/kwsearch.c94
-rw-r--r--src/kwset.c568
-rw-r--r--src/main.c1186
-rw-r--r--src/pcresearch.c48
-rw-r--r--src/searchutils.c14
-rwxr-xr-xtests/backref.sh8
-rw-r--r--tests/bre.awk18
-rwxr-xr-xtests/empty96
-rw-r--r--tests/ere.awk20
-rw-r--r--tests/fedora8
-rwxr-xr-xtests/file.sh12
-rwxr-xr-xtests/fmbtest12
-rwxr-xr-xtests/khadafy.sh6
-rwxr-xr-xtests/options.sh4
-rw-r--r--tests/spencer1-locale.awk20
-rw-r--r--tests/spencer1.awk14
-rwxr-xr-xtests/status.sh62
34 files changed, 2622 insertions, 2622 deletions
diff --git a/.gitmodules b/.gitmodules
index acb26693..bb9e1baf 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,3 @@
[submodule "gnulib"]
- path = gnulib
- url = git://git.sv.gnu.org/gnulib.git
+ path = gnulib
+ url = git://git.sv.gnu.org/gnulib.git
diff --git a/COPYING b/COPYING
index bf0f7d37..35ca8a5a 100644
--- a/COPYING
+++ b/COPYING
@@ -1,12 +1,12 @@
- GNU GENERAL PUBLIC LICENSE
- Version 3, 29 June 2007
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
- Preamble
+ Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
@@ -69,7 +69,7 @@ patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
- TERMS AND CONDITIONS
+ TERMS AND CONDITIONS
0. Definitions.
@@ -619,9 +619,9 @@ an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
- END OF TERMS AND CONDITIONS
+ END OF TERMS AND CONDITIONS
- How to Apply These Terms to Your New Programs
+ How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
diff --git a/NEWS b/NEWS
index a389361b..1c491d0a 100644
--- a/NEWS
+++ b/NEWS
@@ -194,7 +194,7 @@ Version 2.4.1
--binary-files='binary' (the default) outputs a 1-line summary of matches.
--binary-files='without-match' assumes binary files do not match.
--binary-files='text' treats binary files as text
- (equivalent to the -a or --text option).
+ (equivalent to the -a or --text option).
- New option -I; equivalent to --binary-files='without-match'.
diff --git a/README b/README
index 18ee0d32..660b8da9 100644
--- a/README
+++ b/README
@@ -47,9 +47,9 @@ necessarily of the same byte length.
Additional bug reports can be found at:
- http://savannah.gnu.org/bugs/?group=grep
+ http://savannah.gnu.org/bugs/?group=grep
You can also browse the bug-grep mailing list archive at:
- http://lists.gnu.org/archive/html/bug-grep/
+ http://lists.gnu.org/archive/html/bug-grep/
diff --git a/README.DOS b/README.DOS
index 7662f8c3..f750ab9b 100644
--- a/README.DOS
+++ b/README.DOS
@@ -11,22 +11,22 @@ To compile the GNU grep package with DJGPP tools, you will need the
following tools (the names of the archives on DJGPP ftp sites where
these tools are available are in parentheses):
- - The basic DJGPP development environment, including the
+ - The basic DJGPP development environment, including the
GCC compiler and the libraries (v2gnu/gccNNNb.zip,
v2gnu/bnuNNNb.zip, v2/djdevNNN.zip).
- - GNU Make revision 3.75 or later (v2gnu/makNNNb.zip).
+ - GNU Make revision 3.75 or later (v2gnu/makNNNb.zip).
- - GNU Bash (v2gnu/bshNNNb.zip).
+ - GNU Bash (v2gnu/bshNNNb.zip).
- - GNU Sed (v2gnu/sedNNNb.zip).
+ - GNU Sed (v2gnu/sedNNNb.zip).
- - GNU M4 (v2gnu/m4-NNNb.zip).
+ - GNU M4 (v2gnu/m4-NNNb.zip).
- - GNU Fileutils (v2gnu/filNNNb.zip), Textutils
+ - GNU Fileutils (v2gnu/filNNNb.zip), Textutils
(v2gnu/txtNNNb.zip) and Diffutils (v2gnu/difNNNb.zip).
- - A (previous version of) GNU grep (v2gnu/grepNNb.zip).
+ - A (previous version of) GNU grep (v2gnu/grepNNb.zip).
Running the tests ("make check" in the top-level directory)
additionally requires Gawk (v2gnu/gwkNNNb.zip). TAGS and ID targets
@@ -36,9 +36,9 @@ ID-utils, v2gnu/iduNNb.zip), respectively.
All of these tools are available from the DJGPP archive sites.
To build grep:
- sh autogen.sh
+ sh autogen.sh
sh configure
- make
+ make
Source distributions on DJGPP sites usually come pre-configured, so
@@ -79,4 +79,4 @@ perform the following in the docs directory:
2.5f ported by Andrew Cottrell <anddjgpp@ihug.com.au>
Enjoy,
- Eli Zaretskii <eliz@is.elta.co.il>
+ Eli Zaretskii <eliz@is.elta.co.il>
diff --git a/gl/lib/regcomp.c.diff b/gl/lib/regcomp.c.diff
index 63fc1875..a3be4226 100644
--- a/gl/lib/regcomp.c.diff
+++ b/gl/lib/regcomp.c.diff
@@ -8,7 +8,7 @@ index d5968bd..4926676 100644
size_t
-regerror (int errcode, const regex_t *_Restrict_ preg,
+regerror (int errcode, const regex_t *_Restrict_ preg _UNUSED_PARAMETER_,
- char *_Restrict_ errbuf, size_t errbuf_size)
+ char *_Restrict_ errbuf, size_t errbuf_size)
#endif
{
@@ -1383,7 +1383,7 @@ calc_first (void *extra, bin_tree_t *node)
@@ -28,7 +28,7 @@ index d5968bd..4926676 100644
+ re_charset_t *mbcset _UNUSED_PARAMETER_,
+ Idx *coll_sym_alloc _UNUSED_PARAMETER_,
# endif
- const unsigned char *name)
+ const unsigned char *name)
{
@@ -3323,7 +3324,8 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
@@ -37,7 +37,7 @@ index d5968bd..4926676 100644
- re_token_t *token, int token_len, re_dfa_t *dfa,
+ re_token_t *token, int token_len,
+ re_dfa_t *dfa _UNUSED_PARAMETER_,
- reg_syntax_t syntax, bool accept_hyphen)
+ reg_syntax_t syntax, bool accept_hyphen)
{
#ifdef RE_ENABLE_I18N
@@ -3410,8 +3412,9 @@ parse_bracket_symbol (bracket_elem_t *elem, re_string_t *regexp,
diff --git a/gl/lib/regex_internal.c.diff b/gl/lib/regex_internal.c.diff
index 2cede3c0..0cb9d853 100644
--- a/gl/lib/regex_internal.c.diff
+++ b/gl/lib/regex_internal.c.diff
@@ -9,8 +9,8 @@ index 904b88e..61c8d9d 100644
+#include "verify.h"
+#include "intprops.h"
static void re_string_construct_common (const char *str, Idx len,
- re_string_t *pstr,
- RE_TRANSLATE_TYPE trans, bool icase,
+ re_string_t *pstr,
+ RE_TRANSLATE_TYPE trans, bool icase,
@@ -1390,7 +1392,10 @@ static void
internal_function
re_node_set_remove_at (re_node_set *set, Idx idx)
diff --git a/gl/lib/regexec.c.diff b/gl/lib/regexec.c.diff
index d9b6d1cd..37a7c55e 100644
--- a/gl/lib/regexec.c.diff
+++ b/gl/lib/regexec.c.diff
@@ -9,7 +9,7 @@ index 21a8166..7762437 100644
+#include "verify.h"
+#include "intprops.h"
static reg_errcode_t match_ctx_init (re_match_context_t *cache, int eflags,
- Idx n) internal_function;
+ Idx n) internal_function;
static void match_ctx_clean (re_match_context_t *mctx) internal_function;
@@ -378,8 +380,11 @@ re_search_2_stub (struct re_pattern_buffer *bufp,
Idx len = length1 + length2;
diff --git a/grep.spec b/grep.spec
index 452a1283..4a910e33 100644
--- a/grep.spec
+++ b/grep.spec
@@ -53,7 +53,7 @@ rm -rf ${RPM_BUILD_ROOT}
%preun
if [ $1 = 0 ]; then
- [ -e %{_infodir}/grep.info.* ] && /sbin/install-info --quiet --info-dir=%{_infodir} --delete %{_infodir}/grep.info.*
+ [ -e %{_infodir}/grep.info.* ] && /sbin/install-info --quiet --info-dir=%{_infodir} --delete %{_infodir}/grep.info.*
fi
%files -f %{name}.lang
diff --git a/lib/savedir.c b/lib/savedir.c
index 6b2a848c..2d17f3f2 100644
--- a/lib/savedir.c
+++ b/lib/savedir.c
@@ -74,7 +74,7 @@ isdir1 (const char *dir, const char *file)
Return NULL if DIR cannot be opened or if out of memory. */
char *
savedir (const char *dir, off_t name_size, struct exclude *included_patterns,
- struct exclude *excluded_patterns, struct exclude *excluded_directory_patterns )
+ struct exclude *excluded_patterns, struct exclude *excluded_directory_patterns )
{
DIR *dirp;
struct dirent *dp;
@@ -102,50 +102,50 @@ savedir (const char *dir, off_t name_size, struct exclude *included_patterns,
{
/* Skip "." and ".." (some NFS file systems' directories lack them). */
if (dp->d_name[0] != '.'
- || (dp->d_name[1] != '\0'
- && (dp->d_name[1] != '.' || dp->d_name[2] != '\0')))
- {
- size_t namlen = strlen (dp->d_name);
- size_t size_needed = (namep - name_space) + namlen + 2;
-
- if ((included_patterns || excluded_patterns)
- && !isdir1 (dir, dp->d_name))
- {
- if (included_patterns
- && excluded_file_name (included_patterns, dp->d_name))
- continue;
- if (excluded_patterns
- && excluded_file_name (excluded_patterns, dp->d_name))
- continue;
- }
-
- if ( excluded_directory_patterns
- && isdir1 (dir, dp->d_name) )
- {
- if (excluded_directory_patterns
- && excluded_file_name (excluded_directory_patterns, dp->d_name))
- continue;
- }
-
- if (size_needed > name_size)
- {
- char *new_name_space;
-
- while (size_needed > name_size)
- name_size += 1024;
-
- new_name_space = realloc (name_space, name_size);
- if (new_name_space == NULL)
- {
- closedir (dirp);
- goto fail;
- }
- namep = new_name_space + (namep - name_space);
- name_space = new_name_space;
- }
- strcpy (namep, dp->d_name);
- namep += namlen + 1;
- }
+ || (dp->d_name[1] != '\0'
+ && (dp->d_name[1] != '.' || dp->d_name[2] != '\0')))
+ {
+ size_t namlen = strlen (dp->d_name);
+ size_t size_needed = (namep - name_space) + namlen + 2;
+
+ if ((included_patterns || excluded_patterns)
+ && !isdir1 (dir, dp->d_name))
+ {
+ if (included_patterns
+ && excluded_file_name (included_patterns, dp->d_name))
+ continue;
+ if (excluded_patterns
+ && excluded_file_name (excluded_patterns, dp->d_name))
+ continue;
+ }
+
+ if ( excluded_directory_patterns
+ && isdir1 (dir, dp->d_name) )
+ {
+ if (excluded_directory_patterns
+ && excluded_file_name (excluded_directory_patterns, dp->d_name))
+ continue;
+ }
+
+ if (size_needed > name_size)
+ {
+ char *new_name_space;
+
+ while (size_needed > name_size)
+ name_size += 1024;
+
+ new_name_space = realloc (name_space, name_size);
+ if (new_name_space == NULL)
+ {
+ closedir (dirp);
+ goto fail;
+ }
+ namep = new_name_space + (namep - name_space);
+ name_space = new_name_space;
+ }
+ strcpy (namep, dp->d_name);
+ namep += namlen + 1;
+ }
}
*namep = '\0';
if (CLOSEDIR (dirp))
diff --git a/lib/savedir.h b/lib/savedir.h
index 003f7fe3..00cb1a98 100644
--- a/lib/savedir.h
+++ b/lib/savedir.h
@@ -5,7 +5,7 @@
extern char *
savedir (const char *dir, off_t name_size,
- struct exclude *, struct exclude *,
- struct exclude *);
+ struct exclude *, struct exclude *,
+ struct exclude *);
#endif
diff --git a/m4/pcre.m4 b/m4/pcre.m4
index 3fc931e5..476396d3 100644
--- a/m4/pcre.m4
+++ b/m4/pcre.m4
@@ -28,12 +28,12 @@ AC_DEFUN([gl_FUNC_PCRE],
|| test $ac_cv_header_pcre_pcre_h = yes; then
pcre_saved_LIBS=$LIBS
AC_SEARCH_LIBS([pcre_compile], [pcre],
- [test "$ac_cv_search_pcre_compile" = "none required" ||
- LIB_PCRE=$ac_cv_search_pcre_compile])
+ [test "$ac_cv_search_pcre_compile" = "none required" ||
+ LIB_PCRE=$ac_cv_search_pcre_compile])
AC_CHECK_FUNCS([pcre_compile])
LIBS=$pcre_saved_LIBS
if test $ac_cv_func_pcre_compile = yes; then
- use_pcre=yes
+ use_pcre=yes
fi
fi
if test $use_pcre = no; then
diff --git a/src/dfa.c b/src/dfa.c
index 92c9f68a..ec015d6e 100644
--- a/src/dfa.c
+++ b/src/dfa.c
@@ -142,94 +142,94 @@ typedef int charclass[CHARCLASS_INTS];
typedef enum
{
END = -1, /* END is a terminal symbol that matches the
- end of input; any value of END or less in
- the parse tree is such a symbol. Accepting
- states of the DFA are those that would have
- a transition on END. */
+ end of input; any value of END or less in
+ the parse tree is such a symbol. Accepting
+ states of the DFA are those that would have
+ a transition on END. */
/* Ordinary character values are terminal symbols that match themselves. */
EMPTY = NOTCHAR, /* EMPTY is a terminal symbol that matches
- the empty string. */
+ the empty string. */
BACKREF, /* BACKREF is generated by \<digit>; it
- it not completely handled. If the scanner
- detects a transition on backref, it returns
- a kind of "semi-success" indicating that
- the match will have to be verified with
- a backtracking matcher. */
+ it not completely handled. If the scanner
+ detects a transition on backref, it returns
+ a kind of "semi-success" indicating that
+ the match will have to be verified with
+ a backtracking matcher. */
BEGLINE, /* BEGLINE is a terminal symbol that matches
- the empty string if it is at the beginning
- of a line. */
+ the empty string if it is at the beginning
+ of a line. */
ENDLINE, /* ENDLINE is a terminal symbol that matches
- the empty string if it is at the end of
- a line. */
+ the empty string if it is at the end of
+ a line. */
BEGWORD, /* BEGWORD is a terminal symbol that matches
- the empty string if it is at the beginning
- of a word. */
+ the empty string if it is at the beginning
+ of a word. */
ENDWORD, /* ENDWORD is a terminal symbol that matches
- the empty string if it is at the end of
- a word. */
+ the empty string if it is at the end of
+ a word. */
LIMWORD, /* LIMWORD is a terminal symbol that matches
- the empty string if it is at the beginning
- or the end of a word. */
+ the empty string if it is at the beginning
+ or the end of a word. */
NOTLIMWORD, /* NOTLIMWORD is a terminal symbol that
- matches the empty string if it is not at
- the beginning or end of a word. */
+ matches the empty string if it is not at
+ the beginning or end of a word. */
QMARK, /* QMARK is an operator of one argument that
- matches zero or one occurences of its
- argument. */
+ matches zero or one occurences of its
+ argument. */
STAR, /* STAR is an operator of one argument that
- matches the Kleene closure (zero or more
- occurrences) of its argument. */
+ matches the Kleene closure (zero or more
+ occurrences) of its argument. */
PLUS, /* PLUS is an operator of one argument that
- matches the positive closure (one or more
- occurrences) of its argument. */
+ matches the positive closure (one or more
+ occurrences) of its argument. */
REPMN, /* REPMN is a lexical token corresponding
- to the {m,n} construct. REPMN never
- appears in the compiled token vector. */
+ to the {m,n} construct. REPMN never
+ appears in the compiled token vector. */
CAT, /* CAT is an operator of two arguments that
- matches the concatenation of its
- arguments. CAT is never returned by the
- lexical analyzer. */
+ matches the concatenation of its
+ arguments. CAT is never returned by the
+ lexical analyzer. */
OR, /* OR is an operator of two arguments that
- matches either of its arguments. */
+ matches either of its arguments. */
ORTOP, /* OR at the toplevel in the parse tree.
- This is used for a boyer-moore heuristic. */
+ This is used for a boyer-moore heuristic. */
LPAREN, /* LPAREN never appears in the parse tree,
- it is only a lexeme. */
+ it is only a lexeme. */
RPAREN, /* RPAREN never appears in the parse tree. */
#if MBS_SUPPORT
ANYCHAR, /* ANYCHAR is a terminal symbol that matches
any multibyte (or single byte) characters.
- It is used only if MB_CUR_MAX > 1. */
+ It is used only if MB_CUR_MAX > 1. */
MBCSET, /* MBCSET is similar to CSET, but for
- multibyte characters. */
+ multibyte characters. */
WCHAR, /* Only returned by lex. wctok contains
- the wide character representation. */
+ the wide character representation. */
#endif /* MBS_SUPPORT */
CSET /* CSET and (and any value greater) is a
- terminal symbol that matches any of a
- class of characters. */
+ terminal symbol that matches any of a
+ class of characters. */
} token;
@@ -265,8 +265,8 @@ typedef struct
#if MBS_SUPPORT
position_set mbps; /* Positions which can match multibyte
characters. e.g. period.
- These staff are used only if
- MB_CUR_MAX > 1. */
+ These staff are used only if
+ MB_CUR_MAX > 1. */
#endif
} dfa_state;
@@ -304,11 +304,11 @@ struct dfa
int tindex; /* Index for adding new tokens. */
int talloc; /* Number of tokens currently allocated. */
int depth; /* Depth required of an evaluation stack
- used for depth-first traversal of the
- parse tree. */
+ used for depth-first traversal of the
+ parse tree. */
int nleaves; /* Number of leaves on the parse tree. */
int nregexps; /* Count of parallel regexps being built
- with dfaparse(). */
+ with dfaparse(). */
#if MBS_SUPPORT
unsigned int mb_cur_max; /* Cached value of MB_CUR_MAX. */
@@ -347,50 +347,50 @@ struct dfa
/* Fields filled by the parse tree->NFA conversion. */
position_set *follows; /* Array of follow sets, indexed by position
- index. The follow of a position is the set
- of positions containing characters that
- could conceivably follow a character
- matching the given position in a string
- matching the regexp. Allocated to the
- maximum possible position index. */
+ index. The follow of a position is the set
+ of positions containing characters that
+ could conceivably follow a character
+ matching the given position in a string
+ matching the regexp. Allocated to the
+ maximum possible position index. */
int searchflag; /* True if we are supposed to build a searching
- as opposed to an exact matcher. A searching
- matcher finds the first and shortest string
- matching a regexp anywhere in the buffer,
- whereas an exact matcher finds the longest
- string matching, but anchored to the
- beginning of the buffer. */
+ as opposed to an exact matcher. A searching
+ matcher finds the first and shortest string
+ matching a regexp anywhere in the buffer,
+ whereas an exact matcher finds the longest
+ string matching, but anchored to the
+ beginning of the buffer. */
/* Fields filled by dfaexec. */
int tralloc; /* Number of transition tables that have
- slots so far. */
+ slots so far. */
int trcount; /* Number of transition tables that have
- actually been built. */
+ actually been built. */
int **trans; /* Transition tables for states that can
- never accept. If the transitions for a
- state have not yet been computed, or the
- state could possibly accept, its entry in
- this table is NULL. */
+ never accept. If the transitions for a
+ state have not yet been computed, or the
+ state could possibly accept, its entry in
+ this table is NULL. */
int **realtrans; /* Trans always points to realtrans + 1; this
- is so trans[-1] can contain NULL. */
+ is so trans[-1] can contain NULL. */
int **fails; /* Transition tables after failing to accept
- on a state that potentially could do so. */
+ on a state that potentially could do so. */
int *success; /* Table of acceptance conditions used in
- dfaexec and computed in build_state. */
+ dfaexec and computed in build_state. */
int *newlines; /* Transitions on newlines. The entry for a
- newline 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
- as a special case. Newline is also used
- as a sentinel at the end of the buffer. */
+ newline 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
+ 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
- is known to appear in any r.e. matching
- the dfa. */
+ is known to appear in any r.e. matching
+ the dfa. */
#ifdef GAWK
int broken; /* True if using a feature where there
- are bugs and gawk should use regex. */
+ are bugs and gawk should use regex. */
#endif
};
@@ -403,7 +403,7 @@ struct dfa
specified context. */
#define ACCEPTS_IN_CONTEXT(prevn, currn, prevl, currl, state, dfa) \
SUCCEEDS_IN_CONTEXT((dfa).states[state].constraint, \
- prevn, currn, prevl, currl)
+ prevn, currn, prevl, currl)
static void dfamust (struct dfa *dfa);
static void regexp (int toplevel);
@@ -417,7 +417,7 @@ static void regexp (int toplevel);
if ((index) >= (nalloc)) \
{ \
do \
- (nalloc) *= 2; \
+ (nalloc) *= 2; \
while ((index) >= (nalloc)); \
REALLOC(p, t, nalloc); \
}
@@ -437,29 +437,29 @@ prtok (token t)
else
{
switch (t)
- {
- 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 ORTOP: s = "ORTOP"; break;
- case LPAREN: s = "LPAREN"; break;
- case RPAREN: s = "RPAREN"; 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 ORTOP: s = "ORTOP"; break;
+ case LPAREN: s = "LPAREN"; break;
+ case RPAREN: s = "RPAREN"; break;
#if MBS_SUPPORT
- case ANYCHAR: s = "ANYCHAR"; break;
- case MBCSET: s = "MBCSET"; break;
+ case ANYCHAR: s = "ANYCHAR"; break;
+ case MBCSET: s = "MBCSET"; break;
#endif /* MBS_SUPPORT */
- default: s = "CSET"; break;
- }
+ default: s = "CSET"; break;
+ }
fprintf(stderr, "%s", s);
}
}
@@ -578,7 +578,7 @@ setbit_case_fold (
{
unsigned char b1 = isupper(b) ? tolower(b) : b;
unsigned char b2 = islower(b) ? toupper(b) : b;
- setbit (b1, c);
+ setbit (b1, c);
if (b2 != b1)
setbit (b2, c);
}
@@ -620,34 +620,34 @@ static char const *lexptr; /* Pointer to next input character. */
static int lexleft; /* Number of characters remaining. */
static token lasttok; /* Previous token returned; initially END. */
static int laststart; /* True if we're separated from beginning or (, |
- only by zero-width characters. */
+ only by zero-width characters. */
static int parens; /* Count of outstanding left parens. */
static int minrep, maxrep; /* Repeat counts for {m,n}. */
static int hard_LC_COLLATE; /* Nonzero if LC_COLLATE is hard. */
static int cur_mb_len = 1; /* Length of the multibyte representation of
- wctok. */
+ wctok. */
#if MBS_SUPPORT
/* These variables are used only if (MB_CUR_MAX > 1). */
static mbstate_t mbs; /* Mbstate for mbrlen(). */
static wchar_t wctok; /* Wide character representation of the current
- multibyte character. */
+ 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
- */
+ 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
- string in dfaexec().
- The length of this array is same as
- the length of input string(char array).
- inputstring[i] is a single-byte char,
- or 1st byte of a multibyte char.
- And inputwcs[i] is the codepoint. */
+ string in dfaexec().
+ The length of this array is same as
+ the length of input string(char array).
+ inputstring[i] is a single-byte char,
+ or 1st byte of a multibyte char.
+ 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(). */
#endif /* MBS_SUPPORT */
@@ -660,9 +660,9 @@ static unsigned char const *buf_end; /* reference to end in dfaexec(). */
if (! lexleft) \
{ \
if ((eoferr) != 0) \
- dfaerror (eoferr); \
+ dfaerror (eoferr); \
else \
- return lasttok = END; \
+ return lasttok = END; \
} \
else \
{ \
@@ -696,10 +696,10 @@ static unsigned char const *buf_end; /* reference to end in dfaexec(). */
do { \
if (! lexleft) \
{ \
- if ((eoferr) != 0) \
- dfaerror (eoferr); \
- else \
- return lasttok = END; \
+ if ((eoferr) != 0) \
+ dfaerror (eoferr); \
+ else \
+ return lasttok = END; \
} \
(c) = (unsigned char) *lexptr++; \
--lexleft; \
@@ -804,51 +804,51 @@ parse_bracket_exp (void)
c1 = EOF; /* mark c1 is not initialized". */
/* Note that if we're looking at some other [:...:] construct,
- we just treat it as a bunch of ordinary characters. We can do
- this because we assume regex has checked for syntax errors before
- dfa is ever called. */
+ we just treat it as a bunch of ordinary characters. We can do
+ this because we assume regex has checked for syntax errors before
+ dfa is ever called. */
if (c == '[' && (syntax_bits & RE_CHAR_CLASSES))
- {
+ {
#define BRACKET_BUFFER_SIZE 128
- char str[BRACKET_BUFFER_SIZE];
- FETCH_WC (c1, wc1, _("unbalanced ["));
+ char str[BRACKET_BUFFER_SIZE];
+ FETCH_WC (c1, wc1, _("unbalanced ["));
- /* If pattern contains `[[:', `[[.', or `[[='. */
- if (c1 == ':'
+ /* If pattern contains `[[:', `[[.', or `[[='. */
+ if (c1 == ':'
#if MBS_SUPPORT
/* TODO: handle `[[.' and `[[=' also for MB_CUR_MAX == 1. */
- || (MB_CUR_MAX > 1 && (c1 == '.' || c1 == '='))
+ || (MB_CUR_MAX > 1 && (c1 == '.' || c1 == '='))
#endif
- )
- {
- size_t len = 0;
- for (;;)
- {
- FETCH_WC (c, wc, _("unbalanced ["));
- if ((c == c1 && *lexptr == ']') || lexleft == 0)
- break;
- if (len < BRACKET_BUFFER_SIZE)
- str[len++] = c;
- else
- /* This is in any case an invalid class name. */
- str[0] = '\0';
- }
- str[len] = '\0';
+ )
+ {
+ size_t len = 0;
+ for (;;)
+ {
+ FETCH_WC (c, wc, _("unbalanced ["));
+ if ((c == c1 && *lexptr == ']') || lexleft == 0)
+ break;
+ if (len < BRACKET_BUFFER_SIZE)
+ str[len++] = c;
+ else
+ /* This is in any case an invalid class name. */
+ str[0] = '\0';
+ }
+ str[len] = '\0';
/* Fetch bracket. */
- FETCH_WC (c, wc, _("unbalanced ["));
- if (c1 == ':')
- /* build character class. */
- {
- char const *class
- = (case_fold && (STREQ (str, "upper")
- || STREQ (str, "lower"))
- ? "alpha"
- : str);
+ FETCH_WC (c, wc, _("unbalanced ["));
+ if (c1 == ':')
+ /* build character class. */
+ {
+ char const *class
+ = (case_fold && (STREQ (str, "upper")
+ || STREQ (str, "lower"))
+ ? "alpha"
+ : str);
#if MBS_SUPPORT
if (MB_CUR_MAX > 1)
{
- /* Store the character class as wctype_t. */
+ /* Store the character class as wctype_t. */
wctype_t wt = wctype (class);
if (ch_classes_al == 0)
@@ -871,61 +871,61 @@ parse_bracket_exp (void)
}
#if MBS_SUPPORT
- else if (c1 == '=' || c1 == '.')
- {
- char *elem;
- MALLOC(elem, char, len + 1);
- strncpy(elem, str, len + 1);
-
- if (c1 == '=')
- /* build equivalent class. */
- {
- if (equivs_al == 0)
- MALLOC(work_mbc->equivs, char*, ++equivs_al);
- REALLOC_IF_NECESSARY(work_mbc->equivs, char*,
- equivs_al,
- work_mbc->nequivs + 1);
- work_mbc->equivs[work_mbc->nequivs++] = elem;
- }
-
- if (c1 == '.')
- /* build collating element. */
- {
- if (coll_elems_al == 0)
- MALLOC(work_mbc->coll_elems, char*, ++coll_elems_al);
- REALLOC_IF_NECESSARY(work_mbc->coll_elems, char*,
- coll_elems_al,
- work_mbc->ncoll_elems + 1);
- work_mbc->coll_elems[work_mbc->ncoll_elems++] = elem;
- }
- }
+ else if (c1 == '=' || c1 == '.')
+ {
+ char *elem;
+ MALLOC(elem, char, len + 1);
+ strncpy(elem, str, len + 1);
+
+ if (c1 == '=')
+ /* build equivalent class. */
+ {
+ if (equivs_al == 0)
+ MALLOC(work_mbc->equivs, char*, ++equivs_al);
+ REALLOC_IF_NECESSARY(work_mbc->equivs, char*,
+ equivs_al,
+ work_mbc->nequivs + 1);
+ work_mbc->equivs[work_mbc->nequivs++] = elem;
+ }
+
+ if (c1 == '.')
+ /* build collating element. */
+ {
+ if (coll_elems_al == 0)
+ MALLOC(work_mbc->coll_elems, char*, ++coll_elems_al);
+ REALLOC_IF_NECESSARY(work_mbc->coll_elems, char*,
+ coll_elems_al,
+ work_mbc->ncoll_elems + 1);
+ work_mbc->coll_elems[work_mbc->ncoll_elems++] = elem;
+ }
+ }
#endif
/* Fetch new lookahead character. */
- FETCH_WC (c1, wc1, _("unbalanced ["));
+ FETCH_WC (c1, wc1, _("unbalanced ["));
continue;
- }
+ }
/* We treat '[' as a normal character here. c/c1/wc/wc1
are already set up. */
- }
+ }
if (c == '\\' && (syntax_bits & RE_BACKSLASH_ESCAPE_IN_LISTS))
FETCH_WC(c, wc, _("unbalanced ["));
if (c1 == EOF)
- FETCH_WC(c1, wc1, _("unbalanced ["));
+ FETCH_WC(c1, wc1, _("unbalanced ["));
if (c1 == '-')
- /* build range characters. */
- {
- FETCH_WC(c2, wc2, _("unbalanced ["));
- if (c2 == ']')
- {
- /* In the case [x-], the - is an ordinary hyphen,
- which is left in c1, the lookahead character. */
- lexptr -= cur_mb_len;
- lexleft += cur_mb_len;
+ /* build range characters. */
+ {
+ FETCH_WC(c2, wc2, _("unbalanced ["));
+ if (c2 == ']')
+ {
+ /* In the case [x-], the - is an ordinary hyphen,
+ which is left in c1, the lookahead character. */
+ lexptr -= cur_mb_len;
+ lexleft += cur_mb_len;
}
}
@@ -938,9 +938,9 @@ parse_bracket_exp (void)
#if MBS_SUPPORT
if (MB_CUR_MAX > 1)
{
- /* When case folding map a range, say [m-z] (or even [M-z])
- to the pair of ranges, [m-z] [M-Z]. */
- if (range_sts_al == 0)
+ /* When case folding map a range, say [m-z] (or even [M-z])
+ to the pair of ranges, [m-z] [M-Z]. */
+ if (range_sts_al == 0)
{
MALLOC(work_mbc->range_sts, wchar_t, ++range_sts_al);
MALLOC(work_mbc->range_ends, wchar_t, ++range_ends_al);
@@ -986,8 +986,8 @@ parse_bracket_exp (void)
}
FETCH_WC(c1, wc1, _("unbalanced ["));
- continue;
- }
+ continue;
+ }
#if MBS_SUPPORT
/* Build normal characters. */
@@ -1005,7 +1005,7 @@ parse_bracket_exp (void)
work_mbc->chars[work_mbc->nchars++] = wc;
}
#ifdef GREP
- continue;
+ continue;
#else
wc = towupper(wc);
c = wctob(wc);
@@ -1024,14 +1024,14 @@ parse_bracket_exp (void)
}
while ((
#if MBS_SUPPORT
- wc = wc1,
+ wc = wc1,
#endif
- (c = c1) != ']'));
+ (c = c1) != ']'));
#if MBS_SUPPORT
if (MB_CUR_MAX > 1
&& (!using_utf8()
- || invert
+ || invert
|| work_mbc->nchars != 0
|| work_mbc->nch_classes != 0
|| work_mbc->nranges != 0
@@ -1089,299 +1089,299 @@ lex (void)
FETCH(c, NULL);
switch (c)
- {
- case '\\':
- if (backslash)
- goto normal_char;
- if (lexleft == 0)
- dfaerror(_("unfinished \\ escape"));
- backslash = 1;
- break;
-
- case '^':
- if (backslash)
- goto normal_char;
- if (syntax_bits & RE_CONTEXT_INDEP_ANCHORS
- || lasttok == END
- || lasttok == LPAREN
- || lasttok == OR)
- return lasttok = BEGLINE;
- goto normal_char;
-
- case '$':
- if (backslash)
- goto normal_char;
- if (syntax_bits & RE_CONTEXT_INDEP_ANCHORS
- || lexleft == 0
- || (syntax_bits & RE_NO_BK_PARENS
- ? lexleft > 0 && *lexptr == ')'
- : lexleft > 1 && lexptr[0] == '\\' && lexptr[1] == ')')
- || (syntax_bits & RE_NO_BK_VBAR
- ? lexleft > 0 && *lexptr == '|'
- : lexleft > 1 && lexptr[0] == '\\' && lexptr[1] == '|')
- || ((syntax_bits & RE_NEWLINE_ALT)
- && lexleft > 0 && *lexptr == '\n'))
- return lasttok = ENDLINE;
- goto normal_char;
-
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- if (backslash && !(syntax_bits & RE_NO_BK_REFS))
- {
- laststart = 0;
- return lasttok = BACKREF;
- }
- goto normal_char;
-
- case '`':
- if (backslash && !(syntax_bits & RE_NO_GNU_OPS))
- return lasttok = BEGLINE; /* FIXME: should be beginning of string */
- goto normal_char;
-
- case '\'':
- if (backslash && !(syntax_bits & RE_NO_GNU_OPS))
- return lasttok = ENDLINE; /* FIXME: should be end of string */
- goto normal_char;
-
- case '<':
- if (backslash && !(syntax_bits & RE_NO_GNU_OPS))
- return lasttok = BEGWORD;
- goto normal_char;
-
- case '>':
- if (backslash && !(syntax_bits & RE_NO_GNU_OPS))
- return lasttok = ENDWORD;
- goto normal_char;
-
- case 'b':
- if (backslash && !(syntax_bits & RE_NO_GNU_OPS))
- return lasttok = LIMWORD;
- goto normal_char;
-
- case 'B':
- if (backslash && !(syntax_bits & RE_NO_GNU_OPS))
- return lasttok = NOTLIMWORD;
- goto normal_char;
-
- case '?':
- if (syntax_bits & RE_LIMITED_OPS)
- goto normal_char;
- if (backslash != ((syntax_bits & RE_BK_PLUS_QM) != 0))
- goto normal_char;
- if (!(syntax_bits & RE_CONTEXT_INDEP_OPS) && laststart)
- goto normal_char;
- return lasttok = QMARK;
-
- case '*':
- if (backslash)
- goto normal_char;
- if (!(syntax_bits & RE_CONTEXT_INDEP_OPS) && laststart)
- goto normal_char;
- return lasttok = STAR;
-
- case '+':
- if (syntax_bits & RE_LIMITED_OPS)
- goto normal_char;
- if (backslash != ((syntax_bits & RE_BK_PLUS_QM) != 0))
- goto normal_char;
- if (!(syntax_bits & RE_CONTEXT_INDEP_OPS) && laststart)
- goto normal_char;
- return lasttok = PLUS;
-
- case '{':
- if (!(syntax_bits & RE_INTERVALS))
- goto normal_char;
- if (backslash != ((syntax_bits & RE_NO_BK_BRACES) == 0))
- goto normal_char;
- if (!(syntax_bits & RE_CONTEXT_INDEP_OPS) && laststart)
- goto normal_char;
-
- if (syntax_bits & RE_NO_BK_BRACES)
- {
- /* Scan ahead for a valid interval; if it's not valid,
- treat it as a literal '{'. */
- int lo = -1, hi = -1;
- char const *p = lexptr;
- char const *lim = p + lexleft;
- for (; p != lim && ISASCIIDIGIT (*p); p++)
- lo = (lo < 0 ? 0 : lo * 10) + *p - '0';
- if (p != lim && *p == ',')
- while (++p != lim && ISASCIIDIGIT (*p))
- hi = (hi < 0 ? 0 : hi * 10) + *p - '0';
- else
- hi = lo;
- if (p == lim || *p != '}'
- || lo < 0 || RE_DUP_MAX < hi || (0 <= hi && hi < lo))
- goto normal_char;
- }
-
- minrep = 0;
- /* Cases:
- {M} - exact count
- {M,} - minimum count, maximum is infinity
- {M,N} - M through N */
- FETCH(c, _("unfinished repeat count"));
- if (ISASCIIDIGIT (c))
- {
- minrep = c - '0';
- for (;;)
- {
- FETCH(c, _("unfinished repeat count"));
- if (! ISASCIIDIGIT (c))
- break;
- minrep = 10 * minrep + c - '0';
- }
- }
- else
- dfaerror(_("malformed repeat count"));
- if (c == ',')
- {
- FETCH (c, _("unfinished repeat count"));
- if (! ISASCIIDIGIT (c))
- maxrep = -1;
- else
- {
- maxrep = c - '0';
- for (;;)
- {
- FETCH (c, _("unfinished repeat count"));
- if (! ISASCIIDIGIT (c))
- break;
- maxrep = 10 * maxrep + c - '0';
- }
- if (0 <= maxrep && maxrep < minrep)
- dfaerror (_("malformed repeat count"));
- }
- }
- else
- maxrep = minrep;
- if (!(syntax_bits & RE_NO_BK_BRACES))
- {
- if (c != '\\')
- dfaerror(_("malformed repeat count"));
- FETCH(c, _("unfinished repeat count"));
- }
- if (c != '}')
- dfaerror(_("malformed repeat count"));
- laststart = 0;
+ {
+ case '\\':
+ if (backslash)
+ goto normal_char;
+ if (lexleft == 0)
+ dfaerror(_("unfinished \\ escape"));
+ backslash = 1;
+ break;
+
+ case '^':
+ if (backslash)
+ goto normal_char;
+ if (syntax_bits & RE_CONTEXT_INDEP_ANCHORS
+ || lasttok == END
+ || lasttok == LPAREN
+ || lasttok == OR)
+ return lasttok = BEGLINE;
+ goto normal_char;
+
+ case '$':
+ if (backslash)
+ goto normal_char;
+ if (syntax_bits & RE_CONTEXT_INDEP_ANCHORS
+ || lexleft == 0
+ || (syntax_bits & RE_NO_BK_PARENS
+ ? lexleft > 0 && *lexptr == ')'
+ : lexleft > 1 && lexptr[0] == '\\' && lexptr[1] == ')')
+ || (syntax_bits & RE_NO_BK_VBAR
+ ? lexleft > 0 && *lexptr == '|'
+ : lexleft > 1 && lexptr[0] == '\\' && lexptr[1] == '|')
+ || ((syntax_bits & RE_NEWLINE_ALT)
+ && lexleft > 0 && *lexptr == '\n'))
+ return lasttok = ENDLINE;
+ goto normal_char;
+
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ if (backslash && !(syntax_bits & RE_NO_BK_REFS))
+ {
+ laststart = 0;
+ return lasttok = BACKREF;
+ }
+ goto normal_char;
+
+ case '`':
+ if (backslash && !(syntax_bits & RE_NO_GNU_OPS))
+ return lasttok = BEGLINE; /* FIXME: should be beginning of string */
+ goto normal_char;
+
+ case '\'':
+ if (backslash && !(syntax_bits & RE_NO_GNU_OPS))
+ return lasttok = ENDLINE; /* FIXME: should be end of string */
+ goto normal_char;
+
+ case '<':
+ if (backslash && !(syntax_bits & RE_NO_GNU_OPS))
+ return lasttok = BEGWORD;
+ goto normal_char;
+
+ case '>':
+ if (backslash && !(syntax_bits & RE_NO_GNU_OPS))
+ return lasttok = ENDWORD;
+ goto normal_char;
+
+ case 'b':
+ if (backslash && !(syntax_bits & RE_NO_GNU_OPS))
+ return lasttok = LIMWORD;
+ goto normal_char;
+
+ case 'B':
+ if (backslash && !(syntax_bits & RE_NO_GNU_OPS))
+ return lasttok = NOTLIMWORD;
+ goto normal_char;
+
+ case '?':
+ if (syntax_bits & RE_LIMITED_OPS)
+ goto normal_char;
+ if (backslash != ((syntax_bits & RE_BK_PLUS_QM) != 0))
+ goto normal_char;
+ if (!(syntax_bits & RE_CONTEXT_INDEP_OPS) && laststart)
+ goto normal_char;
+ return lasttok = QMARK;
+
+ case '*':
+ if (backslash)
+ goto normal_char;
+ if (!(syntax_bits & RE_CONTEXT_INDEP_OPS) && laststart)
+ goto normal_char;
+ return lasttok = STAR;
+
+ case '+':
+ if (syntax_bits & RE_LIMITED_OPS)
+ goto normal_char;
+ if (backslash != ((syntax_bits & RE_BK_PLUS_QM) != 0))
+ goto normal_char;
+ if (!(syntax_bits & RE_CONTEXT_INDEP_OPS) && laststart)
+ goto normal_char;
+ return lasttok = PLUS;
+
+ case '{':
+ if (!(syntax_bits & RE_INTERVALS))
+ goto normal_char;
+ if (backslash != ((syntax_bits & RE_NO_BK_BRACES) == 0))
+ goto normal_char;
+ if (!(syntax_bits & RE_CONTEXT_INDEP_OPS) && laststart)
+ goto normal_char;
+
+ if (syntax_bits & RE_NO_BK_BRACES)
+ {
+ /* Scan ahead for a valid interval; if it's not valid,
+ treat it as a literal '{'. */
+ int lo = -1, hi = -1;
+ char const *p = lexptr;
+ char const *lim = p + lexleft;
+ for (; p != lim && ISASCIIDIGIT (*p); p++)
+ lo = (lo < 0 ? 0 : lo * 10) + *p - '0';
+ if (p != lim && *p == ',')
+ while (++p != lim && ISASCIIDIGIT (*p))
+ hi = (hi < 0 ? 0 : hi * 10) + *p - '0';
+ else
+ hi = lo;
+ if (p == lim || *p != '}'
+ || lo < 0 || RE_DUP_MAX < hi || (0 <= hi && hi < lo))
+ goto normal_char;
+ }
+
+ minrep = 0;
+ /* Cases:
+ {M} - exact count
+ {M,} - minimum count, maximum is infinity
+ {M,N} - M through N */
+ FETCH(c, _("unfinished repeat count"));
+ if (ISASCIIDIGIT (c))
+ {
+ minrep = c - '0';
+ for (;;)
+ {
+ FETCH(c, _("unfinished repeat count"));
+ if (! ISASCIIDIGIT (c))
+ break;
+ minrep = 10 * minrep + c - '0';
+ }
+ }
+ else
+ dfaerror(_("malformed repeat count"));
+ if (c == ',')
+ {
+ FETCH (c, _("unfinished repeat count"));
+ if (! ISASCIIDIGIT (c))
+ maxrep = -1;
+ else
+ {
+ maxrep = c - '0';
+ for (;;)
+ {
+ FETCH (c, _("unfinished repeat count"));
+ if (! ISASCIIDIGIT (c))
+ break;
+ maxrep = 10 * maxrep + c - '0';
+ }
+ if (0 <= maxrep && maxrep < minrep)
+ dfaerror (_("malformed repeat count"));
+ }
+ }
+ else
+ maxrep = minrep;
+ if (!(syntax_bits & RE_NO_BK_BRACES))
+ {
+ if (c != '\\')
+ dfaerror(_("malformed repeat count"));
+ FETCH(c, _("unfinished repeat count"));
+ }
+ if (c != '}')
+ dfaerror(_("malformed repeat count"));
+ laststart = 0;
#ifdef GAWK
- dfa->broken = (minrep == maxrep && minrep == 0);
+ dfa->broken = (minrep == maxrep && minrep == 0);
#endif
- return lasttok = REPMN;
-
- case '|':
- if (syntax_bits & RE_LIMITED_OPS)
- goto normal_char;
- if (backslash != ((syntax_bits & RE_NO_BK_VBAR) == 0))
- goto normal_char;
- laststart = 1;
- return lasttok = OR;
-
- case '\n':
- if (syntax_bits & RE_LIMITED_OPS
- || backslash
- || !(syntax_bits & RE_NEWLINE_ALT))
- goto normal_char;
- laststart = 1;
- return lasttok = OR;
-
- case '(':
- if (backslash != ((syntax_bits & RE_NO_BK_PARENS) == 0))
- goto normal_char;
- ++parens;
- laststart = 1;
- return lasttok = LPAREN;
-
- case ')':
- if (backslash != ((syntax_bits & RE_NO_BK_PARENS) == 0))
- goto normal_char;
- if (parens == 0 && syntax_bits & RE_UNMATCHED_RIGHT_PAREN_ORD)
- goto normal_char;
- --parens;
- laststart = 0;
- return lasttok = RPAREN;
-
- case '.':
- if (backslash)
- goto normal_char;
+ return lasttok = REPMN;
+
+ case '|':
+ if (syntax_bits & RE_LIMITED_OPS)
+ goto normal_char;
+ if (backslash != ((syntax_bits & RE_NO_BK_VBAR) == 0))
+ goto normal_char;
+ laststart = 1;
+ return lasttok = OR;
+
+ case '\n':
+ if (syntax_bits & RE_LIMITED_OPS
+ || backslash
+ || !(syntax_bits & RE_NEWLINE_ALT))
+ goto normal_char;
+ laststart = 1;
+ return lasttok = OR;
+
+ case '(':
+ if (backslash != ((syntax_bits & RE_NO_BK_PARENS) == 0))
+ goto normal_char;
+ ++parens;
+ laststart = 1;
+ return lasttok = LPAREN;
+
+ case ')':
+ if (backslash != ((syntax_bits & RE_NO_BK_PARENS) == 0))
+ goto normal_char;
+ if (parens == 0 && syntax_bits & RE_UNMATCHED_RIGHT_PAREN_ORD)
+ goto normal_char;
+ --parens;
+ laststart = 0;
+ return lasttok = RPAREN;
+
+ case '.':
+ if (backslash)
+ goto normal_char;
#if MBS_SUPPORT
- if (MB_CUR_MAX > 1)
- {
- /* In multibyte environment period must match with a single
- character not a byte. So we use ANYCHAR. */
- laststart = 0;
- return lasttok = ANYCHAR;
- }
+ if (MB_CUR_MAX > 1)
+ {
+ /* In multibyte environment period must match with a single
+ character not a byte. So we use ANYCHAR. */
+ laststart = 0;
+ return lasttok = ANYCHAR;
+ }
#endif /* MBS_SUPPORT */
- zeroset(ccl);
- notset(ccl);
- if (!(syntax_bits & RE_DOT_NEWLINE))
- clrbit(eolbyte, ccl);
- if (syntax_bits & RE_DOT_NOT_NULL)
- clrbit('\0', ccl);
- laststart = 0;
- return lasttok = CSET + charclass_index(ccl);
+ zeroset(ccl);
+ notset(ccl);
+ if (!(syntax_bits & RE_DOT_NEWLINE))
+ clrbit(eolbyte, ccl);
+ if (syntax_bits & RE_DOT_NOT_NULL)
+ clrbit('\0', ccl);
+ laststart = 0;
+ return lasttok = CSET + charclass_index(ccl);
#ifndef GAWK
- case 's':
- case 'S':
- if (!backslash || (syntax_bits & RE_NO_GNU_OPS))
- goto normal_char;
- zeroset(ccl);
- for (c2 = 0; c2 < NOTCHAR; ++c2)
- if (isspace(c2))
- setbit(c2, ccl);
- if (c == 'S')
- notset(ccl);
- laststart = 0;
- return lasttok = CSET + charclass_index(ccl);
+ case 's':
+ case 'S':
+ if (!backslash || (syntax_bits & RE_NO_GNU_OPS))
+ goto normal_char;
+ zeroset(ccl);
+ for (c2 = 0; c2 < NOTCHAR; ++c2)
+ if (isspace(c2))
+ setbit(c2, ccl);
+ if (c == 'S')
+ notset(ccl);
+ laststart = 0;
+ return lasttok = CSET + charclass_index(ccl);
#endif
- case 'w':
- case 'W':
- if (!backslash || (syntax_bits & RE_NO_GNU_OPS))
- goto normal_char;
- zeroset(ccl);
- for (c2 = 0; c2 < NOTCHAR; ++c2)
- if (IS_WORD_CONSTITUENT(c2))
- setbit(c2, ccl);
- if (c == 'W')
- notset(ccl);
- laststart = 0;
- return lasttok = CSET + charclass_index(ccl);
-
- case '[':
- if (backslash)
- goto normal_char;
- laststart = 0;
- return lasttok = parse_bracket_exp();
-
- default:
- normal_char:
- laststart = 0;
+ case 'w':
+ case 'W':
+ if (!backslash || (syntax_bits & RE_NO_GNU_OPS))
+ goto normal_char;
+ zeroset(ccl);
+ for (c2 = 0; c2 < NOTCHAR; ++c2)
+ if (IS_WORD_CONSTITUENT(c2))
+ setbit(c2, ccl);
+ if (c == 'W')
+ notset(ccl);
+ laststart = 0;
+ return lasttok = CSET + charclass_index(ccl);
+
+ case '[':
+ if (backslash)
+ goto normal_char;
+ laststart = 0;
+ return lasttok = parse_bracket_exp();
+
+ default:
+ normal_char:
+ laststart = 0;
#if MBS_SUPPORT
- /* For multibyte character sets, folding is done in atom. Always
+ /* For multibyte character sets, folding is done in atom. Always
return WCHAR. */
if (MB_CUR_MAX > 1)
return lasttok = WCHAR;
#endif
- if (case_fold && isalpha(c))
- {
- zeroset(ccl);
- setbit_case_fold (c, ccl);
- return lasttok = CSET + charclass_index(ccl);
- }
+ if (case_fold && isalpha(c))
+ {
+ zeroset(ccl);
+ setbit_case_fold (c, ccl);
+ return lasttok = CSET + charclass_index(ccl);
+ }
- return lasttok = c;
- }
+ return lasttok = c;
+ }
}
/* The above loop should consume at most a backslash
@@ -1394,10 +1394,10 @@ lex (void)
static token tok; /* Lookahead token. */
static int depth; /* Current depth of a hypothetical stack
- holding deferred productions. This is
- used to determine the depth that will be
- required of the real stack later on in
- dfaanalyze(). */
+ holding deferred productions. This is
+ used to determine the depth that will be
+ required of the real stack later on in
+ dfaanalyze(). */
static void
addtok_mb (token t, int mbprop)
@@ -1406,7 +1406,7 @@ addtok_mb (token t, int mbprop)
if (MB_CUR_MAX > 1)
{
REALLOC_IF_NECESSARY(dfa->multibyte_prop, int, dfa->nmultibyte_prop,
- dfa->tindex);
+ dfa->tindex);
dfa->multibyte_prop[dfa->tindex] = mbprop;
}
#else
@@ -1553,7 +1553,7 @@ atom (void)
tok = lex();
regexp(0);
if (tok != RPAREN)
- dfaerror(_("unbalanced ("));
+ dfaerror(_("unbalanced ("));
tok = lex();
}
else
@@ -1594,7 +1594,7 @@ copytoks (int tindex, int ntokens)
#if MBS_SUPPORT
/* Update index into multibyte csets. */
if (MB_CUR_MAX > 1 && dfa->tokens[tindex + i] == MBCSET)
- dfa->multibyte_prop[dfa->tindex - 1] = dfa->multibyte_prop[tindex + i];
+ dfa->multibyte_prop[dfa->tindex - 1] = dfa->multibyte_prop[tindex + i];
#endif
}
}
@@ -1608,29 +1608,29 @@ closure (void)
while (tok == QMARK || tok == STAR || tok == PLUS || tok == REPMN)
if (tok == REPMN)
{
- ntokens = nsubtoks(dfa->tindex);
- tindex = dfa->tindex - ntokens;
- if (maxrep < 0)
- addtok(PLUS);
- if (minrep == 0)
- addtok(QMARK);
- for (i = 1; i < minrep; ++i)
- {
- copytoks(tindex, ntokens);
- addtok(CAT);
- }
- for (; i < maxrep; ++i)
- {
- copytoks(tindex, ntokens);
- addtok(QMARK);
- addtok(CAT);
- }
- tok = lex();
+ ntokens = nsubtoks(dfa->tindex);
+ tindex = dfa->tindex - ntokens;
+ if (maxrep < 0)
+ addtok(PLUS);
+ if (minrep == 0)
+ addtok(QMARK);
+ for (i = 1; i < minrep; ++i)
+ {
+ copytoks(tindex, ntokens);
+ addtok(CAT);
+ }
+ for (; i < maxrep; ++i)
+ {
+ copytoks(tindex, ntokens);
+ addtok(QMARK);
+ addtok(CAT);
+ }
+ tok = lex();
}
else
{
- addtok(tok);
- tok = lex();
+ addtok(tok);
+ tok = lex();
}
}
@@ -1654,9 +1654,9 @@ regexp (int toplevel)
tok = lex();
branch();
if (toplevel)
- addtok(ORTOP);
+ addtok(ORTOP);
else
- addtok(OR);
+ addtok(OR);
}
}
@@ -1761,8 +1761,8 @@ merge (position_set const *s1, position_set const *s2, position_set *m)
m->elems[m->nelem++] = s2->elems[j++];
else
{
- m->elems[m->nelem] = s1->elems[i++];
- m->elems[m->nelem++].constraint |= s2->elems[j++].constraint;
+ m->elems[m->nelem] = s1->elems[i++];
+ m->elems[m->nelem++].constraint |= s2->elems[j++].constraint;
}
while (i < s1->nelem)
m->elems[m->nelem++] = s1->elems[i++];
@@ -1805,15 +1805,15 @@ state_index (struct dfa *d, position_set const *s, int newline, int letter)
for (i = 0; i < d->sindex; ++i)
{
if (hash != d->states[i].hash || s->nelem != d->states[i].elems.nelem
- || newline != d->states[i].newline || letter != d->states[i].letter)
- continue;
+ || newline != d->states[i].newline || letter != d->states[i].letter)
+ continue;
for (j = 0; j < s->nelem; ++j)
- if (s->elems[j].constraint
- != d->states[i].elems.elems[j].constraint
- || s->elems[j].index != d->states[i].elems.elems[j].index)
- break;
+ if (s->elems[j].constraint
+ != d->states[i].elems.elems[j].constraint
+ || s->elems[j].index != d->states[i].elems.elems[j].index)
+ break;
if (j == s->nelem)
- return i;
+ return i;
}
/* We'll have to create a new state. */
@@ -1833,19 +1833,19 @@ state_index (struct dfa *d, position_set const *s, int newline, int letter)
for (j = 0; j < s->nelem; ++j)
if (d->tokens[s->elems[j].index] < 0)
{
- 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))
- d->states[i].constraint |= constraint;
- if (! d->states[i].first_end)
- d->states[i].first_end = d->tokens[s->elems[j].index];
+ 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))
+ d->states[i].constraint |= constraint;
+ if (! d->states[i].first_end)
+ d->states[i].first_end = d->tokens[s->elems[j].index];
}
else if (d->tokens[s->elems[j].index] == BACKREF)
{
- d->states[i].constraint = NO_CONSTRAINT;
- d->states[i].backref = 1;
+ d->states[i].constraint = NO_CONSTRAINT;
+ d->states[i].backref = 1;
}
++d->sindex;
@@ -1869,52 +1869,52 @@ epsclosure (position_set *s, struct dfa const *d)
for (i = 0; i < s->nelem; ++i)
if (d->tokens[s->elems[i].index] >= NOTCHAR
- && d->tokens[s->elems[i].index] != BACKREF
+ && d->tokens[s->elems[i].index] != BACKREF
#if MBS_SUPPORT
- && d->tokens[s->elems[i].index] != ANYCHAR
- && d->tokens[s->elems[i].index] != MBCSET
+ && d->tokens[s->elems[i].index] != ANYCHAR
+ && d->tokens[s->elems[i].index] != MBCSET
#endif
- && d->tokens[s->elems[i].index] < CSET)
+ && d->tokens[s->elems[i].index] < CSET)
{
- old = s->elems[i];
- p.constraint = old.constraint;
- delete(s->elems[i], s);
- if (visited[old.index])
- {
- --i;
- continue;
- }
- visited[old.index] = 1;
- switch (d->tokens[old.index])
- {
- case BEGLINE:
- p.constraint &= BEGLINE_CONSTRAINT;
- break;
- case ENDLINE:
- p.constraint &= ENDLINE_CONSTRAINT;
- break;
- case BEGWORD:
- p.constraint &= BEGWORD_CONSTRAINT;
- break;
- case ENDWORD:
- p.constraint &= ENDWORD_CONSTRAINT;
- break;
- case LIMWORD:
- p.constraint &= LIMWORD_CONSTRAINT;
- break;
- case NOTLIMWORD:
- p.constraint &= NOTLIMWORD_CONSTRAINT;
- break;
- default:
- break;
- }
- for (j = 0; j < d->follows[old.index].nelem; ++j)
- {
- p.index = d->follows[old.index].elems[j].index;
- insert(p, s);
- }
- /* Force rescan to start at the beginning. */
- i = -1;
+ old = s->elems[i];
+ p.constraint = old.constraint;
+ delete(s->elems[i], s);
+ if (visited[old.index])
+ {
+ --i;
+ continue;
+ }
+ visited[old.index] = 1;
+ switch (d->tokens[old.index])
+ {
+ case BEGLINE:
+ p.constraint &= BEGLINE_CONSTRAINT;
+ break;
+ case ENDLINE:
+ p.constraint &= ENDLINE_CONSTRAINT;
+ break;
+ case BEGWORD:
+ p.constraint &= BEGWORD_CONSTRAINT;
+ break;
+ case ENDWORD:
+ p.constraint &= ENDWORD_CONSTRAINT;
+ break;
+ case LIMWORD:
+ p.constraint &= LIMWORD_CONSTRAINT;
+ break;
+ case NOTLIMWORD:
+ p.constraint &= NOTLIMWORD_CONSTRAINT;
+ break;
+ default:
+ break;
+ }
+ for (j = 0; j < d->follows[old.index].nelem; ++j)
+ {
+ p.index = d->follows[old.index].elems[j].index;
+ insert(p, s);
+ }
+ /* Force rescan to start at the beginning. */
+ i = -1;
}
free(visited);
@@ -2024,108 +2024,108 @@ dfaanalyze (struct dfa *d, int searchflag)
switch (d->tokens[i])
{
case EMPTY:
- /* The empty set is nullable. */
- *nullable++ = 1;
+ /* 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);
- REALLOC_IF_NECESSARY(d->follows[pos[j].index].elems, position,
- nalloc[pos[j].index], merged.nelem - 1);
- copy(&merged, &d->follows[pos[j].index]);
- }
+ /* 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);
+ REALLOC_IF_NECESSARY(d->follows[pos[j].index].elems, position,
+ nalloc[pos[j].index], merged.nelem - 1);
+ 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;
+ /* 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);
- REALLOC_IF_NECESSARY(d->follows[pos[j].index].elems, position,
- nalloc[pos[j].index], merged.nelem - 1);
- 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])
- 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;
+ /* 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);
+ REALLOC_IF_NECESSARY(d->follows[pos[j].index].elems, position,
+ nalloc[pos[j].index], merged.nelem - 1);
+ 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])
+ 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:
case ORTOP:
- /* The firstpos is the union of the firstpos of each argument. */
- nfirstpos[-2] += nfirstpos[-1];
- --nfirstpos;
+ /* 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;
+ /* 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;
-
- /* Allocate the follow set for this position. */
- nalloc[i] = 1;
- MALLOC(d->follows[i].elems, position, nalloc[i]);
- break;
+ /* 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. */
+ nalloc[i] = 1;
+ MALLOC(d->follows[i].elems, position, nalloc[i]);
+ break;
}
#ifdef DEBUG
/* ... balance the above nonsyntactic #ifdef goo... */
@@ -2135,16 +2135,16 @@ dfaanalyze (struct dfa *d, int searchflag)
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:");
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);
}
#endif
@@ -2157,24 +2157,24 @@ dfaanalyze (struct dfa *d, int searchflag)
|| d->tokens[i] == ANYCHAR
|| d->tokens[i] == MBCSET
#endif
- || d->tokens[i] >= CSET)
+ || d->tokens[i] >= CSET)
{
#ifdef DEBUG
- 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]);
- }
- putc('\n', 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]);
+ }
+ putc('\n', stderr);
#endif
- copy(&d->follows[i], &merged);
- epsclosure(&merged, d);
- if (d->follows[i].nelem < merged.nelem)
- REALLOC(d->follows[i].elems, position, merged.nelem);
- copy(&merged, &d->follows[i]);
+ copy(&d->follows[i], &merged);
+ epsclosure(&merged, d);
+ if (d->follows[i].nelem < merged.nelem)
+ REALLOC(d->follows[i].elems, position, merged.nelem);
+ copy(&merged, &d->follows[i]);
}
/* Get the epsilon closure of the firstpos of the regexp. The result will
@@ -2268,8 +2268,8 @@ dfastate (int s, struct dfa *d, int trans[])
{
initialized = 1;
for (i = 0; i < NOTCHAR; ++i)
- if (IS_WORD_CONSTITUENT(i))
- setbit(i, letters);
+ if (IS_WORD_CONSTITUENT(i))
+ setbit(i, letters);
setbit(eolbyte, newline);
}
@@ -2279,115 +2279,115 @@ dfastate (int s, struct dfa *d, int trans[])
{
pos = d->states[s].elems.elems[i];
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);
#if MBS_SUPPORT
else if (d->tokens[pos.index] == ANYCHAR
|| d->tokens[pos.index] == MBCSET)
/* MB_CUR_MAX > 1 */
- {
- /* ANYCHAR and MBCSET must match with a single character, so we
- must put it to d->states[s].mbps, which contains the positions
- which can match with a single character not a byte. */
- if (d->states[s].mbps.nelem == 0)
- {
- MALLOC(d->states[s].mbps.elems, position,
- d->states[s].elems.nelem);
- }
- insert(pos, &(d->states[s].mbps));
- continue;
- }
+ {
+ /* ANYCHAR and MBCSET must match with a single character, so we
+ must put it to d->states[s].mbps, which contains the positions
+ which can match with a single character not a byte. */
+ if (d->states[s].mbps.nelem == 0)
+ {
+ MALLOC(d->states[s].mbps.elems, position,
+ d->states[s].elems.nelem);
+ }
+ insert(pos, &(d->states[s].mbps));
+ continue;
+ }
#endif /* MBS_SUPPORT */
else
- continue;
+ continue;
/* Some characters may need to be eliminated from matches because
- they fail in the current context. */
+ they fail in the current context. */
if (pos.constraint != 0xFF)
- {
- 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))
- for (j = 0; j < CHARCLASS_INTS; ++j)
- matches[j] &= ~letters[j];
- if (! MATCHES_LETTER_CONTEXT(pos.constraint,
- d->states[s].letter, 0))
- for (j = 0; j < CHARCLASS_INTS; ++j)
- matches[j] &= letters[j];
-
- /* If there are no characters left, there's no point in going on. */
- for (j = 0; j < CHARCLASS_INTS && !matches[j]; ++j)
- continue;
- if (j == CHARCLASS_INTS)
- continue;
- }
+ {
+ 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))
+ for (j = 0; j < CHARCLASS_INTS; ++j)
+ matches[j] &= ~letters[j];
+ if (! MATCHES_LETTER_CONTEXT(pos.constraint,
+ d->states[s].letter, 0))
+ for (j = 0; j < CHARCLASS_INTS; ++j)
+ matches[j] &= letters[j];
+
+ /* If there are no characters left, there's no point in going on. */
+ for (j = 0; j < CHARCLASS_INTS && !matches[j]; ++j)
+ continue;
+ if (j == CHARCLASS_INTS)
+ continue;
+ }
for (j = 0; j < ngrps; ++j)
- {
- /* If matches contains a single character only, and the current
- group's label doesn't contain that character, go on to the
- next group. */
- if (d->tokens[pos.index] >= 0 && d->tokens[pos.index] < NOTCHAR
- && !tstbit(d->tokens[pos.index], labels[j]))
- continue;
-
- /* Check if this group's label has a nonempty intersection with
- matches. */
- intersectf = 0;
- for (k = 0; k < CHARCLASS_INTS; ++k)
- (intersect[k] = matches[k] & labels[j][k]) ? (intersectf = 1) : 0;
- if (! intersectf)
- continue;
-
- /* It does; now find the set differences both ways. */
- leftoversf = matchesf = 0;
- for (k = 0; k < CHARCLASS_INTS; ++k)
- {
- /* Even an optimizing compiler can't know this for sure. */
- int match = matches[k], label = labels[j][k];
-
- (leftovers[k] = ~match & label) ? (leftoversf = 1) : 0;
- (matches[k] = match & ~label) ? (matchesf = 1) : 0;
- }
-
- /* If there were leftovers, create a new group labeled with them. */
- if (leftoversf)
- {
- copyset(leftovers, labels[ngrps]);
- copyset(intersect, labels[j]);
- MALLOC(grps[ngrps].elems, position, d->nleaves);
- copy(&grps[j], &grps[ngrps]);
- ++ngrps;
- }
-
- /* Put the position in the current group. Note that there is no
- reason to call insert() here. */
- grps[j].elems[grps[j].nelem++] = pos;
-
- /* If every character matching the current position has been
- accounted for, we're done. */
- if (! matchesf)
- break;
- }
+ {
+ /* If matches contains a single character only, and the current
+ group's label doesn't contain that character, go on to the
+ next group. */
+ if (d->tokens[pos.index] >= 0 && d->tokens[pos.index] < NOTCHAR
+ && !tstbit(d->tokens[pos.index], labels[j]))
+ continue;
+
+ /* Check if this group's label has a nonempty intersection with
+ matches. */
+ intersectf = 0;
+ for (k = 0; k < CHARCLASS_INTS; ++k)
+ (intersect[k] = matches[k] & labels[j][k]) ? (intersectf = 1) : 0;
+ if (! intersectf)
+ continue;
+
+ /* It does; now find the set differences both ways. */
+ leftoversf = matchesf = 0;
+ for (k = 0; k < CHARCLASS_INTS; ++k)
+ {
+ /* Even an optimizing compiler can't know this for sure. */
+ int match = matches[k], label = labels[j][k];
+
+ (leftovers[k] = ~match & label) ? (leftoversf = 1) : 0;
+ (matches[k] = match & ~label) ? (matchesf = 1) : 0;
+ }
+
+ /* If there were leftovers, create a new group labeled with them. */
+ if (leftoversf)
+ {
+ copyset(leftovers, labels[ngrps]);
+ copyset(intersect, labels[j]);
+ MALLOC(grps[ngrps].elems, position, d->nleaves);
+ copy(&grps[j], &grps[ngrps]);
+ ++ngrps;
+ }
+
+ /* Put the position in the current group. Note that there is no
+ reason to call insert() here. */
+ grps[j].elems[grps[j].nelem++] = pos;
+
+ /* If every character matching the current position has been
+ accounted for, we're done. */
+ if (! matchesf)
+ break;
+ }
/* If we've passed the last group, and there are still characters
- unaccounted for, then we'll have to create a new group. */
+ unaccounted for, then we'll have to create a new group. */
if (j == ngrps)
- {
- copyset(matches, labels[ngrps]);
- zeroset(matches);
- MALLOC(grps[ngrps].elems, position, d->nleaves);
- grps[ngrps].nelem = 1;
- grps[ngrps].elems[0] = pos;
- ++ngrps;
- }
+ {
+ copyset(matches, labels[ngrps]);
+ zeroset(matches);
+ MALLOC(grps[ngrps].elems, position, d->nleaves);
+ grps[ngrps].nelem = 1;
+ grps[ngrps].elems[0] = pos;
+ ++ngrps;
+ }
}
MALLOC(follows.elems, position, d->nleaves);
@@ -2401,24 +2401,24 @@ dfastate (int s, struct dfa *d, int trans[])
wants_newline = 0;
wants_letter = 0;
for (i = 0; i < d->states[0].elems.nelem; ++i)
- {
- 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))
- wants_letter = 1;
- }
+ {
+ 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))
+ wants_letter = 1;
+ }
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
- state_newline = state;
+ state_newline = state;
if (wants_letter)
- state_letter = state_index(d, &follows, 0, 1);
+ state_letter = state_index(d, &follows, 0, 1);
else
- state_letter = state;
+ state_letter = state;
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;
}
else
@@ -2430,95 +2430,95 @@ dfastate (int s, struct dfa *d, int trans[])
follows.nelem = 0;
/* Find the union of the follows of the positions of the group.
- This is a hideously inefficient loop. Fix it someday. */
+ This is a hideously inefficient loop. Fix it someday. */
for (j = 0; j < grps[i].nelem; ++j)
- for (k = 0; k < d->follows[grps[i].elems[j].index].nelem; ++k)
- insert(d->follows[grps[i].elems[j].index].elems[k], &follows);
+ for (k = 0; k < d->follows[grps[i].elems[j].index].nelem; ++k)
+ insert(d->follows[grps[i].elems[j].index].elems[k], &follows);
#if MBS_SUPPORT
if (d->mb_cur_max > 1)
- {
- /* If a token in follows.elems is not 1st byte of a multibyte
- character, or the states of follows must accept the bytes
- which are not 1st byte of the multibyte character.
- Then, if a state of follows encounter a byte, it must not be
- a 1st byte of a multibyte character nor single byte character.
- We cansel to add state[0].follows to next state, because
- state[0] must accept 1st-byte
-
- For example, we assume <sb a> is a certain single byte
- character, <mb A> is a certain multibyte character, and the
- codepoint of <sb a> equals the 2nd byte of the codepoint of
- <mb A>.
- When state[0] accepts <sb a>, state[i] transit to state[i+1]
- by accepting accepts 1st byte of <mb A>, and state[i+1]
- accepts 2nd byte of <mb A>, if state[i+1] encounter the
- codepoint of <sb a>, it must not be <sb a> but 2nd byte of
- <mb A>, so we can not add state[0]. */
-
- next_isnt_1st_byte = 0;
- for (j = 0; j < follows.nelem; ++j)
- {
- if (!(d->multibyte_prop[follows.elems[j].index] & 1))
- {
- next_isnt_1st_byte = 1;
- break;
- }
- }
- }
+ {
+ /* If a token in follows.elems is not 1st byte of a multibyte
+ character, or the states of follows must accept the bytes
+ which are not 1st byte of the multibyte character.
+ Then, if a state of follows encounter a byte, it must not be
+ a 1st byte of a multibyte character nor single byte character.
+ We cansel to add state[0].follows to next state, because
+ state[0] must accept 1st-byte
+
+ For example, we assume <sb a> is a certain single byte
+ character, <mb A> is a certain multibyte character, and the
+ codepoint of <sb a> equals the 2nd byte of the codepoint of
+ <mb A>.
+ When state[0] accepts <sb a>, state[i] transit to state[i+1]
+ by accepting accepts 1st byte of <mb A>, and state[i+1]
+ accepts 2nd byte of <mb A>, if state[i+1] encounter the
+ codepoint of <sb a>, it must not be <sb a> but 2nd byte of
+ <mb A>, so we can not add state[0]. */
+
+ next_isnt_1st_byte = 0;
+ for (j = 0; j < follows.nelem; ++j)
+ {
+ if (!(d->multibyte_prop[follows.elems[j].index] & 1))
+ {
+ next_isnt_1st_byte = 1;
+ break;
+ }
+ }
+ }
#endif
/* If we are building a searching matcher, throw in the positions
- of state 0 as well. */
+ of state 0 as well. */
#if MBS_SUPPORT
if (d->searchflag && (d->mb_cur_max == 1 || !next_isnt_1st_byte))
#else
if (d->searchflag)
#endif
- for (j = 0; j < d->states[0].elems.nelem; ++j)
- insert(d->states[0].elems.elems[j], &follows);
+ for (j = 0; j < d->states[0].elems.nelem; ++j)
+ insert(d->states[0].elems.elems[j], &follows);
/* Find out if the new state will want any context information. */
wants_newline = 0;
if (tstbit(eolbyte, labels[i]))
- for (j = 0; j < follows.nelem; ++j)
- if (PREV_NEWLINE_DEPENDENT(follows.elems[j].constraint))
- wants_newline = 1;
+ for (j = 0; j < follows.nelem; ++j)
+ if (PREV_NEWLINE_DEPENDENT(follows.elems[j].constraint))
+ wants_newline = 1;
wants_letter = 0;
for (j = 0; j < CHARCLASS_INTS; ++j)
- if (labels[i][j] & letters[j])
- break;
+ if (labels[i][j] & letters[j])
+ break;
if (j < CHARCLASS_INTS)
- for (j = 0; j < follows.nelem; ++j)
- if (PREV_LETTER_DEPENDENT(follows.elems[j].constraint))
- wants_letter = 1;
+ for (j = 0; j < follows.nelem; ++j)
+ if (PREV_LETTER_DEPENDENT(follows.elems[j].constraint))
+ wants_letter = 1;
/* Find the state(s) corresponding to the union of the 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
- state_newline = state;
+ state_newline = state;
if (wants_letter)
- state_letter = state_index(d, &follows, 0, 1);
+ state_letter = state_index(d, &follows, 0, 1);
else
- state_letter = state;
+ state_letter = state;
/* Set the transitions for each character in the current label. */
for (j = 0; j < CHARCLASS_INTS; ++j)
- for (k = 0; k < INTBITS; ++k)
- if (labels[i][j] & 1 << k)
- {
- int c = j * INTBITS + k;
-
- if (c == eolbyte)
- trans[c] = state_newline;
- else if (IS_WORD_CONSTITUENT(c))
- trans[c] = state_letter;
- else if (c < NOTCHAR)
- trans[c] = state;
- }
+ for (k = 0; k < INTBITS; ++k)
+ if (labels[i][j] & 1 << k)
+ {
+ int c = j * INTBITS + k;
+
+ if (c == eolbyte)
+ trans[c] = state_newline;
+ else if (IS_WORD_CONSTITUENT(c))
+ trans[c] = state_letter;
+ else if (c < NOTCHAR)
+ trans[c] = state;
+ }
}
for (i = 0; i < ngrps; ++i)
@@ -2548,10 +2548,10 @@ build_state (int s, struct dfa *d)
{
for (i = 0; i < d->tralloc; ++i)
{
- free(d->trans[i]);
- free(d->fails[i]);
- d->trans[i] = d->fails[i] = NULL;
- }
+ free(d->trans[i]);
+ free(d->fails[i]);
+ d->trans[i] = d->fails[i] = NULL;
+ }
d->trcount = 0;
}
@@ -2578,20 +2578,20 @@ build_state (int s, struct dfa *d)
for (i = 0; i < NOTCHAR; ++i)
if (trans[i] >= d->tralloc)
{
- int oldalloc = d->tralloc;
-
- while (trans[i] >= d->tralloc)
- d->tralloc *= 2;
- REALLOC(d->realtrans, int *, d->tralloc + 1);
- d->trans = d->realtrans + 1;
- REALLOC(d->fails, int *, d->tralloc);
- REALLOC(d->success, int, d->tralloc);
- REALLOC(d->newlines, int, d->tralloc);
- while (oldalloc < d->tralloc)
- {
- d->trans[oldalloc] = NULL;
- d->fails[oldalloc++] = NULL;
- }
+ int oldalloc = d->tralloc;
+
+ while (trans[i] >= d->tralloc)
+ d->tralloc *= 2;
+ REALLOC(d->realtrans, int *, d->tralloc + 1);
+ d->trans = d->realtrans + 1;
+ REALLOC(d->fails, int *, d->tralloc);
+ REALLOC(d->success, int, d->tralloc);
+ REALLOC(d->newlines, int, d->tralloc);
+ while (oldalloc < d->tralloc)
+ {
+ d->trans[oldalloc] = NULL;
+ d->fails[oldalloc++] = NULL;
+ }
}
/* Keep the newline transition in a special place so we can use it as
@@ -2636,12 +2636,12 @@ build_state_zero (struct dfa *d)
&& (unsigned char const *) p < buf_end) \
++p; \
if ((char *) p >= end) \
- { \
+ { \
free(mblen_buf); \
free(inputwcs); \
- *end = saved_end; \
- return NULL; \
- } \
+ *end = saved_end; \
+ return NULL; \
+ } \
}
static void
@@ -2654,17 +2654,17 @@ realloc_trans_if_necessary(struct dfa *d, int new_state)
int oldalloc = d->tralloc;
while (new_state >= d->tralloc)
- d->tralloc *= 2;
+ d->tralloc *= 2;
REALLOC(d->realtrans, int *, d->tralloc + 1);
d->trans = d->realtrans + 1;
REALLOC(d->fails, int *, d->tralloc);
REALLOC(d->success, int, d->tralloc);
REALLOC(d->newlines, int, d->tralloc);
while (oldalloc < d->tralloc)
- {
- d->trans[oldalloc] = NULL;
- d->fails[oldalloc++] = NULL;
- }
+ {
+ d->trans[oldalloc] = NULL;
+ d->fails[oldalloc++] = NULL;
+ }
}
}
@@ -2683,7 +2683,7 @@ typedef enum
reach the end of the buffer. */
static status_transit_state
transit_state_singlebyte (struct dfa *d, int s, unsigned char const *p,
- int *next_state)
+ int *next_state)
{
int *t;
int works = s;
@@ -2693,30 +2693,30 @@ transit_state_singlebyte (struct dfa *d, int s, unsigned char const *p,
while (rval == TRANSIT_STATE_IN_PROGRESS)
{
if ((t = d->trans[works]) != NULL)
- {
- works = t[*p];
- rval = TRANSIT_STATE_DONE;
- if (works < 0)
- works = 0;
- }
+ {
+ works = t[*p];
+ rval = TRANSIT_STATE_DONE;
+ if (works < 0)
+ works = 0;
+ }
else if (works < 0)
- {
- if (p == buf_end)
- {
- /* At the moment, it must not happen. */
- abort ();
- }
- works = 0;
- }
+ {
+ if (p == buf_end)
+ {
+ /* At the moment, it must not happen. */
+ abort ();
+ }
+ works = 0;
+ }
else if (d->fails[works])
- {
- works = d->fails[works][*p];
- rval = TRANSIT_STATE_DONE;
- }
+ {
+ works = d->fails[works][*p];
+ rval = TRANSIT_STATE_DONE;
+ }
else
- {
- build_state(works, d);
- }
+ {
+ build_state(works, d);
+ }
}
*next_state = works;
return rval;
@@ -2742,13 +2742,13 @@ match_anychar (struct dfa *d, int s, position pos, int idx)
if (wc == (wchar_t)eolbyte)
{
if (!(syntax_bits & RE_DOT_NEWLINE))
- return 0;
+ return 0;
newline = 1;
}
else if (wc == (wchar_t)'\0')
{
if (syntax_bits & RE_DOT_NOT_NULL)
- return 0;
+ return 0;
newline = 1;
}
@@ -2756,7 +2756,7 @@ match_anychar (struct dfa *d, int s, position pos, int idx)
letter = 1;
if (!SUCCEEDS_IN_CONTEXT(pos.constraint, d->states[s].newline,
- newline, d->states[s].letter, letter))
+ newline, d->states[s].letter, letter))
return 0;
return mbclen;
@@ -2773,7 +2773,7 @@ match_mb_charset (struct dfa *d, int s, position pos, int idx)
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. */
+ with which this operator match. */
int op_len; /* Length of the operator. */
char buffer[128];
wchar_t wcbuf[6];
@@ -2791,19 +2791,19 @@ match_mb_charset (struct dfa *d, int s, position pos, int idx)
if (wc == (wchar_t)eolbyte)
{
if (!(syntax_bits & RE_DOT_NEWLINE))
- return 0;
+ return 0;
newline = 1;
}
else if (wc == (wchar_t)'\0')
{
if (syntax_bits & RE_DOT_NOT_NULL)
- return 0;
+ return 0;
newline = 1;
}
if (iswalnum(wc) || wc == L'_')
letter = 1;
if (!SUCCEEDS_IN_CONTEXT(pos.constraint, d->states[s].newline,
- newline, d->states[s].letter, letter))
+ newline, d->states[s].letter, letter))
return 0;
/* Assign the current refering operator to work_mbc. */
@@ -2820,7 +2820,7 @@ match_mb_charset (struct dfa *d, int s, position pos, int idx)
for (i = 0; i<work_mbc->nch_classes; i++)
{
if (iswctype((wint_t)wc, work_mbc->ch_classes[i]))
- goto charset_matched;
+ goto charset_matched;
}
strncpy(buffer, (char const *) buf_begin + idx, match_len);
@@ -2833,10 +2833,10 @@ match_mb_charset (struct dfa *d, int s, position pos, int idx)
strncpy(buffer, (char const *) buf_begin + idx, op_len);
buffer[op_len] = '\0';
if (strcoll(work_mbc->equivs[i], buffer) == 0)
- {
- match_len = op_len;
- goto charset_matched;
- }
+ {
+ match_len = op_len;
+ goto charset_matched;
+ }
}
/* match with a collating element? */
@@ -2847,10 +2847,10 @@ match_mb_charset (struct dfa *d, int s, position pos, int idx)
buffer[op_len] = '\0';
if (strcoll(work_mbc->coll_elems[i], buffer) == 0)
- {
- match_len = op_len;
- goto charset_matched;
- }
+ {
+ match_len = op_len;
+ goto charset_matched;
+ }
}
wcbuf[0] = wc;
@@ -2863,15 +2863,15 @@ match_mb_charset (struct dfa *d, int s, position pos, int idx)
wcbuf[4] = work_mbc->range_ends[i];
if (wcscoll(wcbuf, wcbuf+2) >= 0 &&
- wcscoll(wcbuf+4, wcbuf) >= 0)
- goto charset_matched;
+ wcscoll(wcbuf+4, wcbuf) >= 0)
+ goto charset_matched;
}
/* match with a character? */
for (i = 0; i<work_mbc->nchars; i++)
{
if (wc == work_mbc->chars[i])
- goto charset_matched;
+ goto charset_matched;
}
match = !match;
@@ -2898,16 +2898,16 @@ check_matching_with_multibyte_ops (struct dfa *d, int s, int idx)
{
position pos = d->states[s].mbps.elems[i];
switch(d->tokens[pos.index])
- {
- case ANYCHAR:
- rarray[i] = match_anychar(d, s, pos, idx);
- break;
- case MBCSET:
- rarray[i] = match_mb_charset(d, s, pos, idx);
- break;
- default:
- break; /* can not happen. */
- }
+ {
+ case ANYCHAR:
+ rarray[i] = match_anychar(d, s, pos, idx);
+ break;
+ case MBCSET:
+ rarray[i] = match_mb_charset(d, s, pos, idx);
+ break;
+ default:
+ break; /* can not happen. */
+ }
}
return rarray;
}
@@ -2920,7 +2920,7 @@ check_matching_with_multibyte_ops (struct dfa *d, int s, int idx)
character consumed, and `pps' is the set this function enumerate. */
static status_transit_state
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)
{
int i, j;
int s1, s2;
@@ -2954,10 +2954,10 @@ transit_state_consume_1char (struct dfa *d, int s, unsigned char const **pp,
for (i = 0; i < d->states[s].mbps.nelem ; i++)
{
if (work_mbls[i] == *mbclen)
- for (j = 0; j < d->follows[d->states[s].mbps.elems[i].index].nelem;
- j++)
- insert(d->follows[d->states[s].mbps.elems[i].index].elems[j],
- pps);
+ for (j = 0; j < d->follows[d->states[s].mbps.elems[i].index].nelem;
+ j++)
+ insert(d->follows[d->states[s].mbps.elems[i].index].elems[j],
+ pps);
}
if (match_lens == NULL && work_mbls != NULL)
@@ -2989,12 +2989,12 @@ transit_state (struct dfa *d, int s, unsigned char const **pp)
match_lens = check_matching_with_multibyte_ops(d, s, *pp - buf_begin);
for (i = 0; i < nelem; i++)
- /* Search the operator which match the longest string,
- in this state. */
- {
- if (match_lens[i] > maxlen)
- maxlen = match_lens[i];
- }
+ /* Search the operator which match the longest string,
+ in this state. */
+ {
+ if (match_lens[i] > maxlen)
+ maxlen = match_lens[i];
+ }
}
if (nelem == 0 || maxlen == 0)
@@ -3006,7 +3006,7 @@ transit_state (struct dfa *d, int s, unsigned char const **pp)
/* We must update the pointer if state transition succeeded. */
if (rs == TRANSIT_STATE_DONE)
- ++*pp;
+ ++*pp;
free(match_lens);
return s1;
@@ -3032,13 +3032,13 @@ transit_state (struct dfa *d, int s, unsigned char const **pp)
transit_state_consume_1char(d, s1, pp, NULL, &mbclen, &follows);
for (i = 0; i < nelem ; i++)
- {
- if (match_lens[i] == *pp - p1)
- for (j = 0;
- 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);
- }
+ {
+ if (match_lens[i] == *pp - p1)
+ for (j = 0;
+ 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);
+ }
wc = inputwcs[*pp - mbclen - buf_begin];
s1 = state_index(d, &follows, wc == L'\n', iswalnum(wc));
@@ -3065,12 +3065,12 @@ transit_state (struct dfa *d, int s, unsigned char const **pp)
to decide whether to fall back on a backtracking matcher. */
char *
dfaexec (struct dfa *d, char const *begin, char *end,
- int newline, int *count, int *backref)
+ int newline, int *count, int *backref)
{
int s, s1, tmp; /* Current state. */
unsigned char const *p; /* Current input character. */
int **trans, *t; /* Copy of d->trans so it can be optimized
- into a register. */
+ into a register. */
unsigned char eol = eolbyte; /* Likewise for eolbyte. */
static int sbit[NOTCHAR]; /* Table for anding with d->success. */
static int sbit_init;
@@ -3081,7 +3081,7 @@ dfaexec (struct dfa *d, char const *begin, char *end,
sbit_init = 1;
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;
}
@@ -3108,31 +3108,31 @@ dfaexec (struct dfa *d, char const *begin, char *end,
memset(&mbs, 0, sizeof mbs);
remain_bytes = 0;
for (i = 0; i < end - begin + 1; i++)
- {
- if (remain_bytes == 0)
- {
- remain_bytes
- = mbrtowc(inputwcs + i, begin + i, end - begin - i + 1, &mbs);
- if (remain_bytes < 1
- || (remain_bytes == 1 && inputwcs[i] == (wchar_t)begin[i]))
- {
- remain_bytes = 0;
- inputwcs[i] = (wchar_t)begin[i];
- mblen_buf[i] = 0;
- }
- else
- {
- mblen_buf[i] = remain_bytes;
- remain_bytes--;
- }
- }
- else
- {
- mblen_buf[i] = remain_bytes;
- inputwcs[i] = 0;
- remain_bytes--;
- }
- }
+ {
+ if (remain_bytes == 0)
+ {
+ remain_bytes
+ = mbrtowc(inputwcs + i, begin + i, end - begin - i + 1, &mbs);
+ if (remain_bytes < 1
+ || (remain_bytes == 1 && inputwcs[i] == (wchar_t)begin[i]))
+ {
+ remain_bytes = 0;
+ inputwcs[i] = (wchar_t)begin[i];
+ mblen_buf[i] = 0;
+ }
+ else
+ {
+ mblen_buf[i] = remain_bytes;
+ remain_bytes--;
+ }
+ }
+ else
+ {
+ mblen_buf[i] = remain_bytes;
+ inputwcs[i] = 0;
+ remain_bytes--;
+ }
+ }
mblen_buf[i] = 0;
inputwcs[i] = 0; /* sentinel */
}
@@ -3142,97 +3142,97 @@ dfaexec (struct dfa *d, char const *begin, char *end,
{
#if MBS_SUPPORT
if (d->mb_cur_max > 1)
- while ((t = trans[s]))
- {
- if ((char *) p > end)
- break;
- s1 = s;
- SKIP_REMAINS_MB_IF_INITIAL_STATE(s, p);
-
- if (d->states[s].mbps.nelem == 0)
- {
- s = t[*p++];
- continue;
- }
-
- /* Can match with a multibyte character (and multi character
- collating element). Transition table might be updated. */
- s = transit_state(d, s, &p);
- trans = d->trans;
- }
+ while ((t = trans[s]))
+ {
+ if ((char *) p > end)
+ break;
+ s1 = s;
+ SKIP_REMAINS_MB_IF_INITIAL_STATE(s, p);
+
+ if (d->states[s].mbps.nelem == 0)
+ {
+ s = t[*p++];
+ continue;
+ }
+
+ /* Can match with a multibyte character (and multi character
+ collating element). Transition table might be updated. */
+ s = transit_state(d, s, &p);
+ trans = d->trans;
+ }
else
#endif /* MBS_SUPPORT */
while ((t = trans[s]) != 0) { /* hand-optimized loop */
- s1 = t[*p++];
- if ((t = trans[s1]) == 0) {
- tmp = s ; s = s1 ; s1 = tmp ; /* swap */
- break;
- }
- s = t[*p++];
+ s1 = t[*p++];
+ if ((t = trans[s1]) == 0) {
+ tmp = s ; s = s1 ; s1 = tmp ; /* swap */
+ break;
+ }
+ s = t[*p++];
}
if (s >= 0 && (char *) p <= end && d->fails[s])
- {
- if (d->success[s] & sbit[*p])
- {
- if (backref)
- *backref = (d->states[s].backref != 0);
+ {
+ if (d->success[s] & sbit[*p])
+ {
+ if (backref)
+ *backref = (d->states[s].backref != 0);
#if MBS_SUPPORT
- if (d->mb_cur_max > 1)
- {
- free(mblen_buf);
- free(inputwcs);
- }
+ if (d->mb_cur_max > 1)
+ {
+ free(mblen_buf);
+ free(inputwcs);
+ }
#endif /* MBS_SUPPORT */
- *end = saved_end;
- return (char *) p;
- }
+ *end = saved_end;
+ return (char *) p;
+ }
- s1 = s;
+ s1 = s;
#if MBS_SUPPORT
- if (d->mb_cur_max > 1)
- {
+ if (d->mb_cur_max > 1)
+ {
/* Can match with a multibyte character (and multicharacter
collating element). Transition table might be updated. */
s = transit_state(d, s, &p);
trans = d->trans;
}
- else
+ else
#endif /* MBS_SUPPORT */
- s = d->fails[s][*p++];
- continue;
- }
+ s = d->fails[s][*p++];
+ continue;
+ }
/* If the previous character was a newline, count it. */
if (count && (char *) p <= end && p[-1] == eol)
- ++*count;
+ ++*count;
/* Check if we've run off the end of the buffer. */
if ((char *) p > end)
- {
+ {
#if MBS_SUPPORT
- if (d->mb_cur_max > 1)
- {
- free(mblen_buf);
- free(inputwcs);
- }
+ if (d->mb_cur_max > 1)
+ {
+ free(mblen_buf);
+ free(inputwcs);
+ }
#endif /* MBS_SUPPORT */
- *end = saved_end;
- return NULL;
- }
+ *end = saved_end;
+ return NULL;
+ }
if (s >= 0)
- {
- build_state(s, d);
- trans = d->trans;
- continue;
- }
+ {
+ build_state(s, d);
+ trans = d->trans;
+ continue;
+ }
if (p[-1] == eol && newline)
- {
- s = d->newlines[s1];
- continue;
- }
+ {
+ s = d->newlines[s1];
+ continue;
+ }
s = 0;
}
@@ -3320,14 +3320,14 @@ dfaoptimize (struct dfa *d)
for (i = 0; i < d->tindex; ++i)
{
switch(d->tokens[i])
- {
- case ANYCHAR:
- case MBCSET:
- /* Requires multi-byte algorithm. */
- return;
- default:
- break;
- }
+ {
+ case ANYCHAR:
+ case MBCSET:
+ /* Requires multi-byte algorithm. */
+ return;
+ default:
+ break;
+ }
}
free_mbdata (d);
@@ -3400,10 +3400,10 @@ dfafree (struct dfa *d)
We do a bottom-up calculation of sequences of characters that must appear
in matches of r.e.'s represented by trees rooted at the nodes of the postfix
representation:
- sequences that must appear at the left of the match ("left")
- sequences that must appear at the right of the match ("right")
- lists of sequences that must appear somewhere in the match ("in")
- sequences that must constitute the match ("is")
+ sequences that must appear at the left of the match ("left")
+ sequences that must appear at the right of the match ("right")
+ lists of sequences that must appear somewhere in the match ("in")
+ sequences that must constitute the match ("is")
When we get to the root of the tree, we use one of the longest of its
calculated "in" sequences as our answer. The sequence we find is returned in
@@ -3417,32 +3417,32 @@ dfafree (struct dfa *d)
"ZERO" means "a zero-length sequence" below.
- Type left right is in
- ---- ---- ----- -- --
- char c # c # c # c # c
+ Type left right is in
+ ---- ---- ----- -- --
+ char c # c # c # c # c
- ANYCHAR ZERO ZERO ZERO ZERO
+ ANYCHAR ZERO ZERO ZERO ZERO
- MBCSET ZERO ZERO ZERO ZERO
+ MBCSET ZERO ZERO ZERO ZERO
- CSET ZERO ZERO ZERO ZERO
+ CSET ZERO ZERO ZERO ZERO
- STAR ZERO ZERO ZERO ZERO
+ STAR ZERO ZERO ZERO ZERO
- QMARK ZERO ZERO ZERO ZERO
+ QMARK ZERO ZERO ZERO ZERO
- PLUS p->left p->right ZERO p->in
+ PLUS p->left p->right ZERO p->in
- CAT (p->is==ZERO)? (q->is==ZERO)? (p->is!=ZERO && p->in plus
- p->left : q->right : q->is!=ZERO) ? q->in plus
- p->is##q->left p->right##q->is p->is##q->is : p->right##q->left
- ZERO
+ CAT (p->is==ZERO)? (q->is==ZERO)? (p->is!=ZERO && p->in plus
+ p->left : q->right : q->is!=ZERO) ? q->in plus
+ p->is##q->left p->right##q->is p->is##q->is : p->right##q->left
+ ZERO
- OR longest common longest common (do p->is and substrings common to
- leading trailing q->is have same p->in and q->in
- (sub)sequence (sub)sequence length and
- of p->left of p->right content) ?
- and q->left and q->right p->is : NULL
+ OR longest common longest common (do p->is and substrings common to
+ leading trailing q->is have same p->in and q->in
+ (sub)sequence (sub)sequence length and
+ of p->left of p->right content) ?
+ and q->left and q->right p->is : NULL
If there's anything else we recognize in the tree, all four sequences get set
to zero-length sequences. If there's something we don't recognize in the tree,
@@ -3452,15 +3452,15 @@ dfafree (struct dfa *d)
'aaa')?
And. . .is it here or someplace that we might ponder "optimizations" such as
- egrep 'psi|epsilon' -> egrep 'psi'
- egrep 'pepsi|epsilon' -> egrep 'epsi'
- (Yes, we now find "epsi" as a "string
- that must occur", but we might also
- simplify the *entire* r.e. being sought)
- grep '[c]' -> grep 'c'
- grep '(ab|a)b' -> grep 'ab'
- grep 'ab*' -> grep 'a'
- grep 'a*b' -> grep 'b'
+ egrep 'psi|epsilon' -> egrep 'psi'
+ egrep 'pepsi|epsilon' -> egrep 'epsi'
+ (Yes, we now find "epsi" as a "string
+ that must occur", but we might also
+ simplify the *entire* r.e. being sought)
+ grep '[c]' -> grep 'c'
+ grep '(ab|a)b' -> grep 'ab'
+ grep 'ab*' -> grep 'a'
+ grep 'a*b' -> grep 'b'
There are several issues:
@@ -3545,8 +3545,8 @@ enlist (char **cpp, char *new, size_t len)
for (i = 0; cpp[i] != NULL; ++i)
if (istrstr(cpp[i], new) != NULL)
{
- free(new);
- return cpp;
+ free(new);
+ return cpp;
}
/* Eliminate any obsoleted strings. */
j = 0;
@@ -3555,11 +3555,11 @@ enlist (char **cpp, char *new, size_t len)
++j;
else
{
- free(cpp[j]);
- if (--i == j)
- break;
- cpp[j] = cpp[i];
- cpp[i] = NULL;
+ free(cpp[j]);
+ if (--i == j)
+ break;
+ cpp[j] = cpp[i];
+ cpp[i] = NULL;
}
/* Add the new string. */
cpp = realloc((char *) cpp, (i + 2) * sizeof *cpp);
@@ -3592,17 +3592,17 @@ comsubs (char *left, char const *right)
len = 0;
rcp = strchr (right, *lcp);
while (rcp != NULL)
- {
- for (i = 1; lcp[i] != '\0' && lcp[i] == rcp[i]; ++i)
- continue;
- if (i > len)
- len = i;
- rcp = strchr (rcp + 1, *lcp);
- }
+ {
+ for (i = 1; lcp[i] != '\0' && lcp[i] == rcp[i]; ++i)
+ continue;
+ if (i > len)
+ len = i;
+ rcp = strchr (rcp + 1, *lcp);
+ }
if (len == 0)
- continue;
+ continue;
if ((cpp = enlist(cpp, lcp, len)) == NULL)
- break;
+ break;
}
return cpp;
}
@@ -3618,7 +3618,7 @@ addlists (char **old, char **new)
{
old = enlist(old, new[i], strlen(new[i]));
if (old == NULL)
- break;
+ break;
}
return old;
}
@@ -3641,19 +3641,19 @@ inboth (char **left, char **right)
for (lnum = 0; left[lnum] != NULL; ++lnum)
{
for (rnum = 0; right[rnum] != NULL; ++rnum)
- {
- temp = comsubs(left[lnum], right[rnum]);
- if (temp == NULL)
- {
- freelist(both);
- return NULL;
- }
- both = addlists(both, temp);
- freelist(temp);
- free(temp);
- if (both == NULL)
- return NULL;
- }
+ {
+ temp = comsubs(left[lnum], right[rnum]);
+ if (temp == NULL)
+ {
+ freelist(both);
+ return NULL;
+ }
+ both = addlists(both, temp);
+ freelist(temp);
+ free(temp);
+ if (both == NULL)
+ return NULL;
+ }
}
return both;
}
@@ -3702,8 +3702,8 @@ dfamust (struct dfa *d)
mp[i].right = malloc(2);
mp[i].is = malloc(2);
if (mp[i].in == NULL || mp[i].left == NULL ||
- mp[i].right == NULL || mp[i].is == NULL)
- goto done;
+ mp[i].right == NULL || mp[i].is == NULL)
+ goto done;
mp[i].left[0] = mp[i].right[0] = mp[i].is[0] = '\0';
mp[i].in[0] = NULL;
}
@@ -3719,178 +3719,178 @@ dfamust (struct dfa *d)
for (ri = 0; ri < d->tindex; ++ri)
{
switch (t = d->tokens[ri])
- {
- case LPAREN:
- case RPAREN:
- goto done; /* "cannot happen" */
- case EMPTY:
- case BEGLINE:
- case ENDLINE:
- case BEGWORD:
- case ENDWORD:
- case LIMWORD:
- case NOTLIMWORD:
- case BACKREF:
- resetmust(mp);
- break;
- case STAR:
- case QMARK:
- if (mp <= musts)
- goto done; /* "cannot happen" */
- --mp;
- resetmust(mp);
- break;
- case OR:
- case ORTOP:
- if (mp < &musts[2])
- goto done; /* "cannot happen" */
- {
- char **new;
- must *lmp;
- must *rmp;
- int j, ln, rn, n;
-
- rmp = --mp;
- lmp = --mp;
- /* Guaranteed to be. Unlikely, but. . . */
- if (!STREQ (lmp->is, rmp->is))
- lmp->is[0] = '\0';
- /* Left side--easy */
- i = 0;
- while (lmp->left[i] != '\0' && lmp->left[i] == rmp->left[i])
- ++i;
- lmp->left[i] = '\0';
- /* Right side */
- ln = strlen(lmp->right);
- rn = strlen(rmp->right);
- n = ln;
- if (n > rn)
- n = rn;
- for (i = 0; i < n; ++i)
- if (lmp->right[ln - i - 1] != rmp->right[rn - i - 1])
- break;
- for (j = 0; j < i; ++j)
- lmp->right[j] = lmp->right[(ln - i) + j];
- lmp->right[j] = '\0';
- new = inboth(lmp->in, rmp->in);
- if (new == NULL)
- goto done;
- freelist(lmp->in);
- free(lmp->in);
- lmp->in = new;
- }
- break;
- case PLUS:
- if (mp <= musts)
- goto done; /* "cannot happen" */
- --mp;
- mp->is[0] = '\0';
- break;
- case END:
- if (mp != &musts[1])
- goto done; /* "cannot happen" */
- for (i = 0; musts[0].in[i] != NULL; ++i)
- if (strlen(musts[0].in[i]) > strlen(result))
- result = musts[0].in[i];
- if (STREQ (result, musts[0].is))
- exact = 1;
- goto done;
- case CAT:
- if (mp < &musts[2])
- goto done; /* "cannot happen" */
- {
- must *lmp;
- must *rmp;
-
- rmp = --mp;
- lmp = --mp;
- /* In. Everything in left, plus everything in
- right, plus catenation of
- left's right and right's left. */
- lmp->in = addlists(lmp->in, rmp->in);
- if (lmp->in == NULL)
- goto done;
- if (lmp->right[0] != '\0' &&
- rmp->left[0] != '\0')
- {
- char *tp;
-
- tp = icpyalloc(lmp->right);
- if (tp == NULL)
- goto done;
- tp = icatalloc(tp, rmp->left);
- if (tp == NULL)
- goto done;
- lmp->in = enlist(lmp->in, tp,
- strlen(tp));
- free(tp);
- if (lmp->in == NULL)
- goto done;
- }
- /* Left-hand */
- if (lmp->is[0] != '\0')
- {
- lmp->left = icatalloc(lmp->left,
- rmp->left);
- if (lmp->left == NULL)
- goto done;
- }
- /* Right-hand */
- if (rmp->is[0] == '\0')
- lmp->right[0] = '\0';
- lmp->right = icatalloc(lmp->right, rmp->right);
- if (lmp->right == NULL)
- goto done;
- /* Guaranteed to be */
- if (lmp->is[0] != '\0' && rmp->is[0] != '\0')
- {
- lmp->is = icatalloc(lmp->is, rmp->is);
- if (lmp->is == NULL)
- goto done;
- }
- else
- lmp->is[0] = '\0';
- }
- break;
- default:
- if (t < END)
- {
- /* "cannot happen" */
- goto done;
- }
- else if (t == '\0')
- {
- /* not on *my* shift */
- goto done;
- }
- else if (t >= CSET
+ {
+ case LPAREN:
+ case RPAREN:
+ goto done; /* "cannot happen" */
+ case EMPTY:
+ case BEGLINE:
+ case ENDLINE:
+ case BEGWORD:
+ case ENDWORD:
+ case LIMWORD:
+ case NOTLIMWORD:
+ case BACKREF:
+ resetmust(mp);
+ break;
+ case STAR:
+ case QMARK:
+ if (mp <= musts)
+ goto done; /* "cannot happen" */
+ --mp;
+ resetmust(mp);
+ break;
+ case OR:
+ case ORTOP:
+ if (mp < &musts[2])
+ goto done; /* "cannot happen" */
+ {
+ char **new;
+ must *lmp;
+ must *rmp;
+ int j, ln, rn, n;
+
+ rmp = --mp;
+ lmp = --mp;
+ /* Guaranteed to be. Unlikely, but. . . */
+ if (!STREQ (lmp->is, rmp->is))
+ lmp->is[0] = '\0';
+ /* Left side--easy */
+ i = 0;
+ while (lmp->left[i] != '\0' && lmp->left[i] == rmp->left[i])
+ ++i;
+ lmp->left[i] = '\0';
+ /* Right side */
+ ln = strlen(lmp->right);
+ rn = strlen(rmp->right);
+ n = ln;
+ if (n > rn)
+ n = rn;
+ for (i = 0; i < n; ++i)
+ if (lmp->right[ln - i - 1] != rmp->right[rn - i - 1])
+ break;
+ for (j = 0; j < i; ++j)
+ lmp->right[j] = lmp->right[(ln - i) + j];
+ lmp->right[j] = '\0';
+ new = inboth(lmp->in, rmp->in);
+ if (new == NULL)
+ goto done;
+ freelist(lmp->in);
+ free(lmp->in);
+ lmp->in = new;
+ }
+ break;
+ case PLUS:
+ if (mp <= musts)
+ goto done; /* "cannot happen" */
+ --mp;
+ mp->is[0] = '\0';
+ break;
+ case END:
+ if (mp != &musts[1])
+ goto done; /* "cannot happen" */
+ for (i = 0; musts[0].in[i] != NULL; ++i)
+ if (strlen(musts[0].in[i]) > strlen(result))
+ result = musts[0].in[i];
+ if (STREQ (result, musts[0].is))
+ exact = 1;
+ goto done;
+ case CAT:
+ if (mp < &musts[2])
+ goto done; /* "cannot happen" */
+ {
+ must *lmp;
+ must *rmp;
+
+ rmp = --mp;
+ lmp = --mp;
+ /* In. Everything in left, plus everything in
+ right, plus catenation of
+ left's right and right's left. */
+ lmp->in = addlists(lmp->in, rmp->in);
+ if (lmp->in == NULL)
+ goto done;
+ if (lmp->right[0] != '\0' &&
+ rmp->left[0] != '\0')
+ {
+ char *tp;
+
+ tp = icpyalloc(lmp->right);
+ if (tp == NULL)
+ goto done;
+ tp = icatalloc(tp, rmp->left);
+ if (tp == NULL)
+ goto done;
+ lmp->in = enlist(lmp->in, tp,
+ strlen(tp));
+ free(tp);
+ if (lmp->in == NULL)
+ goto done;
+ }
+ /* Left-hand */
+ if (lmp->is[0] != '\0')
+ {
+ lmp->left = icatalloc(lmp->left,
+ rmp->left);
+ if (lmp->left == NULL)
+ goto done;
+ }
+ /* Right-hand */
+ if (rmp->is[0] == '\0')
+ lmp->right[0] = '\0';
+ lmp->right = icatalloc(lmp->right, rmp->right);
+ if (lmp->right == NULL)
+ goto done;
+ /* Guaranteed to be */
+ if (lmp->is[0] != '\0' && rmp->is[0] != '\0')
+ {
+ lmp->is = icatalloc(lmp->is, rmp->is);
+ if (lmp->is == NULL)
+ goto done;
+ }
+ else
+ lmp->is[0] = '\0';
+ }
+ break;
+ default:
+ if (t < END)
+ {
+ /* "cannot happen" */
+ goto done;
+ }
+ else if (t == '\0')
+ {
+ /* not on *my* shift */
+ goto done;
+ }
+ else if (t >= CSET
#if MBS_SUPPORT
- || t == ANYCHAR
- || t == MBCSET
+ || t == ANYCHAR
+ || t == MBCSET
#endif /* MBS_SUPPORT */
- )
- {
- /* easy enough */
- resetmust(mp);
- }
- else
- {
- /* plain character */
- 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);
- if (mp->in == NULL)
- goto done;
- }
- break;
- }
+ )
+ {
+ /* easy enough */
+ resetmust(mp);
+ }
+ else
+ {
+ /* plain character */
+ 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);
+ if (mp->in == NULL)
+ goto done;
+ }
+ break;
+ }
#ifdef DEBUG
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, " \"%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);
diff --git a/src/dfa.h b/src/dfa.h
index c107930b..9a43a662 100644
--- a/src/dfa.h
+++ b/src/dfa.h
@@ -67,7 +67,7 @@ extern void dfacomp (char const *, size_t, struct dfa *, int);
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, int *count, int *backref);
+ int newline, int *count, int *backref);
/* Free the storage held by the components of a struct dfa. */
extern void dfafree (struct dfa *);
diff --git a/src/dfasearch.c b/src/dfasearch.c
index cf87b907..35933e37 100644
--- a/src/dfasearch.c
+++ b/src/dfasearch.c
@@ -39,7 +39,7 @@ static struct patterns
/* Regex compiled regexp. */
struct re_pattern_buffer regexbuf;
struct re_registers regs; /* This is here on account of a BRAIN-DEAD
- Q@#%!# library interface in regex.c. */
+ Q@#%!# library interface in regex.c. */
} patterns0;
struct patterns *patterns;
@@ -91,27 +91,27 @@ kwsmusts (void)
{
kwsinit (&kwset);
/* First, we compile in the substrings known to be exact
- matches. The kwset matcher will return the index
- of the matching string that it chooses. */
+ matches. The kwset matcher will return the index
+ of the matching string that it chooses. */
for (; dm; dm = dm->next)
- {
- if (!dm->exact)
- continue;
- ++kwset_exact_matches;
- if ((err = kwsincr_case (dm->must)) != NULL)
- error (EXIT_TROUBLE, 0, "%s", err);
- }
+ {
+ if (!dm->exact)
+ continue;
+ ++kwset_exact_matches;
+ if ((err = kwsincr_case (dm->must)) != NULL)
+ error (EXIT_TROUBLE, 0, "%s", err);
+ }
/* Now, we compile the substrings that will require
- the use of the regexp matcher. */
+ the use of the regexp matcher. */
for (dm = dfamusts (dfa); dm; dm = dm->next)
- {
- if (dm->exact)
- continue;
- if ((err = kwsincr_case (dm->must)) != NULL)
- error (EXIT_TROUBLE, 0, "%s", err);
- }
+ {
+ if (dm->exact)
+ continue;
+ if ((err = kwsincr_case (dm->must)) != NULL)
+ error (EXIT_TROUBLE, 0, "%s", err);
+ }
if ((err = kwsprep (kwset)) != NULL)
- error (EXIT_TROUBLE, 0, "%s", err);
+ error (EXIT_TROUBLE, 0, "%s", err);
}
}
@@ -138,25 +138,25 @@ GEAcompile (char const *pattern, size_t size, reg_syntax_t syntax_bits)
size_t len;
sep = memchr (p, '\n', total);
if (sep)
- {
- len = sep - p;
- sep++;
- total -= (len + 1);
- }
+ {
+ len = sep - p;
+ sep++;
+ total -= (len + 1);
+ }
else
- {
- len = total;
- total = 0;
- }
+ {
+ len = total;
+ total = 0;
+ }
patterns = realloc (patterns, (pcount + 1) * sizeof (*patterns));
if (patterns == NULL)
- error (EXIT_TROUBLE, errno, _("memory exhausted"));
+ error (EXIT_TROUBLE, errno, _("memory exhausted"));
patterns[pcount] = patterns0;
if ((err = re_compile_pattern (p, len,
- &(patterns[pcount].regexbuf))) != NULL)
- error (EXIT_TROUBLE, 0, "%s", err);
+ &(patterns[pcount].regexbuf))) != NULL)
+ error (EXIT_TROUBLE, 0, "%s", err);
pcount++;
p = sep;
@@ -180,12 +180,12 @@ GEAcompile (char const *pattern, size_t size, reg_syntax_t syntax_bits)
char *n = xmalloc (sizeof word_beg_bk - 1 + size + sizeof word_end_bk);
strcpy (n, match_lines ? (bk ? line_beg_bk : line_beg_no_bk)
- : (bk ? word_beg_bk : word_beg_no_bk));
+ : (bk ? word_beg_bk : word_beg_no_bk));
total = strlen(n);
memcpy (n + total, pattern, size);
total += size;
strcpy (n + total, match_lines ? (bk ? line_end_bk : line_end_no_bk)
- : (bk ? word_end_bk : word_end_no_bk));
+ : (bk ? word_end_bk : word_end_no_bk));
total += strlen (n + total);
pattern = motif = n;
size = total;
@@ -202,7 +202,7 @@ GEAcompile (char const *pattern, size_t size, reg_syntax_t syntax_bits)
size_t
EGexecute (char const *buf, size_t size, size_t *match_size,
- char const *start_ptr)
+ char const *start_ptr)
{
char const *buflim, *beg, *end, *match, *best_match, *mb_start;
char eol = eolbyte;
@@ -215,10 +215,10 @@ EGexecute (char const *buf, size_t size, size_t *match_size,
if (match_icase)
{
/* mbtolower adds a NUL byte at the end. That will provide
- space for the sentinel byte dfaexec may add. */
+ space for the sentinel byte dfaexec may add. */
char *case_buf = mbtolower (buf, &size);
- if (start_ptr)
- start_ptr = case_buf + (start_ptr - buf);
+ if (start_ptr)
+ start_ptr = case_buf + (start_ptr - buf);
buf = case_buf;
}
}
@@ -230,155 +230,155 @@ EGexecute (char const *buf, size_t size, size_t *match_size,
for (beg = end = buf; end < buflim; beg = end)
{
if (!start_ptr)
- {
- /* We don't care about an exact match. */
- if (kwset)
- {
- /* Find a possible match using the KWset matcher. */
- size_t offset = kwsexec (kwset, beg, buflim - beg, &kwsm);
- if (offset == (size_t) -1)
- goto failure;
- beg += offset;
- /* Narrow down to the line containing the candidate, and
- run it through DFA. */
- if ((end = memchr(beg, eol, buflim - beg)) != NULL)
- end++;
+ {
+ /* We don't care about an exact match. */
+ if (kwset)
+ {
+ /* Find a possible match using the KWset matcher. */
+ size_t offset = kwsexec (kwset, beg, buflim - beg, &kwsm);
+ if (offset == (size_t) -1)
+ goto failure;
+ beg += offset;
+ /* Narrow down to the line containing the candidate, and
+ run it through DFA. */
+ if ((end = memchr(beg, eol, buflim - beg)) != NULL)
+ end++;
else
end = buflim;
- match = beg;
- while (beg > buf && beg[-1] != eol)
- --beg;
- if (kwsm.index < kwset_exact_matches)
+ match = beg;
+ while (beg > buf && beg[-1] != eol)
+ --beg;
+ if (kwsm.index < kwset_exact_matches)
{
#if MBS_SUPPORT
if (mb_start < beg)
mb_start = beg;
if (MB_CUR_MAX == 1
- || !is_mb_middle (&mb_start, match, buflim,
- kwsm.size[0]))
+ || !is_mb_middle (&mb_start, match, buflim,
+ kwsm.size[0]))
#endif
goto success;
}
- if (dfaexec (dfa, beg, (char *) end, 0, NULL, &backref) == NULL)
- continue;
- }
- else
- {
- /* No good fixed strings; start with DFA. */
- char const *next_beg = dfaexec (dfa, beg, (char *) buflim,
- 0, NULL, &backref);
- if (next_beg == NULL)
- break;
- /* Narrow down to the line we've found. */
- beg = next_beg;
- if ((end = memchr(beg, eol, buflim - beg)) != NULL)
- end++;
+ if (dfaexec (dfa, beg, (char *) end, 0, NULL, &backref) == NULL)
+ continue;
+ }
+ else
+ {
+ /* No good fixed strings; start with DFA. */
+ char const *next_beg = dfaexec (dfa, beg, (char *) buflim,
+ 0, NULL, &backref);
+ if (next_beg == NULL)
+ break;
+ /* Narrow down to the line we've found. */
+ beg = next_beg;
+ if ((end = memchr(beg, eol, buflim - beg)) != NULL)
+ end++;
else
end = buflim;
- while (beg > buf && beg[-1] != eol)
- --beg;
- }
- /* Successful, no backreferences encountered! */
- if (!backref)
- goto success;
- }
+ while (beg > buf && beg[-1] != eol)
+ --beg;
+ }
+ /* Successful, no backreferences encountered! */
+ if (!backref)
+ goto success;
+ }
else
- {
- /* We are looking for the leftmost (then longest) exact match.
- We will go through the outer loop only once. */
- beg = start_ptr;
- end = buflim;
- }
+ {
+ /* We are looking for the leftmost (then longest) exact match.
+ We will go through the outer loop only once. */
+ beg = start_ptr;
+ end = buflim;
+ }
/* If we've made it to this point, this means DFA has seen
- a probable match, and we need to run it through Regex. */
+ a probable match, and we need to run it through Regex. */
best_match = end;
best_len = 0;
for (i = 0; i < pcount; i++)
- {
- patterns[i].regexbuf.not_eol = 0;
- if (0 <= (start = re_search (&(patterns[i].regexbuf),
- buf, end - buf - 1,
- beg - buf, end - beg - 1,
- &(patterns[i].regs))))
- {
- len = patterns[i].regs.end[0] - start;
- match = buf + start;
- if (match > best_match)
- continue;
- if (start_ptr && !match_words)
- goto assess_pattern_match;
- if ((!match_lines && !match_words)
- || (match_lines && len == end - beg - 1))
- {
- match = beg;
- len = end - beg;
- goto assess_pattern_match;
- }
- /* If -w, check if the match aligns with word boundaries.
- We do this iteratively because:
- (a) the line may contain more than one occurence of the
- pattern, and
- (b) Several alternatives in the pattern might be valid at a
- given point, and we may need to consider a shorter one to
- find a word boundary. */
- if (match_words)
- while (match <= best_match)
- {
- if ((match == buf || !WCHAR ((unsigned char) match[-1]))
- && (len == end - beg - 1
- || !WCHAR ((unsigned char) match[len])))
- goto assess_pattern_match;
- if (len > 0)
- {
- /* Try a shorter length anchored at the same place. */
- --len;
- patterns[i].regexbuf.not_eol = 1;
- len = re_match (&(patterns[i].regexbuf),
- buf, match + len - beg, match - buf,
- &(patterns[i].regs));
- }
- if (len <= 0)
- {
- /* Try looking further on. */
- if (match == end - 1)
- break;
- match++;
- patterns[i].regexbuf.not_eol = 0;
- start = re_search (&(patterns[i].regexbuf),
- buf, end - buf - 1,
- match - buf, end - match - 1,
- &(patterns[i].regs));
- if (start < 0)
- break;
- len = patterns[i].regs.end[0] - start;
- match = buf + start;
- }
- } /* while (match <= best_match) */
- continue;
- assess_pattern_match:
- if (!start_ptr)
- {
- /* Good enough for a non-exact match.
- No need to look at further patterns, if any. */
- goto success;
- }
- if (match < best_match || (match == best_match && len > best_len))
- {
- /* Best exact match: leftmost, then longest. */
- best_match = match;
- best_len = len;
- }
- } /* if re_search >= 0 */
- } /* for Regex patterns. */
- if (best_match < end)
- {
- /* We have found an exact match. We were just
- waiting for the best one (leftmost then longest). */
- beg = best_match;
- len = best_len;
- goto success_in_len;
- }
+ {
+ patterns[i].regexbuf.not_eol = 0;
+ if (0 <= (start = re_search (&(patterns[i].regexbuf),
+ buf, end - buf - 1,
+ beg - buf, end - beg - 1,
+ &(patterns[i].regs))))
+ {
+ len = patterns[i].regs.end[0] - start;
+ match = buf + start;
+ if (match > best_match)
+ continue;
+ if (start_ptr && !match_words)
+ goto assess_pattern_match;
+ if ((!match_lines && !match_words)
+ || (match_lines && len == end - beg - 1))
+ {
+ match = beg;
+ len = end - beg;
+ goto assess_pattern_match;
+ }
+ /* If -w, check if the match aligns with word boundaries.
+ We do this iteratively because:
+ (a) the line may contain more than one occurence of the
+ pattern, and
+ (b) Several alternatives in the pattern might be valid at a
+ given point, and we may need to consider a shorter one to
+ find a word boundary. */
+ if (match_words)
+ while (match <= best_match)
+ {
+ if ((match == buf || !WCHAR ((unsigned char) match[-1]))
+ && (len == end - beg - 1
+ || !WCHAR ((unsigned char) match[len])))
+ goto assess_pattern_match;
+ if (len > 0)
+ {
+ /* Try a shorter length anchored at the same place. */
+ --len;
+ patterns[i].regexbuf.not_eol = 1;
+ len = re_match (&(patterns[i].regexbuf),
+ buf, match + len - beg, match - buf,
+ &(patterns[i].regs));
+ }
+ if (len <= 0)
+ {
+ /* Try looking further on. */
+ if (match == end - 1)
+ break;
+ match++;
+ patterns[i].regexbuf.not_eol = 0;
+ start = re_search (&(patterns[i].regexbuf),
+ buf, end - buf - 1,
+ match - buf, end - match - 1,
+ &(patterns[i].regs));
+ if (start < 0)
+ break;
+ len = patterns[i].regs.end[0] - start;
+ match = buf + start;
+ }
+ } /* while (match <= best_match) */
+ continue;
+ assess_pattern_match:
+ if (!start_ptr)
+ {
+ /* Good enough for a non-exact match.
+ No need to look at further patterns, if any. */
+ goto success;
+ }
+ if (match < best_match || (match == best_match && len > best_len))
+ {
+ /* Best exact match: leftmost, then longest. */
+ best_match = match;
+ best_len = len;
+ }
+ } /* if re_search >= 0 */
+ } /* for Regex patterns. */
+ if (best_match < end)
+ {
+ /* We have found an exact match. We were just
+ waiting for the best one (leftmost then longest). */
+ beg = best_match;
+ len = best_len;
+ goto success_in_len;
+ }
} /* for (beg = end ..) */
failure:
diff --git a/src/dosbuf.c b/src/dosbuf.c
index dc22682f..a4fbc574 100644
--- a/src/dosbuf.c
+++ b/src/dosbuf.c
@@ -125,8 +125,8 @@ undossify_input (char *buf, size_t buflen)
{
dos_pos_map_size = inp_map_idx ? inp_map_idx * 2 : 1000;
dos_pos_map = xrealloc((char *)dos_pos_map,
- dos_pos_map_size *
- sizeof(struct dos_map));
+ dos_pos_map_size *
+ sizeof(struct dos_map));
}
if (!inp_map_idx)
diff --git a/src/grep.c b/src/grep.c
index 1a4166c1..7b30f66a 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -5,9 +5,9 @@ static void
Gcompile (char const *pattern, size_t size)
{
GEAcompile (pattern, size,
- RE_SYNTAX_GREP
- | RE_HAT_LISTS_NOT_NEWLINE
- | RE_NO_EMPTY_RANGES);
+ RE_SYNTAX_GREP
+ | RE_HAT_LISTS_NOT_NEWLINE
+ | RE_NO_EMPTY_RANGES);
}
static void
diff --git a/src/kwsearch.c b/src/kwsearch.c
index 1da66238..b03ff0cd 100644
--- a/src/kwsearch.c
+++ b/src/kwsearch.c
@@ -48,26 +48,26 @@ Fcompile (char const *pattern, size_t size)
do
{
for (lim = beg;; ++lim)
- {
- end = lim;
- if (lim >= pat + psize)
- break;
- if (*lim == '\n')
- {
- lim++;
- break;
- }
+ {
+ end = lim;
+ if (lim >= pat + psize)
+ break;
+ if (*lim == '\n')
+ {
+ lim++;
+ break;
+ }
#if HAVE_DOS_FILE_CONTENTS
- if (*lim == '\r' && lim + 1 < pat + psize && lim[1] == '\n')
- {
- lim += 2;
- break;
- }
+ if (*lim == '\r' && lim + 1 < pat + psize && lim[1] == '\n')
+ {
+ lim += 2;
+ break;
+ }
#endif
- }
+ }
if ((err = kwsincr (kwset, beg, end - beg)) != NULL)
- error (EXIT_TROUBLE, 0, "%s", err);
+ error (EXIT_TROUBLE, 0, "%s", err);
beg = lim;
}
while (beg < pat + psize);
@@ -78,7 +78,7 @@ Fcompile (char const *pattern, size_t size)
size_t
Fexecute (char const *buf, size_t size, size_t *match_size,
- char const *start_ptr)
+ char const *start_ptr)
{
char const *beg, *try, *end, *mb_start;
size_t len;
@@ -91,8 +91,8 @@ Fexecute (char const *buf, size_t size, size_t *match_size,
if (match_icase)
{
char *case_buf = mbtolower (buf, &size);
- if (start_ptr)
- start_ptr = case_buf + (start_ptr - buf);
+ if (start_ptr)
+ start_ptr = case_buf + (start_ptr - buf);
buf = case_buf;
}
}
@@ -102,11 +102,11 @@ Fexecute (char const *buf, size_t size, size_t *match_size,
{
size_t offset = kwsexec (kwset, beg, buf + size - beg, &kwsmatch);
if (offset == (size_t) -1)
- goto failure;
+ goto failure;
len = kwsmatch.size[0];
#if MBS_SUPPORT
if (MB_CUR_MAX > 1 && is_mb_middle (&mb_start, beg + offset, buf + size,
- len))
+ len))
{
/* The match was a part of multibyte character, advance at least
one byte to ensure no infinite loop happens. */
@@ -123,35 +123,35 @@ Fexecute (char const *buf, size_t size, size_t *match_size,
#endif /* MBS_SUPPORT */
beg += offset;
if (start_ptr && !match_words)
- goto success_in_beg_and_len;
+ goto success_in_beg_and_len;
if (match_lines)
- {
- if (beg > buf && beg[-1] != eol)
- continue;
- if (beg + len < buf + size && beg[len] != eol)
- continue;
- goto success;
- }
+ {
+ if (beg > buf && beg[-1] != eol)
+ continue;
+ if (beg + len < buf + size && beg[len] != eol)
+ continue;
+ goto success;
+ }
else if (match_words)
- for (try = beg; len; )
- {
- if (try > buf && WCHAR((unsigned char) try[-1]))
- break;
- if (try + len < buf + size && WCHAR((unsigned char) try[len]))
- {
- offset = kwsexec (kwset, beg, --len, &kwsmatch);
- if (offset == (size_t) -1)
- break;
- try = beg + offset;
- len = kwsmatch.size[0];
- }
- else if (!start_ptr)
- goto success;
- else
- goto success_in_beg_and_len;
- } /* for (try) */
+ for (try = beg; len; )
+ {
+ if (try > buf && WCHAR((unsigned char) try[-1]))
+ break;
+ if (try + len < buf + size && WCHAR((unsigned char) try[len]))
+ {
+ offset = kwsexec (kwset, beg, --len, &kwsmatch);
+ if (offset == (size_t) -1)
+ break;
+ try = beg + offset;
+ len = kwsmatch.size[0];
+ }
+ else if (!start_ptr)
+ goto success;
+ else
+ goto success_in_beg_and_len;
+ } /* for (try) */
else
- goto success;
+ goto success;
} /* for (beg in buf) */
failure:
diff --git a/src/kwset.c b/src/kwset.c
index 995be79f..d85fa309 100644
--- a/src/kwset.c
+++ b/src/kwset.c
@@ -151,122 +151,122 @@ kwsincr (kwset_t kws, char const *text, size_t len)
label = kwset->trans ? kwset->trans[U(*--text)] : *--text;
/* Descend the tree of outgoing links for this trie node,
- looking for the current character and keeping track
- of the path followed. */
+ looking for the current character and keeping track
+ of the path followed. */
link = trie->links;
links[0] = (struct tree *) &trie->links;
dirs[0] = L;
depth = 1;
while (link && label != link->label)
- {
- links[depth] = link;
- if (label < link->label)
- dirs[depth++] = L, link = link->llink;
- else
- dirs[depth++] = R, link = link->rlink;
- }
+ {
+ links[depth] = link;
+ if (label < link->label)
+ dirs[depth++] = L, link = link->llink;
+ else
+ dirs[depth++] = R, link = link->rlink;
+ }
/* The current character doesn't have an outgoing link at
- this trie node, so build a new trie node and install
- a link in the current trie node's tree. */
+ this trie node, so build a new trie node and install
+ a link in the current trie node's tree. */
if (!link)
- {
- link = (struct tree *) obstack_alloc(&kwset->obstack,
- sizeof (struct tree));
- if (!link)
- return _("memory exhausted");
- link->llink = NULL;
- link->rlink = NULL;
- link->trie = (struct trie *) obstack_alloc(&kwset->obstack,
- sizeof (struct trie));
- if (!link->trie)
- {
- obstack_free(&kwset->obstack, link);
- return _("memory exhausted");
- }
- link->trie->accepting = 0;
- link->trie->links = NULL;
- link->trie->parent = trie;
- link->trie->next = NULL;
- link->trie->fail = NULL;
- link->trie->depth = trie->depth + 1;
- link->trie->shift = 0;
- link->label = label;
- link->balance = 0;
-
- /* Install the new tree node in its parent. */
- if (dirs[--depth] == L)
- links[depth]->llink = link;
- else
- links[depth]->rlink = link;
-
- /* Back up the tree fixing the balance flags. */
- while (depth && !links[depth]->balance)
- {
- if (dirs[depth] == L)
- --links[depth]->balance;
- else
- ++links[depth]->balance;
- --depth;
- }
-
- /* Rebalance the tree by pointer rotations if necessary. */
- if (depth && ((dirs[depth] == L && --links[depth]->balance)
- || (dirs[depth] == R && ++links[depth]->balance)))
- {
- switch (links[depth]->balance)
- {
- case (char) -2:
- switch (dirs[depth + 1])
- {
- case L:
- r = links[depth], t = r->llink, rl = t->rlink;
- t->rlink = r, r->llink = rl;
- t->balance = r->balance = 0;
- break;
- case R:
- r = links[depth], l = r->llink, t = l->rlink;
- rl = t->rlink, lr = t->llink;
- t->llink = l, l->rlink = lr, t->rlink = r, r->llink = rl;
- l->balance = t->balance != 1 ? 0 : -1;
- r->balance = t->balance != (char) -1 ? 0 : 1;
- t->balance = 0;
- break;
- default:
- abort ();
- }
- break;
- case 2:
- switch (dirs[depth + 1])
- {
- case R:
- l = links[depth], t = l->rlink, lr = t->llink;
- t->llink = l, l->rlink = lr;
- t->balance = l->balance = 0;
- break;
- case L:
- l = links[depth], r = l->rlink, t = r->llink;
- lr = t->llink, rl = t->rlink;
- t->llink = l, l->rlink = lr, t->rlink = r, r->llink = rl;
- l->balance = t->balance != 1 ? 0 : -1;
- r->balance = t->balance != (char) -1 ? 0 : 1;
- t->balance = 0;
- break;
- default:
- abort ();
- }
- break;
- default:
- abort ();
- }
-
- if (dirs[depth - 1] == L)
- links[depth - 1]->llink = t;
- else
- links[depth - 1]->rlink = t;
- }
- }
+ {
+ link = (struct tree *) obstack_alloc(&kwset->obstack,
+ sizeof (struct tree));
+ if (!link)
+ return _("memory exhausted");
+ link->llink = NULL;
+ link->rlink = NULL;
+ link->trie = (struct trie *) obstack_alloc(&kwset->obstack,
+ sizeof (struct trie));
+ if (!link->trie)
+ {
+ obstack_free(&kwset->obstack, link);
+ return _("memory exhausted");
+ }
+ link->trie->accepting = 0;
+ link->trie->links = NULL;
+ link->trie->parent = trie;
+ link->trie->next = NULL;
+ link->trie->fail = NULL;
+ link->trie->depth = trie->depth + 1;
+ link->trie->shift = 0;
+ link->label = label;
+ link->balance = 0;
+
+ /* Install the new tree node in its parent. */
+ if (dirs[--depth] == L)
+ links[depth]->llink = link;
+ else
+ links[depth]->rlink = link;
+
+ /* Back up the tree fixing the balance flags. */
+ while (depth && !links[depth]->balance)
+ {
+ if (dirs[depth] == L)
+ --links[depth]->balance;
+ else
+ ++links[depth]->balance;
+ --depth;
+ }
+
+ /* Rebalance the tree by pointer rotations if necessary. */
+ if (depth && ((dirs[depth] == L && --links[depth]->balance)
+ || (dirs[depth] == R && ++links[depth]->balance)))
+ {
+ switch (links[depth]->balance)
+ {
+ case (char) -2:
+ switch (dirs[depth + 1])
+ {
+ case L:
+ r = links[depth], t = r->llink, rl = t->rlink;
+ t->rlink = r, r->llink = rl;
+ t->balance = r->balance = 0;
+ break;
+ case R:
+ r = links[depth], l = r->llink, t = l->rlink;
+ rl = t->rlink, lr = t->llink;
+ t->llink = l, l->rlink = lr, t->rlink = r, r->llink = rl;
+ l->balance = t->balance != 1 ? 0 : -1;
+ r->balance = t->balance != (char) -1 ? 0 : 1;
+ t->balance = 0;
+ break;
+ default:
+ abort ();
+ }
+ break;
+ case 2:
+ switch (dirs[depth + 1])
+ {
+ case R:
+ l = links[depth], t = l->rlink, lr = t->llink;
+ t->llink = l, l->rlink = lr;
+ t->balance = l->balance = 0;
+ break;
+ case L:
+ l = links[depth], r = l->rlink, t = r->llink;
+ lr = t->llink, rl = t->rlink;
+ t->llink = l, l->rlink = lr, t->rlink = r, r->llink = rl;
+ l->balance = t->balance != 1 ? 0 : -1;
+ r->balance = t->balance != (char) -1 ? 0 : 1;
+ t->balance = 0;
+ break;
+ default:
+ abort ();
+ }
+ break;
+ default:
+ abort ();
+ }
+
+ if (dirs[depth - 1] == L)
+ links[depth - 1]->llink = t;
+ else
+ links[depth - 1]->rlink = t;
+ }
+ }
trie = link->trie;
}
@@ -303,7 +303,7 @@ enqueue (struct tree *tree, struct trie **last)
well as a last resort failure node. */
static void
treefails (struct tree const *tree, struct trie const *fail,
- struct trie *recourse)
+ struct trie *recourse)
{
struct tree *link;
@@ -319,15 +319,15 @@ treefails (struct tree const *tree, struct trie const *fail,
{
link = fail->links;
while (link && tree->label != link->label)
- if (tree->label < link->label)
- link = link->llink;
- else
- link = link->rlink;
+ if (tree->label < link->label)
+ link = link->llink;
+ else
+ link = link->rlink;
if (link)
- {
- tree->trie->fail = link->trie;
- return;
- }
+ {
+ tree->trie->fail = link->trie;
+ return;
+ }
fail = fail->fail;
}
@@ -338,8 +338,8 @@ treefails (struct tree const *tree, struct trie const *fail,
the preexisting delta value is larger than the current depth. */
static void
treedelta (struct tree const *tree,
- unsigned int depth,
- unsigned char delta[])
+ unsigned int depth,
+ unsigned char delta[])
{
if (!tree)
return;
@@ -406,21 +406,21 @@ kwsprep (kwset_t kws)
/* Looking for just one string. Extract it from the trie. */
kwset->target = obstack_alloc(&kwset->obstack, kwset->mind);
if (!kwset->target)
- return _("memory exhausted");
+ return _("memory exhausted");
for (i = kwset->mind - 1, curr = kwset->trie; i >= 0; --i)
- {
- kwset->target[i] = curr->links->label;
- curr = curr->links->trie;
- }
+ {
+ kwset->target[i] = curr->links->label;
+ curr = curr->links->trie;
+ }
/* Build the Boyer Moore delta. Boy that's easy compared to CW. */
for (i = 0; i < kwset->mind; ++i)
- delta[U(kwset->target[i])] = kwset->mind - (i + 1);
+ delta[U(kwset->target[i])] = kwset->mind - (i + 1);
/* Find the minimal delta2 shift that we might make after
- a backwards match has failed. */
+ a backwards match has failed. */
c = kwset->target[kwset->mind - 1];
for (i = kwset->mind - 2; i >= 0; --i)
- if (kwset->target[i] == c)
- break;
+ if (kwset->target[i] == c)
+ break;
kwset->mind2 = kwset->mind - (i + 1);
}
else
@@ -429,61 +429,61 @@ kwsprep (kwset_t kws)
struct trie *last, *next[NCHAR];
/* Traverse the nodes of the trie in level order, simultaneously
- computing the delta table, failure function, and shift function. */
+ computing the delta table, failure function, and shift function. */
for (curr = last = kwset->trie; curr; curr = curr->next)
- {
- /* Enqueue the immediate descendents in the level order queue. */
- enqueue(curr->links, &last);
-
- curr->shift = kwset->mind;
- curr->maxshift = kwset->mind;
-
- /* Update the delta table for the descendents of this node. */
- treedelta(curr->links, curr->depth, delta);
-
- /* Compute the failure function for the decendents of this node. */
- treefails(curr->links, curr->fail, kwset->trie);
-
- /* Update the shifts at each node in the current node's chain
- of fails back to the root. */
- for (fail = curr->fail; fail; fail = fail->fail)
- {
- /* If the current node has some outgoing edge that the fail
- doesn't, then the shift at the fail should be no larger
- than the difference of their depths. */
- if (!hasevery(fail->links, curr->links))
- if (curr->depth - fail->depth < fail->shift)
- fail->shift = curr->depth - fail->depth;
-
- /* If the current node is accepting then the shift at the
- fail and its descendents should be no larger than the
- difference of their depths. */
- if (curr->accepting && fail->maxshift > curr->depth - fail->depth)
- fail->maxshift = curr->depth - fail->depth;
- }
- }
+ {
+ /* Enqueue the immediate descendents in the level order queue. */
+ enqueue(curr->links, &last);
+
+ curr->shift = kwset->mind;
+ curr->maxshift = kwset->mind;
+
+ /* Update the delta table for the descendents of this node. */
+ treedelta(curr->links, curr->depth, delta);
+
+ /* Compute the failure function for the decendents of this node. */
+ treefails(curr->links, curr->fail, kwset->trie);
+
+ /* Update the shifts at each node in the current node's chain
+ of fails back to the root. */
+ for (fail = curr->fail; fail; fail = fail->fail)
+ {
+ /* If the current node has some outgoing edge that the fail
+ doesn't, then the shift at the fail should be no larger
+ than the difference of their depths. */
+ if (!hasevery(fail->links, curr->links))
+ if (curr->depth - fail->depth < fail->shift)
+ fail->shift = curr->depth - fail->depth;
+
+ /* If the current node is accepting then the shift at the
+ fail and its descendents should be no larger than the
+ difference of their depths. */
+ if (curr->accepting && fail->maxshift > curr->depth - fail->depth)
+ fail->maxshift = curr->depth - fail->depth;
+ }
+ }
/* Traverse the trie in level order again, fixing up all nodes whose
- shift exceeds their inherited maxshift. */
+ shift exceeds their inherited maxshift. */
for (curr = kwset->trie->next; curr; curr = curr->next)
- {
- if (curr->maxshift > curr->parent->maxshift)
- curr->maxshift = curr->parent->maxshift;
- if (curr->shift > curr->maxshift)
- curr->shift = curr->maxshift;
- }
+ {
+ if (curr->maxshift > curr->parent->maxshift)
+ curr->maxshift = curr->parent->maxshift;
+ if (curr->shift > curr->maxshift)
+ curr->shift = curr->maxshift;
+ }
/* Create a vector, indexed by character code, of the outgoing links
- from the root node. */
+ from the root node. */
for (i = 0; i < NCHAR; ++i)
- next[i] = NULL;
+ next[i] = NULL;
treenext(kwset->trie->links, next);
if ((trans = kwset->trans) != NULL)
- for (i = 0; i < NCHAR; ++i)
- kwset->next[i] = next[U(trans[i])];
+ for (i = 0; i < NCHAR; ++i)
+ kwset->next[i] = next[U(trans[i])];
else
- memcpy(kwset->next, next, NCHAR * sizeof(struct trie *));
+ memcpy(kwset->next, next, NCHAR * sizeof(struct trie *));
}
/* Fix things up for any translation table. */
@@ -529,35 +529,35 @@ bmexec (kwset_t kws, char const *text, size_t size)
/* 11 is not a bug, the initial offset happens only once. */
for (ep = text + size - 11 * len;;)
{
- while (tp <= ep)
- {
- d = d1[U(tp[-1])], tp += d;
- d = d1[U(tp[-1])], tp += d;
- if (d == 0)
- goto found;
- d = d1[U(tp[-1])], tp += d;
- d = d1[U(tp[-1])], tp += d;
- d = d1[U(tp[-1])], tp += d;
- if (d == 0)
- goto found;
- d = d1[U(tp[-1])], tp += d;
- d = d1[U(tp[-1])], tp += d;
- d = d1[U(tp[-1])], tp += d;
- if (d == 0)
- goto found;
- d = d1[U(tp[-1])], tp += d;
- d = d1[U(tp[-1])], tp += d;
- }
- break;
+ while (tp <= ep)
+ {
+ d = d1[U(tp[-1])], tp += d;
+ d = d1[U(tp[-1])], tp += d;
+ if (d == 0)
+ goto found;
+ d = d1[U(tp[-1])], tp += d;
+ d = d1[U(tp[-1])], tp += d;
+ d = d1[U(tp[-1])], tp += d;
+ if (d == 0)
+ goto found;
+ d = d1[U(tp[-1])], tp += d;
+ d = d1[U(tp[-1])], tp += d;
+ d = d1[U(tp[-1])], tp += d;
+ if (d == 0)
+ goto found;
+ d = d1[U(tp[-1])], tp += d;
+ d = d1[U(tp[-1])], tp += d;
+ }
+ break;
found:
- if (U(tp[-2]) == gc)
- {
- for (i = 3; i <= len && U(tp[-i]) == U(sp[-i]); ++i)
- ;
- if (i > len)
- return tp - len - text;
- }
- tp += md2;
+ if (U(tp[-2]) == gc)
+ {
+ for (i = 3; i <= len && U(tp[-i]) == U(sp[-i]); ++i)
+ ;
+ if (i > len)
+ return tp - len - text;
+ }
+ tp += md2;
}
/* Now we have only a few characters left to search. We
@@ -568,14 +568,14 @@ bmexec (kwset_t kws, char const *text, size_t size)
{
d = d1[U((tp += d)[-1])];
if (d != 0)
- continue;
+ continue;
if (U(tp[-2]) == gc)
- {
- for (i = 3; i <= len && U(tp[-i]) == U(sp[-i]); ++i)
- ;
- if (i > len)
- return tp - len - text;
- }
+ {
+ for (i = 3; i <= len && U(tp[-i]) == U(sp[-i]); ++i)
+ ;
+ if (i > len)
+ return tp - len - text;
+ }
d = md2;
}
@@ -627,52 +627,52 @@ cwexec (kwset_t kws, char const *text, size_t len, struct kwsmatch *kwsmatch)
while (lim - end >= d)
{
if (qlim && end <= qlim)
- {
- end += d - 1;
- while ((d = delta[c = *end]) && end < qlim)
- {
- end += d;
- end += delta[U(*end)];
- end += delta[U(*end)];
- }
- ++end;
- }
+ {
+ end += d - 1;
+ while ((d = delta[c = *end]) && end < qlim)
+ {
+ end += d;
+ end += delta[U(*end)];
+ end += delta[U(*end)];
+ }
+ ++end;
+ }
else
- d = delta[c = (end += d)[-1]];
+ d = delta[c = (end += d)[-1]];
if (d)
- continue;
+ continue;
beg = end - 1;
trie = next[c];
if (trie->accepting)
- {
- mch = beg;
- accept = trie;
- }
+ {
+ mch = beg;
+ accept = trie;
+ }
d = trie->shift;
while (beg > text)
- {
- c = trans ? trans[U(*--beg)] : *--beg;
- tree = trie->links;
- while (tree && c != tree->label)
- if (c < tree->label)
- tree = tree->llink;
- else
- tree = tree->rlink;
- if (tree)
- {
- trie = tree->trie;
- if (trie->accepting)
- {
- mch = beg;
- accept = trie;
- }
- }
- else
- break;
- d = trie->shift;
- }
+ {
+ c = trans ? trans[U(*--beg)] : *--beg;
+ tree = trie->links;
+ while (tree && c != tree->label)
+ if (c < tree->label)
+ tree = tree->llink;
+ else
+ tree = tree->rlink;
+ if (tree)
+ {
+ trie = tree->trie;
+ if (trie->accepting)
+ {
+ mch = beg;
+ accept = trie;
+ }
+ }
+ else
+ break;
+ d = trie->shift;
+ }
if (mch)
- goto match;
+ goto match;
}
return -1;
@@ -687,48 +687,48 @@ cwexec (kwset_t kws, char const *text, size_t len, struct kwsmatch *kwsmatch)
while (lim - end >= d)
{
if ((d = delta[c = (end += d)[-1]]) != 0)
- continue;
+ continue;
beg = end - 1;
if (!(trie = next[c]))
- {
- d = 1;
- continue;
- }
+ {
+ d = 1;
+ continue;
+ }
if (trie->accepting && beg <= mch)
- {
- lmch = beg;
- accept = trie;
- }
+ {
+ lmch = beg;
+ accept = trie;
+ }
d = trie->shift;
while (beg > text)
- {
- c = trans ? trans[U(*--beg)] : *--beg;
- tree = trie->links;
- while (tree && c != tree->label)
- if (c < tree->label)
- tree = tree->llink;
- else
- tree = tree->rlink;
- if (tree)
- {
- trie = tree->trie;
- if (trie->accepting && beg <= mch)
- {
- lmch = beg;
- accept = trie;
- }
- }
- else
- break;
- d = trie->shift;
- }
+ {
+ c = trans ? trans[U(*--beg)] : *--beg;
+ tree = trie->links;
+ while (tree && c != tree->label)
+ if (c < tree->label)
+ tree = tree->llink;
+ else
+ tree = tree->rlink;
+ if (tree)
+ {
+ trie = tree->trie;
+ if (trie->accepting && beg <= mch)
+ {
+ lmch = beg;
+ accept = trie;
+ }
+ }
+ else
+ break;
+ d = trie->shift;
+ }
if (lmch)
- {
- mch = lmch;
- goto match;
- }
+ {
+ mch = lmch;
+ goto match;
+ }
if (!d)
- d = 1;
+ d = 1;
}
kwsmatch->index = accept->accepting / 2;
@@ -751,11 +751,11 @@ kwsexec (kwset_t kws, char const *text, size_t size, struct kwsmatch *kwsmatch)
{
size_t ret = bmexec (kws, text, size);
if (ret != (size_t) -1)
- {
- kwsmatch->index = 0;
- kwsmatch->offset[0] = ret;
- kwsmatch->size[0] = kwset->mind;
- }
+ {
+ kwsmatch->index = 0;
+ kwsmatch->offset[0] = ret;
+ kwsmatch->size[0] = kwset->mind;
+ }
return ret;
}
else
diff --git a/src/main.c b/src/main.c
index ddb1413a..aa3819cc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -86,45 +86,45 @@ static const char *group_separator = SEP_STR_GROUP;
/* The context and logic for choosing default --color screen attributes
(foreground and background colors, etc.) are the following.
-- There are eight basic colors available, each with its own
- nominal luminosity to the human eye and foreground/background
- codes (black [0 %, 30/40], blue [11 %, 34/44], red [30 %, 31/41],
- magenta [41 %, 35/45], green [59 %, 32/42], cyan [70 %, 36/46],
- yellow [89 %, 33/43], and white [100 %, 37/47]).
+ nominal luminosity to the human eye and foreground/background
+ codes (black [0 %, 30/40], blue [11 %, 34/44], red [30 %, 31/41],
+ magenta [41 %, 35/45], green [59 %, 32/42], cyan [70 %, 36/46],
+ yellow [89 %, 33/43], and white [100 %, 37/47]).
-- Sometimes, white as a background is actually implemented using
- a shade of light gray, so that a foreground white can be visible
- on top of it (but most often not).
+ a shade of light gray, so that a foreground white can be visible
+ on top of it (but most often not).
-- Sometimes, black as a foreground is actually implemented using
- a shade of dark gray, so that it can be visible on top of a
- background black (but most often not).
+ a shade of dark gray, so that it can be visible on top of a
+ background black (but most often not).
-- Sometimes, more colors are available, as extensions.
-- Other attributes can be selected/deselected (bold [1/22],
- underline [4/24], standout/inverse [7/27], blink [5/25], and
- invisible/hidden [8/28]). They are sometimes implemented by
- using colors instead of what their names imply; e.g., bold is
- often achieved by using brighter colors. In practice, only bold
- is really available to us, underline sometimes being mapped by
- the terminal to some strange color choice, and standout best
- being left for use by downstream programs such as less(1).
+ underline [4/24], standout/inverse [7/27], blink [5/25], and
+ invisible/hidden [8/28]). They are sometimes implemented by
+ using colors instead of what their names imply; e.g., bold is
+ often achieved by using brighter colors. In practice, only bold
+ is really available to us, underline sometimes being mapped by
+ the terminal to some strange color choice, and standout best
+ being left for use by downstream programs such as less(1).
-- We cannot assume that any of the extensions or special features
- are available for the purpose of choosing defaults for everyone.
+ are available for the purpose of choosing defaults for everyone.
-- The most prevalent default terminal backgrounds are pure black
- and pure white, and are not necessarily the same shades of
- those as if they were selected explicitly with SGR sequences.
- Some terminals use dark or light pictures as default background,
- but those are covered over by an explicit selection of background
- color with an SGR sequence; their users will appreciate their
- background pictures not be covered like this, if possible.
+ and pure white, and are not necessarily the same shades of
+ those as if they were selected explicitly with SGR sequences.
+ Some terminals use dark or light pictures as default background,
+ but those are covered over by an explicit selection of background
+ color with an SGR sequence; their users will appreciate their
+ background pictures not be covered like this, if possible.
-- Some uses of colors attributes is to make some output items
- more understated (e.g., context lines); this cannot be achieved
- by changing the background color.
+ more understated (e.g., context lines); this cannot be achieved
+ by changing the background color.
-- For these reasons, the grep color defaults should strive not
- to change the background color from its default, unless it's
- for a short item that should be highlighted, not understated.
+ to change the background color from its default, unless it's
+ for a short item that should be highlighted, not understated.
-- The grep foreground color defaults (without an explicitly set
- background) should provide enough contrast to be readable on any
- terminal with either a black (dark) or white (light) background.
- This only leaves red, magenta, green, and cyan (and their bold
- counterparts) and possibly bold blue. */
+ background) should provide enough contrast to be readable on any
+ terminal with either a black (dark) or white (light) background.
+ This only leaves red, magenta, green, and cyan (and their bold
+ counterparts) and possibly bold blue. */
/* The color strings used for matched text.
The user can overwrite them using the deprecated
environment variable GREP_COLOR or the new GREP_COLORS. */
@@ -142,54 +142,54 @@ static const char *context_line_color = ""; /* default color pair */
/* Select Graphic Rendition (SGR, "\33[...m") strings. */
/* Also Erase in Line (EL) to Right ("\33[K") by default. */
/* Why have EL to Right after SGR?
- -- The behavior of line-wrapping when at the bottom of the
- terminal screen and at the end of the current line is often
- such that a new line is introduced, entirely cleared with
- the current background color which may be different from the
- default one (see the boolean back_color_erase terminfo(5)
- capability), thus scrolling the display by one line.
- The end of this new line will stay in this background color
- even after reverting to the default background color with
- "\33[m', unless it is explicitly cleared again with "\33[K"
- (which is the behavior the user would instinctively expect
- from the whole thing). There may be some unavoidable
- background-color flicker at the end of this new line because
- of this (when timing with the monitor's redraw is just right).
- -- The behavior of HT (tab, "\t") is usually the same as that of
- Cursor Forward Tabulation (CHT) with a default parameter
- of 1 ("\33[I"), i.e., it performs pure movement to the next
- tab stop, without any clearing of either content or screen
- attributes (including background color); try
- printf 'asdfqwerzxcv\rASDF\tZXCV\n'
- in a bash(1) shell to demonstrate this. This is not what the
- user would instinctively expect of HT (but is ok for CHT).
- The instinctive behavior would include clearing the terminal
- cells that are skipped over by HT with blank cells in the
- current screen attributes, including background color;
- the boolean dest_tabs_magic_smso terminfo(5) capability
- indicates this saner behavior for HT, but only some rare
- terminals have it (although it also indicates a special
- glitch with standout mode in the Teleray terminal for which
- it was initially introduced). The remedy is to add "\33K"
- after each SGR sequence, be it START (to fix the behavior
- of any HT after that before another SGR) or END (to fix the
- behavior of an HT in default background color that would
- follow a line-wrapping at the bottom of the screen in another
- background color, and to complement doing it after START).
- Piping grep's output through a pager such as less(1) avoids
- any HT problems since the pager performs tab expansion.
+ -- The behavior of line-wrapping when at the bottom of the
+ terminal screen and at the end of the current line is often
+ such that a new line is introduced, entirely cleared with
+ the current background color which may be different from the
+ default one (see the boolean back_color_erase terminfo(5)
+ capability), thus scrolling the display by one line.
+ The end of this new line will stay in this background color
+ even after reverting to the default background color with
+ "\33[m', unless it is explicitly cleared again with "\33[K"
+ (which is the behavior the user would instinctively expect
+ from the whole thing). There may be some unavoidable
+ background-color flicker at the end of this new line because
+ of this (when timing with the monitor's redraw is just right).
+ -- The behavior of HT (tab, "\t") is usually the same as that of
+ Cursor Forward Tabulation (CHT) with a default parameter
+ of 1 ("\33[I"), i.e., it performs pure movement to the next
+ tab stop, without any clearing of either content or screen
+ attributes (including background color); try
+ printf 'asdfqwerzxcv\rASDF\tZXCV\n'
+ in a bash(1) shell to demonstrate this. This is not what the
+ user would instinctively expect of HT (but is ok for CHT).
+ The instinctive behavior would include clearing the terminal
+ cells that are skipped over by HT with blank cells in the
+ current screen attributes, including background color;
+ the boolean dest_tabs_magic_smso terminfo(5) capability
+ indicates this saner behavior for HT, but only some rare
+ terminals have it (although it also indicates a special
+ glitch with standout mode in the Teleray terminal for which
+ it was initially introduced). The remedy is to add "\33K"
+ after each SGR sequence, be it START (to fix the behavior
+ of any HT after that before another SGR) or END (to fix the
+ behavior of an HT in default background color that would
+ follow a line-wrapping at the bottom of the screen in another
+ background color, and to complement doing it after START).
+ Piping grep's output through a pager such as less(1) avoids
+ any HT problems since the pager performs tab expansion.
Generic disadvantages of this remedy are:
- -- Some very rare terminals might support SGR but not EL (nobody
- will use "grep --color" on a terminal that does not support
- SGR in the first place).
- -- Having these extra control sequences might somewhat complicate
- the task of any program trying to parse "grep --color"
- output in order to extract structuring information from it.
+ -- Some very rare terminals might support SGR but not EL (nobody
+ will use "grep --color" on a terminal that does not support
+ SGR in the first place).
+ -- Having these extra control sequences might somewhat complicate
+ the task of any program trying to parse "grep --color"
+ output in order to extract structuring information from it.
A specific disadvantage to doing it after SGR START is:
- -- Even more possible background color flicker (when timing
- with the monitor's redraw is just right), even when not at the
- bottom of the screen.
+ -- Even more possible background color flicker (when timing
+ with the monitor's redraw is just right), even when not at the
+ bottom of the screen.
There are no additional disadvantages specific to doing it after
SGR END.
@@ -405,11 +405,11 @@ context_length_arg (char const *str, int *out)
{
uintmax_t value;
if (! (xstrtoumax (str, 0, 10, &value, "") == LONGINT_OK
- && 0 <= (*out = value)
- && *out == value))
+ && 0 <= (*out = value)
+ && *out == value))
{
error (EXIT_TROUBLE, 0, "%s: %s\n", str,
- _("invalid context length argument"));
+ _("invalid context length argument"));
}
}
@@ -427,8 +427,8 @@ static char *buflim; /* Limit of user-visible stuff. */
static size_t pagesize; /* alignment of memory pages */
static off_t bufoffset; /* Read offset; defined on regular files. */
static off_t after_last_match; /* Pointer after last matching line that
- would have been output if we were
- outputting characters. */
+ would have been output if we were
+ outputting characters. */
/* Return VAL aligned to the next multiple of ALIGNMENT. VAL can be
an integer or a pointer. Both args must be free of side effects. */
@@ -446,7 +446,7 @@ reset (int fd, char const *file, struct stats *stats)
{
pagesize = getpagesize ();
if (pagesize == 0 || 2 * pagesize + 1 <= pagesize)
- abort ();
+ abort ();
bufalloc = ALIGN_TO (INITIAL_BUFSIZE, pagesize) + pagesize + 1;
buffer = xmalloc (bufalloc);
}
@@ -458,16 +458,16 @@ reset (int fd, char const *file, struct stats *stats)
if (S_ISREG (stats->stat.st_mode))
{
if (file)
- bufoffset = 0;
+ bufoffset = 0;
else
- {
- bufoffset = lseek (fd, 0, SEEK_CUR);
- if (bufoffset < 0)
- {
- error (0, errno, _("lseek failed"));
- return 0;
- }
- }
+ {
+ bufoffset = lseek (fd, 0, SEEK_CUR);
+ if (bufoffset < 0)
+ {
+ error (0, errno, _("lseek failed"));
+ return 0;
+ }
+ }
}
return 1;
}
@@ -502,27 +502,27 @@ fillbuf (size_t save, struct stats const *stats)
/* Grow newsize until it is at least as great as minsize. */
for (newsize = bufalloc - pagesize - 1; newsize < minsize; newsize *= 2)
- if (newsize * 2 < newsize || newsize * 2 + pagesize + 1 < newsize * 2)
- xalloc_die ();
+ if (newsize * 2 < newsize || newsize * 2 + pagesize + 1 < newsize * 2)
+ xalloc_die ();
/* Try not to allocate more memory than the file size indicates,
- as that might cause unnecessary memory exhaustion if the file
- is large. However, do not use the original file size as a
- heuristic if we've already read past the file end, as most
- likely the file is growing. */
+ as that might cause unnecessary memory exhaustion if the file
+ is large. However, do not use the original file size as a
+ heuristic if we've already read past the file end, as most
+ likely the file is growing. */
if (S_ISREG (stats->stat.st_mode))
- {
- off_t to_be_read = stats->stat.st_size - bufoffset;
- off_t maxsize_off = save + to_be_read;
- if (0 <= to_be_read && to_be_read <= maxsize_off
- && maxsize_off == (size_t) maxsize_off
- && minsize <= (size_t) maxsize_off
- && (size_t) maxsize_off < newsize)
- newsize = maxsize_off;
- }
+ {
+ off_t to_be_read = stats->stat.st_size - bufoffset;
+ off_t maxsize_off = save + to_be_read;
+ if (0 <= to_be_read && to_be_read <= maxsize_off
+ && maxsize_off == (size_t) maxsize_off
+ && minsize <= (size_t) maxsize_off
+ && (size_t) maxsize_off < newsize)
+ newsize = maxsize_off;
+ }
/* Add enough room so that the buffer is aligned and has room
- for byte sentinels fore and aft. */
+ for byte sentinels fore and aft. */
newalloc = newsize + pagesize + 1;
newbuf = bufalloc < newalloc ? xmalloc (bufalloc = newalloc) : buffer;
@@ -531,10 +531,10 @@ fillbuf (size_t save, struct stats const *stats)
memmove (bufbeg, buffer + saved_offset, save);
bufbeg[-1] = eolbyte;
if (newbuf != buffer)
- {
- free (buffer);
- buffer = newbuf;
- }
+ {
+ free (buffer);
+ buffer = newbuf;
+ }
}
readsize = buffer + bufalloc - readbuf;
@@ -544,12 +544,12 @@ fillbuf (size_t save, struct stats const *stats)
{
ssize_t bytesread;
while ((bytesread = read (bufdesc, readbuf, readsize)) < 0
- && errno == EINTR)
- continue;
+ && errno == EINTR)
+ continue;
if (bytesread < 0)
- cc = 0;
+ cc = 0;
else
- fillsize = bytesread;
+ fillsize = bytesread;
}
bufoffset += fillsize;
@@ -581,9 +581,9 @@ static int count_matches; /* Count matching lines. */
static int list_files; /* List matching files. */
static int no_filenames; /* Suppress file names. */
static off_t max_count; /* Stop after outputting this many
- lines from an input file. */
+ lines from an input file. */
static int line_buffered; /* If nonzero, use line buffering, i.e.
- fflush everyline out. */
+ fflush everyline out. */
static char *label = NULL; /* Fake filename for stdin */
@@ -591,12 +591,12 @@ static char *label = NULL; /* Fake filename for stdin */
static uintmax_t totalcc; /* Total character count before bufbeg. */
static char const *lastnl; /* Pointer after last newline counted. */
static char const *lastout; /* Pointer after last character output;
- NULL if no character has been output
- or if it's conceptually before bufbeg. */
+ NULL if no character has been output
+ or if it's conceptually before bufbeg. */
static uintmax_t totalnl; /* Total newline count before lastnl. */
static off_t outleft; /* Maximum number of lines to be output. */
static int pending; /* Pending lines of output.
- Always kept 0 if out_quiet is true. */
+ Always kept 0 if out_quiet is true. */
static int done_on_match; /* Stop scanning file on first match. */
static int exit_on_match; /* Exit on first match. */
@@ -624,7 +624,7 @@ nlscan (char const *lim)
{
beg = memchr (beg, eolbyte, lim - beg);
if (!beg)
- break;
+ break;
newlines++;
}
totalnl = add_count (totalnl, newlines);
@@ -686,21 +686,21 @@ print_line_head (char const *beg, char const *lim, int sep)
{
print_filename();
if (filename_mask)
- pending_sep = 1;
+ pending_sep = 1;
else
- fputc(0, stdout);
+ fputc(0, stdout);
}
if (out_line)
{
if (lastnl < lim)
- {
- nlscan (beg);
- totalnl = add_count (totalnl, 1);
- lastnl = lim;
- }
+ {
+ nlscan (beg);
+ totalnl = add_count (totalnl, 1);
+ lastnl = lim;
+ }
if (pending_sep)
- print_sep(sep);
+ print_sep(sep);
print_offset (totalnl, 4, line_num_color);
pending_sep = 1;
}
@@ -712,7 +712,7 @@ print_line_head (char const *beg, char const *lim, int sep)
pos = dossified_pos (pos);
#endif
if (pending_sep)
- print_sep(sep);
+ print_sep(sep);
print_offset (pos, 6, byte_num_color);
pending_sep = 1;
}
@@ -720,11 +720,11 @@ print_line_head (char const *beg, char const *lim, int sep)
if (pending_sep)
{
/* This assumes sep is one column wide.
- Try doing this any other way with Unicode
- (and its combining and wide characters)
- filenames and you're wasting your efforts. */
+ Try doing this any other way with Unicode
+ (and its combining and wide characters)
+ filenames and you're wasting your efforts. */
if (align_tabs)
- fputs("\t\b", stdout);
+ fputs("\t\b", stdout);
print_sep(sep);
}
@@ -732,7 +732,7 @@ print_line_head (char const *beg, char const *lim, int sep)
static const char *
print_line_middle (const char *beg, const char *lim,
- const char *line_color, const char *match_color)
+ const char *line_color, const char *match_color)
{
size_t match_size;
size_t match_offset;
@@ -740,48 +740,48 @@ print_line_middle (const char *beg, const char *lim,
const char *mid = NULL;
while (cur < lim
- && ((match_offset = execute(beg, lim - beg, &match_size,
- beg + (cur - beg))) != (size_t) -1))
+ && ((match_offset = execute(beg, lim - beg, &match_size,
+ beg + (cur - beg))) != (size_t) -1))
{
char const *b = beg + match_offset;
/* Avoid matching the empty line at the end of the buffer. */
if (b == lim)
- break;
+ break;
/* Avoid hanging on grep --color "" foo */
if (match_size == 0)
- {
- /* Make minimal progress; there may be further non-empty matches. */
- /* XXX - Could really advance by one whole multi-octet character. */
- match_size = 1;
- if (!mid)
- mid = cur;
- }
+ {
+ /* Make minimal progress; there may be further non-empty matches. */
+ /* XXX - Could really advance by one whole multi-octet character. */
+ match_size = 1;
+ if (!mid)
+ mid = cur;
+ }
else
- {
- /* This function is called on a matching line only,
- but is it selected or rejected/context? */
- if (only_matching)
- print_line_head(b, lim, out_invert ? SEP_CHAR_REJECTED
- : SEP_CHAR_SELECTED);
- else
- {
- PR_SGR_START(line_color);
- if (mid)
- {
- cur = mid;
- mid = NULL;
- }
- fwrite (cur, sizeof (char), b - cur, stdout);
- }
-
- PR_SGR_START_IF(match_color);
- fwrite (b, sizeof (char), match_size, stdout);
- PR_SGR_END_IF(match_color);
- if (only_matching)
- fputs("\n", stdout);
- }
+ {
+ /* This function is called on a matching line only,
+ but is it selected or rejected/context? */
+ if (only_matching)
+ print_line_head(b, lim, out_invert ? SEP_CHAR_REJECTED
+ : SEP_CHAR_SELECTED);
+ else
+ {
+ PR_SGR_START(line_color);
+ if (mid)
+ {
+ cur = mid;
+ mid = NULL;
+ }
+ fwrite (cur, sizeof (char), b - cur, stdout);
+ }
+
+ PR_SGR_START_IF(match_color);
+ fwrite (b, sizeof (char), match_size, stdout);
+ PR_SGR_END_IF(match_color);
+ if (only_matching)
+ fputs("\n", stdout);
+ }
cur = b + match_size;
}
@@ -829,10 +829,10 @@ prline (char const *beg, char const *lim, int sep)
if (color_option)
{
line_color = ( (sep == SEP_CHAR_SELECTED)
- ^ (out_invert && (color_option < 0)))
- ? selected_line_color : context_line_color;
+ ^ (out_invert && (color_option < 0)))
+ ? selected_line_color : context_line_color;
match_color = (sep == SEP_CHAR_SELECTED)
- ? selected_match_color : context_match_color;
+ ? selected_match_color : context_match_color;
}
else
line_color = match_color = NULL; /* Shouldn't be used. */
@@ -842,11 +842,11 @@ prline (char const *beg, char const *lim, int sep)
{
/* We already know that non-matching lines have no match (to colorize). */
if (matching && (only_matching || *match_color))
- beg = print_line_middle(beg, lim, line_color, match_color);
+ beg = print_line_middle(beg, lim, line_color, match_color);
/* FIXME: this test may be removable. */
if (!only_matching && *line_color)
- beg = print_line_tail(beg, lim, line_color);
+ beg = print_line_tail(beg, lim, line_color);
}
if (!only_matching && lim > beg)
@@ -874,12 +874,12 @@ prpending (char const *lim)
size_t match_size;
--pending;
if (outleft
- || ((execute(lastout, nl + 1 - lastout,
- &match_size, NULL) == (size_t) -1)
- == !out_invert))
- prline (lastout, nl + 1, SEP_CHAR_REJECTED);
+ || ((execute(lastout, nl + 1 - lastout,
+ &match_size, NULL) == (size_t) -1)
+ == !out_invert))
+ prline (lastout, nl + 1, SEP_CHAR_REJECTED);
else
- pending = 0;
+ pending = 0;
}
}
@@ -904,41 +904,41 @@ prtext (char const *beg, char const *lim, int *nlinesp)
bp = lastout ? lastout : bufbeg;
for (i = 0; i < out_before; ++i)
- if (p > bp)
- do
- --p;
- while (p[-1] != eol);
+ if (p > bp)
+ do
+ --p;
+ while (p[-1] != eol);
/* We print the SEP_STR_GROUP separator only if our output is
- discontiguous from the last output in the file. */
+ discontiguous from the last output in the file. */
if ((out_before || out_after) && used && p != lastout && group_separator)
- {
- PR_SGR_START_IF(sep_color);
- fputs (group_separator, stdout);
- PR_SGR_END_IF(sep_color);
- fputc('\n', stdout);
- }
+ {
+ PR_SGR_START_IF(sep_color);
+ fputs (group_separator, stdout);
+ PR_SGR_END_IF(sep_color);
+ fputc('\n', stdout);
+ }
while (p < beg)
- {
- char const *nl = memchr (p, eol, beg - p);
- nl++;
- prline (p, nl, SEP_CHAR_REJECTED);
- p = nl;
- }
+ {
+ char const *nl = memchr (p, eol, beg - p);
+ nl++;
+ prline (p, nl, SEP_CHAR_REJECTED);
+ p = nl;
+ }
}
if (nlinesp)
{
/* Caller wants a line count. */
for (n = 0; p < lim && n < outleft; n++)
- {
- char const *nl = memchr (p, eol, lim - p);
- nl++;
- if (!out_quiet)
- prline (p, nl, SEP_CHAR_SELECTED);
- p = nl;
- }
+ {
+ char const *nl = memchr (p, eol, lim - p);
+ nl++;
+ if (!out_quiet)
+ prline (p, nl, SEP_CHAR_SELECTED);
+ p = nl;
+ }
*nlinesp = n;
/* relying on it that this function is never called when outleft = 0. */
@@ -987,7 +987,7 @@ do_execute (char const *buf, size_t size, size_t *match_size, char const *start_
result = execute (line_buf, line_next - line_buf, match_size, start_ptr);
if (result != (size_t) -1)
- return (line_buf - buf) + result;
+ return (line_buf - buf) + result;
}
return (size_t) -1;
@@ -1007,34 +1007,34 @@ grepbuf (char const *beg, char const *lim)
nlines = 0;
p = beg;
while ((match_offset = do_execute(p, lim - p, &match_size,
- NULL)) != (size_t) -1)
+ NULL)) != (size_t) -1)
{
char const *b = p + match_offset;
char const *endp = b + match_size;
/* Avoid matching the empty line at the end of the buffer. */
if (b == lim)
- break;
+ break;
if (!out_invert)
- {
- prtext (b, endp, (int *) 0);
- nlines++;
+ {
+ prtext (b, endp, (int *) 0);
+ nlines++;
outleft--;
- if (!outleft || done_on_match)
- {
- if (exit_on_match)
- exit (EXIT_SUCCESS);
- after_last_match = bufoffset - (buflim - endp);
- return nlines;
- }
- }
+ if (!outleft || done_on_match)
+ {
+ if (exit_on_match)
+ exit (EXIT_SUCCESS);
+ after_last_match = bufoffset - (buflim - endp);
+ return nlines;
+ }
+ }
else if (p < b)
- {
- prtext (p, b, &n);
- nlines += n;
+ {
+ prtext (p, b, &n);
+ nlines += n;
outleft -= n;
- if (!outleft)
- return nlines;
- }
+ if (!outleft)
+ return nlines;
+ }
p = endp;
}
if (out_invert && p < lim)
@@ -1067,9 +1067,9 @@ grep (int fd, char const *file, struct stats *stats)
&& S_ISDIR (stats->stat.st_mode))
{
/* Close fd now, so that we don't open a lot of file descriptors
- when we recurse deeply. */
+ when we recurse deeply. */
if (close (fd) != 0)
- error (0, errno, "%s", file);
+ error (0, errno, "%s", file);
return grepdir (file, stats) - 2;
}
@@ -1087,13 +1087,13 @@ grep (int fd, char const *file, struct stats *stats)
if (! fillbuf (save, stats))
{
if (! is_EISDIR (errno, file))
- suppressible_error (filename, errno);
+ suppressible_error (filename, errno);
return 0;
}
not_text = (((binary_files == BINARY_BINARY_FILES && !out_quiet)
- || binary_files == WITHOUT_MATCH_BINARY_FILES)
- && memchr (bufbeg, eol ? '\0' : '\200', buflim - bufbeg));
+ || binary_files == WITHOUT_MATCH_BINARY_FILES)
+ && memchr (bufbeg, eol ? '\0' : '\200', buflim - bufbeg));
if (not_text && binary_files == WITHOUT_MATCH_BINARY_FILES)
return 0;
done_on_match += not_text;
@@ -1103,71 +1103,71 @@ grep (int fd, char const *file, struct stats *stats)
{
lastnl = bufbeg;
if (lastout)
- lastout = bufbeg;
+ lastout = bufbeg;
beg = bufbeg + save;
/* no more data to scan (eof) except for maybe a residue -> break */
if (beg == buflim)
- break;
+ break;
/* Determine new residue (the length of an incomplete line at the end of
the buffer, 0 means there is no incomplete last line). */
oldc = beg[-1];
beg[-1] = eol;
for (lim = buflim; lim[-1] != eol; lim--)
- continue;
+ continue;
beg[-1] = oldc;
if (lim == beg)
- lim = beg - residue;
+ lim = beg - residue;
beg -= residue;
residue = buflim - lim;
if (beg < lim)
- {
- if (outleft)
- nlines += grepbuf (beg, lim);
- if (pending)
- prpending (lim);
- if((!outleft && !pending) || (nlines && done_on_match && !out_invert))
- goto finish_grep;
- }
+ {
+ if (outleft)
+ nlines += grepbuf (beg, lim);
+ if (pending)
+ prpending (lim);
+ if((!outleft && !pending) || (nlines && done_on_match && !out_invert))
+ goto finish_grep;
+ }
/* The last OUT_BEFORE lines at the end of the buffer will be needed as
- leading context if there is a matching line at the begin of the
- next data. Make beg point to their begin. */
+ leading context if there is a matching line at the begin of the
+ next data. Make beg point to their begin. */
i = 0;
beg = lim;
while (i < out_before && beg > bufbeg && beg != lastout)
- {
- ++i;
- do
- --beg;
- while (beg[-1] != eol);
- }
+ {
+ ++i;
+ do
+ --beg;
+ while (beg[-1] != eol);
+ }
/* detect if leading context is discontinuous from last printed line. */
if (beg != lastout)
- lastout = 0;
+ lastout = 0;
/* Handle some details and read more data to scan. */
save = residue + lim - beg;
if (out_byte)
- totalcc = add_count (totalcc, buflim - bufbeg - save);
+ totalcc = add_count (totalcc, buflim - bufbeg - save);
if (out_line)
- nlscan (beg);
+ nlscan (beg);
if (! fillbuf (save, stats))
- {
- if (! is_EISDIR (errno, file))
- suppressible_error (filename, errno);
- goto finish_grep;
- }
+ {
+ if (! is_EISDIR (errno, file))
+ suppressible_error (filename, errno);
+ goto finish_grep;
+ }
}
if (residue)
{
*buflim++ = eol;
if (outleft)
- nlines += grepbuf (bufbeg + save - residue, buflim);
+ nlines += grepbuf (bufbeg + save - residue, buflim);
if (pending)
prpending (buflim);
}
@@ -1202,49 +1202,49 @@ grepfile (char const *file, struct stats *stats)
if (directories == SKIP_DIRECTORIES && S_ISDIR (stats->stat.st_mode))
return 1;
if (devices == SKIP_DEVICES && (S_ISCHR (stats->stat.st_mode)
- || S_ISBLK (stats->stat.st_mode)
- || S_ISSOCK (stats->stat.st_mode)
- || S_ISFIFO (stats->stat.st_mode)))
+ || S_ISBLK (stats->stat.st_mode)
+ || S_ISSOCK (stats->stat.st_mode)
+ || S_ISFIFO (stats->stat.st_mode)))
return 1;
while ((desc = open (file, O_RDONLY)) < 0 && errno == EINTR)
- continue;
+ continue;
if (desc < 0)
- {
- int e = errno;
-
- if (is_EISDIR (e, file) && directories == RECURSE_DIRECTORIES)
- {
- if (stat (file, &stats->stat) != 0)
- {
- error (0, errno, "%s", file);
- return 1;
- }
-
- return grepdir (file, stats);
- }
-
- if (!suppress_errors)
- {
- if (directories == SKIP_DIRECTORIES)
- switch (e)
- {
+ {
+ int e = errno;
+
+ if (is_EISDIR (e, file) && directories == RECURSE_DIRECTORIES)
+ {
+ if (stat (file, &stats->stat) != 0)
+ {
+ error (0, errno, "%s", file);
+ return 1;
+ }
+
+ return grepdir (file, stats);
+ }
+
+ if (!suppress_errors)
+ {
+ if (directories == SKIP_DIRECTORIES)
+ switch (e)
+ {
#if defined EISDIR
- case EISDIR:
- return 1;
+ case EISDIR:
+ return 1;
#endif
- case EACCES:
- /* When skipping directories, don't worry about
- directories that can't be opened. */
- if (isdir (file))
- return 1;
- break;
- }
- }
-
- suppressible_error (file, e);
- return 1;
- }
+ case EACCES:
+ /* When skipping directories, don't worry about
+ directories that can't be opened. */
+ if (isdir (file))
+ return 1;
+ break;
+ }
+ }
+
+ suppressible_error (file, e);
+ return 1;
+ }
filename = file;
}
@@ -1262,40 +1262,40 @@ grepfile (char const *file, struct stats *stats)
else
{
if (count_matches)
- {
- if (out_file)
- {
- print_filename();
- if (filename_mask)
- print_sep(SEP_CHAR_SELECTED);
- else
- fputc(0, stdout);
- }
- printf ("%d\n", count);
- }
+ {
+ if (out_file)
+ {
+ print_filename();
+ if (filename_mask)
+ print_sep(SEP_CHAR_SELECTED);
+ else
+ fputc(0, stdout);
+ }
+ printf ("%d\n", count);
+ }
status = !count;
if (list_files == 1 - 2 * status)
- {
- print_filename();
- fputc('\n' & filename_mask, stdout);
- }
+ {
+ print_filename();
+ fputc('\n' & filename_mask, stdout);
+ }
if (! file)
- {
- off_t required_offset = outleft ? bufoffset : after_last_match;
- if (required_offset != bufoffset
- && lseek (desc, required_offset, SEEK_SET) < 0
- && S_ISREG (stats->stat.st_mode))
- error (0, errno, "%s", filename);
- }
+ {
+ off_t required_offset = outleft ? bufoffset : after_last_match;
+ if (required_offset != bufoffset
+ && lseek (desc, required_offset, SEEK_SET) < 0
+ && S_ISREG (stats->stat.st_mode))
+ error (0, errno, "%s", filename);
+ }
else
- while (close (desc) != 0)
- if (errno != EINTR)
- {
- error (0, errno, "%s", file);
- break;
- }
+ while (close (desc) != 0)
+ if (errno != EINTR)
+ {
+ error (0, errno, "%s", file);
+ break;
+ }
}
return status;
@@ -1318,44 +1318,44 @@ grepdir (char const *dir, struct stats const *stats)
if (stats->stat.st_ino)
for (ancestor = stats; (ancestor = ancestor->parent) != 0; )
if (ancestor->stat.st_ino == stats->stat.st_ino
- && ancestor->stat.st_dev == stats->stat.st_dev)
- {
- if (!suppress_errors)
- error (0, 0, _("warning: %s: %s\n"), dir,
- _("recursive directory loop"));
- return 1;
- }
+ && ancestor->stat.st_dev == stats->stat.st_dev)
+ {
+ if (!suppress_errors)
+ error (0, 0, _("warning: %s: %s\n"), dir,
+ _("recursive directory loop"));
+ return 1;
+ }
name_space = savedir (dir, stats->stat.st_size, included_patterns,
- excluded_patterns, excluded_directory_patterns);
+ excluded_patterns, excluded_directory_patterns);
if (! name_space)
{
if (errno)
- suppressible_error (dir, errno);
+ suppressible_error (dir, errno);
else
- xalloc_die ();
+ xalloc_die ();
}
else
{
size_t dirlen = strlen (dir);
int needs_slash = ! (dirlen == FILE_SYSTEM_PREFIX_LEN (dir)
- || ISSLASH (dir[dirlen - 1]));
+ || ISSLASH (dir[dirlen - 1]));
char *file = NULL;
char const *namep = name_space;
struct stats child;
child.parent = stats;
out_file += !no_filenames;
while (*namep)
- {
- size_t namelen = strlen (namep);
- file = xrealloc (file, dirlen + 1 + namelen + 1);
- strcpy (file, dir);
- file[dirlen] = '/';
- strcpy (file + dirlen + needs_slash, namep);
- namep += namelen + 1;
- status &= grepfile (file, &child);
- }
+ {
+ size_t namelen = strlen (namep);
+ file = xrealloc (file, dirlen + 1 + namelen + 1);
+ strcpy (file, dir);
+ file[dirlen] = '/';
+ strcpy (file + dirlen + needs_slash, namep);
+ namep += namelen + 1;
+ status &= grepfile (file, &child);
+ }
out_file -= !no_filenames;
free (file);
free (name_space);
@@ -1371,9 +1371,9 @@ usage (int status)
if (status != 0)
{
fprintf (stderr, _("Usage: %s [OPTION]... PATTERN [FILE]...\n"),
- program_name);
+ program_name);
fprintf (stderr, _("Try `%s --help' for more information.\n"),
- program_name);
+ program_name);
}
else
{
@@ -1489,7 +1489,7 @@ setmatcher (char const *m)
compile = matchers[0].compile;
execute = matchers[0].execute;
if (!matchers[1].name)
- matcher = matchers[0].name;
+ matcher = matchers[0].name;
}
else if (matcher)
@@ -1539,15 +1539,15 @@ set_limits(void)
/* Approximate the amount regex.c needs, plus some more. */
newlim = re_max_failures * 2 * 20 * sizeof (char *);
if (newlim > rlim.rlim_max)
- {
- newlim = rlim.rlim_max;
- re_max_failures = newlim / (2 * 20 * sizeof (char *));
- }
+ {
+ newlim = rlim.rlim_max;
+ re_max_failures = newlim / (2 * 20 * sizeof (char *));
+ }
if (rlim.rlim_cur < newlim)
- {
- rlim.rlim_cur = newlim;
- setrlimit (RLIMIT_STACK, &rlim);
- }
+ {
+ rlim.rlim_cur = newlim;
+ setrlimit (RLIMIT_STACK, &rlim);
+ }
}
#endif
}
@@ -1567,16 +1567,16 @@ prepend_args (char const *options, char *buf, char **argv)
for (;;)
{
while (c_isspace ((unsigned char) *o))
- o++;
+ o++;
if (!*o)
- return n;
+ return n;
if (argv)
- argv[n] = b;
+ argv[n] = b;
n++;
do
- if ((*b++ = *o++) == '\\' && *o)
- b[-1] = *o++;
+ if ((*b++ = *o++) == '\\' && *o)
+ b[-1] = *o++;
while (*o && ! c_isspace ((unsigned char) *o));
*b++ = '\0';
@@ -1601,7 +1601,7 @@ prepend_default_options (char const *options, int *pargc, char ***pargv)
*pp++ = *argv++;
pp += prepend_args (options, buf, pp);
while ((*pp++ = *argv++))
- continue;
+ continue;
}
}
@@ -1621,7 +1621,7 @@ get_nondigit_option (int argc, char *const *argv, int *default_context)
this_digit_optind = optind;
while (opt = getopt_long (argc, (char **) argv, short_options, long_options,
NULL),
- '0' <= opt && opt <= '9')
+ '0' <= opt && opt <= '9')
{
if (prev_digit_optind != this_digit_optind || !was_digit)
{
@@ -1636,14 +1636,14 @@ get_nondigit_option (int argc, char *const *argv, int *default_context)
}
if (p == buf + sizeof buf - 4)
- {
- /* Too many digits. Append "..." to make context_length_arg
- complain about "X...", where X contains the digits seen
- so far. */
- strcpy (p, "...");
- p += 3;
- break;
- }
+ {
+ /* Too many digits. Append "..." to make context_length_arg
+ complain about "X...", where X contains the digits seen
+ so far. */
+ strcpy (p, "...");
+ p += 3;
+ break;
+ }
*p++ = opt;
was_digit = 1;
@@ -1687,50 +1687,50 @@ parse_grep_colors (void)
for (;;)
if (*q == ':' || *q == '\0')
{
- char c = *q;
- struct color_cap *cap;
-
- *q++ = '\0'; /* Terminate name or val. */
- /* Empty name without val (empty cap)
- * won't match and will be ignored. */
- for (cap = color_dict; cap->name; cap++)
- if (STREQ (cap->name, name))
- break;
- /* If name unknown, go on for forward compatibility. */
- if (cap->name)
- {
- if (cap->var)
- {
- if (val)
+ char c = *q;
+ struct color_cap *cap;
+
+ *q++ = '\0'; /* Terminate name or val. */
+ /* Empty name without val (empty cap)
+ * won't match and will be ignored. */
+ for (cap = color_dict; cap->name; cap++)
+ if (STREQ (cap->name, name))
+ break;
+ /* If name unknown, go on for forward compatibility. */
+ if (cap->name)
+ {
+ if (cap->var)
+ {
+ if (val)
*(cap->var) = val;
- else
+ else
error(0, 0, _("in GREP_COLORS=\"%s\", the \"%s\" capacity "
- "needs a value (\"=...\"); skipped"), p, name);
+ "needs a value (\"=...\"); skipped"), p, name);
}
else if (val)
error(0, 0, _("in GREP_COLORS=\"%s\", the \"%s\" capacity "
"is boolean and cannot take a value (\"=%s\"); skipped"),
- p, name, val);
+ p, name, val);
}
- if (cap->fct)
- {
- const char *err_str = cap->fct();
-
- if (err_str)
- error(0, 0, _("in GREP_COLORS=\"%s\", the \"%s\" capacity %s"),
- p, name, err_str);
- }
- if (c == '\0')
- return;
- name = q;
- val = NULL;
+ if (cap->fct)
+ {
+ const char *err_str = cap->fct();
+
+ if (err_str)
+ error(0, 0, _("in GREP_COLORS=\"%s\", the \"%s\" capacity %s"),
+ p, name, err_str);
+ }
+ if (c == '\0')
+ return;
+ name = q;
+ val = NULL;
}
else if (*q == '=')
{
- if (q == name || val)
- goto ill_formed;
- *q++ = '\0'; /* Terminate name. */
- val = q; /* Can be the empty string. */
+ if (q == name || val)
+ goto ill_formed;
+ *q++ = '\0'; /* Terminate name. */
+ val = q; /* Can be the empty string. */
}
else if (val == NULL)
q++; /* Accumulate name. */
@@ -1741,7 +1741,7 @@ parse_grep_colors (void)
ill_formed:
error(0, 0, _("stopped processing of ill-formed GREP_COLORS=\"%s\" "
- "at remaining substring \"%s\""), p, q);
+ "at remaining substring \"%s\""), p, q);
}
int
@@ -1792,216 +1792,216 @@ main (int argc, char **argv)
switch (opt)
{
case 'A':
- context_length_arg (optarg, &out_after);
- break;
+ context_length_arg (optarg, &out_after);
+ break;
case 'B':
- context_length_arg (optarg, &out_before);
- break;
+ context_length_arg (optarg, &out_before);
+ break;
case 'C':
- /* Set output match context, but let any explicit leading or
- trailing amount specified with -A or -B stand. */
- context_length_arg (optarg, &default_context);
- break;
+ /* Set output match context, but let any explicit leading or
+ trailing amount specified with -A or -B stand. */
+ context_length_arg (optarg, &default_context);
+ break;
case 'D':
- if (STREQ (optarg, "read"))
- devices = READ_DEVICES;
- else if (STREQ (optarg, "skip"))
- devices = SKIP_DEVICES;
- else
- error (EXIT_TROUBLE, 0, _("unknown devices method"));
- break;
+ if (STREQ (optarg, "read"))
+ devices = READ_DEVICES;
+ else if (STREQ (optarg, "skip"))
+ devices = SKIP_DEVICES;
+ else
+ error (EXIT_TROUBLE, 0, _("unknown devices method"));
+ break;
case 'E':
- setmatcher ("egrep");
- break;
+ setmatcher ("egrep");
+ break;
case 'F':
- setmatcher ("fgrep");
- break;
+ setmatcher ("fgrep");
+ break;
case 'P':
- setmatcher ("perl");
- break;
+ setmatcher ("perl");
+ break;
case 'G':
- setmatcher ("grep");
- break;
+ setmatcher ("grep");
+ break;
case 'X': /* undocumented on purpose */
- setmatcher (optarg);
- break;
+ setmatcher (optarg);
+ break;
case 'H':
- with_filenames = 1;
- no_filenames = 0;
- break;
+ with_filenames = 1;
+ no_filenames = 0;
+ break;
case 'I':
- binary_files = WITHOUT_MATCH_BINARY_FILES;
- break;
+ binary_files = WITHOUT_MATCH_BINARY_FILES;
+ break;
case 'T':
- align_tabs = 1;
- break;
+ align_tabs = 1;
+ break;
case 'U':
#if defined HAVE_DOS_FILE_CONTENTS
- dos_use_file_type = DOS_BINARY;
+ dos_use_file_type = DOS_BINARY;
#endif
- break;
+ break;
case 'u':
#if defined HAVE_DOS_FILE_CONTENTS
- dos_report_unix_offset = 1;
+ dos_report_unix_offset = 1;
#endif
- break;
+ break;
case 'V':
- show_version = 1;
- break;
+ show_version = 1;
+ break;
case 'a':
- binary_files = TEXT_BINARY_FILES;
- break;
+ binary_files = TEXT_BINARY_FILES;
+ break;
case 'b':
- out_byte = 1;
- break;
+ out_byte = 1;
+ break;
case 'c':
- count_matches = 1;
- break;
+ count_matches = 1;
+ break;
case 'd':
- directories = XARGMATCH ("--directories", optarg,
- directories_args, directories_types);
- break;
+ directories = XARGMATCH ("--directories", optarg,
+ directories_args, directories_types);
+ break;
case 'e':
- cc = strlen (optarg);
- keys = xrealloc (keys, keycc + cc + 1);
- strcpy (&keys[keycc], optarg);
- keycc += cc;
- keys[keycc++] = '\n';
- break;
+ cc = strlen (optarg);
+ keys = xrealloc (keys, keycc + cc + 1);
+ strcpy (&keys[keycc], optarg);
+ keycc += cc;
+ keys[keycc++] = '\n';
+ break;
case 'f':
- fp = STREQ (optarg, "-") ? stdin : fopen (optarg, "r");
- if (!fp)
- error (EXIT_TROUBLE, errno, "%s", optarg);
- for (keyalloc = 1; keyalloc <= keycc + 1; keyalloc *= 2)
- ;
- keys = xrealloc (keys, keyalloc);
- oldcc = keycc;
- while (!feof (fp)
- && (cc = fread (keys + keycc, 1, keyalloc - 1 - keycc, fp)) > 0)
- {
- keycc += cc;
- if (keycc == keyalloc - 1)
- keys = xrealloc (keys, keyalloc *= 2);
- }
- if (fp != stdin)
- fclose(fp);
- /* Append final newline if file ended in non-newline. */
- if (oldcc != keycc && keys[keycc - 1] != '\n')
- keys[keycc++] = '\n';
- break;
+ fp = STREQ (optarg, "-") ? stdin : fopen (optarg, "r");
+ if (!fp)
+ error (EXIT_TROUBLE, errno, "%s", optarg);
+ for (keyalloc = 1; keyalloc <= keycc + 1; keyalloc *= 2)
+ ;
+ keys = xrealloc (keys, keyalloc);
+ oldcc = keycc;
+ while (!feof (fp)
+ && (cc = fread (keys + keycc, 1, keyalloc - 1 - keycc, fp)) > 0)
+ {
+ keycc += cc;
+ if (keycc == keyalloc - 1)
+ keys = xrealloc (keys, keyalloc *= 2);
+ }
+ if (fp != stdin)
+ fclose(fp);
+ /* Append final newline if file ended in non-newline. */
+ if (oldcc != keycc && keys[keycc - 1] != '\n')
+ keys[keycc++] = '\n';
+ break;
case 'h':
- with_filenames = 0;
- no_filenames = 1;
- break;
+ with_filenames = 0;
+ no_filenames = 1;
+ break;
case 'i':
case 'y': /* For old-timers . . . */
- match_icase = 1;
- break;
+ match_icase = 1;
+ break;
case 'L':
- /* Like -l, except list files that don't contain matches.
- Inspired by the same option in Hume's gre. */
- list_files = -1;
- break;
+ /* Like -l, except list files that don't contain matches.
+ Inspired by the same option in Hume's gre. */
+ list_files = -1;
+ break;
case 'l':
- list_files = 1;
- break;
+ list_files = 1;
+ break;
case 'm':
- {
- uintmax_t value;
- switch (xstrtoumax (optarg, 0, 10, &value, ""))
- {
- case LONGINT_OK:
- max_count = value;
- if (0 <= max_count && max_count == value)
- break;
- /* Fall through. */
- case LONGINT_OVERFLOW:
- max_count = TYPE_MAXIMUM (off_t);
- break;
-
- default:
- error (EXIT_TROUBLE, 0, _("invalid max count"));
- }
- }
- break;
+ {
+ uintmax_t value;
+ switch (xstrtoumax (optarg, 0, 10, &value, ""))
+ {
+ case LONGINT_OK:
+ max_count = value;
+ if (0 <= max_count && max_count == value)
+ break;
+ /* Fall through. */
+ case LONGINT_OVERFLOW:
+ max_count = TYPE_MAXIMUM (off_t);
+ break;
+
+ default:
+ error (EXIT_TROUBLE, 0, _("invalid max count"));
+ }
+ }
+ break;
case 'n':
- out_line = 1;
- break;
+ out_line = 1;
+ break;
case 'o':
- only_matching = 1;
- break;
+ only_matching = 1;
+ break;
case 'q':
- exit_on_match = 1;
- exit_failure = 0;
- break;
+ exit_on_match = 1;
+ exit_failure = 0;
+ break;
case 'R':
case 'r':
- directories = RECURSE_DIRECTORIES;
- break;
+ directories = RECURSE_DIRECTORIES;
+ break;
case 's':
- suppress_errors = 1;
- break;
+ suppress_errors = 1;
+ break;
case 'v':
- out_invert = 1;
- break;
+ out_invert = 1;
+ break;
case 'w':
- match_words = 1;
- break;
+ match_words = 1;
+ break;
case 'x':
- match_lines = 1;
- break;
+ match_lines = 1;
+ break;
case 'Z':
- filename_mask = 0;
- break;
+ filename_mask = 0;
+ break;
case 'z':
- eolbyte = '\0';
- break;
+ eolbyte = '\0';
+ break;
case BINARY_FILES_OPTION:
- if (STREQ (optarg, "binary"))
- binary_files = BINARY_BINARY_FILES;
- else if (STREQ (optarg, "text"))
- binary_files = TEXT_BINARY_FILES;
- else if (STREQ (optarg, "without-match"))
- binary_files = WITHOUT_MATCH_BINARY_FILES;
- else
- error (EXIT_TROUBLE, 0, _("unknown binary-files type"));
- break;
+ if (STREQ (optarg, "binary"))
+ binary_files = BINARY_BINARY_FILES;
+ else if (STREQ (optarg, "text"))
+ binary_files = TEXT_BINARY_FILES;
+ else if (STREQ (optarg, "without-match"))
+ binary_files = WITHOUT_MATCH_BINARY_FILES;
+ else
+ error (EXIT_TROUBLE, 0, _("unknown binary-files type"));
+ break;
case COLOR_OPTION:
if(optarg) {
@@ -2019,26 +2019,26 @@ main (int argc, char **argv)
} else
color_option = 2;
if (color_option == 2)
- {
- char const *t;
- if (isatty (STDOUT_FILENO) && (t = getenv ("TERM"))
- && !STREQ (t, "dumb"))
- color_option = 1;
- else
- color_option = 0;
- }
- break;
+ {
+ char const *t;
+ if (isatty (STDOUT_FILENO) && (t = getenv ("TERM"))
+ && !STREQ (t, "dumb"))
+ color_option = 1;
+ else
+ color_option = 0;
+ }
+ break;
case EXCLUDE_OPTION:
- if (!excluded_patterns)
- excluded_patterns = new_exclude ();
- add_exclude (excluded_patterns, optarg, EXCLUDE_WILDCARDS);
- break;
+ if (!excluded_patterns)
+ excluded_patterns = new_exclude ();
+ add_exclude (excluded_patterns, optarg, EXCLUDE_WILDCARDS);
+ break;
case EXCLUDE_FROM_OPTION:
- if (!excluded_patterns)
- excluded_patterns = new_exclude ();
+ if (!excluded_patterns)
+ excluded_patterns = new_exclude ();
if (add_exclude_file (add_exclude, excluded_patterns, optarg,
- EXCLUDE_WILDCARDS, '\n') != 0)
+ EXCLUDE_WILDCARDS, '\n') != 0)
{
error (EXIT_TROUBLE, errno, "%s", optarg);
}
@@ -2046,36 +2046,36 @@ main (int argc, char **argv)
case EXCLUDE_DIRECTORY_OPTION:
if (!excluded_directory_patterns)
- excluded_directory_patterns = new_exclude ();
- add_exclude (excluded_directory_patterns, optarg, EXCLUDE_WILDCARDS);
+ excluded_directory_patterns = new_exclude ();
+ add_exclude (excluded_directory_patterns, optarg, EXCLUDE_WILDCARDS);
break;
case INCLUDE_OPTION:
- if (!included_patterns)
- included_patterns = new_exclude ();
- add_exclude (included_patterns, optarg,
- EXCLUDE_WILDCARDS | EXCLUDE_INCLUDE);
- break;
+ if (!included_patterns)
+ included_patterns = new_exclude ();
+ add_exclude (included_patterns, optarg,
+ EXCLUDE_WILDCARDS | EXCLUDE_INCLUDE);
+ break;
case GROUP_SEPARATOR_OPTION:
group_separator = optarg;
break;
case LINE_BUFFERED_OPTION:
- line_buffered = 1;
- break;
+ line_buffered = 1;
+ break;
case LABEL_OPTION:
- label = optarg;
- break;
+ label = optarg;
+ break;
case 0:
- /* long options */
- break;
+ /* long options */
+ break;
default:
- usage (EXIT_TROUBLE);
- break;
+ usage (EXIT_TROUBLE);
+ break;
}
@@ -2100,7 +2100,7 @@ main (int argc, char **argv)
/* Legacy. */
char *userval = getenv ("GREP_COLOR");
if (userval != NULL && *userval != '\0')
- selected_match_color = context_match_color = userval;
+ selected_match_color = context_match_color = userval;
/* New GREP_COLORS has priority. */
parse_grep_colors();
@@ -2125,22 +2125,22 @@ There is NO WARRANTY, to the extent permitted by law.\n"),
if (keys)
{
if (keycc == 0)
- {
- /* No keys were specified (e.g. -f /dev/null). Match nothing. */
- out_invert ^= 1;
- match_lines = match_words = 0;
- }
+ {
+ /* No keys were specified (e.g. -f /dev/null). Match nothing. */
+ out_invert ^= 1;
+ match_lines = match_words = 0;
+ }
else
- /* Strip trailing newline. */
+ /* Strip trailing newline. */
--keycc;
}
else
if (optind < argc)
{
- /* A copy must be made in case of an xrealloc() or free() later. */
- keycc = strlen(argv[optind]);
- keys = xmalloc(keycc + 1);
- strcpy(keys, argv[optind++]);
+ /* A copy must be made in case of an xrealloc() or free() later. */
+ keycc = strlen(argv[optind]);
+ keys = xmalloc(keycc + 1);
+ strcpy(keys, argv[optind++]);
}
else
usage (EXIT_TROUBLE);
@@ -2164,24 +2164,24 @@ There is NO WARRANTY, to the extent permitted by law.\n"),
if (optind < argc)
{
- status = 1;
- do
- {
- char *file = argv[optind];
- if ((included_patterns || excluded_patterns)
- && !isdir (file))
- {
- if (included_patterns &&
- ! excluded_file_name (included_patterns, file))
- continue;
- if (excluded_patterns &&
- excluded_file_name (excluded_patterns, file))
- continue;
- }
- status &= grepfile (STREQ (file, "-") ? (char *) NULL : file,
- &stats_base);
- }
- while ( ++optind < argc);
+ status = 1;
+ do
+ {
+ char *file = argv[optind];
+ if ((included_patterns || excluded_patterns)
+ && !isdir (file))
+ {
+ if (included_patterns &&
+ ! excluded_file_name (included_patterns, file))
+ continue;
+ if (excluded_patterns &&
+ excluded_file_name (excluded_patterns, file))
+ continue;
+ }
+ status &= grepfile (STREQ (file, "-") ? (char *) NULL : file,
+ &stats_base);
+ }
+ while ( ++optind < argc);
}
else
status = grepfile ((char *) NULL, &stats_base);
diff --git a/src/pcresearch.c b/src/pcresearch.c
index 795f4c4c..7973dbbf 100644
--- a/src/pcresearch.c
+++ b/src/pcresearch.c
@@ -39,8 +39,8 @@ Pcompile (char const *pattern, size_t size)
{
#if !HAVE_LIBPCRE
error (EXIT_TROUBLE, 0, "%s",
- _("support for the -P option is not compiled into "
- "this --disable-perl-regexp binary"));
+ _("support for the -P option is not compiled into "
+ "this --disable-perl-regexp binary"));
#else
int e;
char const *ep;
@@ -75,7 +75,7 @@ Pcompile (char const *pattern, size_t size)
memcpy (n, p, pnul - p);
n += pnul - p;
for (p = pnul; pattern < p && p[-1] == '\\'; p--)
- continue;
+ continue;
n -= (pnul - p) & 1;
strcpy (n, "\\000");
n += 4;
@@ -103,7 +103,7 @@ Pcompile (char const *pattern, size_t size)
size_t
Pexecute (char const *buf, size_t size, size_t *match_size,
- char const *start_ptr)
+ char const *start_ptr)
{
#if !HAVE_LIBPCRE
abort ();
@@ -141,16 +141,16 @@ Pexecute (char const *buf, size_t size, size_t *match_size,
if (e <= 0)
{
switch (e)
- {
- case PCRE_ERROR_NOMATCH:
- return -1;
+ {
+ case PCRE_ERROR_NOMATCH:
+ return -1;
- case PCRE_ERROR_NOMEMORY:
- error (EXIT_TROUBLE, 0, _("memory exhausted"));
+ case PCRE_ERROR_NOMEMORY:
+ error (EXIT_TROUBLE, 0, _("memory exhausted"));
- default:
- abort ();
- }
+ default:
+ abort ();
+ }
}
else
{
@@ -160,18 +160,18 @@ Pexecute (char const *buf, size_t size, size_t *match_size,
char const *buflim = buf + size;
char eol = eolbyte;
if (!start_ptr)
- {
- /* FIXME: The case when '\n' is not found indicates a bug:
- Since grep is line oriented, the match should never contain
- a newline, so there _must_ be a newline following.
- */
- if (!(end = memchr (end, eol, buflim - end)))
- end = buflim;
- else
- end++;
- while (buf < beg && beg[-1] != eol)
- --beg;
- }
+ {
+ /* FIXME: The case when '\n' is not found indicates a bug:
+ Since grep is line oriented, the match should never contain
+ a newline, so there _must_ be a newline following.
+ */
+ if (!(end = memchr (end, eol, buflim - end)))
+ end = buflim;
+ else
+ end++;
+ while (buf < beg && beg[-1] != eol)
+ --beg;
+ }
*match_size = end - beg;
return beg - buf;
diff --git a/src/searchutils.c b/src/searchutils.c
index ee7d9ae4..11924856 100644
--- a/src/searchutils.c
+++ b/src/searchutils.c
@@ -121,7 +121,7 @@ mbtolower (const char *beg, size_t *n)
bool
is_mb_middle (const char **good, const char *buf, const char *end,
- size_t match_len)
+ size_t match_len)
{
const char *p = *good;
const char *prev = p;
@@ -138,12 +138,12 @@ is_mb_middle (const char **good, const char *buf, const char *end,
prev = p;
if (mbclen == (size_t) -1 || mbclen == (size_t) -2 || mbclen == 0)
- {
- /* An invalid sequence, or a truncated multibyte character.
- We treat it as a single byte character. */
- mbclen = 1;
- memset(&cur_state, 0, sizeof cur_state);
- }
+ {
+ /* An invalid sequence, or a truncated multibyte character.
+ We treat it as a single byte character. */
+ mbclen = 1;
+ memset(&cur_state, 0, sizeof cur_state);
+ }
p += mbclen;
}
diff --git a/tests/backref.sh b/tests/backref.sh
index d76206ff..de415c9c 100755
--- a/tests/backref.sh
+++ b/tests/backref.sh
@@ -29,15 +29,15 @@ fi
# backref are local should be error
echo "123" | ${GREP} -e 'a\(.\)' -e 'b\1' > /dev/null 2>&1
if test $? -ne 2 ; then
- echo "Backref: Backref not local, test #3 failed"
- failures=1
+ echo "Backref: Backref not local, test #3 failed"
+ failures=1
fi
# Pattern should fail
echo "123" | ${GREP} -e '[' -e ']' > /dev/null 2>&1
if test $? -ne 2 ; then
- echo "Backref: Compiled not local, test #4 failed"
- failures=1
+ echo "Backref: Compiled not local, test #4 failed"
+ failures=1
fi
exit $failures
diff --git a/tests/bre.awk b/tests/bre.awk
index d8aad74e..7bc0f0f6 100644
--- a/tests/bre.awk
+++ b/tests/bre.awk
@@ -5,21 +5,21 @@
# notice and this notice are preserved.
BEGIN {
- FS="@";
- n = 0;
- printf ("# Generated Spencer BRE Test\n");
- printf ("failures=0\n");
+ FS="@";
+ n = 0;
+ printf ("# Generated Spencer BRE Test\n");
+ printf ("failures=0\n");
}
$0 ~ /^#/ { next; }
NF == 3 {
# printf ("status=$(echo '%s' | { ${GREP} -e '%s' > /dev/null 2>&1; echo $?; cat >/dev/null; })\n",$3, $2);
- printf ("status=$(echo '%s' | { ${GREP} -e '%s' > /dev/null 2>&1; echo $? ; })\n",$3, $2);
- printf ("if test $status -ne %s ; then\n", $1);
- printf ("\techo Spencer bre test \\#%d failed\n", ++n);
- printf ("\tfailures=1\n");
- printf ("fi\n");
+ printf ("status=$(echo '%s' | { ${GREP} -e '%s' > /dev/null 2>&1; echo $? ; })\n",$3, $2);
+ printf ("if test $status -ne %s ; then\n", $1);
+ printf ("\techo Spencer bre test \\#%d failed\n", ++n);
+ printf ("\tfailures=1\n");
+ printf ("fi\n");
}
NF == 4 {
diff --git a/tests/empty b/tests/empty
index 9e8f3359..d4e7fbdb 100755
--- a/tests/empty
+++ b/tests/empty
@@ -18,66 +18,66 @@ failures=0
for locale in C en_US.UTF-8; do
for options in '-E' '-F'; do
- # should return 0 found a match
- echo "" | LC_ALL=$locale timeout 10s grep $options -e ''
- if test $? -ne 0 ; then
- echo "Status: Wrong status code, test \#1 failed ($options $locale)"
- failures=1
- fi
+ # should return 0 found a match
+ echo "" | LC_ALL=$locale timeout 10s grep $options -e ''
+ if test $? -ne 0 ; then
+ echo "Status: Wrong status code, test \#1 failed ($options $locale)"
+ failures=1
+ fi
- # should return 1 found no match
- echo "abcd" | LC_ALL=$locale timeout 10s grep $options -f /dev/null
- if test $? -ne 1 ; then
- echo "Status: Wrong status code, test \#2 failed ($options $locale)"
- failures=1
- fi
+ # should return 1 found no match
+ echo "abcd" | LC_ALL=$locale timeout 10s grep $options -f /dev/null
+ if test $? -ne 1 ; then
+ echo "Status: Wrong status code, test \#2 failed ($options $locale)"
+ failures=1
+ fi
- # should return 0 found a match
- echo "abcd" | LC_ALL=$locale timeout 10s grep $options -f /dev/null -e "abcd"
- if test $? -ne 0 ; then
- echo "Status: Wrong status code, test \#3 failed ($options $locale)"
- failures=1
- fi
+ # should return 0 found a match
+ echo "abcd" | LC_ALL=$locale timeout 10s grep $options -f /dev/null -e "abcd"
+ if test $? -ne 0 ; then
+ echo "Status: Wrong status code, test \#3 failed ($options $locale)"
+ failures=1
+ fi
- # should return 0 found a match
- echo "" | LC_ALL=$locale timeout 10s grep $options -e ''
- if test $? -ne 0 ; then
- echo "Status: Wrong status code, test \#4 failed ($options $locale)"
- failures=1
- fi
+ # should return 0 found a match
+ echo "" | LC_ALL=$locale timeout 10s grep $options -e ''
+ if test $? -ne 0 ; then
+ echo "Status: Wrong status code, test \#4 failed ($options $locale)"
+ failures=1
+ fi
- # should return 0 found a match
- echo "abcd" | LC_ALL=$locale timeout 10s grep $options -e ''
- if test $? -ne 0 ; then
- echo "Status: Wrong status code, test \#5 failed ($options $locale)"
- failures=1
- fi
+ # should return 0 found a match
+ echo "abcd" | LC_ALL=$locale timeout 10s grep $options -e ''
+ if test $? -ne 0 ; then
+ echo "Status: Wrong status code, test \#5 failed ($options $locale)"
+ failures=1
+ fi
done
# -F -w omitted because it fails test #6, will be revisited after 2.6
# stabilizes.
for options in '-E -w' '-E -x' '-E -w -x' '-F -x' '-F -w -x'; do
- # should return 0 found a match
- echo "" | LC_ALL=$locale timeout 10s grep $options -e ''
- if test $? -ne 0 ; then
- echo "Status: Wrong status code, test \#6 failed ($options $locale)"
- failures=1
- fi
+ # should return 0 found a match
+ echo "" | LC_ALL=$locale timeout 10s grep $options -e ''
+ if test $? -ne 0 ; then
+ echo "Status: Wrong status code, test \#6 failed ($options $locale)"
+ failures=1
+ fi
- # should return 1 found no match
- echo "abcd" | LC_ALL=$locale timeout 10s grep $options -f /dev/null
- if test $? -ne 1 ; then
- echo "Status: Wrong status code, test \#7 failed ($options $locale)"
- failures=1
- fi
+ # should return 1 found no match
+ echo "abcd" | LC_ALL=$locale timeout 10s grep $options -f /dev/null
+ if test $? -ne 1 ; then
+ echo "Status: Wrong status code, test \#7 failed ($options $locale)"
+ failures=1
+ fi
- # should return 1 found no match
- echo "abcd" | LC_ALL=$locale timeout 10s grep $options -f /dev/null -e ""
- if test $? -ne 1 ; then
- echo "Status: Wrong status code, test \#8 failed ($options $locale)"
- failures=1
- fi
+ # should return 1 found no match
+ echo "abcd" | LC_ALL=$locale timeout 10s grep $options -f /dev/null -e ""
+ if test $? -ne 1 ; then
+ echo "Status: Wrong status code, test \#8 failed ($options $locale)"
+ failures=1
+ fi
done
done
diff --git a/tests/ere.awk b/tests/ere.awk
index 9a886bf5..90898a0b 100644
--- a/tests/ere.awk
+++ b/tests/ere.awk
@@ -5,21 +5,21 @@
# notice and this notice are preserved.
BEGIN {
- FS="@";
- n = 0;
- printf ("# Generated Spencer ERE Test\n");
- printf ("failures=0\n");
+ FS="@";
+ n = 0;
+ printf ("# Generated Spencer ERE Test\n");
+ printf ("failures=0\n");
}
$0 ~ /^#/ { next; }
NF == 3 {
# printf ("status=$(echo '%s' | { ${GREP} -E -e '%s' > /dev/null 2>&1; echo $?; cat >/dev/null; })\n",$3, $2);
- printf ("status=$(echo '%s' | { ${GREP} -E -e '%s' > /dev/null 2>&1; echo $?; })\n",$3, $2);
- printf ("if test $status -ne %s ; then\n", $1);
- printf ("\techo Spencer ere test \\#%d failed\n", ++n);
- printf ("\tfailures=1\n");
- printf ("fi\n");
+ printf ("status=$(echo '%s' | { ${GREP} -E -e '%s' > /dev/null 2>&1; echo $?; })\n",$3, $2);
+ printf ("if test $status -ne %s ; then\n", $1);
+ printf ("\techo Spencer ere test \\#%d failed\n", ++n);
+ printf ("\tfailures=1\n");
+ printf ("fi\n");
}
NF == 4 {
@@ -32,7 +32,7 @@ NF == 4 {
NF == 5 {
# don't alarm the user for now
- next;
+ next;
}
END { printf ("exit $failures\n"); }
diff --git a/tests/fedora b/tests/fedora
index 336d913c..a029999e 100644
--- a/tests/fedora
+++ b/tests/fedora
@@ -9,10 +9,10 @@
if [ -t 1 ]
then
- # Colored output on terimal
- G='\033[32m'
- R='\033[31m'
- D='\033[0m'
+ # Colored output on terimal
+ G='\033[32m'
+ R='\033[31m'
+ D='\033[0m'
fi
ok () { printf "${G}OK${D}"; }
diff --git a/tests/file.sh b/tests/file.sh
index 18d90175..6dbaf225 100755
--- a/tests/file.sh
+++ b/tests/file.sh
@@ -37,8 +37,8 @@ fi
# checking for no match
echo "ridar" | ${GREP} -F -f patfile > /dev/null 2>&1
if test $? -ne 1 ; then
- echo "File_pattern: Wrong status code, test \#3 failed"
- failures=1
+ echo "File_pattern: Wrong status code, test \#3 failed"
+ failures=1
fi
cat <<EOF >patfile
@@ -47,8 +47,8 @@ EOF
# empty pattern : every match
echo "abbcd" | ${GREP} -F -f patfile > /dev/null 2>&1
if test $? -ne 0 ; then
- echo "File_pattern: Wrong status code, test \#4 failed"
- failures=1
+ echo "File_pattern: Wrong status code, test \#4 failed"
+ failures=1
fi
cp /dev/null patfile
@@ -56,8 +56,8 @@ cp /dev/null patfile
# null pattern : no match
echo "abbcd" | ${GREP} -F -f patfile > /dev/null 2>&1
if test $? -ne 1 ; then
- echo "File_pattern: Wrong status code, test \#5 failed"
- failures=1
+ echo "File_pattern: Wrong status code, test \#5 failed"
+ failures=1
fi
exit $failures
diff --git a/tests/fmbtest b/tests/fmbtest
index 6fd6d0a9..be0b886d 100755
--- a/tests/fmbtest
+++ b/tests/fmbtest
@@ -52,21 +52,21 @@ EOF
for mode in F G E; do
test1="$(echo $(LC_ALL=cs_CZ.UTF-8 grep -${mode} -f cspatfile csinput \
- | LC_ALL=C sed 's/^.*\([0-9][0-9]\).*$/\1/'))"
+ | LC_ALL=C sed 's/^.*\([0-9][0-9]\).*$/\1/'))"
if test "$test1" != "11 12 13 14 15 16 17 18"; then
echo "Test #1 ${mode} failed: $test1"
failures=1
fi
test2="$(echo $(LC_ALL=cs_CZ.UTF-8 grep -${mode}i -f cspatfile csinput \
- | LC_ALL=C sed 's/^.*\([0-9][0-9]\).*$/\1/'))"
+ | LC_ALL=C sed 's/^.*\([0-9][0-9]\).*$/\1/'))"
if test "$test2" != "01 02 07 08 10 11 12 13 14 15 16 17 18 19 20"; then
echo "Test #2 ${mode} failed: $test2"
failures=1
fi
test3="$(echo $(LC_ALL=cs_CZ.UTF-8 grep -${mode}i -e 'ČÍšE' -e 'Čas' csinput \
- | LC_ALL=C sed 's/^.*\([0-9][0-9]\).*$/\1/'))"
+ | LC_ALL=C sed 's/^.*\([0-9][0-9]\).*$/\1/'))"
if test "$test3" != "01 02 07 08 10 11 12 13 14 15 16 17 18 19 20"; then
echo "Test #3 ${mode} failed: $test3"
failures=1
@@ -83,7 +83,7 @@ fi
# Test that --color=always does not depend on individual pattern order within the pattern
# list, and that a longer match is preferred to a shorter one starting at the same point.
test6="$(echo 'Cosi tu ČišÍ...' \
- | LC_ALL=cs_CZ.UTF-8 grep --color=always -${mode}i -e 'čiš' -e 'čiší')"
+ | LC_ALL=cs_CZ.UTF-8 grep --color=always -${mode}i -e 'čiš' -e 'čiší')"
if echo "$test6" | LC_ALL=C grep -q 'Cosi tu .*\[.*m\(.\[K\)\?ČišÍ.*\[.*m\(.\[K\)\?\.\.\.'; then
:
else
@@ -94,7 +94,7 @@ fi
# Test that --color=always does not depend on individual pattern order within the pattern
# list, and that a longer match is preferred to a shorter one starting at the same point.
test7="$(echo 'Cosi tu ČišÍ...' \
- | LC_ALL=cs_CZ.UTF-8 grep --color=always -${mode}i -e 'čiší' -e 'čiš')"
+ | LC_ALL=cs_CZ.UTF-8 grep --color=always -${mode}i -e 'čiší' -e 'čiš')"
if echo "$test7" | LC_ALL=C grep -q 'Cosi tu .*\[.*m\(.\[K\)\?ČišÍ.*\[.*m\(.\[K\)\?\.\.\.'; then
:
else
@@ -107,7 +107,7 @@ done
for mode in G E; do
test8="$(echo $(LC_ALL=cs_CZ.UTF-8 grep -${mode}i -e 'Č.šE' -e 'Č[a-f]s' csinput \
- | LC_ALL=C sed 's/^.*\([0-9][0-9]\).*$/\1/'))"
+ | LC_ALL=C sed 's/^.*\([0-9][0-9]\).*$/\1/'))"
if test "$test8" != "01 02 07 08 10 11 12 13 14 15 16 17 18 19 20"; then
echo "Test #8 ${mode} failed: $test8"
failures=1
diff --git a/tests/khadafy.sh b/tests/khadafy.sh
index 19d299b7..583f42a3 100755
--- a/tests/khadafy.sh
+++ b/tests/khadafy.sh
@@ -17,10 +17,10 @@ failures=0
${GREP} -E -f $srcdir/khadafy.regexp $srcdir/khadafy.lines > khadafy.out
if cmp $srcdir/khadafy.lines khadafy.out
then
- :
+ :
else
- echo Khadafy test failed -- output left on khadafy.out
- failures=1
+ echo Khadafy test failed -- output left on khadafy.out
+ failures=1
fi
exit $failures
diff --git a/tests/options.sh b/tests/options.sh
index ce2c3398..6b2b9a5a 100755
--- a/tests/options.sh
+++ b/tests/options.sh
@@ -34,8 +34,8 @@ fi
# checking for fixed string
echo "abababccccccd" | ${GREP} -F -e 'c\{3\}' > /dev/null 2>&1
if test $? -ne 1 ; then
- echo "Options: Wrong status code, test \#3 failed"
- failures=1
+ echo "Options: Wrong status code, test \#3 failed"
+ failures=1
fi
exit $failures
diff --git a/tests/spencer1-locale.awk b/tests/spencer1-locale.awk
index 759cafc6..9d224205 100644
--- a/tests/spencer1-locale.awk
+++ b/tests/spencer1-locale.awk
@@ -6,8 +6,8 @@
# notice and this notice are preserved.
BEGIN {
- FS = "@";
- printf ("failures=0\n");
+ FS = "@";
+ printf ("failures=0\n");
}
$0 !~ /^#/ && NF == 3 {
@@ -15,18 +15,18 @@ $0 !~ /^#/ && NF == 3 {
test("ru_RU.KOI8-R")
test("fr_FR.ISO-8859-1")
test("zh_CN")
- if (extra_locale != "") {
- test(extra_locale)
- }
+ if (extra_locale != "") {
+ test(extra_locale)
+ }
}
function test(locale)
{
- printf ("status=$(echo '%s'| { LC_ALL=%s grep -E -e '%s' >/dev/null 2>&1 ; echo $?; })\n",$3, locale, $2);
- printf ("if test $status -ne %s ; then\n", $1);
- printf ("\techo Spencer test \\#%d failed \\(%s\\)\n", ++n, locale);
- printf ("\tfailures=1\n");
- printf ("fi\n");
+ printf ("status=$(echo '%s'| { LC_ALL=%s grep -E -e '%s' >/dev/null 2>&1 ; echo $?; })\n",$3, locale, $2);
+ printf ("if test $status -ne %s ; then\n", $1);
+ printf ("\techo Spencer test \\#%d failed \\(%s\\)\n", ++n, locale);
+ printf ("\tfailures=1\n");
+ printf ("fi\n");
}
END { printf ("exit $failures\n"); }
diff --git a/tests/spencer1.awk b/tests/spencer1.awk
index 06f90b76..ec5ab2da 100644
--- a/tests/spencer1.awk
+++ b/tests/spencer1.awk
@@ -6,17 +6,17 @@
# notice and this notice are preserved.
BEGIN {
- FS = "@";
- printf ("failures=0\n");
+ FS = "@";
+ printf ("failures=0\n");
}
$0 !~ /^#/ && NF == 3 {
# printf ("status=$(echo '%s'| { ${GREP} -E -e '%s' > /dev/null 2>&1; echo $?; cat >/dev/null; })\n",$3, $2);
- printf ("status=$(echo '%s'| { ${GREP} -E -e '%s' >/dev/null 2>&1 ; echo $?; })\n",$3, $2);
- printf ("if test $status -ne %s ; then\n", $1);
- printf ("\techo Spencer test \\#%d failed\n", ++n);
- printf ("\tfailures=1\n");
- printf ("fi\n");
+ printf ("status=$(echo '%s'| { ${GREP} -E -e '%s' >/dev/null 2>&1 ; echo $?; })\n",$3, $2);
+ printf ("if test $status -ne %s ; then\n", $1);
+ printf ("\techo Spencer test \\#%d failed\n", ++n);
+ printf ("\tfailures=1\n");
+ printf ("fi\n");
}
END { printf ("exit $failures\n"); }
diff --git a/tests/status.sh b/tests/status.sh
index d6216d2c..9d5e754a 100755
--- a/tests/status.sh
+++ b/tests/status.sh
@@ -31,42 +31,42 @@ fi
# the filename MMMMMMMM.MMM should not exist hopefully
if test -r MMMMMMMM.MMM; then
- echo "Please remove MMMMMMMM.MMM to run check"
+ echo "Please remove MMMMMMMM.MMM to run check"
else
- # should return 2 file not found
- ${GREP} -E -e 'abc' MMMMMMMM.MMM > /dev/null 2>&1
- if test $? -ne 2 ; then
- echo "Status: Wrong status code, test \#3 failed"
- failures=1
- fi
+ # should return 2 file not found
+ ${GREP} -E -e 'abc' MMMMMMMM.MMM > /dev/null 2>&1
+ if test $? -ne 2 ; then
+ echo "Status: Wrong status code, test \#3 failed"
+ failures=1
+ fi
- # should return 2 file not found
- ${GREP} -E -s -e 'abc' MMMMMMMM.MMM > /dev/null 2>&1
- if test $? -ne 2 ; then
- echo "Status: Wrong status code, test \#4 failed"
- failures=1
- fi
+ # should return 2 file not found
+ ${GREP} -E -s -e 'abc' MMMMMMMM.MMM > /dev/null 2>&1
+ if test $? -ne 2 ; then
+ echo "Status: Wrong status code, test \#4 failed"
+ failures=1
+ fi
- # should return 2 file not found
- echo "abcd" | ${GREP} -E -s 'abc' - MMMMMMMM.MMM > /dev/null 2>&1
- if test $? -ne 2 ; then
- echo "Status: Wrong status code, test \#5 failed"
- failures=1
- fi
+ # should return 2 file not found
+ echo "abcd" | ${GREP} -E -s 'abc' - MMMMMMMM.MMM > /dev/null 2>&1
+ if test $? -ne 2 ; then
+ echo "Status: Wrong status code, test \#5 failed"
+ failures=1
+ fi
- # should return 0 found a match
- echo "abcd" | ${GREP} -E -q -s 'abc' MMMMMMMM.MMM - > /dev/null 2>&1
- if test $? -ne 0 ; then
- echo "Status: Wrong status code, test \#6 failed"
- failures=1
- fi
+ # should return 0 found a match
+ echo "abcd" | ${GREP} -E -q -s 'abc' MMMMMMMM.MMM - > /dev/null 2>&1
+ if test $? -ne 0 ; then
+ echo "Status: Wrong status code, test \#6 failed"
+ failures=1
+ fi
- # should still return 0 found a match
- echo "abcd" | ${GREP} -E -q 'abc' MMMMMMMM.MMM - > /dev/null 2>&1
- if test $? -ne 0 ; then
- echo "Status: Wrong status code, test \#7 failed"
- failures=1
- fi
+ # should still return 0 found a match
+ echo "abcd" | ${GREP} -E -q 'abc' MMMMMMMM.MMM - > /dev/null 2>&1
+ if test $? -ne 0 ; then
+ echo "Status: Wrong status code, test \#7 failed"
+ failures=1
+ fi
fi
exit $failures