Back to index

cell-binutils  2.17cvs20070401
log.c
Go to the documentation of this file.
00001 /* Log file output.
00002    Copyright (C) 2003 Free Software Foundation, Inc.
00003 
00004    This program is free software; you can redistribute it and/or modify it
00005    under the terms of the GNU Library General Public License as published
00006    by the Free Software Foundation; either version 2, or (at your option)
00007    any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public
00015    License along with this program; if not, write to the Free Software
00016    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
00017    USA.  */
00018 
00019 /* Written by Bruno Haible <bruno@clisp.org>.  */
00020 
00021 #ifdef HAVE_CONFIG_H
00022 # include <config.h>
00023 #endif
00024 
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include <string.h>
00028 
00029 /* Print an ASCII string with quotes and escape sequences where needed.  */
00030 static void
00031 print_escaped (stream, str)
00032      FILE *stream;
00033      const char *str;
00034 {
00035   putc ('"', stream);
00036   for (; *str != '\0'; str++)
00037     if (*str == '\n')
00038       {
00039        fputs ("\\n\"", stream);
00040        if (str[1] == '\0')
00041          return;
00042        fputs ("\n\"", stream);
00043       }
00044     else
00045       {
00046        if (*str == '"' || *str == '\\')
00047          putc ('\\', stream);
00048        putc (*str, stream);
00049       }
00050   putc ('"', stream);
00051 }
00052 
00053 /* Add to the log file an entry denoting a failed translation.  */
00054 void
00055 _nl_log_untranslated (logfilename, domainname, msgid1, msgid2, plural)
00056      const char *logfilename;
00057      const char *domainname;
00058      const char *msgid1;
00059      const char *msgid2;
00060      int plural;
00061 {
00062   static char *last_logfilename = NULL;
00063   static FILE *last_logfile = NULL;
00064   FILE *logfile;
00065 
00066   /* Can we reuse the last opened logfile?  */
00067   if (last_logfilename == NULL || strcmp (logfilename, last_logfilename) != 0)
00068     {
00069       /* Close the last used logfile.  */
00070       if (last_logfilename != NULL)
00071        {
00072          if (last_logfile != NULL)
00073            {
00074              fclose (last_logfile);
00075              last_logfile = NULL;
00076            }
00077          free (last_logfilename);
00078          last_logfilename = NULL;
00079        }
00080       /* Open the logfile.  */
00081       last_logfilename = (char *) malloc (strlen (logfilename) + 1);
00082       if (last_logfilename == NULL)
00083        return;
00084       strcpy (last_logfilename, logfilename);
00085       last_logfile = fopen (logfilename, "a");
00086       if (last_logfile == NULL)
00087        return;
00088     }
00089   logfile = last_logfile;
00090 
00091   fprintf (logfile, "domain ");
00092   print_escaped (logfile, domainname);
00093   fprintf (logfile, "\nmsgid ");
00094   print_escaped (logfile, msgid1);
00095   if (plural)
00096     {
00097       fprintf (logfile, "\nmsgid_plural ");
00098       print_escaped (logfile, msgid2);
00099       fprintf (logfile, "\nmsgstr[0] \"\"\n");
00100     }
00101   else
00102     fprintf (logfile, "\nmsgstr \"\"\n");
00103   putc ('\n', logfile);
00104 }