commit a128a59911dd08740da02e365238e67bd4645710
parent 918ed0f27ebeafc345f25919b893ee935070975f
Author: Louis Burda <quent.burda@gmail.com>
Date: Thu, 3 Aug 2023 08:22:35 +0200
Add support for custom templating prefix
Diffstat:
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/tmpl.c b/tmpl.c
@@ -34,6 +34,8 @@ static size_t lineno = 0;
static bool fail_missing = false;
+static const char *prefix = "#{";
+
static void
die(const char *fmt, ...)
{
@@ -162,13 +164,13 @@ template(char *line)
return;
while (1) {
- open = strstr(line, "#{");
+ open = strstr(line, prefix);
if (!open) break;
if (open != line && open[-1] == '\\') {
open[-1] = '\0';
fputs(line, stdout);
- fputs("#{", stdout);
+ fputs(prefix, stdout);
line = open + 2;
continue;
}
@@ -223,6 +225,9 @@ main(int argc, char **argv)
for (dst = arg = argv + 1; *arg; arg++) {
if (!strcmp(*arg, "-e")) {
fail_missing = true;
+ } else if (!strcmp(*arg, "-p")) {
+ prefix = *++arg;
+ if (!prefix || !*prefix) die("invalid prefix");
} else {
*dst++ = *arg;
}
@@ -235,9 +240,11 @@ main(int argc, char **argv)
"[-D NAME=VALUE].. FILE..\n");
return 1;
} else if (!strcmp(*arg, "-D") || !strcmp(*arg, "--define")) {
- assign(*++arg);
+ if (!*++arg) die("missing argument");
+ assign(*arg);
} else if (!strcmp(*arg, "-c") || !strcmp(*arg, "--config")) {
- perline(*++arg, 1, assign);
+ if (!*++arg) die("missing argument");
+ perline(*arg, 1, assign);
} else {
break;
}