OSDN Git Service

(handle_braces): Rework last change.
[pf3gnuchains/gcc-fork.git] / gcc / cpperror.c
index 982bcc3..0cf24b9 100644 (file)
@@ -16,36 +16,19 @@ 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, 675 Mass Ave, Cambridge, MA 02139, USA.
+Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
  In other words, you are welcome to use, share and improve this program.
  You are forbidden to forbid anyone else to use, share and improve
  what you give them.   Help stamp out software-hoarding!  */
 
+#ifndef EMACS
+#include "config.h"
+#endif /* not EMACS */
+
 #include "cpplib.h"
 #include <stdio.h>
 
-/* This defines "errno" properly for VMS, and gives us EACCES. */
-#include <errno.h>
-#ifndef errno
-extern int errno;
-#endif
-
-#ifndef VMS
-#ifndef HAVE_STRERROR
-extern int sys_nerr;
-#if defined(bsd4_4)
-extern const char *const sys_errlist[];
-#else
-extern char *sys_errlist[];
-#endif
-#else  /* HAVE_STERRROR */
-char *strerror ();
-#endif
-#else  /* VMS */
-char *strerror (int,...);
-#endif
-
 /* Print the file names and line numbers of the #include
    commands which led to the current file.  */
 
@@ -84,15 +67,7 @@ cpp_print_containing_files (pfile)
            fprintf (stderr, ",\n                ");
        }
 
-/* start-sanitize-mpw */
-#ifdef MPW
-      fprintf (stderr, " File \"%s\"; Line %d  # ", ip->nominal_fname, line);
-#else
-/* end-sanitize-mpw */
       fprintf (stderr, " from %s:%d", ip->nominal_fname, line);
-/* start-sanitize-mpw */
-#endif /* MPW */
-/* end-sanitize-mpw */
     }
   if (! first)
     fprintf (stderr, ":\n");
@@ -102,228 +77,51 @@ cpp_print_containing_files (pfile)
 }
 
 void
-cpp_print_file_and_line (pfile)
+cpp_file_line_for_message (pfile, filename, line, column)
      cpp_reader *pfile;
+     char *filename;
+     int line, column;
 {
-  cpp_buffer *ip = cpp_file_buffer (pfile);
-
-  if (ip != NULL)
-    {
-      long line, col;
-      cpp_buf_line_and_col (ip, &line, &col);
-      if (pfile->show_column)
-       fprintf (stderr, "%s:%d:%d: ", ip->nominal_fname, line, col);
-      else
-       fprintf (stderr, "%s:%d: ", ip->nominal_fname, line);
-    }
-}
-
-void
-cpp_error (pfile, msg, arg1, arg2, arg3)
-     cpp_reader *pfile;
-     char *msg;
-     char *arg1, *arg2, *arg3;
-{
-  cpp_print_containing_files (pfile);
-  cpp_print_file_and_line (pfile);
-  fprintf (stderr, msg, arg1, arg2, arg3);
-  fprintf (stderr, "\n");
-  pfile->errors++;
-}
-
-/* Print error message but don't count it.  */
-
-void
-cpp_warning (pfile, msg, arg1, arg2, arg3)
-     cpp_reader *pfile;
-     char *msg;
-     char *arg1, *arg2, *arg3;
-{
-  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);
-  fprintf (stderr, "warning: ");
-  fprintf (stderr, msg, arg1, arg2, arg3);
-  fprintf (stderr, "\n");
+  if (column > 0)
+    fprintf (stderr, "%s:%d:%d: ", filename, line, column);
+  else
+    fprintf (stderr, "%s:%d: ", filename, line);
 }
 
-void
-cpp_error_with_line (pfile, line, msg, arg1, arg2, arg3)
-     cpp_reader *pfile;
-     int line;
-     char *msg;
-     char *arg1, *arg2, *arg3;
-{
-  int i;
-  cpp_buffer *ip = cpp_file_buffer (pfile);
-
-  cpp_print_containing_files (pfile);
-
-  if (ip != NULL)
-    fprintf (stderr, "%s:%d: ", ip->nominal_fname, line);
-
-  fprintf (stderr, msg, arg1, arg2, arg3);
-  fprintf (stderr, "\n");
-  pfile->errors++;
-}
+/* IS_ERROR is 2 for "fatal" error, 1 for error, 0 for warning */
 
 void
-cpp_warning_with_line (pfile, line, msg, arg1, arg2, arg3)
+cpp_message (pfile, is_error, msg, arg1, arg2, arg3)
+     int is_error;
      cpp_reader *pfile;
