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, args) {
48 for (n = 1; n in args; n++) call = call sh_escape(args[n]) " ";
50 if (args[1] in MACROS) {
52 RS=""; ORS=""; line="";
53 "printf '%s' " sh_escape(file) " | " sh_escape(ENVIRON["MD_MACROS"]) "/" call | getline line;
57 return HTML("<<" call ">>");
62 if (ENVIRON["MD_MACROS"]) {
64 "cd " sh_escape(ENVIRON["MD_MACROS"]) "; printf '%s/' *" |getline macro_list;
65 split(macro_list, MACROS, "/");
66 for (n in MACROS) { MACROS[MACROS[n]] = ""; delete MACROS[n]; }