RPA Toolkit
Modified testrex
authorMartin Stoilov <martin@sigmadrone.org>
Thu, 28 Apr 2016 06:21:05 +0000 (23:21 -0700)
committerMartin Stoilov <martin@sigmadrone.org>
Thu, 28 Apr 2016 06:21:05 +0000 (23:21 -0700)
rex/rexstate.h
tests/testrex/main.c

index dacf4ac..0d04c2b 100644 (file)
@@ -40,8 +40,8 @@ struct rexstate_s {
        rarray_t *etrans;
        rarray_t *trans;
        rarray_t *subset;
-       unsigned long type;
-       unsigned long uid;
+       unsigned long type;                     /* REX_STATETYPE_START, REX_STATETYPE_ACCEPT, ... */
+       unsigned long uid;                      /* The index of this state in the array of states in rexdb_t */
        rexuserdata_t userdata;
 };
 
index 814ea27..a483c56 100644 (file)
@@ -57,11 +57,13 @@ static void init_ababb(rexdb_t *nfa)
 
 static void init_s4(rexdb_t *nfa)
 {
-       rexstate_t *s1 = rex_state_create(0, REX_STATETYPE_START);
+       rexstate_t *s0 = rex_state_create(0, REX_STATETYPE_NONE);       /* Dummy state, not used */
+       rexstate_t *s1 = rex_state_create(1, REX_STATETYPE_START);
        rexstate_t *s2 = rex_state_create(2, REX_STATETYPE_NONE);
        rexstate_t *s3 = rex_state_create(3, REX_STATETYPE_ACCEPT);
        rexstate_t *s4 = rex_state_create(4, REX_STATETYPE_NONE);
 
+       rex_db_insertstate(nfa, s0);
        rex_db_insertstate(nfa, s1);
        rex_db_insertstate(nfa, s2);
        rex_db_insertstate(nfa, s3);
@@ -72,6 +74,7 @@ static void init_s4(rexdb_t *nfa)
 
        rex_state_addtransition_dst(s1, 'a', 'a', s2);
        rex_state_addtransition_dst(s2, 'b', 'b', s3);
+       rex_state_addtransition_dst(s3, 'a', 'a', s2);
        rex_state_addtransition_dst(s1, 'c', 'c', s4);
        rex_state_addtransition_dst(s4, 'c', 'c', s3);
 }
@@ -102,17 +105,19 @@ int main(int argc, char *argv[])
                        }
                } else if (strcmp(argv[i], "-d") == 0) {
                        int j;
-                       rexdfa_t *dfa = rex_db_todfa(nfa, 1);
+                       rexdb_t *dfadb = rex_db_createdfa(nfa, 1);
+                       rexdfa_t *dfa = rex_db_todfa(dfadb, 1);
                        for (j = 0; j < dfa->nstates; j++) {
                                rex_dfa_dumpstate(dfa, j);
                        }
                        rex_dfa_destroy(dfa);
+                       rex_db_destroy(dfadb);
                } else if (strcmp(argv[i], "-ababb") == 0) {
                        init_ababb(nfa);
                        startstate = 0;
                } else if (strcmp(argv[i], "-s4") == 0) {
                        init_s4(nfa);
-                       startstate = 0;
+                       startstate = 1;
                } else {
                        if (startstate < 0)
                                return 1;