aboutsummaryrefslogtreecommitdiff
path: root/source/1.0/src/shflags
diff options
context:
space:
mode:
authorkate.ward <kate.ward@forestent.com>2009-04-01 14:09:23 +0000
committerkate.ward <kate.ward@forestent.com>2009-04-01 14:09:23 +0000
commit39913d13e3ffb8bacd009155c0f51241dde3659b (patch)
treefff65fb0160e04844de5f679c2f2e4deaad590f7 /source/1.0/src/shflags
parentccb66b4f8bc5a592ace60035a7a5e409b4729d71 (diff)
downloadshflags-39913d13e3ffb8bacd009155c0f51241dde3659b.tar.gz
added check to prevent overriding reserved flags constants
Diffstat (limited to 'source/1.0/src/shflags')
-rw-r--r--source/1.0/src/shflags14
1 files changed, 13 insertions, 1 deletions
diff --git a/source/1.0/src/shflags b/source/1.0/src/shflags
index eff46f6..6546be3 100644
--- a/source/1.0/src/shflags
+++ b/source/1.0/src/shflags
@@ -33,7 +33,7 @@
#
# SPECIAL FLAGS: There are a few flags that have special meaning:
# --help (or -?) prints a list of all the flags in a human-readable fashion
-# --flagfile=foo read flags from foo.
+# --flagfile=foo read flags from foo. (not implemented yet)
# -- as in getopt(), terminates flag-processing
#
# EXAMPLE USAGE:
@@ -80,10 +80,14 @@
[ -n "${FLAGS_VERSION:-}" ] && return 0
FLAGS_VERSION='1.0.3pre'
+# return values
FLAGS_TRUE=0
FLAGS_FALSE=1
FLAGS_ERROR=2
+# reserved flag names
+FLAGS_RESERVED='ARGC ARGV ERROR FALSE HELP PARENT RESERVED TRUE VERSION'
+
_flags_debug() { echo "flags:DEBUG $@" >&2; }
_flags_warn() { echo "flags:WARN $@" >&2; }
_flags_error() { echo "flags:ERROR $@" >&2; }
@@ -157,6 +161,7 @@ __flags_constants=`set |awk -F= '/^FLAGS_/ || /^__FLAGS_/ {print $1}'`
for __flags_const in ${__flags_constants}; do
# skip certain flags
case ${__flags_const} in
+ FLAGS_HELP) continue ;;
FLAGS_PARENT) continue ;;
esac
# set flag readonly
@@ -223,6 +228,13 @@ _flags_define()
# TODO(kward): check for validity of the flag name (e.g. dashes)
+ # check whether the flag name is reserved
+ echo " ${FLAGS_RESERVED} " |grep " ${_flags_name_} " >/dev/null
+ if [ $? -eq 0 ]; then
+ flags_error="flag name (${_flags_name_}) is reserved"
+ _flags_return_=${FLAGS_ERROR}
+ fi
+
# require short option for getopt that don't support long options
if [ ${_flags_return_} -eq ${FLAGS_TRUE} \
-a ${__FLAGS_GETOPT_VERS} -ne ${__FLAGS_GETOPT_VERS_ENH} \