Removed support of POSIX regexp. Now handled only glib-regexp and pcre

POSIX regexp don't support search by code of character (like \x<HEX>).

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2009-06-19 16:08:48 +03:00
parent de248cb274
commit 38601bd224
4 changed files with 3 additions and 77 deletions

View File

@ -6,11 +6,7 @@
#if GLIB_CHECK_VERSION (2, 14, 0)
#define mc_search_regex_t GRegex
#else
# if HAVE_LIBPCRE
# define mc_search_regex_t pcre
# else
# define mc_search_regex_t regex_t
# endif
#define mc_search_regex_t pcre
#endif
/*** enums ***************************************************************************************/

View File

@ -251,25 +251,12 @@ mc_search__regex_found_cond_one (mc_search_t * mc_search, mc_search_regex_t * re
}
mc_search->num_rezults = g_match_info_get_match_count (mc_search->regex_match_info);
#else
#if HAVE_LIBPCRE
mc_search->num_rezults = pcre_exec (regex, mc_search->regex_match_info,
search_str->str, search_str->len, 0, 0, mc_search->iovector,
MC_SEARCH__NUM_REPLACE_ARGS);
if (mc_search->num_rezults < 0) {
return COND__NOT_FOUND;
}
#else /* HAVE_LIBPCRE */
if (regexec (regex, search_str->str, MC_SEARCH__NUM_REPLACE_ARGS, mc_search->regex_match_info, 0))
return COND__NOT_FOUND;
for (mc_search->num_rezults = 0; mc_search->num_rezults < MC_SEARCH__NUM_REPLACE_ARGS;
mc_search->num_rezults++) {
if (mc_search->regex_match_info[mc_search->num_rezults].rm_eo == 0)
break;
}
#endif /* HAVE_LIBPCRE */
#endif /* GLIB_CHECK_VERSION (2, 14, 0) */
return COND__FOUND_OK;
@ -345,13 +332,8 @@ mc_search_regex__get_token_by_num (const mc_search_t * mc_search, gsize index)
#if GLIB_CHECK_VERSION (2, 14, 0)
g_match_info_fetch_pos (mc_search->regex_match_info, index, &fnd_start, &fnd_end);
#else /* GLIB_CHECK_VERSION (2, 14, 0) */
#if HAVE_LIBPCRE
fnd_start = mc_search->iovector[index * 2 + 0];
fnd_end = mc_search->iovector[index * 2 + 1];
#else /* HAVE_LIBPCRE */
fnd_start = mc_search->regex_match_info[index].rm_so;
fnd_end = mc_search->regex_match_info[index].rm_eo;
#endif /* HAVE_LIBPCRE */
#endif /* GLIB_CHECK_VERSION (2, 14, 0) */
if (fnd_end - fnd_start == 0)
@ -519,7 +501,6 @@ mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t * mc_sea
return;
}
#else /* GLIB_CHECK_VERSION (2, 14, 0) */
#if HAVE_LIBPCRE
mc_search_cond->regex_handle =
pcre_compile (mc_search_cond->str->str, PCRE_EXTRA, &error, &erroffset, NULL);
if (mc_search_cond->regex_handle == NULL) {
@ -537,21 +518,6 @@ mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t * mc_sea
return;
}
}
#else /* HAVE_LIBPCRE */
mc_search_cond->regex_handle = g_malloc0 (sizeof (regex_t));
erroffset = regcomp (mc_search_cond->regex_handle, mc_search_cond->str->str, REG_EXTENDED);
if (erroffset) {
size_t err_len = regerror (erroffset, mc_search_cond->regex_handle, NULL, 0);
error = g_malloc (err_len + 1);
regerror (erroffset, mc_search_cond->regex_handle, error, err_len);
mc_search->error = MC_SEARCH_E_REGEX_COMPILE;
mc_search->error_str = error;
regfree (mc_search_cond->regex_handle);
mc_search_cond->regex_handle = NULL;
return;
}
mc_search->regex_match_info = g_new0 (mc_search_matchinfo_t, MC_SEARCH__NUM_REPLACE_ARGS);
#endif /* HAVE_LIBPCRE */
#endif /* GLIB_CHECK_VERSION (2, 14, 0) */
}
@ -600,13 +566,8 @@ mc_search__run_regex (mc_search_t * mc_search, const void *user_data,
#if GLIB_CHECK_VERSION (2, 14, 0)
g_match_info_fetch_pos (mc_search->regex_match_info, 0, &start_pos, &end_pos);
#else /* GLIB_CHECK_VERSION (2, 14, 0) */
#if HAVE_LIBPCRE
start_pos = mc_search->iovector[0];
end_pos = mc_search->iovector[1];
#else /* HAVE_LIBPCRE */
start_pos = mc_search->regex_match_info[0].rm_so;
end_pos = mc_search->regex_match_info[0].rm_eo;
#endif /* HAVE_LIBPCRE */
#endif /* GLIB_CHECK_VERSION (2, 14, 0) */
if (found_len)
*found_len = end_pos - start_pos;

View File

@ -145,13 +145,8 @@ mc_search__cond_struct_free (mc_search_cond_t * mc_search_cond)
if (mc_search_cond->regex_handle)
g_regex_unref (mc_search_cond->regex_handle);
#else /* GLIB_CHECK_VERSION (2, 14, 0) */
#if HAVE_LIBPCRE
if (mc_search_cond->regex_handle)
free (mc_search_cond->regex_handle);
#else /* HAVE_LIBPCRE */
if (mc_search_cond->regex_handle)
regfree (mc_search_cond->regex_handle);
#endif /* HAVE_LIBPCRE */
#endif /* GLIB_CHECK_VERSION (2, 14, 0) */
g_free (mc_search_cond);
@ -217,13 +212,8 @@ mc_search_free (mc_search_t * mc_search)
if (mc_search->regex_match_info)
g_match_info_free (mc_search->regex_match_info);
#else /* GLIB_CHECK_VERSION (2, 14, 0) */
#if HAVE_LIBPCRE
if (mc_search->regex_match_info)
free (mc_search->regex_match_info);
#else /* HAVE_LIBPCRE */
if (mc_search->regex_match_info)
g_free (mc_search->regex_match_info);
#endif /* HAVE_LIBPCRE */
#endif /* GLIB_CHECK_VERSION (2, 14, 0) */
if (mc_search->regex_buffer != NULL)
@ -405,11 +395,7 @@ mc_search_getstart_rezult_by_num (mc_search_t * mc_search, int index)
g_match_info_fetch_pos (mc_search->regex_match_info, index, &start_pos, &end_pos);
return (int) start_pos;
#else /* GLIB_CHECK_VERSION (2, 14, 0) */
#if HAVE_LIBPCRE
return mc_search->iovector[index * 2];
#else /* HAVE_LIBPCRE */
return mc_search->regex_match_info[index].rm_so;
#endif /* HAVE_LIBPCRE */
#endif /* GLIB_CHECK_VERSION (2, 14, 0) */
}
@ -429,11 +415,7 @@ mc_search_getend_rezult_by_num (mc_search_t * mc_search, int index)
g_match_info_fetch_pos (mc_search->regex_match_info, index, &start_pos, &end_pos);
return (int) end_pos;
#else /* GLIB_CHECK_VERSION (2, 14, 0) */
#if HAVE_LIBPCRE
return mc_search->iovector[index * 2 + 1];
#else /* HAVE_LIBPCRE */
return mc_search->regex_match_info[index].rm_eo;
#endif /* HAVE_LIBPCRE */
#endif /* GLIB_CHECK_VERSION (2, 14, 0) */
}

