This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH v2b 2/2][BZ #13853] Replace Bash-only $"msgid" with gettextf


This patch isn't really as major as the diffstat and proposed change log
entries make it seem.  It rather simply defines _gettext and gettextf
and replaces $"msgid" quoting, e.g.:

    s/printf \$"/gettextf "/; s/printf >&2 \$"/gettextf >&2 "/;


2012-11-25  P. J. McDermott  <pjm@nac.net>

	* debug/xtrace.sh (_gettext): New wrapper function that calls gettext if
	installed.
	* elf/ldd.bash.in (_gettext): Likewise.
	* elf/sotruss.ksh (_gettext): Likewise.
	* malloc/memusage.sh (_gettext): Likewise.

	* debug/xtrace.sh (gettextf): New function that writes translated and
	formatted output by calling _gettext and printf.
	* elf/ldd.bash.in (gettextf): Likewise.
	* elf/sotruss.ksh (gettextf): Likewise.
	* malloc/memusage.sh (gettextf): Likewise.

	* debug/xtrace.sh: Replace insecure and Bash-only $"msgid" quoting with
	calls to gettextf.
	* elf/ldd.bash.in: Likewise.
	* elf/sotruss.ksh: Likewise.
	* malloc/memusage.sh: Likewise.
---
 debug/xtrace.sh    |   44 +++++++++++++++++++++++++++++-------------
 elf/ldd.bash.in    |   54 ++++++++++++++++++++++++++++++++++------------------
 elf/sotruss.ksh    |   48 ++++++++++++++++++++++++++++++----------------
 malloc/memusage.sh |   40 +++++++++++++++++++++++++++-----------
 4 files changed, 127 insertions(+), 59 deletions(-)

diff --git a/debug/xtrace.sh b/debug/xtrace.sh
index 943d0f8..5ce11bf 100755
--- a/debug/xtrace.sh
+++ b/debug/xtrace.sh
@@ -19,32 +19,50 @@
 
 pcprofileso='@SLIBDIR@/libpcprofile.so'
 pcprofiledump='@BINDIR@/pcprofiledump'
-TEXTDOMAIN=libc
 script="xtrace"
 year="2012"
 
+if TEXTDOMAIN=libc gettext '' >/dev/null 2>&1; then
+  _gettext ()
+  {
+    TEXTDOMAIN=libc gettext "$1"
+  }
+else
+  _gettext ()
+  {
+    printf '%s' "$1"
+  }
+fi
+
+gettextf ()
+{
+  msg="$(_gettext "$1"; printf 'x')"
+  shift
+  printf "${msg%x}" "$@"
+}
+
 # Print usage message.
 do_usage() {
-  printf $"Usage: xtrace [OPTION]... PROGRAM [PROGRAMOPTION]...\n"
+  gettextf "Usage: xtrace [OPTION]... PROGRAM [PROGRAMOPTION]...\n"
   exit 0
 }
 
 # Refer to --help option.
 help_info() {
-  printf >&2 $"Try \`%s --help' or \`%s --usage' for more information.\n" "$script" "$script"
+  gettextf >&2 "Try \`%s --help' or \`%s --usage' for more information.\n" "$script" "$script"
   exit 1
 }
 
 # Message for missing argument.
 do_missing_arg() {
-  printf >&2 $"%s: option '%s' requires an argument.\n" "$script" "$1"
+  gettextf >&2 "%s: option '%s' requires an argument.\n" "$script" "$1"
   help_info
 }
 
 # Print help message
 do_help() {
-  printf $"Usage: xtrace [OPTION]... PROGRAM [PROGRAMOPTION]...\n"
-  printf $"Trace execution of program by printing currently executed function.
+  gettextf "Usage: xtrace [OPTION]... PROGRAM [PROGRAMOPTION]...\n"
+  gettextf "Trace execution of program by printing currently executed function.
 
      --data=FILE          Don't run the program, just print the data from FILE.
 
@@ -56,18 +74,18 @@ Mandatory arguments to long options are also mandatory for any corresponding
 short options.
 
 "
-  printf $"For bug reporting instructions, please see:\\n%s.\\n" \
+  gettextf "For bug reporting instructions, please see:\\n%s.\\n" \
     "@REPORT_BUGS_TO@"
   exit 0
 }
 
 do_version() {
   echo 'xtrace @PKGVERSION@@VERSION@'
-  printf $"Copyright (C) %s Free Software Foundation, Inc.
+  gettextf "Copyright (C) %s 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.
 " "$year"
-  printf $"Written by %s.
+  gettextf "Written by %s.
 " "Ulrich Drepper"
   exit 0
 }
@@ -124,7 +142,7 @@ while test $# -gt 0; do
     break
     ;;
   --*)
