1 | /****************************************************************** |
---|
2 | * |
---|
3 | * File: MPT_Error.c |
---|
4 | * Purpose: Routines related to Error handling of MPT |
---|
5 | * Author: Olaf Bachman (obachman@mathematik.uni-kl.de) |
---|
6 | * Created: 12/96 |
---|
7 | * |
---|
8 | * Change History (most recent first): |
---|
9 | * |
---|
10 | ******************************************************************/ |
---|
11 | |
---|
12 | #include "MPT.h" |
---|
13 | |
---|
14 | char *MPT_errlist[] = |
---|
15 | { |
---|
16 | "MPT: MPT_Failure", |
---|
17 | "MPT: MPT_Success", |
---|
18 | "MPT: MPT_MP_Failure", |
---|
19 | "MPT: Unknown Type", |
---|
20 | "MPT: Can't allocate memory", |
---|
21 | "MPT: MPT tree has wrong syntax/structure", |
---|
22 | "MPT: MP node of unknown type", |
---|
23 | "MPT: ProtoD:Pointer without Arg", |
---|
24 | "MPT: Union Discriminator too large (out of permissible range)", |
---|
25 | "MPT: An internal assumption has been violated", |
---|
26 | "MPT: External application did not read data from link", |
---|
27 | "MPT: Wrong ApInt format requested" |
---|
28 | }; |
---|
29 | |
---|
30 | |
---|
31 | MPT_Status_t MPT_errno = MPT_Success; |
---|
32 | |
---|
33 | MPT_Status_t MPT_CheckError() |
---|
34 | { |
---|
35 | MPT_Status_t status = MPT_errno; |
---|
36 | MPT_ClearError(); |
---|
37 | return status; |
---|
38 | } |
---|
39 | |
---|
40 | char* MPT_ErrorStr(MPT_Status_t error) |
---|
41 | { |
---|
42 | if (error < MPT_MaxError && error > 0) |
---|
43 | return MPT_errlist[error]; |
---|
44 | else |
---|
45 | return "Unknown MPT error number"; |
---|
46 | } |
---|
47 | |
---|
48 | char* MPT_LinkErrorStr(MP_Link_pt link, MPT_Status_t error) |
---|
49 | { |
---|
50 | if (error == MPT_MP_Failure && |
---|
51 | link != NULL && link->errno >= 0 && link->errno != MP_Success) |
---|
52 | return MP_ErrorStr(link); |
---|
53 | |
---|
54 | if (error >= 0 && error < MPT_MaxError) |
---|
55 | return MPT_errlist[error]; |
---|
56 | |
---|
57 | return "MPT: Unknown Error"; |
---|
58 | } |
---|
59 | |
---|
60 | #ifdef MPT_DEBUG |
---|
61 | MPT_Status_t MPT_SetError(MPT_Status_t mpt_error) |
---|
62 | { |
---|
63 | return MPT_errno = mpt_error; |
---|
64 | } |
---|
65 | |
---|
66 | MPT_Status_t MPT_ClearError() |
---|
67 | { |
---|
68 | return MPT_errno = MPT_Success; |
---|
69 | } |
---|
70 | |
---|
71 | /* when debugging is turned on, this function gets called, whenever |
---|
72 | MPT_Assume is used */ |
---|
73 | void MPT_Assume(MP_Boolean_t ass) |
---|
74 | { |
---|
75 | if (!ass) |
---|
76 | { |
---|
77 | MPT_SetError(MPT_ViolatedAssumption); |
---|
78 | } |
---|
79 | } |
---|
80 | #endif |
---|
81 | |
---|
82 | |
---|