aboutsummaryrefslogtreecommitdiff
path: root/src/crunch.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/crunch.c')
-rw-r--r--src/crunch.c29
1 files changed, 8 insertions, 21 deletions
diff --git a/src/crunch.c b/src/crunch.c
index 315469b..3ab8eff 100644
--- a/src/crunch.c
+++ b/src/crunch.c
@@ -30,10 +30,7 @@ typedef struct s_token {
struct s_token *kids;
} token_t;
-token_t root_tokens[256];
-
-/* not used for lookups, just a fast way to free() everything */
-token_t *tokentab[MAX_TOKENS];
+token_t tokens[MAX_TOKENS];
int token_bits;
int max_token;
@@ -44,12 +41,9 @@ int new_pos;
void init_table(void) {
int i;
- for(i = INIT_TOKEN; i < curr_token; i++)
- free(tokentab[i]);
-
for(i = 0; i < 256; i++) {
- root_tokens[i].chr = root_tokens[i].number = i;
- root_tokens[i].kids = root_tokens[i].sibling = 0;
+ tokens[i].chr = tokens[i].number = i;
+ tokens[i].kids = tokens[i].sibling = 0;
}
token_bits = INITIAL_BITS;
@@ -106,9 +100,9 @@ void dump_tokens(void) {
maxkidcount = maxlevel = totalkidcount = nodeswithkids = 0;
for(i = 0; i < 256; i++) {
- if(root_tokens[i].kids) {
- printf("root_tokens[%s], #%d\n", fmt_chr(root_tokens[i].chr), root_tokens[i].number);
- dump_kids(&root_tokens[i], 1);
+ if(tokens[i].kids) {
+ printf("tokens[%s], #%d\n", fmt_chr(tokens[i].chr), tokens[i].number);
+ dump_kids(&tokens[i], 1);
}
}
@@ -162,7 +156,7 @@ token_t *get_kid(token_t *t, u8 chr) {
token_t *match_token(int pos) {
token_t *t, *p;
- t = &root_tokens[input_buf[pos]];
+ t = &tokens[input_buf[pos]];
new_pos = pos + 1;
if(new_pos == input_len)
return t;
@@ -179,18 +173,11 @@ token_t *match_token(int pos) {
token_t *new_token(u8 chr) {
token_t *newtok;
- newtok = malloc(sizeof(token_t));
- if(!newtok) {
- fprintf(stderr, "%s: fatal: out of memory!\n", self);
- exit(1);
- }
-
+ newtok = &tokens[curr_token];
newtok->chr = chr;
newtok->kids = newtok->sibling = 0;
newtok->number = curr_token;
- tokentab[curr_token] = newtok;
-
return newtok;
}