summaryrefslogtreecommitdiff
path: root/blogtohtml.c
diff options
context:
space:
mode:
Diffstat (limited to 'blogtohtml.c')
-rw-r--r--blogtohtml.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/blogtohtml.c b/blogtohtml.c
new file mode 100644
index 0000000..b6576d7
--- /dev/null
+++ b/blogtohtml.c
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define stylesheet "style.css"
+
+int main() {
+ char c;
+ size_t len = 0;
+
+ size_t size = 100;
+ char *buffer = malloc(size);
+
+ while ((c = getchar()) != EOF){
+ if (len >= size) {
+ size += 100;
+ buffer = realloc(buffer, size);
+ }
+ buffer[len] = c;
+ len++;
+ }
+ len++;
+ buffer = realloc(buffer, len);
+ buffer[len] = 0;
+
+ printf("<link rel=\"stylesheet\" href=\""stylesheet"\">\n");
+
+ int headingcount = 0;
+ for (int i = 0; i < len - 1; i++) {
+ if (memcmp(&buffer[i], "\n*", 2) == 0){
+ i += 3;
+ (headingcount != 0) ? printf("</p>\n<h1 id=blogheading>") : printf("<h1 id=blogheading>");
+ headingcount++;
+ while (buffer[i] != '\n' && buffer[i] != 0) {
+ printf("%c", buffer[i]);
+ i++;
+ }
+ printf("</h1>\n<p id=blogcontent>\n");
+ } else if (buffer[i] == '\n') {
+ printf("\n<br>\n");
+ } else printf("%c", buffer[i]);
+ }
+ printf("</p>\n");
+}