--- gettext.sh.in.orig 2005-05-20 22:14:33.000000000 +0200 +++ gettext.sh.in 2005-12-14 18:30:42.351549936 +0100 @@ -39,40 +39,63 @@ # $PREFIX/share/sh-scripts or $PREFIX/share/gettext. In order to not violate # the Filesystem Hierarchy Standard when doing so, this script is executable. # Therefore it needs to support the standard --help and --version. -case "$0" in - gettext.sh | */gettext.sh | *\gettext.sh) - progname=$0 - address@hidden@ - address@hidden@ - # func_usage - # outputs to stdout the --help usage message. - func_usage () - { - echo "GNU gettext shell script function library version $version" - echo "Usage: . gettext.sh" - } - # func_version - # outputs to stdout the --version message. - func_version () - { - echo "$progname (GNU $package) $version" - echo "Copyright (C) 2003-2005 Free Software Foundation, Inc. +# +# To detect if the script has been called directly we define a test function. +# We do it this way to be able to source the script from zsh, as this shell +# replaces the $0 variable for sourced scripts and functions by default (this +# behaviour is controlled using the option FUNCTION_ARGZERO); by using a +# function we are sure that if FUNCTION_ARGZERO is set, $0 never takes the +# program name, while the program works as expected when $0 is not replaced. +# Note that using this method if we execute the script using zsh with the +# default options we will not see the --help or --version messages, but that +# is not important, as the executable script is run using '/bin/sh' and we get +# the desired efect when it is called directly. + +gettext_sh_fhs_test() +{ + # gettext_sh_usage + # outputs to stdout the --help usage message. + gettext_sh_usage () + { + echo "GNU gettext shell script function library version $version" + echo "Usage: . gettext.sh" + } + # gettext_sh_version + # outputs to stdout the --version message. + gettext_sh_version () + { + echo "$progname (GNU $package) $version" + echo "Copyright (C) 2003-2005 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." - echo "Written by" "Bruno Haible" - } - if test $# = 1; then - case "$1" in - --help | --hel | --he | --h ) - func_usage; exit 0 ;; - --version | --versio | --versi | --vers | --ver | --ve | --v ) - func_version; exit 0 ;; - esac - fi - func_usage 1>&2 - exit 1 + echo "Written by" "Bruno Haible" + } + case "$0" in + gettext.sh | */gettext.sh | *\gettext.sh) + progname=$0 + address@hidden@ + address@hidden@ + if test $# = 1; then + case "$1" in + --help | --hel | --he | --h ) + gettext_sh_usage; exit 0 ;; + --version | --versio | --versi | --vers | --ver | --ve | --v ) + gettext_sh_version; exit 0 ;; + esac + fi + gettext_sh_usage 1>&2 + exit 1 ;; -esac + esac + # Remove auxiliary functions + unset -f gettext_sh_usage + unset -f gettext_sh_version +} + +# Test if we have been called as a script +gettext_sh_fhs_test $@ +# Remove the test function, it is no longer needed +unset -f gettext_sh_fhs_test # eval_gettext MSGID # looks up the translation of MSGID and substitutes shell variables in the