#!/bin/dash

#? NAME
#?      $0  -  template for dash completion function for o-saft, o-saft.pl, o-saft.tcl
#?
#? DESCRIPTION
#?      dash does not support any completion. Hence this file is merely a
#?      template based on bash's completion. IT WILL NOT YET WORK (2016).
#?
#? USAGE
#?      . dash_completion_o-saft
#?
#? SEE ALSO
#?
#? VERSION
#?      @(#) dash_completion_o-saft 1.5 24/08/16 13:04:17
#?
#? AUTHOR
#?      14-dec-14 Achim Hoffmann
# ------------------------------------------------------------------------------

_y_cmds=`o-saft.pl --help=commands|awk '/^\+/{print $1}'`
_y_opts=`o-saft.pl --help=opts    |awk '/^\-/{print $1}'`
_y_help=`o-saft.pl --help=opts    |awk '/^--help=/{print $1}'`
_y_rang=`o-saft.pl --help=range   |awk "/ *'/"'{print "--cipherrange="$1}'`
_y_gui=`o-saft.tcl --help=opts    |awk '/^[+-]/{print $1}'`
_m_help=`make e-ALL.help    |tr -s ' ' '\\012'`
_m_test=`make e-ALL.tests   |tr -s ' ' '\\012'`
_m_warn=`make e-ALL.tests   |tr -s ' ' '\\012'`

# dash darf kein - in Funktion-Namen haben
# dash braucht { in der selben Zeile wie Funktionsdefinition
_o_saft () {
  local curr_arg;
  curr_arg=${COMP_WORDS[COMP_CWORD]}
  case "$curr_arg" in
    +*)             COMPREPLY=$(compgen -W "$_y_cmds" -- $curr_arg ); ;;
    --cipherrange*) COMPREPLY=$(compgen -W "$_y_rang" -- $curr_arg ); ;;
    --help*)        COMPREPLY=$(compgen -W "$_y_help" -- $curr_arg ); ;;
    -*)             COMPREPLY=$(compgen -W "$_y_opts" -- $curr_arg ); ;;
  esac
}
_o_gui () {
  local curr_arg;
  curr_arg=${COMP_WORDS[COMP_CWORD]}
  COMPREPLY=$(compgen -W "$_y_gui" -- $curr_arg )
}
_make () {
  local curr_arg;
  curr_arg=${COMP_WORDS[COMP_CWORD]}
  case "$curr_arg" in
    help*)          COMPREPLY=$(compgen -W "$_m_help" -- $curr_arg ); ;;
    test*)          COMPREPLY=$(compgen -W "$_m_test" -- $curr_arg ); ;;
    warn*)          COMPREPLY=$(compgen -W "$_m_warn" -- $curr_arg ); ;;
  esac
}
complete -F _o_saft o-saft
complete -F _o_saft o-saft.pl
complete -F _o_gui  o-saft.tcl
complete -F _make   make
