Mercurial > octave
annotate liboctave/cruft/misc/lo-error.c @ 23084:ef4d915df748
maint: Merge stable to default.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 23 Jan 2017 14:27:48 -0500 |
parents | 3a2b891d0b33 e9a0469dedd9 |
children | 092078913d54 |
rev | line source |
---|---|
2551 | 1 /* |
2 | |
22323
bac0d6f07a3e
maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
3 Copyright (C) 1996-2016 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 | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
9 the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
10 (at your option) any later version. |
2551 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
15 GNU General Public License for more details. |
2551 | 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 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
24 # include "config.h" |
2551 | 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. */ |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
37 OCTAVE_NORETURN liboctave_error_handler |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
38 current_liboctave_error_handler = liboctave_fatal; |
3325 | 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. */ |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
41 OCTAVE_NORETURN liboctave_error_with_id_handler |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
42 current_liboctave_error_with_id_handler = liboctave_fatal_with_id; |
10370
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. */ |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
45 liboctave_warning_handler |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
46 current_liboctave_warning_handler = liboctave_warning; |
5781 | 47 |
48 /* Pointer to the current warning_with_id handler. */ | |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
49 liboctave_warning_with_id_handler |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
50 current_liboctave_warning_with_id_handler = 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 | |
21040
3e7cfee5f786
maint: Rename attributes GCC_ATTR_XXX to OCTAVE_XXX.
Rik <rik@octave.org>
parents:
21037
diff
changeset
|
64 set_liboctave_error_handler (OCTAVE_NORETURN liboctave_error_handler f) |
2551 | 65 { |
66 if (f) | |
67 current_liboctave_error_handler = f; | |
68 else | |
69 current_liboctave_error_handler = liboctave_fatal; | |
70 } | |
71 | |
72 void | |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
73 set_liboctave_error_with_id_handler (OCTAVE_NORETURN |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
74 liboctave_error_with_id_handler f) |
10370
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
75 { |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
76 if (f) |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
77 current_liboctave_error_with_id_handler = f; |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
78 else |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
79 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
|
80 } |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
81 |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
82 void |
3325 | 83 set_liboctave_warning_handler (liboctave_warning_handler f) |
84 { | |
85 if (f) | |
86 current_liboctave_warning_handler = f; | |
87 else | |
88 current_liboctave_warning_handler = liboctave_warning; | |
89 } | |
90 | |
91 void | |
5781 | 92 set_liboctave_warning_with_id_handler (liboctave_warning_with_id_handler f) |
93 { | |
94 if (f) | |
95 current_liboctave_warning_with_id_handler = f; | |
96 else | |
97 current_liboctave_warning_with_id_handler = liboctave_warning_with_id; | |
98 } | |
99 | |
100 void | |
2551 | 101 liboctave_fatal (const char *fmt, ...) |
102 { | |
103 va_list args; | |
104 va_start (args, fmt); | |
105 verror ("fatal", fmt, args); | |
106 va_end (args); | |
107 | |
108 exit (1); | |
109 } | |
110 | |
3325 | 111 void |
10370
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
112 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
|
113 { |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
114 octave_unused_parameter (id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
115 |
14759
2feab289622a
Move variable declaration at the beginning of code block.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
14658
diff
changeset
|
116 va_list args; |
10370
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
117 va_start (args, fmt); |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
118 verror ("fatal", fmt, args); |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
119 va_end (args); |
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 exit (1); |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
122 } |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
123 |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
124 void |
3325 | 125 liboctave_warning (const char *fmt, ...) |
126 { | |
127 va_list args; | |
128 va_start (args, fmt); | |
129 verror ("warning", fmt, args); | |
130 va_end (args); | |
131 } | |
132 | |
5781 | 133 void |
134 liboctave_warning_with_id (const char *id, const char *fmt, ...) | |
135 { | |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
136 octave_unused_parameter (id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
137 |
14759
2feab289622a
Move variable declaration at the beginning of code block.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
14658
diff
changeset
|
138 va_list args; |
5781 | 139 va_start (args, fmt); |
140 verror ("warning", fmt, args); | |
141 va_end (args); | |
142 } |