Richard W.M. Jones
2010-Jan-29 15:20 UTC
[Libguestfs] [PATCH] Set locale in C programs so l10n works (RHBZ#559962).
Potential fix for https://bugzila.redhat.com/559962 Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw -------------- next part -------------->From a6025c11d97ed5802b3729a93d224d2baa20ff12 Mon Sep 17 00:00:00 2001From: Richard Jones <rjones at redhat.com> Date: Fri, 29 Jan 2010 14:56:13 +0000 Subject: [PATCH] Set locale in C programs so l10n works (RHBZ#559962). This commit adds the calls to setlocale &c to all of the current C programs. It also adds l10n support to hivexget and hivexml which lacked them previously. To test this, try: LANG=pa_IN.UTF-8 guestfish --cmd-help (You can only do this test after installing the package, or at least the 'pa.mo' mo-file in the correct place). --- fish/Makefile.am | 1 + fish/fish.c | 4 ++++ fuse/Makefile.am | 1 + fuse/guestmount.c | 4 ++++ hivex/Makefile.am | 4 ++++ hivex/hivexget.c | 24 +++++++++++++++++++----- hivex/hivexml.c | 21 +++++++++++++++++---- test-tool/Makefile.am | 1 + test-tool/test-tool.c | 4 ++++ 9 files changed, 55 insertions(+), 9 deletions(-) diff --git a/fish/Makefile.am b/fish/Makefile.am index d817e6c..43dce00 100644 --- a/fish/Makefile.am +++ b/fish/Makefile.am @@ -59,6 +59,7 @@ guestfish_CFLAGS = \ -I$(top_srcdir)/src -I$(top_builddir)/src \ -I$(top_srcdir)/fish -I$(top_builddir)/fish \ -DGUESTFS_DEFAULT_PATH='"$(libdir)/guestfs"' \ + -DLOCALEBASEDIR=\""$(datadir)/locale"\" \ -I$(srcdir)/../gnulib/lib -I../gnulib/lib \ $(WARN_CFLAGS) $(WERROR_CFLAGS) diff --git a/fish/fish.c b/fish/fish.c index 7dae815..dd73af7 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -139,6 +139,10 @@ main (int argc, char *argv[]) atexit (close_stdout); + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEBASEDIR); + textdomain (PACKAGE); + enum { HELP_OPTION = CHAR_MAX + 1 }; static const char *options = "a:Df:h::im:nrv?Vx"; diff --git a/fuse/Makefile.am b/fuse/Makefile.am index 5ffdb95..1bfc375 100644 --- a/fuse/Makefile.am +++ b/fuse/Makefile.am @@ -33,6 +33,7 @@ guestmount_CFLAGS = \ -I$(top_srcdir)/src -I$(top_builddir)/src \ -I$(srcdir)/../gnulib/lib -I../gnulib/lib \ -DGUESTFS_DEFAULT_PATH='"$(libdir)/guestfs"' \ + -DLOCALEBASEDIR=\""$(datadir)/locale"\" \ $(FUSE_CFLAGS) \ $(WARN_CFLAGS) $(WERROR_CFLAGS) diff --git a/fuse/guestmount.c b/fuse/guestmount.c index 9f0a39e..c935493 100644 --- a/fuse/guestmount.c +++ b/fuse/guestmount.c @@ -896,6 +896,10 @@ usage (int status) int main (int argc, char *argv[]) { + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEBASEDIR); + textdomain (PACKAGE); + enum { HELP_OPTION = CHAR_MAX + 1 }; /* The command line arguments are broadly compatible with (a subset diff --git a/hivex/Makefile.am b/hivex/Makefile.am index b73aa2f..31275ea 100644 --- a/hivex/Makefile.am +++ b/hivex/Makefile.am @@ -34,6 +34,8 @@ hivexml_SOURCES = \ hivexml_LDADD = libhivex.la $(LIBXML2_LIBS) hivexml_CFLAGS = \ + -I$(top_srcdir)/src \ + -DLOCALEBASEDIR=\""$(datadir)/locale"\" \ $(LIBXML2_CFLAGS) \ $(WARN_CFLAGS) $(WERROR_CFLAGS) @@ -42,6 +44,8 @@ hivexget_SOURCES = \ hivexget_LDADD = libhivex.la hivexget_CFLAGS = \ + -I$(top_srcdir)/src \ + -DLOCALEBASEDIR=\""$(datadir)/locale"\" \ $(WARN_CFLAGS) $(WERROR_CFLAGS) man_MANS = hivex.3 hivexml.1 hivexget.1 diff --git a/hivex/hivexget.c b/hivex/hivexget.c index 3e89d63..fd49293 100644 --- a/hivex/hivexget.c +++ b/hivex/hivexget.c @@ -27,26 +27,40 @@ #include "hivex.h" +#ifdef HAVE_GETTEXT +#include "gettext.h" +#define _(str) dgettext(PACKAGE, (str)) +//#define N_(str) dgettext(PACKAGE, (str)) +#else +#define _(str) str +//#define N_(str) str +#endif + enum { EXIT_NOT_FOUND = 2 }; int main (int argc, char *argv[]) { + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEBASEDIR); + textdomain (PACKAGE); + if (argc < 3 || argc > 4) { - fprintf (stderr, "hivexget regfile path [key]\n"); + fprintf (stderr, _("hivexget regfile path [key]\n")); exit (EXIT_FAILURE); } + char *file = argv[1]; char *path = argv[2]; char *key = argv[3]; /* could be NULL */ if (path[0] != '\\') { - fprintf (stderr, "hivexget: path must start with a \\ character\n"); + fprintf (stderr, _("hivexget: path must start with a \\ character\n")); exit (EXIT_FAILURE); } if (path[1] == '\\') { doubled: - fprintf (stderr, "hivexget: %s: \\ characters in path are doubled - are you escaping the path parameter correctly?\n", path); + fprintf (stderr, _("hivexget: %s: \\ characters in path are doubled - are you escaping the path parameter correctly?\n"), path); exit (EXIT_FAILURE); } @@ -82,7 +96,7 @@ main (int argc, char *argv[]) if (errno) goto error; /* else node not found */ - fprintf (stderr, "hivexget: %s: %s: path element not found\n", + fprintf (stderr, _("hivexget: %s: %s: path element not found\n"), path, p); exit (EXIT_NOT_FOUND); } @@ -104,7 +118,7 @@ main (int argc, char *argv[]) if (errno) goto error; /* else key not found */ - fprintf (stderr, "hivexget: %s: key not found\n", key); + fprintf (stderr, _("hivexget: %s: key not found\n"), key); exit (EXIT_NOT_FOUND); } diff --git a/hivex/hivexml.c b/hivex/hivexml.c index 7fb419f..90cb22b 100644 --- a/hivex/hivexml.c +++ b/hivex/hivexml.c @@ -30,6 +30,15 @@ #include "hivex.h" +#ifdef HAVE_GETTEXT +#include "gettext.h" +#define _(str) dgettext(PACKAGE, (str)) +//#define N_(str) dgettext(PACKAGE, (str)) +#else +#define _(str) str +//#define N_(str) str +#endif + /* Callback functions. */ static int node_start (hive_h *, void *, hive_node_h, const char *name); static int node_end (hive_h *, void *, hive_node_h, const char *name); @@ -58,14 +67,18 @@ static struct hivex_visitor visitor = { #define XML_CHECK(proc, args) \ do { \ if ((proc args) == -1) { \ - fprintf (stderr, "%s: failed to write XML document\n", #proc); \ - exit (EXIT_FAILURE); \ + fprintf (stderr, _("%s: failed to write XML document\n"), #proc); \ + exit (EXIT_FAILURE); \ } \ } while (0) int main (int argc, char *argv[]) { + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEBASEDIR); + textdomain (PACKAGE); + int c; int open_flags = 0; int visit_flags = 0; @@ -85,7 +98,7 @@ main (int argc, char *argv[]) } if (optind + 1 != argc) { - fprintf (stderr, "hivexml: missing name of input file\n"); + fprintf (stderr, _("hivexml: missing name of input file\n")); exit (EXIT_FAILURE); } @@ -104,7 +117,7 @@ main (int argc, char *argv[]) xmlTextWriterPtr writer; writer = xmlNewTextWriterFilename ("/dev/stdout", 0); if (writer == NULL) { - fprintf (stderr, "xmlNewTextWriterFilename: failed to create XML writer\n"); + fprintf (stderr, _("xmlNewTextWriterFilename: failed to create XML writer\n")); exit (EXIT_FAILURE); } diff --git a/test-tool/Makefile.am b/test-tool/Makefile.am index d58f137..66d06e0 100644 --- a/test-tool/Makefile.am +++ b/test-tool/Makefile.am @@ -30,6 +30,7 @@ AM_CPPFLAGS = \ libguestfs_test_tool_SOURCES = test-tool.c libguestfs_test_tool_CFLAGS = \ + -DLOCALEBASEDIR=\""$(datadir)/locale"\" \ -I$(top_srcdir)/src -I$(top_builddir)/src \ -Wall libguestfs_test_tool_LDADD = \ diff --git a/test-tool/test-tool.c b/test-tool/test-tool.c index f38490a..39139e5 100644 --- a/test-tool/test-tool.c +++ b/test-tool/test-tool.c @@ -85,6 +85,10 @@ usage (void) int main (int argc, char *argv[]) { + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEBASEDIR); + textdomain (PACKAGE); + static const char *options = "t:?"; static const struct option long_options[] = { { "help", 0, 0, '?' }, -- 1.6.5.2
Richard W.M. Jones
2010-Jan-29 19:14 UTC
[Libguestfs] [PATCH] Set locale in C programs so l10n works (RHBZ#559962).
On Fri, Jan 29, 2010 at 03:20:24PM +0000, Richard W.M. Jones wrote:> > Potential fix for > https://bugzila.redhat.com/559962Matt reviewed this on IRC and I pushed it. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
Apparently Analagous Threads
- [PATCH] inspect: Don't fail for Windows guests with multiple disks (RHBZ#674130).
- [PATCH version 2] guestfish: Use xstrtol to parse integers (RHBZ#557655).
- [PATCH] Add version numbers to Perl modules (RHBZ#521674).
- [PATCH] Improved error if virt-inspector cannot find OSes in image (RHBZ#591142).
- [PATCH] virt-df: Disallow -h and --csv options together (RHBZ#600977).