1
|
1 // error.cc -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993 John W. Eaton |
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef __GNUG__ |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
|
28 #include <stdio.h> |
|
29 #include <stdlib.h> |
|
30 #include <stdarg.h> |
|
31 |
|
32 #include "error.h" |
|
33 |
143
|
34 // Current error state. |
|
35 int error_state; |
|
36 |
1
|
37 static void |
|
38 verror (const char *name, const char *fmt, va_list args) |
|
39 { |
|
40 if (name != (char *) NULL) |
|
41 fprintf (stderr, "%s: ", name); |
|
42 |
|
43 vfprintf (stderr, fmt, args); |
|
44 fprintf (stderr, "\n"); |
|
45 fflush (stderr); |
|
46 } |
|
47 |
|
48 void |
|
49 message (const char *name, const char *fmt, ...) |
|
50 { |
|
51 va_list args; |
|
52 va_start (args, fmt); |
|
53 verror (name, fmt, args); |
|
54 va_end (args); |
|
55 } |
|
56 |
|
57 void |
|
58 usage (const char *fmt, ...) |
|
59 { |
|
60 va_list args; |
|
61 va_start (args, fmt); |
|
62 verror ("usage", fmt, args); |
|
63 va_end (args); |
|
64 } |
|
65 |
|
66 void |
|
67 warning (const char *fmt, ...) |
|
68 { |
|
69 va_list args; |
|
70 va_start (args, fmt); |
|
71 verror ("warning", fmt, args); |
|
72 va_end (args); |
|
73 } |
|
74 |
|
75 void |
|
76 error (const char *fmt, ...) |
|
77 { |
143
|
78 if (! error_state) |
|
79 error_state = 1; |
|
80 |
1
|
81 va_list args; |
|
82 va_start (args, fmt); |
|
83 verror ("error", fmt, args); |
|
84 va_end (args); |
|
85 } |
|
86 |
103
|
87 void volatile |
1
|
88 panic (const char *fmt, ...) |
|
89 { |
|
90 va_list args; |
|
91 va_start (args, fmt); |
|
92 verror ("panic", fmt, args); |
|
93 va_end (args); |
|
94 abort (); |
|
95 } |
|
96 |
|
97 /* |
|
98 ;;; Local Variables: *** |
|
99 ;;; mode: C++ *** |
|
100 ;;; page-delimiter: "^/\\*" *** |
|
101 ;;; End: *** |
|
102 */ |