#!/bin/awk -f
-#!/opt/busybox/awk -f
-# Copyright 2022 - 2023 Paul Hänsch
+# Copyright 2022 - 2024 Paul Hänsch
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
# IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+function debug(text) { printf "\n---\n%s\n---\n", text > "/dev/stderr"; }
+
function sh_escape(arg){
- return "'" gensub(/'/, "'\"'\"'", "g", arg) "'";
+ gsub(/'/, "'\"'\"'", arg);
+ return "'" arg "'";
}
function argsplit(line, args, LOCAL, c, n, ctx) {
return text;
}
-function macro(call, LOCAL, line, args) {
+function macro(call, LOCAL, line, args, cmd) {
argsplit(call, args);
call="";
for (n = 1; n in args; n++) call = call sh_escape(args[n]) " ";
if (args[1] in MACROS) {
- printf "%s", file | sh_escape(ENVIRON["MD_MACROS"]) "/" call;
- close(sh_escape(ENVIRON["MD_MACROS"]) "/" call);
+ cmd = sh_escape(ENVIRON["MD_MACROS"]) "/" call;
+ printf "%s", file | cmd; close( cmd );
} else {
printf "%s", HTML("<<" call ">>");
}
BEGIN {
if (ENVIRON["MD_MACROS"]) {
- AllowMacros = "true";
- "cd " sh_escape(ENVIRON["MD_MACROS"]) "; printf '%s/' *" |getline macro_list;
+ cmd = "cd " sh_escape(ENVIRON["MD_MACROS"]) "; printf '%s/' *";
+ "" cmd |getline macro_list;
+ # ^- need empty string "" concatenation to work in gowk
+ # need prebuilt cmd-variable to work properly in mawk
split(macro_list, MACROS, "/");
for (n in MACROS) { MACROS[MACROS[n]] = ""; delete MACROS[n]; }
delete MACROS[""];