1*bb16d227Schristos /* Log file output.
2*bb16d227Schristos Copyright (C) 2003 Free Software Foundation, Inc.
3*bb16d227Schristos
4*bb16d227Schristos This program is free software; you can redistribute it and/or modify it
5*bb16d227Schristos under the terms of the GNU Library General Public License as published
6*bb16d227Schristos by the Free Software Foundation; either version 2, or (at your option)
7*bb16d227Schristos any later version.
8*bb16d227Schristos
9*bb16d227Schristos This program is distributed in the hope that it will be useful,
10*bb16d227Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of
11*bb16d227Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12*bb16d227Schristos Library General Public License for more details.
13*bb16d227Schristos
14*bb16d227Schristos You should have received a copy of the GNU Library General Public
15*bb16d227Schristos License along with this program; if not, write to the Free Software
16*bb16d227Schristos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
17*bb16d227Schristos USA. */
18*bb16d227Schristos
19*bb16d227Schristos /* Written by Bruno Haible <bruno@clisp.org>. */
20*bb16d227Schristos
21*bb16d227Schristos #ifdef HAVE_CONFIG_H
22*bb16d227Schristos # include <config.h>
23*bb16d227Schristos #endif
24*bb16d227Schristos
25*bb16d227Schristos #include <stdio.h>
26*bb16d227Schristos #include <stdlib.h>
27*bb16d227Schristos #include <string.h>
28*bb16d227Schristos
29*bb16d227Schristos /* Print an ASCII string with quotes and escape sequences where needed. */
30*bb16d227Schristos static void
print_escaped(stream,str)31*bb16d227Schristos print_escaped (stream, str)
32*bb16d227Schristos FILE *stream;
33*bb16d227Schristos const char *str;
34*bb16d227Schristos {
35*bb16d227Schristos putc ('"', stream);
36*bb16d227Schristos for (; *str != '\0'; str++)
37*bb16d227Schristos if (*str == '\n')
38*bb16d227Schristos {
39*bb16d227Schristos fputs ("\\n\"", stream);
40*bb16d227Schristos if (str[1] == '\0')
41*bb16d227Schristos return;
42*bb16d227Schristos fputs ("\n\"", stream);
43*bb16d227Schristos }
44*bb16d227Schristos else
45*bb16d227Schristos {
46*bb16d227Schristos if (*str == '"' || *str == '\\')
47*bb16d227Schristos putc ('\\', stream);
48*bb16d227Schristos putc (*str, stream);
49*bb16d227Schristos }
50*bb16d227Schristos putc ('"', stream);
51*bb16d227Schristos }
52*bb16d227Schristos
53*bb16d227Schristos /* Add to the log file an entry denoting a failed translation. */
54*bb16d227Schristos void
_nl_log_untranslated(logfilename,domainname,msgid1,msgid2,plural)55*bb16d227Schristos _nl_log_untranslated (logfilename, domainname, msgid1, msgid2, plural)
56*bb16d227Schristos const char *logfilename;
57*bb16d227Schristos const char *domainname;
58*bb16d227Schristos const char *msgid1;
59*bb16d227Schristos const char *msgid2;
60*bb16d227Schristos int plural;
61*bb16d227Schristos {
62*bb16d227Schristos static char *last_logfilename = NULL;
63*bb16d227Schristos static FILE *last_logfile = NULL;
64*bb16d227Schristos FILE *logfile;
65*bb16d227Schristos
66*bb16d227Schristos /* Can we reuse the last opened logfile? */
67*bb16d227Schristos if (last_logfilename == NULL || strcmp (logfilename, last_logfilename) != 0)
68*bb16d227Schristos {
69*bb16d227Schristos /* Close the last used logfile. */
70*bb16d227Schristos if (last_logfilename != NULL)
71*bb16d227Schristos {
72*bb16d227Schristos if (last_logfile != NULL)
73*bb16d227Schristos {
74*bb16d227Schristos fclose (last_logfile);
75*bb16d227Schristos last_logfile = NULL;
76*bb16d227Schristos }
77*bb16d227Schristos free (last_logfilename);
78*bb16d227Schristos last_logfilename = NULL;
79*bb16d227Schristos }
80*bb16d227Schristos /* Open the logfile. */
81*bb16d227Schristos last_logfilename = (char *) malloc (strlen (logfilename) + 1);
82*bb16d227Schristos if (last_logfilename == NULL)
83*bb16d227Schristos return;
84*bb16d227Schristos strcpy (last_logfilename, logfilename);
85*bb16d227Schristos last_logfile = fopen (logfilename, "a");
86*bb16d227Schristos if (last_logfile == NULL)
87*bb16d227Schristos return;
88*bb16d227Schristos }
89*bb16d227Schristos logfile = last_logfile;
90*bb16d227Schristos
91*bb16d227Schristos fprintf (logfile, "domain ");
92*bb16d227Schristos print_escaped (logfile, domainname);
93*bb16d227Schristos fprintf (logfile, "\nmsgid ");
94*bb16d227Schristos print_escaped (logfile, msgid1);
95*bb16d227Schristos if (plural)
96*bb16d227Schristos {
97*bb16d227Schristos fprintf (logfile, "\nmsgid_plural ");
98*bb16d227Schristos print_escaped (logfile, msgid2);
99*bb16d227Schristos fprintf (logfile, "\nmsgstr[0] \"\"\n");
100*bb16d227Schristos }
101*bb16d227Schristos else
102*bb16d227Schristos fprintf (logfile, "\nmsgstr \"\"\n");
103*bb16d227Schristos putc ('\n', logfile);
104*bb16d227Schristos }
105