No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / gettext / gettext-tools / src / read-resources.c
blob600b4ff07b8bc5433bb002fd0c687f8b8563659e
1 /* Reading C# .resources files.
2 Copyright (C) 2003 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)
8 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, write to the Free Software Foundation,
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
23 /* Specification. */
24 #include "read-resources.h"
26 #include <errno.h>
27 #include <stdbool.h>
28 #include <stdlib.h>
29 #include <stdio.h>
31 #include "msgunfmt.h"
32 #include "relocatable.h"
33 #include "csharpexec.h"
34 #include "pipe.h"
35 #include "wait-process.h"
36 #include "read-po.h"
37 #include "message.h"
38 #include "pathname.h"
39 #include "error.h"
40 #include "exit.h"
41 #include "gettext.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
49 comments. */
51 struct locals
53 /* OUT */
54 msgdomain_list_ty *mdlp;
57 static bool
58 execute_and_read_po_output (const char *progname,
59 const char *prog_path, char **prog_argv,
60 void *private_data)
62 struct locals *l = (struct locals *) private_data;
63 pid_t child;
64 int fd[1];
65 FILE *fp;
66 int exitstatus;
68 /* Open a pipe to the C# execution engine. */
69 child = create_pipe_in (progname, prog_path, prog_argv, NULL, false,
70 true, true, fd);
72 fp = fdopen (fd[0], "r");
73 if (fp == NULL)
74 error (EXIT_FAILURE, errno, _("fdopen() failed"));
76 /* Read the message list. */
77 l->mdlp = read_po (fp, "(pipe)", "(pipe)");
79 fclose (fp);
81 /* Remove zombie process from process list, and retrieve exit status. */
82 exitstatus = wait_subprocess (child, progname, false, false, true, true);
83 if (exitstatus != 0)
84 error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"),
85 progname, exitstatus);
87 return false;
91 void
92 read_resources_file (message_list_ty *mlp, const char *filename)
94 const char *args[2];
95 const char *gettextexedir;
96 const char *gettextlibdir;
97 char *assembly_path;
98 const char *libdirs[1];
99 struct locals locals;
101 /* Prepare arguments. */
102 args[0] = filename;
103 args[1] = NULL;
105 /* Make it possible to override the .exe location. This is
106 necessary for running the testsuite before "make install". */
107 gettextexedir = getenv ("GETTEXTCSHARPEXEDIR");
108 if (gettextexedir == NULL || gettextexedir[0] == '\0')
109 gettextexedir = relocate (LIBDIR "/gettext");
111 /* Make it possible to override the .dll location. This is
112 necessary for running the testsuite before "make install". */
113 gettextlibdir = getenv ("GETTEXTCSHARPLIBDIR");
114 if (gettextlibdir == NULL || gettextlibdir[0] == '\0')
115 gettextlibdir = relocate (LIBDIR);
117 /* Dump the resource and retrieve the resulting output. */
118 assembly_path = concatenated_pathname (gettextexedir, "msgunfmt.net", ".exe");
119 libdirs[0] = gettextlibdir;
120 if (execute_csharp_program (assembly_path, libdirs, 1,
121 args,
122 verbose, false,
123 execute_and_read_po_output, &locals))
124 /* An error message should already have been provided. */
125 exit (EXIT_FAILURE);
127 /* Add the output to mlp. */
129 message_list_ty *read_mlp = locals.mdlp->item[0]->messages;
130 size_t j;
132 for (j = 0; j < read_mlp->nitems; j++)
133 message_list_append (mlp, read_mlp->item[j]);
136 free (assembly_path);