]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
its: Prepare for shipping ITS files
authorDaiki Ueno <ueno@gnu.org>
Wed, 30 Sep 2015 01:43:15 +0000 (10:43 +0900)
committerDaiki Ueno <ueno@gnu.org>
Wed, 30 Sep 2015 01:43:15 +0000 (10:43 +0900)
gettext-tools/configure.ac
gettext-tools/src/locating-rule.c
gettext-tools/src/locating-rule.h
gettext-tools/src/xgettext.c
gettext-tools/tests/init-env.in

index ff0f2d10f6d3dbd9edb12f5bccad3bb1a53382a7..8d930ca508a47160308d679321440afddf73721d 100644 (file)
@@ -461,6 +461,11 @@ AC_SUBST([ARCHIVE_FORMAT])
 ARCHIVE_VERSION=0.19.5
 AC_SUBST([ARCHIVE_VERSION])
 
+PACKAGE_SUFFIX="-$ARCHIVE_VERSION"
+AC_SUBST([PACKAGE_SUFFIX])
+AC_DEFINE_UNQUOTED(PACKAGE_SUFFIX, "$PACKAGE_SUFFIX",
+  [Define to the suffix of this package])
+
 dnl Check for tools needed for formatting the documentation.
 ac_aux_dir_abs=`cd $ac_aux_dir && pwd`
 AC_PATH_PROG([DVIPS], [dvips], [$ac_aux_dir_abs/missing dvips])
@@ -519,6 +524,8 @@ AC_CONFIG_FILES([intl/Makefile:../gettext-runtime/intl/Makefile.in], [
   mv intl/Makefile.tmp intl/Makefile
   ])
 
+AC_CONFIG_FILES([its/Makefile])
+
 AC_CONFIG_FILES([gnulib-lib/Makefile])
 
 AC_CONFIG_FILES([libgrep/Makefile])
