2 Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published
6 by the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 /* Written by Bruno Haible <bruno@clisp.org>. */
29 /* Handle multi-threaded applications. */
31 # include <bits/libc-lock.h>
36 /* Separator between msgctxt and msgid in .mo files. */
37 #define MSGCTXT_SEPARATOR '\004' /* EOT */
39 /* Print an ASCII string with quotes and escape sequences where needed. */
41 print_escaped (FILE *stream
, const char *str
, const char *str_end
)
44 for (; str
!= str_end
; str
++)
47 fputs ("\\n\"", stream
);
48 if (str
+ 1 == str_end
)
50 fputs ("\n\"", stream
);
54 if (*str
== '"' || *str
== '\\')
61 static char *last_logfilename
= NULL
;
62 static FILE *last_logfile
= NULL
;
63 __libc_lock_define_initialized (static, lock
)
66 _nl_log_untranslated_locked (const char *logfilename
, const char *domainname
,
67 const char *msgid1
, const char *msgid2
, int plural
)
70 const char *separator
;
72 /* Can we reuse the last opened logfile? */
73 if (last_logfilename
== NULL
|| strcmp (logfilename
, last_logfilename
) != 0)
75 /* Close the last used logfile. */
76 if (last_logfilename
!= NULL
)
78 if (last_logfile
!= NULL
)
80 fclose (last_logfile
);
83 free (last_logfilename
);
84 last_logfilename
= NULL
;
86 /* Open the logfile. */
87 last_logfilename
= (char *) malloc (strlen (logfilename
) + 1);
88 if (last_logfilename
== NULL
)
90 strcpy (last_logfilename
, logfilename
);
91 last_logfile
= fopen (logfilename
, "a");
92 if (last_logfile
== NULL
)
95 logfile
= last_logfile
;
97 fprintf (logfile
, "domain ");
98 print_escaped (logfile
, domainname
, domainname
+ strlen (domainname
));
99 separator
= strchr (msgid1
, MSGCTXT_SEPARATOR
);
100 if (separator
!= NULL
)
102 /* The part before the MSGCTXT_SEPARATOR is the msgctxt. */
103 fprintf (logfile
, "\nmsgctxt ");
104 print_escaped (logfile
, msgid1
, separator
);
105 msgid1
= separator
+ 1;
107 fprintf (logfile
, "\nmsgid ");
108 print_escaped (logfile
, msgid1
, msgid1
+ strlen (msgid1
));
111 fprintf (logfile
, "\nmsgid_plural ");
112 print_escaped (logfile
, msgid2
, msgid2
+ strlen (msgid2
));
113 fprintf (logfile
, "\nmsgstr[0] \"\"\n");
116 fprintf (logfile
, "\nmsgstr \"\"\n");
117 putc ('\n', logfile
);
120 /* Add to the log file an entry denoting a failed translation. */
122 _nl_log_untranslated (const char *logfilename
, const char *domainname
,
123 const char *msgid1
, const char *msgid2
, int plural
)
125 __libc_lock_lock (lock
);
126 _nl_log_untranslated_locked (logfilename
, domainname
, msgid1
, msgid2
, plural
);
127 __libc_lock_unlock (lock
);