prototype patch for cpplib
John Carr
jfc@tiac.net
Mon Sep 22 17:34:00 GMT 1997
Mon Sep 22 20:22:25 1997 John F. Carr <jfc@tiac.net>
* cpplib.h, cpplib.c, cpperr.c: Add ANSI C stdarg support. Define
new variants of error and warning functions taking va_list arguments.
*** cpplib.c.orig Thu Sep 11 18:51:33 1997
--- cpplib.c Mon Sep 22 20:21:13 1997
***************
*** 67,72 ****
--- 67,73 ----
#include <signal.h>
#ifdef __STDC__
#include <stdlib.h>
+ #include <string.h>
#endif
#ifndef VMS
***************
*** 246,260 ****
static void add_import ();
static void append_include_chain ();
- static void make_undef ();
static void make_assertion ();
static void path_include ();
static void initialize_builtins ();
static void initialize_char_syntax ();
- static void dump_arg_n ();
- static void dump_defn_1 ();
extern void delete_macro ();
! static void trigraph_pcp ();
static int finclude ();
static void validate_else ();
static int comp_def_part ();
--- 247,258 ----
static void add_import ();
static void append_include_chain ();
static void make_assertion ();
static void path_include ();
static void initialize_builtins ();
static void initialize_char_syntax ();
extern void delete_macro ();
! /*static void trigraph_pcp ();*/
static int finclude ();
static void validate_else ();
static int comp_def_part ();
***************
*** 261,277 ****
#ifdef abort
extern void fancy_abort ();
#endif
! static void pipe_closed ();
! static void print_containing_files ();
! static int lookup_import ();
static int redundant_include_p ();
static is_system_include ();
static struct file_name_map *read_name_map ();
static char *read_filename_string ();
! static int open_include_file ();
! static int check_preconditions ();
! static void pcfinclude ();
! static void pcstring_used ();
static int check_macro_name ();
static int compare_defs ();
static int compare_token_lists ();
--- 259,271 ----
#ifdef abort
extern void fancy_abort ();
#endif
! struct file_name_list;
! static int lookup_import PROTO((cpp_reader *pfile, char *, struct file_name_list *));
static int redundant_include_p ();
static is_system_include ();
static struct file_name_map *read_name_map ();
static char *read_filename_string ();
! static int open_include_file PROTO((cpp_reader *, char *, struct file_name_list *));
static int check_macro_name ();
static int compare_defs ();
static int compare_token_lists ();
***************
*** 281,287 ****
static int file_size_and_mode ();
static struct arglist *read_token_list ();
static void free_token_list ();
! static int safe_read ();
static void push_macro_expansion PARAMS ((cpp_reader *,
U_CHAR *, int, HASHNODE *));
static struct cpp_pending *nreverse_pending PARAMS ((struct cpp_pending *));
--- 275,281 ----
static int file_size_and_mode ();
static struct arglist *read_token_list ();
static void free_token_list ();
! static int safe_read PROTO((int, char *, int));
static void push_macro_expansion PARAMS ((cpp_reader *,
U_CHAR *, int, HASHNODE *));
static struct cpp_pending *nreverse_pending PARAMS ((struct cpp_pending *));
***************
*** 289,295 ****
static char *xcalloc ();
static char *savestring ();
! static void conditional_skip ();
static void skip_if_group ();
/* Last arg to output_line_command. */
--- 283,289 ----
static char *xcalloc ();
static char *savestring ();
! static void conditional_skip PROTO((cpp_reader *pfile, int, enum node_type, U_CHAR *));
static void skip_if_group ();
/* Last arg to output_line_command. */
***************
*** 1801,1807 ****
/* Print the warning if it's not ok. */
if (!ok)
{
! U_CHAR *msg; /* what pain... */
/* If we are passing through #define and #undef directives, do
that for this re-definition now. */
--- 1795,1801 ----
/* Print the warning if it's not ok. */
if (!ok)
{
! char *msg;
/* If we are passing through #define and #undef directives, do
that for this re-definition now. */
***************
*** 1808,1817 ****
if (CPP_OPTIONS (pfile)->debug_output && keyword)
pass_thru_directive (buf, limit, pfile, keyword);
! msg = (U_CHAR *) alloca (mdef.symlen + 22);
*msg = '`';
bcopy (mdef.symnam, msg + 1, mdef.symlen);
! strcpy ((char *) (msg + mdef.symlen + 1), "' redefined");
cpp_pedwarn (pfile, msg);
if (hp->type == T_MACRO)
cpp_pedwarn_with_file_and_line (pfile, hp->value.defn->file, hp->value.defn->line,
--- 1802,1811 ----
if (CPP_OPTIONS (pfile)->debug_output && keyword)
pass_thru_directive (buf, limit, pfile, keyword);
! msg = (char *) alloca (mdef.symlen + 22);
*msg = '`';
bcopy (mdef.symnam, msg + 1, mdef.symlen);
! strcpy ((msg + mdef.symlen + 1), "' redefined");
cpp_pedwarn (pfile, msg);
if (hp->type == T_MACRO)
cpp_pedwarn_with_file_and_line (pfile, hp->value.defn->file, hp->value.defn->line,
***************
*** 5251,5257 ****
}
if (c == '$' && CPP_PEDANTIC (pfile))
! cpp_pedwarn ("`$' in identifier");
CPP_RESERVE(pfile, 2); /* One more for final NUL. */
CPP_PUTC_Q (pfile, c);
--- 5245,5251 ----
}
if (c == '$' && CPP_PEDANTIC (pfile))
! cpp_pedwarn (pfile, "`$' in identifier");
CPP_RESERVE(pfile, 2); /* One more for final NUL. */
CPP_PUTC_Q (pfile, c);
***************
*** 5611,5617 ****
/* Read the file contents, knowing that st_size is an upper bound
on the number of bytes we can read. */
! length = safe_read (f, fp->buf, st_size);
fp->rlimit = fp->buf + length;
if (length < 0) goto nope;
}
--- 5605,5611 ----
/* Read the file contents, knowing that st_size is an upper bound
on the number of bytes we can read. */
! length = safe_read (f, (char *)fp->buf, st_size);
fp->rlimit = fp->buf + length;
if (length < 0) goto nope;
}
***************
*** 5630,5636 ****
fp->buf = (U_CHAR *) xmalloc (bsize + 2);
for (;;) {
! i = safe_read (f, fp->buf + st_size, bsize - st_size);
if (i < 0)
goto nope; /* error! */
st_size += i;
--- 5624,5630 ----
fp->buf = (U_CHAR *) xmalloc (bsize + 2);
for (;;) {
! i = safe_read (f, (char *)fp->buf + st_size, bsize - st_size);
if (i < 0)
goto nope; /* error! */
st_size += i;
***************
*** 7353,7359 ****
--- 7347,7373 ----
}
}
+ #ifdef __STDC__
void
+ cpp_error (cpp_reader *pfile, const char *msg, ...)
+ {
+ va_list ap;
+ cpp_print_containing_files (pfile);
+ cpp_print_file_and_line (pfile);
+ va_start(ap, msg);
+ cpp_vmessage (pfile, 1, msg, ap);
+ va_end (ap);
+ }
+
+ void
+ cpp_verror (cpp_reader *pfile, const char *msg, va_list ap)
+ {
+ cpp_print_containing_files (pfile);
+ cpp_print_file_and_line (pfile);
+ cpp_vmessage (pfile, 1, msg, ap);
+ }
+ #else
+ void
cpp_error (pfile, msg, arg1, arg2, arg3)
cpp_reader *pfile;
char *msg;
***************
*** 7363,7372 ****
--- 7377,7421 ----
cpp_print_file_and_line (pfile);
cpp_message (pfile, 1, msg, arg1, arg2, arg3);
}
+ #endif
/* Print error message but don't count it. */
+ #ifdef __STDC__
+
void
+ cpp_vwarning (cpp_reader *pfile, const char *msg, 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);
+ cpp_vmessage (pfile, 0, msg, ap);
+ }
+
+ void
+ cpp_warning (cpp_reader *pfile, const char *msg, ...)
+ {
+ 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);
+ va_start (ap, msg);
+ cpp_vmessage (pfile, 0, msg, ap);
+ va_end (ap);
+ }
+ #else
+ void
cpp_warning (pfile, msg, arg1, arg2, arg3)
cpp_reader *pfile;
char *msg;
***************
*** 7382,7391 ****
--- 7431,7454 ----
cpp_print_file_and_line (pfile);
cpp_message (pfile, 0, msg, arg1, arg2, arg3);
}
+ #endif
/* Print an error message and maybe count it. */
+ #ifdef __STDC__
void
+ cpp_pedwarn (cpp_reader *pfile, const char *msg, ...)
+ {
+ va_list ap;
+ va_start (ap, msg);
+ if (CPP_OPTIONS (pfile)->pedantic_errors)
+ cpp_error (pfile, msg, ap);
+ else
+ cpp_warning (pfile, msg, ap);
+ va_end (ap);
+ }
+ #else
+ void
cpp_pedwarn (pfile, msg, arg1, arg2, arg3)
cpp_reader *pfile;
char *msg;
***************
*** 7396,7403 ****
--- 7459,7493 ----
else
cpp_warning (pfile, msg, arg1, arg2, arg3);
}
+ #endif
+ #ifdef __STDC__
void
+ cpp_verror_with_line (cpp_reader *pfile, int line, int column,
+ const char *msg, va_list ap)
+ {
+ int i;
+ 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);
+
+ cpp_vmessage (pfile, 1, msg, ap);
+ }
+
+ void
+ cpp_error_with_line (cpp_reader *pfile, int line, int column,
+ const char *msg, ...)
+ {
+ va_list ap;
+ va_start (ap, msg);
+ cpp_verror_with_line (pfile, line, column, msg, ap);
+ va_end (ap);
+ }
+ #else
+ void
cpp_error_with_line (pfile, line, column, msg, arg1, arg2, arg3)
cpp_reader *pfile;
int line, column;
***************
*** 7414,7421 ****
--- 7504,7535 ----
cpp_message (pfile, 1, msg, arg1, arg2, arg3);
}
+ #endif
+ #ifdef __STDC__
static void
+ cpp_vwarning_with_line (cpp_reader *pfile, int line, int column,
+ const char *msg, 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);
+
+ cpp_vmessage (pfile, 0, msg, ap);
+ }
+ #else
+ static void
cpp_warning_with_line (pfile, line, column, msg, arg1, arg2, arg3)
cpp_reader *pfile;
int line, column;
***************
*** 7440,7447 ****
--- 7554,7576 ----
cpp_message (pfile, 0, msg, arg1, arg2, arg3);
}
+ #endif
+ #ifdef __STDC__
void
+ cpp_pedwarn_with_line (cpp_reader *pfile, int line, int column,
+ const char *msg, ...)
+ {
+ va_list ap;
+ va_start (ap, msg);
+ if (CPP_OPTIONS (pfile)->pedantic_errors)
+ cpp_verror_with_line (pfile, column, line, msg, ap);
+ else
+ cpp_vwarning_with_line (pfile, line, column, msg, ap);
+ va_end (ap);
+ }
+ #else
+ void
cpp_pedwarn_with_line (pfile, line, column, msg, arg1, arg2, arg3)
cpp_reader *pfile;
int line;
***************
*** 7453,7463 ****
--- 7582,7609 ----
else
cpp_warning_with_line (pfile, line, column, msg, arg1, arg2, arg3);
}
+ #endif
/* Report a warning (or an error if pedantic_errors)
giving specified file name and line number, not current. */
+ #ifdef __STDC__
void
+ cpp_pedwarn_with_file_and_line (cpp_reader *pfile, const char *file, int line,
+ const char *msg, ...)
+ {
+ va_list ap;
+ if (!CPP_OPTIONS (pfile)->pedantic_errors
+ && CPP_OPTIONS (pfile)->inhibit_warnings)
+ return;
+ if (file != NULL)
+ cpp_file_line_for_message (pfile, file, line, -1);
+ va_start (ap, msg);
+ cpp_vmessage (pfile, CPP_OPTIONS (pfile)->pedantic_errors, msg, ap);
+ va_end (ap);
+ }
+ #else
+ void
cpp_pedwarn_with_file_and_line (pfile, file, line, msg, arg1, arg2, arg3)
cpp_reader *pfile;
char *file;
***************
*** 7473,7478 ****
--- 7619,7625 ----
cpp_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors,
msg, arg1, arg2, arg3);
}
+ #endif
/* This defines "errno" properly for VMS, and gives us EACCES. */
#include <errno.h>
*** cpplib.h.orig Mon Aug 11 11:57:05 1997
--- cpplib.h Mon Sep 22 20:20:30 1997
***************
*** 22,27 ****
--- 22,31 ----
#include <sys/types.h>
#include <sys/stat.h>
+ #include "gansidecl.h"
+ #ifdef __STDC__
+ #include <stdarg.h>
+ #endif
#ifdef __cplusplus
extern "C" {
***************
*** 636,647 ****
extern cpp_buffer* cpp_file_buffer PARAMS((cpp_reader *));
extern void cpp_define PARAMS ((cpp_reader*, unsigned char *));
! extern void cpp_error ();
! extern void cpp_warning ();
! extern void cpp_pedwarn ();
! extern void cpp_error_with_line ();
! extern void cpp_pedwarn_with_line ();
! extern void cpp_pedwarn_with_file_and_line ();
extern void fatal ();
extern void cpp_error_from_errno ();
extern void cpp_perror_with_name ();
--- 640,659 ----
extern cpp_buffer* cpp_file_buffer PARAMS((cpp_reader *));
extern void cpp_define PARAMS ((cpp_reader*, unsigned char *));
! extern void cpp_error PVPROTO ((cpp_reader *, const char *, ...));
! extern void cpp_fatal PVPROTO ((cpp_reader *, const char *, ...));
! extern void cpp_warning PVPROTO ((cpp_reader *, const char *, ...));
! extern void cpp_pedwarn PVPROTO ((cpp_reader *, const char *, ...));
! extern void cpp_message PVPROTO ((cpp_reader *, int, const char *, ...));
! extern void cpp_error_with_line PVPROTO ((cpp_reader *, int, int, const char *, ...));
! extern void cpp_pedwarn_with_line PVPROTO ((cpp_reader *, int, int, const char *, ...));
! extern void cpp_pedwarn_with_file_and_line PVPROTO ((cpp_reader *, const char *, int, const char *, ...));
! #ifdef __STDC__
! extern void cpp_verror_with_line (cpp_reader *, int, int, const char *, va_list);
! extern void cpp_vmessage (cpp_reader *, int, const char *, va_list);
! extern void cpp_vperror (cpp_reader *, const char *, va_list);
! #endif
!
extern void fatal ();
extern void cpp_error_from_errno ();
extern void cpp_perror_with_name ();
***************
*** 656,661 ****
--- 668,676 ----
extern cpp_hashnode *cpp_lookup PARAMS ((cpp_reader *, const unsigned char *,
int, int));
+ extern void cpp_reader_init PARAMS ((cpp_reader *));
+ extern void cpp_options_init PARAMS ((cpp_options *));
+
#ifdef __cplusplus
}
#endif
*** cpperror.c.orig Mon Aug 11 11:57:05 1997
--- cpperror.c Mon Sep 22 17:33:38 1997
***************
*** 90,96 ****
--- 90,113 ----
/* IS_ERROR is 2 for "fatal" error, 1 for error, 0 for warning */
+ #ifdef __STDC__
void
+ cpp_message (cpp_reader *pfile, int is_error, const char *msg, ...)
+ {
+ va_list ap;
+ if (!is_error)
+ fprintf (stderr, "warning: ");
+ else if (is_error == 2)
+ pfile->errors = CPP_FATAL_LIMIT;
+ else if (pfile->errors < CPP_FATAL_LIMIT)
+ pfile->errors++;
+ va_start (ap, msg);
+ vfprintf (stderr, msg, ap);
+ va_end (ap);
+ fputc ('\n', stderr);
+ }
+ #else
+ void
cpp_message (pfile, is_error, msg, arg1, arg2, arg3)
int is_error;
cpp_reader *pfile;
***************
*** 106,112 ****
--- 123,145 ----
fprintf (stderr, msg, arg1, arg2, arg3);
fprintf (stderr, "\n");
}
+ #endif
+ #ifdef __STDC__
+ void
+ cpp_vmessage (cpp_reader *pfile, int is_error, const char *msg, va_list ap)
+ {
+ if (!is_error)
+ fprintf (stderr, "warning: ");
+ else if (is_error == 2)
+ pfile->errors = CPP_FATAL_LIMIT;
+ else if (pfile->errors < CPP_FATAL_LIMIT)
+ pfile->errors++;
+ vfprintf (stderr, msg, ap);
+ fputc ('\n', stderr);
+ }
+ #endif
+
/* Same as cpp_error, except we consider the error to be "fatal",
such as inconsistent options. I.e. there is little point in continuing.
(We do not exit, to support use of cpplib as a library.
***************
*** 113,119 ****
--- 146,163 ----
Instead, it is the caller's responsibility to check
CPP_FATAL_ERRORS. */
+ #ifdef __STDC__
void
+ cpp_fatal (cpp_reader *pfile, const char *str, ...)
+ {
+ va_list ap;
+ fprintf (stderr, "%s: ", progname);
+ va_start (ap, str);
+ cpp_vmessage (pfile, 2, str, ap);
+ va_end (ap);
+ }
+ #else
+ void
cpp_fatal (pfile, str, arg)
cpp_reader *pfile;
char *str, *arg;
***************
*** 121,126 ****
--- 165,171 ----
fprintf (stderr, "%s: ", progname);
cpp_message (pfile, 2, str, arg);
}
+ #endif
void
cpp_pfatal_with_name (pfile, name)
More information about the Gcc
mailing list