ngx-fancyindex/template.awk

53 lines
940 B
Awk
Raw Normal View History

2007-08-24 11:47:59 +00:00
#! /usr/bin/awk -f
#
# Copyright © Adrian Perez <aperez@igalia.com>
2007-08-24 11:47:59 +00:00
#
# Converts an HTML template into a C header suitable for inclusion.
# Take a look at the HACKING.rst 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;
2007-08-24 11:47:59 +00:00
}
/^<!--[[:space:]]*var[[:space:]]+[^[:space:]]+[[:space:]]*-->$/ {
if (varname) print ";";
2007-08-24 12:07:53 +00:00
if ($3 == "NONE") {
varname = 0;
next;
}
2007-08-24 11:47:59 +00:00
varname = $3;
vars[vars_count++] = varname;
2007-08-24 11:47:59 +00:00
print "static const u_char " varname "[] = \"\"";
next;
}
2007-08-30 12:29:41 +00:00
/^$/ {
if (!varname) next;
print "\"\\n\"";
next;
}
2007-08-24 11:47:59 +00:00
{
if (!varname) next;
# Order matters
gsub(/[\t\v\n\r\f]+/, "");
2007-08-24 11:47:59 +00:00
gsub(/\\/, "\\\\");
gsub(/"/, "\\\"");
print "\"" $0 "\""
}
END {
if (varname) print ";";
print "#define NFI_TEMPLATE_SIZE (0 \\";
for (var in vars) {
2007-08-30 12:29:41 +00:00
print "\t+ nfi_sizeof_ssz(" vars[var] ") \\";
}
print "\t)"
2007-08-24 11:47:59 +00:00
}