index 3d42d02672ba69c6bcab6891cfb2fa5404356ef0..15c3308ea33c6efda8009baadd3b9900959a5198 100644 (file)
@@ -74,8 +74,6 @@ struct locating_rule_ty
 
 struct locating_rule_list_ty
 {
-  char *base;
-
   struct locating_rule_ty *items;
   size_t nitems;
   size_t nitems_max;
@@ -157,7 +155,7 @@ locating_rule_match (struct locating_rule_ty *rule,
   return NULL;
 }
 
-char *
+const char *
 locating_rule_list_locate (struct locating_rule_list_ty *rules,
                            const char *path)
 {
@@ -168,7 +166,7 @@ locating_rule_list_locate (struct locating_rule_list_ty *rules,
     {
       target = locating_rule_match (&rules->items[i], path);
       if (target != NULL)
-        return xconcatenated_filename (rules->base, target, NULL);
+        return target;
     }
 
   return NULL;
@@ -306,7 +304,7 @@ locating_rule_list_add_file (struct locating_rule_list_ty *rules,
   return true;
 }
 
-static bool
+bool
 locating_rule_list_add_directory (struct locating_rule_list_ty *rules,
                                   const char *directory)
 {
@@ -349,16 +347,13 @@ locating_rule_list_add_directory (struct locating_rule_list_ty *rules,
 }
 
 struct locating_rule_list_ty *
-locating_rule_list_alloc (const char *base, const char *directory)
+locating_rule_list_alloc (void)
 {
   struct locating_rule_list_ty *result;
 
   xmlCheckVersion (LIBXML_VERSION);
 
   result = XCALLOC (1, struct locating_rule_list_ty);
-  result->base = xstrdup (base);
-
-  locating_rule_list_add_directory (result, directory);
 
   return result;
 }
@@ -366,8 +361,6 @@ locating_rule_list_alloc (const char *base, const char *directory)
 void
 locating_rule_list_destroy (struct locating_rule_list_ty *rules)
 {
-  free (rules->base);
-
   while (rules->nitems-- > 0)
     locating_rule_destroy (&rules->items[rules->nitems]);
   free (rules->items);
index 91785f8e9d2b23c1d42dde4ce30ee6788ef48dcd..9f0f25667bf1983c6b2ce5391bd848faf2b33283 100644 (file)
@@ -27,18 +27,20 @@ extern "C" {
 
 typedef struct locating_rule_list_ty locating_rule_list_ty;
 
-/* Creates a fresh locating_rule_list_ty with the base URI BASE, and loads
-   the locating rules from the files in DIRECTORY.  */
-extern struct locating_rule_list_ty *locating_rule_list_alloc (const char *base,
-                                                     const char *directory);
+/* Creates a fresh locating_rule_list_ty.  */
+extern struct locating_rule_list_ty *locating_rule_list_alloc (void);
+
+extern bool
+       locating_rule_list_add_directory (locating_rule_list_ty *rules,
+                                         const char *directory);
 
 /* Determines the location of resource associated with PATH, accoding
    to the loaded locating rules.  */
-extern char *locating_rule_list_locate (locating_rule_list_ty *locators,
-                                   const char *path);
+extern const char *locating_rule_list_locate (locating_rule_list_ty *rules,
+                                              const char *path);
 
-/* Releases memory allocated for LOCATORS.  */
-extern void locating_rule_list_free (locating_rule_list_ty *locators);
+/* Releases memory allocated for RULES.  */
+extern void locating_rule_list_free (locating_rule_list_ty *rules);
 
 #ifdef __cplusplus
 }
index e91a835c66ea05938ce32701955f43cba76a8ce4..b241151b75872436bb18124dde065f741a48af83 100644 (file)
@@ -78,6 +78,8 @@
 /* A convenience macro.  I don't like writing gettext() every time.  */
 #define _(str) gettext (str)
 
+#define SIZEOF(a) (sizeof(a) / sizeof(a[0]))
+
 
 #include "x-c.h"
 #include "x-po.h"
@@ -316,6 +318,7 @@ main (int argc, char *argv[])
   bool sort_by_msgid = false;
   bool sort_by_filepos = false;
   bool its = false;
+  char *its_dirs[2] = { NULL, NULL };
   const char *file_name;
   const char *files_from = NULL;
   string_list_ty *file_list;
@@ -719,7 +722,7 @@ xgettext cannot work without keywords to look for"));
   if (its)
     {
       const char *gettextdatadir;
-      char *itsdir;
+      char *versioned_gettextdatadir;
 
       /* Make it possible to override the locator file location.  This
          is necessary for running the testsuite before "make
@@ -728,9 +731,17 @@ xgettext cannot work without keywords to look for"));
       if (gettextdatadir == NULL || gettextdatadir[0] == '\0')
         gettextdatadir = relocate (GETTEXTDATADIR);
 
-      itsdir = xconcatenated_filename (gettextdatadir, "its", NULL);
-      its_locating_rules = locating_rule_list_alloc (itsdir, itsdir);
-      free (itsdir);
+      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_directory (its_locating_rules, its_dirs[i]);
     }
 
   /* Determine extractor from language.  */
@@ -872,20 +883,30 @@ This version was built without iconv()."),
 
           if (language == NULL && its_locating_rules != NULL)
             {
-              char *its_filename = NULL;
-
-              its_filename = locating_rule_list_locate (its_locating_rules,
-                                                        filename);
-              if (its_filename != NULL)
+              const char *its_basename =
+                locating_rule_list_locate (its_locating_rules, filename);
+              if (its_basename != NULL)
                 {
+                  size_t j;
+
                   its_rules = its_rule_list_alloc ();
-                  if (!its_rule_list_add_file (its_rules, its_filename))
+                  for (j = 0; j < SIZEOF (its_dirs); j++)
+                    {
+                      char *its_filename =
+                        xconcatenated_filename (its_dirs[j], its_basename,
+                                                NULL);
+                      bool result =
+                        its_rule_list_add_file (its_rules, its_filename);
+                      free (its_filename);
+                      if (result)
+                        break;
+                    }
+                  if (j == SIZEOF (its_dirs))
                     {
                       its_rule_list_free (its_rules);
                       its_rules = NULL;
                     }
                 }
-              free (its_filename);
             }
 
           if (its_rules == NULL)
@@ -961,6 +982,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++)
+    free (its_dirs[i]);
+
   exit (EXIT_SUCCESS);
 }
 
index 1ee47756106f0c28ed507ab0c57aafbc8971d8d2..b5d55d0cc9acceb10d1351b71c6404553f644d80 100644 (file)
@@ -1,6 +1,9 @@
 # Variable needed by LTLIBINTL.
 top_builddir=../..
 
+# Variable needed by xgettext.
+GETTEXTDATADIR="$top_builddir"
+
 OBJEXT="@OBJEXT@"
 EXEEXT="@EXEEXT@"
 CC="@CC@"