eureka/main.c

851 lines
18 KiB
C
Raw Permalink Normal View History

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <sys/dir.h>
#include <sys/stat.h>
#include <time.h>
#include "config.h"
/*
Copyright (c) 2021 Derek Stevens
Copyright (c) 2021 Devine Lu Linvega
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE.
*/
2021-04-15 18:44:07 +00:00
struct dirent* dir;
2022-10-23 05:00:51 +00:00
time_t edittime;
typedef struct Lexicon {
int len, refs[LEXICON_SIZE];
char files[LEXICON_SIZE][64];
} Lexicon;
/* clang-format off */
char clca(char c) { return c >= 'A' && c <= 'Z' ? c + ('a' - 'A') : c; } /* char to lowercase */
char cuca(char c) { return c >= 'a' && c <= 'z' ? c - ('a' - 'A') : c; } /* char to uppercase */
int slen(char *s) { int i = 0; while(s[i] && s[++i]) { ; } return i; } /* string length */
char *st__(char *s, char (*fn)(char)) { int i = 0; char c; while((c = s[i])) s[i++] = fn(c); return s; }
char *stuc(char *s) { return st__(s, cuca); } /* string to uppercase */
char *stlc(char *s) { return st__(s, clca); } /* string to lowercase */
char *scpy(char *src, char *dst, int len) { int i = 0; while((dst[i] = src[i]) && i < len - 2) i++; dst[i + 1] = '\0'; return dst; } /* string copy */
int scmp(char *a, char *b) { int i = 0; while(a[i] == b[i]) if(!a[i++]) return 1; return 0; } /* string compare */
char *scsw(char *s, char a, char b) { int i = 0; char c; while((c = s[i])) s[i++] = c == a ? b : c; return s; } /* string char swap */
char *scat(char *dst, const char *src) { char *ptr = dst + slen(dst); while(*src) *ptr++ = *src++; *ptr = '\0'; return dst; } /* string cat */
int ssin(char *s, char *ss) { int a = 0, b = 0; while(s[a]) { if(s[a] == ss[b]) { if(!ss[b + 1]) return a - b; b++; } else b = 0; a++; } return -1; } /* string substring index */
char *ccat(char *dst, char c) { int len = slen(dst); dst[len] = c; dst[len + 1] = '\0'; return dst; }
2021-04-17 19:02:02 +00:00
int clin(char *str, char c) {int i = -1; int j = 0; while(str[j] != '\0'){if(str[j] == c) i = j;j++;}return i;} /* find last occurence of character in string */
/* clang-format on */
2021-04-15 18:44:07 +00:00
int fpinject(FILE* f, Lexicon* l, char* filepath);
2022-11-01 05:09:08 +00:00
int fptemplate(FILE*, Lexicon*, char*);
int fpmetatemplate(FILE*, Lexicon*, char*);
2021-04-15 18:44:07 +00:00
int error(char* msg, char* val) {
printf("Error: %s(%s)\n", msg, val);
return 0;
}
2022-10-23 05:00:51 +00:00
time_t getlater(time_t a, time_t b) { return a > b ? a : b; }
2021-04-15 18:44:07 +00:00
int ismetanav(char* name) { return scmp(name, "meta.nav"); }
2021-04-15 18:44:07 +00:00
int findf(Lexicon* l, char* f) {
int i;
char filename[64];
scat(scsw(stlc(scpy(f, filename, 64)), ' ', '_'), ".htm");
for (i = 0; i < l->len; ++i)
if (scmp(l->files[i], filename))
return i;
return -1;
}
2021-06-17 08:05:49 +00:00
int gettwtxt(FILE* f) {
2021-06-17 08:05:49 +00:00
char buf[1024] = {0};
char line[256];
char datebuf[16] = {0};
char msgbuf[240] = {0};
char *l, *d, *m;
FILE* twtxt = fopen(SITEROOT TWTXT, "r");
2021-06-17 08:05:49 +00:00
scat(buf, "<div id='twtxtFeed'><h2>recent activity:</h2>\n<table>\n");
2021-06-17 08:05:49 +00:00
if (!twtxt) {
return 1;
2021-06-17 08:05:49 +00:00
} else {
int i = 0;
while (fgets(line, 256, twtxt) && i < 3) {
if (*line == '#') {
continue;
}
2021-06-17 08:05:49 +00:00
l = line;
while (*l != 'T') {
ccat(datebuf, *l++);
}
while (*l != '\t') {
l++;
}
scat(msgbuf, l);
scat(buf, "<tr><td style='white-space:nowrap;vertical-align: top;'>");
2021-06-17 08:05:49 +00:00
scat(buf, datebuf);
scat(buf, ":</td><td> ");
2021-06-17 08:05:49 +00:00
scat(buf, msgbuf);
scat(buf, "</td></tr>\n");
d = datebuf;
while (*d) {
*d++ = 0;
}
m = msgbuf;
while (*m) {
*m++ = 0;
}
2021-06-17 08:05:49 +00:00
i++;
}
fclose(twtxt);
scat(buf, "</table><a href='" TWTXT "'>see all</a>\n");
scat(buf, "</div>\n");
2021-06-17 08:05:49 +00:00
fputs(buf, f);
return 1;
}
}
2022-10-23 05:00:51 +00:00
void fpedited(FILE* f) {
struct tm timebuf;
2022-11-01 05:09:08 +00:00
char strbuf[16] = {0};
2022-10-23 05:00:51 +00:00
timebuf = *localtime(&edittime);
strftime(strbuf, 16, "%Y-%m-%d", &timebuf);
fprintf(f, "modified %s<br/>", strbuf);
}
2021-04-15 18:44:07 +00:00
int fpportal(FILE* f, Lexicon* l, char* s, int head) {
2022-10-23 05:00:51 +00:00
struct stat attr;
int target;
char srcpath[64], filename[64];
target = findf(l, s);
if (target < 0)
return error("Missing portal", s);
srcpath[0] = 0;
filename[0] = 0;
scat(scat(scat(srcpath, "inc/"), scpy(s, filename, 64)), ".htm");
2022-10-23 05:00:51 +00:00
stat(scsw(srcpath, ' ', '_'), &attr);
if (!ismetanav(s)) {
edittime = getlater(edittime, attr.st_mtime);
}
if (head)
2021-04-15 18:44:07 +00:00
fprintf(
f,
"<h3 id='%s'><a href='%s.html'>%s</a></h3>\n",
2021-04-15 18:44:07 +00:00
scsw(filename, ' ', '_'),
filename,
s);
fpinject(f, l, srcpath);
l->refs[target]++;
return 1;
}
int fphref(FILE* f, char* s) {
char href[1024] = {0};
char txt[1024] = {0};
char* c = s;
int i = 0;
while (i < 2) {
if (*c == '|' || !(*c)) {
i++;
c++;
continue;
}
switch (i) {
case 0:
ccat(href, *c++);
break;
case 1:
ccat(txt, *c++);
break;
}
}
fprintf(f, "<a href='%s'>%s</a>", href, txt);
return 1;
}
char* thumbtrans(char* s, char* thumb) {
int i, j;
char* ss;
char* fnss;
char fn[1024];
scpy(s, thumb, slen(s));
i = clin(thumb, '/');
ss = thumb + i + 1;
scpy(ss, fn, slen(thumb) - i + 1);
scpy(".thumb/", ss, 8);
j = clin(fn, '.');
fnss = fn + j;
scpy(".png", fnss, 5);
scat(thumb, fn);
return thumb;
}
2021-04-17 19:02:02 +00:00
int fpimg(FILE* f, char* s) {
char id[1024] = {0};
char src[1024] = {0};
char alt[1024] = {0};
char thumb[1024] = {0};
2021-04-17 19:02:02 +00:00
char* c = s;
int i = 0;
while (i < 3) {
if (*c == '|' || !(*c)) {
i++;
c++;
continue;
}
switch (i) {
case 0:
ccat(id, *c++);
break;
case 1:
ccat(src, *c++);
break;
case 2:
ccat(alt, *c++);
break;
}
}
thumbtrans(src, thumb);
2021-04-17 19:02:02 +00:00
fprintf(f, "<a id='%s' href='%s'>\n", id, src);
fprintf(f, "<img class='image' src='%s' alt='%s'/>\n", thumb, alt);
fputs("</a>\n", f);
2021-04-17 19:02:02 +00:00
return 1;
}
2022-11-01 05:09:08 +00:00
int fpthead(FILE* f, char* s) {
char sbuf[TAG_BODY_SIZE] = {0};
char* c = s;
int data = 0;
fputs("<table><thead><tr>\n", f);
while (*c) {
data = 1;
if (*c != '|') {
ccat(sbuf, *c);
} else {
fprintf(f, "<th>%s</th>\n", sbuf);
sbuf[0] = 0;
}
c++;
}
if (data) {
fprintf(f, "<th>%s</th>\n", sbuf);
}
fputs("</tr></thead>\n<tbody>", f);
return 1;
}
int fptbody(FILE* f, Lexicon* l, char* s) {
char sbuf[TAG_BODY_SIZE] = {0};
char* c = s;
int data = 0;
int bopen = 0;
int bclose = 0;
fputs("<tr>\n", f);
while (*c) {
data = 1;
if (*c == '{') {
bopen++;
}
if (*c == '}') {
bclose++;
}
if (*c != '|' || bopen != bclose) {
ccat(sbuf, *c);
} else {
fputs("<td>", f);
fpmetatemplate(f, l, sbuf);
fputs("</td>\n", f);
sbuf[0] = 0;
}
c++;
}
if (data) {
fputs("<td>", f);
fpmetatemplate(f, l, sbuf);
fputs("</td>\n", f);
}
fputs("</tr>", f);
return 1;
}
int fptfoot(FILE* f) {
fputs("</tbody></table>", f);
return 1;
}
int fphimg(FILE* f, char* s) {
2021-04-17 19:02:02 +00:00
char id[1024] = {0};
char href[1024] = {0};
char src[1024] = {0};
char alt[1024] = {0};
char thumb[1024] = {0};
2021-04-17 19:02:02 +00:00
char* c = s;
int i = 0;
while (i < 4) {
if (*c == '|' || !(*c)) {
i++;
c++;
continue;
}
switch (i) {
case 0:
ccat(id, *c++);
break;
case 1:
ccat(href, *c++);
break;
case 2:
ccat(src, *c++);
break;
case 3:
ccat(alt, *c++);
break;
}
}
thumbtrans(src, thumb);
2021-04-17 19:02:02 +00:00
fprintf(f, "<a id='%s' href='%s'>\n", id, href);
fprintf(f, "<img class='image' src='%s' alt='%s'/>\n", thumb, alt);
fputs("</a>\n", f);
2021-04-17 19:02:02 +00:00
return 1;
}
2022-08-21 20:18:03 +00:00
int fpvideo(FILE* f, char* s) {
char id[1024] = {0};
char href[1024] = {0};
char src[1024] = {0};
char alt[1024] = {0};
char thumb[1024] = {0};
char* c = s;
int i = 0;
while (i < 4) {
if (*c == '|' || !(*c)) {
i++;
c++;
continue;
}
switch (i) {
case 0:
ccat(id, *c++);
break;
case 1:
ccat(href, *c++);
break;
case 2:
ccat(src, *c++);
break;
case 3:
ccat(alt, *c++);
break;
}
}
thumbtrans(src, thumb);
fprintf(
f,
"<video id='%s' src='%s' controls preload='metadata' poster='%s'>\n",
id,
href,
thumb);
fprintf(f, "<a href='%s'><img src='%s' alt=''%s'></a>\n", href, thumb, alt);
2022-08-21 20:18:03 +00:00
fprintf(f, "</video>\n");
return 1;
}
2021-04-17 19:02:02 +00:00
int fpaudio(FILE* f, char* s) {
fputs("<audio class='player' preload='metadata' controls>\n", f);
fprintf(
f,
"<source src='%s' type='audio/mpeg'>[<a href='%s'>HTML5 audio</a>]\n",
s,
s);
fputs("</audio>\n", f);
2021-04-17 19:02:02 +00:00
return 1;
}
int fpmono(FILE* f, Lexicon* l, char* s) {
fputs("<span style='font-family:monospace;'>", f);
int ret = fpmetatemplate(f, l, s);
fputs("</span>", f);
return ret;
}
int fpserif(FILE* f, Lexicon* l, char* s) {
fputs("<span style='font-family:serif;'>", f);
int ret = fpmetatemplate(f, l, s);
fputs("</span>", f);
return ret;
}
int fpsans(FILE* f, Lexicon* l, char* s) {
fputs("<span style='font-family:sans;'>", f);
int ret = fpmetatemplate(f, l, s);
fputs("</span>", f);
return ret;
}
int fppara(FILE* f, Lexicon* l, char* s) {
fputs("<p>", f);
int ret = fpmetatemplate(f, l, s);
fputs("</p>", f);
return ret;
}
int fpul(FILE* f, Lexicon* l, char* s) {
fputs("<ul>", f);
int ret = fpmetatemplate(f, l, s);
fputs("</ul>", f);
return ret;
}
int fpol(FILE* f, Lexicon* l, char* s) {
fputs("<ol>", f);
int ret = fpmetatemplate(f, l, s);
fputs("</ol>", f);
return ret;
}
int fppublish(FILE* f, char* s) {
2022-02-13 02:47:58 +00:00
fputs("<time class='publish-date'>", f);
fputs(s, f);
2022-02-13 02:47:58 +00:00
fputs("</time>", f);
return 1;
}
int fpli(FILE* f, Lexicon* l, char* s) {
fputs("<li>", f);
int ret = fpmetatemplate(f, l, s);
fputs("</li>", f);
return ret;
}
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;
}
2022-06-19 05:55:45 +00:00
int fpstrike(FILE* f, Lexicon* l, char* s) {
fputs("<s>", f);
int ret = fpmetatemplate(f, l, s);
fputs("</s>", f);
return ret;
}
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;
}
2021-04-15 18:44:07 +00:00
int fptemplate(FILE* f, Lexicon* l, char* 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);
2022-08-21 20:18:03 +00:00
case ']':
return fpvideo(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 '~':
2022-06-19 05:55:45 +00:00
return fpstrike(f, l, 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);
2022-11-01 05:09:08 +00:00
case '[':
return fpthead(f, s + 1);
case '|':
return fptbody(f, l, s + 1);
case ';':
return fptfoot(f);
case '=':
return fpmono(f, l, s + 1);
case '(':
return fpsans(f, l, s + 1);
case ')':
return fpserif(f, l, s + 1);
}
2022-10-23 05:00:51 +00:00
if (s[0]) {
target = findf(l, s);
2022-10-23 05:00:51 +00:00
}
if (target < 0) {
return error("Missing link", s);
2022-10-23 05:00:51 +00:00
}
fprintf(f, "<a href='/%s.html' class='local'>", scsw(stlc(s), ' ', '_'));
fprintf(f, "%s</a>", scsw(stlc(s), '_', ' '));
l->refs[target]++;
return 1;
}
int fpmetatemplate(FILE* f, Lexicon* l, char* s) {
int bopen, bclose;
char ss[TAG_BODY_SIZE];
unsigned char t = 0;
bopen = 0;
bclose = 0;
while (*s) {
if (*s == '}') {
bclose++;
if (bopen == bclose) {
t = 0;
bopen = 0;
bclose = 0;
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) >= TAG_BODY_SIZE)
return error("Templating error", "text block exceeds tag body size");
if (t) {
ccat(ss, *s);
2022-10-23 05:00:51 +00:00
} else {
fprintf(f, "%c", *s);
2022-10-23 05:00:51 +00:00
}
s++;
}
return 1;
}
2021-04-15 18:44:07 +00:00
int fpinject(FILE* f, Lexicon* l, char* filepath) {
FILE* inc;
int bopen, bclose;
char c, s[TAG_BODY_SIZE];
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);
2022-10-23 05:00:51 +00:00
s[0] = 0;
while ((c = fgetc(inc)) != EOF) {
if (c == '}') {
bclose++;
if (bopen == bclose) {
t = 0;
bopen = 0;
bclose = 0;
if (!fptemplate(f, l, s)) {
return 0;
}
continue;
}
}
if (c == '{') {
bopen++;
if (bopen == 1) {
s[0] = 0;
t = 1;
continue;
}
}
2022-10-23 05:00:51 +00:00
if (slen(s) >= TAG_BODY_SIZE) {
return error("Templating error", filepath);
2022-10-23 05:00:51 +00:00
}
if (t) {
ccat(s, c);
2022-10-23 05:00:51 +00:00
} else {
fprintf(f, "%c", c);
2022-10-23 05:00:51 +00:00
}
}
fclose(inc);
return 1;
}
2022-10-23 05:00:51 +00:00
int fpfooter(FILE* f, char* name) {
if (!f || !name) {
return 0;
2022-10-23 05:00:51 +00:00
}
fputs("<footer>", f);
if (!ismetanav(name)) {
2022-10-23 05:00:51 +00:00
fpedited(f);
fputs(CONTACT_HTML, f);
}
fputs(FOOTER_HTML, f);
fputs(LICENSE_HTML, f);
fputs("</footer>", f);
return 1;
}
2021-04-15 18:44:07 +00:00
FILE* build(FILE* f, Lexicon* l, char* name, char* srcpath) {
2022-10-23 05:00:51 +00:00
struct stat attr;
if (!f)
return f;
/* begin */
2022-10-23 05:00:51 +00:00
fputs("<!DOCTYPE html>\n<html lang='en'>\n", f);
fputs("<head>\n", f);
2021-04-15 18:44:07 +00:00
fprintf(
f,
"<meta charset='utf-8'>\n"
"<meta name='description' content='%s'/>\n"
"<meta name='viewport' content='width=device-width,initial-scale=1'>\n",
DESC);
if (ismetanav(name)) {
fputs("<link rel='stylesheet' type='text/css' href='" FRONTCSS "'>\n", f);
} else {
fputs("<link rel='stylesheet' type='text/css' href='" MAINCSS "'>\n", f);
}
2021-04-15 18:44:07 +00:00
fprintf(
f,
"<link rel='shortcut icon' href='/favicon.png'>\n"
"<title>" NAME " &mdash; %s</title>\n",
2021-04-17 19:02:02 +00:00
ismetanav(name) ? "home" : name);
fputs("</head>\n", f);
fputs("<body>\n", f);
/* header */
fputs("<header>\n", f);
fputs("<a href='/'><h1>" LOGO_HTML "</h1></a>\n", f);
if (IS_NAV_IN_HEADER) {
/* nav */
fputs("<nav>\n", f);
if (!fpportal(f, l, "meta.nav", 0))
printf(">>> Building failed: %s\n", name);
fputs("</nav>\n", f);
fputs("</header>\n", f);
} else {
fputs("</header>\n", f);
/* nav */
fputs("<nav>\n", f);
if (!fpportal(f, l, "meta.nav", 0))
printf(">>> Building failed: %s\n", name);
fputs("</nav>\n", f);
}
/* main */
2022-10-23 05:00:51 +00:00
stat(srcpath, &attr);
edittime = attr.st_mtime;
if (!ismetanav(name)) {
fputs("<main>\n", f);
fprintf(f, "<h2>%s</h2>\n", name);
if (!fpinject(f, l, srcpath))
printf(">>> Building failed: %s\n", name);
fputs("\n</main>", f);
2021-06-17 08:05:49 +00:00
} else {
/* about & twtxt (main page only) */
fputs("<div id='about'>" ABOUT_HTML "</div>\n", f);
2021-06-17 08:05:49 +00:00
gettwtxt(f);
}
/* footer */
2022-10-23 05:00:51 +00:00
if (!fpfooter(f, name)) {
printf(">>> Building failed: footer(%s)\n", name);
}
/* end */
fputs("</body>\n</html>\n", f);
return f;
}
2021-04-15 18:44:07 +00:00
int generate(Lexicon* l) {
int i = 0;
char srcpath[64], dstpath[64], filename[64];
for (i = 0; i < l->len; ++i) {
srcpath[0] = 0;
dstpath[0] = 0;
filename[0] = 0;
/* src */
scpy(l->files[i], filename, ssin(l->files[i], ".htm") + 1);
scat(srcpath, "inc/");
scat(srcpath, filename);
scat(srcpath, ".htm");
/* dst */
if (scmp(filename, "meta.nav")) {
scat(dstpath, SITEROOT);
scat(dstpath, "index.html");
} else {
scat(dstpath, SITEROOT);
scat(dstpath, filename);
scat(dstpath, ".html");
}
fclose(build(fopen(dstpath, "w"), l, scsw(filename, '_', ' '), srcpath));
}
printf("Generated %d files\n", i);
return 1;
}
2021-04-15 18:44:07 +00:00
int index(Lexicon* l, DIR* d) {
while ((dir = readdir(d)))
if (ssin(dir->d_name, ".htm") > 0) {
l->refs[l->len] = 0;
scpy(dir->d_name, l->files[l->len++], 64);
}
closedir(d);
printf("Indexed %d terms\n", l->len);
return 1;
}
2021-04-15 18:44:07 +00:00
void inspect(Lexicon* l) {
int i;
for (i = 0; i < l->len; ++i)
if (!l->refs[i])
error("Orphaned", l->files[i]);
}
void map(Lexicon* l) {
char dstpath[64];
char srcpath[64];
struct dirent** d;
FILE* siteMap;
int n, i = 0;
n = scandir("inc", &d, NULL, alphasort);
if (n < 0)
return;
dstpath[0] = 0;
srcpath[0] = 0;
scat(dstpath, SITEROOT);
scat(dstpath, "sitemap.html");
scat(srcpath, "map.htm");
siteMap = fopen("map.htm", "w");
/* don't use shorthand for the <ul> tag because it will easily overflow
* TAG_BODY_SIZE */
fprintf(siteMap, "<ul>\n");
while (i < n) {
char filepath[64], filename[64];
if (d[i]->d_name[0] != '.' && !scmp(d[i]->d_name, "meta.nav.htm")) {
scpy(d[i]->d_name, filepath, 64);
fprintf(
siteMap,
" {-{%s}}\n",
scsw(
scpy(d[i]->d_name, filename, ssin(d[i]->d_name, ".htm") + 1),
'_',
' '));
}
free(d[i++]);
}
free(d);
fprintf(siteMap, "</ul>\n");
fclose(siteMap);
fclose(build(fopen(dstpath, "w"), l, "sitemap", srcpath));
remove("map.htm");
printf("Created sitemap\n");
}
int main(void) {
Lexicon lex;
2021-04-15 18:44:07 +00:00
DIR* d;
lex.len = 0;
if (!(d = opendir("inc")))
return error("Open", "Missing inc/ folder. ");
if (!index(&lex, d))
return error("Indexing", "Failed");
if (!generate(&lex))
return error("Generating", "Failed");
inspect(&lex);
map(&lex);
return 0;
}