#! /bin/sh
#
# usage:        lmerror error_message
#
# abstract:     This Bourne Shell script is execed by MATLAB when it
#		fails to startup due to a license manager problem.
#		The error message is passed as an argument.
#
# note(s):      1. The code to call lmdebug at this point is commented
#		   out.
#
# Copyright (c) 1986-1998 by The MathWorks, Inc.
# $Revision: 1.6 $  $Date: 1998/10/08 19:11:14 $
#----------------------------------------------------------------------------
#
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
    echo '------------------------------------------------------------------'
    echo '>>>>>  MATLAB did not start due to a license manager problem. <<<<<'
    echo ''
    echo '       If you need additional help try:'
    echo '' 
    echo '       1. UNIX Installation and License Manager Troubleshooting Guide'
    echo ''
    echo '          http://www.mathworks.com/support/tech-notes/v5/1300/1310.shtml'
    echo ''
    echo '       2. Installation Guide for UNIX'
    echo '          License Management, Troubleshooting'
    echo ''
    echo '          Printed manual or PostScript file in $MATLAB.'
    echo ''
    echo '       As a last resort you can execute the script, $MATLAB/etc/lmdebug.'
    echo ''
    echo '           MATLAB = '"$MATLAB"
    echo ''
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo "$LM_LICENSE_FILE" | awk '
#----------------------------------------------------------------------------
        BEGIN { backslash = sprintf ("%c", 92) }
	{ n = split($0,a,":")
	  print "       LM_LICENSE_FILE = " backslash
          printf "%s", "           " a[1]
	  for (i = 2; i <= n; i = i + 1) {
	      printf "%s\n", ":" backslash
              printf "%s", "           " a[i]
	  }
	  printf"\n"
	}'
#----------------------------------------------------------------------------
#
#  If no port@host being used inform people about it.
#
#  Check for dummy port@host and license files that do not exist
#
    licensefilelist=`echo $LM_LICENSE_FILE | tr ':' ' '`
    nfiles=`echo $licensefilelist | awk '{ print NF }'`
    portathost=0
    for licensefile in $licensefilelist
    do
        if [ `expr "$licensefile" : '.*@.*'` -ne 0 ]; then
	    portathost=1
        elif [ ! -f $licensefile ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''  
    echo "       $licensefile:  file not found . . ."
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	fi
    done 
#
    if [ "$portathost" = "0" ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
    echo 'Note:  The value of LM_LICENSE_FILE can be a colon separated list'
    echo '       of port@host entries and/or filenames.  Using a port@host'
    echo '       entry instead of a license filename is highly recommended.'
    echo '       To configure for port@host see $MATLAB/bin/.matlab5rc.sh.'
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    fi
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#    mesg="      Run the 'lmdebug' script now? (y/[n])"
#    . $MATLAB/install/echon.sh
#    read ans
#    if [ `expr "$ans" : '[Yy].*'` -ne 0 ]; then
#	. $MATLAB/etc/lmdebug
#    else
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo '------------------------------------------------------------------'
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#    fi
    exit 0
