summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-04-07 17:54:02 +0200
committerDan McGee <dan@archlinux.org>2012-04-07 18:03:48 +0200
commit3c5d5a19b36c5ea3638de263cb7cd1be6289cb44 (patch)
tree6b8d70b09046bb3bfb75fe720514892f0a78f87b
parent297916e6a2ad91bbd4cbd0173cac79937b93a393 (diff)
downloadpacman-3c5d5a19b36c5ea3638de263cb7cd1be6289cb44.tar.gz
pacman-3c5d5a19b36c5ea3638de263cb7cd1be6289cb44.tar.xz
Revert "parseopts: normalize options into an array"
This was really only half a fix for FS#28445, as it still doesn't correctly handle the case of filenames with spaces. In the short term, there is no obvious fix for this. In the long term, I believe the correct decision is to rewrite the options parser to be more in line with GNU getopt_long. This reverts commits: ca4142714137b16feabac09c4cda86b0a75036f8. 969dcddbdf9d5dbd91aa414cdd193f3fb26b644b.
-rw-r--r--scripts/library/parse_options.sh32
-rw-r--r--scripts/makepkg.sh.in6
-rw-r--r--scripts/pacman-key.sh.in6
3 files changed, 27 insertions, 17 deletions
diff --git a/scripts/library/parse_options.sh b/scripts/library/parse_options.sh
index d57443b0..039eef92 100644
--- a/scripts/library/parse_options.sh
+++ b/scripts/library/parse_options.sh
@@ -3,7 +3,7 @@ parse_options() {
local short_options=$1; shift;
local long_options=$1; shift;
local ret=0;
- local unused_options=()
+ local unused_options=""
local i
while [[ -n $1 ]]; do
@@ -23,15 +23,17 @@ parse_options() {
[[ ${match} = ${1:2}:: && -n $2 && ${2:0:1} != "-" ]] && needsargument=1
if (( ! needsargument )); then
- OPTRET+=("$1")
+ printf ' %s' "$1"
else
if [[ -n $2 ]]; then
- OPTRET+=("$1" "$2")
+ printf ' %s ' "$1"
shift
+ printf "'%q" "$1"
while [[ -n $2 && ${2:0:1} != "-" ]]; do
shift
- OPTRET+=("$1")
+ printf " %q" "$1"
done
+ printf "'"
else
printf "@SCRIPTNAME@: $(gettext "option %s requires an argument\n")" "'$1'" >&2
ret=1
@@ -55,22 +57,26 @@ parse_options() {
( -n ${1:$i+1} || ( -n $2 && ${2:0:1} != "-" ) ) ]] && needsargument=1
if (( ! needsargument )); then
- OPTRET+=("-${1:i:1}")
+ printf ' -%s' "${1:i:1}"
else
if [[ -n ${1:$i+1} ]]; then
- OPTRET+=("-${1:i:1}" "${1:i+1}")
+ printf ' -%s ' "${1:i:1}"
+ printf "'%q" "${1:$i+1}"
while [[ -n $2 && ${2:0:1} != "-" ]]; do
shift
- OPTRET+=("$1")
+ printf " %q" "$1"
done
+ printf "'"
else
if [[ -n $2 ]]; then
- OPTRET+=("-${1:i:1}" "$2")
+ printf ' -%s ' "${1:i:1}"
shift
+ printf "'%q" "$1"
while [[ -n $2 && ${2:0:1} != "-" ]]; do
shift
- OPTRET+=("$1")
+ printf " %q" "$1"
done
+ printf "'"
else
printf "@SCRIPTNAME@: $(gettext "option %s requires an argument\n")" "'-${1:i:1}'" >&2
@@ -85,11 +91,15 @@ parse_options() {
fi
done
else
- unused_options+=("$1")
+ unused_options="${unused_options} '$1'"
fi
shift
done
- OPTRET+=('--' "${unused_options[@]}")
+ printf " --"
+ [[ $unused_options ]] && printf ' %s' "${unused_options[@]}"
+ [[ $1 ]] && printf " '%s'" "$@"
+ printf "\n"
+
return $ret
}
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 1faf591f..eeb7ede1 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -1918,11 +1918,11 @@ OPT_LONG+=",version,config:"
# Pacman Options
OPT_LONG+=",noconfirm,noprogressbar"
-if ! parse_options $OPT_SHORT $OPT_LONG "$@"; then
+if ! OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@")"; then
echo; usage; exit 1 # E_INVALID_OPTION;
fi
-set -- "${OPTRET[@]}"
-unset OPT_SHORT OPT_LONG OPTRET
+eval set -- "$OPT_TEMP"
+unset OPT_SHORT OPT_LONG OPT_TEMP
while true; do
case "$1" in
diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in
index 278e3d6e..9a77a19f 100644
--- a/scripts/pacman-key.sh.in
+++ b/scripts/pacman-key.sh.in
@@ -469,11 +469,11 @@ OPT_LONG="add::,config:,delete:,edit-key:,export::,finger::,gpgdir:"
OPT_LONG+=",help,import:,import-trustdb:,init,keyserver:,list-keys::,list-sigs::"
OPT_LONG+=",lsign-key:,populate::,recv-keys:,refresh-keys::,updatedb"
OPT_LONG+=",verify:,version"
-if ! parse_options $OPT_SHORT $OPT_LONG "$@"; then
+if ! OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@")"; then
echo; usage; exit 1 # E_INVALID_OPTION;
fi
-set -- "${OPTRET[@]}"
-unset OPT_SHORT OPT_LONG OPTRET
+eval set -- "$OPT_TEMP"
+unset OPT_SHORT OPT_LONG OPT_TEMP
if [[ $1 == "--" ]]; then
usage;