1 /* log.c - Log file output. */
3 /* Copyright (C) 2003, 2005-2009 Free Software Foundation, Inc.
5 This file is part of GNU Bash.
7 Bash 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 Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>.
21 /* Written by Bruno Haible <bruno@clisp.org>. */
31 /* Print an ASCII string with quotes and escape sequences where needed. */
33 print_escaped (stream
, str
)
38 for (; *str
!= '\0'; str
++)
41 fputs ("\\n\"", stream
);
44 fputs ("\n\"", stream
);
48 if (*str
== '"' || *str
== '\\')
55 /* Add to the log file an entry denoting a failed translation. */
57 _nl_log_untranslated (logfilename
, domainname
, msgid1
, msgid2
, plural
)
58 const char *logfilename
;
59 const char *domainname
;
64 static char *last_logfilename
= NULL
;
65 static FILE *last_logfile
= NULL
;
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
);
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
)
86 strcpy (last_logfilename
, logfilename
);
87 last_logfile
= fopen (logfilename
, "a");
88 if (last_logfile
== NULL
)
91 logfile
= last_logfile
;
93 fprintf (logfile
, "domain ");
94 print_escaped (logfile
, domainname
);
95 fprintf (logfile
, "\nmsgid ");
96 print_escaped (logfile
, msgid1
);
99 fprintf (logfile
, "\nmsgid_plural ");
100 print_escaped (logfile
, msgid2
);
101 fprintf (logfile
, "\nmsgstr[0] \"\"\n");
104 fprintf (logfile
, "\nmsgstr \"\"\n");
105 putc ('\n', logfile
);