-     int line;
      char *msg;
      char *arg1, *arg2, *arg3;
 {
-  int i;
-  cpp_buffer *ip;
-
-  if (CPP_OPTIONS (pfile)->inhibit_warnings)
-    return;
-
-  if (CPP_OPTIONS (pfile)->warnings_are_errors)
+  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++;
-
-  cpp_print_containing_files (pfile);
-
-  ip = cpp_file_buffer (pfile);
-
-  if (ip != NULL)
-    fprintf (stderr, "%s:%d: ", ip->nominal_fname, line);
-  fprintf (stderr, "warning: ");
   fprintf (stderr, msg, arg1, arg2, arg3);
   fprintf (stderr, "\n");
 }
 
-/* Print an error message and maybe count it.  */
+/* 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.
+   Instead, it is the caller's responsibility to check
+   CPP_FATAL_ERRORS.  */
 
 void
-cpp_pedwarn (pfile, msg, arg1, arg2, arg3)
+cpp_fatal (pfile, str, arg)
      cpp_reader *pfile;
-     char *msg;
-     char *arg1, *arg2, *arg3;
-{
-  if (CPP_OPTIONS (pfile)->pedantic_errors)
-    cpp_error (pfile, msg, arg1, arg2, arg3);
-  else
-    cpp_warning (pfile, msg, arg1, arg2, arg3);
-}
-
-void
-cpp_pedwarn_with_line (pfile, line, msg, arg1, arg2, arg3)
-     cpp_reader *pfile;
-     int line;
-     char *msg;
-     char *arg1, *arg2, *arg3;
-{
-  if (CPP_OPTIONS (pfile)->pedantic_errors)
-    cpp_error_with_line (pfile, line, msg, arg1, arg2, arg3);
-  else
-    cpp_warning_with_line (pfile, line, msg, arg1, arg2, arg3);
-}
-
-/* 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 (pfile, file, line, msg, arg1, arg2, arg3)
-     cpp_reader *pfile;
-     char *file;
-     int line;
-     char *msg;
-     char *arg1, *arg2, *arg3;
-{
-  if (!CPP_OPTIONS (pfile)->pedantic_errors
-      && CPP_OPTIONS (pfile)->inhibit_warnings)
-    return;
-  if (file != NULL)
-    fprintf (stderr, "%s:%d: ", file, line);
-  if (CPP_OPTIONS (pfile)->pedantic_errors)
-    pfile->errors++;
-  else
-    fprintf (stderr, "warning: ");
-  fprintf (stderr, msg, arg1, arg2, arg3);
-  fprintf (stderr, "\n");
-}
-
-void
-fatal (str, arg)
      char *str, *arg;
 {
   fprintf (stderr, "%s: ", progname);
-  fprintf (stderr, str, arg);
-  fprintf (stderr, "\n");
-  exit (FAILURE_EXIT_CODE);
+  cpp_message (pfile, 2, str, arg);
 }
-
 \f
-/*
- * my_strerror - return the descriptive text associated with an `errno' code.
- */
-
-char *
-my_strerror (errnum)
-     int errnum;
-{
-  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 = "undocumented I/O error";
-
-  return result;
-}
-
-/* Error including a message from `errno'.  */
-
-void
-cpp_error_from_errno (pfile, name)
-     cpp_reader *pfile;
-     char *name;
-{
-  int i;
-  cpp_buffer *ip = cpp_file_buffer (pfile);
-
-  cpp_print_containing_files (pfile);
-
-  if (ip != NULL)
-    fprintf (stderr, "%s:%d: ", ip->nominal_fname, ip->lineno);
-
-  fprintf (stderr, "%s: %s\n", name, my_strerror (errno));
-
-  pfile->errors++;
-}
-
-void
-cpp_perror_with_name (pfile, name)
-     cpp_reader *pfile;
-     char *name;
-{
-  fprintf (stderr, "%s: ", progname);
-  fprintf (stderr, "%s: %s\n", name, my_strerror (errno));
-  pfile->errors++;
-}
-
 void
 cpp_pfatal_with_name (pfile, name)
      cpp_reader *pfile;
@@ -333,6 +131,6 @@ cpp_pfatal_with_name (pfile, name)
 #ifdef VMS
   exit (vaxc$errno);
 #else
-  exit (FAILURE_EXIT_CODE);
+  exit (FATAL_EXIT_CODE);
 #endif
 }