From c1dfd0bb139f58a9f34dbfc61920b59df00c70c1 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Mon, 13 Jul 2020 18:14:22 -0400 Subject: Incorporate CSS into C without file2c It's a shame file2c is not available everywhere. --- .gitignore | 2 +- Makefile | 10 +++++----- css.sh | 9 +++++++++ server.c | 11 +++++------ 4 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 css.sh diff --git a/.gitignore b/.gitignore index bc13172..791d6d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ *.o .test config.mk -default.css.h +css.h scooper tags diff --git a/Makefile b/Makefile index cd9f014..1cb3bf4 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ PREFIX ?= ~/.local MANDIR ?= ${PREFIX}/share/man -CFLAGS += -std=c11 -Wall -Wextra -Wpedantic +CFLAGS += -std=c11 -Wall -Wextra -Wpedantic -Wno-overlength-strings LDLIBS = -lkcgi -lkcgihtml -lsqlite3 TEST_DB = ~/.local/share/litterbox/litterbox.sqlite @@ -24,10 +24,10 @@ scooper: ${OBJS} ${OBJS}: server.h -server.o: default.css.h +server.o: css.h -default.css.h: default.css color.css - cat default.css color.css | file2c > $@ +css.h: css.sh default.css color.css + sh css.sh default.css color.css > $@ test: .test @@ -39,7 +39,7 @@ tags: *.c *.h ctags -w *.c *.h clean: - rm -f scooper ${OBJS} .test tags + rm -f scooper ${OBJS} css.h .test tags install: scooper scooper.1 install -d ${PREFIX}/bin ${MANDIR}/man1 diff --git a/css.sh b/css.sh new file mode 100644 index 0000000..80f28d1 --- /dev/null +++ b/css.sh @@ -0,0 +1,9 @@ +#!/bin/sh +set -eu + +cat < #include +#include "css.h" #include "server.h" sqlite3 *db; @@ -51,15 +52,13 @@ const struct kvalid Keys[KeysLen] = { #undef X }; -static const char CSS[] = { -#include "default.css.h" -}; -static const char *Cache = "public, max-age=86400, immutable"; - static enum kcgi_err stylesheet(struct kreq *req) { if (req->mime != KMIME_TEXT_CSS) return httpFail(req, KHTTP_404); return httpHead(req, KHTTP_200, KMIME_TEXT_CSS) - || khttp_head(req, kresps[KRESP_CACHE_CONTROL], "%s", Cache) + || khttp_head( + req, kresps[KRESP_CACHE_CONTROL], + "public, max-age=86400, immutable" + ) || khttp_body(req) || khttp_write(req, CSS, sizeof(CSS)); } -- cgit 1.4.1