TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpcextensions
statusmsg.c
Go to the documentation of this file.
1
4
/*****************************************************************************/
5
#include "tpcclibConfig.h"
6
/*****************************************************************************/
7
#include <stdio.h>
8
#include <stdlib.h>
9
#include <time.h>
10
#include <string.h>
11
/*****************************************************************************/
12
#include "
tpcextensions.h
"
13
/*****************************************************************************/
14
15
/*****************************************************************************/
19
static
char
*tpcerrormsg[] = {
20
// typedef enum tpcerror in tpcextensions.h must be edited accordingly
21
"OK"
,
22
"unspecified error"
,
23
"unable to allocate memory"
,
24
"file does not exist"
,
25
"file exists"
,
26
"invalid filename"
,
27
"cannot open file"
,
28
"cannot read file"
,
29
"cannot write file"
,
30
"cannot delete"
,
31
"invalid file format"
,
32
"unsupported file type"
,
33
"file contains no data"
,
34
"file contains duplicate data"
,
35
"file contains no weights"
,
36
"file contains no date or time"
,
37
"file contains missing values"
,
38
"file contains too few samples"
,
39
"file is too big"
,
40
"overlapping data"
,
41
"large gap in data"
,
42
"no sample times"
,
43
"invalid sample time"
,
44
"invalid sample time range"
,
45
"incompatible units"
,
46
"incompatible data"
,
47
"reference not found"
,
48
"key not found"
,
49
"value not found"
,
50
"invalid value"
,
51
"invalid field delimiter"
,
52
"invalid nr of parameters"
,
53
"invalid header"
,
54
"missing header"
,
55
"unknown isotope"
,
56
"unknown data unit"
,
57
"no solution"
,
58
"fitting not successful"
,
59
0};
60
/*****************************************************************************/
61
62
/*****************************************************************************/
68
char
*
errorMsg
(
70
tpcerror
e
71
) {
72
if
(e<TPCERROR_OK || e>=
TPCERROR_LAST
)
return
NULL;
73
return
tpcerrormsg[e];
74
}
75
/*****************************************************************************/
76
77
/*****************************************************************************/
82
void
statusPrint
(
84
FILE *fp,
86
TPCSTATUS
*s
87
) {
88
if
(fp==NULL || s==NULL)
return
;
89
if
(s->
current_file
!=NULL && s->
current_func
!=0 && s->
current_line
>0)
90
fprintf(fp,
"In %s() on line %d of file %s\n"
, s->
current_func
, s->
current_line
, s->
current_file
);
91
if
(s->
verbose
<=0)
return
;
92
if
(s->
last_file
!=NULL && s->
last_func
!=0 && s->
last_line
>0)
93
fprintf(fp,
"called in %s() on line %d of file %s\n"
, s->
last_func
, s->
last_line
, s->
last_file
);
94
return
;
95
}
96
/*****************************************************************************/
97
98
/*****************************************************************************/
104
void
statusInit
(
106
TPCSTATUS
*s
107
) {
108
if
(s==NULL)
return
;
109
s->
last_line
=0;
110
s->
last_file
=NULL;
111
s->
last_func
=NULL;
112
s->
current_line
=0;
113
s->
current_file
=NULL;
114
s->
current_func
=NULL;
115
s->
verbose
=0;
116
s->
fp
=stdout;
117
s->
forgiving
=0;
118
s->
error
=0;
119
}
120
/*****************************************************************************/
121
122
/*****************************************************************************/
126
void
statusFree
(
128
TPCSTATUS
*s
129
) {
130
if
(s==NULL)
return
;
131
free(s->
last_file
); free(s->
last_func
);
132
free(s->
current_file
); free(s->
current_func
);
133
if
(s->
fp
!=NULL && s->
fp
!=stdout && s->
fp
!=stderr) fclose(s->
fp
);
134
statusInit
(s);
135
}
136
/*****************************************************************************/
137
138
/*****************************************************************************/
142
void
statusSet
(
144
TPCSTATUS
*s,
146
const
char
*func,
148
const
char
*srcfile,
150
int
srcline,
152
tpcerror
error
153
) {
154
if
(s==NULL)
return
;
155
s->
error
=error;
156
/* Delete any previous content */
157
s->
last_line
=0;
158
free(s->
last_file
); free(s->
last_func
);
159
s->
last_file
=NULL; s->
last_func
=NULL;
160
/* Move current content to previous */
161
s->
last_line
=s->
current_line
;
162
s->
last_file
=s->
current_file
;
163
s->
last_func
=s->
current_func
;
164
/* Set current contents */
165
s->
current_line
=srcline;
166
if
(func!=NULL) s->
current_func
=
strdup
(func);
167
if
(srcfile!=NULL) s->
current_file
=
strdup
(srcfile);
168
s->
error
=error;
169
}
170
/*****************************************************************************/
171
172
/*****************************************************************************/
statusPrint
void statusPrint(FILE *fp, TPCSTATUS *s)
Definition
statusmsg.c:82
statusInit
void statusInit(TPCSTATUS *s)
Definition
statusmsg.c:104
errorMsg
char * errorMsg(tpcerror e)
Definition
statusmsg.c:68
statusSet
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition
statusmsg.c:142
statusFree
void statusFree(TPCSTATUS *s)
Definition
statusmsg.c:126
strdup
char * strdup(const char *s)
Definition
stringext.c:185
TPCSTATUS
Definition
tpcextensions.h:241
TPCSTATUS::verbose
int verbose
Verbose level, used by statusPrint() etc.
Definition
tpcextensions.h:242
TPCSTATUS::fp
FILE * fp
File pointer for writing log information during development and testing.
Definition
tpcextensions.h:243
TPCSTATUS::forgiving
int forgiving
Force level, 0 for strict tests for data units etc.
Definition
tpcextensions.h:244
TPCSTATUS::current_func
char * current_func
Function where status was last time set.
Definition
tpcextensions.h:246
TPCSTATUS::current_line
int current_line
Source line nr where status was last time set.
Definition
tpcextensions.h:248
TPCSTATUS::last_file
char * last_file
Source file name where status previously set.
Definition
tpcextensions.h:250
TPCSTATUS::current_file
char * current_file
Source file name where status was last time set.
Definition
tpcextensions.h:247
TPCSTATUS::last_line
int last_line
Source line nr where status was previously set.
Definition
tpcextensions.h:251
TPCSTATUS::error
tpcerror error
Error code.
Definition
tpcextensions.h:245
TPCSTATUS::last_func
char * last_func
Function where status was previously set.
Definition
tpcextensions.h:249
tpcextensions.h
Header file for library libtpcextensions.
tpcerror
tpcerror
Error codes. Error code tpcerror, same as error message position in the table (table can not be acces...
Definition
tpcextensions.h:189
TPCERROR_LAST
@ TPCERROR_LAST
marking the end of list
Definition
tpcextensions.h:229
Generated on
for TPCCLIB by
1.17.0