home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / gnu / gawk213s.lzh / GAWK213S / MSG.C < prev    next >
C/C++ Source or Header  |  1993-07-29  |  2KB  |  105 lines

  1. /*
  2.  * msg.c - routines for error messages
  3.  */
  4.  
  5. /* 
  6.  * Copyright (C) 1986, 1988, 1989, 1991 the Free Software Foundation, Inc.
  7.  * 
  8.  * This file is part of GAWK, the GNU implementation of the
  9.  * AWK Progamming Language.
  10.  * 
  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 1, or (at your option)
  14.  * any later version.
  15.  * 
  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.
  20.  * 
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with GAWK; see the file COPYING.  If not, write to
  23.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  */
  25.  
  26. #include "awk.h"
  27.  
  28. int sourceline = 0;
  29. char *source = NULL;
  30.  
  31. /* VARARGS2 */
  32. static void
  33. err(s, msg, argp)
  34. char *s;
  35. char *msg;
  36. va_list *argp;
  37. {
  38.     char *file;
  39.  
  40.     (void) fflush(stdout);
  41.     (void) fprintf(stderr, "%s: %s ", myname, s);
  42.     vfprintf(stderr, msg, *argp);
  43.     (void) fprintf(stderr, "\n");
  44.     if (FNR) {
  45.         (void) fprintf(stderr, "  input line number %d", FNR);
  46.         file = FILENAME_node->var_value->stptr;
  47.         if (file && !STREQ(file, "-"))
  48.             (void) fprintf(stderr, ", file `%s'", file);
  49.         (void) fprintf(stderr, "\n");
  50.     }
  51.     if (sourceline) {
  52.         (void) fprintf(stderr, "  source line number %d", sourceline);
  53.         if (source)
  54.             (void) fprintf(stderr, ", file `%s'", source);
  55.         (void) fprintf(stderr, "\n");
  56.     }
  57.     (void) fflush(stderr);
  58. }
  59.  
  60. /*VARARGS0*/
  61. void
  62. msg(va_alist)
  63. va_dcl
  64. {
  65.     va_list args;
  66.     char *mesg;
  67.  
  68.     va_start(args);
  69.     mesg = va_arg(args, char *);
  70.     err("", mesg, &args);
  71.     va_end(args);
  72. }
  73.  
  74. /*VARARGS0*/
  75. void
  76. warning(va_alist)
  77. va_dcl
  78. {
  79.     va_list args;
  80.     char *mesg;
  81.  
  82.     va_start(args);
  83.     mesg = va_arg(args, char *);
  84.     err("warning:", mesg, &args);
  85.     va_end(args);
  86. }
  87.  
  88. /*VARARGS0*/
  89. void
  90. fatal(va_alist)
  91. va_dcl
  92. {
  93.     va_list args;
  94.     char *mesg;
  95.  
  96.     va_start(args);
  97.     mesg = va_arg(args, char *);
  98.     err("fatal error:", mesg, &args);
  99.     va_end(args);
  100. #ifdef DEBUG
  101.     abort();
  102. #endif
  103.     exit(2);
  104. }
  105.