#!/bin/sh
getrealfullprogname()
{
    # If possible, handle the case that someone has created a symlink in
    # /usr/local/bin back to this script in its original unpacked
    # distribution directory.
    thisfile=`{ readlink -f "$1" \
                || { ls -ld "$1" | sed -n -e 's/.* -> //p'; }
              } 2> /dev/null`
    case $thisfile in
        '' ) thisfile=$1 ;;
    esac

    echo "$thisfile"
}

topdir()
{
    progdir=`dirname "$1"`
    case $progdir in
        . | '' | "$1" ) progdir=`pwd` ;;
    esac

    case $progdir in
        */bin ) topdir=`dirname "$progdir"` ;;
        *     ) topdir=$progdir ;;
    esac

    echo "$topdir"
}

main()
{
    realfullprogname=`getrealfullprogname "$0"`
              prefix=`topdir   "$realfullprogname"`

    P4VRES=$prefix/lib/P4VResources
    LD_LIBRARY_PATH=$prefix/lib${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH}
    PATH=$prefix/bin:$PATH
    export P4VRES LD_LIBRARY_PATH PATH

    exec "$prefix/bin/p4v.bin" -p4vc "$@" || exit $?
}

main "$@"

# eof
