+char*
+read_file(char* file_name, long* size)
+{ // apparently using seek isnt the greatest, may change to chunk reading later
+ FILE* file;
+ char* output;
+ long fsize;
+
+ file = fopen(file_name, "r");
+ if (file == NULL) {
+ printf("Something went wrong opening file\n");
+ return NULL;
+ }
+
+ fseek(file, 0, SEEK_END);
+ fsize = ftell(file);
+ fseek(file, 0, SEEK_SET);
+
+ output = malloc(fsize+1); // maybe error check malloc
+ fread(output, 1, fsize, file);
+ if (ferror(file)) {
+ printf("Something went wrong reading file\n");
+ fclose(file);
+ free(output);
+ return NULL;
+ }
+ output[fsize] = 0; // add null terminator
+
+ /* clean up */
+ fclose(file);
+
+ /* return */
+ *size = fsize;
+ return output;
+}
+
+Board*
+begin_parse(char* board_path)
+{
+ const char* input_buffer;
+ long input_size;
+ State* state;
+ Board* new_board;
+
+ /* read entire file */
+ input_buffer = read_file(board_path, &input_size);
+
+ /* setup state */
+ state = malloc(sizeof(State));
+ state->cur_todolist = NULL;
+ state->cur_todoitem = NULL;
+
+ new_board = malloc(sizeof(Board));
+ new_board->todolist_list = malloc(0);
+ new_board->todolist_count = 0;
+ state->board = new_board;
+
+ md_parse(input_buffer, input_size, &parser, state);
+
+ /* finish calls */
+ exit_todolist(state);
+
+ free((char*)input_buffer);
+
+ return state->board;
+}
+
+void
+enter_todolist(State* state, char* list_name)
+{
+ TodoList* new_todolist;
+
+ new_todolist = malloc(sizeof(TodoList));
+ new_todolist->list_name = list_name;
+ new_todolist->item_list = malloc(0);
+ new_todolist->item_count = 0;
+
+ state->cur_todolist = new_todolist;
+}
+
+void
+exit_todolist(State* state)
+{
+ Board* board;
+ TodoList** todolist_list;
+
+ if (state->cur_todolist == NULL) {
+ return;
+ }
+
+ exit_todoitem(state);
+
+ /* append new todolist to board */
+ board = state->board;
+ todolist_list = board->todolist_list;
+
+ board->todolist_count += 1;
+ todolist_list = realloc(todolist_list, board->todolist_count*sizeof(TodoList*));
+ todolist_list[board->todolist_count-1] = state->cur_todolist;
+ state->cur_todolist = NULL;
+
+ /* save */
+ board->todolist_list = todolist_list;
+
+}
+
+void
+enter_todoitem(State* state, char* item_name)
+{
+ TodoItem* new_todoitem;
+
+ new_todoitem = malloc(sizeof(TodoItem));
+ new_todoitem->item_name = item_name;
+ new_todoitem->description = NULL;
+ new_todoitem->due = NULL;
+ new_todoitem->subtask_list = malloc(0);
+ new_todoitem->subtask_count = 0;
+
+ state->cur_todoitem = new_todoitem;
+
+}
+
+void
+exit_todoitem(State* state)