trying to parse md
[taskasaur.git] / parser.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 typedef struct TodoItem {
6     char* name;
7     char* description;
8     char* due;
9     char** items;
10 } TodoItem;
11
12 void parse(FILE* file, int* length);
13
14
15 static char task_md[] = "###";
16
17 int
18 main(int argc, char** argv)
19 {
20     FILE* input_file;
21     int todo_length;
22
23     input_file = fopen("test_board.md", "r");     
24     if (!input_file) {
25         printf("Something went wrong opening file");
26         return 1;
27     }
28
29     parse(input_file, &todo_length);
30
31     return 0;    
32 }
33
34 /* TodoItem** */ 
35 void
36 parse(FILE* file, int* length) 
37 {
38     TodoItem** out_arr;
39     int out_len;
40     char* lineptr;
41     size_t len;
42     ssize_t nread;
43
44     out_arr = NULL;
45     out_len = 0;
46     lineptr = NULL;
47     len = 0;
48
49     while ((nread = getline(&lineptr, &len, file)) != -1) {
50
51         lineptr[strcspn(lineptr, "\n")] = 0; // remove newline
52         
53         if (strcmp(lineptr, "") == 0) {
54             printf("found empty line\n");
55             lineptr = NULL;
56             continue;
57         } 
58
59         // found a task
60         if (strlen(lineptr) > 3 && strncmp(lineptr, task_md, 3) == 0) {
61             printf("found_task\n");
62             lineptr = NULL;
63             continue;
64         }
65
66
67         
68
69         /* out_arr = realloc(out_arr, (sizeof(char*))*out_len); // bad to keep resizing? */
70
71         /* out_arr[out_len-1] = lineptr; */
72
73         lineptr = NULL;
74     }
75     
76     *length = out_len;
77     /* return out_arr; */
78 }