Skip to content

Commit e57989a

Browse files
committed
Some pcre improvements
Fixes #60 Assisted-by: Cursor
1 parent 8e9ed8d commit e57989a

5 files changed

Lines changed: 74 additions & 10 deletions

File tree

configure.ac

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,48 @@ dnl gnulib will handle getopt and error functions
5656
dnl Check pcre2 availability
5757
AC_MSG_CHECKING([whether PCRE2 support is requested])
5858
AC_ARG_WITH([pcre2],
59-
[AS_HELP_STRING([--with-pcre2],
60-
[use pcre2 regex library @<:@default=check@:>@])],
59+
[AS_HELP_STRING([--with-pcre2@<:@=PATH@:>@],
60+
[use pcre2 regex library, optionally from PATH @<:@default=check@:>@])],
6161
[], [with_pcre2=check])
6262
LIBPCRE2=
6363
AS_IF([test "x$with_pcre2" != xno],
6464
[
6565
AC_MSG_RESULT($with_pcre2)
66+
dnl Handle custom path for PCRE2
67+
AS_IF([test "x$with_pcre2" != xyes && test "x$with_pcre2" != xcheck],
68+
[
69+
dnl Custom path specified
70+
PCRE2_CPPFLAGS="-I$with_pcre2/include"
71+
PCRE2_LDFLAGS="-L$with_pcre2/lib"
72+
save_CPPFLAGS="$CPPFLAGS"
73+
save_LDFLAGS="$LDFLAGS"
74+
CPPFLAGS="$CPPFLAGS $PCRE2_CPPFLAGS"
75+
LDFLAGS="$LDFLAGS $PCRE2_LDFLAGS"
76+
])
6677
AC_CHECK_HEADERS([pcre2posix.h], [], [LIBPCRE2=_missing_header])
6778
AC_CHECK_LIB([pcre2-posix${LIBPCRE2}], [regexec],
68-
[],
69-
[if test "x$with_pcre2" != xcheck; then
70-
AC_MSG_FAILURE(
71-
[--with-pcre2 was given, but test for pcre2-posix failed])
72-
fi]
79+
[
80+
dnl Success - add the flags permanently if custom path was used
81+
AS_IF([test "x$with_pcre2" != xyes && test "x$with_pcre2" != xcheck],
82+
[
83+
CPPFLAGS="$save_CPPFLAGS $PCRE2_CPPFLAGS"
84+
LDFLAGS="$save_LDFLAGS $PCRE2_LDFLAGS"
85+
])
86+
dnl Add the library to LIBS
87+
LIBS="$LIBS -lpcre2-posix${LIBPCRE2}"
88+
],
89+
[
90+
dnl Failure - restore original flags if custom path was used
91+
AS_IF([test "x$with_pcre2" != xyes && test "x$with_pcre2" != xcheck],
92+
[
93+
CPPFLAGS="$save_CPPFLAGS"
94+
LDFLAGS="$save_LDFLAGS"
95+
])
96+
if test "x$with_pcre2" != xcheck; then
97+
AC_MSG_FAILURE(
98+
[--with-pcre2 was given, but test for pcre2-posix failed])
99+
fi
100+
]
73101
)
74102
],
75103
AC_MSG_RESULT(no)

doc/patchutils.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,10 @@ will pipe patch of file #2 to vim - -R
22662266
<para>The regular expression is treated as POSIX Basic Regular
22672267
Expression syntax, unless the <option>-E</option> option is
22682268
given in which case POSIX Extended Regular Expression syntax
2269-
is used.</para>
2269+
is used. When compiled with PCRE2 support, PCRE regular expressions
2270+
are used instead of POSIX regular expressions, and the <option>-E</option>
2271+
option has no effect since PCRE already supports extended regular
2272+
expression features by default.</para>
22702273

22712274
<para>For example, to see the patches in
22722275
<filename>my.patch</filename> which contain the regular
@@ -2497,7 +2500,9 @@ will pipe patch of file #2 to vim - -R
24972500
<option>--extended-regexp</option></term>
24982501
<listitem>
24992502
<para>Use POSIX Extended Regular Expression
2500-
syntax.</para>
2503+
syntax. Note: when compiled with PCRE2 support, this option
2504+
has no effect as PCRE regular expressions are used by default
2505+
and already support extended regular expression features.</para>
25012506
</listitem>
25022507
</varlistentry>
25032508

lib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ LIBGNU_LIBDEPS =
966966
LIBGNU_LTLIBDEPS =
967967
LIBINTL =
968968
LIBOBJS =
969-
LIBS = -lpcre2-posix
969+
LIBS = -lpcre2-posix
970970
LIMITS_H = limits.h
971971
LN_S = ln -s
972972
LOCALENAME_ENHANCE_LOCALE_FUNCS = 0

src/filterdiff.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,11 @@ const char * syntax_str =
12571257
" -v, --verbose\n"
12581258
" verbose output -- use more than once for extra verbosity\n"
12591259
" -E, --extended-regexp (grepdiff)\n"
1260+
#ifdef HAVE_PCRE2POSIX_H
1261+
" this option has no effect as PCRE regexes are used by default (grepdiff)\n"
1262+
#else
12601263
" use extended regexps, like egrep (grepdiff)\n"
1264+
#endif
12611265
" -E, --empty-files-as-absent (lsdiff)\n"
12621266
" treat empty files as absent (lsdiff)\n"
12631267
" -f FILE, --file=FILE (grepdiff)\n"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
3+
# Test for PCRE2 extended regexp functionality (GitHub issue #60)
4+
5+
. ${top_srcdir-.}/tests/common.sh
6+
7+
# Create a simple test diff with both patterns
8+
cat << EOF > diff
9+
--- file1
10+
+++ file1
11+
@@ -1,2 +1,3 @@
12+
context
13+
-old
14+
+landblockelim
15+
+blockall
16+
EOF
17+
18+
# Test extended regexp pattern with -E flag
19+
${GREPDIFF} -E 'landblockelim|blockall' diff 2>errors >output || exit 1
20+
21+
[ -s errors ] && exit 1
22+
23+
# Verify both patterns are found
24+
if ! grep -q "file1" output; then
25+
echo "ERROR: Extended regexp pattern failed to match"
26+
exit 1
27+
fi

0 commit comments

Comments
 (0)