+2001-05-02 Bruno Haible <haible@clisp.cons.org>
+
+ * xerror.h: New file.
+ * xerror.c: New file.
+ * Makefile.am (libnlsut_a_SOURCES): Add xerror.c.
+ (noinst_HEADERS): Add xerror.h.
+
2001-05-01 Bruno Haible <haible@clisp.cons.org>
Prefix most error messages with the program name, except those
libnlsut_a_SOURCES = basename.c c-ctype.c concatpath.c fstrcmp.c \
getopt.c getopt1.c hash.c linebreak.c localcharset.c mbswidth.c obstack.c \
-xgetcwd.c xmalloc.c xstrdup.c
+xerror.c xgetcwd.c xmalloc.c xstrdup.c
libnlsut_a_LIBADD = @ALLOCA@ @LIBOBJS@
noinst_HEADERS = c-ctype.h error.h fstrcmp.h getline.h getopt.h hash.h \
lbrkprop.h linebreak.h mbswidth.h obstack.h printf-parse.h printf.h system.h \
-pathmax.h
+pathmax.h xerror.h
DEFS = -DLIBDIR=\"$(libdir)\" @DEFS@
INCLUDES = -I. -I$(srcdir) -I.. -I../intl
--- /dev/null
+/* Multiline error-reporting functions.
+ Copyright (C) 2001 Free Software Foundation, Inc.
+ Written by Bruno Haible <haible@clisp.cons.org>, 2001.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "xerror.h"
+#include "error.h"
+#include "progname.h"
+#include "mbswidth.h"
+#include "libgettext.h"
+
+#define _(str) gettext (str)
+
+#if __STDC__
+# include <stdarg.h>
+# define VA_START(args, lastarg) va_start(args, lastarg)
+#else
+# include <varargs.h>
+# define VA_START(args, lastarg) va_start(args)
+# define NEW_VARARGS 1 /* or 0 if it doesn't work */
+#endif
+
+/* Format a message and return the freshly allocated resulting string. */
+char *
+#if __STDC__
+xasprintf (const char *format, ...)
+#elif NEW_VARARGS
+xasprintf (format, va_alist)
+ const char *format;
+ va_dcl
+#else
+xasprintf (va_alist)
+ va_dcl
+#endif
+{
+#if !__STDC__ && !NEW_VARARGS
+ const char *format;
+#endif
+ va_list args;
+ char *result;
+
+ va_start (args, format);
+#if !__STDC__ && !NEW_VARARGS
+ format = va_arg (args, const char *);
+#endif
+ if (vasprintf (&result, format, args) < 0)
+ error (EXIT_FAILURE, 0, _("memory exhausted"));
+ va_end (args);
+ return result;
+}
+
+/* Emit a multiline warning to stderr, consisting of MESSAGE, with the
+ first line prefixed with PREFIX and the remaining lines prefixed with
+ the same amount of spaces. Reuse the spaces of the previous call if
+ PREFIX is NULL. Free the PREFIX and MESSAGE when done. */
+void
+multiline_warning (prefix, message)
+ char *prefix;
+ char *message;
+{
+ static int width;
+ const char *cp;
+ int i;
+
+ fflush (stdout);
+
+ cp = message;
+
+ if (prefix != NULL)
+ {
+ width = 0;
+ if (error_with_progname)
+ {
+ fprintf (stderr, "%s: ", program_name);
+ width += mbswidth (program_name, 0) + 2;
+ }
+ fputs (prefix, stderr);
+ width += mbswidth (prefix, 0);
+ free (prefix);
+ goto after_indent;
+ }
+
+ while (1)
+ {
+ const char *np;
+
+ for (i = width; i > 0; i--)
+ putc (' ', stderr);
+
+ after_indent:
+ np = strchr (cp, '\n');
+
+ if (np == NULL || np[1] == '\0')
+ {
+ fputs (cp, stderr);
+ break;
+ }
+
+ np++;
+ fwrite (cp, 1, np - cp, stderr);
+ cp = np;
+ }
+
+ free (message);
+}
+
+/* Emit a multiline error to stderr, consisting of MESSAGE, with the
+ first line prefixed with PREFIX and the remaining lines prefixed with
+ the same amount of spaces. Reuse the spaces of the previous call if
+ PREFIX is NULL. Free the PREFIX and MESSAGE when done. */
+void
+multiline_error (prefix, message)
+ char *prefix;
+ char *message;
+{
+ if (prefix != NULL)
+ ++error_message_count;
+ multiline_warning (prefix, message);
+}
--- /dev/null
+/* Multiline error-reporting functions.
+ Copyright (C) 2001 Free Software Foundation, Inc.
+ Written by Bruno Haible <haible@clisp.cons.org>, 2001.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#ifndef _XERROR_H
+#define _XERROR_H
+
+/* Get fallback definition of __attribute__. */
+#include "error.h"
+
+/* Format a message and return the freshly allocated resulting string. */
+#if defined (__STDC__) && __STDC__
+extern char *xasprintf (const char *format, ...)
+ __attribute__ ((__format__ (__printf__, 1, 2)));
+#else
+extern char *xasprintf ();
+#endif
+
+/* Emit a multiline warning to stderr, consisting of MESSAGE, with the
+ first line prefixed with PREFIX and the remaining lines prefixed with
+ the same amount of spaces. Reuse the spaces of the previous call if
+ PREFIX is NULL. Free the PREFIX and MESSAGE when done. */
+extern void multiline_warning PARAMS ((char *prefix, char *message));
+
+/* Emit a multiline error to stderr, consisting of MESSAGE, with the
+ first line prefixed with PREFIX and the remaining lines prefixed with
+ the same amount of spaces. Reuse the spaces of the previous call if
+ PREFIX is NULL. Free the PREFIX and MESSAGE when done. */
+extern void multiline_error PARAMS ((char *prefix, char *message));
+
+#endif /* _XERROR_H */
+2001-05-02 Bruno Haible <haible@clisp.cons.org>
+
+ * POTFILES.in: Add lib/xerror.c.
+
2001-04-30 Bruno Haible <haible@clisp.cons.org>
* et.po: New file, from Ivar Smolin <okul@trenet.ee>.
lib/error.c
lib/getopt.c
lib/obstack.c
+lib/xerror.c
lib/xmalloc.c
# Package source files
+2001-05-02 Bruno Haible <haible@clisp.cons.org>
+
+ * po-charset.c: Don't include stdio.h, stdlib.h, mbswidth.h. Include
+ xerror.h instead.
+ (multiline_warning): Move to xerror.c.
+ (po_lex_charset_set): Use xasprintf instead of asprintf.
+ * msgfmt.c: Include xerror.h.
+ (format_debrief): Use multiline_error for the error message.
+
2001-05-01 Bruno Haible <haible@clisp.cons.org>
Prefix most error messages with the program name, except those
#include "dir-list.h"
#include "error.h"
#include "progname.h"
+#include "xerror.h"
#include "getline.h"
#include "printf.h"
#include <system.h>
FIXME: Should do this even if not in verbose mode, because the
consequences are not harmless. But it breaks the test suite. */
if (verbose_level > 0 && this->has_header_entry == 0)
- error (0, 0, _("%s: warning: PO file header missing, fuzzy, or invalid\n\
-%*s warning: charset conversion will not work"),
- gram_pos.file_name, (int) strlen (gram_pos.file_name), "");
+ {
+ multiline_error (xasprintf ("%s: ", gram_pos.file_name),
+ xasprintf (_("\
+warning: PO file header missing, fuzzy, or invalid\n")));
+ multiline_error (NULL,
+ xasprintf (_("\
+warning: charset conversion will not work\n")));
+ }
}
warned = 1;
error (0, 0, _("\
%s: warning: source file contains fuzzy translation"),
- gram_pos.file_name);
+ gram_pos.file_name);
}
this->is_fuzzy = 1;
# include "config.h"
#endif
-#include <stdio.h>
-#include <stdlib.h>
-
#include "po-charset.h"
#include "error.h"
+#include "xerror.h"
#include "system.h"
-#include "mbswidth.h"
#include "libgettext.h"
extern const char *program_name;
#endif
}
-/* Emit a multiline warning to stderr, consisting of MESSAGE, with the
- first line prefixed with PREFIX and the remaining lines prefixed with
- the same amount of spaces. Reuse the spaces of the previous call if
- PREFIX is NULL. Free the PREFIX and MESSAGE when done. */
-static void
-multiline_warning (prefix, message)
- char *prefix;
- char *message;
-{
- static int width;
- const char *cp;
- int i;
-
- fflush (stdout);
-
- cp = message;
-
- if (prefix != NULL)
- {
- fputs (prefix, stderr);
- width = mbswidth (prefix, 0);
- free (prefix);
- goto after_indent;
- }
-
- while (1)
- {
- const char *np;
-
- for (i = width; i > 0; i--)
- putc (' ', stderr);
-
- after_indent:
- np = strchr (cp, '\n');
-
- if (np == NULL || np[1] == '\0')
- {
- fputs (cp, stderr);
- break;
- }
-
- np++;
- fwrite (cp, 1, np - cp, stderr);
- cp = np;
- }
-
- free (message);
-}
-
void
po_lex_charset_set (header_entry, filename)
const char *header_entry;
if (!(filenamelen >= 4
&& memcmp (filename + filenamelen - 4, ".pot", 4) == 0
&& strcmp (charset, "CHARSET") == 0))
- {
- char *prefix;
- char *msg;
-
- asprintf (&prefix, _("%s: warning: "), filename);
- asprintf (&msg, _("\
+ multiline_warning (xasprintf (_("%s: warning: "), filename),
+ xasprintf (_("\
Charset \"%s\" is not a portable encoding name.\n\
Message conversion to user's charset might not work.\n"),
- charset);
- if (prefix == NULL || msg == NULL)
- error (EXIT_FAILURE, 0, _("memory exhausted"));
- multiline_warning (prefix, msg);
- }
+ charset));
}
else
{
{
size_t i;
const char *note;
- char *prefix;
- char *msg;
for (i = 0; i < SIZEOF (weird_charsets); i++)
if (strcmp (po_lex_charset, weird_charsets[i]) == 0)
else
note = _("Continuing anyway.");
- asprintf (&prefix, _("%s: warning: "), filename);
- asprintf (&msg, _("\
+ multiline_warning (xasprintf (_("%s: warning: "), filename),
+ xasprintf (_("\
Charset \"%s\" is not supported. %s relies on iconv(),\n\
and iconv() does not support \"%s\".\n"),
- po_lex_charset, basename (program_name),
- po_lex_charset);
- if (prefix == NULL || msg == NULL)
- error (EXIT_FAILURE, 0, _("memory exhausted"));
- multiline_warning (prefix, msg);
+ po_lex_charset,
+ basename (program_name),
+ po_lex_charset));
# if !defined _LIBICONV_VERSION
- asprintf (&msg, _("\
+ multiline_warning (NULL,
+ xasprintf (_("\
Installing GNU libiconv and then reinstalling GNU gettext\n\
-would fix this problem.\n"));
- if (msg == NULL)
- error (EXIT_FAILURE, 0, _("memory exhausted"));
- multiline_warning (NULL, msg);
+would fix this problem.\n")));
# endif
- asprintf (&msg, _("%s\n"), note);
- if (msg == NULL)
- error (EXIT_FAILURE, 0, _("memory exhausted"));
- multiline_warning (NULL, msg);
+ multiline_warning (NULL, xasprintf (_("%s\n"), note));
}
#else
for (i = 0; i < SIZEOF (weird_charsets); i++)
{
const char *note =
_("Continuing anyway, expect parse errors.");
- char *prefix;
- char *msg;
- asprintf (&prefix, _("%s: warning: "), filename);
- asprintf (&msg, _("\
+ multiline_warning (xasprintf (_("%s: warning: "), filename),
+ xasprintf (_("\
Charset \"%s\" is not supported. %s relies on iconv().\n\
This version was built without iconv().\n"),
- po_lex_charset, basename (program_name));
- if (prefix == NULL || msg == NULL)
- error (EXIT_FAILURE, 0, _("memory exhausted"));
- multiline_warning (prefix, msg);
+ po_lex_charset,
+ basename (program_name)));
- asprintf (&msg, _("\
+ multiline_warning (NULL,
+ xasprintf (_("\
Installing GNU libiconv and then reinstalling GNU gettext\n\
-would fix this problem.\n"));
- if (msg == NULL)
- error (EXIT_FAILURE, 0, _("memory exhausted"));
- multiline_warning (NULL, msg);
+would fix this problem.\n")));
- asprintf (&msg, _("%s\n"), note);
- if (msg == NULL)
- error (EXIT_FAILURE, 0, _("memory exhausted"));
- multiline_warning (NULL, msg);
+ multiline_warning (NULL, xasprintf (_("%s\n"), note));
}
#endif
}
if (!(filenamelen >= 4
&& memcmp (filename + filenamelen - 4, ".pot", 4) == 0))
- {
- char *prefix;
- char *msg;
-
- asprintf (&prefix, _("%s: warning: "), filename);
- asprintf (&msg, _("\
+ multiline_warning (xasprintf (_("%s: warning: "), filename),
+ xasprintf (_("\
Charset missing in header.\n\
-Message conversion to user's charset will not work.\n"));
- if (prefix == NULL || msg == NULL)
- error (EXIT_FAILURE, 0, _("memory exhausted"));
- multiline_warning (prefix, msg);
- }
+Message conversion to user's charset will not work.\n")));
}
}