diff options
author | rtz12 <koenig@fagott.pw> | 2016-01-20 18:34:19 (UTC) |
---|---|---|
committer | rtz12 <koenig@fagott.pw> | 2016-01-20 18:34:19 (UTC) |
commit | 5325336ea46e4347f4ca12d4daaeec6269ce6c7b (patch) | |
tree | e608e0eecc6da33aa23fd7811c2e488cfe22ce5d /bin | |
parent | 94da9601d1d17ddeaf1d7d5ea8df68008e90f3ab (diff) |
Buildsystem verfeinert
Dafuer JS temporaer kaputtgemacht
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/template.awk | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/bin/template.awk b/bin/template.awk new file mode 100755 index 0000000..f543506 --- /dev/null +++ b/bin/template.awk | |||
@@ -0,0 +1,56 @@ | |||
1 | #!/usr/bin/awk -f | ||
2 | #taken from werc [http://werc.cat-v.org/] | ||
3 | function pr(str) { | ||
4 | if(lastc !~ "[{(]") | ||
5 | gsub(/'/, "''", str) | ||
6 | printf "%s", str | ||
7 | } | ||
8 | function trans(c) { | ||
9 | printf "%s", end | ||
10 | |||
11 | lastc = c | ||
12 | end = "\n" | ||
13 | if(c == "%") | ||
14 | end = "" | ||
15 | else if(c == "(") | ||
16 | printf "echo -n " | ||
17 | else if(c ~ "[})]") { | ||
18 | end = "'\n" | ||
19 | printf "echo -n '" | ||
20 | } | ||
21 | } | ||
22 | |||
23 | BEGIN { | ||
24 | lastc = "{" | ||
25 | trans("}") | ||
26 | } | ||
27 | END { | ||
28 | print end | ||
29 | } | ||
30 | |||
31 | /^%/ && $0 !~ /^%[{()}%]/ && lastc !~ /[({]/ { | ||
32 | trans("%") | ||
33 | print substr($0, 2) | ||
34 | next | ||
35 | } | ||
36 | { | ||
37 | if(lastc == "%") | ||
38 | trans("}") | ||
39 | n = split($0, a, "%") | ||
40 | pr(a[1]) | ||
41 | for(i=2; i<=n; i++) { | ||
42 | c = substr(a[i], 1, 1) | ||
43 | rest = substr(a[i], 2) | ||
44 | |||
45 | if((lastc !~ "[({]" && c ~ "[({]") || | ||
46 | (lastc == "{" && c == "}") || | ||
47 | (lastc == "(" && c == ")")) | ||
48 | trans(c) | ||
49 | else if(c == "%") | ||
50 | pr("%") | ||
51 | else | ||
52 | pr("%" c) | ||
53 | pr(rest) | ||
54 | } | ||
55 | pr("\n") | ||
56 | } | ||