]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
if glib does not have regex support, try libpcre 548/head
authorTobias Oetiker <tobi@oetiker.ch>
Thu, 23 Oct 2014 21:35:51 +0000 (23:35 +0200)
committerTobias Oetiker <tobi@oetiker.ch>
Thu, 23 Oct 2014 21:35:51 +0000 (23:35 +0200)
configure.ac
src/rrd_create.c
src/rrd_graph.c

index 0d57afc36e56f7e8a44ea2a01ea448b0bc43b520..8f53cff77607a02495c30c0bda3404edde1f157f 100644 (file)
@@ -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/, "")
index 6d126c3ba23df373a27c2a0df9a8c874a193c4bf..75121953bda8da122f8119d10b82d0e3a3b3570c 100644 (file)
@@ -9,12 +9,24 @@
 #include <locale.h>
 #include <math.h>
 #include <glib.h>   // will use glist and regex
+
+
+
 #include <sys/types.h>      // stat()
 #include <sys/stat.h>       // stat()
 #include <unistd.h>         // stat()
 
 #include "rrd_strtod.h"
 #include "rrd_tool.h"
+
+#ifndef HAVE_G_REGEX_NEW
+#ifdef HAVE_PCRE_H
+#include <pcre.h>
+#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
 }
index ea258e8d5fe8bd2928fc380914a4c167b5ddc5c9..26897f1084f668abf5fe2bad95a0963edf0d365f 100644 (file)
@@ -6,7 +6,8 @@
 
 
 #include <sys/stat.h>
-#include <glib.h>   // will use regex
+
+
 
 #ifdef WIN32
 #include "strftime.h"
 #include "rrd_tool.h"
 #include "unused.h"
 
+
+#ifdef HAVE_G_REGEX_NEW
+#include <glib.h>
+#else
+#ifdef HAVE_PCRE_H
+#include <pcre.h>
+#else
+#error "you must have either glib with regexp support or libpcre"
+#endif
+#endif
+
+
 /* for basename */
 #ifdef HAVE_LIBGEN_H
 #  include <libgen.h>
@@ -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;