Skip to content

Commit

Permalink
Add PCRE support
Browse files Browse the repository at this point in the history
Closes #1137
  • Loading branch information
koutcher committed Sep 11, 2021
1 parent 529182c commit 3d069a8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
2 changes: 2 additions & 0 deletions INSTALL.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ configure script and building documentation:
|Tool |Description
|readline |Adds support for completion and history in
search and command prompts.
|PCRE |Adds support for Perl Compatible Regular
Expressions in searches.
|autoconf |Contains autoreconf for generating configure
from configure.ac.
|asciidoc (>= 8.4) |Generates HTML and (DocBook) XML from text.
Expand Down
23 changes: 22 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,33 @@ AX_LIB_READLINE(6.3)

AM_ICONV

dnl Check for PCRE (Perl Compatible Regular Expressions) library
AC_ARG_WITH(pcre, [AS_HELP_STRING([--without-pcre], [do not use PCRE (Perl Compatible Regular Expressions) library])])
AS_IF([test "x$with_pcre" != xno], [
AC_CHECK_HEADERS([pcre2posix.h])
AS_IF([test "x$ac_cv_header_pcre2posix_h" = xyes], [
AC_CHECK_LIB([pcre2-posix], [regexec], [
AC_DEFINE([HAVE_PCRE2], [1], [Define if you have PCRE2])
LIBS="$LIBS -lpcre2-posix -lpcre2-8"
])
])
AS_IF([test "x$ac_cv_lib_pcre2_posix_regexec" != xyes], [
AC_CHECK_HEADERS([pcreposix.h])
AS_IF([test "x$ac_cv_header_pcreposix_h" = xyes], [
AC_CHECK_LIB([pcreposix], [regexec], [
AC_DEFINE([HAVE_PCRE], [1], [Define if you have PCRE])
LIBS="$LIBS -lpcreposix -lpcre"
])
])
])
])

dnl OS-specific
case $(uname -s 2>/dev/null || echo unknown) in "OS400")
AC_CHECK_LIB(util, main, [LIBS="$LIBS -lutil"], AC_MSG_ERROR([Please install the libutil-devel package]))
;;
esac

AC_CHECK_PROGS(SED, [gsed], [sed])
AC_TDD_GCOV
AC_SUBST(COVERAGE_CFLAGS)
Expand Down
6 changes: 6 additions & 0 deletions include/tig/tig.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@
#include <libgen.h>
#include <termios.h>

#if defined HAVE_PCRE2
#include <pcre2posix.h>
#elif defined HAVE_PCRE
#include <pcreposix.h>
#else
#include <regex.h>
#endif

#include <locale.h>
#include <langinfo.h>
Expand Down
10 changes: 6 additions & 4 deletions src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@ setup_and_find_next(struct view *view, enum request request)
&& !utf8_string_contains_uppercase(view->env->search))
regex_flags |= REG_ICASE;

if (view->regex) {
regfree(view->regex);
*view->grep = 0;
} else {
if (!view->regex) {
view->regex = calloc(1, sizeof(*view->regex));
if (!view->regex)
return ERROR_OUT_OF_MEMORY;
}

if (*view->grep) {
regfree(view->regex);
*view->grep = 0;
}

regex_err = regcomp(view->regex, view->env->search, REG_EXTENDED | regex_flags);
if (regex_err != 0) {
char buf[SIZEOF_STR] = "unknown error";
Expand Down

0 comments on commit 3d069a8

Please sign in to comment.