]>
Commit | Line | Data |
---|---|---|
3185942a | 1 | /* log.c - Log file output. */ |
b80f6443 | 2 | |
3185942a | 3 | /* Copyright (C) 2003, 2005-2009 Free Software Foundation, Inc. |
b80f6443 | 4 | |
3185942a JA |
5 | This file is part of GNU Bash. |
6 | ||
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. | |
11 | ||
12 | Bash is distributed in the hope that it will be useful, | |
b80f6443 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
3185942a JA |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. | |
b80f6443 | 16 | |
3185942a JA |
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/>. | |
19 | */ | |
b80f6443 JA |
20 | |
21 | /* Written by Bruno Haible <bruno@clisp.org>. */ | |
22 | ||
23 | #ifdef HAVE_CONFIG_H | |
24 | # include <config.h> | |
25 | #endif | |
26 | ||
27 | #include <stdio.h> | |
28 | #include <stdlib.h> | |
29 | #include <string.h> | |
30 | ||
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; | |
36 | { | |
37 | putc ('"', stream); | |
38 | for (; *str != '\0'; str++) | |
39 | if (*str == '\n') | |
40 | { | |
41 | fputs ("\\n\"", stream); | |
42 | if (str[1] == '\0') | |
43 | return; | |
44 | fputs ("\n\"", stream); | |
45 | } | |
46 | else | |
47 | { | |
48 | if (*str == '"' || *str == '\\') | |
49 | putc ('\\', stream); | |
50 | putc (*str, stream); | |
51 | } | |
52 | putc ('"', stream); | |
53 | } | |
54 | ||
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; | |
63 | { | |
64 | static char *last_logfilename = NULL; | |
65 | static FILE *last_logfile = NULL; | |
66 | FILE *logfile; | |
67 | ||
68 | /* Can we reuse the last opened logfile? */ | |
69 | if (last_logfilename == NULL || strcmp (logfilename, last_logfilename) != 0) | |
70 | { | |
71 | /* Close the last used logfile. */ | |
72 | if (last_logfilename != NULL) | |
73 | { | |
74 | if (last_logfile != NULL) | |
75 | { | |
76 | fclose (last_logfile); | |
77 | last_logfile = NULL; | |
78 | } | |
79 | free (last_logfilename); | |
80 | last_logfilename = NULL; | |
81 | } | |
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; | |
90 | } | |
91 | logfile = last_logfile; | |
92 | ||
93 | fprintf (logfile, "domain "); | |
94 | print_escaped (logfile, domainname); | |
95 | fprintf (logfile, "\nmsgid "); | |
96 | print_escaped (logfile, msgid1); | |
97 | if (plural) | |
98 | { | |
99 | fprintf (logfile, "\nmsgid_plural "); | |
100 | print_escaped (logfile, msgid2); | |
101 | fprintf (logfile, "\nmsgstr[0] \"\"\n"); | |
102 | } | |
103 | else | |
104 | fprintf (logfile, "\nmsgstr \"\"\n"); | |
105 | putc ('\n', logfile); | |
106 | } |