about summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--template.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/template.c b/template.c
index 750f339..fed3202 100644
--- a/template.c
+++ b/template.c
@@ -24,6 +24,11 @@
 
 #include "archive.h"
 
+static int escapeNull(FILE *file, const char *str) {
+	size_t n = fwrite(str, strlen(str), 1, file);
+	return (n ? 0 : -1);
+}
+
 int escapeURL(FILE *file, const char *str) {
 	static const char *Safe = {
 		"$-_.+!*'(),"
@@ -70,11 +75,12 @@ int templateRender(
 	FILE *file, const char *template,
 	const struct Variable vars[], EscapeFn *escape
 ) {
+	if (!escape) escape = escapeNull;
 	for (bool subst = false; *template; subst ^= true) {
 		size_t len = strcspn(template, "[]");
 		if (subst) {
 			const char *value = NULL;
-			for (const struct Variable *var = vars; var->name; ++var) {
+			for (const struct Variable *var = vars; var && var->name; ++var) {
 				if (strlen(var->name) != len) continue;
 				if (strncmp(var->name, template, len)) continue;
 				value = var->value;
@@ -103,15 +109,14 @@ char *templateURL(const char *template, const struct Variable vars[]) {
 	for (const struct Variable *var = vars; var->name; ++var) {
 		cap += 3 * strlen(var->value);
 	}
-
 	char *buf = malloc(cap);
 	if (!buf) err(EX_OSERR, "malloc");
 
 	FILE *file = fmemopen(buf, cap, "w");
 	if (!file) err(EX_OSERR, "fmemopen");
 
-	int error = templateRender(file, template, vars, escapeURL) || fclose(file);
+	int error = templateRender(file, template, vars, escapeURL)
+		|| fclose(file);
 	assert(!error);
-
 	return buf;
 }
ss='logsubject'>Add influencer tweetJune McEnroe 2020-09-10Add The Kingdom of GodsJune McEnroe Reading has really slowed down :( 2020-09-07Add SunglassesJune McEnroe An IRC find. 2020-09-06Add Between the BreathsJune McEnroe One of those good songs from a soundtrack of a film that probably isn't? The summary sounds a lot more interesting than the title implies, at least. 2020-09-04Open /dev/tty in nudgeJune McEnroe This makes it work even when it's run connected to a pipe, i.e. as the notify command of catgirl... 2020-09-04Add nudgeJune McEnroe 2020-09-03Build fbclock with -lzJune McEnroe I guess this got lost somewhere, long ago... 2020-08-29Add tweets from retweetsJune McEnroe