-    printf >&2 $"%s: unrecognized option \`%s'\n" "$script" "$1"
+    gettextf >&2 "%s: unrecognized option \`%s'\n" "$script" "$1"
     help_info
     ;;
   *)
@@ -137,7 +155,7 @@ done
 
 # See whether any arguments are left.
 if test $# -eq 0; then
-  printf >&2 $"No program name given\n"
+  gettextf >&2 "No program name given\n"
   help_info
 fi
 
@@ -145,11 +163,11 @@ fi
 program=$1
 shift
 if test ! -f "$program"; then
-  printf >&2 $"executable \`%s' not found\n" "$program"
+  gettextf >&2 "executable \`%s' not found\n" "$program"
   help_info
 fi
 if test ! -x "$program"; then
-  printf >&2 $"\`%s' is no executable\n" "$program"
+  gettextf >&2 "\`%s' is no executable\n" "$program"
   help_info
 fi
 
diff --git a/elf/ldd.bash.in b/elf/ldd.bash.in
index 5e5a626..9140337 100644
--- a/elf/ldd.bash.in
+++ b/elf/ldd.bash.in
@@ -22,10 +22,6 @@
 # run-time dynamic linker as a command and setting the environment
 # variable LD_TRACE_LOADED_OBJECTS to a non-empty value.
 
-# We should be able to find the translation right at the beginning.
-TEXTDOMAIN=libc
-TEXTDOMAINDIR=@TEXTDOMAINDIR@
-
 RTLDLIST=@RTLD@
 warn=
 bind_now=
@@ -33,20 +29,40 @@ verbose=
 script="ldd"
 year="2012"
 
+if TEXTDOMAIN=libc TEXTDOMAINDIR=@TEXTDOMAINDIR@ gettext '' >/dev/null 2>&1
+then
+  _gettext ()
+  {
+    TEXTDOMAIN=libc TEXTDOMAINDIR=@TEXTDOMAINDIR@ gettext "$1"
+  }
+else
+  _gettext ()
+  {
+    printf '%s' "$1"
+  }
+fi
+
+gettextf ()
+{
+  msg="$(_gettext "$1"; printf 'x')"
+  shift
+  printf "${msg%x}" "$@"
+}
+
 while test $# -gt 0; do
   case "$1" in
   --vers | --versi | --versio | --version)
     echo 'ldd @PKGVERSION@@VERSION@'
-    printf $"Copyright (C) %s Free Software Foundation, Inc.
+    gettextf "Copyright (C) %s 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.
 " "$year"
-    printf $"Written by %s and %s.
+    gettextf "Written by %s and %s.
 " "Roland McGrath" "Ulrich Drepper"
     exit 0
     ;;
   --h | --he | --hel | --help)
-    printf $"Usage: ldd [OPTION]... FILE...
+    gettextf "Usage: ldd [OPTION]... FILE...
       --help              print this help and exit
       --version           print version information and exit
   -d, --data-relocs       process data relocations
@@ -55,7 +71,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   -v, --verbose           print all information
 
 "
-    printf $"For bug reporting instructions, please see:\\n%s.\\n" \
+    gettextf "For bug reporting instructions, please see:\\n%s.\\n" \
       "@REPORT_BUGS_TO@"
     exit 0
     ;;
@@ -80,15 +96,15 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     shift
     ;;
   --v | --ve | --ver)
