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 "blackHole://server" +#define DESC "lair of drkste aka nilix: programmer, artist, philosopher" +#define ABOUT "Derek Stevens <"\ + "nilix@nilfm.cc>
"\ + "artist, programmer, philosopher

"\ + "verify my signature: signing public key
"\ + "send me an encrypted message: encryption public key" +#define CONTACT "contact: nilix@nilfm.cc (keys)
" +#define FOOTER "visit the nilFM hack lab. "\ + "visit me on the Fediverse. "\ + "visit the Webring.
" +#define LICENSE "CC-BY-NC 4" +#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 #include #include + +#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 "blackHole://server" -#define DESC "lair of drkste aka nilix: programmer, artist, philosopher" -#define ABOUT "Derek Stevens <"\ - "nilix@nilfm.cc>
"\ - "artist, programmer, philosopher

"\ - "verify my signature: signing public key
"\ - "send me an encrypted message: encryption public key" -#define CONTACT "contact: nilix@nilfm.cc (keys)
" -#define FOOTER "visit the nilFM hack lab. "\ - "visit me on the Fediverse. "\ - "visit the Webring.
" -#define LICENSE "CC-BY-NC 4" -#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, "see all"); scat(buf, ""); 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("

", f); + fpmetatemplate(f, l, s); + fputs("

", f); + return 1; +} + +int fpul(FILE* f, Lexicon* l, char* s) { + fputs("
    ", f); + fpmetatemplate(f, l, s); + fputs("
", f); + return 1; +} + +int fpol(FILE* f, Lexicon* l, char* s) { + fputs("
    ", f); + fpmetatemplate(f, l, s); + fputs("
", f); + return 1; +} + +int fppublish(FILE* f, char* s) { + fputs("
", f); + fputs(s, f); + fputs("
", f); + return 1; +} + +int fpli(FILE* f, Lexicon* l, char* s) { + fputs("
  • ", f); + fpmetatemplate(f, l, s); + fputs("
  • ", f); + return 1; +} + +int fph3(FILE* f, char* s) { + fputs("

    ", f); + fputs(s, f); + fputs("

    ", f); + return 1; +} + +int fph4(FILE* f, char* s) { + fputs("

    ", f); + fputs(s, f); + fputs("

    ", f); + return 1; +} + +int fpcode(FILE* f, char* s) { + fputs("", f); + fputs(s, f); + fputs("", f); + return 1; +} + +int fpbold(FILE* f, char* s) { + fputs("", f); + fputs(s, f); + fputs("", f); + return 1; +} + +int fpitalic(FILE* f, char* s) { + fputs("", f); + fputs(s, f); + fputs("", f); + return 1; +} + +int fpstrike(FILE* f, char* s) { + fputs("", f); + fputs(s, f); + fputs("", f); + return 1; +} + +int fppre(FILE* f, char* s) { + fputs("
    ", f);
    +  fputs(s, f);
    +  fputs("
    ", f); + return 1; +} + +int fpquote(FILE* f, char* s) { + fputs("", f); + fputs(s, f); + fputs("", f); + return 1; +} + +int fpblock(FILE* f, char* s) { + fputs("
    ", f); + fputs(s, f); + fputs("
    ", 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, "", scsw(stlc(s), ' ', '_')); + fprintf(f, "", scsw(stlc(s), ' ', '_')); fprintf(f, "%s", 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);