From: Daniel Liu Date: Sun, 20 Dec 2020 05:06:42 +0000 (-0500) Subject: md4c lib setup X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=5b9185f1e592039de4c7a9b08b48a352483dc5e2;p=taskasaur.git md4c lib setup --- diff --git a/makefile b/makefile index 28d0835..12b8d45 100644 --- a/makefile +++ b/makefile @@ -2,11 +2,11 @@ CC=gcc make: taskasaur test -taskasaur: +taskasaur: taskasur.c $(CC) -lncurses -lmenu taskasaur.c -o taskasaur -test: - $(CC) -lncurses -lmenu parser.c -o parser +test: parser.c + $(CC) -lncurses -lmenu -lmd4c parser.c -o parser clean: rm taskasaur parser diff --git a/parser.c b/parser.c index 0f476b4..9a2c7f9 100644 --- a/parser.c +++ b/parser.c @@ -1,6 +1,7 @@ #include #include #include +#include typedef struct TodoItem { char* name; @@ -9,11 +10,28 @@ typedef struct TodoItem { char** items; } TodoItem; -void parse(FILE* file, int* length); - +/* callbacks to parser */ +int enter_block(MD_BLOCKTYPE type, void* detail, void* userdata); +int leave_block(MD_BLOCKTYPE type, void* detail, void* userdata); +int enter_span(MD_SPANTYPE type, void* detail, void* userdata); +int leave_span(MD_SPANTYPE type, void* detail, void* userdata); +int text(MD_TEXTTYPE type, const MD_CHAR* text, MD_SIZE size, void* userdata); +void debug_log(const char* msg, void* userdata); +void syntax(void); + +static MD_PARSER parser = { + 0, + MD_DIALECT_COMMONMARK, + &enter_block, + &leave_block, + &enter_span, + &leave_span, + &text, + &debug_log, + &syntax +}; static char task_md[] = "###"; - int main(int argc, char** argv) { @@ -26,53 +44,46 @@ main(int argc, char** argv) return 1; } - parse(input_file, &todo_length); - return 0; } -/* TodoItem** */ -void -parse(FILE* file, int* length) +int +enter_block(MD_BLOCKTYPE type, void* detail, void* userdata) { - 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; - } + return 0; +} - // found a task - if (strlen(lineptr) > 3 && strncmp(lineptr, task_md, 3) == 0) { - printf("found_task\n"); - lineptr = NULL; - continue; - } +int +leave_block(MD_BLOCKTYPE type, void* detail, void* userdata) +{ + return 0; +} +int +enter_span(MD_SPANTYPE type, void* detail, void* userdata) +{ + return 0; +} - +int +leave_span(MD_SPANTYPE type, void* detail, void* userdata) +{ + return 0; +} - /* out_arr = realloc(out_arr, (sizeof(char*))*out_len); // bad to keep resizing? */ +int +text(MD_TEXTTYPE type, const MD_CHAR* text, MD_SIZE size, void* userdata){ + return 0; +} - /* out_arr[out_len-1] = lineptr; */ +void +debug_log(const char* msg, void* userdata) +{ + return; +} - lineptr = NULL; - } - - *length = out_len; - /* return out_arr; */ +void +syntax(void) +{ + return; } diff --git a/taskasaur.c b/taskasaur.c index 3987cc7..28c25a8 100644 --- a/taskasaur.c +++ b/taskasaur.c @@ -6,6 +6,15 @@ #include #include +#define SELECTED_COLOR 1 +#define NON_SELECTED_COLOR 2 + +struct todo_item { + char* name; + char* description; + char** items; +}; + void winch_handler(int sig); char** read_todo(FILE* file, int* length); @@ -17,17 +26,8 @@ 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 -#define NON_SELECTED_COLOR 2 - int main(int argc, char** argv) {