From f541a6a059c96525fdb66f23df993b70c94d8b7b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Fri, 18 Mar 2022 12:51:40 +0100 Subject: [PATCH] cache macro list --- md_macros.awk | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/md_macros.awk b/md_macros.awk index 7e15482..4b85a0e 100755 --- a/md_macros.awk +++ b/md_macros.awk @@ -41,18 +41,13 @@ function argsplit(line, args, LOCAL, c, n, ctx) { } } -function macro(call, LOCAL, line, files, n, args) { - "cd " sh_escape(ENVIRON["MD_MACROS"]) "; printf '%s/' *" |getline line; - split(line, files, "/"); - for (n in files) { files[files[n]] = ""; delete files[n]; } - delete files[""]; - +function macro(call, LOCAL, line, args) { argsplit(call, args); call=""; for (n = 1; n in args; n++) call = call sh_escape(args[n]) " "; - if (args[1] in files) { + if (args[1] in MACROS) { RS=""; ORS=""; line=""; "printf '%s' " sh_escape(file) " | " sh_escape(ENVIRON["MD_MACROS"]) "/" call | getline line; return line; @@ -62,5 +57,11 @@ function macro(call, LOCAL, line, files, n, args) { } BEGIN { - if (ENVIRON["MD_MACROS"]) { AllowMacros = "true"; } + if (ENVIRON["MD_MACROS"]) { + AllowMacros = "true"; + "cd " sh_escape(ENVIRON["MD_MACROS"]) "; printf '%s/' *" |getline macro_list; + split(macro_list, MACROS, "/"); + for (n in MACROS) { MACROS[MACROS[n]] = ""; delete MACROS[n]; } + delete MACROS[""]; + } } -- 2.39.2