summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--main.c49
-rw-r--r--stack.c65
-rw-r--r--stack.h21
4 files changed, 28 insertions, 109 deletions
diff --git a/Makefile b/Makefile
index 64c0860..d06cfa0 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ CFLAGS = -g
vmp: *.c
- gcc *.c $(CFLAGS) -o vmp
+ gcc *.c $(CFLAGS) -o vmp -lcmark
clean:
rm -rf *.o vmp
diff --git a/main.c b/main.c
index 5a87c71..deeff4a 100644
--- a/main.c
+++ b/main.c
@@ -1,33 +1,38 @@
-#include <string.h>
#include <stdio.h>
#include <stdlib.h>
-#include "parser.h"
-
-#define MAX_LINE_LEN 1024
+#include <cmark.h>
+#include <string.h>
+#define MAX_SIZE 1024
+#define BUFFER_SIZE 4096
-int main(int argc, char** argv) {
-
- char line[MAX_LINE_LEN];
- struct md_token* mt = malloc(sizeof(struct md_token));
- if (!mt) {
- return -1;
- }
+/* TODO: Add custom syntax filter */
+int apply_custom_syntax(char *input);
- mt->idx = 0;
+int main()
+{
+ size_t cap = BUFFER_SIZE;
+ size_t len = 0;
+ char *markdown_input = malloc(cap);
- while(fgets(line, sizeof(line), stdin) != NULL) {
- mt->line_len = strlen(line);
- mt->line = line;
- if (line[0] == '#') {
- int a = parse_title(mt);
- } else {
- parse_content(mt);
+ char buffer[BUFFER_SIZE];
+ while (fgets(buffer, sizeof(buffer), stdin) != NULL) {
+ size_t line_len = strlen(buffer);
+ if (len + line_len >= cap) {
+ cap *= 2;
+ markdown_input = realloc(markdown_input, cap);
}
+ strcpy(markdown_input + len, buffer);
+ len += line_len;
+ }
+ char *html_output =
+ cmark_markdown_to_html(markdown_input, len, CMARK_OPT_DEFAULT);
-
-
- mt->idx = 0;
+ if (html_output) {
+ printf("%s", html_output);
+ free(html_output);
}
+
+ free(markdown_input);
return 0;
}
diff --git a/stack.c b/stack.c
deleted file mode 100644
index 1014785..0000000
--- a/stack.c
+++ /dev/null
@@ -1,65 +0,0 @@
-#include "./stack.h"
-#include <stdbool.h>
-#include <stdlib.h>
-
-bool stack_is_empty(stack *s)
-{
- if (!s || s->top == -1) {
- return true;
- }
-
- return false;
-}
-
-stack *new_stack(size_t size)
-{
- stack *s = malloc(sizeof(stack));
- if (!s)
- return NULL;
-
- s->data = malloc(size * sizeof(void *));
- if (!s->data) {
- free(s);
- return NULL;
- }
-
- s->capacity = size;
- s->top = -1;
- return s;
-}
-
-void free_stack(stack *s)
-{
- if (!s)
- return;
-
- free(s->data);
- free(s);
-}
-
-void *pop(stack *s)
-{
- if (stack_is_empty(s))
- return NULL;
- return s->data[s->top--];
-}
-
-void *peek(stack *s)
-{
- if (stack_is_empty(s))
- return NULL;
- return s->data[s->top];
-}
-
-void *push(stack *s, void *data)
-{
- if (!s)
- return NULL;
-
- if (s->top + 1 >= s->capacity) {
- s->capacity *= 2;
- s->data = realloc(s->data, sizeof(void *) * s->capacity);
- }
-
- return s->data[++s->top] = data;
-}
diff --git a/stack.h b/stack.h
deleted file mode 100644
index 7755d42..0000000
--- a/stack.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#define STACK_H
-#ifdef STACK_H
-#include <stdbool.h>
-#include <stdlib.h>
-
-typedef struct stack {
- void* *data;
- int top;
- size_t capacity;
-} stack;
-
-
-stack* new_stack(size_t size);
-
-void* peek(stack *s);
-void* pop(stack *s);
-void* push(stack* s, void* data);
-bool stack_is_empty(stack *s);
-void free_stack(stack *s);
-
-#endif