You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

log.c 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Log file output.
  2. Copyright (C) 2003 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU Library General Public License as published
  5. by the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  14. USA. */
  15. /* Written by Bruno Haible <bruno@clisp.org>. */
  16. #ifdef HAVE_CONFIG_H
  17. # include <config.h>
  18. #endif
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. /* Print an ASCII string with quotes and escape sequences where needed. */
  23. static void
  24. print_escaped (FILE *stream, const char *str)
  25. {
  26. putc ('"', stream);
  27. for (; *str != '\0'; str++)
  28. if (*str == '\n')
  29. {
  30. fputs ("\\n\"", stream);
  31. if (str[1] == '\0')
  32. return;
  33. fputs ("\n\"", stream);
  34. }
  35. else
  36. {
  37. if (*str == '"' || *str == '\\')
  38. putc ('\\', stream);
  39. putc (*str, stream);
  40. }
  41. putc ('"', stream);
  42. }
  43. /* Add to the log file an entry denoting a failed translation. */
  44. void
  45. _nl_log_untranslated (const char *logfilename, const char *domainname,
  46. const char *msgid1, const char *msgid2, int plural)
  47. {
  48. static char *last_logfilename = NULL;
  49. static FILE *last_logfile = NULL;
  50. FILE *logfile;
  51. /* Can we reuse the last opened logfile? */
  52. if (last_logfilename == NULL || strcmp (logfilename, last_logfilename) != 0)
  53. {
  54. /* Close the last used logfile. */
  55. if (last_logfilename != NULL)
  56. {
  57. if (last_logfile != NULL)
  58. {
  59. fclose (last_logfile);
  60. last_logfile = NULL;
  61. }
  62. free (last_logfilename);
  63. last_logfilename = NULL;
  64. }
  65. /* Open the logfile. */
  66. last_logfilename = (char *) malloc (strlen (logfilename) + 1);
  67. if (last_logfilename == NULL)
  68. return;
  69. strcpy (last_logfilename, logfilename);
  70. last_logfile = fopen (logfilename, "a");
  71. if (last_logfile == NULL)
  72. return;
  73. }
  74. logfile = last_logfile;
  75. fprintf (logfile, "domain ");
  76. print_escaped (logfile, domainname);
  77. fprintf (logfile, "\nmsgid ");
  78. print_escaped (logfile, msgid1);
  79. if (plural)
  80. {
  81. fprintf (logfile, "\nmsgid_plural ");
  82. print_escaped (logfile, msgid2);
  83. fprintf (logfile, "\nmsgstr[0] \"\"\n");
  84. }
  85. else
  86. fprintf (logfile, "\nmsgstr \"\"\n");
  87. putc ('\n', logfile);
  88. }