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 v2a 2/2][BZ #13853] Replace Bash-only $"msgid" with _gettext


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: Replace insecure and Bash-only $"msgid" quoting with
	calls to _gettext.
	* elf/ldd.bash.in: Likewise.
	* elf/sotruss.ksh: Likewise.
	* malloc/memusage.sh: Likewise.
---
 debug/xtrace.sh    |   45 ++++++++++++++++++++++++------------------
 elf/ldd.bash.in    |   55 +++++++++++++++++++++++++++++-----------------------
 elf/sotruss.ksh    |   46 +++++++++++++++++++++++++------------------
 malloc/memusage.sh |   44 ++++++++++++++++++++++++-----------------
 4 files changed, 110 insertions(+), 80 deletions(-)

diff --git a/debug/xtrace.sh b/debug/xtrace.sh
index e71c815..c106186 100755
--- a/debug/xtrace.sh
+++ b/debug/xtrace.sh
@@ -19,30 +19,41 @@
 
 pcprofileso='@SLIBDIR@/libpcprofile.so'
 pcprofiledump='@BINDIR@/pcprofiledump'
-TEXTDOMAIN=libc
+
+if TEXTDOMAIN=libc gettext '' >/dev/null 2>&1; then
+  _gettext ()
+  {
+    TEXTDOMAIN=libc gettext "$1"
+  }
+else
+  _gettext ()
+  {
+    printf '%s' "$1"
+  }
+fi
 
 # Print usage message.
 do_usage() {
-  printf $"Usage: xtrace [OPTION]... PROGRAM [PROGRAMOPTION]...\n"
+  printf "$(_gettext "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" xtrace xtrace
+  printf >&2 "$(_gettext "Try \`%s --help' or \`%s --usage' for more information.\n")" xtrace xtrace
   exit 1
 }
 
 # Message for missing argument.
 do_missing_arg() {
-  printf >&2 $"%s: option '%s' requires an argument.\n" xtrace "$1"
+  printf >&2 "$(_gettext "%s: option '%s' requires an argument.\n")" xtrace "$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.
+  printf "$(_gettext "Usage: xtrace [OPTION]... PROGRAM [PROGRAMOPTION]...\n")"
+  printf "$(_gettext "Trace execution of program by printing currently executed function.
 
      --data=FILE          Don't run the program, just print the data from FILE.
 
@@ -51,22 +62,18 @@ do_help() {
    -V,--version           Print version information and exit
 
 Mandatory arguments to long options are also mandatory for any corresponding
-short options.
-
-"
-  printf $"For bug reporting instructions, please see:\\n%s.\\n" \
+short options.\n\n")"
+  printf "$(_gettext "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.
+  printf "$(_gettext "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.
-" "2012"
-  printf $"Written by %s.
-" "Ulrich Drepper"
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n")" "2012"
+  printf "$(_gettext "Written by %s.\n")" "Ulrich Drepper"
   exit 0
 }
 
@@ -122,7 +129,7 @@ while test $# -gt 0; do
     break
     ;;
   --*)
-    printf >&2 $"xtrace: unrecognized option \`%s'\n" "$1"
+    printf >&2 "$(_gettext "xtrace: unrecognized option \`%s'\n")" "$1"
     help_info
     ;;
   *)
@@ -135,7 +142,7 @@ done
 
 # See whether any arguments are left.
 if test $# -eq 0; then
-  printf >&2 $"No program name given\n"
+  printf >&2 "$(_gettext "No program name given\n")"
   help_info
 fi
 
@@ -143,11 +150,11 @@ fi
 program=$1
 shift
 if test ! -f "$program"; then
-  printf >&2 $"executable \`%s' not found\n" "$program"
+  printf >&2 "$(_gettext "executable \`%s' not found\n")" "$program"
   help_info
 fi
 if test ! -x "$program"; then
-  printf >&2 $"\`%s' is no executable\n" "$program"
+  printf >&2 "$(_gettext "\`%s' is no executable\n")" "$program"
   help_info
 fi
 
diff --git a/elf/ldd.bash.in b/elf/ldd.bash.in
index b36c6c1..c63646a 100644
--- a/elf/ldd.bash.in
+++ b/elf/ldd.bash.in
@@ -22,9 +22,18 @@
 # 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@
+if TEXTDOMAIN=libc TEXTDOMAINDIR=@TEXTDOMAINDIR@ gettext '' >/dev/null 2>&1
+then
+  _gettext ()
+  {
+    TEXTDOMAIN=libc TEXTDOMAINDIR=@TEXTDOMAINDIR@ gettext "$1"
+  }
+else
+  _gettext ()
+  {
+    printf '%s' "$1"
+  }
+fi
 
 RTLDLIST=@RTLD@
 warn=
@@ -35,24 +44,22 @@ while test $# -gt 0; do
   case "$1" in
   --vers | --versi | --versio | --version)
     echo 'ldd @PKGVERSION@@VERSION@'
-    printf $"Copyright (C) %s Free Software Foundation, Inc.
+    printf "$(_gettext "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.
-" "2012"
-    printf $"Written by %s and %s.
-" "Roland McGrath" "Ulrich Drepper"
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n")" "2012"
+    printf "$(_gettext "Written by %s and %s.\n")" \
+      "Roland McGrath" "Ulrich Drepper"
     exit 0
     ;;
   --h | --he | --hel | --help)
-    echo $"Usage: ldd [OPTION]... FILE...
+    printf "$(_gettext "Usage: ldd [OPTION]... FILE...
       --help              print this help and exit
       --version           print version information and exit
   -d, --data-relocs       process data relocations
   -r, --function-relocs   process data and function relocations
   -u, --unused            print unused direct dependencies
-  -v, --verbose           print all information
-"
-    printf $"For bug reporting instructions, please see:\\n%s.\\n" \
+  -v, --verbose           print all information\n\n")"
+    printf "$(_gettext "For bug reporting instructions, please see:\\n%s.\\n")" \
       "@REPORT_BUGS_TO@"
     exit 0
     ;;
@@ -77,15 +84,15 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     shift
     ;;
   --v | --ve | --ver)
-    printf >&2 $"ldd: option \`%s' is ambiguous\n" "$1"
+    printf >&2 "$(_gettext "ldd: option \`%s' is ambiguous\n")" "$1"
     exit 1
     ;;
   --)		# Stop option processing.
     shift; break
     ;;
   -*)
-    echo >&2 'ldd:' $"unrecognized option" "\`$1'"
-    echo >&2 $"Try \`ldd --help' for more information."
+    echo >&2 'ldd:' "$(_gettext "unrecognized option")" "\`$1'"
+    echo >&2 "$(_gettext "Try \`ldd --help' for more information.")"
     exit 1
     ;;
   *)
@@ -122,8 +129,8 @@ fi
 
 case $# in
 0)
-  echo >&2 'ldd:' $"missing file arguments"
-  echo >&2 $"Try \`ldd --help' for more information."
+  echo >&2 'ldd:' "$(_gettext "missing file arguments")"
+  echo >&2 "$(_gettext "Try \`ldd --help' for more information.")"
   exit 1
   ;;
 1)
@@ -145,14 +152,14 @@ for file do
      ;;
   esac
   if test ! -e "$file"; then
-    echo "ldd: ${file}:" $"No such file or directory" >&2
+    echo "ldd: ${file}:" "$(_gettext "No such file or directory")" >&2
     result=1
   elif test ! -f "$file"; then
-    echo "ldd: ${file}:" $"not regular file" >&2
+    echo "ldd: ${file}:" "$(_gettext "not regular file")" >&2
     result=1
   elif test -r "$file"; then
-    test -x "$file" || echo 'ldd:' $"\
-warning: you do not have execution permission for" "\`$file'" >&2
+    test -x "$file" || echo 'ldd:' "$(_gettext "\
+warning: you do not have execution permission for")" "\`$file'" >&2
     RTLD=
     ret=1
     for rtld in ${RTLDLIST}; do
@@ -180,7 +187,7 @@ warning: you do not have execution permission for" "\`$file'" >&2
     1)
       # This can be a non-ELF binary or no binary at all.
       nonelf "$file" || {
-	echo $"	not a dynamic executable"
+	echo "$(_gettext "	not a dynamic executable")"
 	result=1
       }
       ;;
@@ -188,12 +195,12 @@ warning: you do not have execution permission for" "\`$file'" >&2
       try_trace "$RTLD" "$file" || result=1
       ;;
     *)
-      echo 'ldd:' ${RTLD} $"exited with unknown exit code" "($ret)" >&2
+      echo 'ldd:' ${RTLD} "$(_gettext "exited with unknown exit code")" "($ret)" >&2
       exit 1
       ;;
     esac
   else
-    echo 'ldd:' $"error: you do not have read permission for" "\`$file'" >&2
+    echo 'ldd:' "$(_gettext "error: you do not have read permission for")" "\`$file'" >&2
     result=1
   fi
 done
diff --git a/elf/sotruss.ksh b/elf/sotruss.ksh
index 587ab68..5c68178 100755
--- a/elf/sotruss.ksh
+++ b/elf/sotruss.ksh
@@ -16,9 +16,18 @@
 # 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@
+if TEXTDOMAIN=libc TEXTDOMAINDIR=@TEXTDOMAINDIR@ gettext '' >/dev/null 2>&1
+then
+  _gettext ()
+  {
+    TEXTDOMAIN=libc TEXTDOMAINDIR=@TEXTDOMAINDIR@ gettext "$1"
+  }
+else
+  _gettext ()
+  {
+    printf '%s' "$1"
+  }
+fi
 
 unset SOTRUSS_FROMLIST
 unset SOTRUSS_TOLIST
@@ -29,7 +38,7 @@ SOTRUSS_WHICH=$$
 lib='@PREFIX@/$LIB/audit/sotruss-lib.so'
 
 function do_help {
-  echo $"Usage: sotruss [OPTION...] [--] EXECUTABLE [EXECUTABLE-OPTION...]
+  echo "$(_gettext "Usage: sotruss [OPTION...] [--] EXECUTABLE [EXECUTABLE-OPTION...]
   -F, --from FROMLIST     Trace calls from objects on FROMLIST
   -T, --to TOLIST         Trace calls to objects on TOLIST
 
@@ -40,31 +49,31 @@ function do_help {
 
   -?, --help              Give this help list
       --usage             Give a short usage message
-      --version           Print program version"
+      --version           Print program version")"
 
   echo
-  printf $"Mandatory arguments to long options are also mandatory for any corresponding\nshort options.\n"
+  printf "$(_gettext "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" \
+  printf "$(_gettext "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" sotruss "$1"
-  printf >&2 $"Try \`%s --help' or \`%s --usage' for more information.\n" sotruss sotruss
+  printf >&2 "$(_gettext "%s: option requires an argument -- '%s'\n")" sotruss "$1"
+  printf >&2 "$(_gettext "Try \`%s --help' or \`%s --usage' for more information.\n")" sotruss sotruss
   exit 1
 }
 
 function do_ambiguous {
-  printf >&2 $"%s: option is ambiguous; possibilities:"
+  printf >&2 "$(_gettext "%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" sotruss sotruss
+  printf >&2 "$(_gettext "Try \`%s --help' or \`%s --usage' for more information.\n")" sotruss sotruss
   exit 1
 }
 
@@ -72,21 +81,20 @@ 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.
+    printf "$(_gettext "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.
-" "2012"
-    printf $"Written by %s.\n" "Ulrich Drepper"
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n")" "2012"
+    printf "$(_gettext "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]
+    printf "$(_gettext "Usage: %s [-ef] [-F FROMLIST] [-o FILENAME] [-T TOLIST] [--exit]
 	    [--follow] [--from FROMLIST] [--output FILENAME] [--to TOLIST]
 	    [--help] [--usage] [--version] [--]
-	    EXECUTABLE [EXECUTABLE-OPTION...]\n" sotruss
+	    EXECUTABLE [EXECUTABLE-OPTION...]\n")" sotruss
     exit 0
     ;;
   -F | --fr | --fro | --from)
@@ -131,8 +139,8 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     break
     ;;
   -*)
-    printf >&2 $"%s: unrecognized option '%c%s'\n" sotruss '-' ${1#-}
-    printf >&2 $"Try \`%s --help' or \`%s --usage' for more information.\n" sotruss sotruss
+    printf >&2 "$(_gettext "%s: unrecognized option '%c%s'\n")" sotruss '-' ${1#-}
+    printf >&2 "$(_gettext "Try \`%s --help' or \`%s --usage' for more information.\n")" sotruss sotruss
     exit 1
     ;;
   *)
diff --git a/malloc/memusage.sh b/malloc/memusage.sh
index 0dee9d0..2c8bd9f 100755
--- a/malloc/memusage.sh
+++ b/malloc/memusage.sh
@@ -19,23 +19,34 @@
 
 memusageso='@SLIBDIR@/libmemusage.so'
 memusagestat='@BINDIR@/memusagestat'
-TEXTDOMAIN=libc
+
+if TEXTDOMAIN=libc gettext '' >/dev/null 2>&1; then
+  _gettext ()
+  {
+    TEXTDOMAIN=libc gettext "$1"
+  }
+else
+  _gettext ()
+  {
+    printf '%s' "$1"
+  }
+fi
 
 # Print usage message.
 do_usage() {
-  printf >&2 $"Try \`%s --help' or \`%s --usage' for more information.\n" memusage memusage
+  printf >&2 "$(_gettext "Try \`%s --help' or \`%s --usage' for more information.\n")" memusage memusage
   exit 1
 }
 
 # Message for missing argument.
 do_missing_arg() {
-  printf >&2 $"%s: option '%s' requires an argument\n" memusage "$1"
+  printf >&2 "$(_gettext "%s: option '%s' requires an argument\n")" memusage "$1"
   do_usage
 }
 
 # Print help message
 do_help() {
-  echo $"Usage: memusage [OPTION]... PROGRAM [PROGRAMOPTION]...
+  printf "$(_gettext "Usage: memusage [OPTION]... PROGRAM [PROGRAMOPTION]...
 Profile memory usage of PROGRAM.
 
    -n,--progname=NAME     Name of the program file to profile
@@ -58,22 +69,18 @@ Profile memory usage of PROGRAM.
    -y,--y-size=SIZE       Make graphic SIZE pixels high
 
 Mandatory arguments to long options are also mandatory for any corresponding
-short options.
-
-"
-  printf $"For bug reporting instructions, please see:\\n%s.\\n" \
+short options.\n\n")"
+  printf "$(_gettext "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.
+  printf "$(_gettext "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.
-" "2012"
-  printf $"Written by %s.
-" "Ulrich Drepper"
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n")" "2012"
+  printf "$(_gettext "Written by %s.\n")" "Ulrich Drepper"
   exit 0
 }
 
@@ -96,10 +103,11 @@ while test $# -gt 0; do
     do_help
     ;;
   --us | --usa | --usag | --usage)
-    echo $"Syntax: memusage [--data=FILE] [--progname=NAME] [--png=FILE] [--unbuffered]
+    echo "$(_gettext "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]..."
+	    PROGRAM [PROGRAMOPTION]...")"
+    echo
     exit 0
     ;;
   -n | --pr | --pro | --prog | --progn | --progna | --prognam | --progname)
@@ -188,7 +196,7 @@ while test $# -gt 0; do
     memusagestat_args="$memusagestat_args -y ${1##*=}"
     ;;
   --p | --p=* | --t | --t=* | --ti | --ti=* | --u)
-    printf >&2 $"memusage: option \`%s' is ambiguous\n" "${1##*=}"
+    printf >&2 "$(_gettext "memusage: option \`%s' is ambiguous\n")" "${1##*=}"
     do_usage
     ;;
   --)
@@ -197,7 +205,7 @@ while test $# -gt 0; do
     break
     ;;
   --*)
-    printf >&2 $"memusage: unrecognized option \`%s'\n" "$1"
+    printf >&2 "$(_gettext "memusage: unrecognized option \`%s'\n")" "$1"
     do_usage
     ;;
   *)
@@ -210,7 +218,7 @@ done
 
 # See whether any arguments are left.
 if test $# -eq 0; then
-  echo >&2 $"No program name given"
+  echo >&2 "$(_gettext "No program name given")"
   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]