cpplib.c (my_strerror, [...]): Move to cpperror.c.

* cpplib.c (my_strerror, cpp_error, cpp_error_with_line,
	cpp_error_from_errno, cpp_warning, cpp_warning_with_line,
	cpp_pedwarn, cpp_pedwarn_with_line,
	cpp_pedwarn_with_file_and_line): Move to cpperror.c.
	(cpp_print_file_and_line, v_cpp_error, v_cpp_warning,
	v_cpp_error_with_line, v_cpp_warning_with_line,
	cpp_message_from_errno, cpp_perror_with_name): Delete.

	* cpperror.c (cpp_print_containing_files): Take starting
	buffer as argument.
	(cpp_file_line_for_message): Rename to cpp_print_file_and_line.
	(v_cpp_message): Now called directly by all entry points.
	Remove -1 case.
	(cpp_pfatal_with_name, cpp_message): Delete.
	(cpp_notice_from_errno, cpp_ice): New functions.
	(cpp_notice): Is now for reporting error conditions, just
	without an associated file.
	(cpp_error, cpp_error_with_line): Don't do anything if
	opts->inhibit_errors is on.
	(cpp_pedwarn_with_file_and_line): Take column argument also.

	* cpplib.h: Update prototypes of exported functions.
	(struct cpp_options): Add inhibit_errors.

	* cppalloc.c, cppfiles.c: Use fprintf not cpp_notice for
	non-error messages.  Include intl.h.

	* cppinit.c, cppmain.c: Likewise.  Also, use
	cpp_notice_from_errno instead of cpp_perror_with_name or
	cpp_pfatal_with_name, and cpp_notice instead of cpp_message.

	* cppexp.c, cpphash.c, cppinit.c, cpplib.c: Use cpp_ice to
	report internal errors.

	* cpplib.c (do_define): Switch bcopy to memcpy.
	Give cpp_pedwarn_with_file_and_line a dummy column argument.

From-SVN: r31829
This commit is contained in:
Zack Weinberg 2000-02-06 23:46:18 +00:00 committed by Zack Weinberg
parent 25e309705a
commit c1212d2f09
10 changed files with 472 additions and 499 deletions

View File

@ -1,5 +1,42 @@
2000-02-06 Zack Weinberg <zack@wolery.cumb.org>
* cpplib.c (my_strerror, cpp_error, cpp_error_with_line,
cpp_error_from_errno, cpp_warning, cpp_warning_with_line,
cpp_pedwarn, cpp_pedwarn_with_line,
cpp_pedwarn_with_file_and_line): Move to cpperror.c.
(cpp_print_file_and_line, v_cpp_error, v_cpp_warning,
v_cpp_error_with_line, v_cpp_warning_with_line,
cpp_message_from_errno, cpp_perror_with_name): Delete.
* cpperror.c (cpp_print_containing_files): Take starting
buffer as argument.
(cpp_file_line_for_message): Rename to cpp_print_file_and_line.
(v_cpp_message): Now called directly by all entry points.
Remove -1 case.
(cpp_pfatal_with_name, cpp_message): Delete.
(cpp_notice_from_errno, cpp_ice): New functions.
(cpp_notice): Is now for reporting error conditions, just
without an associated file.
(cpp_error, cpp_error_with_line): Don't do anything if
opts->inhibit_errors is on.
(cpp_pedwarn_with_file_and_line): Take column argument also.
* cpplib.h: Update prototypes of exported functions.
(struct cpp_options): Add inhibit_errors.
* cppalloc.c, cppfiles.c: Use fprintf not cpp_notice for
non-error messages. Include intl.h.
* cppinit.c, cppmain.c: Likewise. Also, use
cpp_notice_from_errno instead of cpp_perror_with_name or
cpp_pfatal_with_name, and cpp_notice instead of cpp_message.
* cppexp.c, cpphash.c, cppinit.c, cpplib.c: Use cpp_ice to
report internal errors.
* cpplib.c (do_define): Switch bcopy to memcpy.
Give cpp_pedwarn_with_file_and_line a dummy column argument.
* cpplib.c (copy_rest_of_line): Revert previous change: don't
bail out early if we hit a line comment.

View File

@ -26,13 +26,14 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "config.h"
#include "system.h"
#include "cpplib.h"
#include "intl.h"
static void memory_full PARAMS ((void)) ATTRIBUTE_NORETURN;
static void
memory_full ()
{
cpp_notice ("%s: Memory exhausted.\n", progname);
fprintf (stderr, _("%s: virtual memory exhausted\n"), progname);
exit (FATAL_EXIT_CODE);
}

View File

