+2001-05-01 Bruno Haible <haible@clisp.cons.org>
+
+ Prefix most error messages with the program name, except those
+ starting with "filename:lineno:".
+ * progname.h: New file.
+ * progname.c: New file.
+ * Makefile.am (libnlsut_a_SOURCES): Add progname.c.
+ (noinst_HEADERS): Add progname.h.
+
2001-05-01 Bruno Haible <haible@clisp.cons.org>
* vasprintf.c (int_vasprintf): Upon allocation failure, return -1,
--- /dev/null
+/* Program name management.
+ 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 "progname.h"
+
+
+/* String containing name the program is called with.
+ To be initialized by main(). */
+const char *program_name;
+
+/* Indicates whether errors and warnings get prefixed with program_name.
+ Default is true. */
+int error_with_progname = 1;
+
+/* Print program_name prefix on stderr if and only if error_with_progname
+ is true. */
+void
+maybe_print_progname ()
+{
+ if (error_with_progname)
+ fprintf (stderr, "%s: ", program_name);
+}
--- /dev/null
+/* Program name management.
+ 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 _PROGNAME_H
+#define _PROGNAME_H
+
+/* This file supports selectively prefixing or nor prefixing error messages
+ with the program name.
+
+ Programs using this file should do the following in main():
+ program_name = argv[0];
+ error_print_progname = maybe_print_progname;
+ */
+
+/* String containing name the program is called with. */
+extern const char *program_name;
+
+/* Indicates whether errors and warnings get prefixed with program_name.
+ Default is true.
+ A reason to omit the prefix is for better interoperability with Emacs'
+ compile.el. */
+extern int error_with_progname;
+
+/* Print program_name prefix on stderr if and only if error_with_progname
+ is true. */
+extern void maybe_print_progname PARAMS ((void));
+
+#endif /* _PROGNAME_H */
+2001-05-01 Bruno Haible <haible@clisp.cons.org>
+
+ Prefix most error messages with the program name, except those
+ starting with "filename:lineno:".
+ * po-lex.h: Include progname.h.
+ (po_gram_error): Set error_with_progname = 0 during error_at_line()
+ call.
+ (po_gram_error_at_line): Likewise.
+ * po-lex.c (po_gram_error): Likewise.
+ (po_gram_error_at_line): Likewise.
+ * msgcmp.c: Include progname.h.
+ (program_name): Remove variable.
+ (error_print): Remove function.
+ (main): Initialize error_print_progname with maybe_print_progname.
+ * msgcomm.c: Include progname.h.
+ (program_name): Remove variable.
+ (error_print): Remove function.
+ (main): Initialize error_print_progname with maybe_print_progname.
+ * msgfmt.c: Include progname.h.
+ (program_name): Remove variable.
+ (error_print): Remove function.
+ (main): Initialize error_print_progname with maybe_print_progname.
+ (format_directive_message): Set error_with_progname = 0 during
+ error_at_line() call.
+ (check_pair): Likewise.
+ * msgmerge.c: Include progname.h.
+ (program_name): Remove variable.
+ (error_print): Remove function.
+ (main): Initialize error_print_progname with maybe_print_progname.
+ * msgunfmt.c: Include progname.h.
+ (program_name): Remove variable.
+ (error_print): Remove function.
+ (main): Initialize error_print_progname with maybe_print_progname.
+ * xget-lex.c: Include progname.h.
+ (phase5_get): Set error_with_progname = 0 during error() call.
+ * xgettext.c: Include progname.h.
+ (program_name): Remove variable.
+ (error_print): Remove function.
+ (main): Initialize error_print_progname with maybe_print_progname.
+ (scan_c_file): Set error_with_progname = 0 during error() call.
+
2001-04-30 Bruno Haible <haible@clisp.cons.org>
Save the messages' obsoleteness status in the 'message_ty'.
#include "dir-list.h"
#include "error.h"
+#include "progname.h"
#include "message.h"
#include <system.h>
#include "libgettext.h"
message_list_ty *mlp;
};
-/* String containing name the program is called with. */
-const char *program_name;
-
/* Long options. */
static const struct option long_options[] =
{
/* Prototypes for local functions. */
static void usage PARAMS ((int __status));
-static void error_print PARAMS ((void));
static void compare PARAMS ((char *, char *));
static message_list_ty *grammar PARAMS ((char *__filename));
static void compare_constructor PARAMS ((po_ty *__that));
/* Set program name for messages. */
program_name = argv[0];
- error_print_progname = error_print;
+ error_print_progname = maybe_print_progname;
#ifdef HAVE_SETLOCALE
/* Set locale via LC_ALL. */
}
-/* The address of this function will be assigned to the hook in the error
- functions. */
-static void
-error_print ()
-{
- /* We don't want the program name to be printed in messages. Emacs'
- compile.el does not like this. */
-}
-
-
static void
compare (fn1, fn2)
char *fn1;
#include "dir-list.h"
#include "error.h"
+#include "progname.h"
#include "getline.h"
#include "libgettext.h"
#include "message.h"
/* If nonzero omit header with information about this run. */
static int omit_header;
-/* String containing name the program is called with. */
-const char *program_name;
-
/* These variables control which messages are selected. */
static int more_than = -1;
static int less_than = -1;
__attribute__ ((noreturn))
#endif
;
-static void error_print PARAMS ((void));
static string_list_ty *read_name_from_file PARAMS ((const char *__file_name));
static void extract_constructor PARAMS ((po_ty *__that));
static void extract_directive_domain PARAMS ((po_ty *__that, char *__name));
/* Set program name for messages. */
program_name = argv[0];
- error_print_progname = error_print;
+ error_print_progname = maybe_print_progname;
#ifdef HAVE_SETLOCALE
/* Set locale via LC_ALL. */
}
-/* The address of this function will be assigned to the hook in the error
- functions. */
-static void
-error_print ()
-{
- /* We don't want the program name to be printed in messages. */
-}
-
-
/* Read list of files to process from file. */
static string_list_ty *
read_name_from_file (file_name)
#include "dir-list.h"
#include "error.h"
+#include "progname.h"
#include "getline.h"
#include "printf.h"
#include <system.h>
/* Specifies name of the output file. */
static const char *output_file_name;
-/* String containing name the program is called with. */
-const char *program_name;
-
/* We may have more than one input file. Domains with same names in
different files have to merged. So we need a list of tables for
each output file. */
__attribute__ ((noreturn))
#endif
;
-static void error_print PARAMS ((void));
static void grammar PARAMS ((char *__filename));
static void format_constructor PARAMS ((po_ty *__that));
static void format_directive_domain PARAMS ((po_ty *__pop, char *__name));
/* Set program name for messages. */
program_name = argv[0];
- error_print_progname = error_print;
+ error_print_progname = maybe_print_progname;
error_one_per_line = 1;
exit_status = EXIT_SUCCESS;
}
-/* The address of this function will be assigned to the hook in the error
- functions. */
-static void
-error_print ()
-{
- /* We don't want the program name to be printed in messages. Emacs'
- compile.el does not like this. */
-}
-
-
/* Prepare for first message. */
static void
format_constructor (that)
|| (!include_all && this->is_fuzzy && msgid_string[0] != '\0'))
{
if (verbose_level > 1)
- /* We don't change the exit status here because this is really
- only an information. */
- error_at_line (0, 0, msgstr_pos->file_name, msgstr_pos->line_number,
- (msgstr_string[0] == '\0'
- ? _("empty `msgstr' entry ignored")
- : _("fuzzy `msgstr' entry ignored")));
+ {
+ /* We don't change the exit status here because this is really
+ only an information. */
+ error_with_progname = 0;
+ error_at_line (0, 0, msgstr_pos->file_name, msgstr_pos->line_number,
+ (msgstr_string[0] == '\0'
+ ? _("empty `msgstr' entry ignored")
+ : _("fuzzy `msgstr' entry ignored")));
+ error_with_progname = 1;
+ }
/* Increment counter for fuzzy/untranslated messages. */
if (msgstr_string[0] == '\0')
{
if (TEST_NEWLINE(msgid_plural) != has_newline)
{
+ error_with_progname = 0;
error_at_line (0, 0, msgid_pos->file_name, msgid_pos->line_number,
_("\
`msgid' and `msgid_plural' entries do not both begin with '\\n'"));
+ error_with_progname = 1;
exit_status = EXIT_FAILURE;
}
for (p = msgstr, i = 0; p < msgstr + msgstr_len; p += strlen (p) + 1, i++)
if (TEST_NEWLINE(p) != has_newline)
{
+ error_with_progname = 0;
error_at_line (0, 0, msgid_pos->file_name, msgid_pos->line_number,
_("\
`msgid' and `msgstr[%u]' entries do not both begin with '\\n'"), i);
+ error_with_progname = 1;
exit_status = EXIT_FAILURE;
}
}
{
if (TEST_NEWLINE(msgstr) != has_newline)
{
+ error_with_progname = 0;
error_at_line (0, 0, msgid_pos->file_name, msgid_pos->line_number,
_("\
`msgid' and `msgstr' entries do not both begin with '\\n'"));
+ error_with_progname = 1;
exit_status = EXIT_FAILURE;
}
}
{
if (TEST_NEWLINE(msgid_plural) != has_newline)
{
+ error_with_progname = 0;
error_at_line (0, 0, msgid_pos->file_name, msgid_pos->line_number,
_("\
`msgid' and `msgid_plural' entries do not both end with '\\n'"));
+ error_with_progname = 1;
exit_status = EXIT_FAILURE;
}
for (p = msgstr, i = 0; p < msgstr + msgstr_len; p += strlen (p) + 1, i++)
if (TEST_NEWLINE(p) != has_newline)
{
+ error_with_progname = 0;
error_at_line (0, 0, msgid_pos->file_name, msgid_pos->line_number,
_("\
`msgid' and `msgstr[%u]' entries do not both end with '\\n'"), i);
+ error_with_progname = 1;
exit_status = EXIT_FAILURE;
}
}
{
if (TEST_NEWLINE(msgstr) != has_newline)
{
+ error_with_progname = 0;
error_at_line (0, 0, msgid_pos->file_name, msgid_pos->line_number,
_("\
`msgid' and `msgstr' entries do not both end with '\\n'"));
+ error_with_progname = 1;
exit_status = EXIT_FAILURE;
}
}
nstrfmts = parse_printf_format (msgstr, 0, NULL);
if (nidfmts != nstrfmts)
{
+ error_with_progname = 0;
error_at_line (0, 0, msgid_pos->file_name, msgid_pos->line_number,
_("\
number of format specifications in `msgid' and `msgstr' does not match"));
+ error_with_progname = 1;
exit_status = EXIT_FAILURE;
}
else
for (cnt = 0; cnt < nidfmts; ++cnt)
if (id_args[cnt] != str_args[cnt])
{
+ error_with_progname = 0;
error_at_line (0, 0, msgid_pos->file_name,
msgid_pos->line_number, _("\
format specifications for argument %lu are not the same"),
(unsigned long) (cnt + 1));
+ error_with_progname = 1;
exit_status = EXIT_FAILURE;
}
}
#include "dir-list.h"
#include "error.h"
+#include "progname.h"
#include "message.h"
#include "read-po.h"
#include "write-po.h"
#define _(str) gettext (str)
-/* String containing name the program is called with. */
-const char *program_name;
-
/* If non-zero do not print unneeded messages. */
static int quiet;
/* Prototypes for local functions. */
static void usage PARAMS ((int __status));
-static void error_print PARAMS ((void));
static message_list_ty *merge PARAMS ((const char *__fn1, const char *__fn2));
static void compendium PARAMS ((const char *__filename));
/* Set program name for messages. */
program_name = argv[0];
+ error_print_progname = maybe_print_progname;
verbosity_level = 0;
quiet = 0;
- error_print_progname = error_print;
gram_max_allowed_errors = UINT_MAX;
#ifdef HAVE_SETLOCALE
}
-/* The address of this function will be assigned to the hook in the
- error functions. */
-static void
-error_print ()
-{
- /* We don't want the program name to be printed in messages. Emacs'
- compile.el does not like this. */
-
- /* FIXME Why must this program toady to Emacs? Why can't compile.el
- be enhanced to cope with a leading program name? --PMiller */
-}
-
-
#define DOT_FREQUENCE 10
static message_list_ty *
#include "hash.h"
#include "error.h"
+#include "progname.h"
#include "getline.h"
#include "printf.h"
#include <system.h>
#endif
-/* String containing name the program is called with. */
-const char *program_name;
-
/* Force output of PO file even if empty. */
static int force_po;
/* Prototypes for local functions. */
static void usage PARAMS ((int __status));
-static void error_print PARAMS ((void));
static nls_uint32 read32 PARAMS ((FILE *__fp, const char *__fn));
static void seek32 PARAMS ((FILE *__fp, const char *__fn, long __offset));
static char *string32 PARAMS ((FILE *__fp, const char *__fn, long __offset,
/* Set program name for messages. */
program_name = argv[0];
- error_print_progname = error_print;
+ error_print_progname = maybe_print_progname;
#ifdef HAVE_SETLOCALE
/* Set locale via LC_ALL. */
}
-/* The address of this function will be assigned to the hook in the error
- functions. */
-static void
-error_print ()
-{
- /* We don't want the program name to be printed in messages. Emacs'
- compile.el does not like this. */
-}
-
-
/* This function reads a 32-bit number from the file, and assembles it
according to the current ``endian'' setting. */
static nls_uint32
vasprintf (&buffer, fmt, ap);
va_end (ap);
+ error_with_progname = 0;
error_at_line (0, 0, gram_pos.file_name, gram_pos.line_number, "%s", buffer);
+ error_with_progname = 1;
# else
+ error_with_progname = 0;
error_at_line (0, 0, gram_pos.file_name, gram_pos.line_number, fmt,
a1, a2, a3, a4, a5, a6, a7, a8);
+ error_with_progname = 1;
# endif
/* Some messages need more than one line. Continuation lines are
vasprintf (&buffer, fmt, ap);
va_end (ap);
+ error_with_progname = 0;
error_at_line (0, 0, pp->file_name, pp->line_number, "%s", buffer);
+ error_with_progname = 1;
# else
+ error_with_progname = 0;
error_at_line (0, 0, pp->file_name, pp->line_number, fmt,
a1, a2, a3, a4, a5, a6, a7, a8);
+ error_with_progname = 1;
# endif
/* Some messages need more than one line, or more than one location.
#include <sys/types.h>
#include "error.h"
+#include "progname.h"
#include "pos.h"
/* Lexical analyzer for reading PO files. */
# define po_gram_error(fmt, ...) \
do { \
+ error_with_progname = 0; \
error_at_line (0, 0, gram_pos.file_name, gram_pos.line_number, \
fmt, __VA_ARGS__); \
+ error_with_progname = 1; \
if (*fmt == '.') \
--error_message_count; \
else if (error_message_count >= gram_max_allowed_errors) \
# define po_gram_error_at_line(pos, fmt, ...) \
do { \
+ error_with_progname = 0; \
error_at_line (0, 0, (pos)->file_name, (pos)->line_number, \
fmt, __VA_ARGS__); \
+ error_with_progname = 1; \
if (*fmt == '.') \
--error_message_count; \
else if (error_message_count >= gram_max_allowed_errors) \
# define po_gram_error(fmt, args...) \
do { \
+ error_with_progname = 0; \
error_at_line (0, 0, gram_pos.file_name, gram_pos.line_number, \
fmt, ## args); \
+ error_with_progname = 1; \
if (*fmt == '.') \
--error_message_count; \
else if (error_message_count >= gram_max_allowed_errors) \
# define po_gram_error_at_line(pos, fmt, args...) \
do { \
+ error_with_progname = 0; \
error_at_line (0, 0, (pos)->file_name, (pos)->line_number, \
fmt, ## args); \
+ error_with_progname = 1; \
if (*fmt == '.') \
--error_message_count; \
else if (error_message_count >= gram_max_allowed_errors) \
#include "dir-list.h"
#include "error.h"
+#include "progname.h"
#include "system.h"
#include "libgettext.h"
#include "hash.h"
c = phase7_getc ();
if (c == P7_NEWLINE)
{
+ error_with_progname = 0;
error (0, 0, _("%s:%d: warning: unterminated character constant"),
logical_file_name, line_number - 1);
+ error_with_progname = 1;
phase7_ungetc ('\n');
break;
}
c = phase7_getc ();
if (c == P7_NEWLINE)
{
+ error_with_progname = 0;
error (0, 0, _("%s:%d: warning: unterminated string literal"),
logical_file_name, line_number - 1);
+ error_with_progname = 1;
phase7_ungetc ('\n');
break;
}
#include "dir-list.h"
#include "error.h"
+#include "progname.h"
#include "hash.h"
#include "getline.h"
#include "system.h"
/* If nonzero omit header with information about this run. */
static int omit_header;
-/* String containing name the program is called with. */
-const char *program_name;
-
/* Long options. */
static const struct option long_options[] =
{
__attribute__ ((noreturn))
#endif
;
-static void error_print PARAMS ((void));
static string_list_ty *read_name_from_file PARAMS ((const char *__file_name));
static void exclude_directive_domain PARAMS ((po_ty *__pop, char *__name));
static void exclude_directive_message PARAMS ((po_ty *__pop, char *__msgid,
/* Set program name for messages. */
program_name = argv[0];
- error_print_progname = error_print;
+ error_print_progname = maybe_print_progname;
#ifdef HAVE_SETLOCALE
/* Set locale via LC_ALL. */
}
-/* The address of this function will be assigned to the hook in the error
- functions. */
-static void
-error_print ()
-{
- /* We don't want the program name to be printed in messages. */
-}
-
-
/* Read list of files to process from file. */
static string_list_ty *
read_name_from_file (file_name)
{
if (commas_to_skip == 0)
{
+ error_with_progname = 0;
error (0, 0,
_("%s:%d: warning: keyword nested in keyword arg"),
token.file_name, token.line_number);
+ error_with_progname = 1;
continue;
}
potentially unbounded stack. We haven't run across an
example that needs this functionality yet. For now,
we punt and forget the outer keyword. */
+ error_with_progname = 0;
error (0, 0,
_("%s:%d: warning: keyword between outer keyword and its arg"),
token.file_name, token.line_number);
+ error_with_progname = 1;
}
commas_to_skip = token.argnum1 - 1;
plural_commas = (token.argnum2 > token.argnum1