diff options
Diffstat (limited to 'bin/mi5.awk')
-rw-r--r-- | bin/mi5.awk | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/bin/mi5.awk b/bin/mi5.awk new file mode 100644 index 00000000..c05955ff --- /dev/null +++ b/bin/mi5.awk @@ -0,0 +1,50 @@ +# Crude m4 preprocessor +BEGIN { mac = 0 } + +# Print an m4 opener as the first byte +NR == 1 { printf "`" } + +# Blocks +NF == 1 && $1 == "<%" && !mac { + mac = 1 + printf "'" + next +} +NF == 1 && $1 == "%>" && mac { + mac = 0 + printf "`" + next +} + +# If processing macros, strip leading and trailing whitespace and skip blank +# lines +mac { + sub(/^ */, "") + sub(/ *$/, "") +} +mac && !NF { next } + +# Inlines +mac { + print $0 "dnl" +} +!mac { + + # Don't let apostrophes close the comment + gsub(/'/, "''`") + + # Don't let $ signs confound expansion + gsub(/\$/, "$'`") + + # Replace m5 opener with m4 closer + gsub(/<% */, "'") + + # Replace m5 closer with m4 opener + gsub(/ *%>/, "`") + print +} + +# Print an m4 closer and newline deleter as the last bytes +END { + print "'dnl" +} |