From: Richard Jones Date: Fri, 29 Jan 2010 14:56:13 +0000 (+0000) Subject: Set locale in C programs so l10n works (RHBZ#559962). X-Git-Tag: 1.1.0~43 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=23e1a90360ddea4da8eba3b78da4661fb130f07e;p=hivex.git 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). --- 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); }