/* * LIBML library - read, write and manipulate MATLAB MAT-files * Copyright (C) 1994 Michael J. Maurer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Michael Maurer * Durand Bldg - Room 232 * Stanford, CA 94305-4055 * (415) 723-1024 */ /****************************************************************************** error A general-purpose error message routine, inspired by a similar GNU function. Before calling this function, set the value of 'progn' to be the name of your program, e.g. "progn = argv[0]". Optionally, set 'error_cleanup' to point to a function you want executed before abnormal exit. When error() is called, it prints the error message 'message' (a printf-style format string) to stderr using the additional printf arguments on the argument list. If 'errnum' is nonzero, it is assumed to have the value of an error code in , and error() prints the corresponding error message. If 'status' is nonzero, the function will exit with status 'status', but only after calling error_cleanup() first if it is non-NULL. If status==0, error() returns after printing the message. ******************************************************************************/ #include #include void (*error_cleanup)(int) = NULL; char *progn = NULL; void error(int status, int errnum, char *message, ...) { extern char *sys_errlist[]; extern int sys_nerr; va_list args; if (progn) fprintf(stderr,"%s: ",progn); va_start(args,message); vfprintf(stderr,message,args); va_end(args); if (errnum > 0 && errnum < sys_nerr) fprintf(stderr,": \"%s\"",sys_errlist[errnum]); putc('\n',stderr); fflush(stderr); if (status) { if (error_cleanup) (*error_cleanup)(status); exit(status); } }