#!/bin/sh

# 
# check Shared Library
# 
# 
# 

if [ "$1" = "--help" ]; then
  echo "description: verify SLBPATH, _slbname_(.slb), or _path_/*.slb"
  echo "             with optional SLB version check.  Will show all"
  echo "             _slbname_(.slb) in SLBPATH if not absolute path."
  echo
  echo "usage: $0 [--help] | [_path_] | [_slbname_] [_slbver_]"
  echo
  echo " --help    : this page"
  echo " _path_    : verify SLB load of *.slb in _path_"
  echo " _slbname_ : verify SLB load of _slbname_(.slb) (also checks SLBPATH)"
  echo " _slbver_  : check _slbname_(.slb) version is _slbver_ or greater"
  echo
  echo "examples: $0"
  echo "          $0 bgh"
  echo "          $0 /c/gemsys/slb"
  echo "          $0 jpeg 3.2"
  echo "          $0 /c/aniplay/vorbis.slb 1"
  exit 0
fi

CHK_4=""
CHK_VER=""

if [ $# -eq 1 -a -d "$1" ]; then
  echo "$1:"
  cd "$1"
  ls --color=always
  echo
  for SLB in *; do
    IS_SLB=`echo "$SLB" | grep -i .slb`
    if [ "$IS_SLB" != "" ]; then
      SLB_RESULT='sblverfy.ttp "$1/$SLB"'
      echo -e "\t$SLB:\t$SLB_RESULT"
    fi
  done
  echo
  exit 0
fi

if [ $# -eq 1 -o $# -eq 2 ]; then
  if [ "$2" != "" ]; then
    CHK_VER="$2"
  fi
  if [ -f "$1" -o -f "$1.slb" -o -f "$1.SLB" ]; then
    echo -n "$1: "
    echo sblverfy.ttp "$1" "$CHK_VER"
    exit 0
  else
    IS_SLB=`echo "$1" | grep -i .slb`
    if [ "$IS_SLB" != "" ]; then
      CHK_4="$1"
    else
      CHK_4="$1.slb"
    fi
  fi
fi

if [ $# -eq 0 -o "$CHK_4" != "" ]; then
  if [ "$SLBPATH" = "" ]; then
    echo "$0: environment variable not set: \$SLBPATH"
    echo
    echo "set SLBPATH in (/c/mint/_ver_/)mint.cnf, where _ver_ is the folder name"
    echo "for the version of MiNT you are using.  Alternately, in a console use:"
    echo "	export SLBPATH=\"C:\\path\\to\\slb;D:\\another\\slb\\path\\\""
    echo "or	setenv SLBPATH \"C:\\path\\to\\slb;D:\\another\\slb\\path\\\""
    echo "depending on the shell and distribution you use. Use DOS format for paths."
    echo
    echo "for more option use \"$0 --help\""
  else
    echo -en "\$SLBPATH: "; echo -E "$SLBPATH"; echo
    SLB_PATHS=`echo "$SLBPATH" | grep \\;`
    if [ "$SLB_PATHS" = "" ]; then
      SLB_PATHS="$SLBPATH"
    else
      SLB_PATHS=`echo -E "$SLBPATH" | sed 's/\\:\\//;\\//g;s/\\;/ /g;s/,/ /g;s/  / /g;s/  / /g'`
    fi
      SLB_PATHS=`echo -E "$SLB_PATHS" | sed 's/\\\\/\\//g;s/[uU]://g;s/\\([a-zA-Z]\\)\\(:\\)/\\/\\L\\1/g'`
    for SP in $SLB_PATHS; do
      cd "$SP"
      if [ "$CHK_4" != "" ]; then
        if [ -f "$CHK_4" ]; then
          echo -n "$SP: "
          echo sblverfy.ttp "$SP/$CHK_4" "$CHK_VER"
        fi
      else
        echo "$SP:"
        ls --color=always
        echo
      fi
    done
  fi
  exit 0
fi

exit 0