From 47ebc0966078cef33bdf848b33b0f39ae8fa5d62 Mon Sep 17 00:00:00 2001 From: Stephen Cochrane Date: Sun, 3 May 2020 19:19:07 +0200 Subject: [PATCH] Working boxes --- blogs/RawBlogs/test.blog | 10 ++--- src/GenBlog.c | 92 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 88 insertions(+), 14 deletions(-) diff --git a/blogs/RawBlogs/test.blog b/blogs/RawBlogs/test.blog index b65a6e7..638a1a8 100644 --- a/blogs/RawBlogs/test.blog +++ b/blogs/RawBlogs/test.blog @@ -2,9 +2,9 @@ Title [ No Box ] -- -Text in a box -_ -- +( +Hi this is tristan +) +( Another box -- +) diff --git a/src/GenBlog.c b/src/GenBlog.c index 558e866..edb19bb 100644 --- a/src/GenBlog.c +++ b/src/GenBlog.c @@ -7,20 +7,41 @@ void parseBox(void); void parseNoBox(void); void genBP(char *file); void echoFile(FILE *fp); +void next(); +void append_html(char *string); + int ch; +FILE *curr; +FILE *chtml; int main() { DIR *dir; struct dirent *ent; char buff[256]; + char htmlName[256]; + char cat[2]; + char *c; + int i; if ((dir = opendir("./blogs/RawBlogs")) != NULL) { while ((ent = readdir(dir)) != NULL) { if (strcmp(ent->d_name, ".") && strcmp(ent->d_name, "..")) { - printf("file = %s\n", ent->d_name); + sprintf(htmlName, "./blogs/"); + + c = ent->d_name; + i = 0; + while (c[i] != '.') { + cat[0] = c[i]; + cat[1] = '\0'; + strcat(htmlName, cat); + i++; + } + strcat(htmlName, ".html"); + printf("%s\n", htmlName); sprintf(buff, "./blogs/RawBlogs/"); strcat(buff, ent->d_name); - printf("opening, %s\n", buff); + printf("opening, %s, %s|\n", buff, htmlName); + chtml = fopen(htmlName, "a+"); genBP(buff); } } @@ -29,25 +50,31 @@ int main() { } void genBP(char *file) { - FILE *fp = fopen(file, "r"); char buff[256]; + curr = fopen(file, "r"); + + // just for debug echoFile(fopen(file, "r")); //Begin parsing the file. - ch = getc(fp); + next(); while (ch != EOF) { switch (ch) { - case '-': - ch = getc(fp); + case '(': + next(); parseBox(); + next(); break; case '[': - ch = getc(fp); + next(); parseNoBox(); + next(); break; } - ch = getc(fp); + next(); } + fclose(curr); + fclose(chtml); } void echoFile(FILE *fp) { @@ -67,10 +94,57 @@ void echoFile(FILE *fp) { fclose(fp); } -void parseBox() { +void next() { + ch = getc(curr); +} +void parseBox() { + int i = 0; + int j; + char *tb = "+-------------------------------------------------------+\n"; + char *empty = "| |\n"; + char line[256]; + + append_html(tb); + append_html(empty); + + while (ch != ')' && ch != EOF) { + if (ch == '\n') { + next(); + if (ch == ')') { + break; + } + } + if (!i) { + append_html("| "); + } else if ( i < 47) { + //print char + append_html(&ch); + next(); + } else { + //setup newline + i = -1; + append_html("- |"); + } + i++; + } + + for (j = 0; j < (53-i); j++) { + line[j] = ' '; + } + + line[j++] = '|'; + line[j] = '\0'; + append_html(line); + append_html("\n"); + append_html(empty); + append_html(tb); } void parseNoBox() { } + +void append_html(char *str) { + fputs(str, chtml); +}