2 * msg.c - routines for error messages.
6 * Copyright (C) 1986, 1988, 1989, 1991-2001, 2003, 2010
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 int fatal_tag_valid = FALSE;
38 /* err --- print an error message with source line and file and record */
42 err(const char *s, const char *emsg, va_list argp)
47 (void) fflush(output_fp);
49 if (strncmp(me, "dgawk", 5) == 0)
51 (void) fprintf(stderr, "%s: ", me);
53 if (srcfile != NULL) {
54 fprintf(stderr, "%s:%d:", srcfile, srcline);
57 #endif /* GAWKDEBUG */
61 (void) fprintf(stderr, "%s:", source);
63 (void) fprintf(stderr, _("cmd. line:"));
65 (void) fprintf(stderr, "%d: ", sourceline);
68 file = FILENAME_node->var_value->stptr;
69 (void) putc('(', stderr);
71 (void) fprintf(stderr, "FILENAME=%s ", file);
72 (void) fprintf(stderr, "FNR=%ld) ", FNR);
74 (void) fprintf(stderr, "%s", s);
75 vfprintf(stderr, emsg, argp);
76 (void) fprintf(stderr, "\n");
77 (void) fflush(stderr);
80 /* msg --- take a varargs error message and print it */
83 msg(const char *mesg, ...)
91 /* warning --- print a warning message */
94 warning(const char *mesg, ...)
98 err(_("warning: "), mesg, args);
103 error(const char *mesg, ...)
106 va_start(args, mesg);
107 err(_("error: "), mesg, args);
111 /* set_loc --- set location where a fatal error happened */
114 set_loc(const char *file, int line)
119 /* This stupid line keeps some compilers happy: */
120 file = srcfile; line = srcline;
123 /* r_fatal --- print a fatal error message */
126 r_fatal(const char *mesg, ...)
129 va_start(args, mesg);
130 err(_("fatal: "), mesg, args);
135 gawk_exit(EXIT_FATAL);
138 /* gawk_exit --- longjmp out if necessary */
141 gawk_exit(int status)
143 if (fatal_tag_valid) {
145 longjmp(fatal_tag, 1);