mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
The following are the changes in this release: For historical purposes, in lucas.cal, gen_v1(1, n) always returns 4. Fixed some compiler warnings, thanks to a report by Mike <michael dot d dot ince at gmail dot com>. Added work around for a gcc warning bug, thanks to a report by Mike <michael dot d dot ince at gmail dot com>. Fixed errors in various help files such as: mat randbit seed srandom types Removed the MAXSTRING symbol because it was no longer used by calc. Increased HIST_SIZE (depth of the history stack) from 10k to 32k. Increased TTYSIZE (reallocation size for terminal buffers) from 100 to 8191. Increased MAXDEPTH (maximum depth of input stack) from 10 to 255. Increased interactive input buffer size from 1024 to 256k. This has the effect of increasing the maximum length of an input line from a tty. This helps with an interactive bug that was reported by Ruslan Kabatsayev (b7 dot 10110111 at gmail dot com). The calc man page indicates that -d also disables the printing of the leading tilde. Added information to "help command" about how to silence messages while reading calc resource files. Fixed an error message buffer overflow thanks to a report by Frank Peters <nlp at northernlightsphoto dot biz>. Replaced all use of the C funcion sprintf() with snprintf(). Replaced all use of the C funcion vsprintf() with vsnprintf(). Replaced all DONT_HAVE_VSPRINTF with DONT_HAVE_VSNPRINTF. Replaced all Makefile var ${HAVE_VSPRINTF} with ${HAVE_VSNPRINTF}.
121 lines
3.1 KiB
C
121 lines
3.1 KiB
C
/*
|
|
* math_error - a simple libcalc math error routine
|
|
*
|
|
* Copyright (C) 1999 Landon Curt Noll
|
|
*
|
|
* Calc is open software; you can redistribute it and/or modify it under
|
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
|
* as published by the Free Software Foundation.
|
|
*
|
|
* Calc 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.
|
|
*
|
|
* A copy of version 2.1 of the GNU Lesser General Public License is
|
|
* distributed with calc under the filename COPYING-LGPL. You should have
|
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*
|
|
* Under source code control: 1994/08/03 05:08:22
|
|
* File existed as early as: 1994
|
|
*
|
|
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
|
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
|
*/
|
|
|
|
/*
|
|
* Your program MUST provide a function called math_error. This is called
|
|
* by the math routines on an error condition, such as malloc failures or a
|
|
* division by zero. The routine is called in the manner of printf, with a
|
|
* format string and optional arguments.
|
|
*
|
|
* By default, this routine simply prints a message to stderr and then exits.
|
|
*
|
|
* If one sets up calc_matherr_jmpbuf, and then sets calc_use_matherr_jmpbuf
|
|
* to non-zero then this routine will longjmp back with the return value of
|
|
* calc_use_matherr_jmpbuf. In addition, the last calc error message will be
|
|
* found in calc_use_matherr_jmpbuf_msg. This error is not printed to sttderr.
|
|
*
|
|
* For example:
|
|
*
|
|
* #include <setjmp.h>
|
|
* #include "lib_calc.h"
|
|
*
|
|
* int error;
|
|
*
|
|
* ...
|
|
*
|
|
* if ((error = setjmp(calc_matherr_jmpbuf)) != 0) {
|
|
*
|
|
* (* reinitialize calc after a longjmp *)
|
|
* reinitialize();
|
|
*
|
|
* (* report the error *)
|
|
* printf("Ouch: %s\n", calc_err_msg);
|
|
* }
|
|
* calc_use_matherr_jmpbuf = 1;
|
|
*/
|
|
|
|
|
|
#include <stdio.h>
|
|
#include <setjmp.h>
|
|
#include "args.h"
|
|
#include "calc.h"
|
|
#include "lib_calc.h"
|
|
|
|
|
|
/*
|
|
* math_error - print a math error and exit
|
|
*/
|
|
void
|
|
math_error(char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
|
|
/*
|
|
* format the error
|
|
*/
|
|
#ifdef VARARGS
|
|
va_start(ap);
|
|
#else
|
|
va_start(ap, fmt);
|
|
#endif
|
|
vsnprintf(calc_err_msg, MAXERROR, fmt, ap);
|
|
va_end(ap);
|
|
calc_err_msg[MAXERROR] = '\0'; /* paranoia */
|
|
|
|
/*
|
|
* if we should longjmp, so do
|
|
*/
|
|
if (calc_use_matherr_jmpbuf != 0) {
|
|
if (conf->calc_debug & CALCDBG_RUNSTATE)
|
|
printf("math_error: longjmp calc_matherr_jmpbuf\n");
|
|
longjmp(calc_matherr_jmpbuf, calc_use_matherr_jmpbuf);
|
|
}
|
|
|
|
/*
|
|
* print error message and edit
|
|
*/
|
|
(void) fflush(stdout);
|
|
(void) fflush(stderr);
|
|
fprintf(stderr, "%s\n\n", calc_err_msg);
|
|
|
|
/*
|
|
* if interactive, return to main via longjmp()
|
|
*/
|
|
if (calc_use_scanerr_jmpbuf != 0) {
|
|
if (conf->calc_debug & CALCDBG_RUNSTATE)
|
|
printf("math_error: longjmp calc_scanerr_jmpbuf\n");
|
|
longjmp(calc_scanerr_jmpbuf, calc_use_scanerr_jmpbuf);
|
|
}
|
|
|
|
/*
|
|
* exit
|
|
*/
|
|
if (conf->calc_debug & CALCDBG_RUNSTATE)
|
|
printf("math_error: about to exit\n");
|
|
libcalc_call_me_last();
|
|
exit(40);
|
|
}
|