Working boxes

This commit is contained in:
Stephen Cochrane 2020-05-03 19:19:07 +02:00
parent ab63d2b736
commit 47ebc09660
2 changed files with 88 additions and 14 deletions

View File

@ -2,9 +2,9 @@ Title
[
No Box
]
-
Text in a box
_
-
(
Hi this is tristan
)
(
Another box
-
)

View File

@ -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);
}