limit fstBC to 30bp in Python3 ver.
[GalaxyCodeBases.git] / c_cpp / etc / calc / math_error.c
blob4bb25e5ebc4e351a8fd071188df2aa2f674492f7
1 /*
2 * math_error - a simple libcalc math error routine
4 * Copyright (C) 1999 Landon Curt Noll
6 * Calc is open software; you can redistribute it and/or modify it under
7 * the terms of the version 2.1 of the GNU Lesser General Public License
8 * as published by the Free Software Foundation.
10 * Calc is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
13 * Public License for more details.
15 * A copy of version 2.1 of the GNU Lesser General Public License is
16 * distributed with calc under the filename COPYING-LGPL. You should have
17 * received a copy with calc; if not, write to Free Software Foundation, Inc.
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * @(#) $Revision: 30.2 $
21 * @(#) $Id: math_error.c,v 30.2 2008/10/24 09:49:20 chongo Exp $
22 * @(#) $Source: /usr/local/src/bin/calc/RCS/math_error.c,v $
24 * Under source code control: 1994/08/03 05:08:22
25 * File existed as early as: 1994
27 * chongo <was here> /\oo/\ http://www.isthe.com/chongo/
28 * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
32 * Your program MUST provide a function called math_error. This is called
33 * by the math routines on an error condition, such as malloc failures or a
34 * division by zero. The routine is called in the manner of printf, with a
35 * format string and optional arguments.
37 * By default, this routine simply prints a message to stderr and then exits.
39 * If one sets up calc_matherr_jmpbuf, and then sets calc_use_matherr_jmpbuf
40 * to non-zero then this routine will longjmp back with the return value of
41 * calc_use_matherr_jmpbuf. In addition, the last calc error message will be
42 * found in calc_use_matherr_jmpbuf_msg. This error is not printed to sttderr.
44 * For example:
46 * #include <setjmp.h>
47 * #include "lib_calc.h"
49 * int error;
51 * ...
53 * if ((error = setjmp(calc_matherr_jmpbuf)) != 0) {
55 * (* reinitialize calc after a longjmp *)
56 * reinitialize();
58 * (* report the error *)
59 * printf("Ouch: %s\n", calc_err_msg);
60 * }
61 * calc_use_matherr_jmpbuf = 1;
65 #include <stdio.h>
66 #include <setjmp.h>
67 #include "args.h"
68 #include "calc.h"
69 #include "lib_calc.h"
73 * math_error - print a math error and exit
75 void
76 math_error(char *fmt, ...)
78 va_list ap;
81 * format the error
83 #ifdef VARARGS
84 va_start(ap);
85 #else
86 va_start(ap, fmt);
87 #endif
88 vsnprintf(calc_err_msg, MAXERROR, fmt, ap);
89 va_end(ap);
90 calc_err_msg[MAXERROR] = '\0';
93 * if we should longjmp, so do
95 if (calc_use_matherr_jmpbuf != 0) {
96 if (conf->calc_debug & CALCDBG_RUNSTATE)
97 printf("math_error: longjmp calc_matherr_jmpbuf\n");
98 longjmp(calc_matherr_jmpbuf, calc_use_matherr_jmpbuf);
102 * print error message and edit
104 (void) fflush(stdout);
105 (void) fflush(stderr);
106 fprintf(stderr, "%s\n\n", calc_err_msg);
109 * if interactive, return to main via longjmp()
111 if (calc_use_scanerr_jmpbuf != 0) {
112 if (conf->calc_debug & CALCDBG_RUNSTATE)
113 printf("math_error: longjmp calc_scanerr_jmpbuf\n");
114 longjmp(calc_scanerr_jmpbuf, calc_use_scanerr_jmpbuf);
118 * exit
120 if (conf->calc_debug & CALCDBG_RUNSTATE)
121 printf("math_error: about to exit\n");
122 libcalc_call_me_last();
123 exit(40);