From: Aurélien Gâteau Date: Sat, 22 Mar 2014 23:15:05 +0000 (+0100) Subject: msgfmt: Add --source option to generate .java file instead of .class X-Git-Tag: v0.19~132 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75638a4cd22832f58d368e0316dc1c0a4598bbbf;p=thirdparty%2Fgettext.git msgfmt: Add --source option to generate .java file instead of .class --- diff --git a/gettext-tools/doc/ChangeLog b/gettext-tools/doc/ChangeLog index fe21c4e34..82419e92e 100644 --- a/gettext-tools/doc/ChangeLog +++ b/gettext-tools/doc/ChangeLog @@ -1,3 +1,7 @@ +2014-03-26 Aurélien Gâteau (tiny change) + + * msgfmt.texi: Document --source option. + 2014-03-25 Daiki Ueno * msgattrib.texi: Document the optional argument of diff --git a/gettext-tools/doc/msgfmt.texi b/gettext-tools/doc/msgfmt.texi index 2a0dd6f4b..df34c275a 100644 --- a/gettext-tools/doc/msgfmt.texi +++ b/gettext-tools/doc/msgfmt.texi @@ -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, diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 8db372534..ae10478b4 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,13 @@ +2014-03-26 Aurélien Gâteau (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 . + 2014-03-25 Daiki Ueno Extend --add-location option to suppress line number output diff --git a/gettext-tools/src/msgfmt.c b/gettext-tools/src/msgfmt.c index e51319d7f..e41434645 100644 --- a/gettext-tools/src/msgfmt.c +++ b/gettext-tools/src/msgfmt.c @@ -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\ diff --git a/gettext-tools/src/write-java.c b/gettext-tools/src/write-java.c index 5298e4616..9cf4054c6 100644 --- a/gettext-tools/src/write-java.c +++ b/gettext-tools/src/write-java.c @@ -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; } diff --git a/gettext-tools/src/write-java.h b/gettext-tools/src/write-java.h index 830aa75f7..4249edb61 100644 --- a/gettext-tools/src/write-java.h +++ b/gettext-tools/src/write-java.h @@ -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 */