# 1.14 sorcery function
if ! declare -f codex_get_spell_paths &> /dev/null; then
  function codex_get_spell_paths() {
    local SPELL_DIRECTORY=$1
    SECTION_DIRECTORY=${SPELL_DIRECTORY%/*}
    SECTION=${SECTION_DIRECTORY##*/}
    GRIMOIRE=${SECTION_DIRECTORY%/*}
    GRIMOIRE_NAME=$(basename $GRIMOIRE)
  }
fi

# 1.13 workaround sorcery bug #13001
unset -f url_ftp_verify &&
function url_ftp_verify() {
  local  URL=$1

  if  [[  -n  "$URL"  ]];  then
    local  FILENAME=`basename $URL`
    local  DIRECTORY=`dirname $URL`
    local  OUTPUT=`wget --passive-ftp -t 1 -T 30 -O - --spider -S "$DIRECTORY/" 2>&1`

    if grep  -q  "$FILENAME" <<< "$OUTPUT";  then
      rm  -f  .listing
    else
      echo  $OUTPUT  |  sed  's/LIST.*//g'
      [[  -f  .listing  ]]  &&  cat  .listing
      rm -f  .listing
      false
    fi
  fi
}

# too many menu options for 1.13
unset -f select_list &&
function select_list()
{
    local i
    local foo temp number
    local returnvar=$1
    local _default=$2
    local stuff=()
    local _default_num=0

    shift 2
    hash_unset select_list_hash
    # see note in select_provider
    stuff=(0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)

    let i=0
    for foo in "$@"; do
        message "\t$DEFAULT_COLOR(${stuff[$i]})  $SPELL_COLOR$foo$DEFAULT_COLOR"
        hash_put select_list_hash "${stuff[$i]}" "$foo"
        [[ "$foo" ]] && [[ "$foo" == "$_default" ]] && _default_num=${stuff[$i]}
        let i++
    done

    local msgstr="\n${QUERY_COLOR}Which one do you want? [$_default_num]$DEFAULT_COLOR "
    select_list_sub "$returnvar" select_list_hash "$msgstr" "$_default_num"
    hash_unset select_list_hash
}

unset -f select_list_sub &&
function select_list_sub() {
  local returnvar=$1
  local hashname=$2
  local msgstr=$3
  local _default=$4

  local _result _answer

  while [[ ! $_result ]] ; do
    message -n "$msgstr"
    read   -t  $PROMPT_DELAY  -n  1  _answer
    [[ "$_answer" ]] || _answer=$_default
    _result="$(hash_get $hashname $_answer)"
  done
  echo
  eval $returnvar=\"$_result\"
}

unset -f url_https_verify &&
function url_https_verify() {
  local  URL=$1

  if [  -n  "$URL"  ]; then
    if  OUTPUT=`wget --passive-ftp -t 1 -T 30 --spider --no-check-certificate "$URL" 2>&1`;  then
      true
    else
      echo  $OUTPUT
      false
    fi
  fi
}

#---
##
## This software is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This software is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this software; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
##
#---
