cleanup
authorMaximilian Szengel <gnunet@maxsz.de>
Thu, 22 Mar 2012 21:25:43 +0000 (21:25 +0000)
committerMaximilian Szengel <gnunet@maxsz.de>
Thu, 22 Mar 2012 21:25:43 +0000 (21:25 +0000)
src/regex/regex.c

index b9a104faeb3800aa96f91c810ec12ff370d2611f..2c8082608e0cd56054536fa4debb359a148667d8 100644 (file)
@@ -168,16 +168,23 @@ nfa_create_state (int accepting)
   return s;
 }
 
+void
+nfa_destroy_state (struct State *s)
+{
+  if (s->tcnt > 0)
+    GNUNET_free (s->transitions);
+  GNUNET_free (s);
+}
+
 void
 nfa_add_transition (struct State *from_state, const char literal,
                     struct State *to_state)
 {
   struct Transition t;
 
-  if (NULL == to_state)
+  if (NULL == from_state || NULL == to_state)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Could not create Transition. to_state was NULL.\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not create Transition.\n");
     return;
   }
 
@@ -202,75 +209,6 @@ mark_all_states (struct GNUNET_REGEX_Nfa *n, int visited)
   }
 }
 
-void
-print_states (struct GNUNET_REGEX_Nfa *n, char **out_str)
-{
-  struct State *s;
-  int i_s;
-  int i_t;
-  char *s_all;
-
-  mark_all_states (n, 0);
-
-  s_all = GNUNET_malloc (sizeof (char));
-  *s_all = '\0';
-
-  for (i_s = 0; i_s < n->statecnt; i_s++)
-  {
-    struct Transition *ctran;
-    char *s_acc = NULL;
-    char *s_tran = NULL;
-
-    s = n->states[i_s];
-
-    if (s->accepting)
-    {
-      GNUNET_asprintf (&s_acc, "s%i [shape=doublecircle];\n", s->id);
-
-      s_all = GNUNET_realloc (s_all, strlen (s_all) + strlen (s_acc) + 1);
-      strcat (s_all, s_acc);
-      GNUNET_free (s_acc);
-    }
-
-    ctran = s->transitions;
-    s->visited = 1;
-
-    for (i_t = 0; i_t < s->tcnt && NULL != s->transitions; i_t++)
-    {
-      if (NULL == ctran)
-      {
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "s->transitions was NULL\n");
-      }
-
-      if (NULL == ctran->state)
-      {
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                    "Transition from State %i has has no state for transitioning\n",
-                    s->id);
-      }
-
-      if (ctran->literal == 0)
-      {
-        GNUNET_asprintf (&s_tran, "s%i -> s%i [label = \"epsilon\"];\n", s->id,
-                         ctran->state->id);
-      }
-      else
-      {
-        GNUNET_asprintf (&s_tran, "s%i -> s%i [label = \"%c\"];\n", s->id,
-                         ctran->state->id, ctran->literal);
-      }
-
-      s_all = GNUNET_realloc (s_all, strlen (s_all) + strlen (s_tran) + 1);
-      strcat (s_all, s_tran);
-      GNUNET_free (s_tran);
-
-      ctran++;
-    }
-  }
-
-  *out_str = s_all;
-}
-
 void
 nfa_add_concatenation ()
 {
@@ -527,8 +465,11 @@ GNUNET_REGEX_destroy_nfa (struct GNUNET_REGEX_Nfa *n)
 
   for (i = 0; i < n->statecnt; i++)
   {
-    GNUNET_free (n->states[i]);
+    nfa_destroy_state (n->states[i]);
   }
+
+  GNUNET_free (n->states);
+  GNUNET_free (n);
 }
 
 void