aboutsummaryrefslogtreecommitdiff
path: root/lib/shlib
diff options
context:
space:
mode:
authorKate Ward <kate.ward@forestent.com>2016-01-10 16:53:04 +0100
committerKate Ward <kate.ward@forestent.com>2016-01-10 16:53:04 +0100
commit4b66ecdc0d3f6b89d3132b75f5aca1773a29a1a3 (patch)
tree9668b6e23a484f660f25ff34c98876db0276ffe6 /lib/shlib
parentb11509fad7f5e9e66a734116fcec7c418419ee1f (diff)
downloadshflags-4b66ecdc0d3f6b89d3132b75f5aca1773a29a1a3.tar.gz
restructured source for GitHub
Diffstat (limited to 'lib/shlib')
-rw-r--r--lib/shlib40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/shlib b/lib/shlib
new file mode 100644
index 0000000..d294636
--- /dev/null
+++ b/lib/shlib
@@ -0,0 +1,40 @@
+# $Id: shlib 14 2007-02-18 19:43:41Z sfsetse $
+# vim:et:ft=sh:sts=2:sw=2
+#
+# Copyright 2011 Kate Ward. All Rights Reserved.
+# Released under the LGPL (GNU Lesser General Public License).
+#
+# Author: kate.ward@forestent.com (Kate Ward)
+#
+# Library of shell functions.
+
+# Convert a relative path into it's absolute equivalent.
+#
+# This function will automatically prepend the current working directory if the
+# path is not already absolute. It then removes all parent references (../) to
+# reconstruct the proper absolute path.
+#
+# Args:
+# shlib_path_: string: relative path
+# Outputs:
+# string: absolute path
+shlib_relToAbsPath()
+{
+ shlib_path_=$1
+
+ # prepend current directory to relative paths
+ echo "${shlib_path_}" |grep '^/' >/dev/null 2>&1 \
+ || shlib_path_="`pwd`/${shlib_path_}"
+
+ # clean up the path. if all seds supported true regular expressions, then
+ # this is what it would be:
+ shlib_old_=${shlib_path_}
+ while true; do
+ shlib_new_=`echo "${shlib_old_}" |sed 's/[^/]*\/\.\.\/*//g;s/\/\.\//\//'`
+ [ "${shlib_old_}" = "${shlib_new_}" ] && break
+ shlib_old_=${shlib_new_}
+ done
+ echo "${shlib_new_}"
+
+ unset shlib_path_ shlib_old_ shlib_new_
+}