summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2016-03-24 21:04:15 (EDT)
committer P. J. McDermott <pj@pehjota.net>2017-02-08 18:25:52 (EST)
commitb41b9028d447fbd0444824280d53e2b28e8355ad (patch)
tree14781c8e8fc3fea0dc65249f8cf0eea69549f986
parent39e8a092240b07bd4b39a7e327ea894610a9c14a (diff)
downloadeggshell-b41b9028d447fbd0444824280d53e2b28e8355ad.zip
eggshell-b41b9028d447fbd0444824280d53e2b28e8355ad.tar.gz
eggshell-b41b9028d447fbd0444824280d53e2b28e8355ad.tar.bz2
research/ref.sh: New file
-rw-r--r--research/ref.sh66
1 files changed, 66 insertions, 0 deletions
diff --git a/research/ref.sh b/research/ref.sh
new file mode 100644
index 0000000..88f1d31
--- /dev/null
+++ b/research/ref.sh
@@ -0,0 +1,66 @@
+foo()
+{
+ local var=1
+
+ bar var
+}
+
+bar(string ref)
+{
+ local var=2
+
+ eval "${ref}=3"
+}
+
+
+
+foo()
+{
+ local var=1
+
+ bar &var
+}
+
+bar(string ref)
+{
+ local var=2
+
+ !ref=3
+}
+
+
+
+__ref()
+{
+ __var=${1}
+
+ case " ${__fn_vars} " in *" ${__var} "*)
+ printf '__fn_vars_%d_%s' ${__sp} "${__var}"
+ return 0
+ ;; esac
+ eval "__val=\${__${__prev_tu}_static_vars}"
+ case " ${__val} " in *" ${__var} "*)
+ printf '__fn_vars_%d_%s' ${__sp} "${__var}"
+ return 0
+ ;; esac
+}
+
+__derefset()
+{
+ __var=${1}
+
+ case "${__var}" in
+ *[!A-Za-z0-9_]*)
+ printf 'Error: Invalid reference variable\n' >&2
+ exit 1
+ ;;
+ '__fn_vars_'[A-Za-z_]*)
+ ;;
+ *)
+ printf 'Error: Invalid reference variable\n' >&2
+ exit 1
+ ;;
+ esac
+
+ eval "printf '%s' \${${__var#__fn_vars_}}"
+}