@ -28,14 +28,54 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "cpplib.h"
#include "intl.h"
static const char *my_strerror PARAMS ((int));
static void cpp_print_containing_files PARAMS ((cpp_reader *, cpp_buffer *));
static void cpp_print_file_and_line PARAMS ((const char *, long, long));
static void v_cpp_message PARAMS ((cpp_reader *, int,
const char *, long, long,
const char *, va_list));
/* my_strerror - return the descriptive text associated with an
`errno' code.
XXX - link with libiberty so we can use its strerror(). */
static const char *
my_strerror (errnum)
int errnum;
{
const char *result;
#ifndef VMS
#ifndef HAVE_STRERROR
result = (char *) ((errnum < sys_nerr) ? sys_errlist[errnum] : 0);
#else
result = strerror (errnum);
#endif
#else /* VMS */
/* VAXCRTL's strerror() takes an optional second argument, which only
matters when the first argument is EVMSERR. However, it's simplest
just to pass it unconditionally. `vaxc$errno' is declared in
<errno.h>, and maintained by the library in parallel with `errno'.
We assume that caller's `errnum' either matches the last setting of
`errno' by the library or else does not have the value `EVMSERR'. */
result = strerror (errnum, vaxc$errno);
#endif
if (!result)
result = "errno = ?";
return result;
}
/* Print the file names and line numbers of the #include
commands which led to the current file. */
void
cpp_print_containing_files (pfile)
static void
cpp_print_containing_files (pfile, ip)
cpp_reader *pfile;
cpp_buffer *ip;
{
cpp_buffer *ip;
int first = 1;
/* If stack of files hasn't changed since we last printed
@ -43,66 +83,87 @@ cpp_print_containing_files (pfile)
if (pfile->input_stack_listing_current)
return;
ip = cpp_file_buffer (pfile);
/* Give up if we don't find a source file. */
if (ip == NULL)
return;
/* Find the other, outer source files. */
while ((ip = CPP_PREV_BUFFER (ip)), ip != CPP_NULL_BUFFER (pfile))
{
long line, col;
cpp_buf_line_and_col (ip, &line, &col);
if (ip->fname != NULL)
{
if (first)
{
first = 0;
cpp_message (pfile, -1, "In file included from %s:%ld",
ip->nominal_fname, line);
}
else
cpp_message (pfile, -1, ",\n from %s:%ld",
ip->nominal_fname, line);
}
}
if (! first)
for (ip = CPP_PREV_BUFFER (ip);
ip != CPP_NULL_BUFFER (pfile);
ip = CPP_PREV_BUFFER (ip))
if (ip->fname != NULL)
{
long line;
cpp_buf_line_and_col (ip, &line, NULL);
if (first)
{
first = 0;
fprintf (stderr, _("In file included from %s:%ld"),
ip->nominal_fname, line);
}
else
/* Translators note: this message is used in conjunction
with "In file included from %s:%ld" and some other
tricks. We want something like this:
In file included from sys/select.h:123,
from sys/types.h:234,
from userfile.c:31:
bits/select.h:45: <error message here>
The trailing comma is at the beginning of this message,
and the trailing colon is not translated. */
fprintf (stderr, _(",\n from %s:%ld"),
ip->nominal_fname, line);
}
if (first == 0)
fputs (":\n", stderr);
/* Record we have printed the status as of this time. */
pfile->input_stack_listing_current = 1;
}
void
cpp_file_line_for_message (pfile, filename, line, column)
cpp_reader *pfile ATTRIBUTE_UNUSED;
static void
cpp_print_file_and_line (filename, line, column)
const char *filename;
int line, column;
long line, column;
{
if (filename == 0 || *filename == '\0')
filename = "<stdin>";
if (line == 0)
if (line <= 0)
fputs (_("<command line>: "), stderr);
else if (column > 0)
fprintf (stderr, "%s:%d:%d: ", filename, line, column);
fprintf (stderr, "%s:%ld:%ld: ", filename, line, column);
else
fprintf (stderr, "%s:%d: ", filename, line);
fprintf (stderr, "%s:%ld: ", filename, line);
}
/* IS_ERROR is 2 for "fatal" error, 1 for error, 0 for warning, -1 for notice */
/* IS_ERROR is 3 for ICE, 2 for merely "fatal" error,
1 for error, 0 for warning. */
void
v_cpp_message (pfile, is_error, msgid, ap)
cpp_reader * pfile;
int is_error;
const char *msgid;
va_list ap;
static void
v_cpp_message (pfile, is_error, file, line, col, msg, ap)
cpp_reader *pfile;
int is_error;
const char *file;
long line;
long col;
const char *msg;
va_list ap;
{
cpp_buffer *ip = cpp_file_buffer (pfile);
if (ip)
{
if (file == NULL)
file = ip->nominal_fname;
if (line == -1)
cpp_buf_line_and_col (ip, &line, &col);
cpp_print_containing_files (pfile, ip);
cpp_print_file_and_line (file, line, col);
}
else
fprintf (stderr, "%s: ", progname);
switch (is_error)
{
case -1:
break;
case 0:
fprintf (stderr, _("warning: "));
break;
@ -113,22 +174,28 @@ v_cpp_message (pfile, is_error, msgid, ap)
case 2:
pfile->errors = CPP_FATAL_LIMIT;
break;
case 3:
fprintf (stderr, _("internal error: "));
pfile->errors = CPP_FATAL_LIMIT;
break;
default:
cpp_fatal (pfile, "internal error: bad is_error(%d) in v_cpp_message", is_error);
cpp_ice (pfile, "bad is_error(%d) in v_cpp_message", is_error);
}
vfprintf (stderr, _(msgid), ap);
if (0 <= is_error)
fprintf (stderr, "\n");
vfprintf (stderr, _(msg), ap);
putc ('\n', stderr);
}
/* Exported interface. */
/* For reporting internal errors. Prints "internal error: " for you,
otherwise identical to cpp_fatal. */
void
cpp_message VPARAMS ((cpp_reader *pfile, int is_error, const char *msgid, ...))
{
cpp_ice VPARAMS ((cpp_reader *pfile, const char *msgid, ...))
{
#ifndef ANSI_PROTOTYPES
cpp_reader *pfile;
int is_error;
const char *msgid;
#endif
va_list ap;
@ -137,11 +204,10 @@ cpp_message VPARAMS ((cpp_reader *pfile, int is_error, const char *msgid, ...))
#ifndef ANSI_PROTOTYPES
pfile = va_arg (ap, cpp_reader *);
is_error = va_arg (ap, int);
msgid = va_arg (ap, const char *);
#endif
v_cpp_message(pfile, is_error, msgid, ap);
v_cpp_message (pfile, 3, NULL, -1, -1, msgid, ap);
va_end(ap);
}
@ -167,30 +233,41 @@ cpp_fatal VPARAMS ((cpp_reader *pfile, const char *msgid, ...))
msgid = va_arg (ap, const char *);
#endif
fprintf (stderr, "%s: ", progname);
v_cpp_message (pfile, 2, msgid, ap);
v_cpp_message (pfile, 2, NULL, -1, -1, msgid, ap);
va_end(ap);
}
void
cpp_pfatal_with_name (pfile, name)
cpp_reader *pfile;
const char *name;
cpp_error VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
{
cpp_perror_with_name (pfile, name);
#ifdef VMS
exit (vaxc$errno);
#else
exit (FATAL_EXIT_CODE);
#ifndef ANSI_PROTOTYPES
cpp_reader *pfile;
const char *msgid;
#endif
va_list ap;
VA_START(ap, msgid);
#ifndef ANSI_PROTOTYPES
pfile = va_arg (ap, cpp_reader *);
msgid = va_arg (ap, const char *);
#endif
if (CPP_OPTIONS (pfile)->inhibit_errors)
return;
v_cpp_message (pfile, 1, NULL, -1, -1, msgid, ap);
va_end(ap);
}
/* Print an error message. */
void
cpp_notice VPARAMS ((const char *msgid, ...))
{
cpp_error_with_line VPARAMS ((cpp_reader *pfile, int line, int column,
const char *msgid, ...))
{
#ifndef ANSI_PROTOTYPES
cpp_reader *pfile;
int line;
int column;
const char *msgid;
#endif
va_list ap;
@ -198,11 +275,203 @@ cpp_notice VPARAMS ((const char *msgid, ...))
VA_START (ap, msgid);
#ifndef ANSI_PROTOTYPES
pfile = va_arg (ap, cpp_reader *);
line = va_arg (ap, int);
column = va_arg (ap, int);
msgid = va_arg (ap, const char *);
#endif
fprintf (stderr, "%s: ", progname);
v_cpp_message ((cpp_reader *) 0, -1, msgid, ap);
if (CPP_OPTIONS (pfile)->inhibit_errors)
return;
v_cpp_message (pfile, 1, NULL, line, column, msgid, ap);
va_end(ap);
}
/* Error including a message from `errno'. */
void
cpp_error_from_errno (pfile, name)
cpp_reader *pfile;
const char *name;
{
cpp_error (pfile, "%s: %s", name, my_strerror (errno));
}
void
cpp_warning VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
{
#ifndef ANSI_PROTOTYPES
cpp_reader *pfile;
const char *msgid;
#endif
va_list ap;
VA_START (ap, msgid);
#ifndef ANSI_PROTOTYPES
pfile = va_arg (ap, cpp_reader *);
msgid = va_arg (ap, const char *);
#endif
if (CPP_OPTIONS (pfile)->inhibit_warnings)
return;
v_cpp_message (pfile, 0, NULL, -1, -1, msgid, ap);
va_end(ap);
}
void
cpp_warning_with_line VPARAMS ((cpp_reader * pfile, int line, int column,
const char *msgid, ...))
{
#ifndef ANSI_PROTOTYPES
cpp_reader *pfile;
int line;
int column;
const char *msgid;
#endif
va_list ap;
VA_START (ap, msgid);
#ifndef ANSI_PROTOTYPES
pfile = va_arg (ap, cpp_reader *);
line = va_arg (ap, int);
column = va_arg (ap, int);
msgid = va_arg (ap, const char *);
#endif
if (CPP_OPTIONS (pfile)->inhibit_warnings)
return;
v_cpp_message (pfile, 0, NULL, line, column, msgid, ap);
va_end(ap);
}
void
cpp_pedwarn VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
{
#ifndef ANSI_PROTOTYPES
cpp_reader *pfile;
const char *msgid;
#endif
va_list ap;
VA_START (ap, msgid);
#ifndef ANSI_PROTOTYPES
pfile = va_arg (ap, cpp_reader *);
msgid = va_arg (ap, const char *);
#endif
if (CPP_OPTIONS (pfile)->pedantic_errors
? CPP_OPTIONS (pfile)->inhibit_errors
: CPP_OPTIONS (pfile)->inhibit_warnings)
return;
v_cpp_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors,
NULL, -1, -1, msgid, ap);
va_end(ap);
}
void
cpp_pedwarn_with_line VPARAMS ((cpp_reader * pfile, int line, int column,
const char *msgid, ...))
{
#ifndef ANSI_PROTOTYPES
cpp_reader *pfile;
int line;
int column;
const char *msgid;
#endif
va_list ap;
VA_START (ap, msgid);
#ifndef ANSI_PROTOTYPES
pfile = va_arg (ap, cpp_reader *);
line = va_arg (ap, int);
column = va_arg (ap, int);
msgid = va_arg (ap, const char *);
#endif
if (CPP_OPTIONS (pfile)->pedantic_errors
? CPP_OPTIONS (pfile)->inhibit_errors
: CPP_OPTIONS (pfile)->inhibit_warnings)
return;
v_cpp_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors,
NULL, line, column, msgid, ap);
va_end(ap);
}
/* Report a warning (or an error if pedantic_errors)
giving specified file name and line number, not current. */
void
cpp_pedwarn_with_file_and_line VPARAMS ((cpp_reader *pfile,
const char *file, int line, int col,
const char *msgid, ...))
{
#ifndef ANSI_PROTOTYPES
cpp_reader *pfile;
const char *file;
int line;
int col;
const char *msgid;
#endif
va_list ap;
VA_START (ap, msgid);
#ifndef ANSI_PROTOTYPES
pfile = va_arg (ap, cpp_reader *);
file = va_arg (ap, const char *);
line = va_arg (ap, int);
col = va_arg (ap, int);
msgid = va_arg (ap, const char *);
#endif
if (CPP_OPTIONS (pfile)->pedantic_errors
? CPP_OPTIONS (pfile)->inhibit_errors
: CPP_OPTIONS (pfile)->inhibit_warnings)
return;
v_cpp_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors,
file, line, col, msgid, ap);
va_end(ap);
}
/* Print an error message not associated with a file. */
void
cpp_notice VPARAMS ((cpp_reader *pfile, const char *msgid, ...))
{
#ifndef ANSI_PROTOTYPES
cpp_reader *pfile;
const char *msgid;
#endif
va_list ap;
VA_START (ap, msgid);
#ifndef ANSI_PROTOTYPES
pfile = va_arg (ap, cpp_reader *);
msgid = va_arg (ap, const char *);
#endif
if (pfile->errors < CPP_FATAL_LIMIT)
pfile->errors++;
vfprintf (stderr, _(msgid), ap);
putc('\n', stderr);
va_end(ap);
}
void
cpp_notice_from_errno (pfile, name)
cpp_reader *pfile;
const char *name;
{
cpp_notice (pfile, "%s: %s", name, my_strerror (errno));
}

