exit $not_implemented_exit_code
}
-# Don't set $POSIXLY_CORRECT here.
-_temp=$(getopt -n "$prog" -o "Xvhn:" -l help -- "$@") || \
- usage
-
-eval set -- "$_temp"
-
verbose=false
machine_readable=false
nodespec=""
-args="$*"
+args=""
+
+# Options and command argument can appear in any order, so when
+# getopts thinks it is done, process any non-option arguments and go
+# around again.
+while [ $# -gt 0 ] ; do
+ while getopts "Xvhn:?" opt ; do
+ case "$opt" in
+ X) machine_readable=true ;;
+ v) verbose=true ;;
+ n) nodespec="$OPTARG" ;;
+ \?|*) usage ;;
+ esac
+ done
+ shift $((OPTIND - 1))
-while true ; do
- case "$1" in
- -X) machine_readable=true ; shift ;;
- -v) verbose=true ; shift ;;
- -n) nodespec="$2" ; shift 2 ;;
- --) shift ; break ;;
- -h|--help|*) usage ;; # * shouldn't happen, so this is reasonable.
- esac
+ # Anything left over must be a non-option arg
+ if [ $# -gt 0 ] ; then
+ args="${args}${args:+ }${1}"
+ shift
+ fi
done
-[ $# -ge 1 ] || usage
+[ -n "$args" ] || usage
+set -- $args
setup_tickles ()
{
parse_options ()
{
- _temp=$(getopt -n "$prog" -o "T:h" -- "$@")
+ while getopts "T:h?" opt ; do
+ case "$opt" in
+ T) netid="$OPTARG" ;;
+ \?|h) usage ;;
+ esac
+ done
+ shift $((OPTIND - 1))
- [ $? != 0 ] && usage
+ [ "$netid" = "tcp" ] || usage
- eval set -- "$_temp"
+ host="$1" ; shift
+ [ "$host" = "localhost" -o "$host" = "127.0.0.1" ] || usage
- while true ; do
- case "$1" in
- -T) netid="$2"; shift 2 ;;
- --) shift ; break ;;
- -h|*) usage ;; # * shouldn't happen, so this is reasonable.
- esac
- done
+ [ 1 -le $# -a $# -le 2 ] || usage
- [ "$netid" = "tcp" ] || usage
-
- host="$1" ; shift
- [ "$host" = "localhost" -o "$host" = "127.0.0.1" ] || usage
-
- [ 1 -le $# -a $# -le 2 ] || usage
-
- p="$1"
- v="$2"
+ p="$1"
+ v="$2"
}
parse_options "$@"
exit 1
}
-temp=$(getopt -n "smnotify" -o "h" -l client:,ip:,server:,stateval: -- "$@")
-if [ $? != 0 ] ; then
- usage
-fi
-
-eval set -- "$temp"
-
cip=""
sip=""
mon_name=""
state=""
-while : ; do
+while [ $# -gt 0 ] ; do
case "$1" in
--client) cip="$2" ; shift 2 ;;
+ --client=*) cip="${1#*=}" ; shift ;;
--ip) sip="$2" ; shift 2 ;;
+ --ip=*) sip="${1#*=}" ; shift ;;
--server) mon_name="$2" ; shift 2 ;;
+ --server=*) mon_name="${1#*=}" ; shift ;;
--stateval) state="$2" ; shift 2 ;;
+ --stateval=*) state="${1#*=}" ; shift ;;
--) shift ; break ;;
- *) usage ;;
+ -*) usage ;;
+ *) break ;;
esac
done
+[ $# -eq 0 ] || usage
if [ -z "$cip" -o -z "$sip" -o -z "$mon_name" -o -z "$state" ] ; then
usage
header=true
orig="$*"
-temp=$(getopt -n "$prog" -o "txnalHh" -l tcp -l unix -l help -- "$@")
-[ $? -eq 0 ] || usage
-
-eval set -- "$temp"
-
-while true ; do
- case "$1" in
- --tcp|-t) tcp=true ; shift ;;
- --unix|-x) unix=true ; shift ;;
- -l) listen=true ; shift ;;
- -a) all=true ; shift ;;
- -H) header=false ; shift ;;
- -n) shift ;;
- --) shift ; break ;;
- -h|--help|*) usage ;;
+
+while getopts "txnalHh?" opt ; do
+ case "$opt" in
+ t) tcp=true ;;
+ x) unix=true ;;
+ l) listen=true ;;
+ a) all=true ;;
+ H) header=false ;;
+ n) : ;;
+ \?|h) usage ;;
esac
done
+shift $((OPTIND - 1))
$tcp || $unix || not_supported "$*"