Просмотр исходного кода

Ticket #4450: support PCRE2 in the search engine.

  * m4.include/ax_path_lib_pcre.m4: replace by recent version from GNU
Autoconf Archive.
  * m4.include/ax_check_pcre2.m4: get grom GNU Autoconf Archive.
  * m4.include/mc-check-search-type.m4: support both PCRE versions.
  * */*/Makefile.am: remove @CHECK_CFLAGS@ and @PCRE_LIBS@ ads they are
added via AX_PATH_LIB_PCRE and AX_CHECK_PCRE2.
  * lib/search.h, lib/search/: add support of PCRE2. Thanks broly <gagan@hotmail.com>
for the initial patch.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Andrew Borodin 2 лет назад
Родитель
Сommit
49624e473b
10 измененных файлов с 67 добавлено и 11 удалено
  1. 3 0
      AUTHORS
  2. 1 0
      acinclude.m4
  3. 1 2
      doc/INSTALL
  4. 0 2
      lib/Makefile.am
  5. 1 1
      lib/filehighlight/Makefile.am
  6. 17 1
      lib/search.h
  7. 1 1
      lib/search/Makefile.am
  8. 4 0
      lib/search/internal.h
  9. 35 3
      lib/search/regex.c
  10. 4 1
      lib/search/search.c

+ 3 - 0
AUTHORS

@@ -66,6 +66,9 @@ Anton Chumak <nightfast@yahoo.co.uk>
 Antonio Palama, DOS port <palama@posso.dm.unipi.it>
 	DOS port.
 
+broly <gagan@hotmail.com>
+	Support of PCRE2
+
 Dmitry Koterov <dmitry.koterov@gmail.com>
 	s3 extfs bugfixes and improvements
 

+ 1 - 0
acinclude.m4

@@ -6,6 +6,7 @@ m4_include([m4.include/gnulib/mountlist.m4])
 m4_include([m4.include/gnulib/windows-stat-inodes.m4])
 m4_include([m4.include/gnulib/sys_types_h.m4])
 m4_include([m4.include/ax_path_lib_pcre.m4])
+m4_include([m4.include/ax_check_pcre2.m4])
 m4_include([m4.include/dx_doxygen.m4])
 m4_include([m4.include/ax_require_defined.m4])
 m4_include([m4.include/ax_check_compile_flag.m4])

+ 1 - 2
doc/INSTALL

@@ -375,8 +375,7 @@ Newer versions may work, but haven't been tested.
 PCRE
 ----
 
-If the version of glib you have installed is older than 2.14.x, then you
-also need to install PCRE library.
+Both PCRE and PCRE2 libraries are supported.
 
 You can get PCRE from
 

+ 0 - 2
lib/Makefile.am

@@ -73,5 +73,3 @@ if HAVE_GMODULE
 else
     libmc_la_LIBADD += $(GLIB_LIBS)
 endif
-
-libmc_la_LIBADD += $(PCRE_LIBS)

+ 1 - 1
lib/filehighlight/Makefile.am

@@ -6,4 +6,4 @@ libmcfilehighlight_la_SOURCES = \
 	ini-file-read.c \
 	internal.h
 
-AM_CPPFLAGS = -I$(top_srcdir) $(GLIB_CFLAGS) $(PCRE_CPPFLAGS)
+AM_CPPFLAGS = -I$(top_srcdir) $(GLIB_CFLAGS)

+ 17 - 1
lib/search.h

@@ -8,9 +8,13 @@
 #include <sys/types.h>
 
 #ifdef SEARCH_TYPE_PCRE
+#ifdef HAVE_PCRE2
+#define PCRE2_CODE_UNIT_WIDTH 8
+#include <pcre2.h>
+#else
 #include <pcre.h>
 #endif
-
+#endif /* SEARCH_TYPE_PCRE */
 /*** typedefs(not structures) and defined constants **********************************************/
 
 typedef enum mc_search_cbret_t mc_search_cbret_t;
