#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);
}