aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-06-02 22:52:40 +1200
committerTom Ryder <tom@sanctum.geek.nz>2017-06-02 23:01:28 +1200
commite69db9954057b6df99e8e666b199e499aec12007 (patch)
treeeaa51d95cb1ae762114f050b1ea79f1466a532f6 /bin
parentCorrect mi5(1df) man page formatting (diff)
downloaddotfiles-e69db9954057b6df99e8e666b199e499aec12007.tar.gz
dotfiles-e69db9954057b6df99e8e666b199e499aec12007.zip
Implemented an idea
Slightly cleverer parsing for mi5
Diffstat (limited to 'bin')
-rw-r--r--bin/mi5.awk54
1 files changed, 36 insertions, 18 deletions
diff --git a/bin/mi5.awk b/bin/mi5.awk
index 46bbbb25..1ddc5a2f 100644
--- a/bin/mi5.awk
+++ b/bin/mi5.awk
@@ -16,33 +16,51 @@ NF == 1 && $1 == "%>" && mac {
next
}
-# If processing macros, strip leading and trailing whitespace and skip blank
-# lines
-mac {
+# If in a block, print each line with any content on it after stripping leading
+# and trailing whitespace
+mac && NF {
sub(/^ */, "")
sub(/ *$/, "")
-}
-mac && !NF { next }
-
-# Inlines
-mac {
print $0 "dnl"
}
+
+# If not in a block, look for inlines to process
!mac {
- # Don't let apostrophes close the comment
- gsub(/'/, "''`")
+ # We'll empty one variable into another
+ src = $0
+ dst = ""
+
+ # As long as there's a pair of opening and closing tags
+ while (src ~ /<%.*%>/) {
- # Replace m5 opener with m4 closer
- gsub(/<% */, "'")
+ # Read up to opening tag into seg, shift from src
+ ind = index(src, "<%")
+ seg = substr(src, 1, ind - 1)
+ src = substr(src, ind)
- # Replace m5 closer with m4 opener
- gsub(/ *%>/, "`")
+ # Escape quote closer and add to dst
+ gsub(/'/, "''`", seg)
+ dst = dst seg
- print
+ # Read up to closing tag into seg, shift from src
+ ind = index(src, "%>")
+ seg = substr(src, 1, ind + 1)
+ src = substr(src, ind + 2)
+
+ # Translate tags to quote open and close and add to dst
+ sub(/^<% */ , "'", seg)
+ sub(/ *%>$/ , "`", seg)
+ dst = dst seg
+ }
+
+ # Escape quote closers in whatever's left
+ gsub(/'/, "''`", src)
+
+ # Tack that onto the end, and print it
+ dst = dst src
+ print dst
}
# Print an m4 closer and newline deleter as the last bytes
-END {
- print "'dnl"
-}
+END { print "'dnl" }