1 /* Reading C# satellite assemblies.
2 Copyright (C) 2003-2004, 2006-2008, 2011, 2015 Free Software
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-csharp.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 C# satellite assembly can only be manipulated by a C# execution engine.
47 So we start a C# process to execute the DumpResource program, and read its
48 output, which is .po format without comments. */
53 msgdomain_list_ty *mdlp;
57 execute_and_read_po_output (const char *progname,
58 const char *prog_path, char **prog_argv,
61 struct locals *l = (struct locals *) private_data;
67 /* Open a pipe to the C# execution engine. */
68 child = create_pipe_in (progname, prog_path, prog_argv, DEV_NULL, false,
71 fp = fdopen (fd[0], "r");
73 error (EXIT_FAILURE, errno, _("fdopen() failed"));
75 /* Read the message list. */
76 l->mdlp = read_catalog_stream (fp, "(pipe)", "(pipe)", &input_format_po);
80 /* Remove zombie process from process list, and retrieve exit status. */
82 wait_subprocess (child, progname, false, false, true, true, NULL);
84 error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"),
85 progname, exitstatus);
92 msgdomain_read_csharp (const char *resource_name, const char *locale_name,
93 const char *directory)
97 const char *gettextexedir;
98 const char *gettextlibdir;
100 const char *libdirs[1];
101 struct locals locals;
103 /* Assign a default value to the resource name. */
104 if (resource_name == NULL)
105 resource_name = "Messages";
107 /* Convert the locale name to a .NET specific culture name. */
108 culture_name = xstrdup (locale_name);
111 for (p = culture_name; *p != '\0'; p++)
114 if (strncmp (culture_name, "sr-CS", 5) == 0)
115 memcpy (culture_name, "sr-SP", 5);
116 p = strchr (culture_name, '@');
119 if (strcmp (p, "@latin") == 0)
121 else if (strcmp (p, "@cyrillic") == 0)
124 if (strcmp (culture_name, "sr-SP") == 0)
127 culture_name = xstrdup ("sr-SP-Latn");
129 else if (strcmp (culture_name, "uz-UZ") == 0)
132 culture_name = xstrdup ("uz-UZ-Latn");
136 /* Prepare arguments. */
138 args[1] = resource_name;
139 args[2] = culture_name;
142 /* Make it possible to override the .exe location. This is
143 necessary for running the testsuite before "make install". */
144 gettextexedir = getenv ("GETTEXTCSHARPEXEDIR");
145 if (gettextexedir == NULL || gettextexedir[0] == '\0')
146 gettextexedir = relocate (LIBDIR "/gettext");
148 /* Make it possible to override the .dll location. This is
149 necessary for running the testsuite before "make install". */
150 gettextlibdir = getenv ("GETTEXTCSHARPLIBDIR");
151 if (gettextlibdir == NULL || gettextlibdir[0] == '\0')
152 gettextlibdir = relocate (LIBDIR);
154 /* Dump the resource and retrieve the resulting output. */
156 xconcatenated_filename (gettextexedir, "msgunfmt.net", ".exe");
157 libdirs[0] = gettextlibdir;
158 if (execute_csharp_program (assembly_path, libdirs, 1,
161 execute_and_read_po_output, &locals))
162 /* An error message should already have been provided. */
165 free (assembly_path);