2551
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2551
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
2551
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY 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 |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
2551
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include <stdarg.h> |
|
28 #include <stdio.h> |
|
29 #include <stdlib.h> |
|
30 |
|
31 #include "lo-error.h" |
|
32 |
2597
|
33 /* Having this file in this directory is a kluge to avoid unresolved |
|
34 symbol errors when creating shared versions of libcruft. */ |
2551
|
35 |
2597
|
36 /* Pointer to the current error handling function. */ |
3325
|
37 liboctave_error_handler current_liboctave_error_handler |
|
38 = liboctave_fatal; |
|
39 |
|
40 /* Pointer to the current warning handler. */ |
|
41 liboctave_warning_handler current_liboctave_warning_handler |
5781
|
42 = liboctave_warning; |
|
43 |
|
44 /* Pointer to the current warning_with_id handler. */ |
|
45 liboctave_warning_with_id_handler current_liboctave_warning_with_id_handler |
|
46 = liboctave_warning_with_id; |
2551
|
47 |
|
48 static void |
|
49 verror (const char *name, const char *fmt, va_list args) |
|
50 { |
|
51 if (name) |
|
52 fprintf (stderr, "%s: ", name); |
|
53 |
|
54 vfprintf (stderr, fmt, args); |
|
55 fprintf (stderr, "\n"); |
|
56 fflush (stderr); |
|
57 } |
|
58 |
|
59 void |
|
60 set_liboctave_error_handler (liboctave_error_handler f) |
|
61 { |
|
62 if (f) |
|
63 current_liboctave_error_handler = f; |
|
64 else |
|
65 current_liboctave_error_handler = liboctave_fatal; |
|
66 } |
|
67 |
|
68 void |
3325
|
69 set_liboctave_warning_handler (liboctave_warning_handler f) |
|
70 { |
|
71 if (f) |
|
72 current_liboctave_warning_handler = f; |
|
73 else |
|
74 current_liboctave_warning_handler = liboctave_warning; |
|
75 } |
|
76 |
|
77 void |
5781
|
78 set_liboctave_warning_with_id_handler (liboctave_warning_with_id_handler f) |
|
79 { |
|
80 if (f) |
|
81 current_liboctave_warning_with_id_handler = f; |
|
82 else |
|
83 current_liboctave_warning_with_id_handler = liboctave_warning_with_id; |
|
84 } |
|
85 |
|
86 void |
2551
|
87 liboctave_fatal (const char *fmt, ...) |
|
88 { |
|
89 va_list args; |
|
90 va_start (args, fmt); |
|
91 verror ("fatal", fmt, args); |
|
92 va_end (args); |
|
93 |
|
94 exit (1); |
|
95 } |
|
96 |
3325
|
97 void |
|
98 liboctave_warning (const char *fmt, ...) |
|
99 { |
|
100 va_list args; |
|
101 va_start (args, fmt); |
|
102 verror ("warning", fmt, args); |
|
103 va_end (args); |
|
104 } |
|
105 |
5781
|
106 void |
|
107 liboctave_warning_with_id (const char *id, const char *fmt, ...) |
|
108 { |
|
109 va_list args; |
|
110 va_start (args, fmt); |
|
111 verror ("warning", fmt, args); |
|
112 va_end (args); |
|
113 } |
|
114 |
2551
|
115 /* |
|
116 ;;; Local Variables: *** |
|
117 ;;; mode: C *** |
|
118 ;;; page-delimiter: "^/\\*" *** |
|
119 ;;; End: *** |
|
120 */ |