From: Daniel Liu Date: Sat, 19 Dec 2020 04:01:47 +0000 (-0500) Subject: trying to parse md X-Git-Url: https://git.danieliu.xyz/?p=taskasaur.git;a=commitdiff_plain;h=28b77363ab45af4b933097364f511a4748648264 trying to parse md --- diff --git a/makefile b/makefile index c2841d6..28d0835 100644 --- a/makefile +++ b/makefile @@ -1,9 +1,12 @@ CC=gcc -make: taskasaur +make: taskasaur test taskasaur: $(CC) -lncurses -lmenu taskasaur.c -o taskasaur +test: + $(CC) -lncurses -lmenu parser.c -o parser + clean: - rm taskasaur + rm taskasaur parser diff --git a/parser.c b/parser.c new file mode 100644 index 0000000..0f476b4 --- /dev/null +++ b/parser.c @@ -0,0 +1,78 @@ +#include +#include +#include + +typedef struct TodoItem { + char* name; + char* description; + char* due; + char** items; +} TodoItem; + +void parse(FILE* file, int* length); + + +static char task_md[] = "###"; + +int +main(int argc, char** argv) +{ + FILE* input_file; + int todo_length; + + input_file = fopen("test_board.md", "r"); + if (!input_file) { + printf("Something went wrong opening file"); + return 1; + } + + parse(input_file, &todo_length); + + return 0; +} + +/* TodoItem** */ +void +parse(FILE* file, int* length) +{ + TodoItem** out_arr; + int out_len; + char* lineptr; + size_t len; + ssize_t nread; + + out_arr = NULL; + out_len = 0; + lineptr = NULL; + len = 0; + + while ((nread = getline(&lineptr, &len, file)) != -1) { + + lineptr[strcspn(lineptr, "\n")] = 0; // remove newline + + if (strcmp(lineptr, "") == 0) { + printf("found empty line\n"); + lineptr = NULL; + continue; + } + + // found a task + if (strlen(lineptr) > 3 && strncmp(lineptr, task_md, 3) == 0) { + printf("found_task\n"); + lineptr = NULL; + continue; + } + + + + + /* out_arr = realloc(out_arr, (sizeof(char*))*out_len); // bad to keep resizing? */ + + /* out_arr[out_len-1] = lineptr; */ + + lineptr = NULL; + } + + *length = out_len; + /* return out_arr; */ +} diff --git a/taskasaur.c b/taskasaur.c index 966907b..3987cc7 100644 --- a/taskasaur.c +++ b/taskasaur.c @@ -17,6 +17,12 @@ void on_select(char *item); void free_todo(char** todo_list, int todo_length); +struct todo_item { + char* name; + char* description; + char** items; +}; + #include "config.h" #define SELECTED_COLOR 1