aboutsummaryrefslogtreecommitdiff
path: root/src/regex/regex.c
diff options
context:
space:
mode:
authorMaximilian Szengel <gnunet@maxsz.de>2012-03-28 15:49:20 +0000
committerMaximilian Szengel <gnunet@maxsz.de>2012-03-28 15:49:20 +0000
commitc722eb033c1295d88a7c3c7366625207b7ea6627 (patch)
tree9287c4973a9812da76300848d2e806a65e72eabc /src/regex/regex.c
parentba5736672201f5c3a97c7e8b46f716077b416d6c (diff)
downloadgnunet-c722eb033c1295d88a7c3c7366625207b7ea6627.tar.gz
gnunet-c722eb033c1295d88a7c3c7366625207b7ea6627.zip
api changes
Diffstat (limited to 'src/regex/regex.c')
-rw-r--r--src/regex/regex.c48
1 files changed, 37 insertions, 11 deletions
diff --git a/src/regex/regex.c b/src/regex/regex.c
index bbfc71f1c..a98e187f5 100644
--- a/src/regex/regex.c
+++ b/src/regex/regex.c
@@ -724,8 +724,16 @@ GNUNET_REGEX_move (struct GNUNET_REGEX_Automaton *a, struct State *s,
724 return l; 724 return l;
725} 725}
726 726
727/**
728 * Construct an NFA by parsing the regex string of length 'len'.
729 *
730 * @param regex regular expression string
731 * @param len length of the string
732 *
733 * @return NFA.Needs to be freed using GNUNET_REGEX_destroy_automaton
734 */
727struct GNUNET_REGEX_Automaton * 735struct GNUNET_REGEX_Automaton *
728GNUNET_REGEX_construct_nfa (const char *regex, const size_t len) 736GNUNET_REGEX_construct_nfa(const char *regex, const size_t len)
729{ 737{
730 struct GNUNET_REGEX_Context ctx; 738 struct GNUNET_REGEX_Context ctx;
731 struct GNUNET_REGEX_Automaton *nfa; 739 struct GNUNET_REGEX_Automaton *nfa;
@@ -862,15 +870,20 @@ error:
862 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", error_msg); 870 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", error_msg);
863 GNUNET_free (p); 871 GNUNET_free (p);
864 while (!stack_empty (ctx.stack)) 872 while (!stack_empty (ctx.stack))
865 GNUNET_REGEX_destroy_automaton (stack_pop 873 GNUNET_REGEX_automaton_destroy (stack_pop (ctx.stack,
866 (ctx.stack, 874 sizeof (struct GNUNET_REGEX_Automaton)));
867 sizeof (struct GNUNET_REGEX_Automaton)));
868 GNUNET_REGEX_context_destroy (&ctx); 875 GNUNET_REGEX_context_destroy (&ctx);
869 return NULL; 876 return NULL;
870} 877}
871 878
879/**
880 * Free the memory allocated by constructing the GNUNET_REGEX_Automaton
881 * data structure.
882 *
883 * @param a automaton to be destroyed
884 */
872void 885void
873GNUNET_REGEX_destroy_automaton (struct GNUNET_REGEX_Automaton *a) 886GNUNET_REGEX_automaton_destroy(struct GNUNET_REGEX_Automaton *a)
874{ 887{
875 struct GNUNET_CONTAINER_SList_Iterator it; 888 struct GNUNET_CONTAINER_SList_Iterator it;
876 889
@@ -888,7 +901,14 @@ GNUNET_REGEX_destroy_automaton (struct GNUNET_REGEX_Automaton *a)
888 GNUNET_free (a); 901 GNUNET_free (a);
889} 902}
890 903
891 904/**
905 * Construct DFA for the given 'regex' of lenght 'len'
906 *
907 * @param regex regular expression string
908 * @param len length of the regular expression
909 *
910 * @return DFA. Needs to be freed using GNUNET_REGEX_destroy_automaton
911 */
892struct GNUNET_REGEX_Automaton * 912struct GNUNET_REGEX_Automaton *
893GNUNET_REGEX_construct_dfa (const char *regex, const size_t len) 913GNUNET_REGEX_construct_dfa (const char *regex, const size_t len)
894{ 914{
@@ -966,7 +986,7 @@ GNUNET_REGEX_construct_dfa (const char *regex, const size_t len)
966 GNUNET_CONTAINER_slist_iter_destroy (&tranit); 986 GNUNET_CONTAINER_slist_iter_destroy (&tranit);
967 } 987 }
968 GNUNET_CONTAINER_slist_destroy (dfa_stack); 988 GNUNET_CONTAINER_slist_destroy (dfa_stack);
969 GNUNET_REGEX_destroy_automaton (nfa); 989 GNUNET_REGEX_automaton_destroy (nfa);
970 GNUNET_REGEX_context_destroy (&ctx); 990 GNUNET_REGEX_context_destroy (&ctx);
971 dfa_clear_nfa_set (dfa->states); 991 dfa_clear_nfa_set (dfa->states);
972 992
@@ -976,9 +996,15 @@ GNUNET_REGEX_construct_dfa (const char *regex, const size_t len)
976 return dfa; 996 return dfa;
977} 997}
978 998
999/**
1000 * Save the given automaton as a GraphViz dot file
1001 *
1002 * @param a the automaton to be saved
1003 * @param filename where to save the file
1004 */
979void 1005void
980GNUNET_REGEX_save_nfa_graph (struct GNUNET_REGEX_Automaton *n, 1006GNUNET_REGEX_automaton_save_graph(struct GNUNET_REGEX_Automaton *a,
981 const char *filename) 1007 const char *filename)
982{ 1008{
983 struct GNUNET_CONTAINER_SList_Iterator stateit; 1009 struct GNUNET_CONTAINER_SList_Iterator stateit;
984 struct GNUNET_CONTAINER_SList_Iterator tranit; 1010 struct GNUNET_CONTAINER_SList_Iterator tranit;
@@ -990,7 +1016,7 @@ GNUNET_REGEX_save_nfa_graph (struct GNUNET_REGEX_Automaton *n,
990 char *end; 1016 char *end;
991 FILE *p; 1017 FILE *p;
992 1018
993 if (NULL == n) 1019 if (NULL == a)
994 { 1020 {
995 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not print NFA, was NULL!"); 1021 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not print NFA, was NULL!");
996 return; 1022 return;
@@ -1014,7 +1040,7 @@ GNUNET_REGEX_save_nfa_graph (struct GNUNET_REGEX_Automaton *n,
1014 start = "digraph G {\nrankdir=LR\n"; 1040 start = "digraph G {\nrankdir=LR\n";
1015 fwrite (start, strlen (start), 1, p); 1041 fwrite (start, strlen (start), 1, p);
1016 1042
1017 for (stateit = GNUNET_CONTAINER_slist_begin (n->states); 1043 for (stateit = GNUNET_CONTAINER_slist_begin (a->states);
1018 GNUNET_YES != GNUNET_CONTAINER_slist_end (&stateit); 1044 GNUNET_YES != GNUNET_CONTAINER_slist_end (&stateit);
1019 GNUNET_CONTAINER_slist_next (&stateit)) 1045 GNUNET_CONTAINER_slist_next (&stateit))
1020 { 1046 {