[pacman-dev] [PATCH 5/8] scripts/library: remove parse_options

Dave Reisner dreisner at archlinux.org
Thu Apr 12 10:54:35 EDT 2012


This is retired, as the two consumers of this function are now using the
new parseopts instead.

Signed-off-by: Dave Reisner <dreisner at archlinux.org>
---
 scripts/Makefile.am              |    3 +-
 scripts/library/README           |    6 ---
 scripts/library/parse_options.sh |  105 --------------------------------------
 scripts/po/POTFILES.in           |    1 -
 4 files changed, 1 insertion(+), 114 deletions(-)
 delete mode 100644 scripts/library/parse_options.sh

diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index fc70732..b8a1990 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -27,8 +27,7 @@ EXTRA_DIST = \
 
 LIBRARY = \
 	library/output_format.sh \
-	library/parseopts.sh \
-	library/parse_options.sh
+	library/parseopts.sh
 
 # Files that should be removed, but which Automake does not know.
 MOSTLYCLEANFILES = $(bin_SCRIPTS)
diff --git a/scripts/library/README b/scripts/library/README
index 33f6321..53a0b2e 100644
--- a/scripts/library/README
+++ b/scripts/library/README
@@ -8,12 +8,6 @@ and can be silenced by defining 'QUIET'.  The 'warning' and 'error'
 functions print to stderr with the appropriate prefix added to the
 message.
 
-parse_options.sh:
-A getopt replacement to avoids portability issues, in particular the
-lack of long option name support in the default getopt provided by some
-platforms.
-Usage: parse_option $SHORT_OPTS $LONG_OPTS "$@"
-
 parseopts.sh:
 A getopt_long-like parser which portably supports longopts and shortopts
 with some GNU extensions. It does not allow for options with optional
diff --git a/scripts/library/parse_options.sh b/scripts/library/parse_options.sh
deleted file mode 100644
index 039eef9..0000000
--- 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
-}
diff --git a/scripts/po/POTFILES.in b/scripts/po/POTFILES.in
index 01cc235..162731b 100644
--- a/scripts/po/POTFILES.in
+++ b/scripts/po/POTFILES.in
@@ -8,5 +8,4 @@ scripts/pacman-optimize.sh.in
 scripts/pkgdelta.sh.in
 scripts/repo-add.sh.in
 scripts/library/output_format.sh
-scripts/library/parse_options.sh
 scripts/library/parseopts.sh
-- 
1.7.10



More information about the pacman-dev mailing list