Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026
00027 #include <stdarg.h>
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030
00031 #include "lo-error.h"
00032
00033
00034
00035
00036
00037 liboctave_error_handler current_liboctave_error_handler
00038 = liboctave_fatal;
00039
00040
00041 liboctave_error_with_id_handler current_liboctave_error_with_id_handler
00042 = liboctave_fatal_with_id;
00043
00044
00045 liboctave_warning_handler current_liboctave_warning_handler
00046 = liboctave_warning;
00047
00048
00049 liboctave_warning_with_id_handler current_liboctave_warning_with_id_handler
00050 = liboctave_warning_with_id;
00051
00052 static void
00053 verror (const char *name, const char *fmt, va_list args)
00054 {
00055 if (name)
00056 fprintf (stderr, "%s: ", name);
00057
00058 vfprintf (stderr, fmt, args);
00059 fprintf (stderr, "\n");
00060 fflush (stderr);
00061 }
00062
00063 void
00064 set_liboctave_error_handler (liboctave_error_handler f)
00065 {
00066 if (f)
00067 current_liboctave_error_handler = f;
00068 else
00069 current_liboctave_error_handler = liboctave_fatal;
00070 }
00071
00072 void
00073 set_liboctave_error_with_id_handler (liboctave_error_with_id_handler f)
00074 {
00075 if (f)
00076 current_liboctave_error_with_id_handler = f;
00077 else
00078 current_liboctave_error_with_id_handler = liboctave_fatal_with_id;
00079 }
00080
00081 void
00082 set_liboctave_warning_handler (liboctave_warning_handler f)
00083 {
00084 if (f)
00085 current_liboctave_warning_handler = f;
00086 else
00087 current_liboctave_warning_handler = liboctave_warning;
00088 }
00089
00090 void
00091 set_liboctave_warning_with_id_handler (liboctave_warning_with_id_handler f)
00092 {
00093 if (f)
00094 current_liboctave_warning_with_id_handler = f;
00095 else
00096 current_liboctave_warning_with_id_handler = liboctave_warning_with_id;
00097 }
00098
00099 void
00100 liboctave_fatal (const char *fmt, ...)
00101 {
00102 va_list args;
00103 va_start (args, fmt);
00104 verror ("fatal", fmt, args);
00105 va_end (args);
00106
00107 exit (1);
00108 }
00109
00110 void
00111 liboctave_fatal_with_id (const char *id, const char *fmt, ...)
00112 {
00113 va_list args;
00114 va_start (args, fmt);
00115 verror ("fatal", fmt, args);
00116 va_end (args);
00117
00118 exit (1);
00119 }
00120
00121 void
00122 liboctave_warning (const char *fmt, ...)
00123 {
00124 va_list args;
00125 va_start (args, fmt);
00126 verror ("warning", fmt, args);
00127 va_end (args);
00128 }
00129
00130 void
00131 liboctave_warning_with_id (const char *id, const char *fmt, ...)
00132 {
00133 va_list args;
00134 va_start (args, fmt);
00135 verror ("warning", fmt, args);
00136 va_end (args);
00137 }