Skip to content

Commit

Permalink
released 1.3.3: improved -E, -G, -P GNU/BSD grep compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-van-Engelen committed Jul 26, 2019
1 parent b1970fa commit 0c5f1e3
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,7 @@ Man page



ugrep 1.3.2 July 25, 2019 UGREP(1)
ugrep 1.3.3 July 26, 2019 UGREP(1)

<a name="patterns"/>

Expand Down
Binary file modified bin/linux/ugrep
Binary file not shown.
Binary file modified bin/macosx/ugrep
Binary file not shown.
Binary file modified bin/windows/ugrep.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion man/ugrep.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH UGREP "1" "July 25, 2019" "ugrep 1.3.2" "User Commands"
.TH UGREP "1" "July 26, 2019" "ugrep 1.3.3" "User Commands"
.SH NAME
\fBugrep\fR -- universal file pattern searcher
.SH SYNOPSIS
Expand Down
13 changes: 9 additions & 4 deletions patterns/README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
ugrep predefined patterns
=========================

This directory contains a collection of patterns that are helpful to search
source code files. Use ugrep option `-f` to specify one or more pattern files
to use for searching these patterns in files.

The list of patterns defined in this directory will expand over time.

For example, to display all class defitions in C++ files in myproject directory:
For example, to display class definitions in C++ files in the working directory

ugrep -R -o -tc++ -f c++/classes myproject
ugrep -r -o -tc++ -f c++/classes

To display Java identifiers (Unicode) with the line numbers of the matches, but
skipping all matches of identifiers in comments and strings:

ugrep -R -n -o -f java/names -f java/zap_comments -f java/zap_strings myproject
ugrep -r -n -o -f java/names -f java/zap_comments -f java/zap_strings

Some patterns automatically enable ugrep option `-o` to match multiple lines.
These pattern files start with `###-o` to enbale option `-o` that is required
to match the pattern across multiple lines. For example, strings and comments
may span multiple lines, such as Python docstrings, requiring option `-o`.

Patterns requiring Unicode matching are placed in Unicode mode with (?u:X),
Empty lines and lines starting with a `#` are ignored.

Patterns requiring Unicode matching are placed in Unicode mode with `(?u:X)`,
just in case to prevent ugrep option -U from disabling them.

We love your contributions to this effort! ❤️
Expand Down
2 changes: 1 addition & 1 deletion patterns/php/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ PHP patterns
- `names` matches identifiers (and keywords)
- `strings` matches strings, auto-enables ugrep option -o to match multi-line strings
- `zap_comments` removes comments from matches, recommend ugrep option -o
- `zap_html` removes HTML content outside of <?php...?>, auto-enables ugrep option -o
- `zap_html` removes HTML content outside of `<?php...?>` blocks, auto-enables ugrep option -o
- `zap_strings` removes strings from matches, recommend ugrep option -o
26 changes: 18 additions & 8 deletions src/ugrep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Optional libraries:
#endif

// ugrep version info
#define UGREP_VERSION "1.3.2"
#define UGREP_VERSION "1.3.3"

// ugrep platform -- see configure.ac
#if !defined(PLATFORM)
Expand Down Expand Up @@ -476,7 +476,7 @@ int main(int argc, char **argv)
else if (strncmp(arg, "exclude-from=", 13) == 0)
flag_exclude_from.emplace_back(arg + 13);
else if (strcmp(arg, "extended-regexp") == 0)
;
flag_basic_regexp = false;
else if (strncmp(arg, "file=", 5) == 0)
flag_file.emplace_back(arg + 5);
else if (strncmp(arg, "file-extensions=", 16) == 0)
Expand Down Expand Up @@ -554,7 +554,7 @@ int main(int argc, char **argv)
else if (strncmp(arg, "pager=", 6) == 0)
flag_pager = arg + 6;
else if (strcmp(arg, "perl-regexp") == 0)
flag_perl_regexp = true;
flag_basic_regexp = !(flag_perl_regexp = true);
else if (strcmp(arg, "quiet") == 0 || strcmp(arg, "silent") == 0)
flag_quiet = flag_no_messages = true;
else if (strcmp(arg, "recursive") == 0)
Expand Down Expand Up @@ -650,6 +650,7 @@ int main(int argc, char **argv)
break;

case 'E':
flag_basic_regexp = false;
break;

case 'e':
Expand Down Expand Up @@ -774,6 +775,7 @@ int main(int argc, char **argv)

case 'P':
flag_perl_regexp = true;
flag_basic_regexp = false;
break;

case 'p':
Expand Down Expand Up @@ -894,7 +896,7 @@ int main(int argc, char **argv)
#ifndef HAVE_LIBZ
// -z: but we don't have libz
if (flag_decompress)
help("option -z is disabled");
help("option -z is not available in this version of ugrep");
#endif

// -t list: list table of types
Expand Down Expand Up @@ -1394,6 +1396,9 @@ int main(int argc, char **argv)

// enable --break
flag_break = true;

// enable --line-buffered to flush output to the pager immediately
flag_line_buffered = true;
}
#endif

Expand Down Expand Up @@ -1468,16 +1473,18 @@ int main(int argc, char **argv)
help("invalid --tabs=NUM value");
}

#ifdef HAVE_BOOST_REGEX
if (flag_perl_regexp)
{
#ifdef HAVE_BOOST_REGEX
// construct the NFA pattern matcher
std::string pattern(reflex::BoostPerlMatcher::convert(regex, convert_flags));
reflex::BoostPerlMatcher matcher(pattern, matcher_options.c_str());
found = findinfiles(magic, matcher, infiles, encoding);
#else
help("Option -P is not available in this version of ugrep");
#endif
}
else
#endif
{
// construct the DFA pattern matcher
reflex::Pattern pattern(reflex::Matcher::convert(regex, convert_flags), "r");
Expand All @@ -1499,7 +1506,7 @@ int main(int argc, char **argv)
{
if (!flag_no_messages)
{
std::cerr << "Boost regex error at position " << error.position() << " in " << regex << std::endl;
std::cerr << "Boost regex error in " << regex << std::endl;
switch (error.code())
{
case boost::regex_constants::error_collate:
Expand Down Expand Up @@ -2774,9 +2781,12 @@ bool ugrep(reflex::AbstractMatcher& matcher, reflex::Input& input, const char *p
;
}

// --break: add a line break
// --break: add a line break and flush
if ((matches > 0 || flag_any_line) && flag_break)
{
fputc('\n', out);
fflush(out);
}

return matches > 0;
}
Expand Down

0 comments on commit 0c5f1e3

Please sign in to comment.