-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHydresErr.c
More file actions
113 lines (103 loc) · 3.65 KB
/
Copy pathHydresErr.c
File metadata and controls
113 lines (103 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "HydresErr.h"
static void HydresErrSwitch (int no);
static int __Hydres_errno = 0;
static FILE* customErr = NULL;
void HydresErr(int no)
{
__Hydres_errno = no;
fputs(DEFAULT_ERR_MESS,errstream);
HydresErrSwitch(no);
herr.x = 0;
herr.y = 0;
herr.err = 0;
int i;
for (i = 0; i < SIZE_HERR_T ; i++)
herr.t[i] = 0;
}
static void HydresErrSwitch(int no)
{
switch (no)
{
case S_ERR:
#ifdef WIN32
fprintf(errstream, "Error while using a standard function : %s", strerror(errno));
#elif
fprintf(errstream, "Error while using a standard function : %s", strerror_r(errno));
#endif
break;
case err_fieldInitialize_OutOfMemory:
fprintf(errstream, "fieldInitialize ran out of usable memory (allocation attempt : %d bytes)",herr.x);
HydresErrSwitch(S_ERR);
exit(EXIT_FAILURE);
break;
case err_fieldInitialize_Misc:
fprintf(errstream, "fieldInitialize() attempt to create a negative-size : x %d or y %d", herr.x, herr.y);
break;
case err_fieldDestroy:
fprintf(errstream, "Can't use fieldDestroy on NULL");
break;
case err_copy_no_source:
fprintf(errstream, "No field to copy @ NULL");
break;
case err_display_no_source:
fprintf(errstream, "No field to display @ NULL");
break;
case err_fuse_size:
fprintf(errstream, "Error fusing fields: pasted element is misplaced or too big for the target (x %d > sx %d or y %d > sy %d)\n", herr.t[0], herr.t[1],herr.t[2],herr.t[3]);
switch (herr.err)
{
case errtag_sfuse:
fputs("tag : fieldFuse",errstream);
break;
case errtag_stfuse:
fputs("tag : fieldFuseST", errstream);
break;
}
break;
case err_fuse_nosource:
fprintf(errstream,"Error fusing fields: either arg 1 (%s) or arg 2 (%s) is NULL (tag : %s)",(herr.x & 1) ? "yes" : "no", (herr.x & 2) ? "yes" : "no", (herr.x & 4) ? "seethrough" : "normal");
break;
case err_append_nosource:
fprintf(errstream,"Error appending fields: either arg 1 (%s) or arg 2 (%s) is NULL",(herr.x & 1) ? "yes" : "no", (herr.x & 2) ? "yes" : "no");
break;
case err_paint_nosource:
fprintf(errstream, "Error painting a field : source is NULL");
break;
case err_paint_miscall:
fprintf(errstream,"Error: fieldPaintPart miscalled, either:\n");
fprintf(errstream,"s_x %d < 0\n",herr.t[0]);
fprintf(errstream,"s_y %d < 0\n",herr.t[1]);
fprintf(errstream,"e_x %d >= terrain->fsize_x %d\n",herr.t[2],herr.x);
fprintf(errstream,"e_y %d >= terrain->fsize_y %d\n",herr.t[3],herr.y);
break;
case err_inputstring_nosource:
fprintf(errstream,"Error calling fieldInputString : source is NULL");
if (herr.x == 1)
HydresErrSwitch(err_misc_oom);
break;
case err_misc_oom:
fprintf(errstream,"\nMiscellanous error - Out of memory\n");
HydresErrSwitch(S_ERR);
exit(EXIT_FAILURE);
break;
case err_strpaste_nosource:
fprintf(errstream,"Error pasting a string : source is NULL");
break;
case err_strextract_nosource:
fprintf(errstream,"Error extracting a string : source is NULL");
if (herr.x)
HydresErrSwitch(err_misc_oom);
break;
}
}
int HydresErrNo()
{
return __Hydres_errno;
}
void initErrStream()
{
if (errstream != stderr)
{
customErr = fopen(errstreamName, "a");
}
}