gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r25508 - in gnunet/src: include regex


From: gnunet
Subject: [GNUnet-SVN] r25508 - in gnunet/src: include regex
Date: Mon, 17 Dec 2012 13:35:19 +0100

Author: bartpolot
Date: 2012-12-17 13:35:19 +0100 (Mon, 17 Dec 2012)
New Revision: 25508

Added:
   gnunet/src/regex/regex_test_lib.c
   gnunet/src/regex/regex_test_lib.h
Modified:
   gnunet/src/include/gnunet_regex_lib.h
   gnunet/src/regex/
   gnunet/src/regex/Makefile.am
   gnunet/src/regex/perf-regex.c
   gnunet/src/regex/regex.c
Log:
- move regex_from_file and combine to separate lib file

Modified: gnunet/src/include/gnunet_regex_lib.h
===================================================================
--- gnunet/src/include/gnunet_regex_lib.h       2012-12-17 12:33:59 UTC (rev 
25507)
+++ gnunet/src/include/gnunet_regex_lib.h       2012-12-17 12:35:19 UTC (rev 
25508)
@@ -249,17 +249,7 @@
                           unsigned int prefixlen, char *rxstr);
 
 
-/**
- * Combine an array of regexes into a single prefix-shared regex.
- *
- * @param regexes A NULL-terminated array of regexes.
- *
- * @retrun A string with a single regex that matches any of the original 
regexes
- */
-char *
-GNUNET_REGEX_combine(char * const regexes[]);
 
-
 #if 0                           /* keep Emacsens' auto-indent happy */
 {
 #endif

Index: gnunet/src/regex
===================================================================
--- gnunet/src/regex    2012-12-17 12:33:59 UTC (rev 25507)
+++ gnunet/src/regex    2012-12-17 12:35:19 UTC (rev 25508)

Property changes on: gnunet/src/regex
___________________________________________________________________
Modified: svn:ignore
## -6,6 +6,7 ##
 test_regex_iterate_api
 test_regex_eval_api
 test_regex_big
+perf-regex
 Makefile.in
 Makefile
 .deps
Modified: gnunet/src/regex/Makefile.am
===================================================================
--- gnunet/src/regex/Makefile.am        2012-12-17 12:33:59 UTC (rev 25507)
+++ gnunet/src/regex/Makefile.am        2012-12-17 12:35:19 UTC (rev 25508)
@@ -33,6 +33,17 @@
   libgnunetregex.la
 endif
 
+noinst_LTLIBRARIES = libgnunetregextest.la
+
+libgnunetregextest_la_SOURCES = \
+  regex_test_lib.c regex_test_lib.h
+libgnunetregextest_la_LIBADD = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/regex/libgnunetregex.la
+libgnunetregextest_la_DEPENDENCIES = \
+  libgnunetregex.la
+
+
 noinst_PROGRAMS = $(noinst_mysql_progs) \
   perf-regex
 
@@ -40,7 +51,8 @@
   perf-regex.c
 perf_regex_LDADD = \
   $(top_builddir)/src/util/libgnunetutil.la \
-  $(top_builddir)/src/regex/libgnunetregex.la
+  $(top_builddir)/src/regex/libgnunetregex.la \
+  $(top_builddir)/src/regex/libgnunetregextest.la
 perf_regex_DEPENDENCIES = \
   libgnunetregex.la
 

Modified: gnunet/src/regex/perf-regex.c
===================================================================
--- gnunet/src/regex/perf-regex.c       2012-12-17 12:33:59 UTC (rev 25507)
+++ gnunet/src/regex/perf-regex.c       2012-12-17 12:35:19 UTC (rev 25508)
@@ -19,7 +19,7 @@
 */
 
 /**
- * @file regex/prof-regex.c
+ * @file src/regex/prof-regex.c
  * @brief Test how long it takes to create a automaton from a string regex.
  * @author Bartlomiej Polot
  */
@@ -27,6 +27,7 @@
 #include <time.h>
 #include "platform.h"
 #include "gnunet_regex_lib.h"
+#include "regex_test_lib.h"
 
 static const char *exe;
 
@@ -54,8 +55,6 @@
   unsigned int i;
   int compression;
   long size;
-  size_t len;
-  FILE *f;
 
   GNUNET_log_setup ("perf-regex", "DEBUG", NULL);
   exe = argv[0];
@@ -64,50 +63,7 @@
     usage();
     return 1;
   }
