home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / GAWKNT.ZIP / SRC.ZIP / MSG.C < prev    next >
C/C++ Source or Header  |  1994-03-07  |  2KB  |  108 lines

  1. /*
  2.  * msg.c - routines for error messages
  3.  */
  4.  
  5. /* 
  6.  * Copyright (C) 1986, 1988, 1989, 1991, 1992, 1993 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 2, 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, Inc., 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. void
  33. err(s, emsg, argp)
  34. const char *s;
  35. const char *emsg;
  36. va_list argp;
  37. {
  38.     char *file;
  39.  
  40.     (void) fflush(stdout);
  41.     (void) fprintf(stderr, "%s: ", myname);
  42.     if (sourceline) {
  43.         if (source)
  44.             (void) fprintf(stderr, "%s:", source);
  45.         else
  46.             (void) fprintf(stderr, "cmd. line:");
  47.  
  48.         (void) fprintf(stderr, "%d: ", sourceline);
  49.     }
  50.     if (FNR) {
  51.         file = FILENAME_node->var_value->stptr;
  52.         (void) putc('(', stderr);
  53.         if (file)
  54.             (void) fprintf(stderr, "FILENAME=%s ", file);
  55.         (void) fprintf(stderr, "FNR=%d) ", FNR);
  56.     }
  57.     (void) fprintf(stderr, s);
  58.     vfprintf(stderr, emsg, argp);
  59.     (void) fprintf(stderr, "\n");
  60.     (void) fflush(stderr);
  61. }
  62.  
  63. /*VARARGS0*/
  64. void
  65. msg(va_alist)
  66. va_dcl
  67. {
  68.     va_list args;
  69.     char *mesg;
  70.  
  71.     va_start(args);
  72.     mesg = va_arg(args, char *);
  73.     err("", mesg, args);
  74.     va_end(args);
  75. }
  76.  
  77. /*VARARGS0*/
  78. void
  79. warning(va_alist)
  80. va_dcl
  81. {
  82.     va_list args;
  83.     char *mesg;
  84.  
  85.     va_start(args);
  86.     mesg = va_arg(args, char *);
  87.     err("warning: ", mesg, args);
  88.     va_end(args);
  89. }
  90.  
  91. /*VARARGS0*/
  92. void
  93. fatal(va_alist)
  94. va_dcl
  95. {
  96.     va_list args;
  97.     char *mesg;
  98.  
  99.     va_start(args);
  100.     mesg = va_arg(args, char *);
  101.     err("fatal: ", mesg, args);
  102.     va_end(args);
  103. #ifdef DEBUG
  104.     abort();
  105. #endif
  106.     exit(2);
  107. }
  108.