aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerek Stevens <nilix@nilfm.cc>2022-02-12 16:06:47 -0700
committerDerek Stevens <nilix@nilfm.cc>2022-02-12 16:06:47 -0700
commitdff5bf47a0f12e1177bae5d5aea55598f2eecf55 (patch)
tree73a273646d27aaab7e59af7c767ef055dacf809e
parentd831945f5f593f0fa6b273c94364fb681c18a4ea (diff)
update markup and separate config into header file
-rw-r--r--.gitignore1
-rwxr-xr-xbuild.sh11
-rw-r--r--config.def.h22
-rw-r--r--main.c268
4 files changed, 250 insertions, 52 deletions
diff --git a/.gitignore b/.gitignore
index 1ae5624..7944fd1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
inc/
old/
+config.h
diff --git a/build.sh b/build.sh
index ee64202..437d461 100755
--- a/build.sh
+++ b/build.sh
@@ -1,16 +1,21 @@
#!/bin/sh
+# copy default config if none
+if [ ! -e config.h ]; then
+ cp config.def.h config.h
+fi
+
# Lint
-clang-format -i main.c
+clang-format -i main.c config.h
# Cleanup
rm -f ./main
# Linux(debug)
-cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wuninitialized -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined main.c -o main
+# cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wuninitialized -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined main.c -o main
# Linux(fast)
-# cc main.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o main
+cc main.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o main
# RPi
# tcc -Wall main.c -o main
diff --git a/config.def.h b/config.def.h
new file mode 100644
index 0000000..c96a667
--- /dev/null
+++ b/config.def.h
@@ -0,0 +1,22 @@
+#define NAME "nilFM"
+#define DOMAIN "https://nilfm.cc"
+#define LOGO "<img src='/img/nilfm_blackHole_96.png' alt='blackHole://server'/>"
+#define DESC "lair of drkste aka nilix: programmer, artist, philosopher"
+#define ABOUT "Derek Stevens &lt;"\
+ "<a href='mailto:nilix@nilfm.cc'>nilix@nilfm.cc</a>&gt;<br/>"\
+ "artist, programmer, philosopher<br/><br/>"\
+ "verify my signature: <a href='/serv/signingKey.pub'>signing public key</a><br/>"\
+ "send me an encrypted message: <a href='/serv/encryptionKey.pub'>encryption public key</a>"
+#define CONTACT "contact: <a href='mailto:nilix@nilfm.cc'>nilix@nilfm.cc</a> (<a href='keys.html'>keys</a>)<br/>"
+#define FOOTER "<a href='/git/'><img "\
+ "src='/img/git.svg' alt='visit the nilFM hack lab.'/></a>&nbsp;"\
+ "<a rel='me' href='https://cafe.nilfm.cc/u/nilix'><img "\
+ "src='/img/honk.svg' alt='visit me on the Fediverse.'/></a>&nbsp;"\
+ "<a href='https://webring.xxiivv.com'><img "\
+ "src='/img/webring.svg' alt='visit the Webring.'/></a><br/>"
+#define LICENSE "<a rel='license' "\
+ "href='https://creativecommons.org/licenses/by-nc/4.0/"\
+ "legalcode.txt'>CC-BY-NC 4</a>"
+#define SITEROOT "../www/"
+#define MAINCSS "/new.css"
+#define FRONTCSS "/front.css"
diff --git a/main.c b/main.c
index 2a5abe8..7a47812 100644
--- a/main.c
+++ b/main.c
@@ -3,6 +3,9 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
+
+#include "config.h"
+
/*
Copyright (c) 2021 Derek Stevens
Copyright (c) 2021 Devine Lu Linvega
@@ -15,33 +18,6 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE.
*/
-/* clang-format off */
-
-#define NAME "nilFM"
-#define DOMAIN "https://nilfm.cc"
-#define LOGO "<img src='/img/nilfm_blackHole_96.png' alt='blackHole://server'/>"
-#define DESC "lair of drkste aka nilix: programmer, artist, philosopher"
-#define ABOUT "Derek Stevens &lt;"\
- "<a href='mailto:nilix@nilfm.cc'>nilix@nilfm.cc</a>&gt;<br/>"\
- "artist, programmer, philosopher<br/><br/>"\
- "verify my signature: <a href='/serv/signingKey.pub'>signing public key</a><br/>"\
- "send me an encrypted message: <a href='/serv/encryptionKey.pub'>encryption public key</a>"
-#define CONTACT "contact: <a href='mailto:nilix@nilfm.cc'>nilix@nilfm.cc</a> (<a href='keys.html'>keys</a>)<br/>"
-#define FOOTER "<a href='/git/'><img "\
- "src='/img/git.svg' alt='visit the nilFM hack lab.'/></a>&nbsp;"\
- "<a rel='me' href='https://cafe.nilfm.cc/u/nilix'><img "\
- "src='/img/fedi.svg' alt='visit me on the Fediverse.'/></a>&nbsp;"\
- "<a href='https://webring.xxiivv.com'><img "\
- "src='/img/webring.svg' alt='visit the Webring.'/></a><br/>"
-#define LICENSE "<a rel='license' "\
- "href='https://creativecommons.org/licenses/by-nc/4.0/"\
- "legalcode.txt'>CC-BY-NC 4</a>"
-#define SITEROOT "../www/"
-#define MAINCSS "/new.css"
-#define FRONTCSS "/front.css"
-
-/* clang-format on */
-
struct dirent* dir;
typedef struct Lexicon {
@@ -123,6 +99,7 @@ int gettwtxt(FILE* f) {
}
i++;
}
+ fclose(twtxt);
scat(buf, "</table><a href='/twtxt.txt'>see all</a>");
scat(buf, "</div>");
fputs(buf, f);
@@ -283,22 +260,197 @@ int fpaudio(FILE* f, char* s) {
return 1;
}
+int fptemplate(FILE*, Lexicon*, char*);
+int fpmetatemplate(FILE*, Lexicon*, char*);
+
+int fppara(FILE* f, Lexicon* l, char* s) {
+ fputs("<p>", f);
+ fpmetatemplate(f, l, s);
+ fputs("</p>", f);
+ return 1;
+}
+
+int fpul(FILE* f, Lexicon* l, char* s) {
+ fputs("<ul>", f);
+ fpmetatemplate(f, l, s);
+ fputs("</ul>", f);
+ return 1;
+}
+
+int fpol(FILE* f, Lexicon* l, char* s) {
+ fputs("<ol>", f);
+ fpmetatemplate(f, l, s);
+ fputs("</ol>", f);
+ return 1;
+}
+
+int fppublish(FILE* f, char* s) {
+ fputs("<div class='timestamp'>", f);
+ fputs(s, f);
+ fputs("</div>", f);
+ return 1;
+}
+
+int fpli(FILE* f, Lexicon* l, char* s) {
+ fputs("<li>", f);
+ fpmetatemplate(f, l, s);
+ fputs("</li>", f);
+ return 1;
+}
+
+int fph3(FILE* f, char* s) {
+ fputs("<h3>", f);
+ fputs(s, f);
+ fputs("</h3>", f);
+ return 1;
+}
+
+int fph4(FILE* f, char* s) {
+ fputs("<h4>", f);
+ fputs(s, f);
+ fputs("</h4>", f);
+ return 1;
+}
+
+int fpcode(FILE* f, char* s) {
+ fputs("<code>", f);
+ fputs(s, f);
+ fputs("</code>", f);
+ return 1;
+}
+
+int fpbold(FILE* f, char* s) {
+ fputs("<b>", f);
+ fputs(s, f);
+ fputs("</b>", f);
+ return 1;
+}
+
+int fpitalic(FILE* f, char* s) {
+ fputs("<i>", f);
+ fputs(s, f);
+ fputs("</i>", f);
+ return 1;
+}
+
+int fpstrike(FILE* f, char* s) {
+ fputs("<s>", f);
+ fputs(s, f);
+ fputs("</s>", f);
+ return 1;
+}
+
+int fppre(FILE* f, char* s) {
+ fputs("<pre>", f);
+ fputs(s, f);
+ fputs("</pre>", f);
+ return 1;
+}
+
+int fpquote(FILE* f, char* s) {
+ fputs("<q>", f);
+ fputs(s, f);
+ fputs("</q>", f);
+ return 1;
+}
+
+int fpblock(FILE* f, char* s) {
+ fputs("<blockquote>", f);
+ fputs(s, f);
+ fputs("</blockquote>", f);
+ return 1;
+}
+
+int fpmetatemplate(FILE* f, Lexicon* l, char* s) {
+ int bopen, bclose;
+ char ss[4096];
+ unsigned char t = 0;
+ bopen = 0;
+ bclose = 0;
+
+ while (*s) {
+ if (*s == '}') {
+ bclose++;
+ if (bopen == bclose) {
+ t = 0;
+ bopen = 0;
+ bclose = 0;
+ }
+ if (bopen == bclose) {
+ s++;
+ if (!fptemplate(f, l, ss)) {
+ return 0;
+ }
+ continue;
+ }
+ }
+ if (*s == '{') {
+ bopen++;
+ if (bopen == 1) {
+ ss[0] = 0;
+ t = 1;
+ s++;
+ continue;
+ }
+ }
+ if (slen(s) > 4095)
+ return error("Templating error", "text block over 16k");
+ if (t) {
+ ccat(ss, *s);
+ } else
+ fprintf(f, "%c", *s);
+ s++;
+ }
+ return 1;
+}
+
int fptemplate(FILE* f, Lexicon* l, char* s) {
- int target;
- if (s[0] == '/')
- return fpportal(f, l, s + 1, 1);
- if (s[0] == '*')
- return fphref(f, s + 1);
- if (s[0] == ':')
- return fpimg(f, s + 1);
- if (s[0] == '?')
- return fphimg(f, s + 1);
- if (s[0] == '_')
- return fpaudio(f, s + 1);
- target = findf(l, s);
+ int target = 0;
+ switch (s[0]) {
+ case '/':
+ return fpportal(f, l, s + 1, 1);
+ case '*':
+ return fphref(f, s + 1);
+ case ':':
+ return fpimg(f, s + 1);
+ case '?':
+ return fphimg(f, s + 1);
+ case '_':
+ return fpaudio(f, s + 1);
+ case '`':
+ return fpcode(f, s + 1);
+ case '~':
+ return fpitalic(f, s + 1);
+ case '>':
+ return fpblock(f, s + 1);
+ case '\'':
+ return fpquote(f, s + 1);
+ case '$':
+ return fppre(f, s + 1);
+ case '@':
+ return fpbold(f, s + 1);
+ case '\\':
+ return fpstrike(f, s + 1);
+ case '!':
+ return fph3(f, s + 1);
+ case '.':
+ return fph4(f, s + 1);
+ case '+':
+ return fppublish(f, s + 1);
+ case '#':
+ return fpol(f, l, s + 1);
+ case ',':
+ return fpul(f, l, s + 1);
+ case '-':
+ return fpli(f, l, s + 1);
+ case '&':
+ return fppara(f, l, s + 1);
+ }
+ if (s[0])
+ target = findf(l, s);
if (target < 0)
return error("Missing link", s);
- fprintf(f, "<a href='%s.html' class='local'>", scsw(stlc(s), ' ', '_'));
+ fprintf(f, "<a href='./%s.html' class='local'>", scsw(stlc(s), ' ', '_'));
fprintf(f, "%s</a>", scsw(stlc(s), '_', ' '));
l->refs[target]++;
return 1;
@@ -306,25 +458,43 @@ int fptemplate(FILE* f, Lexicon* l, char* s) {
int fpinject(FILE* f, Lexicon* l, char* filepath) {
FILE* inc;
- char c, s[1024];
+ int bopen, bclose;
+ char c, s[4096];
unsigned char t = 0;
+ /*fprintf(stderr, "Building: %s\n", filepath);*/
+ bopen = 0;
+ bclose = 0;
scsw(filepath, ' ', '_');
if (!(inc = fopen(filepath, "r")))
return error("Missing include", filepath);
s[0] = 0;
while ((c = fgetc(inc)) != EOF) {
if (c == '}') {
- t = 0;
- if (!fptemplate(f, l, s))
- return 0;
- continue;
+ bclose++;
+ if (bopen == bclose) {
+ t = 0;
+ bopen = 0;
+ bclose = 0;
+ }
+
+ if (bopen == bclose) {
+ if (!fptemplate(f, l, s)) {
+ return 0;
+ }
+ continue;
+ }
}
if (c == '{') {
- s[0] = 0;
- t = 1;
- continue;
+ bopen++;
+ if (bopen == 1) {
+
+ s[0] = 0;
+ t = 1;
+
+ continue;
+ }
}
- if (slen(s) > 1023)
+ if (slen(s) > 4095)
return error("Templating error", filepath);
if (t)
ccat(s, c);