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

Commit

Permalink
Ticket #4655: remove PCRE and PCRE2 search engines.
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
aborodin committed Feb 22, 2025
1 parent 9f020f7 commit 18c0c2f
Show file tree
Hide file tree
Showing 11 changed files with 8 additions and 462 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/ci-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get install -y autoconf autopoint check gettext libtool pkg-config
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
sudo apt-get install -y e2fslibs-dev libaspell-dev libglib2.0-dev libgpm-dev libncurses5-dev libslang2-dev libssh2-1-dev libx11-dev unzip
- name: Bootstrap build system
run: ./autogen.sh
Expand Down Expand Up @@ -43,15 +43,14 @@ jobs:
make check
make install
- name: Build ncurses & pcre2 configuration
- name: Build ncurses configuration
run: |
tar -xjf $(ls build-distrib/mc-*.tar.bz2) --one-top-level=build-ncurses
cd build-ncurses
../configure \
--prefix="$(pwd)/install" \
--with-screen=ncurses \
--with-search-engine=pcre2 \
--enable-werror
make -j$(nproc)
Expand Down
3 changes: 0 additions & 3 deletions acinclude.m4
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ m4_include([m4.include/gnulib/fsusage.m4])
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])
Expand All @@ -16,7 +14,6 @@ m4_include([m4.include/ax_append_compile_flags.m4])
m4_include([m4.include/mc-cflags.m4])
m4_include([m4.include/mc-stdckdint.m4])
m4_include([m4.include/ax_gcc_func_attribute.m4])
m4_include([m4.include/mc-check-search-type.m4])
m4_include([m4.include/mc-get-fs-info.m4])
m4_include([m4.include/mc-with-x.m4])
m4_include([m4.include/mc-use-termcap.m4])
Expand Down
2 changes: 0 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ dnl ############################################################################
mc_CHECK_GLIB
mc_G_MODULE_SUPPORTED
mc_WITH_SCREEN
mc_CHECK_SEARCH_TYPE
dnl X11 support. Used to read keyboard modifiers when running under X11.
mc_WITH_X

Expand Down Expand Up @@ -751,7 +750,6 @@ Configuration:
Internal editor: ${edit_msg}
Diff viewer: ${diff_msg}
Support for charset: ${charset_msg}
Search type: ${SEARCH_TYPE}
])

dnl option checking is disable by default due to AC_CONFIG_SUBDIRS
Expand Down
2 changes: 0 additions & 2 deletions doc/INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ Build requirements for GNU Midnight Commander
- https://invisible-island.net/ncurses/ncurses.html
- gettext >= 0.18.2
- https://www.gnu.org/software/gettext/
- pcre or pcre2 (as an alternative to glib-regexp)
- https://www.pcre.org
- gpm (general purpose mouse daemon as an alternative to xterm mouse)
- https://www.nico.schottelius.org/software/gpm/
- libssh2 >= 1.2.8 (required only for sftp vfs)
Expand Down
32 changes: 1 addition & 31 deletions lib/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@

#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
/*** typedefs(not structures) and defined constants **********************************************/

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

#define MC_SEARCH__NUM_REPLACE_ARGS 64

#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 ***************************************************************************************/

typedef enum
Expand Down Expand Up @@ -122,17 +101,8 @@ typedef struct mc_search_struct
// some data for regexp
int num_results;
gboolean is_utf8;
mc_search_matchinfo_t *regex_match_info;
GMatchInfo *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

// private data

Expand Down
12 changes: 1 addition & 11 deletions lib/search/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@

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

#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 ***************************************************************************************/

typedef enum
Expand All @@ -32,7 +22,7 @@ typedef struct mc_search_cond_struct
GString *str;
GString *upper;
GString *lower;
mc_search_regex_t *regex_handle;
GRegex *regex_handle;
gchar *charset;
} mc_search_cond_t;

Expand Down
94 changes: 2 additions & 92 deletions lib/search/regex.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ mc_search__cond_struct_new_regex_ci_str (const char *charset, const GString *ast

/* --------------------------------------------------------------------------------------------- */

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

/* --------------------------------------------------------------------------------------------- */

static mc_search__found_cond_t
mc_search__regex_found_cond_one (mc_search_t *lc_mc_search, mc_search_regex_t *regex,
GString *search_str)
mc_search__regex_found_cond_one (mc_search_t *lc_mc_search, GRegex *regex, GString *search_str)
{
#ifdef SEARCH_TYPE_GLIB
GError *mcerror = NULL;

if (!mc_search__g_regex_match_full_safe (regex, search_str->str, search_str->len, 0,
Expand All @@ -348,21 +344,7 @@ mc_search__regex_found_cond_one (mc_search_t *lc_mc_search, mc_search_regex_t *r
return COND__NOT_FOUND;
}
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 =
# 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;
}
#endif

return COND__FOUND_OK;
}

Expand Down Expand Up @@ -443,12 +425,7 @@ mc_search_regex__get_token_by_num (const mc_search_t *lc_mc_search, gsize lc_ind
{
int fnd_start = 0, fnd_end = 0;

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

if (fnd_end == fnd_start)
return g_strdup ("");
Expand Down Expand Up @@ -807,7 +784,6 @@ mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t *lc_mc_s
}

{
#ifdef SEARCH_TYPE_GLIB
GError *mcerror = NULL;
GRegexCompileFlags g_regex_options = G_REGEX_OPTIMIZE | G_REGEX_DOTALL;

Expand Down Expand Up @@ -842,67 +818,6 @@ mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t *lc_mc_s
g_error_free (mcerror);
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)
{
GString *tmp;

tmp = mc_search_cond->str;
mc_search_cond->str = mc_search__cond_struct_new_regex_ci_str (charset, tmp);
g_string_free (tmp, TRUE);
}

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);
return;
}
#endif
}

