aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-06-02 20:30:20 +1200
committerTom Ryder <tom@sanctum.geek.nz>2017-06-02 20:30:20 +1200
commitcde3c255ff7024181a54b19e5ec1dac3ab892836 (patch)
tree8b4b8ab889bb4d28223ff510ff7e6188d1641aa5 /bin
parentSimplify some awk (diff)
downloaddotfiles-cde3c255ff7024181a54b19e5ec1dac3ab892836.tar.gz
dotfiles-cde3c255ff7024181a54b19e5ec1dac3ab892836.zip
Add mi5(1df)
Diffstat (limited to 'bin')
-rw-r--r--bin/mi5.awk50
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"
+}