thrive/util.c
2025-01-30 18:03:08 -05:00

24 lines
528 B
C

#include <stdlib.h>
#include <string.h>
#include "util.h"
#include "game.h"
void parse_multiline_string(Game *g, char *string, void (*parse_line)(Game *g, char *line)) {
char *buffer = malloc(0);
char *sol = string;
char *eol = strchr(sol, '\n');
while (eol != NULL) {
int line_length = eol - sol;
buffer = realloc(buffer, line_length + 1);
memcpy(buffer, sol, line_length);
buffer[line_length] = '\0';
parse_line(g, buffer);
sol = eol + 1;
eol = strchr(sol, '\n');
}
free(buffer);
}