diff options
author | Jim Meyering <meyering@fb.com> | 2023-04-08 18:16:46 -0700 |
---|---|---|
committer | Jim Meyering <meyering@meta.com> | 2023-04-09 22:22:42 -0700 |
commit | 88b2d37c0a975b736841f66c1b64401bb4d329f3 (patch) | |
tree | 35214a8e534ee64e339c0942d8b8f0a08a0e3ee7 | |
parent | 19d2275fd1195f00e4ffc90a03b388c55d858681 (diff) | |
download | grep-88b2d37c0a975b736841f66c1b64401bb4d329f3.tar.gz |
grep: --version: print pcre version info
PCRE is integral to the functioning of grep's -P option, so it is in our
interest to make it easy to see which version of PCRE grep uses.
* src/grep.c [HAVE_LIBPCRE]: Include <pcre2.h>.
[HAVE_LIBPCRE] (main): Print pcre version info.
* tests/version-pcre: New test for this.
* tests/Makefile.am (TESTS): Add the file name.
* NEWS (Changes in behavior): Mention it.
-rw-r--r-- | NEWS | 8 | ||||
-rw-r--r-- | src/grep.c | 11 | ||||
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rwxr-xr-x | tests/version-pcre | 15 |
4 files changed, 36 insertions, 0 deletions
@@ -14,6 +14,14 @@ GNU grep NEWS -*- outline -*- when running on 32-bit x86 and ARM hosts using glibc 2.34+. [bug introduced in grep 3.9] +** Changes in behavior + + grep --version now prints a line describing the version of PCRE2 it uses. + For example, it prints this when built with the very latest from git: + Built with PCRE 10.43-DEV 2023-01-15 + or this with what's currently available in Fedora 37: + Built with PCRE 10.40 2022-04-14 + * Noteworthy changes in release 3.10 (2023-03-22) [stable] @@ -29,6 +29,11 @@ #include <stdio.h> #include "system.h" +#if HAVE_LIBPCRE +# define PCRE2_CODE_UNIT_WIDTH 8 +# include <pcre2.h> +#endif + #include "argmatch.h" #include "c-ctype.h" #include "c-stack.h" @@ -2830,6 +2835,12 @@ main (int argc, char **argv) (char *) NULL); puts (_("Written by Mike Haertel and others; see\n" "<https://git.savannah.gnu.org/cgit/grep.git/tree/AUTHORS>.")); +#if HAVE_LIBPCRE + unsigned char buf[128]; + (void) pcre2_config (PCRE2_CONFIG_VERSION, buf); + fputs (_("\nBuilt with PCRE "), stdout); + puts ((char *) buf); +#endif return EXIT_SUCCESS; } diff --git a/tests/Makefile.am b/tests/Makefile.am index c9376b19..0ef96d44 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -178,6 +178,7 @@ TESTS = \ unibyte-bracket-expr \ unibyte-negated-circumflex \ utf8-bracket \ + version-pcre \ warn-char-classes \ word-delim-multibyte \ word-multi-file \ @@ -254,6 +255,7 @@ TESTS_ENVIRONMENT = \ srcdir='$(srcdir)' \ top_srcdir='$(top_srcdir)' \ CC='$(CC)' \ + CONFIG_HEADER='$(abs_top_builddir)/$(CONFIG_INCLUDE)' \ GREP_TEST_NAME=`echo $$tst|sed 's,^\./,,;s,/,-,g'` \ MAKE=$(MAKE) \ MALLOC_PERTURB_=$(MALLOC_PERTURB_) \ diff --git a/tests/version-pcre b/tests/version-pcre new file mode 100755 index 00000000..d18daa69 --- /dev/null +++ b/tests/version-pcre @@ -0,0 +1,15 @@ +#! /bin/sh +# Test for presence of pcre version number in --version output. +# +# Copyright (C) 2023 Free Software Foundation, Inc. +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. + +. "${srcdir=.}/init.sh"; path_prepend_ ../src + +grep -q '^#define HAVE_LIBPCRE 1' "$CONFIG_HEADER" \ + || skip_ 'built without PCRE support' + +grep --version | grep -qP '^Built with PCRE [\d.]+' |