2 * msg.c - routines for error messages.
6 * Copyright (C) 1986, 1988, 1989, 1991-2001, 2003, 2010-2013
7 * the Free Software Foundation, Inc.
9 * This file is part of GAWK, the GNU implementation of the
10 * AWK Programming Language.
12 * GAWK is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
17 * GAWK is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
29 extern FILE *output_fp;
32 static const char *srcfile = NULL;
36 bool fatal_tag_valid = false;
38 /* err --- print an error message with source line and file and record */
42 err(bool isfatal, const char *s, const char *emsg, va_list argp)
47 static bool first = true;
48 static bool add_src_info = false;
52 add_src_info = (getenv("GAWK_MSG_SRC") != NULL);
55 (void) fflush(output_fp);
57 (void) fprintf(stderr, "%s: ", me);
59 if (srcfile != NULL && add_src_info) {
60 fprintf(stderr, "%s:%d:", srcfile, srcline);
66 (void) fprintf(stderr, "%s:", source);
68 (void) fprintf(stderr, _("cmd. line:"));
70 (void) fprintf(stderr, "%d: ", sourceline);
74 if (FNR_node && is_mpg_number(FNR_node->var_value)) {
76 val = mpg_update_var(FNR_node);
77 assert((val->flags & MPZN) != 0);
78 if (mpz_sgn(val->mpg_i) > 0) {
79 file = FILENAME_node->var_value->stptr;
80 (void) putc('(', stderr);
82 (void) fprintf(stderr, "FILENAME=%s ", file);
83 (void) mpfr_fprintf(stderr, "FNR=%Zd) ", val->mpg_i);
88 file = FILENAME_node->var_value->stptr;
89 (void) putc('(', stderr);
91 (void) fprintf(stderr, "FILENAME=%s ", file);
92 (void) fprintf(stderr, "FNR=%ld) ", FNR);
95 (void) fprintf(stderr, "%s", s);
96 vfprintf(stderr, emsg, argp);
97 (void) fprintf(stderr, "\n");
98 (void) fflush(stderr);
104 gawk_exit(EXIT_FATAL);
108 /* msg --- take a varargs error message and print it */
111 msg(const char *mesg, ...)
114 va_start(args, mesg);
115 err(false, "", mesg, args);
119 /* r_warning --- print a warning message */
122 r_warning(const char *mesg, ...)
125 va_start(args, mesg);
126 err(false, _("warning: "), mesg, args);
131 error(const char *mesg, ...)
134 va_start(args, mesg);
135 err(false, _("error: "), mesg, args);
139 /* set_loc --- set location where a fatal error happened */
142 set_loc(const char *file, int line)
147 /* This stupid line keeps some compilers happy: */
148 file = srcfile; line = srcline;
151 /* r_fatal --- print a fatal error message */
154 r_fatal(const char *mesg, ...)
157 va_start(args, mesg);
158 err(true, _("fatal: "), mesg, args);
162 /* gawk_exit --- longjmp out if necessary */
165 gawk_exit(int status)
167 if (fatal_tag_valid) {
169 longjmp(fatal_tag, 1);
175 /* final_exit --- run extension exit handlers and exit */
178 final_exit(int status)
180 /* run any extension exit handlers */
181 run_ext_exit_handlers(status);
183 /* we could close_io() here */