refactor
This commit is contained in:
parent
af961dd144
commit
8740f23c0a
6 changed files with 104 additions and 80 deletions
29
src/loader.c
Normal file
29
src/loader.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include "map.h"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MAX_FILE_SIZE 1024 * 16
|
||||
|
||||
void load_elements(hashmap *m, char *table) {
|
||||
FILE *fptr;
|
||||
|
||||
fptr = fopen(table, "r");
|
||||
|
||||
char *str;
|
||||
|
||||
while (1) {
|
||||
str = calloc(MAX_FILE_SIZE, sizeof(char));
|
||||
if (!fgets(str, MAX_FILE_SIZE, fptr))
|
||||
break;
|
||||
|
||||
char *combo = strstr(str, ";");
|
||||
combo[0] = '\0';
|
||||
combo++;
|
||||
|
||||
hashmap_set(m, combo, strlen(combo) - 1, (uintptr_t)str);
|
||||
}
|
||||
|
||||
// todo: properly free this
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue