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