-  f = fopen (argv[1], "r");
-  if (NULL == f)
-  {
-    fprintf (stderr, "Can't open file %s\n", argv[1]);
-    usage();
-    return 2;
-  }
-  fseek (f, 0, SEEK_END);
-  size = ftell (f);
-  fprintf (stderr, "using file %s, size %ld\n", argv[1], size);
-  fseek (f, 0, SEEK_SET);
-  buffer = GNUNET_malloc (size + 1);
-  regexes = GNUNET_malloc (sizeof (char *));
-  nr = 1;
-  do
-  {
-    if (NULL == fgets (buffer, size + 1, f))
-    {
-      fprintf (stderr, "Can't read file %s\n", argv[1]);
-      usage();
-      return 3;
-    }
-    len = strlen (buffer);
-    if (len < 1)
-      continue;
-    if ('\n' == buffer[len - 1])
-    {
-      len--;
-      buffer[len] = '\0';
-    }
-    if (len < 6 || strncmp (&buffer[len - 6], "(0|1)*", 6) != 0)
-    {
-      fprintf (stderr, "\nWARNING:\n");
-      fprintf (stderr, "%s (line %u) does not end in (0|1)*\n", buffer, nr);
-    }
-    else
-    {
-      buffer[len - 6] = '\0';
-    }
-    GNUNET_array_grow (regexes, nr, nr+1);
-    regexes[nr - 2] = GNUNET_strdup (buffer);
-    regexes[nr - 1] = NULL;
-  } while (ftell(f) < size);
-  GNUNET_free (buffer);
+  regexes = GNUNET_REGEX_read_from_file (argv[1]);
 
   buffer = GNUNET_REGEX_combine (regexes);
 

Modified: gnunet/src/regex/regex.c
===================================================================
--- gnunet/src/regex/regex.c    2012-12-17 12:33:59 UTC (rev 25507)
+++ gnunet/src/regex/regex.c    2012-12-17 12:35:19 UTC (rev 25508)
@@ -3479,7 +3479,6 @@
                         NULL, a->start, iterator, iterator_cls);
 }
 
