Macaulay2 Engine
Loading...
Searching...
No Matches
error.c
Go to the documentation of this file.
1
// (c) 1997 Michael E. Stillman
2
3
// This stuff would not be necessary if exceptions worked well,
4
// unfortunately, there are internal errors so that they fail
5
// at least in the presence of template code (even in version 2.7.2).
6
// So, we use the following simple, if unpleasant, scheme.
7
//
8
// Upon finding an error, call ERROR any number of times. Each time,
9
// The message is added to the end (but, it won't write over the end of
10
// the buffer).
11
//
12
// Then, it is unfortunately necessary to check whether an error has
13
// occurred, using 'error'.
14
//
15
// Finally, the error flag is cleared upon giving control back to the front end.
16
17
#include "
error.h
"
18
#include <stdio.h>
19
#include <stdarg.h>
20
#include <stdlib.h>
21
22
#define MAXERROR 200
23
static
int
iserror
= 0;
24
static
char
errmsg
[
MAXERROR
] = {
'\0'
};
25
26
void
ERROR
(
const
char
*
s
, ...)
27
{
28
va_list ap;
29
if
(
iserror
) fprintf(stderr,
"--error message bumped: %s\n"
,
errmsg
);
30
iserror
= 1;
31
va_start(ap,
s
);
32
vsprintf(
errmsg
,
s
, ap);
33
va_end(ap);
34
}
35
36
void
INTERNAL_ERROR
(
const
char
*
s
, ...)
37
{
38
char
buf[
MAXERROR
];
39
buf[0] = 0;
40
va_list ap;
41
va_start(ap,
s
);
42
vsprintf(buf,
s
, ap);
43
va_end(ap);
44
fprintf(stderr,
"--internal error: %s\n"
, buf);
45
abort();
/* we should exit after an internal error, to avoid crashing */
46
}
47
48
int
error
() {
return
iserror
; }
49
const
char
*
error_message
()
50
{
51
if
(
iserror
== 0)
return
""
;
52
iserror
= 0;
53
return
errmsg
;
54
}
55
56
/*
57
// Local Variables:
58
// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
59
// indent-tabs-mode: nil
60
// End:
61
*/
MAXERROR
#define MAXERROR
Definition
error.c:22
iserror
static int iserror
Definition
error.c:23
INTERNAL_ERROR
void INTERNAL_ERROR(const char *s,...)
Definition
error.c:36
error_message
const char * error_message()
Definition
error.c:49
error
int error()
Definition
error.c:48
errmsg
static char errmsg[MAXERROR]
Definition
error.c:24
error.h
Engine error-reporting primitives: ERROR, INTERNAL_ERROR, error, error_message.
s
void size_t s
Definition
m2-mem.cpp:271
ERROR
const int ERROR
Definition
m2-mem.cpp:55
Macaulay2
e
error.c
Generated on
for Macaulay2 Engine by
1.15.0