summaryrefslogtreecommitdiffstats
path: root/gettext-tools/src/xgettext.c
diff options
context:
space:
mode:
authorDaiki Ueno <ueno@gnu.org>2016-05-16 17:08:09 +0900
committerDaiki Ueno <ueno@gnu.org>2016-05-16 17:39:38 +0900
commite26b846fe273243b446cc02a027cc1a715734d1f (patch)
tree07223e40fad19a8fa85e68d05d8ab1aa7e89d842 /gettext-tools/src/xgettext.c
parentcd95c539516127b153ab21b57a1ceaa0e731ec4c (diff)
downloadexternal_gettext-e26b846fe273243b446cc02a027cc1a715734d1f.zip
external_gettext-e26b846fe273243b446cc02a027cc1a715734d1f.tar.gz
external_gettext-e26b846fe273243b446cc02a027cc1a715734d1f.tar.bz2
msgfmt, xgettext: Respect XDG_DATA_DIRS
Suggested in https://savannah.gnu.org/bugs/?47123 * autogen.sh (GNULIB_MODULES_TOOLS_FOR_SRC): Add 'xmemdup0'. * gettext-tools/gnulib-lib/.gitignore: Ignore files brought by gnulib-tool. * gettext-tools/gnulib-tests/.gitignore: Likewise. * gettext-tools/src/search-path.c: New file. * gettext-tools/src/search-path.h: New file. * gettext-tools/src/Makefile.am (noinst_HEADERS): Add search-path.h. (libgettextsrc_la_SOURCES): Add search-path.c. * gettext-tools/src/msgfmt.c: Include "search-path.h". (main): Use get_search_path to locate ITS directories. * gettext-tools/src/xgettext.c: Include "search-path.h". (main): Use get_search_path to locate ITS directories.
Diffstat (limited to 'gettext-tools/src/xgettext.c')
-rw-r--r--gettext-tools/src/xgettext.c54
1 files changed, 26 insertions, 28 deletions
diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c
index c431897..f67ec21 100644
--- a/gettext-tools/src/xgettext.c
+++ b/gettext-tools/src/xgettext.c
@@ -73,6 +73,7 @@
#include "unistr.h"
#include "its.h"
#include "locating-rule.h"
+#include "search-path.h"
#include "gettext.h"
/* A convenience macro. I don't like writing gettext() every time. */
@@ -328,7 +329,8 @@ main (int argc, char *argv[])
bool some_additional_keywords = false;
bool sort_by_msgid = false;
bool sort_by_filepos = false;
- char *its_dirs[2] = { NULL, NULL };
+ char **dirs;
+ char **its_dirs;
char *explicit_its_filename = NULL;
const char *file_name;
const char *files_from = NULL;
@@ -726,36 +728,31 @@ xgettext cannot work without keywords to look for"));
usage (EXIT_FAILURE);
}
- {
- const char *gettextdatadir;
- char *versioned_gettextdatadir;
-
- /* Make it possible to override the locator file location. This
- is necessary for running the testsuite before "make
- install". */
- gettextdatadir = getenv ("GETTEXTDATADIR");
- if (gettextdatadir == NULL || gettextdatadir[0] == '\0')
- gettextdatadir = relocate (GETTEXTDATADIR);
-
- its_dirs[0] = xconcatenated_filename (gettextdatadir, "its", NULL);
-
- versioned_gettextdatadir =
- xasprintf ("%s%s", relocate (GETTEXTDATADIR), PACKAGE_SUFFIX);
- its_dirs[1] = xconcatenated_filename (versioned_gettextdatadir, "its",
- NULL);
- free (versioned_gettextdatadir);
-
- its_locating_rules = locating_rule_list_alloc ();
- for (i = 0; i < SIZEOF (its_dirs); i++)
- locating_rule_list_add_from_directory (its_locating_rules, its_dirs[i]);
- }
-
/* Explicit ITS file selection and language specification are
mutually exclusive. */
if (explicit_its_filename != NULL && language != NULL)
error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"),
"--its", "--language");
+ if (explicit_its_filename == NULL)
+ {
+ its_dirs = get_search_path ("its");
+ its_locating_rules = locating_rule_list_alloc ();
+ for (dirs = its_dirs; *dirs != NULL; dirs++)
+ {
+ /* Make it possible to override the locator file location. This
+ is necessary for running the testsuite before "make
+ install". */
+ char *relocated = relocate (*dirs);
+ if (relocated != *dirs)
+ {
+ free (*dirs);
+ *dirs = relocated;
+ }
+ locating_rule_list_add_from_directory (its_locating_rules, *dirs);
+ }
+ }
+
/* Determine extractor from language. */
if (language != NULL)
extractor = language_to_extractor (language);
@@ -930,7 +927,7 @@ warning: ITS rule file '%s' does not exist"), explicit_its_filename);
its_rule_list_add_from_string (its_rules,
ITS_ROOT_UNTRANSLATABLE);
- for (j = 0; j < SIZEOF (its_dirs); j++)
+ for (j = 0; its_dirs[j] != NULL; j++)
{
char *its_filename =
xconcatenated_filename (its_dirs[j], its_basename,
@@ -945,7 +942,7 @@ warning: ITS rule file '%s' does not exist"), explicit_its_filename);
if (ok)
break;
}
- if (j == SIZEOF (its_dirs))
+ if (its_dirs[j] == NULL)
{
error (0, 0, _("\
warning: ITS rule file '%s' does not exist; check your gettext installation"),
@@ -1030,8 +1027,9 @@ warning: file '%s' extension '%s' is unknown; will try C"), filename, extension)
if (its_locating_rules)
locating_rule_list_free (its_locating_rules);
- for (i = 0; i < SIZEOF (its_dirs); i++)
+ for (i = 0; its_dirs[i] != NULL; i++)
free (its_dirs[i]);
+ free (its_dirs);
exit (EXIT_SUCCESS);
}