#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "read-java.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "msgunfmt.h"
#include "relocatable.h"
#include "javaexec.h"
#include "pipe.h"
#include "wait-process.h"
#include "read-po.h"
#include "error.h"
#include "exit.h"
#include "gettext.h"
#define _(str) gettext (str)
struct locals
{
msgdomain_list_ty *mdlp;
};
static bool
execute_and_read_po_output (const char *progname,
const char *prog_path, char **prog_argv,
void *private_data)
{
struct locals *l = (struct locals *) private_data;
pid_t child;
int fd[1];
FILE *fp;
int exitstatus;
child = create_pipe_in (progname, prog_path, prog_argv, DEV_NULL, false,
true, true, fd);
fp = fdopen (fd[0], "r");
if (fp == NULL)
error (EXIT_FAILURE, errno, _("fdopen() failed"));
l->mdlp = read_po (fp, "(pipe)", "(pipe)");
fclose (fp);
exitstatus = wait_subprocess (child, progname, false, true, true);
if (exitstatus != 0)
error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"),
progname, exitstatus);
return false;
}
msgdomain_list_ty *
msgdomain_read_java (const char *resource_name, const char *locale_name)
{
const char *class_name = "gnu.gettext.DumpResource";
const char *gettextjexedir;
const char *gettextjar;
const char *args[3];
struct locals locals;
#if USEJEXE
gettextjexedir = getenv ("GETTEXTJEXEDIR");
if (gettextjexedir == NULL || gettextjexedir[0] == '\0')
gettextjexedir = relocate (GETTEXTJEXEDIR);
#else
gettextjexedir = NULL;
#endif
gettextjar = getenv ("GETTEXTJAR");
if (gettextjar == NULL || gettextjar[0] == '\0')
gettextjar = GETTEXTJAR;
if (resource_name == NULL)
resource_name = "Messages";
args[0] = resource_name;
if (locale_name != NULL)
{
args[1] = locale_name;
args[2] = NULL;
}
else
args[1] = NULL;
if (execute_java_class (class_name, &gettextjar, 1, false, gettextjexedir,
args,
verbose, false,
execute_and_read_po_output, &locals))
exit (EXIT_FAILURE);
return locals.mdlp;
}