-    printf >&2 $"%s: option \`%s' is ambiguous\n" "$script" "$1"
+    gettextf >&2 "%s: option \`%s' is ambiguous\n" "$script" "$1"
     exit 1
     ;;
   --)		# Stop option processing.
     shift; break
     ;;
   -*)
-    printf >&2 $"%s: unrecognized option \`%s'\n" "$script" "$1"
-    printf >&2 $"Try \`%s --help' for more information.\n" "$script"
+    gettextf >&2 "%s: unrecognized option \`%s'\n" "$script" "$1"
+    gettextf >&2 "Try \`%s --help' for more information.\n" "$script"
     exit 1
     ;;
   *)
@@ -125,8 +141,8 @@ fi
 
 case $# in
 0)
-  printf >&2 $"%s: missing file arguments\n" "$script"
-  printf >&2 $"Try \`%s --help' for more information.\n" "$script"
+  gettextf >&2 "%s: missing file arguments\n" "$script"
+  gettextf >&2 "Try \`%s --help' for more information.\n" "$script"
   exit 1
   ;;
 1)
@@ -148,13 +164,13 @@ for file do
      ;;
   esac
   if test ! -e "$file"; then
-    printf $"%s: %s: No such file or directory\n" "$script" "$file" >&2
+    gettextf "%s: %s: No such file or directory\n" "$script" "$file" >&2
     result=1
   elif test ! -f "$file"; then
-    printf $"%s: %s: not regular file\n" "$script" "$file" >&2
+    gettextf "%s: %s: not regular file\n" "$script" "$file" >&2
     result=1
   elif test -r "$file"; then
