garbage collection
This commit is contained in:
parent
c02e8aa59a
commit
e6165f3af8
6 changed files with 44 additions and 21 deletions
25
src/main.c
25
src/main.c
|
@ -12,6 +12,20 @@
|
|||
#define MAX_BUF_LENGTH 1024
|
||||
#define MAX_COMBO_LENGTH 1024
|
||||
|
||||
void init_tables(hashmap *elements, hashmap *inv, int do_inv) {
|
||||
|
||||
load_elements(elements, "../elem_data/" combo_file, 0) ||
|
||||
load_elements(elements, combo_file, 0) ||
|
||||
load_elements(elements, "bin/" combo_file, 0);
|
||||
|
||||
if (!do_inv)
|
||||
return;
|
||||
|
||||
load_elements(elements, "../elem_data/" inv_base_file, 1) ||
|
||||
load_elements(inv, inv_base_file, 1) ||
|
||||
load_elements(inv, "bin/" inv_base_file, 1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
hashmap *elements = hashmap_create();
|
||||
hashmap *inv = hashmap_create();
|
||||
|
@ -20,10 +34,7 @@ int main(int argc, char *argv[]) {
|
|||
char *command_re = calloc(MAX_BUF_LENGTH, sizeof(char));
|
||||
char **sort_tmp = calloc(MAX_COMBO_LENGTH, sizeof(char **));
|
||||
|
||||
load_elements(elements, combo_file, 0) ||
|
||||
load_elements(elements, "bin/" combo_file, 0);
|
||||
load_elements(inv, inv_base_file, 1) ||
|
||||
load_elements(inv, "bin/" inv_base_file, 1);
|
||||
init_tables(elements, inv, 1);
|
||||
|
||||
load_elements(inv, inv_file, 1);
|
||||
|
||||
|
@ -56,10 +67,8 @@ int main(int argc, char *argv[]) {
|
|||
uintptr_t result;
|
||||
hashmap_get(elements, command_re, strlen(command_re), &result);
|
||||
|
||||
// todo: better
|
||||
if (result == 0) {
|
||||
load_elements(elements, combo_file, 0) ||
|
||||
load_elements(elements, "bin/" combo_file, 0);
|
||||
init_tables(elements, inv, 0);
|
||||
|
||||
hashmap_get(elements, command_re, strlen(command_re), &result);
|
||||
}
|
||||
|
@ -71,7 +80,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
char *res_str = (char *)result;
|
||||
|
||||
hashmap_set(inv, res_str, strlen(res_str), (uintptr_t)1);
|
||||
hashmap_set(inv, res_str, strlen(res_str), (uintptr_t)1, 0);
|
||||
printf("You made %s!\n", res_str);
|
||||
|
||||
FILE *fptr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue