blob: 84a1afd4a442e36d5ee1cf36661ac4be49a0584c [file] [log] [blame]
#!/bin/bash
## -----------------------------------------------------------------------
## -----------------------------------------------------------------------
## -----------------------------------------------------------------------
## Intent: Set state flags for parsing based on detection of switch modifiers
## -----------------------------------------------------------------------
function getopt_detect_modifiers()
{
local arg="$1"; shift
local -a patterns=()
patterns+=('and' 'or')
patterns+=('excl' 'incl')
patterns+=('in' 'not')
patterns+=('is-empty')
unset getopt_argv_AND
unset getopt_argv_EXCL
unset getopt_argv_INCL
unset getopt_argv_IN
unset getopt_argv_IS_EMPTY
unset getopt_argv_NOT
unset getopt_argv_OR
local pattern
for pattern in "${patterns[@]}";
do
# echo "** ${FUNCNAME} pattern=[$pattern], arg=[$arg]"
case "$pattern" in
'and')
case "$arg" in
*'-'[aA][nN][dD]*) declare -g -i getopt_argv_AND=1 ;;
esac
;;
'or')
case "$arg" in
*'-'[oO][rR]*)
declare -g -i getopt_argv_OR=1
;;
esac
;;
'excl')
case "$arg" in
*'-'[eE][xX][cC][lL]*) declare -g -i getopt_argv_EXCL=1 ;;
esac
;;
'incl')
case "$arg" in
*'-'[iI][nN][cC][lL]*) declare -g -i getopt_argv_INCL=1 ;;
esac
;;
'in')
if [[ ! -v getopt_argv_INCL ]]; then
case "$arg" in
*'-'[iI][nN]*) declare -g -i getopt_argv_IN=1 ;;
esac
fi
;;
'is-empty')
case "$arg" in
*'-'[iI][sS]-[eE][mM][pP][tT][yY]) declare -g -i getopt_argv_IS_EMPTY=1 ;;
esac
;;
'not')
case "$arg" in
*'-'[nN][oO][tT]*) declare -g -i getopt_argv_NOT=1 ;;
esac
;;
esac
done
if false; then
[[ -v getopt_argv_AND ]] && { declare -p getopt_argv_AND; }
[[ -v getopt_argv_EXCL ]] && { declare -p getopt_argv_EXCL; }
[[ -v getopt_argv_INCL ]] && { declare -p getopt_argv_INCL; }
[[ -v getopt_argv_IN ]] && { declare -p getopt_argv_IN; }
[[ -v getopt_argv_IS_EMPTY ]] && { declare -p getopt_argv_IS_EMPTY; }
[[ -v getopt_argv_NOT ]] && { declare -p getopt_argv_NOT; }
[[ -v getopt_argv_OR ]] && { declare -p getopt_argv_OR; }
fi
: # return $?==0
return
}
# [EOF]