+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
@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,
+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
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;
{ "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 },
byteswap = endianness ^ ENDIANNESS;
}
break;
+ case CHAR_MAX + 14: /* --source */
+ java_output_source = true;
+ break;
default:
usage (EXIT_FAILURE);
break;
{
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)
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\
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;
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)
/* 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)
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++)
{
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. */
freea (subdirs);
free (class_name);
quit2:
- cleanup_temp_dir (tmpdir);
+ if (tmpdir != NULL)
+ cleanup_temp_dir (tmpdir);
quit1:
return retval;
}
const char *resource_name,
const char *locale_name,
const char *directory,
- bool assume_java2);
+ bool assume_java2,
+ bool output_source);
#endif /* _WRITE_JAVA_H */