From 40a4bd93aacafca2a6284c3bd493bcfa8eac7aef Mon Sep 17 00:00:00 2001 From: Olav Vitters Date: Tue, 4 Aug 2020 10:07:35 +0200 Subject: etc/rc.d/init.d/functions: prevent gprintf from showing an "shift" error message meanwhile, cleanup tabs and spaces --- etc/rc.d/init.d/functions | 59 +++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/etc/rc.d/init.d/functions b/etc/rc.d/init.d/functions index 2ce76120..cc2f2c26 100755 --- a/etc/rc.d/init.d/functions +++ b/etc/rc.d/init.d/functions @@ -109,20 +109,20 @@ if [ -z "${BOOTUP:-}" ]; then fi gprintf() { - if [ -x /bin/gettext -a -n "$1" ]; then - if [ -n "$GP_LANG" ]; then - local TEXT=`LC_ALL=$GP_LANG LANGUAGE=$GP_LANGUAGE gettext -e --domain=$TEXTDOMAIN -- "$1"` - else - local TEXT=`gettext -e --domain=$TEXTDOMAIN -- "$1"` - fi - else - local TEXT=$1 - fi - [ "${1#*\\n}" ] || TEXT="$TEXT\n" - - shift - printf -- "$TEXT" "$@" -} + if [ -x /bin/gettext ] && [ -n "$1" ]; then + if [ -n "$GP_LANG" ]; then + local TEXT=$(LC_ALL=$GP_LANG LANGUAGE=$GP_LANGUAGE gettext -e --domain=$TEXTDOMAIN -- "$1") + else + local TEXT=$(gettext -e --domain=$TEXTDOMAIN -- "$1") + fi + else + local TEXT=$1 + fi + [ "${1#*\\n}" ] || TEXT="$TEXT\n" + + shift + printf -- "$TEXT" "$@" +} # Frontend to gprintf (support up to 4 %s in format string) # returns the message transleted in GPRINTF_MSG and @@ -130,24 +130,29 @@ gprintf() { # This simplifies a lot the call of functions like action, # now with i18n support gprintf_msg_rest() { -case "$1" in + GPRINTF_REST="" + return + fi + case "$1" in *%s*%s*%s*%s*) - GPRINTF_MSG=$(gprintf "$1" "$2" "$3" "$4" "$5") - shift 5;; + GPRINTF_MSG=$(gprintf "$1" "$2" "$3" "$4" "$5") + shift 5;; *%s*%s*%s*) - GPRINTF_MSG=$(gprintf "$1" "$2" "$3" "$4") - shift 4;; + GPRINTF_MSG=$(gprintf "$1" "$2" "$3" "$4") + shift 4;; *%s*%s*) - GPRINTF_MSG=$(gprintf "$1" "$2" "$3") - shift 3;; + GPRINTF_MSG=$(gprintf "$1" "$2" "$3") + shift 3;; *%s*) - GPRINTF_MSG=$(gprintf "$1" "$2") - shift 2;; + GPRINTF_MSG=$(gprintf "$1" "$2") + shift 2;; *) - GPRINTF_MSG=$(gprintf "$1") - shift;; -esac -GPRINTF_REST="$@" + GPRINTF_MSG=$(gprintf "$1") + # function may be called without any arguments, e.g. for 'success' + [ $# -ne 0 ] && shift + ;; + esac + GPRINTF_REST="$@" } # Check if $pid (could be plural) are running with -- cgit v1.2.1