api changes
authorMaximilian Szengel <gnunet@maxsz.de>
Wed, 28 Mar 2012 15:49:20 +0000 (15:49 +0000)
committerMaximilian Szengel <gnunet@maxsz.de>
Wed, 28 Mar 2012 15:49:20 +0000 (15:49 +0000)
src/include/gnunet_regex_lib.h
src/regex/regex.c
src/regex/test_regex.c

index 46ca11ba2b36bd17464182fd8d9f4c5b31952466..d95ad3808916c99f0a6a670f85b96cbee6c5df7f 100644 (file)
@@ -43,8 +43,7 @@ extern "C"
 struct GNUNET_REGEX_Automaton;
 
 /**
- * Construct an NFA data structure by parsing the regex string of 
- * length len.
+ * Construct an NFA by parsing the regex string of length 'len'.
  *
  * @param regex regular expression string
  * @param len length of the string
@@ -54,6 +53,17 @@ struct GNUNET_REGEX_Automaton;
 struct GNUNET_REGEX_Automaton *
 GNUNET_REGEX_construct_nfa(const char *regex, const size_t len);
 
+/**
+ * Construct DFA for the given 'regex' of lenght 'len'
+ *
+ * @param regex regular expression string
+ * @param len length of the regular expression
+ *
+ * @return DFA. Needs to be freed using GNUNET_REGEX_destroy_automaton
+ */
+struct GNUNET_REGEX_Automaton *
+GNUNET_REGEX_construct_dfa (const char *regex, const size_t len);
+
 /**
  * Free the memory allocated by constructing the GNUNET_REGEX_Automaton
  * data structure.
@@ -61,29 +71,17 @@ GNUNET_REGEX_construct_nfa(const char *regex, const size_t len);
  * @param a automaton to be destroyed
  */
 void
-GNUNET_REGEX_destroy_automaton(struct GNUNET_REGEX_Automaton *a);
+GNUNET_REGEX_automaton_destroy(struct GNUNET_REGEX_Automaton *a);
 
 /**
- * Save the given NFA as a GraphViz dot file
+ * Save the given automaton as a GraphViz dot file
  *
- * @param n NFA to be saved
+ * @param a the automaton to be saved
  * @param filename where to save the file
  */
 void
-GNUNET_REGEX_save_nfa_graph(struct GNUNET_REGEX_Automaton *n,
-                            const char *filename);
-
-
-/**
- * Construct DFA for the given 'regex' of lenght 'len'
- *
- * @param regex regular expression string
- * @param len length of the regular expression
- *
- * @return DFA. Needs to be freed using GNUNET_REGEX_destroy_automaton
- */
-struct GNUNET_REGEX_Automaton *
-GNUNET_REGEX_construct_dfa (const char *regex, const size_t len);
+GNUNET_REGEX_automaton_save_graph(struct GNUNET_REGEX_Automaton *a,
+                                  const char *filename);
 
 #if 0                           /* keep Emacsens' auto-indent happy */
 {
index bbfc71f1c0978761f17a2f78fe4bac43f97cc5bb..a98e187f548162e54243d6ab5b0d169e52a7a806 100644 (file)
@@ -724,8 +724,16 @@ GNUNET_REGEX_move (struct GNUNET_REGEX_Automaton *a, struct State *s,
   return l;
 }
 
+/**
+ * Construct an NFA by parsing the regex string of length 'len'.
+ *
+ * @param regex regular expression string
+ * @param len length of the string
+ *
+ * @return NFA.Needs to be freed using GNUNET_REGEX_destroy_automaton
+ */
 struct GNUNET_REGEX_Automaton *
-GNUNET_REGEX_construct_nfa (const char *regex, const size_t len)
+GNUNET_REGEX_construct_nfa(const char *regex, const size_t len)
 {
   struct GNUNET_REGEX_Context ctx;
   struct GNUNET_REGEX_Automaton *nfa;
@@ -862,15 +870,20 @@ error:
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", error_msg);
   GNUNET_free (p);
   while (!stack_empty (ctx.stack))
-    GNUNET_REGEX_destroy_automaton (stack_pop
-                                    (ctx.stack,
-                                     sizeof (struct GNUNET_REGEX_Automaton)));
+    GNUNET_REGEX_automaton_destroy (stack_pop (ctx.stack,
+                                               sizeof (struct GNUNET_REGEX_Automaton)));
   GNUNET_REGEX_context_destroy (&ctx);
   return NULL;
 }
 
+/**
+ * Free the memory allocated by constructing the GNUNET_REGEX_Automaton
+ * data structure.
+ *
+ * @param a automaton to be destroyed
+ */
 void
-GNUNET_REGEX_destroy_automaton (struct GNUNET_REGEX_Automaton *a)
+GNUNET_REGEX_automaton_destroy(struct GNUNET_REGEX_Automaton *a)
 {
   struct GNUNET_CONTAINER_SList_Iterator it;
 
@@ -888,7 +901,14 @@ GNUNET_REGEX_destroy_automaton (struct GNUNET_REGEX_Automaton *a)
   GNUNET_free (a);
 }
 
-
+/**
+ * Construct DFA for the given 'regex' of lenght 'len'
+ *
+ * @param regex regular expression string
+ * @param len length of the regular expression
+ *
+ * @return DFA. Needs to be freed using GNUNET_REGEX_destroy_automaton
+ */
 struct GNUNET_REGEX_Automaton *
 GNUNET_REGEX_construct_dfa (const char *regex, const size_t len)
 {
@@ -966,7 +986,7 @@ GNUNET_REGEX_construct_dfa (const char *regex, const size_t len)
     GNUNET_CONTAINER_slist_iter_destroy (&tranit);
   }
   GNUNET_CONTAINER_slist_destroy (dfa_stack);
-  GNUNET_REGEX_destroy_automaton (nfa);
+  GNUNET_REGEX_automaton_destroy (nfa);
   GNUNET_REGEX_context_destroy (&ctx);
   dfa_clear_nfa_set (dfa->states);
 
@@ -976,9 +996,15 @@ GNUNET_REGEX_construct_dfa (const char *regex, const size_t len)
   return dfa;
 }
 
