]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
msgfmt: Add --source option to generate .java file instead of .class
authorAurélien Gâteau <mail@agateau.com>
Sat, 22 Mar 2014 23:15:05 +0000 (00:15 +0100)
committerDaiki Ueno <ueno@gnu.org>
Wed, 26 Mar 2014 03:18:37 +0000 (12:18 +0900)
gettext-tools/doc/ChangeLog
gettext-tools/doc/msgfmt.texi
gettext-tools/src/ChangeLog
gettext-tools/src/msgfmt.c
gettext-tools/src/write-java.c
gettext-tools/src/write-java.h

index fe21c4e34c9ec0486436d49a7fa5ce3d7648b61c..82419e92e3de7431d94ae30314cab1bed1a5f68a 100644 (file)
@@ -1,3 +1,7 @@
+2014-03-26  Aurélien Gâteau <mail@agateau.com>  (tiny change)
+
+       * msgfmt.texi: Document --source option.
+
 2014-03-25  Daiki Ueno  <ueno@gnu.org>
 
        * msgattrib.texi: Document the optional argument of
index 2a0dd6f4bcdab7e0a78cdcf224a89d8549775927..df34c275a9fced21edcad4c0aa8c9ca58fa2bae3 100644 (file)
@@ -107,6 +107,10 @@ or a combined language and country specification of the form @var{ll_CC}.
 @opindex -d@r{, @code{msgfmt} option}
 Specify the base directory of classes directory hierarchy.
 
+@item --source
+@opindex --source@r{, @code{msgfmt} option}
+Produce a .java source file, instead of a compiled .class file.
+
 @end table
 
 The class name is determined by appending the locale name to the resource name,
index 8db372534cc5b21adeae386076b6fd09544dfbe4..ae10478b40af0bb7f7d25f8a68094ca8ba095e8b 100644 (file)
@@ -1,3 +1,13 @@
+2014-03-26  Aurélien Gâteau <mail@agateau.com>  (tiny change)
+
+       msgfmt: Add --source option to generate .java file instead of .class
+       * msgfmt.c (java_output_source): New variable.
+       (long_options, main, usage): Add --source option.
+       * write-java.h (msgdomain_write_java): Add OUTPUT_SOURCE argument.
+       * write-java.c (msgdomain_write_java): Generate .java file instead
+       of .class if OUTPUT_SOURCE argument is given.
+       Reported at <https://savannah.gnu.org/bugs/?41766>.
+
 2014-03-25  Daiki Ueno  <ueno@gnu.org>
 
        Extend --add-location option to suppress line number output
index e51319d7f49edfbd6d6f88b982b1fa9524d939e9..e414346450497c95c3ebf509b5a82888d53c87db 100644 (file)
@@ -76,6 +76,7 @@ static bool assume_java2;
 static const char *java_resource_name;
 static const char *java_locale_name;
 static const char *java_class_directory;
+static bool java_output_source;
 
 /* C# mode output file specification.  */
 static bool csharp_mode;
@@ -168,6 +169,7 @@ static const struct option long_options[] =
   { "properties-input", no_argument, NULL, 'P' },
   { "qt", no_argument, NULL, CHAR_MAX + 9 },
   { "resource", required_argument, NULL, 'r' },
+  { "source", no_argument, NULL, CHAR_MAX + 14 },
   { "statistics", no_argument, &do_statistics, 1 },
   { "strict", no_argument, NULL, 'S' },
   { "stringtable-input", no_argument, NULL, CHAR_MAX + 8 },
@@ -353,6 +355,9 @@ main (int argc, char *argv[])
           byteswap = endianness ^ ENDIANNESS;
         }
         break;
+      case CHAR_MAX + 14: /* --source */
+        java_output_source = true;
+        break;
       default:
         usage (EXIT_FAILURE);
         break;
@@ -556,7 +561,8 @@ There is NO WARRANTY, to the extent permitted by law.\n\
         {
           if (msgdomain_write_java (domain->mlp, canon_encoding,
                                     java_resource_name, java_locale_name,
-                                    java_class_directory, assume_java2))
+                                    java_class_directory, assume_java2,
+                                    java_output_source))
             exit_status = EXIT_FAILURE;
         }
       else if (csharp_mode)
