gsu: Change semantics of gsu_check_arg_count().
authorAndre Noll <maan@systemlinux.org>
Sun, 18 Jul 2010 13:30:18 +0000 (15:30 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Fri, 29 Aug 2014 19:36:08 +0000 (21:36 +0200)
It's kind of ugly having to specify an artificial upper bound on the arg count
if the allowed number of arguments is unlimited.

funcs/gsu

index 8cfa4de..b409bc5 100644 (file)
--- a/funcs/gsu
+++ b/funcs/gsu
@@ -45,17 +45,25 @@ gsu_is_a_number()
 }
 export -f gsu_is_a_number
 
 }
 export -f gsu_is_a_number
 
+# Check number of arguments.
+#
 # Usage: gsu_check_arg_count <num_given> <num1> [<num2>]
 #
 # Usage: gsu_check_arg_count <num_given> <num1> [<num2>]
 #
-# If only <num1> ist given, then <num_given> must equal <num1>.
-# Otherwise, <num1>..<num2> is treated as a range and it is checked
-# that <num_given> lies between <num1> and <num2> inclusively.
+# Check that <num_given> is between <num1> and <num2> inclusively.
+# If only <num1> ist given, num2 is assumed to be infinity.
+#
+# Examples:
+#      0 0 no argument allowed
+#      1 1 exactly one argument required
+#      0 2 at most two arguments admissible
+#      2   at least two arguments reqired
+#
 gsu_check_arg_count()
 {
        ret=-$E_GSU_BAD_ARG_COUNT
        if [[ $# -eq 2 ]]; then # only num1 is given
 gsu_check_arg_count()
 {
        ret=-$E_GSU_BAD_ARG_COUNT
        if [[ $# -eq 2 ]]; then # only num1 is given
-               result="exactly $2 args needed, $1 given"
-               [[ $1 -ne $2 ]] && return
+               result="at least $2 args required, $1 given"
+               [[ $1 -lt $2 ]] && return
                ret=$GSU_SUCCESS
                return
        fi
                ret=$GSU_SUCCESS
                return
        fi