Mercurial > hg > octave-nkf
annotate libcruft/misc/lo-error.c @ 10843:229675bb7647 ss-3-3-52
version is now 3.3.52
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 01 Aug 2010 11:49:45 -0400 |
parents | 9c4daf174387 |
children | fd0a3ac60b0e |
rev | line source |
---|---|
2551 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1999, 2005, 2006, 2007 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 | |
10370
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
40 /* Pointer to the current error_with_id handling function. */ |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
41 liboctave_error_with_id_handler current_liboctave_error_with_id_handler |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
42 = liboctave_fatal_with_id; |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
43 |
3325 | 44 /* Pointer to the current warning handler. */ |
45 liboctave_warning_handler current_liboctave_warning_handler | |
5781 | 46 = liboctave_warning; |
47 | |
48 /* Pointer to the current warning_with_id handler. */ | |
49 liboctave_warning_with_id_handler current_liboctave_warning_with_id_handler | |
50 = liboctave_warning_with_id; | |
2551 | 51 |
52 static void | |
53 verror (const char *name, const char *fmt, va_list args) | |
54 { | |
55 if (name) | |
56 fprintf (stderr, "%s: ", name); | |
57 | |
58 vfprintf (stderr, fmt, args); | |
59 fprintf (stderr, "\n"); | |
60 fflush (stderr); | |
61 } | |
62 | |
63 void | |
64 set_liboctave_error_handler (liboctave_error_handler f) | |
65 { | |
66 if (f) | |
67 current_liboctave_error_handler = f; | |
68 else | |
69 current_liboctave_error_handler = liboctave_fatal; | |
70 } | |
71 | |
72 void | |
10370
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
73 set_liboctave_error_with_id_handler (liboctave_error_with_id_handler f) |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
74 { |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
75 if (f) |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
76 current_liboctave_error_with_id_handler = f; |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
77 else |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
78 current_liboctave_error_with_id_handler = liboctave_fatal_with_id; |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
79 } |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
80 |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
81 void |
3325 | 82 set_liboctave_warning_handler (liboctave_warning_handler f) |
83 { | |
84 if (f) | |
85 current_liboctave_warning_handler = f; | |
86 else | |
87 current_liboctave_warning_handler = liboctave_warning; | |
88 } | |
89 | |
90 void | |
5781 | 91 set_liboctave_warning_with_id_handler (liboctave_warning_with_id_handler f) |
92 { | |
93 if (f) | |
94 current_liboctave_warning_with_id_handler = f; | |
95 else | |
96 current_liboctave_warning_with_id_handler = liboctave_warning_with_id; | |
97 } | |
98 | |
99 void | |
2551 | 100 liboctave_fatal (const char *fmt, ...) |
101 { | |
102 va_list args; | |
103 va_start (args, fmt); | |
104 verror ("fatal", fmt, args); | |
105 va_end (args); | |
106 | |
107 exit (1); | |
108 } | |
109 | |
3325 | 110 void |
10370
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
111 liboctave_fatal_with_id (const char *id, const char *fmt, ...) |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
112 { |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
113 va_list args; |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
114 va_start (args, fmt); |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
115 verror ("fatal", fmt, args); |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
116 va_end (args); |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
117 |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
118 exit (1); |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
119 } |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
120 |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
121 void |
3325 | 122 liboctave_warning (const char *fmt, ...) |
123 { | |
124 va_list args; | |
125 va_start (args, fmt); | |
126 verror ("warning", fmt, args); | |
127 va_end (args); | |
128 } | |
129 | |
5781 | 130 void |
131 liboctave_warning_with_id (const char *id, const char *fmt, ...) | |
132 { | |
133 va_list args; | |
134 va_start (args, fmt); | |
135 verror ("warning", fmt, args); | |
136 va_end (args); | |
137 } |