+/**
+ * Save the given automaton as a GraphViz dot file
+ *
+ * @param a the automaton to be saved
+ * @param filename where to save the file
+ */
 void
-GNUNET_REGEX_save_nfa_graph (struct GNUNET_REGEX_Automaton *n,
-                             const char *filename)
+GNUNET_REGEX_automaton_save_graph(struct GNUNET_REGEX_Automaton *a,
+                                  const char *filename)
 {
   struct GNUNET_CONTAINER_SList_Iterator stateit;
   struct GNUNET_CONTAINER_SList_Iterator tranit;
@@ -990,7 +1016,7 @@ GNUNET_REGEX_save_nfa_graph (struct GNUNET_REGEX_Automaton *n,
   char *end;
   FILE *p;
 
-  if (NULL == n)
+  if (NULL == a)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not print NFA, was NULL!");
     return;
@@ -1014,7 +1040,7 @@ GNUNET_REGEX_save_nfa_graph (struct GNUNET_REGEX_Automaton *n,
   start = "digraph G {\nrankdir=LR\n";
   fwrite (start, strlen (start), 1, p);
 
-  for (stateit = GNUNET_CONTAINER_slist_begin (n->states);
+  for (stateit = GNUNET_CONTAINER_slist_begin (a->states);
        GNUNET_YES != GNUNET_CONTAINER_slist_end (&stateit);
        GNUNET_CONTAINER_slist_next (&stateit))
   {
index e4e8d45217f6d653828a10ff2e42b0e3eceb1daf..dcc4ce0edd89e90212051614d9beb234315530c1 100644 (file)
@@ -53,8 +53,8 @@ main (int argc, char *argv[])
 
   if (nfa)
   {
-    GNUNET_REGEX_save_nfa_graph (nfa, "nfa_graph.dot");
-    GNUNET_REGEX_destroy_automaton (nfa);
+    GNUNET_REGEX_automaton_save_graph (nfa, "nfa_graph.dot");
+    GNUNET_REGEX_automaton_destroy (nfa);
   }
   else
     err = 1;
@@ -62,8 +62,8 @@ main (int argc, char *argv[])
   dfa = GNUNET_REGEX_construct_dfa (regex, strlen (regex));
   if (dfa)
   {
-    GNUNET_REGEX_save_nfa_graph (dfa, "dfa_graph.dot");
-    GNUNET_REGEX_destroy_automaton (dfa);
+    GNUNET_REGEX_automaton_save_graph (dfa, "dfa_graph.dot");
+    GNUNET_REGEX_automaton_destroy (dfa);
   }
   return err;
 }