From: Bruno Haible Date: Fri, 14 Nov 2008 11:10:35 +0000 (+0000) Subject: msgfilter now sets the environment variables MSGFILTER_MSGCTXT, X-Git-Tag: v0.18~293 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26278fe9dc80e51ab9d06573ff5a83deaccbf72a;p=thirdparty%2Fgettext.git msgfilter now sets the environment variables MSGFILTER_MSGCTXT, MSGFILTER_MSGID, MSGFILTER_LOCATION. --- diff --git a/NEWS b/NEWS index c59131ba3..1847c2f90 100644 --- a/NEWS +++ b/NEWS @@ -24,6 +24,9 @@ Version 0.18 - January 2008 * msgcmp has a new option -N/--no-fuzzy-matching, like msgmerge has since version 0.12. +* msgfilter now sets environment variables during the invocation of the + filter, indicating the msgid and location of the messge being processed. + * Updated the meaning of 'gcc-internal-format' to match GCC 4.3. Version 0.17 - November 2007 diff --git a/gettext-tools/doc/ChangeLog b/gettext-tools/doc/ChangeLog index 36a6d66ba..311ac16ff 100644 --- a/gettext-tools/doc/ChangeLog +++ b/gettext-tools/doc/ChangeLog @@ -1,3 +1,8 @@ +2008-11-14 Bruno Haible + + * msgfilter.texi: Document the environment variables MSGFILTER_MSGCTXT, + MSGFILTER_MSGID, MSGFILTER_LOCATION. + 2008-10-10 Noritada Kobayashi * gettext.texi (PO Mode): Update remaining obsolete key bindings used diff --git a/gettext-tools/doc/msgfilter.texi b/gettext-tools/doc/msgfilter.texi index 13ea7d54c..736373d6b 100644 --- a/gettext-tools/doc/msgfilter.texi +++ b/gettext-tools/doc/msgfilter.texi @@ -8,6 +8,16 @@ msgfilter [@var{option}] @var{filter} [@var{filter-option}] The @code{msgfilter} program applies a filter to all translations of a translation catalog. +@vindex MSGFILTER_MSGCTXT@r{, environment variable} +@vindex MSGFILTER_MSGID@r{, environment variable} +@vindex MSGFILTER_LOCATION@r{, environment variable} +During each @var{filter} invocation, the environment variable +@code{MSGFILTER_MSGID} is bound to the message's msgid, and the environment +variable @code{MSGFILTER_LOCATION} is bound to the location in the PO file +of the message. If the message has a context, the environment variable +@code{MSGFILTER_MSGCTXT} is bound to the message's msgctxt, otherwise it is +unbound. + @subsection Input file location @table @samp diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 3ccaabd41..4ac3abc6d 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,9 @@ +2008-11-14 Bruno Haible + + * msgfilter.c: Include xvasprintf.h, xsetenv.h. + (process_message): Set the environment variables MSGFILTER_MSGCTXT, + MSGFILTER_MSGID, MSGFILTER_LOCATION. + 2008-10-28 Bruno Haible * msgmerge.c (match_domain): Remove space between '#' and 'pragma' for diff --git a/gettext-tools/src/msgfilter.c b/gettext-tools/src/msgfilter.c index 1177361f8..66e5ffb66 100644 --- a/gettext-tools/src/msgfilter.c +++ b/gettext-tools/src/msgfilter.c @@ -43,6 +43,7 @@ #include "closeout.h" #include "dir-list.h" #include "error.h" +#include "xvasprintf.h" #include "error-progname.h" #include "progname.h" #include "relocatable.h" @@ -61,6 +62,7 @@ #include "findprog.h" #include "pipe.h" #include "wait-process.h" +#include "xsetenv.h" #include "filters.h" #include "msgl-iconv.h" #include "po-charset.h" @@ -758,6 +760,7 @@ process_message (message_ty *mp) { const char *msgstr = mp->msgstr; size_t msgstr_len = mp->msgstr_len; + char *location; size_t nsubstrings; char **substrings; size_t total_len; @@ -770,6 +773,17 @@ process_message (message_ty *mp) if (is_header (mp) && keep_header) return; + /* Set environment variables for the subprocess. */ + if (mp->msgctxt != NULL) + xsetenv ("MSGFILTER_MSGCTXT", mp->msgctxt, 1); + else + unsetenv ("MSGFILTER_MSGCTXT"); + xsetenv ("MSGFILTER_MSGID", mp->msgid, 1); + location = xasprintf ("%s:%ld", mp->pos.file_name, + (long) mp->pos.line_number); + xsetenv ("MSGFILTER_LOCATION", location, 1); + free (location); + /* Count NUL delimited substrings. */ for (p = msgstr, nsubstrings = 0; p < msgstr + msgstr_len;