/* * The Spar Library - modular math parser * Copyright (C) 2000,2001 Davide Angelocola * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * */ #include #include #include #include #include #include #include #include jmp_buf jb; const char *sl_error_messages_TABLE[SL_ERROR_NO] = { "", "syntax error", "unbalanced parenthesis", "division by zero", "unknown variable", "maximum variables reached", "unrecognised function", "wrong number of arguments to function", "missing an argument", "negative argument", "null argument", "domain error in function", "variable already exist as constant", "internal range error", "identifier too long", "module init failed", "module load failed", "module run failed", "module unload failed", "no memory", "free memory twice", "message too long" }; static void __error_internal (const char *fmt, va_list ap) { char buffer[1000]; int c = vsnprintf (buffer, 1000, fmt, ap); buffer[c] = '\0'; fputs (buffer, stderr); fputs ("\n", stderr); fflush (NULL); return; } void sl_error_throw (sl_error_class __class, sl_error __error, const char *__fmt, ...) { va_list __ap; sl_assert (__error < SL_ERROR_NO); va_start (__ap, __fmt); switch (__class) { case SL_ERROR_CLASS_PARSER: sl_write ("parser: "); sl_write ("%s: ", sl_error_messages_TABLE[__error]); __error_internal (__fmt, __ap); longjmp (jb, 1); break; case SL_ERROR_CLASS_ERROR: sl_write ("error: "); if (__error != SL_ERROR_CUSTOM) sl_write ("%s: ", sl_error_messages_TABLE[__error]); __error_internal (__fmt, __ap); break; case SL_ERROR_CLASS_FATAL: sl_write ("fatal: "); __error_internal (__fmt, __ap); sl_de_init (); exit (SL_ERROR); case SL_ERROR_CLASS_WARNING: sl_write ("warning: "); sl_write ("%s: ", sl_error_messages_TABLE[__error]); __error_internal (__fmt, __ap); break; default: sl_write ("unknow error class (ID %d)", __class); break; } va_end (__ap); return; }