init version.
[bush.git] / lib / intl / log.c
blob6be782552f49f9d99bd045d296a73483d1ee4702
1 /* log.c - Log file output. */
3 /* Copyright (C) 2003, 2005-2009 Free Software Foundation, Inc.
5 This file is part of GNU Bush.
7 Bush is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 Bush is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Bush. If not, see <http://www.gnu.org/licenses/>.
21 /* Written by Bruno Haible <bruno@clisp.org>. */
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
31 /* Print an ASCII string with quotes and escape sequences where needed. */
32 static void
33 print_escaped (stream, str)
34 FILE *stream;
35 const char *str;
37 putc ('"', stream);
38 for (; *str != '\0'; str++)
39 if (*str == '\n')
41 fputs ("\\n\"", stream);
42 if (str[1] == '\0')
43 return;
44 fputs ("\n\"", stream);
46 else
48 if (*str == '"' || *str == '\\')
49 putc ('\\', stream);
50 putc (*str, stream);
52 putc ('"', stream);
55 /* Add to the log file an entry denoting a failed translation. */
56 void
57 _nl_log_untranslated (logfilename, domainname, msgid1, msgid2, plural)
58 const char *logfilename;
59 const char *domainname;
60 const char *msgid1;
61 const char *msgid2;
62 int plural;
64 static char *last_logfilename = NULL;
65 static FILE *last_logfile = NULL;
66 FILE *logfile;
68 /* Can we reuse the last opened logfile? */
69 if (last_logfilename == NULL || strcmp (logfilename, last_logfilename) != 0)
71 /* Close the last used logfile. */
72 if (last_logfilename != NULL)
74 if (last_logfile != NULL)
76 fclose (last_logfile);
77 last_logfile = NULL;
79 free (last_logfilename);
80 last_logfilename = NULL;
82 /* Open the logfile. */
83 last_logfilename = (char *) malloc (strlen (logfilename) + 1);
84 if (last_logfilename == NULL)
85 return;
86 strcpy (last_logfilename, logfilename);
87 last_logfile = fopen (logfilename, "a");
88 if (last_logfile == NULL)
89 return;
91 logfile = last_logfile;
93 fprintf (logfile, "domain ");
94 print_escaped (logfile, domainname);
95 fprintf (logfile, "\nmsgid ");
96 print_escaped (logfile, msgid1);
97 if (plural)
99 fprintf (logfile, "\nmsgid_plural ");
100 print_escaped (logfile, msgid2);
101 fprintf (logfile, "\nmsgstr[0] \"\"\n");
103 else
104 fprintf (logfile, "\nmsgstr \"\"\n");
105 putc ('\n', logfile);