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
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
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/, "")
#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"
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;
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;
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);
// 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;
}
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
}
#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>
}
}
+#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;
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;