Permalink
Browse files

more coding standard changes

git-svn-id: http://shflags.googlecode.com/svn/trunk/source/1.0@86 9d7cb843-df4f-0410-8a79-4785ae5a3405
  • Loading branch information...
kate.ward@forestent.com
kate.ward@forestent.com committed Nov 15, 2008
1 parent 335171e commit 1d9f5e45d6ebe79a220bbf7b9a34ab52af52d9c8
Showing with 64 additions and 67 deletions.
  1. +64 −67 src/shflags
View
@@ -157,28 +157,33 @@ __FLAGS_TYPE_INTEGER=3
__FLAGS_TYPE_STRING=4
# set the constants readonly
-_flags_constants=`set |awk -F= '/^FLAGS_/ || /^__FLAGS_/ {print $1}'`
-for _flags_const in ${_flags_constants}; do
- if [ -n "${ZSH_VERSION:-}" ]; then
+__flags_constants=`set |awk -F= '/^FLAGS_/ || /^__FLAGS_/ {print $1}'`
+for __flags_const in ${__flags_constants}; do
+ # skip certain flags
+ case ${__flags_const} in
+ FLAGS_PARENT) continue ;;
+ esac
+ # set flag readonly
+ if [ -z "${ZSH_VERSION:-}" ]; then
+ readonly ${__flags_const}
+ else # handle zsh
case ${ZSH_VERSION} in
- [123].*) readonly ${_flags_const} ;;
- *) readonly -g ${_flags_const} ;; # declare readonly constants globally
+ [123].*) readonly ${__flags_const} ;;
+ *) readonly -g ${__flags_const} ;; # declare readonly constants globally
esac
- else
- readonly ${_flags_const}
fi
done
-unset _flags_const _flags_constants
+unset __flags_const __flags_constants
#
# internal variables
#
-__flags_boolNames=' '
-__flags_longNames=' '
-__flags_shortNames=' '
+__flags_boolNames=' ' # space separated list of boolean flag names
+__flags_longNames=' ' # space separated list of long flag names
+__flags_shortNames=' ' # space separated list of short flag names
-__flags_opts=''
+__flags_opts='' # temporary storage for parsed getopt flags
# restore the previous set of shell flags
for __flags_shellFlag in ${__FLAGS_SHELL_FLAGS}; do
@@ -588,7 +593,7 @@ _flags_enhancedGetopt()
flags_return=${FLAGS_TRUE}
_flags_shortOpts_=`_flags_genOptStr ${__FLAGS_OPTSTR_SHORT}`
_flags_boolOpts_=`echo "${__flags_boolNames}" \
- |sed 's/^ *//;s/ *$//;s/ /,/g'`
+ |sed 's/^ *//;s/ *$//;s/ /,/g'`
_flags_longOpts_=`_flags_genOptStr ${__FLAGS_OPTSTR_LONG}`
__flags_opts=`getopt \
@@ -676,8 +681,8 @@ _flags_parseGetopt()
# set new flag value
[ ${_flags_type_} -eq ${__FLAGS_TYPE_NONE} ] && \
- _flags_type_=`_flags_getFlagInfo \
- "${_flags_name_}" ${__FLAGS_INFO_TYPE_STR}`
+ _flags_type_=`_flags_getFlagInfo \
+ "${_flags_name_}" ${__FLAGS_INFO_TYPE_STR}`
case ${_flags_type_} in
${__FLAGS_TYPE_BOOLEAN})
if [ ${_flags_len_} -eq ${__FLAGS_LEN_LONG} ]; then
@@ -847,11 +852,7 @@ flags_getoptInfo()
# bool: true if getopt is the enhanced version
flags_getoptIsEnh()
{
- if [ ${__FLAGS_GETOPT_VERS} -eq ${__FLAGS_GETOPT_VERS_ENH} ]; then
- return ${FLAGS_TRUE}
- else
- return ${FLAGS_FALSE}
- fi
+ test ${__FLAGS_GETOPT_VERS} -eq ${__FLAGS_GETOPT_VERS_ENH}
}
# Returns whether the detected getopt version is the standard version.
@@ -862,11 +863,7 @@ flags_getoptIsEnh()
# bool: true if getopt is the standard version
flags_getoptIsStd()
{
- if [ ${__FLAGS_GETOPT_VERS} -eq ${__FLAGS_GETOPT_VERS_STD} ]; then
- return ${FLAGS_TRUE}
- else
- return ${FLAGS_FALSE}
- fi
+ test ${__FLAGS_GETOPT_VERS} -eq ${__FLAGS_GETOPT_VERS_STD}
}
# This is effectively a 'usage()' function. It prints usage information and
@@ -887,62 +884,62 @@ flags_help()
fi
if [ -n "${__flags_longNames}" ]; then
echo 'flags:' >&2
- for _flags_name in ${__flags_longNames}; do
- _flags_flagStr=''
+ for flags_name_ in ${__flags_longNames}; do
+ flags_flagStr_=''
- _flags_default=`_flags_getFlagInfo \
- "${_flags_name}" ${__FLAGS_INFO_DEFAULT_STR}`
- _flags_help=`_flags_getFlagInfo \
- "${_flags_name}" ${__FLAGS_INFO_HELP_STR}`
- _flags_short=`_flags_getFlagInfo \
- "${_flags_name}" ${__FLAGS_INFO_SHORT_STR}`
- _flags_type=`_flags_getFlagInfo \
- "${_flags_name}" ${__FLAGS_INFO_TYPE_STR}`
+ flags_default_=`_flags_getFlagInfo \
+ "${flags_name_}" ${__FLAGS_INFO_DEFAULT_STR}`
+ flags_help_=`_flags_getFlagInfo \
+ "${flags_name_}" ${__FLAGS_INFO_HELP_STR}`
+ flags_short_=`_flags_getFlagInfo \
+ "${flags_name_}" ${__FLAGS_INFO_SHORT_STR}`
+ flags_type_=`_flags_getFlagInfo \
+ "${flags_name_}" ${__FLAGS_INFO_TYPE_STR}`
- [ "${_flags_short}" != "${__FLAGS_NULL}" ] && \
- _flags_flagStr="${_flags_flagStr}-${_flags_short}"
+ [ "${flags_short_}" != "${__FLAGS_NULL}" ] && \
+ flags_flagStr_="${flags_flagStr_}-${flags_short_}"
if [ ${__FLAGS_GETOPT_VERS} -eq ${__FLAGS_GETOPT_VERS_ENH} ]; then
- [ "${_flags_short}" != "${__FLAGS_NULL}" ] && \
- _flags_flagStr="${_flags_flagStr},"
- if [ ${_flags_type} -eq ${__FLAGS_TYPE_BOOLEAN} ]; then
- _flags_boolStr='[no]'
+ [ "${flags_short_}" != "${__FLAGS_NULL}" ] && \
+ flags_flagStr_="${flags_flagStr_},"
+ if [ ${flags_type_} -eq ${__FLAGS_TYPE_BOOLEAN} ]; then
+ flags_boolStr_='[no]'
else
- _flags_boolStr=''
+ flags_boolStr_=''
fi
- _flags_flagStr="${_flags_flagStr}--${_flags_boolStr}${_flags_name}:"
+ flags_flagStr_="${flags_flagStr_}--${flags_boolStr_}${flags_name_}:"
fi
- case ${_flags_type} in
+ case ${flags_type_} in
${__FLAGS_TYPE_BOOLEAN})
- if [ ${_flags_default} -eq ${FLAGS_TRUE} ]; then
- _flags_defaultStr='true'
+ if [ ${flags_default_} -eq ${FLAGS_TRUE} ]; then
+ flags_defaultStr_='true'
else
- _flags_defaultStr='false'
+ flags_defaultStr_='false'
fi
;;
${__FLAGS_TYPE_FLOAT}|${__FLAGS_TYPE_INTEGER})
- _flags_defaultStr=${_flags_default} ;;
- ${__FLAGS_TYPE_STRING}) _flags_defaultStr="'${_flags_default}'" ;;
+ flags_defaultStr_=${flags_default_} ;;
+ ${__FLAGS_TYPE_STRING}) flags_defaultStr_="'${flags_default_}'" ;;
esac
- _flags_defaultStr="(default: ${_flags_defaultStr})"
+ flags_defaultStr_="(default: ${flags_defaultStr_})"
- _flags_helpStr=" ${_flags_flagStr} ${_flags_help} ${_flags_defaultStr}"
- _flags_helpStrLen=`expr "${_flags_helpStr}" : '.*'`
+ flags_helpStr_=" ${flags_flagStr_} ${flags_help_} ${flags_defaultStr_}"
+ flags_helpStrLen_=`expr "${flags_helpStr_}" : '.*'`
flags_screenCols_=`_flags_screenColumns`
- if [ ${_flags_helpStrLen} -lt ${flags_screenCols_} ]; then
- echo "${_flags_helpStr}" >&2
+ if [ ${flags_helpStrLen_} -lt ${flags_screenCols_} ]; then
+ echo "${flags_helpStr_}" >&2
else
- _flags_emptyStr="`echo ${_flags_flagStr} |sed 's/./ /g'`"
- echo " ${_flags_flagStr} ${_flags_help}" >&2
- echo " ${_flags_emptyStr} ${_flags_defaultStr}" >&2
+ flags_emptyStr_="`echo ${flags_flagStr_} |sed 's/./ /g'`"
+ echo " ${flags_flagStr_} ${flags_help_}" >&2
+ echo " ${flags_emptyStr_} ${flags_defaultStr_}" >&2
fi
done
fi
- unset _flags_boolStr _flags_default _flags_defaultStr _flags_emptyStr \
- _flags_flagStr _flags_help _flags_helpStr _flags_helpStrLen _flags_name \
- _flags_short _flags_type
+ unset flags_boolStr_ flags_default_ flags_defaultStr_ flags_emptyStr_ \
+ flags_flagStr_ flags_help_ flags_helpStr flags_helpStrLen flags_name_ \
+ flags_short_ flags_type_
return ${FLAGS_TRUE}
}
@@ -954,23 +951,23 @@ flags_help()
# nothing
flags_reset()
{
- for _flags_name in ${__flags_longNames}; do
- _flags_strToEval="unset FLAGS_${_flags_name}"
- for _flags_type in \
+ for flags_name_ in ${__flags_longNames}; do
+ flags_strToEval_="unset FLAGS_${flags_name_}"
+ for flags_type_ in \
${__FLAGS_INFO_HELP_STR} \
${__FLAGS_INFO_SHORT_STR} \
${__FLAGS_INFO_TYPE_STR}
do
- _flags_strToEval=\
-"${_flags_strToEval} __flags_${_flags_name}_${_flags_type}"
+ flags_strToEval_=\
+"${flags_strToEval_} __flags_${flags_name_}_${flags_type_}"
done
- eval ${_flags_strToEval}
+ eval ${flags_strToEval_}
done
# reset internal variables
__flags_boolNames=' '
__flags_longNames=' '
__flags_shortNames=' '
- unset _flags_name _flags_type _flags_strToEval
+ unset flags_name_ flags_type_ flags_strToEval_
}

0 comments on commit 1d9f5e4

Please sign in to comment.