-    test -x "$file" || printf $"%s: \
+    test -x "$file" || gettextf "%s: \
 warning: you do not have execution permission for \`%s'\n" "$script" "$file" >&2
     RTLD=
     ret=1
@@ -183,7 +199,7 @@ warning: you do not have execution permission for \`%s'\n" "$script" "$file" >&2
     1)
       # This can be a non-ELF binary or no binary at all.
       nonelf "$file" || {
-	printf $"	not a dynamic executable\n"
+	gettextf "	not a dynamic executable\n"
 	result=1
       }
       ;;
@@ -191,12 +207,12 @@ warning: you do not have execution permission for \`%s'\n" "$script" "$file" >&2
       try_trace "$RTLD" "$file" || result=1
       ;;
     *)
-      printf $"%s: %s exited with unknown exit code (%d)\n" "$script" "$RTLD" $ret >&2
+      gettextf "%s: %s exited with unknown exit code (%d)\n" "$script" "$RTLD" $ret >&2
       exit 1
       ;;
     esac
   else
-    printf $"%s: error: you do not have read permission for \`%s'\n" "$script" "$file" >&2
+    gettextf "%s: error: you do not have read permission for \`%s'\n" "$script" "$file" >&2
     result=1
   fi
 done
diff --git a/elf/sotruss.ksh b/elf/sotruss.ksh
index afbecbd..f7142d3 100755
--- a/elf/sotruss.ksh
+++ b/elf/sotruss.ksh
@@ -16,10 +16,6 @@
 # License along with the GNU C Library; if not, see
 # <http://www.gnu.org/licenses/>.
 
-# We should be able to find the translation right at the beginning.
-TEXTDOMAIN=libc
-TEXTDOMAINDIR=@TEXTDOMAINDIR@
-
 unset SOTRUSS_FROMLIST
 unset SOTRUSS_TOLIST
 unset SOTRUSS_OUTNAME
@@ -30,8 +26,28 @@ lib='@PREFIX@/$LIB/audit/sotruss-lib.so'
 script="sotruss"
 year="2012"
 
+if TEXTDOMAIN=libc TEXTDOMAINDIR=@TEXTDOMAINDIR@ gettext '' >/dev/null 2>&1
+then
+  _gettext ()
+  {
+    TEXTDOMAIN=libc TEXTDOMAINDIR=@TEXTDOMAINDIR@ gettext "$1"
+  }
+else
+  _gettext ()
+  {
+    printf '%s' "$1"
+  }
+fi
+
+gettextf ()
+{
+  msg="$(_gettext "$1"; printf 'x')"
+  shift
+  printf "${msg%x}" "$@"
+}
+
 function do_help {
-  printf $"Usage: sotruss [OPTION...] [--] EXECUTABLE [EXECUTABLE-OPTION...]
+  gettextf "Usage: sotruss [OPTION...] [--] EXECUTABLE [EXECUTABLE-OPTION...]
   -F, --from FROMLIST     Trace calls from objects on FROMLIST
   -T, --to TOLIST         Trace calls to objects on TOLIST
 
@@ -46,28 +62,28 @@ function do_help {
 
 "
 
-  printf $"Mandatory arguments to long options are also mandatory for any corresponding\nshort options.\n"
+  gettextf "Mandatory arguments to long options are also mandatory for any corresponding\nshort options.\n"
   echo
 
-  printf $"For bug reporting instructions, please see:\\n%s.\\n" \
+  gettextf "For bug reporting instructions, please see:\\n%s.\\n" \
     "@REPORT_BUGS_TO@"
   exit 0
 }
 
 function do_missing_arg {
-  printf >&2 $"%s: option requires an argument -- '%s'\n" "$script" "$1"
-  printf >&2 $"Try \`%s --help' or \`%s --usage' for more information.\n" "$script" "$script"
+  gettextf >&2 "%s: option requires an argument -- '%s'\n" "$script" "$1"
+  gettextf >&2 "Try \`%s --help' or \`%s --usage' for more information.\n" "$script" "$script"
   exit 1
 }
 
 function do_ambiguous {
-  printf >&2 $"%s: option is ambiguous; possibilities:"
+  gettextf >&2 "%s: option is ambiguous; possibilities:"
   while test $# -gt 0; do
     printf >&2 " '%s'" $1
     shift
   done
   printf >&2 "\n"
-  printf >&2 $"Try \`%s --help' or \`%s --usage' for more information.\n" "$script" "$script"
+  gettextf >&2 "Try \`%s --help' or \`%s --usage' for more information.\n" "$script" "$script"
   exit 1
 }
 
@@ -75,18 +91,18 @@ while test $# -gt 0; do
   case "$1" in
   --v | --ve | --ver | --vers | --versi | --versio | --version)
     echo "sotruss @PKGVERSION@@VERSION@"
-    printf $"Copyright (C) %s Free Software Foundation, Inc.
+    gettextf "Copyright (C) %s 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.
 " "$year"
-    printf $"Written by %s.\n" "Ulrich Drepper"
+    gettextf "Written by %s.\n" "Ulrich Drepper"
     exit 0
     ;;
   -\? | --h | --he | --hel | --help)
     do_help
     ;;
   --u | --us | --usa | --usag | --usage)
-    printf $"Usage: %s [-ef] [-F FROMLIST] [-o FILENAME] [-T TOLIST] [--exit]
+    gettextf "Usage: %s [-ef] [-F FROMLIST] [-o FILENAME] [-T TOLIST] [--exit]
 	    [--follow] [--from FROMLIST] [--output FILENAME] [--to TOLIST]
 	    [--help] [--usage] [--version] [--]
 	    EXECUTABLE [EXECUTABLE-OPTION...]\n" "$script"
@@ -134,8 +150,8 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     break
     ;;
   -*)
-    printf >&2 $"%s: unrecognized option '%c%s'\n" "$script" '-' ${1#-}
-    printf >&2 $"Try \`%s --help' or \`%s --usage' for more information.\n" "$script" "$script"
+    gettextf >&2 "%s: unrecognized option '%c%s'\n" "$script" '-' ${1#-}
+    gettextf >&2 "Try \`%s --help' or \`%s --usage' for more information.\n" "$script" "$script"
     exit 1
     ;;
   *)
diff --git a/malloc/memusage.sh b/malloc/memusage.sh
index 2a722a1..5dfa539 100755
--- a/malloc/memusage.sh
+++ b/malloc/memusage.sh
@@ -19,25 +19,43 @@
 
 memusageso='@SLIBDIR@/libmemusage.so'
 memusagestat='@BINDIR@/memusagestat'
-TEXTDOMAIN=libc
 script="memusage"
 year="2012"
 
+if TEXTDOMAIN=libc gettext '' >/dev/null 2>&1; then
+  _gettext ()
+  {
+    TEXTDOMAIN=libc gettext "$1"
+  }
+else
+  _gettext ()
+  {
+    printf '%s' "$1"
+  }
+fi
+
+gettextf ()
+{
+  msg="$(_gettext "$1"; printf 'x')"
+  shift
+  printf "${msg%x}" "$@"
+}
+
 # Print usage message.
 do_usage() {
-  printf >&2 $"Try \`%s --help' or \`%s --usage' for more information.\n" "$script" "$script"
+  gettextf >&2 "Try \`%s --help' or \`%s --usage' for more information.\n" "$script" "$script"
   exit 1
 }
 
 # Message for missing argument.
 do_missing_arg() {
-  printf >&2 $"%s: option '%s' requires an argument\n" "$script" "$1"
+  gettextf >&2 "%s: option '%s' requires an argument\n" "$script" "$1"
   do_usage
 }
 
 # Print help message
 do_help() {
-  printf $"Usage: memusage [OPTION]... PROGRAM [PROGRAMOPTION]...
+  gettextf "Usage: memusage [OPTION]... PROGRAM [PROGRAMOPTION]...
 Profile memory usage of PROGRAM.
 
    -n,--progname=NAME     Name of the program file to profile
@@ -63,18 +81,18 @@ Mandatory arguments to long options are also mandatory for any corresponding
 short options.
 
 "
-  printf $"For bug reporting instructions, please see:\\n%s.\\n" \
+  gettextf "For bug reporting instructions, please see:\\n%s.\\n" \
     "@REPORT_BUGS_TO@"
   exit 0
 }
 
 do_version() {
   echo 'memusage @PKGVERSION@@VERSION@'
-  printf $"Copyright (C) %s Free Software Foundation, Inc.
+  gettextf "Copyright (C) %s 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.
 " "$year"
-  printf $"Written by %s.
+  gettextf "Written by %s.
 " "Ulrich Drepper"
   exit 0
 }
@@ -98,7 +116,7 @@ while test $# -gt 0; do
     do_help
     ;;
   --us | --usa | --usag | --usage)
-    printf $"Syntax: memusage [--data=FILE] [--progname=NAME] [--png=FILE] [--unbuffered]
+    gettextf "Syntax: memusage [--data=FILE] [--progname=NAME] [--png=FILE] [--unbuffered]
 	    [--buffer=SIZE] [--no-timer] [--time-based] [--total]
 	    [--title=STRING] [--x-size=SIZE] [--y-size=SIZE]
 	    PROGRAM [PROGRAMOPTION]...\n"
@@ -190,7 +208,7 @@ while test $# -gt 0; do
     memusagestat_args="$memusagestat_args -y ${1##*=}"
     ;;
   --p | --p=* | --t | --t=* | --ti | --ti=* | --u)
-    printf >&2 $"%s: option \`%s' is ambiguous\n" "$script" "${1##*=}"
+    gettextf >&2 "%s: option \`%s' is ambiguous\n" "$script" "${1##*=}"
     do_usage
     ;;
   --)
@@ -199,7 +221,7 @@ while test $# -gt 0; do
     break
     ;;
   --*)
-    printf >&2 $"%s: unrecognized option \`%s'\n" "$script" "$1"
+    gettextf >&2 "%s: unrecognized option \`%s'\n" "$script" "$1"
     do_usage
     ;;
   *)
@@ -212,7 +230,7 @@ done
 
 # See whether any arguments are left.
 if test $# -eq 0; then
-  printf >&2 $"No program name given\n"
+  gettextf >&2 "No program name given\n"
   do_usage
 fi
 
-- 
1.7.10.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]