X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/d2729d44ab05f89e96d199ad6b10e127c1cb0a38..10a9273b34548200a4e592093b8ba9bec4d980a8:/src/main.c diff --git a/src/main.c b/src/main.c index 88444a18..58939d92 100644 --- a/src/main.c +++ b/src/main.c @@ -1,21 +1,22 @@ /* Top level entry point of bison, - Copyright (C) 1984, 1986, 1989, 1992, 1995 Free Software Foundation, Inc. + Copyright (C) 1984, 1986, 1989, 1992, 1995, 2000 Free Software Foundation, Inc. -This file is part of Bison, the GNU Compiler Compiler. + This file is part of Bison, the GNU Compiler Compiler. -Bison 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. + Bison 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. -Bison 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. + Bison 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 Bison; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ + You should have received a copy of the GNU General Public License + along with Bison; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ #include @@ -144,16 +145,33 @@ int_to_string (int i) return buf; } +/* Display filename and lino if available. */ + +static void +banner (void) +{ + if (infile == 0) + fprintf(stderr, "%s: ", program_name); + else + fprintf(stderr, "%s:%d: ", infile, lineno); +} + +static void +fatal_banner (void) +{ + banner (); + fputs (_("fatal error: "), stderr); +} + /* Print the message S for a fatal error. */ void fatal (char *s) { - if (infile == 0) - fprintf(stderr, _("%s: fatal error: %s\n"), program_name, s); - else - fprintf(stderr, _("%s:%d: fatal error: %s\n"), infile, lineno, s); - done(1); + fatal_banner (); + fputs (s, stderr); + fputc ('\n', stderr); + done (1); } @@ -163,9 +181,17 @@ fatal (char *s) void fatals (char *fmt, char *x1) { - char buffer[200]; - sprintf(buffer, fmt, x1); - fatal(buffer); + fatal_banner (); + fprintf (stderr, fmt, x1); + fputc ('\n', stderr); + done (1); +} + +static void +warn_banner (void) +{ + banner (); + failure = 1; } /* Print a warning message S. */ @@ -173,13 +199,9 @@ fatals (char *fmt, char *x1) void warn (char *s) { - if (infile == 0) - fprintf(stderr, _("%s: %s\n"), program_name, s); - else - fprintf(stderr, _("%s:%d: %s\n"), - infile, lineno, s); - - failure = 1; + warn_banner (); + fputs (s, stderr); + fputc ('\n', stderr); } /* Print a warning message containing the string for the integer X1. @@ -188,9 +210,9 @@ warn (char *s) void warni (char *fmt, int x1) { - char buffer[200]; - sprintf(buffer, fmt, x1); - warn(buffer); + warn_banner (); + fprintf (stderr, fmt, x1); + fputc ('\n', stderr); } /* Print a warning message containing the string X1. @@ -199,9 +221,9 @@ warni (char *fmt, int x1) void warns (char *fmt, char *x1) { - char buffer[200]; - sprintf(buffer, fmt, x1); - warn(buffer); + warn_banner (); + fprintf (stderr, fmt, x1); + fputc ('\n', stderr); } /* Print a warning message containing the two strings X1 and X2. @@ -210,9 +232,9 @@ warns (char *fmt, char *x1) void warnss (char *fmt, char *x1, char *x2) { - char buffer[200]; - sprintf(buffer, fmt, x1, x2); - warn(buffer); + warn_banner (); + fprintf (stderr, fmt, x1, x2); + fputc ('\n', stderr); } /* Print a warning message containing the 3 strings X1, X2, X3. @@ -221,9 +243,9 @@ warnss (char *fmt, char *x1, char *x2) void warnsss (char *fmt, char *x1, char *x2, char *x3) { - char buffer[200]; - sprintf(buffer, fmt, x1, x2, x3); - warn(buffer); + warn_banner (); + fprintf (stderr, fmt, x1, x2, x3); + fputc ('\n', stderr); } /* Print a message for the fatal occurence of more than MAXSHORT @@ -232,9 +254,10 @@ warnsss (char *fmt, char *x1, char *x2, char *x3) void toomany (char *s) { - char buffer[200]; - sprintf(buffer, _("too many %s (max %d)"), s, MAXSHORT); - fatal(buffer); + fatal_banner (); + fprintf (stderr, _("too many %s (max %d)"), s, MAXSHORT); + fputc ('\n', stderr); + done (1); } /* Abort for an internal error denoted by string S. */