forked from aperezdc/ngx-fancyindex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.awk
executable file
·52 lines (45 loc) · 939 Bytes
/
template.awk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#! /usr/bin/awk -f
#
# Copyright © Adrian Perez <[email protected]>
#
# Converts an HTML template into a C header suitable for inclusion.
# Take a look at the HACKING.md file to know how to use it :-)
#
# This code is placed in the public domain.
BEGIN {
varname = 0;
print "/* Automagically generated, do not edit! */"
vars_count = 0;
}
/^<!--[[:space:]]*var[[:space:]]+[^[:space:]]+[[:space:]]*-->$/ {
if (varname) print ";";
if ($3 == "NONE") {
varname = 0;
next;
}
varname = $3;
vars[vars_count++] = varname;
print "static const u_char " varname "[] = \"\"";
next;
}
/^$/ {
if (!varname) next;
print "\"\\n\"";
next;
}
{
if (!varname) next;
# Order matters
gsub(/[\t\v\n\r\f]+/, "");
gsub(/\\/, "\\\\");
gsub(/"/, "\\\"");
print "\"" $0 "\""
}
END {
if (varname) print ";";
print "#define NFI_TEMPLATE_SIZE (0 \\";
for (var in vars) {
print "\t+ nfi_sizeof_ssz(" vars[var] ") \\";
}
print "\t)"
}