From: Gustav Eek Date: Wed, 21 Aug 2024 18:20:25 +0000 (+0200) Subject: Add a macro code padding script for compilation purpuses X-Git-Url: https://git.g-eek.se/?a=commitdiff_plain;h=8a6925d269cdc240f181ca5887bbfba41528d001;p=guitarsections.git Add a macro code padding script for compilation purpuses --- diff --git a/sh/macrocode.sh b/sh/macrocode.sh new file mode 100644 index 0000000..790d0e3 --- /dev/null +++ b/sh/macrocode.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +# Between stdin and -out, padds level-tree comment sections ("%%%") +# with LaTeX documentation macrocode environments. + +BEGIN='# Strip empty lines and provide begin-end placeholders + /^%%%/,$ { + $ a % \\end{macrocode} + /^\s*$/ d + /^%%%/ { + i % \\end{macrocode} + a % \\begin{macrocode} + } + } +' + +END='# Remove odd begin-end items + 1,/end.*macrocode/ { + /end.*macrocode/ d + } + /begin.*macrocode/ { + N + /begin.*macrocode.*end.*macrocode/ d + } +' + +cat - | \ + sed -e "$BEGIN" | sed -e "$END"