aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/regex/regex_internal.h6
-rw-r--r--src/regex/test_regex_iterate_api.c22
2 files changed, 19 insertions, 9 deletions
diff --git a/src/regex/regex_internal.h b/src/regex/regex_internal.h
index 7ab51ba69..3e4d0ca0e 100644
--- a/src/regex/regex_internal.h
+++ b/src/regex/regex_internal.h
@@ -378,9 +378,9 @@ struct GNUNET_REGEX_Context
378 * @param stride_len length of the strides. 378 * @param stride_len length of the strides.
379 */ 379 */
380void 380void
381GNUNET_REGEX_add_multi_strides_to_dfa (struct GNUNET_REGEX_Context *regex_ctx, 381GNUNET_REGEX_dfa_add_multi_strides (struct GNUNET_REGEX_Context *regex_ctx,
382 struct GNUNET_REGEX_Automaton *dfa, 382 struct GNUNET_REGEX_Automaton *dfa,
383 const unsigned int stride_len); 383 const unsigned int stride_len);
384 384
385 385
386/** 386/**
diff --git a/src/regex/test_regex_iterate_api.c b/src/regex/test_regex_iterate_api.c
index afbb548c7..b8f3cd266 100644
--- a/src/regex/test_regex_iterate_api.c
+++ b/src/regex/test_regex_iterate_api.c
@@ -30,13 +30,20 @@
30 30
31static unsigned int transition_counter; 31static unsigned int transition_counter;
32 32
33struct IteratorContext
34{
35 int error;
36 int should_save_graph;
37 FILE *graph_file;
38};
39
33void 40void
34key_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof, 41key_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof,
35 int accepting, unsigned int num_edges, 42 int accepting, unsigned int num_edges,
36 const struct GNUNET_REGEX_Edge *edges) 43 const struct GNUNET_REGEX_Edge *edges)
37{ 44{
38 unsigned int i; 45 unsigned int i;
39 int *error = cls; 46 struct IteratorContext *ctx = cls;
40 47
41 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating... (accepting: %i)\n", 48 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating... (accepting: %i)\n",
42 accepting); 49 accepting);
@@ -54,7 +61,7 @@ key_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof,
54 i, edges[i].label, GNUNET_h2s (&edges[i].destination)); 61 i, edges[i].label, GNUNET_h2s (&edges[i].destination));
55 } 62 }
56 63
57 *error += (GNUNET_OK == GNUNET_REGEX_check_proof (proof, key)) ? 0 : 1; 64 ctx->error += (GNUNET_OK == GNUNET_REGEX_check_proof (proof, key)) ? 0 : 1;
58} 65}
59 66
60int 67int
@@ -69,9 +76,10 @@ main (int argc, char *argv[])
69 NULL); 76 NULL);
70 77
71 int error; 78 int error;
72 int i;
73 struct GNUNET_REGEX_Automaton *dfa; 79 struct GNUNET_REGEX_Automaton *dfa;
80 unsigned int i;
74 unsigned int num_transitions; 81 unsigned int num_transitions;
82 struct IteratorContext ctx = { 0, 0, NULL };
75 83
76 error = 0; 84 error = 0;
77 85
@@ -99,7 +107,7 @@ main (int argc, char *argv[])
99 { 107 {
100 transition_counter = 0; 108 transition_counter = 0;
101 dfa = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i])); 109 dfa = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]));
102 GNUNET_REGEX_iterate_all_edges (dfa, key_iterator, &error); 110 GNUNET_REGEX_iterate_all_edges (dfa, key_iterator, &ctx);
103 num_transitions = GNUNET_REGEX_get_transition_count (dfa); 111 num_transitions = GNUNET_REGEX_get_transition_count (dfa);
104 if (transition_counter != num_transitions) 112 if (transition_counter != num_transitions)
105 { 113 {
@@ -113,10 +121,12 @@ main (int argc, char *argv[])
113 for (i = 0; i < 17; i++) 121 for (i = 0; i < 17; i++)
114 { 122 {
115 dfa = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i])); 123 dfa = GNUNET_REGEX_construct_dfa (regex[i], strlen (regex[i]));
116 GNUNET_REGEX_add_multi_strides_to_dfa (NULL, dfa, 2); 124 GNUNET_REGEX_dfa_add_multi_strides (NULL, dfa, 2);
117 GNUNET_REGEX_iterate_all_edges (dfa, key_iterator, &error); 125 GNUNET_REGEX_iterate_all_edges (dfa, key_iterator, &ctx);
118 GNUNET_REGEX_automaton_destroy (dfa); 126 GNUNET_REGEX_automaton_destroy (dfa);
119 } 127 }
120 128
129 error += ctx.error;
130
121 return error; 131 return error;
122} 132}