summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2023-04-10 11:31:58 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2023-04-10 16:16:08 -0700
commitfd2d0f7165d390ce4b4d08acf25552f6635d9ecb (patch)
treea0dc3f7015d735ab9ad903363869ea6d8fcb0378 /src
parent3b15d738978fb5e4a865f5f6e99a08e8fc840948 (diff)
downloadgrep-fd2d0f7165d390ce4b4d08acf25552f6635d9ecb.tar.gz
grep: improve PCRE2 version output
* src/grep.c: No need to include pcre2.h. (main) [HAVE_LIBPCRE]: Call Pprint_version instead of doing it ourselves. * src/pcresearch.c (Pprint_version): New function. It also checks belatedly for buffer overflow, and says "grep -P uses PCRE2" instead of "Built with PCRE". * tests/version-pcre: Adjust test to match.
Diffstat (limited to 'src')
-rw-r--r--src/grep.c10
-rw-r--r--src/pcresearch.c9
-rw-r--r--src/search.h1
3 files changed, 11 insertions, 9 deletions
diff --git a/src/grep.c b/src/grep.c
index bd776e8b..491dd028 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -29,11 +29,6 @@
#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"
@@ -2836,10 +2831,7 @@ main (int argc, char **argv)
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);
+ Pprint_version ();
#endif
return EXIT_SUCCESS;
}
diff --git a/src/pcresearch.c b/src/pcresearch.c
index e77509c4..9e2f393d 100644
--- a/src/pcresearch.c
+++ b/src/pcresearch.c
@@ -74,6 +74,15 @@ private_free (void *ptr, _GL_UNUSED void *unused)
free (ptr);
}
+void
+Pprint_version (void)
+{
+ char buf[128];
+ if (sizeof buf <= pcre2_config (PCRE2_CONFIG_VERSION, buf))
+ abort ();
+ printf (_("\ngrep -P uses PCRE2 %s\n"), buf);
+}
+
/* Match the already-compiled PCRE pattern against the data in SUBJECT,
of size SEARCH_BYTES and starting with offset SEARCH_OFFSET, with
options OPTIONS.
diff --git a/src/search.h b/src/search.h
index 61d65626..ebb9d070 100644
--- a/src/search.h
+++ b/src/search.h
@@ -65,6 +65,7 @@ extern ptrdiff_t Fexecute (void *, char const *, idx_t, idx_t *, char const *);
/* pcresearch.c */
extern void *Pcompile (char *, idx_t, reg_syntax_t, bool);
extern ptrdiff_t Pexecute (void *, char const *, idx_t, idx_t *, char const *);
+extern void Pprint_version (void);
/* grep.c */
extern struct localeinfo localeinfo;