4 function sh_escape(arg){
5 return "'" gensub(/'/, "'\"'\"'", "g", arg) "'";
8 function argsplit(line, args, LOCAL, c, n, ctx) {
11 while ( length(line) > 0 ) {
12 c = substr(line, 1, 1);
13 line = substr(line, 2);
15 if (c ~ /[ \t]/) ctx = "space";
16 else if (c ~ /\\/) { n++; ctx = "escbare"; }
17 else if (c ~ /"/) { n++; ctx = "dquot"; }
18 else if (c ~ /'/) { n++; ctx = "squot"; }
19 else { n++; args[n] = c; ctx = "bare"; }
20 else if (ctx == "bare")
21 if (c ~ /[ \t]/) ctx = "space";
22 else if (c ~ /\\/) ctx = "escbare";
23 else if (c ~ /"/) ctx = "dquot";
24 else if (c ~ /'/) ctx = "squot";
25 else args[n] = args[n] c;
26 else if (ctx == "dquot")
27 if (c ~ /"/) ctx = "bare";
28 else if (c ~ /\\/) ctx = "escdquot";
29 else args[n] = args[n] c;
30 else if (ctx == "squot")
31 if (c ~ /'/) ctx = "bare";
32 else args[n] = args[n] c;
33 else if (ctx == "escbare") {
37 else if (ctx == "escdquot") {
44 function macro(call, LOCAL, line, files, n, args) {
45 "cd " sh_escape(ENVIRON["MD_MACROS"]) "; printf '%s/' *" |getline line;
46 split(line, files, "/");
47 for (n in files) { files[files[n]] = ""; delete files[n]; }
53 for (n = 1; n in args; n++) call = call sh_escape(args[n]) " ";
55 if (args[1] in files) {
56 RS=""; ORS=""; line="";
57 "printf '%s' " sh_escape(file) " | " sh_escape(ENVIRON["MD_MACROS"]) "/" call | getline line;
60 return HTML("<<" call ">>");
65 if (ENVIRON["MD_MACROS"]) { AllowMacros = "true"; }