/* Pass translations to a subprocess.
- Copyright (C) 2001-2012 Free Software Foundation, Inc.
+ Copyright (C) 2001-2015 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2001.
This program is free software: you can redistribute it and/or modify
static char **sub_argv;
static int sub_argc;
+static bool newline;
+
/* Maximum exit code encountered. */
static int exitcode;
{ "directory", required_argument, NULL, 'D' },
{ "help", no_argument, NULL, 'h' },
{ "input", required_argument, NULL, 'i' },
+ { "newline", no_argument, NULL, CHAR_MAX + 2 },
{ "properties-input", no_argument, NULL, 'P' },
{ "stringtable-input", no_argument, NULL, CHAR_MAX + 1 },
{ "version", no_argument, NULL, 'V' },
input_syntax = &input_format_stringtable;
break;
+ case CHAR_MAX + 2: /* --newline */
+ newline = true;
+ break;
+
default:
usage (EXIT_FAILURE);
break;
"));
printf ("\n");
printf (_("\
+Command input:\n"));
+ printf (_("\
+ --newline add newline at the end of input\n"));
+ printf ("\n");
+ printf (_("\
Mandatory arguments to long options are mandatory for short options too.\n"));
printf ("\n");
printf (_("\
int fd[1];
void (*orig_sigpipe_handler)(int);
int exitstatus;
+ char *newstr;
/* Set environment variables for the subprocess.
Note: These environment variables, especially MSGEXEC_MSGCTXT and
- MSGEXEC_MSGCTXT, may contain non-ASCII characters. The subprocess
+ MSGEXEC_MSGID, may contain non-ASCII characters. The subprocess
may not interpret these values correctly if the locale encoding is
different from the PO file's encoding. We want about this situation,
above.
else
unsetenv ("MSGEXEC_MSGCTXT");
xsetenv ("MSGEXEC_MSGID", mp->msgid, 1);
+ if (mp->msgid_plural != NULL)
+ xsetenv ("MSGEXEC_MSGID_PLURAL", mp->msgid_plural, 1);
+ else
+ unsetenv ("MSGEXEC_MSGID_PLURAL");
location = xasprintf ("%s:%ld", mp->pos.file_name,
(long) mp->pos.line_number);
xsetenv ("MSGEXEC_LOCATION", location, 1);
free (location);
+ if (mp->prev_msgctxt != NULL)
+ xsetenv ("MSGEXEC_PREV_MSGCTXT", mp->prev_msgctxt, 1);
+ else
+ unsetenv ("MSGEXEC_PREV_MSGCTXT");
+ if (mp->prev_msgid != NULL)
+ xsetenv ("MSGEXEC_PREV_MSGID", mp->prev_msgid, 1);
+ else
+ unsetenv ("MSGEXEC_PREV_MSGID");
+ if (mp->prev_msgid_plural != NULL)
+ xsetenv ("MSGEXEC_PREV_MSGID_PLURAL", mp->prev_msgid_plural, 1);
+ else
+ unsetenv ("MSGEXEC_PREV_MSGID_PLURAL");
/* Open a pipe to a subprocess. */
child = create_pipe_out (sub_name, sub_path, sub_argv, NULL, false, true,
successfully without having read all of the input that we feed it. */
orig_sigpipe_handler = signal (SIGPIPE, SIG_IGN);
- if (full_write (fd[0], str, len) < len)
+ if (newline)
+ {
+ newstr = XNMALLOC (len + 1, char);
+ memcpy (newstr, str, len);
+ newstr[len++] = '\n';
+ }
+ else
+ newstr = (char *) str;
+
+ if (full_write (fd[0], newstr, len) < len)
if (errno != EPIPE)
error (EXIT_FAILURE, errno,
_("write to %s subprocess failed"), sub_name);
+ if (newstr != str)
+ free (newstr);
+
close (fd[0]);
signal (SIGPIPE, orig_sigpipe_handler);
const char *msgstr = mp->msgstr;
size_t msgstr_len = mp->msgstr_len;
const char *p;
+ size_t k;
/* Process each NUL delimited substring separately. */
- for (p = msgstr; p < msgstr + msgstr_len; )
+ for (p = msgstr, k = 0; p < msgstr + msgstr_len; k++)
{
size_t length = strlen (p);
+ if (mp->msgid_plural != NULL)
+ {
+ char *plural_form_string = xasprintf ("%zu", k);
+
+ xsetenv ("MSGEXEC_PLURAL_FORM", plural_form_string, 1);
+ free (plural_form_string);
+ }
+ else
+ unsetenv ("MSGEXEC_PLURAL_FORM");
process_string (mp, p, length);
p += length + 1;