From: Tobias Oetiker Date: Thu, 23 Oct 2014 21:35:51 +0000 (+0200) Subject: if glib does not have regex support, try libpcre X-Git-Tag: v1.5.0-rc1~22^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=be6bc22d726b355429bda656a77e4c5ed06cc844;p=thirdparty%2Frrdtool-1.x.git if glib does not have regex support, try libpcre --- diff --git a/configure.ac b/configure.ac index 0d57afc3..8f53cff7 100644 --- a/configure.ac +++ b/configure.ac @@ -215,7 +215,7 @@ CONFIGURE_PART(Checking for Header Files) dnl Checks for header files. AC_HEADER_STDC AC_HEADER_DIRENT -AC_CHECK_HEADERS(langinfo.h stdint.h inttypes.h libgen.h features.h sys/stat.h sys/types.h fcntl.h fp_class.h malloc.h unistd.h ieeefp.h math.h sys/times.h sys/param.h sys/resource.h signal.h float.h stdio.h stdlib.h errno.h string.h ctype.h grp.h pwd.h) +AC_CHECK_HEADERS(pcre.h langinfo.h stdint.h inttypes.h libgen.h features.h sys/stat.h sys/types.h fcntl.h fp_class.h malloc.h unistd.h ieeefp.h math.h sys/times.h sys/param.h sys/resource.h signal.h float.h stdio.h stdlib.h errno.h string.h ctype.h grp.h pwd.h) dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST @@ -552,6 +552,14 @@ AM_CONDITIONAL(BUILD_RRDRESTORE,[test $enable_rrd_restore != no]) EX_CHECK_ALL(glib-2.0, glib_check_version, glib.h, glib-2.0, 2.28.7, ftp://ftp.gtk.org/pub/glib/2.28/, "") +AC_CHECK_FUNC(g_regex_new,[],[ + AC_MSG_CHECKING(if pcre is available to supply the missing regex support in glib) + AC_MSG_RESULT(checking now ...) + EX_CHECK_ALL(pcre, pcre_compile, pcre.h, pcre, x.x.x, [get a newer glib and you will not need pcre at all],"") +]) + + + CORE_LIBS="$LIBS" if test $enable_rrd_graph != no; then @@ -559,7 +567,7 @@ dnl EX_CHECK_ALL(z, zlibVersion, zlib.h, dnl EX_CHECK_ALL(png, png_access_version_number, png.h, libpng, 1.4.8, ftp://ftp.simplesystems.org/pub/libpng/png/src/, "") dnl EX_CHECK_ALL(freetype, FT_Init_FreeType, ft2build.h, freetype2, 2.4.6, http://download.savannah.gnu.org/releases/freetype/, /usr/include/freetype2) dnl EX_CHECK_ALL(fontconfig, FcInit, fontconfig.h, fontconfig, 2.8.0, http://www.freedesktop.org/software/fontconfig/release/, /usr/include) -EX_CHECK_ALL(cairo, cairo_font_options_create, cairo.h, cairo-png, 1.10.2, http://cairographics.org/releases/, "") +dnl EX_CHECK_ALL(cairo, cairo_font_options_create, cairo.h, cairo-png, 1.10.2, http://cairographics.org/releases/, "") dnl EX_CHECK_ALL(cairo, cairo_svg_surface_create, cairo-svg.h, cairo-svg, 1.10.2, http://cairographics.org/releases/, "") dnl EX_CHECK_ALL(cairo, cairo_pdf_surface_create, cairo-pdf.h, cairo-pdf, 1.10.2, http://cairographics.org/releases/, "") dnl EX_CHECK_ALL(cairo, cairo_ps_surface_create, cairo-ps.h, cairo-ps, 1.10.2, http://cairographics.org/releases/, "") diff --git a/src/rrd_create.c b/src/rrd_create.c index 6d126c3b..75121953 100644 --- a/src/rrd_create.c +++ b/src/rrd_create.c @@ -9,12 +9,24 @@ #include #include #include // will use glist and regex + + + #include // stat() #include // stat() #include // stat() #include "rrd_strtod.h" #include "rrd_tool.h" + +#ifndef HAVE_G_REGEX_NEW +#ifdef HAVE_PCRE_H +#include +#else +#error "you must have either glib with regexp support or libpcre" +#endif +#endif + #include "rrd_rpncalc.h" #include "rrd_hw.h" #include "rrd_client.h" @@ -265,7 +277,7 @@ int parseDS(const char *def, int rc = -1; char *dst_tmp = NULL; char *dst_args = NULL; - +#ifdef HAVE_G_REGEX_NEW GError *gerr = NULL; GRegex *re = g_regex_new(DS_RE, G_REGEX_EXTENDED, 0, &gerr); GMatchInfo *mi; @@ -275,7 +287,19 @@ int parseDS(const char *def, goto done; } int m = g_regex_match(re, def, 0, &mi); - +#else +#define OVECCOUNT 30 /* should be a multiple of 3 */ + pcre *re; + const char *error; + int erroffset; + int ovector[OVECCOUNT]; + re = pcre_compile(DS_RE,PCRE_EXTENDED,&error,&erroffset,NULL); + if (re == NULL){ + rrd_set_error("cannot compile regular expression: %s (%s)", error,DS_RE); + goto done; + } + int m = pcre_exec(re,NULL,def,(int)strlen(def),0,0,ovector,OVECCOUNT); +#endif if (!m) { rrd_set_error("invalid DS format"); goto done; @@ -293,14 +317,25 @@ int parseDS(const char *def, int s, e, s2, e2; // NAME - g_match_info_fetch_pos(mi, DS_NAME_SUBGROUP, &s, &e); memset(ds_def->ds_nam, 0, sizeof(ds_def->ds_nam)); +#ifdef HAVE_G_REGEX_NEW + g_match_info_fetch_pos(mi, DS_NAME_SUBGROUP, &s, &e); +#else + s=ovector[DS_NAME_SUBGROUP*2]; + e=ovector[DS_NAME_SUBGROUP*2+1]; +#endif strncpy(ds_def->ds_nam, def + s, e - s); - + // DST + DST args +#ifdef HAVE_G_REGEX_NEW g_match_info_fetch_pos(mi, DST_SUBGROUP, &s, &e); g_match_info_fetch_pos(mi, DST_ARGS_SUBGROUP, &s2, &e2); - +#else + s=ovector[DST_SUBGROUP*2]; + e=ovector[DST_SUBGROUP*2+1]; + s2=ovector[DST_ARGS_SUBGROUP*2]; + e2=ovector[DST_ARGS_SUBGROUP*2+1]; +#endif dst_tmp = strndup(def + s, e - s); dst_args = strndup(def + s2, e2 - s2); @@ -324,31 +359,44 @@ int parseDS(const char *def, // mapping, but only if we are interested in it... if (mapping) { char *endptr; - g_match_info_fetch_pos(mi, MAPPED_DS_NAME_SUBGROUP, &s, &e); - mapping->ds_nam = strdup(ds_def->ds_nam); +#ifdef HAVE_G_REGEX_NEW + g_match_info_fetch_pos(mi, MAPPED_DS_NAME_SUBGROUP, &s, &e); +#else + s=ovector[MAPPED_DS_NAME_SUBGROUP*2]; + e=ovector[MAPPED_DS_NAME_SUBGROUP*2+1]; +#endif mapping->mapped_name = strndup(def + s, e - s); - if (mapping->ds_nam == NULL || mapping->mapped_name == NULL) { rrd_set_error("Cannot allocate memory"); goto done; } +#ifdef HAVE_G_REGEX_NEW g_match_info_fetch_pos(mi, OPT_MAPPED_INDEX_SUBGROUP, &s, &e); - +#else + s=ovector[OPT_MAPPED_INDEX_SUBGROUP*2]; + e=ovector[OPT_MAPPED_INDEX_SUBGROUP*2+1]; +#endif /* we do not have to check for errors: invalid indices will be checked later, * and syntactically, the RE has done the job for us already*/ mapping->index = s != e ? strtol(def + s, &endptr, 10) : -1; + } rc = 0; done: if (re) { +#ifdef HAVE_G_REGEX_NEW g_match_info_free(mi); g_regex_unref(re); +#else + pcre_free(re); +#endif } - + if (dst_tmp) free(dst_tmp); if (dst_args) free(dst_args); + return rc; } @@ -2391,5 +2439,9 @@ static void free_mapping(mapping_t *mapping) { if (! mapping) return; if (mapping->ds_nam) free(mapping->ds_nam); if (mapping->def) free(mapping->def); +#ifdef HAVE_G_REGEX_NEW if (mapping->mapped_name) free(mapping->mapped_name); +#else + if (mapping->mapped_name) pcre_free_substring(mapping->mapped_name); +#endif } diff --git a/src/rrd_graph.c b/src/rrd_graph.c index ea258e8d..26897f10 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -6,7 +6,8 @@ #include -#include // will use regex + + #ifdef WIN32 #include "strftime.h" @@ -17,6 +18,18 @@ #include "rrd_tool.h" #include "unused.h" + +#ifdef HAVE_G_REGEX_NEW +#include +#else +#ifdef HAVE_PCRE_H +#include +#else +#error "you must have either glib with regexp support or libpcre" +#endif +#endif + + /* for basename */ #ifdef HAVE_LIBGEN_H # include @@ -5070,8 +5083,10 @@ int rrd_graph_color( } } +#define OVECCOUNT 30 /* should be a multiple of 3 */ -static int bad_format_check(const char *pattern, char *fmt) { +static int bad_format_check(const char *pattern, char *fmt) { +#ifdef HAVE_G_REGEX_NEW GError *gerr = NULL; GRegex *re = g_regex_new(pattern, G_REGEX_EXTENDED, 0, &gerr); GMatchInfo *mi; @@ -5082,6 +5097,19 @@ static int bad_format_check(const char *pattern, char *fmt) { int m = g_regex_match(re, fmt, 0, &mi); g_match_info_free (mi); g_regex_unref(re); +#else + const char *error; + int erroffset; + int ovector[OVECCOUNT]; + pcre *re; + re = pcre_compile(pattern,PCRE_EXTENDED,&error,&erroffset,NULL); + if (re == NULL){ + rrd_set_error("cannot compile regular expression: %s (%s)", error,pattern); + return 1; + } + int m = pcre_exec(re,NULL,fmt,(int)strlen(fmt),0,0,ovector,OVECCOUNT); + pcre_free(re); +#endif if (!m) { rrd_set_error("invalid format string '%s' (should match '%s')",fmt,pattern); return 1;