home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / groff-1.09-src.lha / src / amiga / groff-1.09 / libgroff / error.cc < prev    next >
C/C++ Source or Header  |  1994-02-21  |  3KB  |  138 lines

  1. // -*- C++ -*-
  2. /* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
  3.      Written by James Clark (jjc@jclark.com)
  4.  
  5. This file is part of groff.
  6.  
  7. groff is free software; you can redistribute it and/or modify it under
  8. the terms of the GNU General Public License as published by the Free
  9. Software Foundation; either version 2, or (at your option) any later
  10. version.
  11.  
  12. groff is distributed in the hope that it will be useful, but WITHOUT ANY
  13. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License along
  18. with groff; see the file COPYING.  If not, write to the Free Software
  19. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include </gnu/include/string.h>
  24. #include "errarg.h"
  25. #include "error.h"
  26.  
  27. extern void fatal_error_exit();
  28.  
  29. enum error_type { WARNING, ERROR, FATAL };
  30.  
  31. static void do_error_with_file_and_line(const char *filename, int lineno,
  32.                     error_type type, 
  33.                     const char *format, 
  34.                     const errarg &arg1,
  35.                     const errarg &arg2,
  36.                     const errarg &arg3)
  37. {
  38.   int need_space = 0;
  39.   if (program_name) {
  40.     fprintf(stderr, "%s:", program_name);
  41.     need_space = 1;
  42.   }
  43.   if (lineno >= 0 && filename != 0) {
  44.     if (strcmp(filename, "-") == 0)
  45.       filename = "<standard input>";
  46.     fprintf(stderr, "%s:%d:", filename, lineno);
  47.     need_space = 1;
  48.   }
  49.   switch (type) {
  50.   case FATAL:
  51.     fputs("fatal error:", stderr);
  52.     need_space = 1;
  53.     break;
  54.   case ERROR:
  55.     break;
  56.   case WARNING:
  57.     fputs("warning:", stderr);
  58.     need_space = 1;
  59.     break;
  60.   }
  61.   if (need_space)
  62.     fputc(' ', stderr);
  63.   errprint(format, arg1, arg2, arg3);
  64.   fputc('\n', stderr);
  65.   fflush(stderr);
  66.   if (type == FATAL)
  67.     fatal_error_exit();
  68. }
  69.       
  70.  
  71. static void do_error(error_type type, 
  72.              const char *format, 
  73.              const errarg &arg1,
  74.              const errarg &arg2,
  75.              const errarg &arg3)
  76. {
  77.   do_error_with_file_and_line(current_filename, current_lineno,
  78.                   type, format, arg1, arg2, arg3);
  79. }
  80.  
  81.  
  82. void error(const char *format, 
  83.        const errarg &arg1,
  84.        const errarg &arg2,
  85.        const errarg &arg3)
  86. {
  87.   do_error(ERROR, format, arg1, arg2, arg3);
  88. }
  89.  
  90. void warning(const char *format, 
  91.          const errarg &arg1,
  92.          const errarg &arg2,
  93.          const errarg &arg3)
  94. {
  95.   do_error(WARNING, format, arg1, arg2, arg3);
  96. }
  97.  
  98. void fatal(const char *format, 
  99.        const errarg &arg1,
  100.        const errarg &arg2,
  101.        const errarg &arg3)
  102. {
  103.   do_error(FATAL, format, arg1, arg2, arg3);
  104. }
  105.  
  106. void error_with_file_and_line(const char *filename,
  107.                   int lineno,
  108.                   const char *format, 
  109.                   const errarg &arg1,
  110.                   const errarg &arg2,
  111.                   const errarg &arg3)
  112. {
  113.   do_error_with_file_and_line(filename, lineno, 
  114.                   ERROR, format, arg1, arg2, arg3);
  115. }
  116.  
  117. void warning_with_file_and_line(const char *filename,
  118.                   int lineno,
  119.                   const char *format, 
  120.                   const errarg &arg1,
  121.                   const errarg &arg2,
  122.                   const errarg &arg3)
  123. {
  124.   do_error_with_file_and_line(filename, lineno, 
  125.                   WARNING, format, arg1, arg2, arg3);
  126. }
  127.  
  128. void fatal_with_file_and_line(const char *filename,
  129.                   int lineno,
  130.                   const char *format, 
  131.                   const errarg &arg1,
  132.                   const errarg &arg2,
  133.                   const errarg &arg3)
  134. {
  135.   do_error_with_file_and_line(filename, lineno, 
  136.                   FATAL, format, arg1, arg2, arg3);
  137. }
  138.