saait

Simple static page generator
git clone https://git.sinitax.com/codemadness/saait
Log | Files | Refs | README | LICENSE | Upstream | sfeed.txt

commit 76dc99f57364131d08f22e79f71340334fffb1c4
parent ffdca76fc49e952a455ff10a449ddef03fc1ede7
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sat, 26 Nov 2016 18:56:03 +0100

wip

Diffstat:
MMakefile | 2+-
MREADME | 4----
MTODO | 2+-
Mconfig.cfg | 2+-
Msaait.c | 38+++++++++-----------------------------
5 files changed, 12 insertions(+), 36 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,6 +1,6 @@ test: build mkdir -p output - ./saait + ./saait `ls -1r pages/*.cfg` build: clean cc -ggdb saait.c -o saait -Wall -std=c99 diff --git a/README b/README @@ -24,10 +24,6 @@ Directory structure for pages: - pages/file1.html - pages/file1.cfg -The pages are traversed in reverse alphabetical order. This is to make sure -the index and other templates are listed from the most recent to oldest -(for example). - Directory structure for templates: diff --git a/TODO b/TODO @@ -21,5 +21,5 @@ must work on: Linux, OpenBSD, MingW (Windows). - show line number in error improve -- max 1000 LOC +- about 500 LOC x pledge diff --git a/config.cfg b/config.cfg @@ -1,7 +1,7 @@ # defaults: but can be overwritten by any page. # last updated the site. -siteupdated=2016-11-18 15:48:12 +siteupdated=2016-11-26 # site title (part of ${pagetitle} probably). sitetitle=Codemadness diff --git a/saait.c b/saait.c @@ -346,22 +346,6 @@ writepage(FILE *fp, const char *filename, struct config *c, char *s) } } -int -revalphasort(const struct dirent **d1, const struct dirent **d2) -{ - return -alphasort(d1, d2); -} - -int selectcfgfile(const struct dirent *d) -{ - size_t namelen; - - namelen = strlen(d->d_name); - - return (d->d_name[0] != '.' && namelen > 4 && - !strcmp(&d->d_name[namelen - 4], ".cfg")); -} - void usage(void) { @@ -374,8 +358,7 @@ main(int argc, char *argv[]) { struct config *c; char *p, *base, *basefile, file[PATH_MAX], outputfile[PATH_MAX]; - struct dirent **namelist = NULL; - int entries, c, i, j, r; + int i, j, r; #ifdef __OpenBSD__ if (pledge("stdio cpath rpath wpath", NULL) == -1) { @@ -430,23 +413,19 @@ main(int argc, char *argv[]) writepage(templates[i].fp, "", NULL, templates[i].blocks[BlockHeader].data); } - if ((entries = scandir(pagesdir, &namelist, selectcfgfile, revalphasort)) < 0) { - fprintf(stderr, "scandir: %s\n", strerror(errno)); - exit(1); - } - /* pages */ - for (i = 0; i < entries; i++) { - r = snprintf(file, sizeof(file), "%s/%s", pagesdir, namelist[i]->d_name); + for (i = 1; i < argc; i++) { + r = snprintf(file, sizeof(file), "%s", argv[i]); if (r < 0 || (size_t)r >= sizeof(file)) { fprintf(stderr, "path truncated: '%s'\n", argv[i]); exit(1); } if ((p = strrchr(file, '.'))) - base = estrndup(file, p - file); - else - base = estrdup(file); + *p = '\0'; + base = estrdup(file); + if (p) + *p = '.'; /* read config */ c = readconfig(file); @@ -491,12 +470,13 @@ main(int argc, char *argv[]) fclose(templates[j].fp); templates[j].fp = NULL; + + free(basefile); } else { writepage(templates[j].fp, file, c, templates[j].blocks[BlockItem].data); } } free(base); - free(basefile); freevars(c->vars); free(c); }