check both main dir and parent dir (temp fix)
This commit is contained in:
parent
f4be64fe19
commit
4bef1a220c
3 changed files with 29 additions and 10 deletions
18
src/loader.c
18
src/loader.c
|
@ -6,18 +6,25 @@
|
||||||
|
|
||||||
#define MAX_FILE_SIZE 1024 * 16
|
#define MAX_FILE_SIZE 1024 * 16
|
||||||
|
|
||||||
void load_elements(hashmap *m, char *table, int use_inv) {
|
int load_elements(hashmap *m, char *table, int use_inv) {
|
||||||
FILE *fptr;
|
FILE *fptr;
|
||||||
|
|
||||||
fptr = fopen(table, "r");
|
fptr = fopen(table, "r");
|
||||||
|
|
||||||
|
if (fptr == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
|
int did_something = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
str = calloc(MAX_FILE_SIZE, sizeof(char));
|
str = calloc(MAX_FILE_SIZE, sizeof(char));
|
||||||
if (!fgets(str, MAX_FILE_SIZE, fptr))
|
if (!fgets(str, MAX_FILE_SIZE, fptr))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
did_something = 1;
|
||||||
|
|
||||||
if (use_inv) {
|
if (use_inv) {
|
||||||
hashmap_set(m, str, strlen(str) - 2, (uintptr_t)1);
|
hashmap_set(m, str, strlen(str) - 2, (uintptr_t)1);
|
||||||
continue;
|
continue;
|
||||||
|
@ -30,5 +37,14 @@ void load_elements(hashmap *m, char *table, int use_inv) {
|
||||||
hashmap_set(m, combo, strlen(combo) - 1, (uintptr_t)str);
|
hashmap_set(m, combo, strlen(combo) - 1, (uintptr_t)str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
printf("%i\n",did_something);
|
||||||
|
|
||||||
|
if (!did_something) {
|
||||||
|
free(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
return did_something;
|
||||||
|
|
||||||
// todo: properly free this
|
// todo: properly free this
|
||||||
}
|
}
|
|
@ -1,2 +1,2 @@
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
void load_elements(hashmap *m, char *table, int use_inv);
|
int load_elements(hashmap *m, char *table, int use_inv);
|
11
src/main.c
11
src/main.c
|
@ -16,8 +16,9 @@ int main(int argc, char *argv[]) {
|
||||||
char *command_re = calloc(MAX_BUF_LENGTH, sizeof(char));
|
char *command_re = calloc(MAX_BUF_LENGTH, sizeof(char));
|
||||||
char **sort_tmp = calloc(MAX_COMBO_LENGTH, sizeof(char **));
|
char **sort_tmp = calloc(MAX_COMBO_LENGTH, sizeof(char **));
|
||||||
|
|
||||||
|
load_elements(elements, "combos.txt", 0) ||
|
||||||
load_elements(elements, "bin/combos.txt", 0);
|
load_elements(elements, "bin/combos.txt", 0);
|
||||||
load_elements(inv, "bin/inv.txt", 1);
|
load_elements(inv, "inv.txt", 1) || load_elements(inv, "bin/inv.txt", 1);
|
||||||
|
|
||||||
printf("Welcome to Elemental on Command Line!\n");
|
printf("Welcome to Elemental on Command Line!\n");
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -25,8 +26,9 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
fgets(command, MAX_BUF_LENGTH - 1, stdin);
|
fgets(command, MAX_BUF_LENGTH - 1, stdin);
|
||||||
int slashRan = slash_command(command,inv);
|
int slashRan = slash_command(command, inv);
|
||||||
if (slashRan) continue;
|
if (slashRan)
|
||||||
|
continue;
|
||||||
|
|
||||||
int combos = get_command(command, command_re, sort_tmp);
|
int combos = get_command(command, command_re, sort_tmp);
|
||||||
|
|
||||||
|
@ -41,7 +43,8 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (failed) continue;
|
if (failed)
|
||||||
|
continue;
|
||||||
|
|
||||||
uintptr_t result;
|
uintptr_t result;
|
||||||
hashmap_get(elements, command_re, strlen(command_re), &result);
|
hashmap_get(elements, command_re, strlen(command_re), &result);
|
||||||
|
|
Loading…
Reference in a new issue