-
 /**
  * Create a string with binary IP notation for the given 'addr' in 'str'.
  *
@@ -3493,38 +3492,38 @@
 iptobinstr (const int af, const void *addr, char *str)
 {
   int i;
-
+  
   switch (af)
   {
-  case AF_INET:
-  {
-    uint32_t b = htonl (((struct in_addr *) addr)->s_addr);
-
-    str[32] = '\0';
-    str += 31;
-    for (i = 31; i >= 0; i--)
+    case AF_INET:
     {
-      *str = (b & 1) + '0';
-      str--;
-      b >>= 1;
+      uint32_t b = htonl (((struct in_addr *) addr)->s_addr);
+      
+      str[32] = '\0';
+          str += 31;
+          for (i = 31; i >= 0; i--)
+          {
+            *str = (b & 1) + '0';
+            str--;
+            b >>= 1;
+          }
+              break;
     }
-    break;
-  }
-  case AF_INET6:
-  {
-    struct in6_addr b = *(const struct in6_addr *) addr;
-
-    str[128] = '\0';
-    str += 127;
-    for (i = 127; i >= 0; i--)
+    case AF_INET6:
     {
-      *str = (b.s6_addr[i / 8] & 1) + '0';
-      str--;
-      b.s6_addr[i / 8] >>= 1;
+      struct in6_addr b = *(const struct in6_addr *) addr;
+      
+      str[128] = '\0';
+            str += 127;
+            for (i = 127; i >= 0; i--)
+            {
+              *str = (b.s6_addr[i / 8] & 1) + '0';
+            str--;
+            b.s6_addr[i / 8] >>= 1;
+            }
+                break;
     }
-    break;
   }
-  }
 }
 
 
@@ -3541,7 +3540,7 @@
   struct in_addr a;
   unsigned int len;
   uint32_t t;
-
+  
   if (1 != inet_pton (AF_INET, netmask, &a))
     return 0;
   len = 32;
@@ -3564,12 +3563,12 @@
                           char *rxstr)
 {
   unsigned int pfxlen;
-
+  
   pfxlen = ipv4netmasktoprefixlen (netmask);
   iptobinstr (AF_INET, ip, rxstr);
   rxstr[pfxlen] = '\0';
-  if (pfxlen < 32)
-    strcat (rxstr, "(0|1)+");
+            if (pfxlen < 32)
+              strcat (rxstr, "(0|1)+");
 }
 
 
@@ -3587,136 +3586,9 @@
 {
   iptobinstr (AF_INET6, ipv6, rxstr);
   rxstr[prefixlen] = '\0';
-  if (prefixlen < 128)
-    strcat (rxstr, "(0|1)+");
+    if (prefixlen < 128)
+      strcat (rxstr, "(0|1)+");
 }
 
 
-struct RegexCombineCtx {
-  struct RegexCombineCtx *next;
-  struct RegexCombineCtx *prev;
-
-  struct RegexCombineCtx *head;
-  struct RegexCombineCtx *tail;
-
-  char *s;
-};
-
-
-static char *
-regex_combine (struct RegexCombineCtx *ctx)
-{
-  struct RegexCombineCtx *p;
-  size_t len;
-  char *regex;
-  char *tmp;
-  char *s;
-
-  if (NULL != ctx->s)
-    GNUNET_asprintf (&regex, "%s(", ctx->s);
-  else
-    regex = GNUNET_strdup ("(");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "prefix: %s\n", regex);
-
-  for (p = ctx->head; NULL != p; p = p->next)
-  {
-    s = regex_combine (p);
-    GNUNET_asprintf (&tmp, "%s%s|", regex, s);
-    GNUNET_free_non_null (s);
-    GNUNET_free_non_null (regex);
-    regex = tmp;
-  }
-  len = strlen (regex);
-  if (1 == len)
-    return GNUNET_strdup ("");
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pre-partial: %s\n", regex);
-  if ('|' == regex[len - 1])
-    regex[len - 1] = ')';
-  if ('(' == regex[len - 1])
-    regex[len - 1] = '\0';
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "partial: %s\n", regex);
-  return regex;
-}
-
-static void
-regex_add (struct RegexCombineCtx *ctx, const char *regex)
-{
-  struct RegexCombineCtx *p;
-  const char *rest;
-
-  rest = &regex[1];
-  for (p = ctx->head; NULL != p; p = p->next)
-  {
-    if (p->s[0] == regex[0])
-    {
-      if (1 == strlen(p->s))
-      {
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "common char %s\n", p->s);
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "adding %s\n", rest);
-        regex_add (p, rest);
-      }
-      else
-      {
-        struct RegexCombineCtx *new;
-        new = GNUNET_malloc (sizeof (struct RegexCombineCtx));
-        new->s = GNUNET_strdup (&p->s[1]);
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " p has now %s\n", p->s);
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " p will have %.1s\n", p->s);
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " regex is %s\n", regex);
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " new has now %s\n", new->s);
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " rest is now %s\n", rest);
-        p->s[1] = '\0'; /* dont realloc */
-        GNUNET_CONTAINER_DLL_insert (p->head, p->tail, new);
-        regex_add (p, rest);
-      }
-      return;
-    }
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " no  match\n");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " new state %s\n", regex);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " under %s\n", ctx->s);
-  p = GNUNET_malloc (sizeof (struct RegexCombineCtx));
-  p->s = GNUNET_strdup (regex);
-  GNUNET_CONTAINER_DLL_insert (ctx->head, ctx->tail, p);
-}
-/*
-static void
-debug (struct RegexCombineCtx *ctx, int lvl)
-{
-  struct RegexCombineCtx *p;
-  unsigned int i;
-
-  for (i = 0; i < lvl; i++) fprintf (stderr, " ");
-  fprintf (stderr, "%s\n", ctx->s);
-
-  for (p = ctx->head; NULL != p; p = p->next)
-  {
-    debug (p, lvl + 2);
-  }
-}*/
-
-char *
-GNUNET_REGEX_combine (char * const regexes[])
-{
-  unsigned int i;
-  char *combined;
-  const char *current;
-  struct RegexCombineCtx ctx;
-
-  memset (&ctx, 0, sizeof (struct RegexCombineCtx));
-  for (i = 0; regexes[i]; i++)
-  {
-    current = regexes[i];
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Regex %u: %s\n", i, current);
-    regex_add (&ctx, current);
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\nCombining...\n");
-
-  combined = regex_combine (&ctx);
-
-  return combined;
-}
-
 /* end of regex.c */

Added: gnunet/src/regex/regex_test_lib.c
===================================================================
--- gnunet/src/regex/regex_test_lib.c                           (rev 0)
+++ gnunet/src/regex/regex_test_lib.c   2012-12-17 12:35:19 UTC (rev 25508)
@@ -0,0 +1,248 @@
+/*
+ *  This file is part of GNUnet
+ *  (C) 2012 Christian Grothoff (and other contributing authors)
+ * 
+ *  GNUnet is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published
+ *  by the Free Software Foundation; either version 3, or (at your
+ *  option) any later version.
+ * 
+ *  GNUnet is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ * 
+ *  You should have received a copy of the GNU General Public License
+ *  along with GNUnet; see the file COPYING.  If not, write to the
+ *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ *  Boston, MA 02111-1307, USA.
+ */
+/**
+ * @file src/regex/regex_test_lib.c
+ * @brief library to read regexes representing IP networks from a file.
+ *        and simplyfinying the into one big regex, in order to run
+ *        tests (regex performance, mesh profiler).
+ * @author Bartlomiej Polot
+ */
+
+#include "platform.h"
+#include "gnunet_util_lib.h"
+
+struct RegexCombineCtx {
+  struct RegexCombineCtx *next;
+  struct RegexCombineCtx *prev;
+
+  struct RegexCombineCtx *head;
+  struct RegexCombineCtx *tail;
+
+  char *s;
+};
+
+
+static char *
+regex_combine (struct RegexCombineCtx *ctx)
+{
+  struct RegexCombineCtx *p;
+  size_t len;
+  char *regex;
+  char *tmp;
+  char *s;
+
+  if (NULL != ctx->s)
+    GNUNET_asprintf (&regex, "%s(", ctx->s);
+  else
+    regex = GNUNET_strdup ("(");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "prefix: %s\n", regex);
+
+  for (p = ctx->head; NULL != p; p = p->next)
+  {
+    s = regex_combine (p);
+    GNUNET_asprintf (&tmp, "%s%s|", regex, s);
+    GNUNET_free_non_null (s);
+    GNUNET_free_non_null (regex);
+    regex = tmp;
+  }
+  len = strlen (regex);
+  if (1 == len)
+    return GNUNET_strdup ("");
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pre-partial: %s\n", regex);
+  if ('|' == regex[len - 1])
+    regex[len - 1] = ')';
+  if ('(' == regex[len - 1])
+    regex[len - 1] = '\0';
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "partial: %s\n", regex);
+  return regex;
+}
+
+static void
+regex_add (struct RegexCombineCtx *ctx, const char *regex)
+{
+  struct RegexCombineCtx *p;
+  const char *rest;
+
+  rest = &regex[1];
+  for (p = ctx->head; NULL != p; p = p->next)
+  {
+    if (p->s[0] == regex[0])
+    {
+      if (1 == strlen(p->s))
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "common char %s\n", p->s);
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "adding %s\n", rest);
+        regex_add (p, rest);
+      }
+      else
+      {
+        struct RegexCombineCtx *new;
+        new = GNUNET_malloc (sizeof (struct RegexCombineCtx));
+        new->s = GNUNET_strdup (&p->s[1]);
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " p has now %s\n", p->s);
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " p will have %.1s\n", p->s);
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " regex is %s\n", regex);
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " new has now %s\n", new->s);
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " rest is now %s\n", rest);
+        p->s[1] = '\0'; /* dont realloc */
+        GNUNET_CONTAINER_DLL_insert (p->head, p->tail, new);
+        regex_add (p, rest);
+      }
+      return;
+    }
+  }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " no  match\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " new state %s\n", regex);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " under %s\n", ctx->s);
+  p = GNUNET_malloc (sizeof (struct RegexCombineCtx));
+  p->s = GNUNET_strdup (regex);
+  GNUNET_CONTAINER_DLL_insert (ctx->head, ctx->tail, p);
+}
+
+
+/**
+ * Return a prefix-combine regex that matches the same strings as
+ * any of the original regexes.
+ *
+ * WARNING: only useful for reading specific regexes for specific applications,
+ *          namely the gnunet-regex-profiler / gnunet-regex-daemon.
+ *          This function DOES NOT support arbitrary regex combining.
+ */
+char *
+GNUNET_REGEX_combine (char * const regexes[])
+{
+  unsigned int i;
+  char *combined;
+  const char *current;
+  struct RegexCombineCtx ctx;
+
+  memset (&ctx, 0, sizeof (struct RegexCombineCtx));
+  for (i = 0; regexes[i]; i++)
+  {
+    current = regexes[i];
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Regex %u: %s\n", i, current);
+    regex_add (&ctx, current);
+  }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\nCombining...\n");
+
+  combined = regex_combine (&ctx);
+
+  return combined;
+}
+
+
+/**
+ * Read a set of regexes from a file, one per line and return them in an array
+ * suitable for GNUNET_REGEX_combine.
+ * The array must be free'd using GNUNET_REGEX_free_from_file.
+ *
+ * @param filename Name of the file containing the regexes.
+ *
+ * @return A newly allocated, NULL terminated array of regexes.
+ */
+char **
+GNUNET_REGEX_read_from_file (const char *filename)
+{
+  struct GNUNET_DISK_FileHandle *f;
+  unsigned int nr;
+  unsigned int offset;
+  off_t size;
+  size_t len;
+  char *buffer;
+  char *regex;
+  char **regexes;
+
+  f = GNUNET_DISK_file_open (filename,
+                             GNUNET_DISK_OPEN_READ,
+                             GNUNET_DISK_PERM_NONE);
+  if (NULL == f)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Can't open file %s for reading\n", filename);
+    return NULL;
+  }
+  if (GNUNET_OK != GNUNET_DISK_file_handle_size (f, &size))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Can't get size of file %s\n", filename);
+    return NULL;
+  }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "using file %s, size %llu\n",
+              filename, (unsigned long long) size);
+
+  buffer = GNUNET_malloc (size + 1);
+  GNUNET_DISK_file_read (f, buffer, size);
+  GNUNET_DISK_file_close (f);
+  regexes = GNUNET_malloc (sizeof (char *));
+  nr = 1;
+  offset = 0;
+  regex = NULL;
+  do
+  {
+    if (NULL == regex)
+      regex = GNUNET_malloc (size + 1);
+    len = (size_t) sscanf (&buffer[offset], "%s", regex);
+    if (0 == len)
+      break;
+    len = strlen (regex);
+    offset += len + 1;
+    if (len < 1)
+      continue;
+    if (len < 6 || strncmp (&regex[len - 6], "(0|1)*", 6) != 0)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  "%s (line %u) does not end in \"(0|1)*\"\n",
+                  buffer, nr);
+    }
+    else
+    {
+      len -= 6;
+      buffer[len] = '\0';
+    }
+    regex = GNUNET_realloc (regex, len + 1);
+    GNUNET_array_grow (regexes, nr, nr + 1);
+    regexes[nr - 2] = regex;
+    regexes[nr - 1] = NULL;
+  } while (offset < size);
+  GNUNET_free (buffer);
+
+  return regexes;
+}
+
+
+/**
+ * Free all memory reserved for a set of regexes created by read_from_file.
+ *
+ * @param regexes NULL-terminated array of regexes.
+ */
+void
+GNUNET_REGEX_free_from_file (char **regexes)
+{
+  unsigned int i;
+
+  for (i = 0; regexes[i]; i++)
+    GNUNET_free (regexes[i]);
+  GNUNET_free (regexes);
+}
+
+/* end of regex_test_lib.c */
\ No newline at end of file

Added: gnunet/src/regex/regex_test_lib.h
===================================================================
--- gnunet/src/regex/regex_test_lib.h                           (rev 0)
+++ gnunet/src/regex/regex_test_lib.h   2012-12-17 12:35:19 UTC (rev 25508)
@@ -0,0 +1,80 @@
+/*
+ *  This file is part of GNUnet
+ *  (C) 2012 Christian Grothoff (and other contributing authors)
+ * 
+ *  GNUnet is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published
+ *  by the Free Software Foundation; either version 3, or (at your
+ *  option) any later version.
+ * 
+ *  GNUnet is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ * 
+ *  You should have received a copy of the GNU General Public License
+ *  along with GNUnet; see the file COPYING.  If not, write to the
+ *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ *  Boston, MA 02111-1307, USA.
+ */
+/**
+ * @file src/regex/regex_test_lib.h
+ * @brief library to read regexes representing IP networks from a file.
+ *        and simplyfinying the into one big regex, in order to run
+ *        tests (regex performance, mesh profiler).
+ * @author Bertlomiej Polot
+ *
+ */
+
+#ifndef GNUNET_REGEX_TEST_LIB_H
+#define GNUNET_REGEX_TEST_LIB_H
+
+
+#ifdef __cplusplus
+extern "C"
+{
+  #if 0                           /* keep Emacsens' auto-indent happy */
+}
+#endif
+#endif
+
+/**
+ * Combine an array of regexes into a single prefix-shared regex.
+ *
+ * @param regexes A NULL-terminated array of regexes.
+ *
+ * @retrun A string with a single regex that matches any of the original 
regexes
+ */
+char *
+GNUNET_REGEX_combine(char * const regexes[]);
+
+/**
+ * Read a set of regexes from a file, one per line and return them in an array
+ * suitable for GNUNET_REGEX_combine.
+ * The array must be free'd using GNUNET_REGEX_free_from_file.
+ *
+ * @param filename Name of the file containing the regexes.
+ *
+ * @return A newly allocated, NULL terminated array of regexes.
+ */
+char **
+GNUNET_REGEX_read_from_file (const char *filename);
+
+
+/**
+ * Free all memory reserved for a set of regexes created by read_from_file.
+ *
+ * @param regexes NULL-terminated array of regexes.
+ */
+void
+GNUNET_REGEX_free_from_file (char **regexes);
+
+#if 0                           /* keep Emacsens' auto-indent happy */
+{
+  #endif
+  #ifdef __cplusplus
+}
+#endif
+
+/* end of gnunet_regex_lib.h */
+#endif
\ No newline at end of file




reply via email to

[Prev in Thread] Current Thread [Next in Thread]