#
# usage:        defltmap.sh
#
# abstract:     This Bourne Shell script determines
#
#               DEFAULT_MAP = size is NPRODUCTS. If default selected
#			      than number in product list (file
#			      screen.map) else 0
#
# note(s):      1. This routine must be called using a . (period)
#
#		2. VENDOR_STRINGS is determined by twelcome.sh
#
# Copyright (c) 1994 by The MathWorks, Inc.
# $Revision: 1.5 $  $Date: 1994/12/12 13:50:50 $
#----------------------------------------------------------------------------
#
#                               Get DEFAULT_MAP
#                               ---------------
#
    DECRYPT_PRODUCTS=
    if [ "$VENDOR_STRINGS" != "" ]; then
	vendor_string="$VENDOR_STRINGS"
	. $dir/$decryptl_sh
    fi
#
# Use the first arch if the arch.$Arch is not on the tape.
# If tbx.matlab is specified then set matlab
#
    plist="$DECRYPT_PRODUCTS"
    if [ "$plist" != "" ]; then
	plist="arch.$Arch $plist"
    fi
    DEFAULT_MAP=`echo $Arch "$plist" | cat - $MAPS_DIR/screen.map | awk '
#--------------------------------------------------------------------------
    BEGIN { na = 0; np = 0; matlabn = 0; tbxmatlab = 0 }
    NR == 1 { arch = $1; archn = 0
              for ( i = 2; i <= NF; i = i + 1) {
		  if ( $i == "tbx.matlab" ) tbxmatlab = 1
		  a[$i] = "1"
	      }
	      next
	    }
    NF == 0          { next }
    $1 ~ /^matlab$/  { np = np + 1; b[np] = $1; matlabn = np; next } 
    $1 ~ /^arch\..*/ { np = np + 1; na = na + 1; b[np] = $1
		       name = "arch." arch
		       if ( $1 == name ) archn = na; next }
		     { np = np + 1; b[np] = $1; next }
    END { s = ""
	  for (i = 1; i <= np; i = i + 1) {
	      name = b[i]
	      if (name == "matlab" && tbxmatlab == "1") 
		  snext = sprintf ("%d ", i)
	      else if (a[name] == "1")
		  snext = sprintf ("%d ", i)
	      else
		  snext = sprintf ("%d ", 0)
	      s = s snext
	  }
	  if (archn == 0) s = "1" substr(s,2)
          print substr(s,1,length(s)-1) }'`
#--------------------------------------------------------------------------
#
# Set LOCALARCH_ON_TAPE to 1 if arch is on tape.
#
    LOCALARCH_ON_TAPE=`echo $Arch |cat - $MAPS_DIR/screen.map | awk '
#--------------------------------------------------------------------------
    BEGIN { na = 0 }
    NR == 1 { arch = $1; archn = 0; next }
    NF == 0          { next }
    $1 ~ /^arch\..*/ { na = na + 1; b[na] = $1
		       name = "arch." arch
		       if ( $1 == name ) archn = na; next }
		     { next }
    END { if (archn != 0)
	      print 1
	  else
	      print 0
	}'`
#--------------------------------------------------------------------------
