Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/scripts/library/parse_options.sh
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-04-08 15:12:27 -0400
committerDan McGee <dan@archlinux.org>2012-04-24 08:38:36 -0500
commit00ab01e6342b7183d5a16ae57497b19dc1c2c7dc (patch)
tree255ed695cf0ae4655028777d15508f5e891aef30 /scripts/library/parse_options.sh
parente07a2ab45e67e8ee989f9d102051481a35329b09 (diff)
scripts/library: remove parse_options
This is retired, as the two consumers of this function are now using the new parseopts instead. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Diffstat (limited to 'scripts/library/parse_options.sh')
-rw-r--r--scripts/library/parse_options.sh105
1 files changed, 0 insertions, 105 deletions
diff --git a/scripts/library/parse_options.sh b/scripts/library/parse_options.sh
deleted file mode 100644
index 039eef92..00000000
--- a/scripts/library/parse_options.sh
+++ /dev/null
@@ -1,105 +0,0 @@
-# getopt like parser
-parse_options() {
- local short_options=$1; shift;
- local long_options=$1; shift;
- local ret=0;
- local unused_options=""
- local i
-
- while [[ -n $1 ]]; do
- if [[ ${1:0:2} = '--' ]]; then
- if [[ -n ${1:2} ]]; then
- local match=""
- for i in ${long_options//,/ }; do
- if [[ ${1:2} = ${i//:} ]]; then
- match=$i
- break
- fi
- done
- if [[ -n $match ]]; then
- local needsargument=0
-
- [[ ${match} = ${1:2}: ]] && needsargument=1
- [[ ${match} = ${1:2}:: && -n $2 && ${2:0:1} != "-" ]] && needsargument=1
-
- if (( ! needsargument )); then
- printf ' %s' "$1"
- else
- if [[ -n $2 ]]; then
- printf ' %s ' "$1"
- shift
- printf "'%q" "$1"
- while [[ -n $2 && ${2:0:1} != "-" ]]; do
- shift
- printf " %q" "$1"
- done
- printf "'"
- else
- printf "@SCRIPTNAME@: $(gettext "option %s requires an argument\n")" "'$1'" >&2
- ret=1
- fi
- fi
- else
- echo "@SCRIPTNAME@: $(gettext "unrecognized option") '$1'" >&2
- ret=1
- fi
- else
- shift
- break
- fi
- elif [[ ${1:0:1} = '-' ]]; then
- for ((i=1; i<${#1}; i++)); do
- if [[ $short_options =~ ${1:i:1} ]]; then
- local needsargument=0
-
- [[ $short_options =~ ${1:i:1}: && ! $short_options =~ ${1:i:1}:: ]] && needsargument=1
- [[ $short_options =~ ${1:i:1}:: && \
- ( -n ${1:$i+1} || ( -n $2 && ${2:0:1} != "-" ) ) ]] && needsargument=1
-
- if (( ! needsargument )); then
- printf ' -%s' "${1:i:1}"
- else
- if [[ -n ${1:$i+1} ]]; then
- printf ' -%s ' "${1:i:1}"
- printf "'%q" "${1:$i+1}"
- while [[ -n $2 && ${2:0:1} != "-" ]]; do
- shift
- printf " %q" "$1"
- done
- printf "'"
- else
- if [[ -n $2 ]]; then
- printf ' -%s ' "${1:i:1}"
- shift
- printf "'%q" "$1"
- while [[ -n $2 && ${2:0:1} != "-" ]]; do
- shift
- printf " %q" "$1"
- done
- printf "'"
-
- else
- printf "@SCRIPTNAME@: $(gettext "option %s requires an argument\n")" "'-${1:i:1}'" >&2
- ret=1
- fi
- fi
- break
- fi
- else
- echo "@SCRIPTNAME@: $(gettext "unrecognized option") '-${1:i:1}'" >&2
- ret=1
- fi
- done
- else
- unused_options="${unused_options} '$1'"
- fi
- shift
- done
-
- printf " --"
- [[ $unused_options ]] && printf ' %s' "${unused_options[@]}"
- [[ $1 ]] && printf " '%s'" "$@"
- printf "\n"
-
- return $ret
-}