#
# usage:        options.sh
#
# abstract:     This Bourne Shell script parsers the options on the
#		command line.
#
# note(s):      1. This routine must be called using a . (period)
#		2. Options:
#
#     	   -h | -help   Help. Show command usage.
#     		   -b   Batch mode. Ignore all queries to continue.
#			Cannot be used with -m option.
#		   -m   Minimal install. Do not allow changes to anything
#			outside the MATLAB root directory. Cannot be
#			specified with -b option.
#     		   -t 	Terse mode. Only print screens that are critical
#			to the installation.
#		   -u   User mode. Ignore checking for superuser and network
#			superuser.
#		   -x   Extract files only, i.e. do updating only.
#		   -X   Extract files and update scripts only.
#		-<arch> Assume this architecture for installation.
#     		   type Type of installation:
#               	1 - normal
#               	4 - license manager only
#
# Copyright (c) 1992-2002 by The MathWorks, Inc.
# $Revision: 1.31.4.1 $  $Date: 2002/11/01 02:33:39 $
#----------------------------------------------------------------------------
#
    extract_only=0
    extract_fix_only=0
    terse=0
    batch=0
    usermode=0
    minimal_install=0
#
    bad=0
    type=0
    msg=
    alone=0
    notalone=0
    while [ $# -gt 0 ]
    do
	case $1 in
	    -h|-help)				# help
		bad=1
		;;
	    -x)				# extract files only
		notalone=`expr $notalone + 1`
		extract_only=1
		type=1
		;;
	    -X)				# extract files and update scripts
		notalone=`expr $notalone + 1`
		extract_fix_only=1
		type=1
		;;
	    -t)				# terse  
		notalone=`expr $notalone + 1`
		terse=1
		;;
	    -b)				# batch
		notalone=`expr $notalone + 1`
		batch=1
		;;
	    -u)				# install as non-superuser
		notalone=`expr $notalone + 1`
		usermode=1
		;;
	    -m)				# only make changes inside of $MATLAB
		notalone=`expr $notalone + 1`
		minimal_install=1
		;;
	     -*)
		check_archlist argument=$1 noprint
		if [ "$ARCH" = "" ]; then
		    msg='invalid arch'
                    stat=""
                fi
		;;
	     *)				# type of install and everything else
		notalone=`expr $notalone + 1`
		if [ "$1" != "1" -a "$1" != "4" ]; then
        	    msg='usage'
		    bad=1
		else
		    type=`expr $1 + 0`
		fi
		;;
	esac
	shift
	if [ "$bad" = "1" ]; then
	    break
	fi
    done
    alone=`expr $alone + 0`
    notalone=`expr $notalone + 0`
    if [ $alone -gt 1 ]; then
	bad=1
        msg='usage'
    elif [ $alone -gt 0 -a $notalone -gt 0 ]; then
#
# Next two cases for auto-updating from ftp
#
        if [ $alone -eq 1 -a $notalone -eq 1 -a "$batch" = "1" ]; then
	    :
	elif [ $alone -eq 1 -a $notalone -eq 2 -a "$batch" = "1" -a "$type" != "0" ]; then
	    :
	else
	    bad=1
            msg='usage'
	fi
    elif [ "$extract_only" = "1" -a "$type" != "1" ]; then
	bad=1
        msg='usage'
    elif [ "$extract_fix_only" = "1" -a "$type" != "1" ]; then
	bad=1
        msg='usage'
    elif [ "$extract_only" = "1" -a "$extract_fix_only" = "1" ]; then
	bad=1
        msg='usage'
    elif [ "$batch" = "1" -a "$minimal_install" = "1" ]; then
	bad=1
        msg='usage'
    fi
    if [ "$bad" = "1" ]; then
	if [ "$msg" != "" ]; then
	    cat /dev/null > $temp_file 2>&1
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	cat > $temp_file << EOF
    echo '--------------------------------------------------------------------'
    echo "    Error: $msg"
EOF
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	fi
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	cat >> $temp_file << EOF
    echo '--------------------------------------------------------------------'
    echo ' '
    echo '    Usage: install_matlab [-h|-help] | -e | -E | -r |' 
    echo '                      [-t] [-b|-m] [1] [-u] -x |'
    echo '                      [-t] [-b|-m] [1] [-u] -X |'
    echo '                      [-t] [-b|-m] [1] [-u] |'
    echo '                      [-t] [-b|-m] [-u] [-<arch>] [type]'
    echo ' '
    echo '      -h    Help. Show command usage.'
    echo '      -help'
    echo ' '
    echo '      -b    Batch mode. Ignore all queries to continue. Cannot'
    echo '            be specified with -m option.'
    echo ' '
    echo '      -m    Minimal install. Do not allow changes to anything'
    echo '            outside the MATLAB root directory. Cannot be specified'
    echo '            with -b option.'
    echo ' '
    echo '      -t    Terse mode. Print critical screens only.'
    echo ' '
    echo '      -u    User mode. Ignore checking for superuser and network'
    echo '            superuser.'
    echo ' '
    echo '      -x    Extract files only, i.e. do updating only.'
    echo ' '  
    echo '      -X    Extract files and update scripts only.'
    echo ' '
    echo '      -<arch> Assume this architecture for installation.'
    echo ' '
    echo '      type Type of installation:'
    echo '           1 - normal '
    echo '           4 - license manager only'
    echo ' '
    echo '--------------------------------------------------------------------'
EOF
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	chmod +x $temp_file
	. $temp_file | more
        . $dir/$cleanup_sh
	exit 0
    fi
