1
|
1 // error.cc -*- C++ -*- |
|
2 /* |
|
3 |
436
|
4 Copyright (C) 1992, 1993, 1994 John W. Eaton |
1
|
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 |
240
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include "config.h" |
1
|
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 { |
436
|
79 if (error_state == -2) |
|
80 return; |
|
81 |
143
|
82 if (! error_state) |
|
83 error_state = 1; |
|
84 |
169
|
85 flush_output_to_pager (); |
|
86 |
1
|
87 va_list args; |
|
88 va_start (args, fmt); |
436
|
89 |
|
90 int len; |
|
91 if (fmt && fmt[(len = strlen (fmt) - 1)] == '\n') |
|
92 { |
|
93 error_state = -2; |
|
94 char *tmp_fmt = strsave (fmt); |
|
95 tmp_fmt[len - 1] = '\0'; |
|
96 verror ("error", tmp_fmt, args); |
|
97 } |
|
98 else |
|
99 verror ("error", fmt, args); |
|
100 |
1
|
101 va_end (args); |
|
102 } |
|
103 |
189
|
104 void |
1
|
105 panic (const char *fmt, ...) |
|
106 { |
169
|
107 flush_output_to_pager (); |
|
108 |
1
|
109 va_list args; |
|
110 va_start (args, fmt); |
|
111 verror ("panic", fmt, args); |
|
112 va_end (args); |
|
113 abort (); |
240
|
114 exit (1); |
1
|
115 } |
|
116 |
|
117 /* |
|
118 ;;; Local Variables: *** |
|
119 ;;; mode: C++ *** |
|
120 ;;; page-delimiter: "^/\\*" *** |
|
121 ;;; End: *** |
|
122 */ |