#!/bin/sh set verbose set xtrace # arg0_=$0 # Gene - patch for testing. arg0_=/usr/local/bin/matlab # ARCH_LIST='glnx86 glnxa64 mac maci sol2 sol64' # #======================================================================= # Functions: # build_cmd () #======================================================================= build_cmd () { # Takes the cmd input string and outputs the same # string correctly quoted to be evaluated again. # # Always returns a 0 # # usage: build_cmd # echo "$cmd" | awk ' #---------------------------------------------------------------------------- BEGIN { squote = sprintf ("%c", 39) # set single quote dquote = sprintf ("%c", 34) # set double quote } NF != 0 { newarg=dquote # initialize output string to # double quote lookquote=dquote # look for double quote oldarg = $0 while ((i = index (oldarg, lookquote))) { newarg = newarg substr (oldarg, 1, i - 1) lookquote oldarg = substr (oldarg, i, length (oldarg) - i + 1) if (lookquote == dquote) lookquote = squote else lookquote = dquote newarg = newarg lookquote } printf " %s", newarg oldarg lookquote }' #---------------------------------------------------------------------------- return 0 } #======================================================================= # #************************************************************************** # Determine the path of the MATLAB root directory - always one directory # up from the path to this command. #************************************************************************** # echo "................arg0_=$arg0_" filename=$arg0_ echo "................filename=$filename" # # Now it is either a file or a link to a file. # cpath=`pwd` echo "................cpath=$cpath" # # Use it to find the top of the tree # Skip this if someone wants to override the default # if [ "$SOURCE_MATLAB_ENV_FROM" = "" ]; then # # Follow up to 8 links before giving up. Same as BSD 4.3 # n=1 maxlinks=8 while [ $n -le $maxlinks ] do # # Get directory correctly! # echo "..................filename=$filename" newdir=`echo "$filename" | awk ' { tail = $0 np = index (tail, "/") while ( np != 0 ) { tail = substr (tail, np + 1, length (tail) - np) if (tail == "" ) break np = index (tail, "/") } head = substr ($0, 1, length ($0) - length (tail)) if ( tail == "." || tail == "..") print $0 else print head }'` echo "..................newdir=$newdir" if [ ! "$newdir" ]; then newdir="." fi echo "..................newdir=$newdir" (cd $newdir) > /dev/null 2>&1 if [ $? -ne 0 ]; then #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ echo '' echo 'Internal error 1: We could not determine the path of the' echo ' MATLAB root directory.' echo '' echo " original command path = $arg0_" echo " current command path = $filename" echo '' echo ' Please contact:' echo '' echo ' MathWorks Technical Support' echo '' echo ' for further assistance.' echo '' #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ exit 1 fi echo "................--cd newdir=cd $newdir" cd $newdir # # Need the function pwd - not the built in one # newdir=`/bin/pwd` echo "................--newdir=$newdir" # echo "................--filename=$filename" newbase=`expr //$filename : '.*/\(.*\)' \| $filename` echo "................--newbase=$newbase" lscmd=`ls -l $newbase 2>/dev/null` echo "................--lscmd=$lscmd" if [ ! "$lscmd" ]; then #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ echo '' echo 'Internal error 2: Could not determine the path of the' echo ' MATLAB root directory.' echo '' echo " original command path = $filename" echo " current command path = $filename" echo '' echo ' Please contact:' echo '' echo ' MathWorks Technical Support' echo '' echo ' for further assistance.' echo '' #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ exit 1 fi # # Check for link portably # if [ `expr "$lscmd" : '.*->.*'` -ne 0 ]; then filename=`echo "$lscmd" | awk '{ print $NF }'` else # # It's a file # dir="$newdir" command="$newbase" # cd $dir/.. MATLABdefault=`/bin/pwd` break fi n=`expr $n + 1` done echo "................................Beyond error 3" if [ $n -gt $maxlinks ]; then echo "................................Reached internal error 3" #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ echo '' echo 'Internal error 3: More than $maxlinks links in path to' echo " this script. That's too many!" echo '' echo " original command path = $filename" echo " current command path = $filename" echo '' echo ' Please contact:' echo '' echo ' MathWorks Technical Support' echo '' echo ' for further assistance.' echo '' #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ exit 1 fi else MATLABdefault="$SOURCE_MATLAB_ENV_FROM" fi