char** items;
} TodoItem;
+char* read_file(char* file_name, long* size);
+
/* callbacks to parser */
int enter_block(MD_BLOCKTYPE type, void* detail, void* userdata);
int leave_block(MD_BLOCKTYPE type, void* detail, void* userdata);
void debug_log(const char* msg, void* userdata);
void syntax(void);
-static MD_PARSER parser = {
+const MD_PARSER parser = {
0,
MD_DIALECT_COMMONMARK,
&enter_block,
&syntax
};
-static char task_md[] = "###";
int
main(int argc, char** argv)
{
- FILE* input_file;
- int todo_length;
+ char* input_buffer;
+ long input_size;
- input_file = fopen("test_board.md", "r");
- if (!input_file) {
- printf("Something went wrong opening file");
- return 1;
- }
+ input_buffer = read_file("test_board.md", &input_size);
+
+ md_parse(input_buffer, input_size, &parser, NULL);
return 0;
}
+char*
+read_file(char* file_name, long* size)
+{ // apparently using seek isnt the greatest, may change to chunk reading later
+ FILE* file;
+ char* output;
+ long fsize;
+
+ file = fopen(file_name, "r");
+ if (file == NULL) {
+ printf("Something went wrong opening file\n");
+ return NULL;
+ }
+
+ fseek(file, 0, SEEK_END);
+ fsize = ftell(file);
+ fseek(file, 0, SEEK_SET);
+
+ output = malloc(fsize+1); // maybe error check malloc
+ fread(output, 1, fsize, file);
+ if (ferror(file)) {
+ printf("Something went wrong reading file\n");
+ fclose(file);
+ free(output);
+ return NULL;
+ }
+ output[fsize] = 0; // add null terminator
+
+ /* clean up */
+ fclose(file);
+
+ /* return */
+ *size = fsize;
+ return output;
+}
+
int
enter_block(MD_BLOCKTYPE type, void* detail, void* userdata)
{