#
# usage:        decryptl.sh
#
# abstract:     This Bourne Shell script determines
#
#		DECRYPT_PRODUCTS = list of products from 
#				   $vstring_map file found in the
#				   the string, vendor_string.
#
# note(s):      1. This routine must be called using a . (period)
#
# Copyright (c) 1994 by The MathWorks, Inc.
# $Revision: 1.2 $  $Date: 1994/12/08 16:55:23 $
#----------------------------------------------------------------------------
#
#                               Get decrypt product list
#                               ------------------------
#
    DECRYPT_PRODUCTS=
    if [ "$vendor_string" != "" ]; then
	DECRYPT_PRODUCTS=`echo $vendor_string | cat - $vstring_map | awk '
#--------------------------------------------------------------------------
    BEGIN { x[0] = "0 0 0 0"
	    x[1] = "0 0 0 1"
	    x[2] = "0 0 1 0"
	    x[3] = "0 0 1 1"
	    x[4] = "0 1 0 0"
	    x[5] = "0 1 0 1"
	    x[6] = "0 1 1 0"
	    x[7] = "0 1 1 1"
	    x[8] = "1 0 0 0"
	    x[9] = "1 0 0 1"
	    x["a"] = "1 0 1 0"; x["A"] = "1 0 1 0"
	    x["b"] = "1 0 1 1"; x["B"] = "1 0 1 1" 
	    x["c"] = "1 1 0 0"; x["C"] = "1 1 0 0"
	    x["d"] = "1 1 0 1"; x["D"] = "1 1 0 1"
	    x["e"] = "1 1 1 0"; x["E"] = "1 1 1 0"
	    x["f"] = "1 1 1 1"; x["F"] = "1 1 1 1" }
#
# There can be more than one string for multiple lines
#
    NR == 1 { nbits = 0
	      for (ns = 1; ns <= NF; ns = ns + 1) {
	          len = length($ns)
	          list = ""
	          for ( i = 1; i <= len; i = i + 1) {
		      name=substr($ns,i,1)
		      if ( x[name] != "" ) list = list " " x[name]
	          }
		  if ( list == "" ) continue
	          nbitsnew = split(list,bitsnew);
		  if ( nbits == 0 ) {
		      for ( i = 1; i <= nbitsnew; i = i + 1 )
		          bits[i] = bitsnew[i]
		      nbits = nbitsnew
		      continue
		  }
#
#		  case 1                    case 2
#
#	      1               n            1      n 
#   bits    =          xxxxxxxx            xxxxxxxx
#   bitsnew = yyyyyyyyyyyyyyyyy                yyyy
#		       zzzzzzzz            xxxxzzzz
#	      yyyyyyyyyzzzzzzzz
#
		  minbits = nbitsnew
		  if (minbits > nbits) minbits = nbits
		  for (i = 1; i <= minbits; i = i + 1)
		      if ( bitsnew[nbitsnew - i + 1] != "0" ) bits[nbits - i + 1] = bitsnew[nbitsnew - i + 1]
		  if ( nbitsnew > nbits ) {
		      for (i = 1; i <= minbits; i = i + 1)
			  bitsnew[nbitsnew - i + 1] = bits[nbits - i + 1]
		      for (i = 1; i <= nbitsnew; i = i + 1)
			  bits[i] = bitsnew[i]
		      nbits = nbitsnew
		  }
	      }
	      if ( nbits == 0 ) exit
	      next
	    }
	    { lic[NR - 1] = $2; next }
    END { list = ""
	  nlic = NR - 1
          for ( i = 1; i <= nbits; i = i + 1) {
	      if ( nbits - i + 1 > nlic ) continue
	      if ( bits[i] == "0" ) continue
	      name=lic[nbits - i + 1]
	      if ( save[name] == "" ) {
		   list = name " " list 
		   save[name] = "1"
	      }
	  }
	  if ( list != "" ) print substr(list,1,length(list)-1)
	  }'`
#--------------------------------------------------------------------------
    fi