lc_mc_search->is_utf8 = str_isutf8 (charset);
Expand Down Expand Up @@ -985,12 +900,7 @@ mc_search__run_regex (mc_search_t *lc_mc_search, const void *user_data, off_t st
switch (mc_search__regex_found_cond (lc_mc_search, lc_mc_search->regex_buffer))
{
case COND__FOUND_OK:
#ifdef SEARCH_TYPE_GLIB
g_match_info_fetch_pos (lc_mc_search->regex_match_info, 0, &start_pos, &end_pos);
#else // SEARCH_TYPE_GLIB
start_pos = lc_mc_search->iovector[0];
end_pos = lc_mc_search->iovector[1];
#endif
if (found_len != NULL)
*found_len = end_pos - start_pos;
lc_mc_search->normal_offset = lc_mc_search->start_buffer + start_pos;
Expand Down
24 changes: 2 additions & 22 deletions lib/search/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ mc_search__cond_struct_new (mc_search_t *lc_mc_search, const GString *str, const
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:
Expand Down Expand Up @@ -111,12 +108,8 @@ mc_search__cond_struct_free (gpointer data)
g_string_free (mc_search_cond->str, TRUE);
g_free (mc_search_cond->charset);

#ifdef SEARCH_TYPE_GLIB
if (mc_search_cond->regex_handle != NULL)
g_regex_unref (mc_search_cond->regex_handle);
#else // SEARCH_TYPE_GLIB
g_free (mc_search_cond->regex_handle);
#endif

g_free (mc_search_cond);
}
Expand Down Expand Up @@ -188,12 +181,8 @@ mc_search_free (mc_search_t *lc_mc_search)
if (lc_mc_search->prepared.conditions != NULL)
g_ptr_array_free (lc_mc_search->prepared.conditions, TRUE);

#ifdef SEARCH_TYPE_GLIB
if (lc_mc_search->regex_match_info != NULL)
g_match_info_free (lc_mc_search->regex_match_info);
#else // SEARCH_TYPE_GLIB
g_free (lc_mc_search->regex_match_info);
#endif

if (lc_mc_search->regex_buffer != NULL)
g_string_free (lc_mc_search->regex_buffer, TRUE);
Expand Down Expand Up @@ -282,13 +271,12 @@ mc_search_run (mc_search_t *lc_mc_search, const void *user_data, off_t start_sea
mc_search_set_error (lc_mc_search, MC_SEARCH_E_INPUT, "%s", _ (STR_E_UNKNOWN_TYPE));
return FALSE;
}
#ifdef SEARCH_TYPE_GLIB

if (lc_mc_search->regex_match_info != NULL)
{
g_match_info_free (lc_mc_search->regex_match_info);
lc_mc_search->regex_match_info = NULL;
}
#endif

mc_search_set_error (lc_mc_search, MC_SEARCH_E_OK, NULL);

Expand Down Expand Up @@ -455,17 +443,13 @@ mc_search_getstart_result_by_num (mc_search_t *lc_mc_search, int lc_index)
return 0;
if (lc_mc_search->search_type == MC_SEARCH_T_NORMAL)
return 0;
#ifdef SEARCH_TYPE_GLIB
{
gint start_pos;
gint end_pos;

g_match_info_fetch_pos (lc_mc_search->regex_match_info, lc_index, &start_pos, &end_pos);
return (int) start_pos;
}
#else // SEARCH_TYPE_GLIB
return lc_mc_search->iovector[lc_index * 2];
#endif
}

/* --------------------------------------------------------------------------------------------- */
Expand All @@ -477,17 +461,13 @@ mc_search_getend_result_by_num (mc_search_t *lc_mc_search, int lc_index)
return 0;
if (lc_mc_search->search_type == MC_SEARCH_T_NORMAL)
return 0;
#ifdef SEARCH_TYPE_GLIB
{
gint start_pos;
gint end_pos;

g_match_info_fetch_pos (lc_mc_search->regex_match_info, lc_index, &start_pos, &end_pos);
return (int) end_pos;
}
#else // SEARCH_TYPE_GLIB
return lc_mc_search->iovector[lc_index * 2 + 1];
#endif
}

/* --------------------------------------------------------------------------------------------- */
Expand Down
Loading

0 comments on commit 18c0c2f

Please sign in to comment.