diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-06-02 23:35:33 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-06-02 23:35:33 +1200 |
commit | 31460b8e225813a63cc28331b794769246447397 (patch) | |
tree | 89ac5278d97f4c30daafa2194b95cb1090f3fc2b /bin | |
parent | Add another mi5(1df) caveat (diff) | |
download | dotfiles-31460b8e225813a63cc28331b794769246447397.tar.gz dotfiles-31460b8e225813a63cc28331b794769246447397.zip |
Allow custom delimiters for mi5(1df)
Diffstat (limited to 'bin')
-rw-r--r-- | bin/mi5.awk | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/bin/mi5.awk b/bin/mi5.awk index 1ddc5a2f..82c5f914 100644 --- a/bin/mi5.awk +++ b/bin/mi5.awk @@ -1,16 +1,22 @@ # Crude m4 preprocessor -BEGIN { mac = 0 } +BEGIN { + mac = 0 + if (!length(open)) + open = "<%" + if (!length(shut)) + shut = "%>" +} # Print an m4 opener as the first byte NR == 1 { printf "`" } # Blocks -NF == 1 && $1 == "<%" && !mac { +NF == 1 && $1 == open && !mac { mac = 1 printf "'" next } -NF == 1 && $1 == "%>" && mac { +NF == 1 && $1 == shut && mac { mac = 0 printf "`" next @@ -32,10 +38,10 @@ mac && NF { dst = "" # As long as there's a pair of opening and closing tags - while (src ~ /<%.*%>/) { + while (src ~ open ".*" shut) { # Read up to opening tag into seg, shift from src - ind = index(src, "<%") + ind = index(src, open) seg = substr(src, 1, ind - 1) src = substr(src, ind) @@ -44,13 +50,13 @@ mac && NF { dst = dst seg # Read up to closing tag into seg, shift from src - ind = index(src, "%>") - seg = substr(src, 1, ind + 1) - src = substr(src, ind + 2) + ind = index(src, shut) + seg = substr(src, 1, ind + length(shut) - 1) + src = substr(src, ind + length(shut)) # Translate tags to quote open and close and add to dst - sub(/^<% */ , "'", seg) - sub(/ *%>$/ , "`", seg) + sub("^" open " *", "'", seg) + sub(" *" shut "$", "`", seg) dst = dst seg } |