aboutsummaryrefslogtreecommitdiff
path: root/src/regex/regex.c
diff options
context:
space:
mode:
authorszengel <szengel@140774ce-b5e7-0310-ab8b-a85725594a96>2012-06-06 14:35:05 +0000
committerszengel <szengel@140774ce-b5e7-0310-ab8b-a85725594a96>2012-06-06 14:35:05 +0000
commit81cf3679c745d66a6d71c27b98685fd44b39aa00 (patch)
treef4a0155bc59b73d28265f9ee4ba0944ed4278d2e /src/regex/regex.c
parente15bf6bc5236d7edf9a6047aeec401d3b757fc70 (diff)
Test for computed regex.
git-svn-id: https://gnunet.org/svn/gnunet@21787 140774ce-b5e7-0310-ab8b-a85725594a96
Diffstat (limited to 'src/regex/regex.c')
-rw-r--r--src/regex/regex.c55
1 files changed, 53 insertions, 2 deletions
diff --git a/src/regex/regex.c b/src/regex/regex.c
index 67cadfc5e8..cd08b8dcd2 100644
--- a/src/regex/regex.c
+++ b/src/regex/regex.c
@@ -116,6 +116,16 @@ struct GNUNET_REGEX_Automaton
* Type of the automaton.
*/
enum GNUNET_REGEX_automaton_type type;
+
+ /**
+ * Regex
+ */
+ char *regex;
+
+ /**
+ * Computed regex (result of RX->NFA->DFA->RX)
+ */
+ char *computed_regex;
};
/**
@@ -799,7 +809,7 @@ automaton_traverse (void *cls, struct GNUNET_REGEX_Automaton *a,
/**
* Create proofs for all states in the given automaton. Implementation of the
- * algorithms descriped in chapter 3.2.1 of "Automata Theory, Languages, and
+ * algorithm descriped in chapter 3.2.1 of "Automata Theory, Languages, and
* Computation 3rd Edition" by Hopcroft, Motwani and Ullman.
*
* @param a automaton.
@@ -821,6 +831,7 @@ automaton_create_proofs (struct GNUNET_REGEX_Automaton *a)
char *R_cur_r;
int length_l;
int length_r;
+ char *complete_regex;
k = 0;
n = a->state_count;
@@ -853,7 +864,6 @@ automaton_create_proofs (struct GNUNET_REGEX_Automaton *a)
}
}
-
if (i == j)
{
if (NULL == R_last[i][j])
@@ -973,6 +983,26 @@ automaton_create_proofs (struct GNUNET_REGEX_Automaton *a)
&states[i]->hash);
}
+ // complete regex for whole DFA
+ complete_regex = NULL;
+ for (i = 0; i < n; i++)
+ {
+ if (states[i]->accepting)
+ {
+ if (NULL == complete_regex)
+ GNUNET_asprintf (&complete_regex, "%s", R_last[a->start->marked][i]);
+ else if (NULL != R_last[a->start->marked][i] &&
+ 0 != strcmp (R_last[a->start->marked][i], ""))
+ {
+ temp = complete_regex;
+ GNUNET_asprintf (&complete_regex, "%s|%s", complete_regex,
+ R_last[a->start->marked][i]);
+ GNUNET_free (temp);
+ }
+ }
+ }
+ a->computed_regex = complete_regex;
+
// cleanup
for (i = 0; i < n; i++)
{
@@ -1867,6 +1897,8 @@ GNUNET_REGEX_construct_nfa (const char *regex, const size_t len)
goto error;
}
+ nfa->regex = GNUNET_strdup (regex);
+
return nfa;
error:
@@ -1968,6 +2000,7 @@ GNUNET_REGEX_construct_dfa (const char *regex, const size_t len)
dfa = GNUNET_malloc (sizeof (struct GNUNET_REGEX_Automaton));
dfa->type = DFA;
+ dfa->regex = GNUNET_strdup (regex);
// Create DFA start state from epsilon closure
nfa_set = nfa_closure_create (nfa, nfa->start, 0);
@@ -2005,6 +2038,8 @@ GNUNET_REGEX_automaton_destroy (struct GNUNET_REGEX_Automaton *a)
if (NULL == a)
return;
+ GNUNET_free (a->regex);
+
for (s = a->states_head; NULL != s;)
{
next_state = s->next;
@@ -2242,6 +2277,22 @@ GNUNET_REGEX_eval (struct GNUNET_REGEX_Automaton *a, const char *string)
}
/**
+ * Get the computed regex of the given automaton.
+ * When constructing the automaton a proof is computed for each state,
+ * consisting of the regular expression leading to this state. A complete
+ * regex for the automaton can be computed by combining these proofs.
+ * As of now this computed regex is only useful for testing.
+ */
+const char *
+GNUNET_REGEX_get_computed_regex (struct GNUNET_REGEX_Automaton *a)
+{
+ if (NULL == a)
+ return NULL;
+
+ return a->computed_regex;
+}
+
+/**
* Get the first key for the given 'input_string'. This hashes the first x bits
* of the 'input_strings'.
*