2 * msg.c - routines for error messages
6 * Copyright (C) 1986, 1988, 1989, 1991-2000 the Free Software Foundation, Inc.
8 * This file is part of GAWK, the GNU implementation of the
9 * AWK Programming Language.
11 * GAWK is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
16 * GAWK is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
31 static char *srcfile = NULL;
34 /* prototype needed for ansi / gcc */
35 void err P((const char *s, const char *emsg, va_list argp));
37 /* err --- print an error message with source line and file and record */
48 (void) fflush(stdout);
49 (void) fprintf(stderr, "%s: ", myname);
51 if (srcfile != NULL) {
52 fprintf(stderr, "%s:%d:", srcfile, srcline);
56 if (sourceline != 0) {
58 (void) fprintf(stderr, "%s:", source);
60 (void) fprintf(stderr, "cmd. line:");
62 (void) fprintf(stderr, "%d: ", sourceline);
65 file = FILENAME_node->var_value->stptr;
66 (void) putc('(', stderr);
68 (void) fprintf(stderr, "FILENAME=%s ", file);
69 (void) fprintf(stderr, "FNR=%ld) ", FNR);
71 (void) fprintf(stderr, s);
72 vfprintf(stderr, emsg, argp);
73 (void) fprintf(stderr, "\n");
74 (void) fflush(stderr);
77 /* msg --- take a varargs error message and print it */
79 #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
90 #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
96 mesg = va_arg(args, char *);
102 /* warning --- print a warning message */
104 #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
106 warning(char *mesg, ...)
115 #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
116 va_start(args, mesg);
121 mesg = va_arg(args, char *);
123 err("warning: ", mesg, args);
127 #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
129 error(char *mesg, ...)
138 #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
139 va_start(args, mesg);
144 mesg = va_arg(args, char *);
146 err("error: ", mesg, args);
150 /* set_loc --- set location where a fatal error happened */
161 /* fatal --- print an error message and die */
163 #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
165 r_fatal(char *mesg, ...)
174 #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
175 va_start(args, mesg);
180 mesg = va_arg(args, char *);
182 err("fatal: ", mesg, args);