Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.

Commit 18c0c2f

Browse files
committed
Ticket #4655: remove PCRE and PCRE2 search engines.
GRegex as PCRE wrapper was introduced in GLib-2.14. PCRE was required for MC on OSes with GLib < 2.14. Currently MC requires GLib >= 2.32. Since 2.73.2 (released at 2022-07-08), GRegex is based on PCRE2. We can remove PCRE and PCRE2 from MC and use GLib only. Signed-off-by: Andrew Borodin <[email protected]>
1 parent 9f020f7 commit 18c0c2f

File tree

11 files changed

+8
-462
lines changed

11 files changed

+8
-462
lines changed

.github/workflows/ci-ubuntu.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Install dependencies
1515
run: |
1616
sudo apt-get install -y autoconf autopoint check gettext libtool pkg-config
17-
sudo apt-get install -y e2fslibs-dev libaspell-dev libglib2.0-dev libgpm-dev libncurses5-dev libpcre2-dev libslang2-dev libssh2-1-dev libx11-dev unzip
17+
sudo apt-get install -y e2fslibs-dev libaspell-dev libglib2.0-dev libgpm-dev libncurses5-dev libslang2-dev libssh2-1-dev libx11-dev unzip
1818
1919
- name: Bootstrap build system
2020
run: ./autogen.sh
@@ -43,15 +43,14 @@ jobs:
4343
make check
4444
make install
4545
46-
- name: Build ncurses & pcre2 configuration
46+
- name: Build ncurses configuration
4747
run: |
4848
tar -xjf $(ls build-distrib/mc-*.tar.bz2) --one-top-level=build-ncurses
4949
cd build-ncurses
5050
5151
../configure \
5252
--prefix="$(pwd)/install" \
5353
--with-screen=ncurses \
54-
--with-search-engine=pcre2 \
5554
--enable-werror
5655
5756
make -j$(nproc)

acinclude.m4

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ m4_include([m4.include/gnulib/fsusage.m4])
66
m4_include([m4.include/gnulib/mountlist.m4])
77
m4_include([m4.include/gnulib/windows-stat-inodes.m4])
88
m4_include([m4.include/gnulib/sys_types_h.m4])
9-
m4_include([m4.include/ax_path_lib_pcre.m4])
10-
m4_include([m4.include/ax_check_pcre2.m4])
119
m4_include([m4.include/dx_doxygen.m4])
1210
m4_include([m4.include/ax_require_defined.m4])
1311
m4_include([m4.include/ax_check_compile_flag.m4])
@@ -16,7 +14,6 @@ m4_include([m4.include/ax_append_compile_flags.m4])
1614
m4_include([m4.include/mc-cflags.m4])
1715
m4_include([m4.include/mc-stdckdint.m4])
1816
m4_include([m4.include/ax_gcc_func_attribute.m4])
19-
m4_include([m4.include/mc-check-search-type.m4])
2017
m4_include([m4.include/mc-get-fs-info.m4])
2118
m4_include([m4.include/mc-with-x.m4])
2219
m4_include([m4.include/mc-use-termcap.m4])

configure.ac

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ dnl ############################################################################
228228
mc_CHECK_GLIB
229229
mc_G_MODULE_SUPPORTED
230230
mc_WITH_SCREEN
231-
mc_CHECK_SEARCH_TYPE
232231
dnl X11 support. Used to read keyboard modifiers when running under X11.
233232
mc_WITH_X
234233

@@ -751,7 +750,6 @@ Configuration:
751750
Internal editor: ${edit_msg}
752751
Diff viewer: ${diff_msg}
753752
Support for charset: ${charset_msg}
754-
Search type: ${SEARCH_TYPE}
755753
])
756754

757755
dnl option checking is disable by default due to AC_CONFIG_SUBDIRS

doc/INSTALL

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ Build requirements for GNU Midnight Commander
2525
- https://invisible-island.net/ncurses/ncurses.html
2626
- gettext >= 0.18.2
2727
- https://www.gnu.org/software/gettext/
28-
- pcre or pcre2 (as an alternative to glib-regexp)
29-
- https://www.pcre.org
3028
- gpm (general purpose mouse daemon as an alternative to xterm mouse)
3129
- https://www.nico.schottelius.org/software/gpm/
3230
- libssh2 >= 1.2.8 (required only for sftp vfs)

lib/search.h

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@
77

88
#include <sys/types.h>
99

10-
#ifdef SEARCH_TYPE_PCRE
11-
# ifdef HAVE_PCRE2
12-
# define PCRE2_CODE_UNIT_WIDTH 8
13-
# include <pcre2.h>
14-
# else
15-
# include <pcre.h>
16-
# endif
17-
#endif
1810
/*** typedefs(not structures) and defined constants **********************************************/
1911