@@ -24,8 +28,15 @@ typedef mc_search_cbret_t (*mc_update_fn) (const void *user_data, gsize char_off
 #ifdef SEARCH_TYPE_GLIB
 #define mc_search_matchinfo_t GMatchInfo
 #else
+#ifdef HAVE_PCRE2
+/* no pcre_extra in PCRE2. pcre2_jit_compile (equivalent of pcre_study) handles
+ * all of this internally. but we can use this to hold the pcre2_matches data
+ * until the search is complete */
+#define mc_search_matchinfo_t pcre2_match_data
+#else
 #define mc_search_matchinfo_t pcre_extra
 #endif
+#endif
 
 /*** enums ***************************************************************************************/
 
@@ -102,7 +113,12 @@ typedef struct mc_search_struct
     mc_search_matchinfo_t *regex_match_info;
     GString *regex_buffer;
 #ifdef SEARCH_TYPE_PCRE
+#ifdef HAVE_PCRE2
+    /* pcre2 will provide a pointer to a match_data structure that can be manipulated like an iovector*/
+    size_t *iovector;
+#else
     int iovector[MC_SEARCH__NUM_REPLACE_ARGS * 2];
+#endif
 #endif                          /* SEARCH_TYPE_PCRE */
 
     /* private data */

+ 1 - 1
lib/search/Makefile.am

@@ -9,4 +9,4 @@ libsearch_la_SOURCES = \
 	glob.c \
 	hex.c
 
-AM_CPPFLAGS = -I$(top_srcdir) $(GLIB_CFLAGS) $(PCRE_CPPFLAGS)
+AM_CPPFLAGS = -I$(top_srcdir) $(GLIB_CFLAGS)

+ 4 - 0
lib/search/internal.h

@@ -6,8 +6,12 @@
 #ifdef SEARCH_TYPE_GLIB
 #define mc_search_regex_t GRegex
 #else
+#ifdef HAVE_PCRE2
+#define mc_search_regex_t pcre2_code
+#else
 #define mc_search_regex_t pcre
 #endif
+#endif
 
 /*** enums ***************************************************************************************/
 

+ 35 - 3
lib/search/regex.c

@@ -345,9 +345,15 @@ mc_search__regex_found_cond_one (mc_search_t * lc_mc_search, mc_search_regex_t *
     }
     lc_mc_search->num_results = g_match_info_get_match_count (lc_mc_search->regex_match_info);
 #else /* SEARCH_TYPE_GLIB */
-    lc_mc_search->num_results = pcre_exec (regex, lc_mc_search->regex_match_info,
-                                           search_str->str, search_str->len, 0, 0,
-                                           lc_mc_search->iovector, MC_SEARCH__NUM_REPLACE_ARGS);
+
+    lc_mc_search->num_results =
+#ifdef HAVE_PCRE2
+        pcre2_match (regex, (unsigned char *) search_str->str, search_str->len, 0, 0,
+                     lc_mc_search->regex_match_info, NULL);
+#else
+        pcre_exec (regex, lc_mc_search->regex_match_info, search_str->str, search_str->len, 0, 0,
+                   lc_mc_search->iovector, MC_SEARCH__NUM_REPLACE_ARGS);
+#endif
     if (lc_mc_search->num_results < 0)
     {
         return COND__NOT_FOUND;
@@ -835,15 +841,29 @@ mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t * lc_mc_
             return;
         }
 #else /* SEARCH_TYPE_GLIB */
+
+#ifdef HAVE_PCRE2
+        int errcode;
+        char error[BUF_SMALL];
+        size_t erroffset;
+        int pcre_options = PCRE2_MULTILINE;
+#else
         const char *error;
         int erroffset;
         int pcre_options = PCRE_EXTRA | PCRE_MULTILINE;
+#endif
 
         if (str_isutf8 (charset) && mc_global.utf8_display)
         {
+#ifdef HAVE_PCRE2
+            pcre_options |= PCRE2_UTF;
+            if (!lc_mc_search->is_case_sensitive)
+                pcre_options |= PCRE2_CASELESS;
+#else
             pcre_options |= PCRE_UTF8;
             if (!lc_mc_search->is_case_sensitive)
                 pcre_options |= PCRE_CASELESS;
+#endif
         }
         else if (!lc_mc_search->is_case_sensitive)
         {
@@ -855,14 +875,26 @@ mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t * lc_mc_
         }
 
         mc_search_cond->regex_handle =
+#ifdef HAVE_PCRE2
+            pcre2_compile ((unsigned char *) mc_search_cond->str->str, PCRE2_ZERO_TERMINATED,
+                           pcre_options, &errcode, &erroffset, NULL);
+#else
             pcre_compile (mc_search_cond->str->str, pcre_options, &error, &erroffset, NULL);
+#endif
         if (mc_search_cond->regex_handle == NULL)
         {
+#ifdef HAVE_PCRE2
+            pcre2_get_error_message (errcode, (unsigned char *) error, sizeof (error));
+#endif
             mc_search_set_error (lc_mc_search, MC_SEARCH_E_REGEX_COMPILE, "%s", error);
             return;
         }
+#ifdef HAVE_PCRE2
+        if (pcre2_jit_compile (mc_search_cond->regex_handle, PCRE2_JIT_COMPLETE) && *error != '\0')
+#else
         lc_mc_search->regex_match_info = pcre_study (mc_search_cond->regex_handle, 0, &error);
         if (lc_mc_search->regex_match_info == NULL && error != NULL)
+#endif
         {
             mc_search_set_error (lc_mc_search, MC_SEARCH_E_REGEX_COMPILE, "%s", error);
             MC_PTR_FREE (mc_search_cond->regex_handle);

+ 4 - 1
lib/search/search.c

@@ -71,7 +71,10 @@ mc_search__cond_struct_new (mc_search_t * lc_mc_search, const GString * str, con
     mc_search_cond = g_malloc0 (sizeof (mc_search_cond_t));
     mc_search_cond->str = mc_g_string_dup (str);
     mc_search_cond->charset = g_strdup (charset);
-
+#ifdef HAVE_PCRE2
+    lc_mc_search->regex_match_info = pcre2_match_data_create (MC_SEARCH__NUM_REPLACE_ARGS, NULL);
+    lc_mc_search->iovector = pcre2_get_ovector_pointer (lc_mc_search->regex_match_info);
+#endif
     switch (lc_mc_search->search_type)
     {
     case MC_SEARCH_T_GLOB:

Некоторые файлы не были показаны из-за большого количества измененных файлов