re PR tree-optimization/57066 (std::logb(-inf) returns wrong value)
[official-gcc.git] / intl / log.c
blob2ce2d02c5862cbd583a51e173717f91fcf37e30e
1 /* Log file output.
2 Copyright (C) 2003 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)
7 any later version.
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,
17 USA. */
19 /* Written by Bruno Haible <bruno@clisp.org>. */
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
29 /* Print an ASCII string with quotes and escape sequences where needed. */
30 static void
31 print_escaped (stream, str)
32 FILE *stream;
33 const char *str;
35 putc ('"', stream);
36 for (; *str != '\0'; str++)
37 if (*str == '\n')
39 fputs ("\\n\"", stream);
40 if (str[1] == '\0')
41 return;
42 fputs ("\n\"", stream);
44 else
46 if (*str == '"' || *str == '\\')
47 putc ('\\', stream);
48 putc (*str, stream);
50 putc ('"', stream);
53 /* Add to the log file an entry denoting a failed translation. */
54 void
55 _nl_log_untranslated (logfilename, domainname, msgid1, msgid2, plural)
56 const char *logfilename;
57 const char *domainname;
58 const char *msgid1;
59 const char *msgid2;
60 int plural;
62 static char *last_logfilename = NULL;
63 static FILE *last_logfile = NULL;
64 FILE *logfile;
66 /* Can we reuse the last opened logfile? */
67 if (last_logfilename == NULL || strcmp (logfilename, last_logfilename) != 0)
69 /* Close the last used logfile. */
70 if (last_logfilename != NULL)
72 if (last_logfile != NULL)
74 fclose (last_logfile);
75 last_logfile = NULL;
77 free (last_logfilename);
78 last_logfilename = NULL;
80 /* Open the logfile. */
81 last_logfilename = (char *) malloc (strlen (logfilename) + 1);
82 if (last_logfilename == NULL)
83 return;
84 strcpy (last_logfilename, logfilename);
85 last_logfile = fopen (logfilename, "a");
86 if (last_logfile == NULL)
87 return;
89 logfile = last_logfile;
91 fprintf (logfile, "domain ");
92 print_escaped (logfile, domainname);
93 fprintf (logfile, "\nmsgid ");
94 print_escaped (logfile, msgid1);
95 if (plural)
97 fprintf (logfile, "\nmsgid_plural ");
98 print_escaped (logfile, msgid2);
99 fprintf (logfile, "\nmsgstr[0] \"\"\n");
101 else
102 fprintf (logfile, "\nmsgstr \"\"\n");
103 putc ('\n', logfile);