# vim:et:ft=sh:sts=2:sw=2 # # 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 proc shlib_relToAbsPath { setglobal shlib_path_ = $1 # prepend current directory to relative paths echo $(shlib_path_) |grep '^/' >/dev/null !2 > !1 \ || setglobal shlib_path_ = ""$[pwd]/$(shlib_path_)"" # clean up the path. if all seds supported true regular expressions, then # this is what it would be: setglobal shlib_old_ = $(shlib_path_) while true { setglobal shlib_new_ = $[echo $(shlib_old_) |sed 's/[^/]*\/\.\.\/*//g;s/\/\.\//\//] test $(shlib_old_) = $(shlib_new_) && break setglobal shlib_old_ = $(shlib_new_) } echo $(shlib_new_) unset shlib_path_ shlib_old_ shlib_new_ }