summaryrefslogtreecommitdiff
path: root/src/dfa.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dfa.c')
-rw-r--r--src/dfa.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/dfa.c b/src/dfa.c
index fb67047..9da201d 100644
--- a/src/dfa.c
+++ b/src/dfa.c
@@ -623,11 +623,14 @@ run_dfa(const dfa * const restrict table, const NUM code)
break;
}
- char *s = MYALLOC(char, 5);
+ /* negative codes have special purposes */
+ if (code < 0) return 0;
+
+ char s[5];
str *strp = new_str(s, 5);
if (encode(code, strp)) {
- destroy_str(strp, 1);
+ destroy_str(strp, 0);
fleprintf0("Fail to encode\n");
return 0;
}
@@ -636,33 +639,33 @@ run_dfa(const dfa * const restrict table, const NUM code)
for (NUM i = 0; i < str_length(strp); i++) {
unsigned char c = (unsigned char) *(s+i);
+
int lookup_value = 0;
for (int j = 0, len = 0; len <= c;) {
+
len += *(*(table->data.table.table+current_row)+(j<<1)+1);
lookup_value = *(*(table->data.table.table+current_row)
+(j++<<1));
}
- /* fleprintf("lookup_value = %d\n", lookup_value); */
-
if (lookup_value > 0) {
current_row = lookup_value;
} else {
switch (lookup_value) {
case DFA_STATE_REJECT:
- destroy_str(strp, 1);
+ destroy_str(strp, 0);
return 0;
break;
case DFA_STATE_UNKNOWN:
switch (table->type) {
case DFA_TYPE_BOTH:
case DFA_TYPE_POSITIVE:
- destroy_str(strp, 1);
+ destroy_str(strp, 0);
return 0;
break;
case DFA_TYPE_NEGATIVE:
- destroy_str(strp, 1);
+ destroy_str(strp, 0);
return 1;
break;
default:
@@ -670,26 +673,26 @@ run_dfa(const dfa * const restrict table, const NUM code)
the table is of the special type. But I am apparently
paranoia. */
fleprintf0("Special table in the wrong place\n");
- destroy_str(strp, 1);
+ destroy_str(strp, 0);
return 0;
break;
}
break;
case DFA_STATE_ACCEPT:
- destroy_str(strp, 1);
+ destroy_str(strp, 0);
return 1;
break;
default:
fleprintf("Unknown state number for char %d: %d\n",
c, lookup_value);
- destroy_str(strp, 1);
+ destroy_str(strp, 0);
return 0;
break;
}
}
}
- destroy_str(strp, 1);
+ destroy_str(strp, 0);
return 0;
}