From 63cf4c66e97a92f3e553707ecd0bc278a7cc4563 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Wed, 1 Oct 2014 21:41:24 +0300 Subject: More doc updates. --- awklib/eg/lib/processarray.awk | 12 ++++++++++++ awklib/eg/lib/shellquote.awk | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 awklib/eg/lib/processarray.awk create mode 100644 awklib/eg/lib/shellquote.awk (limited to 'awklib/eg/lib') diff --git a/awklib/eg/lib/processarray.awk b/awklib/eg/lib/processarray.awk new file mode 100644 index 00000000..79a86d1f --- /dev/null +++ b/awklib/eg/lib/processarray.awk @@ -0,0 +1,12 @@ +function process_array(arr, name, process, do_arrays, i, new_name) +{ + for (i in arr) { + new_name = (name "[" i "]") + if (isarray(arr[i])) { + if (do_arrays) + @process(new_name, arr[i]) + process_array(arr[i], new_name, process, do_arrays) + } else + @process(new_name, arr[i]) + } +} diff --git a/awklib/eg/lib/shellquote.awk b/awklib/eg/lib/shellquote.awk new file mode 100644 index 00000000..cd943dc7 --- /dev/null +++ b/awklib/eg/lib/shellquote.awk @@ -0,0 +1,22 @@ +# shell_quote --- quote an argument for passing to the shell +# +# Michael Brennan +# brennan@madronabluff.com +# September 2014 + +function shell_quote(s, # parameter + SINGLE, QSINGLE, i, X, n, ret) # locals +{ + if (s == "") + return "\"\"" + + SINGLE = "\x27" # single quote + QSINGLE = "\"\x27\"" + n = split(s, X, SINGLE) + + ret = SINGLE X[1] SINGLE + for (i = 2; i <= n; i++) + ret = ret QSINGLE SINGLE X[i] SINGLE + + return ret +} -- cgit v1.2.3