lo-error.c

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
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 /* Having this file in this directory is a kluge to avoid unresolved
00034    symbol errors when creating shared versions of libcruft. */
00035 
00036 /* Pointer to the current error handling function. */
00037 liboctave_error_handler current_liboctave_error_handler
00038   = liboctave_fatal;
00039 
00040 /* Pointer to the current error_with_id handling function. */
00041 liboctave_error_with_id_handler current_liboctave_error_with_id_handler
00042   = liboctave_fatal_with_id;
00043 
00044 /* Pointer to the current warning handler. */
00045 liboctave_warning_handler current_liboctave_warning_handler
00046   = liboctave_warning;
00047 
00048 /* Pointer to the current warning_with_id handler. */
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 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines