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" |
169
|
33 #include "pager.h" |
1
|
34 |
143
|
35 // Current error state. |
|
36 int error_state; |
|
37 |
1
|
38 static void |
|
39 verror (const char *name, const char *fmt, va_list args) |
|
40 { |
|
41 if (name != (char *) NULL) |
|
42 fprintf (stderr, "%s: ", name); |
|
43 |
|
44 vfprintf (stderr, fmt, args); |
|
45 fprintf (stderr, "\n"); |
|
46 fflush (stderr); |
|
47 } |
|
48 |
|
49 void |
|
50 message (const char *name, const char *fmt, ...) |
|
51 { |
|
52 va_list args; |
|
53 va_start (args, fmt); |
|
54 verror (name, fmt, args); |
|
55 va_end (args); |
|
56 } |
|
57 |
|
58 void |
|
59 usage (const char *fmt, ...) |
|
60 { |
|
61 va_list args; |
|
62 va_start (args, fmt); |
|
63 verror ("usage", fmt, args); |
|
64 va_end (args); |
|
65 } |
|
66 |
|
67 void |
|
68 warning (const char *fmt, ...) |
|
69 { |
|
70 va_list args; |
|
71 va_start (args, fmt); |
|
72 verror ("warning", fmt, args); |
|
73 va_end (args); |
|
74 } |
|
75 |
|
76 void |
|
77 error (const char *fmt, ...) |
|
78 { |
143
|
79 if (! error_state) |
|
80 error_state = 1; |
|
81 |
169
|
82 flush_output_to_pager (); |
|
83 |
1
|
84 va_list args; |
|
85 va_start (args, fmt); |
|
86 verror ("error", fmt, args); |
|
87 va_end (args); |
|
88 } |
|
89 |
189
|
90 void |
1
|
91 panic (const char *fmt, ...) |
|
92 { |
169
|
93 flush_output_to_pager (); |
|
94 |
1
|
95 va_list args; |
|
96 va_start (args, fmt); |
|
97 verror ("panic", fmt, args); |
|
98 va_end (args); |
|
99 abort (); |
|
100 } |
|
101 |
|
102 /* |
|
103 ;;; Local Variables: *** |
|
104 ;;; mode: C++ *** |
|
105 ;;; page-delimiter: "^/\\*" *** |
|
106 ;;; End: *** |
|
107 */ |