trying to parse md
authorDaniel Liu <mr.picklepinosaur@gmail.com>
Sat, 19 Dec 2020 04:01:47 +0000 (23:01 -0500)
committerDaniel Liu <mr.picklepinosaur@gmail.com>
Sat, 19 Dec 2020 04:01:47 +0000 (23:01 -0500)
makefile
parser.c [new file with mode: 0644]
taskasaur.c

index c2841d6..28d0835 100644 (file)
--- 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 (file)
index 0000000..0f476b4
--- /dev/null
+++ b/parser.c
@@ -0,0 +1,78 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+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; */
+}
index 966907b..3987cc7 100644 (file)
@@ -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