Home | History | Annotate | Download | only in src
      1 /* Declaration for error-reporting function for Bison.
      2 
      3    Copyright (C) 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
      4 
      5    This program is free software; you can redistribute it and/or modify it
      6    under the terms of the GNU General Public License as published by the
      7    Free Software Foundation; either version 2, or (at your option) any
      8    later version.
      9 
     10    This program is distributed in the hope that it will be useful,
     11    but WITHOUT ANY WARRANTY; without even the implied warranty of
     12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13    GNU General Public License for more details.
     14 
     15    You should have received a copy of the GNU General Public License
     16    along with this program; if not, write to the Free Software
     17    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
     18    USA.  */
     19 
     20 /* Based on error.c and error.h,
     21    written by David MacKenzie <djm (at) gnu.ai.mit.edu>.  */
     22 
     23 #include <config.h>
     24 #include "system.h"
     25 
     26 #include <stdarg.h>
     27 
     28 #include "complain.h"
     29 #include "files.h"
     30 
     31 /* The calling program should define program_name and set it to the
     32    name of the executing program.  */
     33 extern char *program_name;
     34 
     35 /* This variable is set each time `warn' is called.  */
     36 bool warning_issued;
     37 
     38 /* This variable is set each time `complain' is called.  */
     39 bool complaint_issued;
     40 
     41 
     42 /*--------------------------------.
     44 | Report a warning, and proceed.  |
     45 `--------------------------------*/
     46 
     47 void
     48 warn_at (location loc, const char *message, ...)
     49 {
     50   va_list args;
     51 
     52   location_print (stderr, loc);
     53   fputs (": ", stderr);
     54   fputs (_("warning: "), stderr);
     55 
     56   va_start (args, message);
     57   vfprintf (stderr, message, args);
     58   va_end (args);
     59 
     60   warning_issued = true;
     61   putc ('\n', stderr);
     62 }
     63 
     64 void
     65 warn (const char *message, ...)
     66 {
     67   va_list args;
     68 
     69   fprintf (stderr, "%s: %s", current_file ? current_file : program_name, _("warning: "));
     70 
     71   va_start (args, message);
     72   vfprintf (stderr, message, args);
     73   va_end (args);
     74 
     75   warning_issued = true;
     76   putc ('\n', stderr);
     77 }
     78 
     79 /*-----------------------------------------------------------.
     81 | An error has occurred, but we can proceed, and die later.  |
     82 `-----------------------------------------------------------*/
     83 
     84 void
     85 complain_at (location loc, const char *message, ...)
     86 {
     87   va_list args;
     88 
     89   location_print (stderr, loc);
     90   fputs (": ", stderr);
     91 
     92   va_start (args, message);
     93   vfprintf (stderr, message, args);
     94   va_end (args);
     95 
     96   complaint_issued = true;
     97   putc ('\n', stderr);
     98 }
     99 
    100 void
    101 complain (const char *message, ...)
    102 {
    103   va_list args;
    104 
    105   fprintf (stderr, "%s: ", current_file ? current_file : program_name);
    106 
    107   va_start (args, message);
    108   vfprintf (stderr, message, args);
    109   va_end (args);
    110 
    111   complaint_issued = true;
    112   putc ('\n', stderr);
    113 }
    114 
    115 /*-------------------------------------------------.
    117 | A severe error has occurred, we cannot proceed.  |
    118 `-------------------------------------------------*/
    119 
    120 void
    121 fatal_at (location loc, const char *message, ...)
    122 {
    123   va_list args;
    124 
    125   location_print (stderr, loc);
    126   fputs (": ", stderr);
    127   fputs (_("fatal error: "), stderr);
    128 
    129   va_start (args, message);
    130   vfprintf (stderr, message, args);
    131   va_end (args);
    132   putc ('\n', stderr);
    133   exit (EXIT_FAILURE);
    134 }
    135 
    136 void
    137 fatal (const char *message, ...)
    138 {
    139   va_list args;
    140 
    141   fprintf (stderr, "%s: ", current_file ? current_file : program_name);
    142 
    143   fputs (_("fatal error: "), stderr);
    144 
    145   va_start (args, message);
    146   vfprintf (stderr, message, args);
    147   va_end (args);
    148   putc ('\n', stderr);
    149   exit (EXIT_FAILURE);
    150 }
    151