sapp

Suckless awk preprocessor
Log | Files | Refs | README | LICENSE

commit 7110d113b6a74dad28c5deed7c55ab7b3e2436cb
parent e27a2cb70095f67206732db2844f62a6570b41f6
Author: Rubén Santos <kojicomics@openmailbox.org>
Date:   Fri Dec  2 19:54:17 +0100

First sapp commit

Diffstat:
sapp | 37+++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+), 0 deletions(-)
diff --git a/sapp b/sapp @@ -0,0 +1,37 @@ +#!/usr/bin/awk -f + +function q(s) { + gsub(/{%%/, "{%", s); + gsub(/\\/, "\\\\", s); + gsub(/%/, "%%", s); + gsub(/'\''/, "'\''\"'\''\"'\''", s); + return s; +} + +content == 0 && /^$/ { content = 1; next; } +content == 0 && /^\w+:/ { + key = substr($0, 0, index($0, ":") - 1) + value = substr($0, index($0, ":") + 1) + gsub(/^\s+/, "", key); gsub(/\s+$/, "", key); + gsub(/^\s+/, "", value); gsub(/\s+$/, "", value); + page[key] = value; +} +content == 1 { body = body "{%nl%}" $0; } + +END { + for (i in page) + print("export page_" i "='\''" q(page[i]) "'\'';"); + + n = split(body, g, /{%[^%]+%}/, sep); + + for (i = 1; i < n; i++) { + if (g[i] != "") + printf("printf -- '\''%s'\'';", q(g[i])); + gsub(/^{%\s*/, "", sep[i]); gsub(/\s*%}$/, "", sep[i]); + if (sep[i] == "nl") + print("echo;"); + else if (sep[i] in page) + printf("printf -- '\''%s'\'';", q(page[sep[i]])); + else print(sep[i] ";"); + } +}