View File

@ -733,7 +733,7 @@ cpp_parse_expr (pfile)
switch (op.op)
{
case NAME:
cpp_fatal (pfile, "internal error: cpp_lex returns a NAME");
cpp_ice (pfile, "cpp_lex returns a NAME");
goto syntax_error;
case INT: case CHAR:
top->value = op.value;
@ -1020,7 +1020,7 @@ cpp_parse_expr (pfile)
if (op.op == 0)
{
if (top != stack)
cpp_error (pfile, "internal error in #if expression");
cpp_ice (pfile, "unbalanced stack in #if expression");
if (stack != init_stack)
free (stack);
return top->value;

View File

@ -26,6 +26,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "config.h"
#include "system.h"
#include "cpplib.h"
#include "intl.h"
/* The entry points to this file are: find_include_file, finclude,
include_hash, append_include_chain, deps_output, and file_cleanup.
@ -126,7 +127,8 @@ merge_include_chains (opts)
&& cur->dev == other->dev)
{
if (opts->verbose)
cpp_notice ("ignoring duplicate directory `%s'\n", cur->name);
fprintf (stderr, _("ignoring duplicate directory `%s'\n"),
cur->name);
prev->next = cur->next;
free (cur->name);
@ -145,7 +147,8 @@ merge_include_chains (opts)
&& cur->dev == other->dev)
{
if (opts->verbose)
cpp_notice ("ignoring duplicate directory `%s'\n", cur->name);
fprintf (stderr, _("ignoring duplicate directory `%s'\n"),
cur->name);
prev->next = cur->next;
free (cur->name);
@ -163,8 +166,8 @@ merge_include_chains (opts)
if (quote == qtail)
{
if (opts->verbose)
cpp_notice ("ignoring duplicate directory `%s'\n",
quote->name);
fprintf (stderr, _("ignoring duplicate directory `%s'\n"),
quote->name);
free (quote->name);
free (quote);
@ -177,8 +180,8 @@ merge_include_chains (opts)
cur = cur->next;
cur->next = brack;
if (opts->verbose)
cpp_notice ("ignoring duplicate directory `%s'\n",
qtail->name);
fprintf (stderr, _("ignoring duplicate directory `%s'\n"),
qtail->name);
free (qtail->name);
free (qtail);

View File

@ -295,7 +295,7 @@ collect_expansion (pfile, buf, limit, nargs, arglist)
if (limit < buf)
{
cpp_fatal (pfile, "internal error: limit < buf in collect_expansion");
cpp_ice (pfile, "limit < buf in collect_expansion");
limit = buf; /* treat it like a null defn */
}
@ -974,7 +974,7 @@ special_symbol (hp, pfile)
break;
default:
cpp_fatal (pfile, "cpplib internal error: invalid special hash type");
cpp_ice (pfile, "invalid special hash type");
return;
}
}
@ -1351,7 +1351,7 @@ macroexpand (pfile, hp)
if (totlen > xbuf_len)
{
cpp_fatal (pfile, "internal_error: buffer overrun in macroexpand");
cpp_ice (pfile, "buffer overrun in macroexpand");
return;
}
}

