TPCCLIB
Loading...
Searching...
No Matches
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/*****************************************************************************/
19static 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",
590};
60/*****************************************************************************/
61
62/*****************************************************************************/
70 tpcerror e
71) {
72 if(e<TPCERROR_OK || e>=TPCERROR_LAST) return NULL;
73 return tpcerrormsg[e];
74}
75/*****************************************************************************/
76
77/*****************************************************************************/
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/*****************************************************************************/
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/*****************************************************************************/
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/*****************************************************************************/
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 */
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/*****************************************************************************/
void statusPrint(FILE *fp, TPCSTATUS *s)
Definition statusmsg.c:82
void statusInit(TPCSTATUS *s)
Definition statusmsg.c:104
char * errorMsg(tpcerror e)
Definition statusmsg.c:68
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition statusmsg.c:142
void statusFree(TPCSTATUS *s)
Definition statusmsg.c:126
char * strdup(const char *s)
Definition stringext.c:185
int verbose
Verbose level, used by statusPrint() etc.
FILE * fp
File pointer for writing log information during development and testing.
int forgiving
Force level, 0 for strict tests for data units etc.
char * current_func
Function where status was last time set.
int current_line
Source line nr where status was last time set.
char * last_file
Source file name where status previously set.
char * current_file
Source file name where status was last time set.
int last_line
Source line nr where status was previously set.
tpcerror error
Error code.
char * last_func
Function where status was previously set.
Header file for library libtpcextensions.
tpcerror
Error codes. Error code tpcerror, same as error message position in the table (table can not be acces...
@ TPCERROR_LAST
marking the end of list