]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Reading C# resources.
authorBruno Haible <bruno@clisp.org>
Fri, 9 Jan 2004 10:59:16 +0000 (10:59 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:11:36 +0000 (12:11 +0200)
gettext-tools/src/read-resources.c [new file with mode: 0644]
gettext-tools/src/read-resources.h [new file with mode: 0644]

diff --git a/gettext-tools/src/read-resources.c b/gettext-tools/src/read-resources.c
new file mode 100644 (file)
index 0000000..600b4ff
--- /dev/null
@@ -0,0 +1,137 @@
+/* Reading C# .resources files.
+   Copyright (C) 2003 Free Software Foundation, Inc.
+   Written by Bruno Haible <bruno@clisp.org>, 2003.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+/* Specification.  */
+#include "read-resources.h"
+
+#include <errno.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "msgunfmt.h"
+#include "relocatable.h"
+#include "csharpexec.h"
+#include "pipe.h"
+#include "wait-process.h"
+#include "read-po.h"
+#include "message.h"
+#include "pathname.h"
+#include "error.h"
+#include "exit.h"
+#include "gettext.h"
+
+#define _(str) gettext (str)
+
+
+/* A .resources file has such a complex format that it's most easily read
+   through the C# class ResourceReader.  So we start a C# process to execute
+   the DumpResource program, and read its output, which is .po format without
+   comments.  */
+
+struct locals
+{
+  /* OUT */
+  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;
+
+  /* Open a pipe to the C# execution engine.  */
+  child = create_pipe_in (progname, prog_path, prog_argv, NULL, false,
+                         true, true, fd);
+
+  fp = fdopen (fd[0], "r");
+  if (fp == NULL)
+    error (EXIT_FAILURE, errno, _("fdopen() failed"));
+
+  /* Read the message list.  */
+  l->mdlp = read_po (fp, "(pipe)", "(pipe)");
+
+  fclose (fp);
+
+  /* Remove zombie process from process list, and retrieve exit status.  */
+  exitstatus = wait_subprocess (child, progname, false, false, true, true);
+  if (exitstatus != 0)
+    error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"),
+          progname, exitstatus);
+
+  return false;
+}
+
+
+void
+read_resources_file (message_list_ty *mlp, const char *filename)
+{
+  const char *args[2];
+  const char *gettextexedir;
+  const char *gettextlibdir;
+  char *assembly_path;
+  const char *libdirs[1];
+  struct locals locals;
+
+  /* Prepare arguments.  */
+  args[0] = filename;
+  args[1] = NULL;
+
+  /* Make it possible to override the .exe location.  This is
+     necessary for running the testsuite before "make install".  */
+  gettextexedir = getenv ("GETTEXTCSHARPEXEDIR");
+  if (gettextexedir == NULL || gettextexedir[0] == '\0')
+    gettextexedir = relocate (LIBDIR "/gettext");
+
+  /* Make it possible to override the .dll location.  This is
+     necessary for running the testsuite before "make install".  */
+  gettextlibdir = getenv ("GETTEXTCSHARPLIBDIR");
+  if (gettextlibdir == NULL || gettextlibdir[0] == '\0')
+    gettextlibdir = relocate (LIBDIR);
+
+  /* Dump the resource and retrieve the resulting output.  */
+  assembly_path = concatenated_pathname (gettextexedir, "msgunfmt.net", ".exe");
+  libdirs[0] = gettextlibdir;
+  if (execute_csharp_program (assembly_path, libdirs, 1,
+                             args,
+                             verbose, false,
+                             execute_and_read_po_output, &locals))
+    /* An error message should already have been provided.  */
+    exit (EXIT_FAILURE);
+
+  /* Add the output to mlp.  */
+  {
+    message_list_ty *read_mlp = locals.mdlp->item[0]->messages;
+    size_t j;
+
+    for (j = 0; j < read_mlp->nitems; j++)
+      message_list_append (mlp, read_mlp->item[j]);
+  }
+
+  free (assembly_path);
+}
diff --git a/gettext-tools/src/read-resources.h b/gettext-tools/src/read-resources.h
new file mode 100644 (file)
index 0000000..191e79e
--- /dev/null
@@ -0,0 +1,28 @@
+/* Reading C# .resources files.
+   Copyright (C) 2003 Free Software Foundation, Inc.
+   Written by Bruno Haible <bruno@clisp.org>, 2003.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+#ifndef _READ_RESOURCES_H
+#define _READ_RESOURCES_H
+
+#include "message.h"
+
+/* Reads an existing binary C# .resources file and adds the messages
+   to mlp.  */
+extern void read_resources_file (message_list_ty *mlp, const char *filename);
+
+#endif /* _READ_RESOURCES_H */