View File

@ -343,15 +343,15 @@ append_include_chain (pfile, pend, dir, path)
{
/* Dirs that don't exist are silently ignored. */
if (errno != ENOENT)
cpp_perror_with_name (pfile, dir);
cpp_notice_from_errno (pfile, dir);
else if (CPP_OPTIONS (pfile)->verbose)
cpp_notice ("ignoring nonexistent directory `%s'\n", dir);
fprintf (stderr, _("ignoring nonexistent directory `%s'\n"), dir);
return;
}
if (!S_ISDIR (st.st_mode))
{
cpp_message (pfile, 1, "%s: %s: Not a directory", progname, dir);
cpp_notice (pfile, "%s: Not a directory", dir);
return;
}
@ -855,14 +855,14 @@ cpp_start_read (pfile, fname)
if (opts->verbose)
{
struct file_name_list *p;
cpp_message (pfile, -1, "#include \"...\" search starts here:\n");
fprintf (stderr, _("#include \"...\" search starts here:\n"));
for (p = opts->quote_include; p; p = p->next)
{
if (p == opts->bracket_include)
cpp_message (pfile, -1, "#include <...> search starts here:\n");
fprintf (stderr, _("#include <...> search starts here:\n"));
fprintf (stderr, " %s\n", p->name);
}
cpp_message (pfile, -1, "End of search list.\n");
fprintf (stderr, _("End of search list.\n"));
}
/* Don't bother trying to do macro expansion if we've already done
@ -880,7 +880,10 @@ cpp_start_read (pfile, fname)
f = 0;
}
else if ((f = open (fname, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666)) < 0)
cpp_pfatal_with_name (pfile, fname);
{
cpp_notice_from_errno (pfile, fname);
return 0;
}
initialize_dependency_output (pfile);
@ -918,7 +921,7 @@ cpp_start_read (pfile, fname)
int fd = open (p->arg, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666);
if (fd < 0)
{
cpp_perror_with_name (pfile, p->arg);
cpp_notice_from_errno (pfile, p->arg);
return 0;
}
if (!cpp_push_buffer (pfile, NULL, 0))
@ -957,7 +960,7 @@ cpp_start_read (pfile, fname)
int fd = open (p->arg, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666);
if (fd < 0)
{
cpp_perror_with_name (pfile, p->arg);
cpp_notice_from_errno (pfile, p->arg);
return 0;
}
if (!cpp_push_buffer (pfile, NULL, 0))
@ -1004,14 +1007,13 @@ cpp_finish (pfile)
struct cpp_options *opts = CPP_OPTIONS (pfile);
if (CPP_PREV_BUFFER (CPP_BUFFER (pfile)) != CPP_NULL_BUFFER (pfile))
cpp_fatal (pfile,
"cpplib internal error: buffers still stacked in cpp_finish");
cpp_ice (pfile, "buffers still stacked in cpp_finish");
cpp_pop_buffer (pfile);
if (opts->print_deps)
{
/* Stream on which to print the dependency information. */
FILE *deps_stream;
FILE *deps_stream = 0;
/* Don't actually write the deps file if compilation has failed. */
if (pfile->errors == 0)
@ -1020,13 +1022,17 @@ cpp_finish (pfile)
if (opts->deps_file == 0)
deps_stream = stdout;
else if ((deps_stream = fopen (opts->deps_file, deps_mode)) == 0)
cpp_pfatal_with_name (pfile, opts->deps_file);
fputs (pfile->deps_buffer, deps_stream);
putc ('\n', deps_stream);
if (opts->deps_file)
cpp_notice_from_errno (pfile, opts->deps_file);
if (deps_stream)
{
if (ferror (deps_stream) || fclose (deps_stream) != 0)
cpp_fatal (pfile, "I/O error on output");
fputs (pfile->deps_buffer, deps_stream);
putc ('\n', deps_stream);
if (opts->deps_file)
{
if (ferror (deps_stream) || fclose (deps_stream) != 0)
cpp_fatal (pfile, "I/O error on output");
}
}
}
}
@ -1487,12 +1493,12 @@ cpp_handle_option (pfile, argc, argv)
if (!strcmp (argv[i], "--help"))
print_help ();
else if (!strcmp (argv[i], "--version"))
cpp_notice ("GNU CPP version %s (cpplib)\n", version_string);
fprintf (stderr, _("GNU CPP version %s (cpplib)\n"), version_string);
exit (0); /* XXX */
break;
case 'v':
cpp_notice ("GNU CPP version %s (cpplib)", version_string);
fprintf (stderr, _("GNU CPP version %s (cpplib)\n"), version_string);
#ifdef TARGET_VERSION
TARGET_VERSION;
#endif
@ -1673,7 +1679,7 @@ cpp_handle_options (pfile, argc, argv)
static void
print_help ()
{
cpp_notice ("Usage: %s [switches] input output\n", progname);
fprintf (stderr, _("Usage: %s [switches] input output\n"), progname);
fputs (_("\
Switches:\n\
-include <file> Include the contents of <file> before other files\n\

View File

@ -74,7 +74,6 @@ static int do_warning PARAMS ((cpp_reader *, const struct directive *));
/* Forward declarations. */
static const char *my_strerror PARAMS ((int));
static void validate_else PARAMS ((cpp_reader *, const char *));
static HOST_WIDEST_INT eval_if_expression PARAMS ((cpp_reader *));
static void conditional_skip PARAMS ((cpp_reader *, int,
@ -96,15 +95,6 @@ static void pass_thru_directive PARAMS ((const U_CHAR *, size_t,
const struct directive *));
static enum cpp_token get_directive_token PARAMS ((cpp_reader *));
static int read_line_number PARAMS ((cpp_reader *, int *));
static void cpp_print_file_and_line PARAMS ((cpp_reader *));
static void v_cpp_error PARAMS ((cpp_reader *, const char *,
va_list));
static void v_cpp_warning PARAMS ((cpp_reader *, const char *,
va_list));
static void v_cpp_error_with_line PARAMS ((cpp_reader *, int, int,
const char *, va_list));
static void v_cpp_warning_with_line PARAMS ((cpp_reader *, int, int,
const char *, va_list));
static U_CHAR *detect_if_not_defined PARAMS ((cpp_reader *));
static int consider_directive_while_skipping PARAMS ((cpp_reader *,
IF_STACK_FRAME *));
@ -551,8 +541,8 @@ handle_directive (pfile)
if (ident_length == 0)
{
/* A line of just `#' becomes blank. A line with something
other than an identifier after the # is reparsed as a non-
directive line. */
other than an identifier after the # is reparsed as a non-
directive line. */
CPP_SET_WRITTEN (pfile, old_written);
return (PEEKC() == '\n');
}
@ -661,7 +651,7 @@ do_define (pfile, keyword)
buf = pfile->token_buffer + here;
end = CPP_PWRITTEN (pfile);
macro = (U_CHAR *) alloca (end - buf + 1);
bcopy (buf, macro, end - buf + 1);
memcpy (macro, buf, end - buf + 1);
end = macro + (end - buf);
CPP_SET_WRITTEN (pfile, here);
@ -697,7 +687,7 @@ do_define (pfile, keyword)
cpp_pedwarn (pfile, "`%.*s' redefined", mdef.symlen, mdef.symnam);
if (hp->type == T_MACRO && CPP_OPTIONS (pfile)->done_initializing)
cpp_pedwarn_with_file_and_line (pfile, hp->value.defn->file,
hp->value.defn->line,
hp->value.defn->line, -1,
"this is the location of the previous definition");
}
if (hp->type != T_POISON)
@ -838,7 +828,7 @@ cpp_expand_to_buffer (pfile, buf, length)
if (length < 0)
{
cpp_fatal (pfile, "internal error: length < 0 in cpp_expand_to_buffer");
cpp_ice (pfile, "length < 0 in cpp_expand_to_buffer");
return;
}
@ -1000,7 +990,7 @@ get_directive_token (pfile)
/* token cannot be vspace, it would have been caught above. */
if (token == CPP_VSPACE)
{
cpp_fatal (pfile, "VSPACE in get_directive_token");
cpp_ice (pfile, "VSPACE in get_directive_token");
return token;
}
@ -1010,12 +1000,12 @@ get_directive_token (pfile)
if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
{
cpp_fatal (pfile, "POP of file buffer in get_directive_token");
cpp_ice (pfile, "POP of file buffer in get_directive_token");
return token;
}
/* We must pop the buffer by hand, else cpp_get_token might hand
us whitespace or newline on the next invocation. */
/* We must pop the buffer by hand, or else cpp_get_token might
hand us white space or newline on the next invocation. */
cpp_pop_buffer (pfile);
}
}
@ -1145,7 +1135,7 @@ do_include (pfile, keyword)
if (fp == CPP_NULL_BUFFER (pfile))
{
cpp_fatal (pfile, "cpp internal error: fp == NULL_BUFFER in do_include");
cpp_ice (pfile, "fp == NULL_BUFFER in do_include");
return 0;
}
@ -2253,7 +2243,7 @@ if_directive_name (pfile, ifs)
case T_ELIF: return "#elif";
case T_ELSE: return "#else";
default:
cpp_fatal (pfile, "impossible if_stack->type value %d", ifs->type);
cpp_ice (pfile, "impossible if_stack->type value %d", ifs->type);
return "unknown";
}
}
@ -2448,9 +2438,7 @@ cpp_get_token (pfile)
here. Just delete 'em. */
int d = GETC();
if (d != '-' && d != ' ')
cpp_fatal (pfile,
"internal error: unrecognized escape \\r%c",
d);
cpp_ice (pfile, "unrecognized escape \\r%c", d);
CPP_ADJUST_WRITTEN (pfile, -1);
}
}
@ -2707,8 +2695,7 @@ cpp_get_token (pfile)
}
else
{
cpp_fatal (pfile,
"internal error: unrecognized escape \\r%c", c);
cpp_ice (pfile, "unrecognized escape \\r%c", c);
goto get_next;
}
}
@ -2868,8 +2855,7 @@ parse_string (pfile, c)
CPP_ADJUST_WRITTEN (pfile, -1);
if (CPP_BUFFER (pfile)->has_escapes)
{
cpp_fatal (pfile,
"internal error: \\r escape inside string constant");
cpp_ice (pfile, "\\r escape inside string constant");
FORWARD(1);
}
else
@ -3015,8 +3001,7 @@ do_assert (pfile, keyword)
else if (base->type != T_ASSERT)
{
/* Token clash - but with what?! */
cpp_fatal (pfile,
"cpp internal error: base->type != T_ASSERT in do_assert");
cpp_ice (pfile, "base->type != T_ASSERT in do_assert");
goto error;
}
@ -3145,8 +3130,7 @@ parse_set_mark (pfile)
{
cpp_buffer *ip = CPP_BUFFER (pfile);
if (ip->mark != -1)
cpp_fatal (pfile,
"cpp internal error: ip->mark != -1 in parse_set_mark");
cpp_ice (pfile, "ip->mark != -1 in parse_set_mark");
ip->mark = ip->cur - ip->buf;
}
@ -3159,8 +3143,7 @@ parse_clear_mark (pfile)
{
cpp_buffer *ip = CPP_BUFFER (pfile);
if (ip->mark == -1)
cpp_fatal (pfile,
"cpp internal error: ip->mark == -1 in parse_clear_mark");
cpp_ice (pfile, "ip->mark == -1 in parse_clear_mark");
ip->mark = -1;
}
@ -3174,340 +3157,8 @@ parse_goto_mark (pfile)
{
cpp_buffer *ip = CPP_BUFFER (pfile);
if (ip->mark == -1)
cpp_fatal (pfile,
"cpp internal error: ip->mark == -1 in parse_goto_mark");
cpp_ice (pfile, "ip->mark == -1 in parse_goto_mark");
ip->cur = ip->buf + ip->mark;
ip->mark = -1;
}
static void
cpp_print_file_and_line (pfile)
cpp_reader *pfile;
{
cpp_buffer *ip = cpp_file_buffer (pfile);
if (ip != NULL)
{
long line, col;
cpp_buf_line_and_col (ip, &line, &col);
cpp_file_line_for_message (pfile, ip->nominal_fname,
line, pfile->show_column ? col : -1);
}
}
static void
v_cpp_error (pfile, msgid, ap)
cpp_reader *pfile;
const char *msgid;
va_list ap;
{
cpp_print_containing_files (pfile);
cpp_print_file_and_line (pfile);
v_cpp_message (pfile, 1, msgid, ap);
}
void
cpp_error VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
{
#ifndef ANSI_PROTOTYPES
cpp_reader *pfile;
const char *msgid;
#endif
va_list ap;
VA_START(ap, msgid);
#ifndef ANSI_PROTOTYPES
pfile = va_arg (ap, cpp_reader *);
msgid = va_arg (ap, const char *);
#endif
v_cpp_error (pfile, msgid, ap);
va_end(ap);
}
/* Print error message but don't count it. */
static void
v_cpp_warning (pfile, msgid, ap)
cpp_reader *pfile;
const char *msgid;
va_list ap;
{
if (CPP_OPTIONS (pfile)->inhibit_warnings)
return;
if (CPP_OPTIONS (pfile)->warnings_are_errors)
pfile->errors++;
cpp_print_containing_files (pfile);
cpp_print_file_and_line (pfile);
v_cpp_message (pfile, 0, msgid, ap);
}
void
cpp_warning VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
{
#ifndef ANSI_PROTOTYPES
cpp_reader *pfile;
const char *msgid;
#endif
va_list ap;
VA_START (ap, msgid);
#ifndef ANSI_PROTOTYPES
pfile = va_arg (ap, cpp_reader *);
msgid = va_arg (ap, const char *);
#endif
v_cpp_warning (pfile, msgid, ap);
va_end(ap);
}
/* Print an error message and maybe count it. */
void
cpp_pedwarn VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
{
#ifndef ANSI_PROTOTYPES
cpp_reader *pfile;
const char *msgid;
#endif
va_list ap;
VA_START (ap, msgid);
#ifndef ANSI_PROTOTYPES
pfile = va_arg (ap, cpp_reader *);
msgid = va_arg (ap, const char *);
#endif
if (CPP_OPTIONS (pfile)->pedantic_errors)
v_cpp_error (pfile, msgid, ap);
else
v_cpp_warning (pfile, msgid, ap);
va_end(ap);
}
static void
v_cpp_error_with_line (pfile, line, column, msgid, ap)
cpp_reader * pfile;
int line;
int column;
const char * msgid;
va_list ap;
{
cpp_buffer *ip = cpp_file_buffer (pfile);
cpp_print_containing_files (pfile);
if (ip != NULL)
cpp_file_line_for_message (pfile, ip->nominal_fname, line, column);
v_cpp_message (pfile, 1, msgid, ap);
}
void
cpp_error_with_line VPARAMS ((cpp_reader * pfile, int line, int column,
const char *msgid, ...))
{
#ifndef ANSI_PROTOTYPES
cpp_reader *pfile;
int line;
int column;
const char *msgid;
#endif
va_list ap;
VA_START (ap, msgid);
#ifndef ANSI_PROTOTYPES
pfile = va_arg (ap, cpp_reader *);
line = va_arg (ap, int);
column = va_arg (ap, int);
msgid = va_arg (ap, const char *);
#endif
v_cpp_error_with_line(pfile, line, column, msgid, ap);
va_end(ap);
}
static void
v_cpp_warning_with_line (pfile, line, column, msgid, ap)
cpp_reader * pfile;
int line;
int column;
const char *msgid;
va_list ap;
{
cpp_buffer *ip;
if (CPP_OPTIONS (pfile)->inhibit_warnings)
return;
if (CPP_OPTIONS (pfile)->warnings_are_errors)
pfile->errors++;
cpp_print_containing_files (pfile);
ip = cpp_file_buffer (pfile);
if (ip != NULL)
cpp_file_line_for_message (pfile, ip->nominal_fname, line, column);
v_cpp_message (pfile, 0, msgid, ap);
}
void
cpp_warning_with_line VPARAMS ((cpp_reader * pfile, int line, int column,
const char *msgid, ...))
{
#ifndef ANSI_PROTOTYPES
cpp_reader *pfile;
int line;
int column;
const char *msgid;
#endif
va_list ap;
VA_START (ap, msgid);
#ifndef ANSI_PROTOTYPES
pfile = va_arg (ap, cpp_reader *);
line = va_arg (ap, int);
column = va_arg (ap, int);
msgid = va_arg (ap, const char *);
#endif
v_cpp_warning_with_line (pfile, line, column, msgid, ap);
va_end(ap);
}
void
cpp_pedwarn_with_line VPARAMS ((cpp_reader * pfile, int line, int column,
const char *msgid, ...))
{
#ifndef ANSI_PROTOTYPES
cpp_reader *pfile;
int line;
int column;
const char *msgid;
#endif
va_list ap;
VA_START (ap, msgid);
#ifndef ANSI_PROTOTYPES
pfile = va_arg (ap, cpp_reader *);
line = va_arg (ap, int);
column = va_arg (ap, int);
msgid = va_arg (ap, const char *);
#endif
if (CPP_OPTIONS (pfile)->pedantic_errors)
v_cpp_error_with_line (pfile, column, line, msgid, ap);
else
v_cpp_warning_with_line (pfile, line, column, msgid, ap);
va_end(ap);
}
/* Report a warning (or an error if pedantic_errors)
giving specified file name and line number, not current. */
void
cpp_pedwarn_with_file_and_line VPARAMS ((cpp_reader *pfile, const char *file,
int line, const char *msgid, ...))
{
#ifndef ANSI_PROTOTYPES
cpp_reader *pfile;
const char *file;
int line;
const char *msgid;
#endif
va_list ap;
VA_START (ap, msgid);
#ifndef ANSI_PROTOTYPES
pfile = va_arg (ap, cpp_reader *);
file = va_arg (ap, const char *);
line = va_arg (ap, int);
msgid = va_arg (ap, const char *);
#endif
if (!CPP_OPTIONS (pfile)->pedantic_errors
&& CPP_OPTIONS (pfile)->inhibit_warnings)
return;
cpp_file_line_for_message (pfile, file, line, -1);
v_cpp_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors, msgid, ap);
va_end(ap);
}
/* my_strerror - return the descriptive text associated with an
`errno' code. */
static const char *
my_strerror (errnum)
int errnum;
{
const char *result;
#ifndef VMS
#ifndef HAVE_STRERROR
result = (char *) ((errnum < sys_nerr) ? sys_errlist[errnum] : 0);
#else
result = strerror (errnum);
#endif
#else /* VMS */
/* VAXCRTL's strerror() takes an optional second argument, which only
matters when the first argument is EVMSERR. However, it's simplest
just to pass it unconditionally. `vaxc$errno' is declared in
<errno.h>, and maintained by the library in parallel with `errno'.
We assume that caller's `errnum' either matches the last setting of
`errno' by the library or else does not have the value `EVMSERR'. */
result = strerror (errnum, vaxc$errno);
#endif
if (!result)
result = "errno = ?";
return result;
}
/* Error including a message from `errno'. */
void
cpp_error_from_errno (pfile, name)
cpp_reader *pfile;
const char *name;
{
cpp_message_from_errno (pfile, 1, name);
}
void
cpp_message_from_errno (pfile, is_error, name)
cpp_reader *pfile;
int is_error;
const char *name;
{
int e = errno;
cpp_buffer *ip = cpp_file_buffer (pfile);
cpp_print_containing_files (pfile);
if (ip != NULL)
cpp_file_line_for_message (pfile, ip->nominal_fname, ip->lineno, -1);
cpp_message (pfile, is_error, "%s: %s", name, my_strerror (e));
}
void
cpp_perror_with_name (pfile, name)
cpp_reader *pfile;
const char *name;
{
cpp_message (pfile, 1, "%s: %s: %s", progname, name, my_strerror (errno));
}