View File

@ -6,14 +6,7 @@
#include "../src/global.h" /* <glib.h> */
#if ! GLIB_CHECK_VERSION (2, 14, 0)
# if HAVE_LIBPCRE
# include <pcre.h>
# else
# include <stdio.h>
# include <string.h>
# include <sys/types.h>
# include <regex.h>
# endif
# include <pcre.h>
#endif
/*** typedefs(not structures) and defined constants **********************************************/
@ -25,11 +18,7 @@ typedef int (*mc_search_fn) (const void *user_data, gsize char_offset);
#if GLIB_CHECK_VERSION (2, 14, 0)
#define mc_search_matchinfo_t GMatchInfo
#else
# if HAVE_LIBPCRE
# define mc_search_matchinfo_t pcre_extra
# else
# define mc_search_matchinfo_t regmatch_t
# endif
# define mc_search_matchinfo_t pcre_extra
#endif
/*** enums ***************************************************************************************/
@ -86,9 +75,7 @@ typedef struct mc_search_struct {
mc_search_matchinfo_t *regex_match_info;
GString *regex_buffer;
#if ! GLIB_CHECK_VERSION (2, 14, 0)
#if HAVE_LIBPCRE
int iovector[MC_SEARCH__NUM_REPLACE_ARGS * 2];
#endif /* HAVE_LIBPCRE */
#endif /* ! GLIB_CHECK_VERSION (2, 14, 0) */
/* private data */