From 8ab52cc1b0c93418b143c51f792b1470289198da Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= <carenas@gmail.com>
Date: Fri, 15 Oct 2021 23:44:46 -0700
Subject: [PATCH] pcre: allow more than 1 regular expression
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

As shown in the FIXME that was included with the first version of
the code; grep will die if more than one -e option was used.

Make the minimal change possible, to convert the pattern script
into an alternation, and this way remove the restriction.

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
---
 src/pcresearch.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/pcresearch.c b/src/pcresearch.c
index 3bdaee9..295d605 100644
--- a/src/pcresearch.c
+++ b/src/pcresearch.c
@@ -126,7 +126,7 @@ Pcompile (char *pattern, idx_t size, reg_syntax_t ignored, bool exact)
   char *re = xnmalloc (4, size + (fix_len_max + 4 - 1) / 4);
   int flags = PCRE_DOLLAR_ENDONLY | (match_icase ? PCRE_CASELESS : 0);
   char *patlim = pattern + size;
-  char *n = re;
+  char *n;
   char const *p;
   char const *pnul;
   struct pcre_comp *pc = xcalloc (1, sizeof (*pc));
@@ -138,10 +138,10 @@ Pcompile (char *pattern, idx_t size, reg_syntax_t ignored, bool exact)
       flags |= PCRE_UTF8;
     }
 
-  /* FIXME: Remove this restriction.  */
-  if (rawmemchr (pattern, '\n') != patlim)
-    die (EXIT_TROUBLE, 0, _("the -P option only supports a single pattern"));
+  for (n = pattern; (n = rawmemchr (n, '\n')) < patlim; n++)
+    *n = '|';
 
+  n = re;
   *n = '\0';
   if (match_words)
     strcpy (n, wprefix);
-- 
2.33.0.1155.gbdb71ac078