View File

@ -386,10 +386,15 @@ struct cpp_options {
char pedantic_errors;
/* Nonzero means don't print warning messages. -w. */
/* Nonzero means don't print warning messages. */
char inhibit_warnings;
/* Nonzero means don't print error messages. Has no option to select it,
but can be set by a user of cpplib (e.g. fix-header). */
char inhibit_errors;
/* Nonzero means warn if slash-star appears in a comment. */
char warn_comments;
@ -710,24 +715,34 @@ extern void cpp_assert PARAMS ((cpp_reader *, unsigned char *));
extern void cpp_undef PARAMS ((cpp_reader *, unsigned char *));
extern void cpp_unassert PARAMS ((cpp_reader *, unsigned char *));
extern void cpp_error PARAMS ((cpp_reader *, const char *, ...))
/* N.B. The error-message-printer prototypes have not been nicely
formatted because exgettext needs to see 'msgid' on the same line
as the name of the function in order to work properly. Only the
string argument gets a name in an effort to keep the lines from
getting ridiculously oversized. */
extern void cpp_ice PARAMS ((cpp_reader *, const char *msgid, ...))
ATTRIBUTE_PRINTF_2;
extern void cpp_warning PARAMS ((cpp_reader *, const char *, ...))
extern void cpp_fatal PARAMS ((cpp_reader *, const char *msgid, ...))
ATTRIBUTE_PRINTF_2;
extern void cpp_pedwarn PARAMS ((cpp_reader *, const char *, ...))
extern void cpp_error PARAMS ((cpp_reader *, const char *msgid, ...))
ATTRIBUTE_PRINTF_2;
extern void cpp_error_with_line PARAMS ((cpp_reader *, int, int, const char *, ...))
extern void cpp_warning PARAMS ((cpp_reader *, const char *msgid, ...))
ATTRIBUTE_PRINTF_2;
extern void cpp_pedwarn PARAMS ((cpp_reader *, const char *msgid, ...))
ATTRIBUTE_PRINTF_2;
extern void cpp_notice PARAMS ((cpp_reader *, const char *msgid, ...))
ATTRIBUTE_PRINTF_2;
extern void cpp_error_with_line PARAMS ((cpp_reader *, int, int, const char *msgid, ...))
ATTRIBUTE_PRINTF_4;
extern void cpp_warning_with_line PARAMS ((cpp_reader *, int, int, const char *, ...))
extern void cpp_warning_with_line PARAMS ((cpp_reader *, int, int, const char *msgid, ...))
ATTRIBUTE_PRINTF_4;
extern void cpp_pedwarn_with_line PARAMS ((cpp_reader *, int, int, const char *, ...))
extern void cpp_pedwarn_with_line PARAMS ((cpp_reader *, int, int, const char *msgid, ...))
ATTRIBUTE_PRINTF_4;
extern void cpp_pedwarn_with_file_and_line PARAMS ((cpp_reader *, const char *, int, const char *, ...))
ATTRIBUTE_PRINTF_4;
extern void cpp_message_from_errno PARAMS ((cpp_reader *, int, const char *));
extern void cpp_pedwarn_with_file_and_line PARAMS ((cpp_reader *, const char *, int, int, const char *msgid, ...))
ATTRIBUTE_PRINTF_5;
extern void cpp_error_from_errno PARAMS ((cpp_reader *, const char *));
extern void cpp_perror_with_name PARAMS ((cpp_reader *, const char *));
extern void v_cpp_message PARAMS ((cpp_reader *, int, const char *, va_list));
extern void cpp_notice_from_errno PARAMS ((cpp_reader *, const char *));
extern void cpp_grow_buffer PARAMS ((cpp_reader *, long));
extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
@ -755,18 +770,6 @@ enum file_change_code {same_file, enter_file, leave_file};
extern void output_line_command PARAMS ((cpp_reader *,
enum file_change_code));
/* From cpperror.c */
extern void cpp_fatal PARAMS ((cpp_reader *, const char *, ...))
ATTRIBUTE_PRINTF_2;
extern void cpp_message PARAMS ((cpp_reader *, int, const char *, ...))
ATTRIBUTE_PRINTF_3;
extern void cpp_pfatal_with_name PARAMS ((cpp_reader *, const char *))
ATTRIBUTE_NORETURN;
extern void cpp_file_line_for_message PARAMS ((cpp_reader *, const char *,
int, int));
extern void cpp_print_containing_files PARAMS ((cpp_reader *));
extern void cpp_notice PARAMS ((const char *msgid, ...)) ATTRIBUTE_PRINTF_1;
/* In cppfiles.c */
extern void simplify_pathname PARAMS ((char *));
extern void merge_include_chains PARAMS ((struct cpp_options *));

View File

@ -73,7 +73,10 @@ main (argc, argv)
if (!opts->out_fname || !strcmp (opts->out_fname, ""))
opts->out_fname = "stdout";
else if (! freopen (opts->out_fname, "w", stdout))
cpp_pfatal_with_name (&parse_in, opts->out_fname);
{
cpp_notice_from_errno (&parse_in, opts->out_fname);
return (FATAL_EXIT_CODE);
}
if (! opts->no_output)
{
@ -87,7 +90,7 @@ main (argc, argv)
rem = fwrite (parse_in.token_buffer, 1, count, stdout);
if (rem < count)
/* Write error. */
cpp_pfatal_with_name (&parse_in, opts->out_fname);
cpp_notice_from_errno (&parse_in, opts->out_fname);
CPP_SET_WRITTEN (&parse_in, 0);
}
@ -108,7 +111,7 @@ main (argc, argv)
cpp_finish (&parse_in);
if (fwrite (parse_in.token_buffer, 1, CPP_WRITTEN (&parse_in), stdout)
< CPP_WRITTEN (&parse_in))
cpp_pfatal_with_name (&parse_in, opts->out_fname);
cpp_notice_from_errno (&parse_in, opts->out_fname);
cpp_cleanup (&parse_in);