reading tasklists
authorDaniel Liu <mr.picklepinosaur@gmail.com>
Tue, 29 Dec 2020 23:05:32 +0000 (18:05 -0500)
committerDaniel Liu <mr.picklepinosaur@gmail.com>
Tue, 29 Dec 2020 23:05:32 +0000 (18:05 -0500)
headers/parser.h
parser.c
taskasaur.c

index 4081537..f2a9632 100644 (file)
@@ -4,28 +4,33 @@
 #include <string.h>
 #include <md4c.h>
 
+typedef enum SubTaskState {
+    SubTaskState_todo,
+    SubTaskState_done
+} SubTaskState;
+
 typedef struct SubTask {
     char* subtask_name;
-    int done;
+    SubTaskState done;
 } SubTask;
 
 typedef struct TodoItem {
     char* item_name;
     char* description;
     char* due;
-    SubTask* subtask_list;
+    SubTask** subtask_list;
     int subtask_count;
 } TodoItem;
 
 typedef struct TodoList {
     char* list_name;
-    TodoItem* item_list;
+    TodoItem** item_list;
     int item_count;
 } TodoList;
 
 typedef struct Board {
     char* board_name;
-    TodoList* todolist_list;
+    TodoList** todolist_list;
     int todolist_count;
 } Board;
 
index 6f597f2..0bc2d91 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -12,11 +12,15 @@ typedef struct State {
 char* read_file(char* file_name, long* size);
 
 /* processing */
-void enter_todolist();
-void exit_todolist();
+void enter_todolist(State* state, char* list_name);
+void exit_todolist(State* state);
 
-void enter_todoitem();
-void exit_todoitem();
+void enter_todoitem(State* state, char* item_name);
+void exit_todoitem(State* state);
+
+void set_description(State* state, char* description);
+void set_due(State* state, char* due); // make an acc date struct later
+void add_subtask(State* state, char* subtask_name, SubTaskState subtask_state);
 
 /* callbacks to parser */
 int enter_block(MD_BLOCKTYPE type, void* detail, void* userdata);
@@ -29,7 +33,7 @@ void syntax(void);
 
 const MD_PARSER parser = {
     0,
-    MD_DIALECT_COMMONMARK,
+    MD_FLAG_TASKLISTS,
     &enter_block,
     &leave_block,
     &enter_span,
@@ -80,6 +84,7 @@ 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);
@@ -89,17 +94,88 @@ begin_parse(char* board_path)
     state->cur_todolist = NULL;
     state->cur_todoitem = NULL;
 
-    state->board = malloc(sizeof(Board));
-    state->board->todolist_list = malloc(0);
-    state->board->todolist_count = 0;
+    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;
+    }
+
+    /* 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)
+{
+
+}
+
+void
+exit_todoitem(State* state)
+{
+
+}
+
+void
+set_description(State* state, char* description)
+{
+
+}
+
+void
+set_due(State* state, char* due)
+{
+
+}
+
+void
+add_subtask(State* state, char* subtask_name, SubTaskState subtask_state)
+{
+
+}
+
 int
 enter_block(MD_BLOCKTYPE type, void* detail, void* userdata)
 {
@@ -122,6 +198,8 @@ leave_block(MD_BLOCKTYPE type, void* detail, void* userdata)
                     printf("leave h1, %s\n", state->last_block_text);
                 
                 case 2:
+                    exit_todolist(state);
+                    enter_todolist(state, state->last_block_text);
                     printf("leave h2, %s\n", state->last_block_text);
                     break;
                 case 3:
@@ -132,6 +210,14 @@ leave_block(MD_BLOCKTYPE type, void* detail, void* userdata)
 
             break;
 
+        case MD_BLOCK_QUOTE:
+            printf("blockquote, %s\n", state->last_block_text);
+            break;
+
+        case MD_BLOCK_LI:
+            printf("todo, %s\n", state->last_block_text);
+            break;
+
         // no need for default case for now :>
     }
     return 0;
@@ -140,12 +226,22 @@ leave_block(MD_BLOCKTYPE type, void* detail, void* userdata)
 int
 enter_span(MD_SPANTYPE type, void* detail, void* userdata)
 {
+
+
     return 0;
 }
 
 int
 leave_span(MD_SPANTYPE type, void* detail, void* userdata)
 {
+    State* state;
+    state = (State*)userdata;
+    
+    switch (type) {
+        case MD_SPAN_STRONG:
+            printf("date, %s\n", state->last_block_text);
+            break;
+    }
     return 0;
 }
 
index 8b6c182..2097e63 100644 (file)
@@ -7,5 +7,7 @@ main(int argc, char** argv)
 
     board = begin_parse("test_board.md");
 
+    printf("%d\n", board->todolist_count);
+
     return 0;    
 }