@@ -705,6 +711,8 @@ Output file location in Java mode:\n"));
       printf (_("\
   -l, --locale=LOCALE         locale name, either language or language_COUNTRY\n"));
       printf (_("\
+      --source                produce a .java file, instead of a .class file\n"));
+      printf (_("\
   -d DIRECTORY                base directory of classes directory hierarchy\n"));
       printf (_("\
 The class name is determined by appending the locale name to the resource name,\n\
index 5298e461629653f68ea16c276d3920e3d8514c34..9cf4054c60a3f0baec722f33a1a1925c9c85917f 100644 (file)
@@ -1044,7 +1044,8 @@ int
 msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding,
                       const char *resource_name, const char *locale_name,
                       const char *directory,
-                      bool assume_java2)
+                      bool assume_java2,
+                      bool output_source)
 {
   int retval;
   struct temp_dir *tmpdir;
@@ -1054,6 +1055,7 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding,
   char *java_file_name;
   FILE *java_file;
   const char *java_sources[1];
+  const char *source_dir_name;
 
   /* If no entry for this resource/domain, don't even create the file.  */
   if (mlp->nitems == 0)
@@ -1064,10 +1066,19 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding,
   /* Convert the messages to Unicode.  */
   iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL);
 
-  /* Create a temporary directory where we can put the Java file.  */
-  tmpdir = create_temp_dir ("msg", NULL, false);
-  if (tmpdir == NULL)
-    goto quit1;
+  if (output_source)
+    {
+      tmpdir = NULL;
+      source_dir_name = directory;
+    }
+  else
+    {
+      /* Create a temporary directory where we can put the Java file.  */
+      tmpdir = create_temp_dir ("msg", NULL, false);
+      if (tmpdir == NULL)
+        goto quit1;
+      source_dir_name = tmpdir->dir_name;
+    }
 
   /* Assign a default value to the resource name.  */
   if (resource_name == NULL)
@@ -1092,7 +1103,7 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding,
     const char *last_dir;
     int i;
 
-    last_dir = tmpdir->dir_name;
+    last_dir = source_dir_name;
     p = resource_name;
     for (i = 0; i < ndots; i++)
       {
@@ -1117,6 +1128,40 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding,
       java_file_name = xconcatenated_filename (last_dir, p, ".java");
   }
 
+  /* If OUTPUT_SOURCE, write the Java file in DIRECTORY and return.  */
+  if (output_source)
+    {
+      int i;
+
+      for (i = 0; i < ndots; i++)
+        {
+          if (mkdir (subdirs[i], S_IRUSR | S_IWUSR | S_IXUSR) < 0)
+            {
+              error (0, errno, _("failed to create \"%s\""), subdirs[i]);
+              goto quit3;
+            }
+        }
+
+      java_file = fopen (java_file_name, "w");
+      if (java_file == NULL)
+        {
+          error (0, errno, _("failed to create \"%s\""), java_file_name);
+          goto quit3;
+        }
+
+      write_java_code (java_file, class_name, mlp, assume_java2);
+
+      if (fwriteerror (java_file))
+        {
+          error (0, errno, _("error while writing \"%s\" file"),
+                 java_file_name);
+          goto quit3;
+        }
+
+      retval = 0;
+      goto quit3;
+    }
+
   /* Create the subdirectories.  This is needed because some older Java
      compilers verify that the source of class A.B.C really sits in a
      directory whose name ends in /A/B.  */
@@ -1182,7 +1227,8 @@ compilation of Java class failed, please try to set $JAVAC"));
   freea (subdirs);
   free (class_name);
  quit2:
-  cleanup_temp_dir (tmpdir);
+  if (tmpdir != NULL)
+    cleanup_temp_dir (tmpdir);
  quit1:
   return retval;
 }
index 830aa75f7f3e9d8bc80999c4d686137d0cd9cb23..4249edb61c21a22d41b36aa64cbd90a282f65af5 100644 (file)
@@ -33,6 +33,7 @@ extern int
                              const char *resource_name,
                              const char *locale_name,
                              const char *directory,
-                             bool assume_java2);
+                             bool assume_java2,
+                             bool output_source);
 
 #endif /* _WRITE_JAVA_H */