1
/* Writing C# .resources files.
2
Copyright (C) 2003, 2005, 2007-2009 Free Software Foundation, Inc.
3
Written by Bruno Haible <bruno@clisp.org>, 2003.
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 3 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <http://www.gnu.org/licenses/>. */
23
#include "write-resources.h"
33
#include "relocatable.h"
34
#include "csharpexec.h"
36
#include "wait-process.h"
39
#include "msgl-iconv.h"
40
#include "po-charset.h"
42
#include "concat-filename.h"
43
#include "fwriteerror.h"
46
#define _(str) gettext (str)
49
/* A .resources file has such a complex format that it's most easily generated
50
through the C# class ResourceWriter. So we start a C# process to execute
51
the WriteResource program, sending it the msgid/msgstr pairs as
52
NUL-terminated UTF-8 encoded strings. */
61
execute_writing_input (const char *progname,
62
const char *prog_path, char **prog_argv,
65
struct locals *l = (struct locals *) private_data;
71
/* Open a pipe to the C# execution engine. */
72
child = create_pipe_out (progname, prog_path, prog_argv, NULL, false,
75
fp = fdopen (fd[0], "wb");
77
error (EXIT_FAILURE, errno, _("fdopen() failed"));
79
/* Write the message list. */
81
message_list_ty *mlp = l->mlp;
84
for (j = 0; j < mlp->nitems; j++)
86
message_ty *mp = mlp->item[j];
88
fwrite (mp->msgid, 1, strlen (mp->msgid) + 1, fp);
89
fwrite (mp->msgstr, 1, strlen (mp->msgstr) + 1, fp);
94
error (EXIT_FAILURE, 0, _("error while writing to %s subprocess"),
97
/* Remove zombie process from process list, and retrieve exit status. */
98
/* He we can ignore SIGPIPE because WriteResource either writes to a file
99
- then it never gets SIGPIPE - or to standard output, and in the latter
100
case it has no side effects other than writing to standard output. */
102
wait_subprocess (child, progname, true, false, true, true, NULL);
104
error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"),
105
progname, exitstatus);
111
msgdomain_write_csharp_resources (message_list_ty *mlp,
112
const char *canon_encoding,
113
const char *domain_name,
114
const char *file_name)
116
/* If no entry for this domain don't even create the file. */
117
if (mlp->nitems != 0)
119
/* Determine whether mlp has entries with context. */
125
for (j = 0; j < mlp->nitems; j++)
126
if (mlp->item[j]->msgctxt != NULL)
130
multiline_error (xstrdup (""),
132
message catalog has context dependent translations\n\
133
but the C# .resources format doesn't support contexts\n")));
138
/* Determine whether mlp has plural entries. */
144
for (j = 0; j < mlp->nitems; j++)
145
if (mlp->item[j]->msgid_plural != NULL)
149
multiline_error (xstrdup (""),
151
message catalog has plural form translations\n\
152
but the C# .resources format doesn't support plural handling\n")));
157
/* Convert the messages to Unicode. */
158
iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL);
160
/* Execute the WriteResource program. */
163
const char *gettextexedir;
165
struct locals locals;
167
/* Prepare arguments. */
171
/* Make it possible to override the .exe location. This is
172
necessary for running the testsuite before "make install". */
173
gettextexedir = getenv ("GETTEXTCSHARPEXEDIR");
174
if (gettextexedir == NULL || gettextexedir[0] == '\0')
175
gettextexedir = relocate (LIBDIR "/gettext");
178
xconcatenated_filename (gettextexedir, "msgfmt.net", ".exe");
182
if (execute_csharp_program (assembly_path, NULL, 0,
185
execute_writing_input, &locals))
186
/* An error message should already have been provided. */
189
free (assembly_path);