1 /* Reading C# satellite assemblies.
2 Copyright (C) 2003-2004 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 2, or (at your option)
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, write to the Free Software Foundation,
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 #include "read-csharp.h"
32 #include "relocatable.h"
33 #include "csharpexec.h"
35 #include "wait-process.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_po (fp
, "(pipe)", "(pipe)");
80 /* Remove zombie process from process list, and retrieve exit status. */
81 exitstatus
= wait_subprocess (child
, progname
, false, false, true, true);
83 error (EXIT_FAILURE
, 0, _("%s subprocess failed with exit code %d"),
84 progname
, exitstatus
);
91 msgdomain_read_csharp (const char *resource_name
, const char *locale_name
,
92 const char *directory
)
96 const char *gettextexedir
;
97 const char *gettextlibdir
;
99 const char *libdirs
[1];
100 struct locals locals
;
102 /* Assign a default value to the resource name. */
103 if (resource_name
== NULL
)
104 resource_name
= "Messages";
106 /* Convert the locale name to a .NET specific culture name. */
107 culture_name
= xstrdup (locale_name
);
110 for (p
= culture_name
; *p
!= '\0'; p
++)
113 if (strncmp (culture_name
, "sr-CS", 5) == 0)
114 memcpy (culture_name
, "sr-SP", 5);
115 p
= strchr (culture_name
, '@');
118 if (strcmp (p
, "@latin") == 0)
120 else if (strcmp (p
, "@cyrillic") == 0)
123 if (strcmp (culture_name
, "sr-SP") == 0)
126 culture_name
= xstrdup ("sr-SP-Latn");
128 else if (strcmp (culture_name
, "uz-UZ") == 0)
131 culture_name
= xstrdup ("uz-UZ-Latn");
135 /* Prepare arguments. */
137 args
[1] = resource_name
;
138 args
[2] = culture_name
;
141 /* Make it possible to override the .exe location. This is
142 necessary for running the testsuite before "make install". */
143 gettextexedir
= getenv ("GETTEXTCSHARPEXEDIR");
144 if (gettextexedir
== NULL
|| gettextexedir
[0] == '\0')
145 gettextexedir
= relocate (LIBDIR
"/gettext");
147 /* Make it possible to override the .dll location. This is
148 necessary for running the testsuite before "make install". */
149 gettextlibdir
= getenv ("GETTEXTCSHARPLIBDIR");
150 if (gettextlibdir
== NULL
|| gettextlibdir
[0] == '\0')
151 gettextlibdir
= relocate (LIBDIR
);
153 /* Dump the resource and retrieve the resulting output. */
154 assembly_path
= concatenated_pathname (gettextexedir
, "msgunfmt.net", ".exe");
155 libdirs
[0] = gettextlibdir
;
156 if (execute_csharp_program (assembly_path
, libdirs
, 1,
159 execute_and_read_po_output
, &locals
))
160 /* An error message should already have been provided. */
163 free (assembly_path
);