summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2008-12-22 21:28:35 +1000
committerDan McGee <dan@archlinux.org>2009-01-02 22:17:24 -0600
commit08980fb4bcf4078b4b22b2c1f6f36cbbdee89ec4 (patch)
tree76062201484e5d99fec22e46c5f6b178ef345dfb
parentcc7f3b705e1c3a1fdc356942134456559ce69230 (diff)
downloadpacman-08980fb4bcf4078b4b22b2c1f6f36cbbdee89ec4.tar.xz
makepkg: Replace getopt with internal function
This will allow makepkg to work on systems like Mac OS X where the default getopt is too old to properly handle long options. The new parse_options function should replicate getopt's behaviour completely. Original work: Yun Zheng Hu <yunzheng.hu@gmail.com> [Allan: Rewrite and bug fixes] Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--scripts/makepkg.sh.in91
1 files changed, 89 insertions, 2 deletions
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index ef2ede1f..8a6dcb2f 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -1101,6 +1101,93 @@ devel_update() {
fi
}
+# getopt like parser
+parse_options() {
+ local short_options=$1; shift;
+ local long_options=$1; shift;
+ local ret=0;
+ local unused_options=""
+
+ 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
+ if [ ${1:2} = $match ]; then
+ printf ' %s' "$1"
+ else
+ if [ -n "$2" ]; then
+ printf ' %s' "$1"
+ shift
+ printf " '%s'" "$1"
+ else
+ echo "makepkg: option '$1' $(gettext "requires an argument")" >&2
+ ret=1
+ fi
+ fi
+ else
+ echo "makepkg: $(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
+ if [[ "$short_options" =~ "${1:i:1}:" ]]; then
+ if [ -n "${1:$i+1}" ]; then
+ printf ' -%s' "${1:i:1}"
+ printf " '%s'" "${1:$i+1}"
+ else
+ if [ -n "$2" ]; then
+ printf ' -%s' "${1:i:1}"
+ shift
+ printf " '%s'" "${1}"
+ else
+ echo "makepkg: option $(gettext "requires an argument") -- '${1:i:1}'" >&2
+ ret=1
+ fi
+ fi
+ break
+ else
+ printf ' -%s' "${1:i:1}"
+ fi
+ else
+ echo "makepkg: $(gettext "invalid option") -- '${1:i:1}'" >&2
+ ret=1
+ fi
+ done
+ else
+ unused_options="${unused_options} '$1'"
+ fi
+ shift
+ done
+
+ printf " --"
+ if [ -n "$unused_options" ]; then
+ for i in ${unused_options[@]}; do
+ printf ' %s' "$i"
+ done
+ fi
+ if [ -n "$1" ]; then
+ while [ -n "$1" ]; do
+ printf " '%s'" "${1}"
+ shift
+ done
+ fi
+ printf "\n"
+
+ return $ret
+}
+
usage() {
printf "makepkg (pacman) %s\n" "$myver"
echo
@@ -1189,8 +1276,8 @@ OPT_LONG="$OPT_LONG,install,log,nocolor,nobuild,rmdeps,repackage,source"
OPT_LONG="$OPT_LONG,syncdeps,version"
# Pacman Options
OPT_LONG="$OPT_LONG,noconfirm,noprogressbar"
-OPT_TEMP="$(getopt -o "$OPT_SHORT" -l "$OPT_LONG" -n "$(basename "$0")" -- "$@" || echo 'GETOPT GO BANG!')"
-if echo "$OPT_TEMP" | grep -q 'GETOPT GO BANG!'; then
+OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@" || echo 'PARSE_OPTIONS FAILED')"
+if echo "$OPT_TEMP" | grep -q 'PARSE_OPTIONS FAILED'; then
# This is a small hack to stop the script bailing with 'set -e'
echo; usage; exit 1 # E_INVALID_OPTION;
fi