2012
typedef enum mc_search_cbret_t mc_search_cbret_t;
@@ -25,19 +17,6 @@ typedef mc_search_cbret_t (*mc_update_fn) (const void *user_data, off_t char_off
2517

2618
#define MC_SEARCH__NUM_REPLACE_ARGS 64
2719

28-
#ifdef SEARCH_TYPE_GLIB
29-
# define mc_search_matchinfo_t GMatchInfo
30-
#else
31-
# ifdef HAVE_PCRE2
32-
/* no pcre_extra in PCRE2. pcre2_jit_compile (equivalent of pcre_study) handles
33-
* all of this internally. but we can use this to hold the pcre2_matches data
34-
* until the search is complete */
35-
# define mc_search_matchinfo_t pcre2_match_data
36-
# else
37-
# define mc_search_matchinfo_t pcre_extra
38-
# endif
39-
#endif
40-
4120
/*** enums ***************************************************************************************/
4221

4322
typedef enum
@@ -122,17 +101,8 @@ typedef struct mc_search_struct
122101
// some data for regexp
123102
int num_results;
124103
gboolean is_utf8;
125-
mc_search_matchinfo_t *regex_match_info;
104+
GMatchInfo *regex_match_info;
126105
GString *regex_buffer;
127-
#ifdef SEARCH_TYPE_PCRE
128-
# ifdef HAVE_PCRE2
129-
// pcre2 will provide a pointer to a match_data structure that can be manipulated like an
130-
// iovector
131-
size_t *iovector;
132-
# else
133-
int iovector[MC_SEARCH__NUM_REPLACE_ARGS * 2];
134-
# endif
135-
#endif
136106

137107
// private data
138108

lib/search/internal.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@
33

44
/*** typedefs(not structures) and defined constants **********************************************/
55

6-
#ifdef SEARCH_TYPE_GLIB
7-
# define mc_search_regex_t GRegex
8-
#else
9-
# ifdef HAVE_PCRE2
10-
# define mc_search_regex_t pcre2_code
11-
# else
12-
# define mc_search_regex_t pcre
13-
# endif
14-
#endif
15-
166
/*** enums ***************************************************************************************/
177

188
typedef enum
@@ -32,7 +22,7 @@ typedef struct mc_search_cond_struct
3222
GString *str;
3323
GString *upper;
3424
GString *lower;
35-
mc_search_regex_t *regex_handle;
25+
GRegex *regex_handle;
3626
gchar *charset;
3727
} mc_search_cond_t;
3828

lib/search/regex.c

