[go: up one dir, main page]

File: shlib

package info (click to toggle)
shunit2 2.1.5-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 444 kB
  • ctags: 70
  • sloc: sh: 820; xml: 292; makefile: 100; perl: 28
file content (39 lines) | stat: -rw-r--r-- 1,181 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# $Id: shlib 14 2007-02-18 19:43:41Z sfsetse $
# vim:et:ft=sh:sts=2:sw=2
#
# Copyright 2008 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_
}