|
@@ -4,71 +4,32 @@
|
|
#include <string.h>
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
#include <ctype.h>
|
|
|
|
|
|
-#define LENGTH(x) (sizeof (x) / sizeof (*x))
|
|
|
|
-
|
|
|
|
-const char htmlheader[] =
|
|
|
|
-"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n"
|
|
|
|
-"\"http://www.w3.org/TR/html4/loose.dtd\">\n"
|
|
|
|
-"<html>\n"
|
|
|
|
-"<head>\n"
|
|
|
|
-"<meta name=\"generator\" content=\"webgen, see domonkos.tk\">\n"
|
|
|
|
-"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=US-ASCII\">\n"
|
|
|
|
-"<meta name=\"Content-Style\" content=\"text/css\">\n"
|
|
|
|
-"<title>Personal website</title>\n"
|
|
|
|
-"<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n"
|
|
|
|
-"</head>\n"
|
|
|
|
-"<body>\n";
|
|
|
|
-
|
|
|
|
-const char htmlfooter[] =
|
|
|
|
-"<hr>\n"
|
|
|
|
-"</body>\n"
|
|
|
|
-"</html>\n";
|
|
|
|
-
|
|
|
|
-const char htmlrefstring[] = "<a href=\"%s\">%s</a>";
|
|
|
|
-const char htmlimgstring[] = "<img src=\"%s\" alt=\"Image %s\">";
|
|
|
|
|
|
+#include "html.h"
|
|
|
|
+#include "utils.h"
|
|
|
|
|
|
|
|
+#define LENGTH(x) (sizeof (x) / sizeof (*x))
|
|
|
|
|
|
char *line = NULL;
|
|
char *line = NULL;
|
|
-char * params[9] = { 0 };
|
|
|
|
|
|
+unsigned linenum = 0;
|
|
|
|
+size_t linelen;
|
|
|
|
+char *params[9] = { 0 };
|
|
int nparams;
|
|
int nparams;
|
|
|
|
|
|
-int
|
|
|
|
-notimplemented(void)
|
|
|
|
-{
|
|
|
|
- fprintf(stderr, "this function is not yet implemented :(");
|
|
|
|
-
|
|
|
|
- return 1;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int
|
|
|
|
-spithref(void)
|
|
|
|
-{
|
|
|
|
- if (nparams < 1) {
|
|
|
|
- fprintf(stderr, "href requires at least one parameter!\n");
|
|
|
|
- return 1;
|
|
|
|
- } else if (nparams == 1) {
|
|
|
|
- printf(htmlrefstring, params[0], params[0]);
|
|
|
|
- } else if (nparams == 2) {
|
|
|
|
- printf(htmlrefstring, params[0], params[1]);
|
|
|
|
- } else if (nparams > 2) {
|
|
|
|
- fprintf(stderr, "href takes two parameters at max!\n");
|
|
|
|
- return 1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return 0;
|
|
|
|
-}
|
|
|
|
|
|
+int inparagraph = 0;
|
|
|
|
|
|
struct {
|
|
struct {
|
|
char *name;
|
|
char *name;
|
|
int(*fun)(void);
|
|
int(*fun)(void);
|
|
-} tokens[] = {
|
|
|
|
- { ".b", notimplemented },
|
|
|
|
- { ".br", notimplemented },
|
|
|
|
- { ".cw", notimplemented },
|
|
|
|
- { ".i", notimplemented },
|
|
|
|
- { ".pp", notimplemented },
|
|
|
|
|
|
+} tokens[] = { //TODO: make the recognition not dependent on length+order
|
|
|
|
+ { ".img", spitimg },
|
|
{ ".ref", spithref },
|
|
{ ".ref", spithref },
|
|
- { ".img", notimplemented },
|
|
|
|
|
|
+ { ".br", spitlinebreak },
|
|
|
|
+ { ".cw", spitmonospace },
|
|
|
|
+ { ".hr", spithorizontalrule },
|
|
|
|
+ { ".pp", newparagraph },
|
|
|
|
+ { ".b", spitbold },
|
|
|
|
+ { ".i", spititalic },
|
|
|
|
+ //{ "", newparagraph },
|
|
};
|
|
};
|
|
|
|
|
|
char *
|
|
char *
|
|
@@ -111,15 +72,14 @@ paramize(void)
|
|
p = w;
|
|
p = w;
|
|
}
|
|
}
|
|
|
|
|
|
- //printf("n: %d; last---\n", nparams);
|
|
|
|
-
|
|
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
int
|
|
int
|
|
spit(void)
|
|
spit(void)
|
|
{
|
|
{
|
|
- return puts(line);
|
|
|
|
|
|
+ // TODO: should we always spit the original?
|
|
|
|
+ return fputs(line, stdout);
|
|
}
|
|
}
|
|
|
|
|
|
int
|
|
int
|
|
@@ -127,6 +87,12 @@ tokenp(void)
|
|
{
|
|
{
|
|
int i;
|
|
int i;
|
|
|
|
|
|
|
|
+ // implicit new paragraph via an empty line is a special case
|
|
|
|
+ if (line[0] == '\n') {
|
|
|
|
+ newparagraph();
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
for (i = 0; i < LENGTH(tokens); i++) {
|
|
for (i = 0; i < LENGTH(tokens); i++) {
|
|
const char * t = tokens[i].name;
|
|
const char * t = tokens[i].name;
|
|
if (!strncmp(line, t, strlen(t))) {
|
|
if (!strncmp(line, t, strlen(t))) {
|
|
@@ -148,16 +114,20 @@ main(int argc, char *argv[])
|
|
size_t len = 0;
|
|
size_t len = 0;
|
|
ssize_t nread;
|
|
ssize_t nread;
|
|
|
|
|
|
- fputs(htmlheader, stdout);
|
|
|
|
|
|
+ spitheader();
|
|
|
|
|
|
while ((nread = getline(&line, &len, stream)) != -1) {
|
|
while ((nread = getline(&line, &len, stream)) != -1) {
|
|
|
|
+ linenum++;
|
|
tokenp();
|
|
tokenp();
|
|
}
|
|
}
|
|
|
|
|
|
free(line);
|
|
free(line);
|
|
|
|
|
|
- fputs(htmlfooter, stdout);
|
|
|
|
- //fclose(stream);
|
|
|
|
|
|
+ if (inparagraph) {
|
|
|
|
+ puts("</p>");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ spitfooter();
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|