Lines changed: 2 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ mc_search__cond_struct_new_regex_ci_str (const char *charset, const GString *ast
269269

270270
/* --------------------------------------------------------------------------------------------- */
271271

272-
#ifdef SEARCH_TYPE_GLIB
273272
/* A thin wrapper above g_regex_match_full that makes sure the string passed
274273
* to it is valid UTF-8 (unless G_REGEX_RAW compile flag was set), as it is a
275274
* requirement by glib and it might crash otherwise. See: mc ticket 3449.
@@ -319,15 +318,12 @@ mc_search__g_regex_match_full_safe (const GRegex *regex, const gchar *string, gs
319318
g_free (string_safe);
320319
return ret;
321320
}
322-
#endif
323321

324322
/* --------------------------------------------------------------------------------------------- */
325323

326324
static mc_search__found_cond_t
327-
mc_search__regex_found_cond_one (mc_search_t *lc_mc_search, mc_search_regex_t *regex,
328-
GString *search_str)
325+
mc_search__regex_found_cond_one (mc_search_t *lc_mc_search, GRegex *regex, GString *search_str)
329326
{
330-
#ifdef SEARCH_TYPE_GLIB
331327
GError *mcerror = NULL;
332328

333329
if (!mc_search__g_regex_match_full_safe (regex, search_str->str, search_str->len, 0,
@@ -348,21 +344,7 @@ mc_search__regex_found_cond_one (mc_search_t *lc_mc_search, mc_search_regex_t *r
348344
return COND__NOT_FOUND;
349345
}
350346
lc_mc_search->num_results = g_match_info_get_match_count (lc_mc_search->regex_match_info);
351-
#else // SEARCH_TYPE_GLIB
352-
353-
lc_mc_search->num_results =
354-
# ifdef HAVE_PCRE2
355-
pcre2_match (regex, (unsigned char *) search_str->str, search_str->len, 0, 0,
356-
lc_mc_search->regex_match_info, NULL);
357-
# else
358-
pcre_exec (regex, lc_mc_search->regex_match_info, search_str->str, search_str->len, 0, 0,
359-
lc_mc_search->iovector, MC_SEARCH__NUM_REPLACE_ARGS);
360-
# endif
361-
if (lc_mc_search->num_results < 0)
362-
{
363-
return COND__NOT_FOUND;
364-
}
365-
#endif
347+
366348
return COND__FOUND_OK;
367349
}
368350

@@ -443,12 +425,7 @@ mc_search_regex__get_token_by_num (const mc_search_t *lc_mc_search, gsize lc_ind
443425
{
444426
int fnd_start = 0, fnd_end = 0;
445427

446-
#ifdef SEARCH_TYPE_GLIB
447428
g_match_info_fetch_pos (lc_mc_search->regex_match_info, lc_index, &fnd_start, &fnd_end);
448-
#else // SEARCH_TYPE_GLIB
449-
fnd_start = lc_mc_search->iovector[lc_index * 2 + 0];
450-
fnd_end = lc_mc_search->iovector[lc_index * 2 + 1];
451-
#endif
452429

453430
if (fnd_end == fnd_start)
454431
return g_strdup ("");
@@ -807,7 +784,6 @@ mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t *lc_mc_s
807784
}
808785

809786
{
810-
#ifdef SEARCH_TYPE_GLIB
811787
GError *mcerror = NULL;
812788
GRegexCompileFlags g_regex_options = G_REGEX_OPTIMIZE | G_REGEX_DOTALL;
813789

@@ -842,67 +818,6 @@ mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t *lc_mc_s
842818
g_error_free (mcerror);
843819
return;
844820
}
845-
#else // SEARCH_TYPE_GLIB
846-
847-
# ifdef HAVE_PCRE2
848-
int errcode;
849-
char error[BUF_SMALL] = "";
850-
size_t erroffset;
851-
int pcre_options = PCRE2_MULTILINE;
852-
# else
853-
const char *error;
854-
int erroffset;
855-
int pcre_options = PCRE_EXTRA | PCRE_MULTILINE;
856-
# endif
857-
858-
if (str_isutf8 (charset) && mc_global.utf8_display)
859-
{
860-
# ifdef HAVE_PCRE2
861-
pcre_options |= PCRE2_UTF;
862-
if (!lc_mc_search->is_case_sensitive)
863-
pcre_options |= PCRE2_CASELESS;
864-
# else
865-
pcre_options |= PCRE_UTF8;
866-
if (!lc_mc_search->is_case_sensitive)
867-
pcre_options |= PCRE_CASELESS;
868-
# endif
869-
}
870-
else if (!lc_mc_search->is_case_sensitive)
871-
{
872-
GString *tmp;
873-
874-
tmp = mc_search_cond->str;
875-
mc_search_cond->str = mc_search__cond_struct_new_regex_ci_str (charset, tmp);
876-
g_string_free (tmp, TRUE);
877-
}
878-
879-
mc_search_cond->regex_handle =
880-
# ifdef HAVE_PCRE2
881-
pcre2_compile ((unsigned char *) mc_search_cond->str->str, PCRE2_ZERO_TERMINATED,
882-
pcre_options, &errcode, &erroffset, NULL);
883-
# else
884-
pcre_compile (mc_search_cond->str->str, pcre_options, &error, &erroffset, NULL);
885-
# endif
886-
if (mc_search_cond->regex_handle == NULL)
887-
{
888-
# ifdef HAVE_PCRE2
889-
pcre2_get_error_message (errcode, (unsigned char *) error, sizeof (error));
890-
# endif
891-
mc_search_set_error (lc_mc_search, MC_SEARCH_E_REGEX_COMPILE, "%s", error);
892-
return;
893-
}
894-
# ifdef HAVE_PCRE2
895-
if (pcre2_jit_compile (mc_search_cond->regex_handle, PCRE2_JIT_COMPLETE) && *error != '\0')
896-
# else
897-
lc_mc_search->regex_match_info = pcre_study (mc_search_cond->regex_handle, 0, &error);
898-
if (lc_mc_search->regex_match_info == NULL && error != NULL)
899-
# endif
900-
{
901-
mc_search_set_error (lc_mc_search, MC_SEARCH_E_REGEX_COMPILE, "%s", error);
902-
MC_PTR_FREE (mc_search_cond->regex_handle);
903-
return;
904-
}
905-
#endif
906821
}
907822

908823
lc_mc_search->is_utf8 = str_isutf8 (charset);
@@ -985,12 +900,7 @@ mc_search__run_regex (mc_search_t *lc_mc_search, const void *user_data, off_t st
985900
switch (mc_search__regex_found_cond (lc_mc_search, lc_mc_search->regex_buffer))
986901
{
987902
case COND__FOUND_OK:
988-
#ifdef SEARCH_TYPE_GLIB
989903
g_match_info_fetch_pos (lc_mc_search->regex_match_info, 0, &start_pos, &end_pos);
990-
#else // SEARCH_TYPE_GLIB
991-
start_pos = lc_mc_search->iovector[0];
992-
end_pos = lc_mc_search->iovector[1];
993-
#endif
994904
if (found_len != NULL)
995905
*found_len = end_pos - start_pos;
996906
lc_mc_search->normal_offset = lc_mc_search->start_buffer + start_pos;

lib/search/search.c

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,7 @@ mc_search__cond_struct_new (mc_search_t *lc_mc_search, const GString *str, const
7171
mc_search_cond = g_malloc0 (sizeof (mc_search_cond_t));
7272
mc_search_cond->str = mc_g_string_dup (str);
7373
mc_search_cond->charset = g_strdup (charset);
74-
#ifdef HAVE_PCRE2
75-
lc_mc_search->regex_match_info = pcre2_match_data_create (MC_SEARCH__NUM_REPLACE_ARGS, NULL);
76-
lc_mc_search->iovector = pcre2_get_ovector_pointer (lc_mc_search->regex_match_info);
77-
#endif
74+
7875
switch (lc_mc_search->search_type)
7976
{
8077
case MC_SEARCH_T_GLOB:
@@ -111,12 +108,8 @@ mc_search__cond_struct_free (gpointer data)
111108
g_string_free (mc_search_cond->str, TRUE);
112109
g_free (mc_search_cond->charset);
113110

114-
#ifdef SEARCH_TYPE_GLIB
115111
if (mc_search_cond->regex_handle != NULL)
116112
g_regex_unref (mc_search_cond->regex_handle);
117-
#else // SEARCH_TYPE_GLIB
118-
g_free (mc_search_cond->regex_handle);
119-
#endif
120113

121114
g_free (mc_search_cond);
122115
}
@@ -188,12 +181,8 @@ mc_search_free (mc_search_t *lc_mc_search)
188181
if (lc_mc_search->prepared.conditions != NULL)
189182
g_ptr_array_free (lc_mc_search->prepared.conditions, TRUE);
190183

191-
#ifdef SEARCH_TYPE_GLIB
192184
if (lc_mc_search->regex_match_info != NULL)
193185
g_match_info_free (lc_mc_search->regex_match_info);
194-
#else // SEARCH_TYPE_GLIB
195-
g_free (lc_mc_search->regex_match_info);
196-
#endif
197186

198187
if (lc_mc_search->regex_buffer != NULL)
199188
g_string_free (lc_mc_search->regex_buffer, TRUE);
@@ -282,13 +271,12 @@ mc_search_run (mc_search_t *lc_mc_search, const void *user_data, off_t start_sea
282271
mc_search_set_error (lc_mc_search, MC_SEARCH_E_INPUT, "%s", _ (STR_E_UNKNOWN_TYPE));
283272
return FALSE;
284273
}
285-
#ifdef SEARCH_TYPE_GLIB
274+
286275
if (lc_mc_search->regex_match_info != NULL)
287276
{
288277
g_match_info_free (lc_mc_search->regex_match_info);
289278
lc_mc_search->regex_match_info = NULL;
290279
}
291-
#endif
292280

293281
mc_search_set_error (lc_mc_search, MC_SEARCH_E_OK, NULL);
294282

@@ -455,17 +443,13 @@ mc_search_getstart_result_by_num (mc_search_t *lc_mc_search, int lc_index)
455443
return 0;
456444
if (lc_mc_search->search_type == MC_SEARCH_T_NORMAL)
457445
return 0;
458-
#ifdef SEARCH_TYPE_GLIB
459446
{
460447
gint start_pos;
461448
gint end_pos;
462449

463450
g_match_info_fetch_pos (lc_mc_search->regex_match_info, lc_index, &start_pos, &end_pos);
464451
return (int) start_pos;
465452
}
466-
#else // SEARCH_TYPE_GLIB
467-
return lc_mc_search->iovector[lc_index * 2];
468-
#endif
469453
}
470454

471455
/* --------------------------------------------------------------------------------------------- */
@@ -477,17 +461,13 @@ mc_search_getend_result_by_num (mc_search_t *lc_mc_search, int lc_index)
477461
return 0;
478462
if (lc_mc_search->search_type == MC_SEARCH_T_NORMAL)
479463
return 0;
480-
#ifdef SEARCH_TYPE_GLIB
481464
{
482465
gint start_pos;
483466
gint end_pos;
484467

485468
g_match_info_fetch_pos (lc_mc_search->regex_match_info, lc_index, &start_pos, &end_pos);
486469
return (int) end_pos;
487470
}
488-
#else // SEARCH_TYPE_GLIB
489-
return lc_mc_search->iovector[lc_index * 2 + 1];
490-
#endif
491471
}
492472

493473
/* --------------------------------------------------------------------------------------------- */

0 commit comments

Comments
 (0)