1 /* Reading C# .resources files.
2 Copyright (C) 2003, 2006-2008, 2011, 2015 Free Software Foundation,
4 Written by Bruno Haible <bruno@clisp.org>, 2003.
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "read-resources.h"
32 #include "relocatable.h"
33 #include "csharpexec.h"
34 #include "spawn-pipe.h"
35 #include "wait-process.h"
36 #include "read-catalog.h"
39 #include "concat-filename.h"
43 #define _(str) gettext (str)
46 /* A .resources file has such a complex format that it's most easily read
47 through the C# class ResourceReader. So we start a C# process to execute
48 the DumpResource program, and read its output, which is .po format without
54 msgdomain_list_ty *mdlp;
58 execute_and_read_po_output (const char *progname,
59 const char *prog_path, char **prog_argv,
62 struct locals *l = (struct locals *) private_data;
68 /* Open a pipe to the C# execution engine. */
69 child = create_pipe_in (progname, prog_path, prog_argv, NULL, false,
72 fp = fdopen (fd[0], "r");
74 error (EXIT_FAILURE, errno, _("fdopen() failed"));
76 /* Read the message list. */
77 l->mdlp = read_catalog_stream (fp, "(pipe)", "(pipe)", &input_format_po);
81 /* Remove zombie process from process list, and retrieve exit status. */
83 wait_subprocess (child, progname, false, false, true, true, NULL);
85 error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"),
86 progname, exitstatus);
93 read_resources_file (message_list_ty *mlp, const char *filename)
96 const char *gettextexedir;
97 const char *gettextlibdir;
99 const char *libdirs[1];
100 struct locals locals;
102 /* Prepare arguments. */
106 /* Make it possible to override the .exe location. This is
107 necessary for running the testsuite before "make install". */
108 gettextexedir = getenv ("GETTEXTCSHARPEXEDIR");
109 if (gettextexedir == NULL || gettextexedir[0] == '\0')
110 gettextexedir = relocate (LIBDIR "/gettext");
112 /* Make it possible to override the .dll location. This is
113 necessary for running the testsuite before "make install". */
114 gettextlibdir = getenv ("GETTEXTCSHARPLIBDIR");
115 if (gettextlibdir == NULL || gettextlibdir[0] == '\0')
116 gettextlibdir = relocate (LIBDIR);
118 /* Dump the resource and retrieve the resulting output. */
120 xconcatenated_filename (gettextexedir, "msgunfmt.net", ".exe");
121 libdirs[0] = gettextlibdir;
122 if (execute_csharp_program (assembly_path, libdirs, 1,
125 execute_and_read_po_output, &locals))
126 /* An error message should already have been provided. */
129 /* Add the output to mlp. */
131 message_list_ty *read_mlp = locals.mdlp->item[0]->messages;
134 for (j = 0; j < read_mlp->nitems; j++)
135 message_list_append (mlp, read_mlp->item[j]);
138 free (assembly_path);