]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
search-path: Don't relocate dirs given as envvar
authorDaiki Ueno <ueno@gnu.org>
Fri, 20 May 2016 06:47:58 +0000 (15:47 +0900)
committerDaiki Ueno <ueno@gnu.org>
Fri, 20 May 2016 06:52:20 +0000 (15:52 +0900)
* gettext-tools/src/search-path.c (foreach_function_ty): New typedef.
(path_array_ty): New struct.
(foreach_components, increment, fill): New functions.
(get_search_path): Rewrite using those functions.  Relocate
GETTEXTDATADIR here.
* gettext-tools/src/search-path.h (get_search_path): Update documentation.
* gettext-tools/src/msgfmt.c (main): Don't relocate directories in ITS
search path.
* gettext-tools/src/xgettext.c (main): Likewise.

gettext-tools/src/msgfmt.c
gettext-tools/src/search-path.c
gettext-tools/src/search-path.h
gettext-tools/src/xgettext.c

index ff4084b2c92e67204b71df6d677612ca29f98e66..58ca9c11d865905ce50cf97ec22bbb7a52cd4c06 100644 (file)
@@ -673,19 +673,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\
       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);
-        }
+        locating_rule_list_add_from_directory (its_locating_rules, *dirs);
 
       its_basename = locating_rule_list_locate (its_locating_rules,
                                                 xml_template_name,
index fdb61cb28f0961159a7f9051af67c25ebe48f08e..c085ec015dec608b6842044f2136c297ac3e5c75 100644 (file)
 #include <string.h>
 
 #include "concat-filename.h"
+#include "relocatable.h"
 #include "xalloc.h"
 #include "xmemdup0.h"
 #include "xvasprintf.h"
 
-/* Find the standard search path for data files.  Returns a NULL
-   terminated list of strings.  */
-char **
-get_search_path (const char *name)
-{
-  char **result;
-  const char *gettextdatadir;
-  const char *gettextdatadirs;
-  char *base, *dir;
-  size_t n_dirs = 2;
+typedef void (* foreach_function_ty) (const char *dir, size_t len, void *data);
 
-  gettextdatadirs = getenv ("GETTEXTDATADIRS");
+struct path_array_ty {
+  char **ptr;
+  size_t len;
+  const char *sub;
+};
 
-  /* If GETTEXTDATADIRS is not set, fallback to XDG_DATA_DIRS.  */
-  if (gettextdatadirs == NULL || *gettextdatadirs == '\0')
-    gettextdatadirs = getenv ("XDG_DATA_DIRS");
+static void
+foreach_components (const char *dirs, foreach_function_ty function, void *data)
+{
+  const char *start = dirs;
 
-  if (gettextdatadirs != NULL)
+  /* Count the number of valid components in GETTEXTDATADIRS.  */
+  while (*start != '\0')
     {
-      const char *start = gettextdatadirs;
+      char *end = strchrnul (start, ':');
 
-      /* Count the number of valid elements in GETTEXTDATADIRS.  */
-      while (*start != '\0')
-        {
-          char *end = strchrnul (start, ':');
+      /* Skip empty component.  */
+      if (start != end)
+        function (start, end - start, data);
 
-          /* Skip empty element.  */
-          if (start != end)
-            n_dirs++;
+      if (*end == '\0')
+        break;
 
-          if (*end == '\0')
-            break;
+      start = end + 1;
+    }
+}
 
-          start = end + 1;
-        }
+static void
+increment (const char *dir, size_t len, void *data)
+{
+  size_t *count = data;
+  (*count)++;
+}
+
+static void
+fill (const char *dir, size_t len, void *data)
+{
+  struct path_array_ty *array = data;
+  char *base, *name;
+
+  base = xmemdup0 (dir, len);
+  if (array->sub == NULL)
+    name = base;
+  else
+    {
+      name = xconcatenated_filename (base, array->sub, NULL);
+      free (base);
     }
 
-  result = XCALLOC (n_dirs + 1, char *);
+  array->ptr[array->len++] = name;
+}
+
+/* Find the standard search path for data files.  Returns a NULL
+   terminated list of strings.  */
+char **
+get_search_path (const char *sub)
+{
+  const char *gettextdatadir;
+  const char *gettextdatadirs;
+  struct path_array_ty array;
+  char *base, *name;
+  size_t count = 2;
+
+  gettextdatadirs = getenv ("GETTEXTDATADIRS");
+  if (gettextdatadirs != NULL)
+    foreach_components (gettextdatadirs, increment, &count);
 
-  n_dirs = 0;
+  gettextdatadirs = getenv ("XDG_DATA_DIRS");
+  if (gettextdatadirs != NULL)
+    foreach_components (gettextdatadirs, increment, &count);
+
+  array.ptr = XCALLOC (count + 1, char *);
+  array.len = 0;
+  array.sub = sub;
 
   gettextdatadir = getenv ("GETTEXTDATADIR");
   if (gettextdatadir == NULL || gettextdatadir[0] == '\0')
-    gettextdatadir = GETTEXTDATADIR;
+    /* Make it possible to override the locator file location.  This
+       is necessary for running the testsuite before "make
+       install".  */
+    gettextdatadir = relocate (GETTEXTDATADIR);
 
-  if (name == NULL)
-    dir = xstrdup (gettextdatadir);
+  if (sub == NULL)
+    name = xstrdup (gettextdatadir);
   else
-    dir = xconcatenated_filename (gettextdatadir, name, NULL);
-  result[n_dirs++] = dir;
+    name = xconcatenated_filename (gettextdatadir, sub, NULL);
+  array.ptr[array.len++] = name;
 
+  gettextdatadirs = getenv ("GETTEXTDATADIRS");
   if (gettextdatadirs != NULL)
-    {
-      const char *start = gettextdatadirs;
-
-      /* Count the number of valid elements in GETTEXTDATADIRS.  */
-      while (*start != '\0')
-        {
-          char *end = strchrnul (start, ':');
-
-          /* Skip empty element.  */
-          if (start != end)
-            {
-              base = xmemdup0 (start, end - start);
-              if (name == NULL)
-                dir = base;
-              else
-                {
-                  dir = xconcatenated_filename (base, name, NULL);
-                  free (base);
-                }
-              result[n_dirs++] = dir;
-            }
-
-          if (*end == '\0')
-            break;
-
-          start = end + 1;
-        }
-    }
+    foreach_components (gettextdatadirs, fill, &array);
+
+  gettextdatadirs = getenv ("XDG_DATA_DIRS");
+  if (gettextdatadirs != NULL)
+    foreach_components (gettextdatadirs, fill, &array);
 
+  /* Append version specific directory.  */
   base = xasprintf ("%s%s", gettextdatadir, PACKAGE_SUFFIX);
-  if (name == NULL)
-    dir = base;
+  if (sub == NULL)
+    name = base;
   else
     {
-      dir = xconcatenated_filename (base, name, NULL);
+      name = xconcatenated_filename (base, sub, NULL);
       free (base);
     }
-  result[n_dirs++] = dir;
+  array.ptr[array.len++] = name;
 
-  return result;
+  return array.ptr;
 }
index fc11d0c8f339d1fe4d0e163bad017f92b1d3acd6..6587d2320cf87c6df1889594537addad78afbc68 100644 (file)
@@ -25,9 +25,9 @@ extern "C" {
 
 
 /* Find the standard search path for data files.  Returns a NULL
-   terminated list of strings.  If NAME is not NULL, append it to each
-   directory.  Note that it does not resolve relocated pathnames.  */
-extern char **get_search_path (const char *name);
+   terminated list of strings.  If SUB is not NULL, append it to each
+   directory.  */
+extern char **get_search_path (const char *sub);
 
 
 #ifdef __cplusplus
index f67ec21f44d847eda6a5d4f5f94e3a6a76c68828..fc86d9ce36a6bbcfcd08c0480b2472a7fff75c0b 100644 (file)
@@ -739,18 +739,7 @@ xgettext cannot work without keywords to look for"));
       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);
-        }
+        locating_rule_list_add_from_directory (its_locating_rules, *dirs);
     }
 
   /* Determine extractor from language.  */