#! /bin/bash
################################################################################
# Filename: ./src/base/sbin/rel2abs
# 
# The contents of this file are subject to the Qlusters Public License
# Version 1.1 (the License); you may not use this file except in compliance
# with the License.
# You may obtain a copy of the License at
# http://www.openqrm.org/content/view/33/69/.
# 
# Software distributed under the License is distributed on an AS IS basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
# the specific language governing rights and limitations under the License.
# 
# The Original Code is openQRM.
# 
# The Initial Developer of the Original Code is Qlusters Corporation. Portions
# created by Qlusters Corporation are Copyright (C) 2003-2005. All Rights
# Reserved.
# 
# Contributor(s):
# 
# Description:
# 
# Comments:
################################################################################
if [ -e $1 ]; then
	if [ -f $1 ]; then
		DIR=`dirname $1`	
		pushd $DIR > /dev/null && echo $PWD/`basename $1` && popd > /dev/null
		exit $?;
	fi
	if [ -d $1 ]; then
		pushd $1 > /dev/null && echo $PWD && popd > /dev/null
	     	exit $?
	fi
else
	TARGET=$1
	if [ ${1:0:1} != "/" ]; then
		TARGET=$PWD/$1
	fi
	TEMP=`mktemp -d /tmp/resolve.XXXXXX` && TEMP_DIR=${TEMP}${TARGET} && mkdir -p ${TEMP_DIR} && cd ${TEMP_DIR} && echo ${PWD##$TEMP} && rm -rf $TEMP
fi

