#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
-/* Avoid side effect of gnulib's error.h on 'struct po_error_handler'. */
-#define _GL_NO_INLINE_ERROR
-
-/* Avoid side effect of config.h on 'struct po_error_handler'. */
-#include <error.h>
-static void (*orig_error) (int status, int errnum,
- const char *format, ...)
- = error;
-
-static void (*orig_error_at_line) (int status, int errnum,
- const char *filename, unsigned int lineno,
- const char *format, ...)
- = error_at_line;
-#undef error
-#undef error_at_line
/* Specification. */
#include "gettext-po.h"
#include <limits.h>
-#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
-#include <stdarg.h>
#include <string.h>
#include "message.h"
#include "read-po-lex.h"
#include "write-catalog.h"
#include "write-po.h"
-#include "xerror.h"
-#include "po-error.h"
#include "po-xerror.h"
-#include "format.h"
#include "xvasprintf.h"
#include "msgl-check.h"
#include "gettext.h"
int libgettextpo_version = LIBGETTEXTPO_VERSION;
-static void
-void_multiline_warning (char *prefix, char *message)
-{
- multiline_warning (prefix, message);
-}
-
-static void
-void_multiline_error (char *prefix, char *message)
-{
- multiline_error (prefix, message);
-}
-
-
/* Create an empty PO file representation in memory. */
po_file_t
fclose (fp);
return file;
}
-#undef po_file_read
-
-#ifdef __cplusplus
-extern "C" po_file_t po_file_read_v2 (const char *filename, po_error_handler_t handler);
-#endif
-po_file_t
-po_file_read_v2 (const char *filename, po_error_handler_t handler)
-{
- FILE *fp;
- po_file_t file;
-
- if (strcmp (filename, "-") == 0 || strcmp (filename, "/dev/stdin") == 0)
- {
- filename = _("<stdin>");
- fp = stdin;
- }
- else
- {
- fp = fopen (filename, "r");
- if (fp == NULL)
- return NULL;
- }
-
- /* Establish error handler around read_catalog_stream(). */
- po_error = handler->error;
- po_error_at_line = handler->error_at_line;
- po_multiline_warning = handler->multiline_warning;
- po_multiline_error = handler->multiline_error;
- gram_max_allowed_errors = UINT_MAX;
-
- file = XMALLOC (struct po_file);
- file->real_filename = filename;
- file->logical_filename = filename;
- file->mdlp = read_catalog_stream (fp, file->real_filename,
- file->logical_filename, &input_format_po);
- file->domains = NULL;
-
- /* Restore error handler. */
- po_error = orig_error;
- po_error_at_line = orig_error_at_line;
- po_multiline_warning = void_multiline_warning;
- po_multiline_error = void_multiline_error;
- gram_max_allowed_errors = 20;
-
- if (fp != stdin)
- fclose (fp);
- return file;
-}
-
-/* Older version for binary backward compatibility. */
-#ifdef __cplusplus
-extern "C" po_file_t po_file_read (const char *filename);
-#endif
-po_file_t
-po_file_read (const char *filename)
-{
- FILE *fp;
- po_file_t file;
-
- if (strcmp (filename, "-") == 0 || strcmp (filename, "/dev/stdin") == 0)
- {
- filename = _("<stdin>");
- fp = stdin;
- }
- else
- {
- fp = fopen (filename, "r");
- if (fp == NULL)
- return NULL;
- }
-
- file = XMALLOC (struct po_file);
- file->real_filename = filename;
- file->logical_filename = filename;
- file->mdlp = read_catalog_stream (fp, file->real_filename,
- file->logical_filename, &input_format_po);
- file->domains = NULL;
-
- if (fp != stdin)
- fclose (fp);
- return file;
-}
/* Write an in-memory PO file to a file.
return file;
}
-#undef po_file_write
-
-/* Older version for binary backward compatibility. */
-#ifdef __cplusplus
-extern "C" po_file_t po_file_write (po_file_t file, const char *filename, po_error_handler_t handler);
-#endif
-po_file_t
-po_file_write (po_file_t file, const char *filename, po_error_handler_t handler)
-{
- /* Establish error handler around msgdomain_list_print(). */
- po_error = handler->error;
- po_error_at_line = handler->error_at_line;
- po_multiline_warning = handler->multiline_warning;
- po_multiline_error = handler->multiline_error;
-
- msgdomain_list_print (file->mdlp, filename, &output_format_po, true, false);
-
- /* Restore error handler. */
- po_error = orig_error;
- po_error_at_line = orig_error_at_line;
- po_multiline_warning = void_multiline_warning;
- po_multiline_error = void_multiline_error;
-
- return file;
-}
/* Free a PO file from memory. */
po_xerror = textmode_xerror;
po_xerror2 = textmode_xerror2;
}
-#undef po_message_check_format
-
-/* Older version for binary backward compatibility. */
-
-/* An error logger based on the po_error function pointer. */
-static void
-po_error_logger (void *data, const char *format, ...)
- __attribute__ ((__format__ (__printf__, 2, 3)));
-static void
-po_error_logger (void *data, const char *format, ...)
-{
- va_list args;
- char *error_message;
-
- va_start (args, format);
- if (vasprintf (&error_message, format, args) < 0)
- orig_error (EXIT_FAILURE, 0, _("memory exhausted"));
- va_end (args);
- po_error (0, 0, "%s", error_message);
- free (error_message);
-}
-
-/* Test whether the message translation is a valid format string if the message
- is marked as being a format string. If it is invalid, pass the reasons to
- the handler. */
-#ifdef __cplusplus
-extern "C" void po_message_check_format (po_message_t message, po_error_handler_t handler);
-#endif
-void
-po_message_check_format (po_message_t message, po_error_handler_t handler)
-{
- message_ty *mp = (message_ty *) message;
-
- /* Establish error handler for po_error_logger(). */
- po_error = handler->error;
-
- check_msgid_msgstr_format (mp->msgid, mp->msgid_plural,
- mp->msgstr, mp->msgstr_len,
- mp->is_format, mp->range, NULL,
- po_error_logger, NULL);
-
- /* Restore error handler. */
- po_error = orig_error;
-}