|
@@ -0,0 +1,128 @@
|
|
1
|
+#include "cmPrefix.h"
|
|
2
|
+#include "cmGlobal.h"
|
|
3
|
+#include "cmRpt.h"
|
|
4
|
+#include "cmErr.h"
|
|
5
|
+#include "cmCtx.h"
|
|
6
|
+#include "cmFile.h"
|
|
7
|
+#include "cmMem.h"
|
|
8
|
+#include "cmMallocDebug.h"
|
|
9
|
+#include "cmRptFile.h"
|
|
10
|
+
|
|
11
|
+cmRptFileH_t cmRptFileNullHandle = cmSTATIC_NULL_HANDLE;
|
|
12
|
+
|
|
13
|
+typedef struct
|
|
14
|
+{
|
|
15
|
+ cmErr_t err;
|
|
16
|
+ cmFileH_t printFileH;
|
|
17
|
+ cmFileH_t errorFileH;
|
|
18
|
+ cmRpt_t rpt;
|
|
19
|
+
|
|
20
|
+} cmRptFile_t;
|
|
21
|
+
|
|
22
|
+cmRptFile_t* _cmRptFileHandleToPtr( cmRptFileH_t h )
|
|
23
|
+{
|
|
24
|
+ cmRptFile_t* p = (cmRptFile_t*)h.h;
|
|
25
|
+ assert(p != NULL );
|
|
26
|
+ return p;
|
|
27
|
+}
|
|
28
|
+
|
|
29
|
+void _cmRptFilePrintFunc(void* cmRptUserPtr, const cmChar_t* text)
|
|
30
|
+{
|
|
31
|
+ cmRptFile_t* p = (cmRptFile_t*)cmRptUserPtr;
|
|
32
|
+ if( cmFileIsValid(p->printFileH))
|
|
33
|
+ cmFilePrint(p->printFileH,text);
|
|
34
|
+}
|
|
35
|
+
|
|
36
|
+void _cmRptFileErrorFunc(void* cmRptUserPtr, const cmChar_t* text)
|
|
37
|
+{
|
|
38
|
+ cmRptFile_t* p = (cmRptFile_t*)cmRptUserPtr;
|
|
39
|
+ if( cmFileIsValid(p->errorFileH))
|
|
40
|
+ cmFilePrint(p->errorFileH,text);
|
|
41
|
+}
|
|
42
|
+
|
|
43
|
+cmRfRC_t _cmRptFileClose( cmRptFile_t* p )
|
|
44
|
+{
|
|
45
|
+ if( cmFileClose( &p->printFileH ) != kOkFileRC )
|
|
46
|
+ cmErrMsg(&p->err,kFileFailRfRC,"Unable to close the print file.");
|
|
47
|
+
|
|
48
|
+ if( cmFileClose( &p->errorFileH ) != kOkFileRC )
|
|
49
|
+ cmErrMsg(&p->err,kFileFailRfRC,"Unable to close the error file.");
|
|
50
|
+
|
|
51
|
+ cmMemFree(p);
|
|
52
|
+
|
|
53
|
+ return kOkRfRC;
|
|
54
|
+}
|
|
55
|
+
|
|
56
|
+cmRfRC_t cmRptFileCreate( cmCtx_t* ctx, cmRptFileH_t* hp, const cmChar_t* printFn, const cmChar_t* errorFn )
|
|
57
|
+{
|
|
58
|
+ cmRptPrintFunc_t printFunc = NULL;
|
|
59
|
+ cmRptPrintFunc_t errorFunc = NULL;
|
|
60
|
+ cmRfRC_t rc;
|
|
61
|
+ if((rc = cmRptFileClose(hp)) != kOkRfRC )
|
|
62
|
+ return rc;
|
|
63
|
+
|
|
64
|
+ cmRptFile_t* p = cmMemAllocZ( cmRptFile_t, 1 );
|
|
65
|
+
|
|
66
|
+ cmErrSetup(&p->err,&ctx->rpt,"Rpt File");
|
|
67
|
+
|
|
68
|
+ if( printFn != NULL )
|
|
69
|
+ {
|
|
70
|
+ if((rc = cmFileOpen(&p->printFileH,printFn,kWriteFileFl,p->err.rpt)) == kOkFileRC )
|
|
71
|
+ printFunc = _cmRptFilePrintFunc;
|
|
72
|
+ else
|
|
73
|
+ {
|
|
74
|
+ rc = cmErrMsg(&p->err,kFileFailRfRC,"Unable to open the print file '%s'.", cmStringNullGuard(printFn));
|
|
75
|
+ goto errLabel;
|
|
76
|
+ }
|
|
77
|
+ }
|
|
78
|
+
|
|
79
|
+ if( errorFn != NULL )
|
|
80
|
+ {
|
|
81
|
+ if((rc = cmFileOpen(&p->errorFileH,errorFn,kWriteFileFl,p->err.rpt)) == kOkFileRC )
|
|
82
|
+ errorFunc = _cmRptFileErrorFunc;
|
|
83
|
+ else
|
|
84
|
+ {
|
|
85
|
+ rc = cmErrMsg(&p->err,kFileFailRfRC,"Unable to open the error file '%s'.", cmStringNullGuard(errorFn));
|
|
86
|
+ goto errLabel;
|
|
87
|
+ }
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+ if( errorFunc == NULL )
|
|
91
|
+ errorFunc = printFunc;
|
|
92
|
+
|
|
93
|
+ cmRptSetup(&p->rpt,printFunc,errorFunc,p);
|
|
94
|
+
|
|
95
|
+ hp->h = p;
|
|
96
|
+
|
|
97
|
+ errLabel:
|
|
98
|
+ if( rc != kOkRfRC )
|
|
99
|
+ _cmRptFileClose(p);
|
|
100
|
+
|
|
101
|
+ return rc;
|
|
102
|
+}
|
|
103
|
+
|
|
104
|
+cmRfRC_t cmRptFileClose( cmRptFileH_t* hp )
|
|
105
|
+{
|
|
106
|
+ cmRfRC_t rc = kOkRfRC;
|
|
107
|
+
|
|
108
|
+ if( hp==NULL || cmRptFileIsValid(*hp)==false)
|
|
109
|
+ return rc;
|
|
110
|
+
|
|
111
|
+ cmRptFile_t* p = _cmRptFileHandleToPtr( *hp );
|
|
112
|
+
|
|
113
|
+ if((rc = _cmRptFileClose(p)) != kOkRfRC )
|
|
114
|
+ return rc;
|
|
115
|
+
|
|
116
|
+ hp->h = NULL;
|
|
117
|
+
|
|
118
|
+ return rc;
|
|
119
|
+}
|
|
120
|
+
|
|
121
|
+bool cmRptFileIsValid( cmRptFileH_t h )
|
|
122
|
+{ return h.h != NULL; }
|
|
123
|
+
|
|
124
|
+cmRpt_t* cmRptFileRpt( cmRptFileH_t h )
|
|
125
|
+{
|
|
126
|
+ cmRptFile_t* p = _cmRptFileHandleToPtr( h );
|
|
127
|
+ return &p->rpt;
|
|
128
|
+}
|