File: report.cpp

package info (click to toggle)
beid 3.5.2.dfsg-10
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 147,240 kB
  • ctags: 34,507
  • sloc: cpp: 149,944; ansic: 41,577; java: 8,927; cs: 6,528; sh: 2,426; perl: 1,866; xml: 805; python: 463; makefile: 263; lex: 92
file content (743 lines) | stat: -rw-r--r-- 18,274 bytes parent folder | download
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
/* ****************************************************************************

 * eID Middleware Project.
 * Copyright (C) 2008-2009 FedICT.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version
 * 3.0 as published by the Free Software Foundation.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, see
 * http://www.gnu.org/licenses/.

**************************************************************************** */
#ifdef WIN32
#include <windows.h>
#elif defined __APPLE__
#include "Mac/mac_helper.h"
#endif

#include <string.h>
#include <iostream>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>

#include "diaglib.h"
#include "report.h"
#include "file.h"

#include "error.h"
#include "log.h"
#include "folder.h"

#define REPORT_TOTAL L"diagreport.txt"
#define REPORT_ABSTRACT L"diagabstract.txt"
#define REPORT_OPEN_ATTEMPT_COUNT 5

//#define FILE_ENCODING L", ccs=UTF-8" 
#define FILE_ENCODING L"" 

#define REPORT_WIDTH		80

static std::wstring g_wsReportTotal;
static std::wstring g_wsReportAbstract;
static std::wstring g_wsReportLevel1;
static std::wstring g_wsReportLevel2;
static std::wstring g_wsReportLevel3;

static FILE *g_pfile_level1=NULL;
static FILE *g_pfile_level2=NULL;
static FILE *g_pfile_level3=NULL;
static bool g_reportFirstOpen=true;

////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// PRIVATE FUNCTIONS DECLARATION ////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
FILE *getFile(Report_TYPE type);
int reportPrintFileSeparator(Report_TYPE type);
int reportLoadResources();

////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// PUBLIC FUNCTIONS /////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
int reportGetFileName(const wchar_t **fileName, bool bAbstractOnly)
{
	int iReturnCode=DIAGLIB_OK;

	if(fileName==NULL)
	{
		return RETURN_LOG_BAD_FUNCTION_CALL;	
	}

	if(bAbstractOnly)
	{
		if(g_wsReportAbstract.empty())
		{
			return RETURN_LOG_BAD_FUNCTION_CALL; //First make a Finalize
		}

		*fileName=g_wsReportAbstract.c_str();
	}
	else
	{
		if(g_wsReportTotal.empty())
		{
			return RETURN_LOG_BAD_FUNCTION_CALL; //First make a Finalize
		}

		*fileName=g_wsReportTotal.c_str();
	}

	return iReturnCode;
}

////////////////////////////////////////////////////////////////////////////////////////////////
int reportInit()
{
	int iReturnCode = DIAGLIB_OK;

	//Initialize g_wsReportResult, g_wsReportMain and g_wsReportComplement
	if(g_wsReportLevel1.empty())
	{
		if(DIAGLIB_OK != folderGetTempFileName(&g_wsReportLevel1))
		{
			return RETURN_LOG_INTERNAL_ERROR;
		}
	}
	if(g_wsReportLevel2.empty())
	{
		if(DIAGLIB_OK != folderGetTempFileName(&g_wsReportLevel2))
		{
			return RETURN_LOG_INTERNAL_ERROR;
		}
	}
	if(g_wsReportLevel3.empty())
	{
		if(DIAGLIB_OK != folderGetTempFileName(&g_wsReportLevel3))
		{
			return RETURN_LOG_INTERNAL_ERROR;
		}
	}
	
	return iReturnCode;
}

////////////////////////////////////////////////////////////////////////////////////////////////
int reportLoadResources()
{
	int iReturnCode=DIAGLIB_OK;
	
	//File already open
	if(g_pfile_level1 != NULL && g_pfile_level2 != NULL && g_pfile_level3 != NULL)
	{
		return DIAGLIB_OK;	
	}

	if(g_wsReportLevel1.empty() || g_wsReportLevel2.empty() || g_wsReportLevel3.empty()) 
	{
		reportInit();
	}
		
	errno_t err=0;
	
	//Create the files (Erase previous file)
	if (!g_pfile_level1)
	{
		for(int i=0;i<REPORT_OPEN_ATTEMPT_COUNT;i++)
		{
			err = _wfopen_s(&g_pfile_level1, g_wsReportLevel1.c_str(), (g_reportFirstOpen?L"w" FILE_ENCODING:L"a" FILE_ENCODING));
			if (!g_pfile_level1)
			{
				LOG_ERRORCODE(L"_wfopen_s failed",err);
				return RETURN_LOG_ERROR(DIAGLIB_ERR_FILE_CREATE_FAILED);
			}
			if (g_pfile_level1)
				break;
			else
				Sleep(50);
		}
	}
	if(g_pfile_level1 && g_reportFirstOpen)
	{
#ifdef WIN32
		fwprintf_s(g_pfile_level1,L"RUNNING eDT VERSION: %hs\n",diaglibVersion());
#elif __APPLE__
		fwprintf_s(g_pfile_level1,L"RUNNING eDT VERSION: %s\n",diaglibVersion());
#endif	
	}
	
	if (!g_pfile_level2)
	{
		for(int i=0;i<REPORT_OPEN_ATTEMPT_COUNT;i++)
		{
			err = _wfopen_s(&g_pfile_level2, g_wsReportLevel2.c_str(), (g_reportFirstOpen?L"w" FILE_ENCODING:L"a" FILE_ENCODING));
			if (!g_pfile_level2)
			{
				LOG_ERRORCODE(L"_wfopen_s failed",err);
				return RETURN_LOG_ERROR(DIAGLIB_ERR_FILE_CREATE_FAILED);
			}
			if (g_pfile_level2)
				break;
			else
				Sleep(50);
		}
	}
	
	if (!g_pfile_level3)
	{
		for(int i=0;i<REPORT_OPEN_ATTEMPT_COUNT;i++)
		{
			err = _wfopen_s(&g_pfile_level3, g_wsReportLevel3.c_str(), (g_reportFirstOpen?L"w" FILE_ENCODING:L"a" FILE_ENCODING));
			if (!g_pfile_level3)
			{
				LOG_ERRORCODE(L"_wfopen_s failed",err);
				return RETURN_LOG_ERROR(DIAGLIB_ERR_FILE_CREATE_FAILED);
			}
			if (g_pfile_level3)
				break;
			else
				Sleep(50);
		}
	}
	
	g_reportFirstOpen = false;
	
	return iReturnCode;
}

////////////////////////////////////////////////////////////////////////////////////////////////
int reportPrintLine(Report_TYPE type, const wchar_t *text,wchar_t c, int uppercase, int padding)
{
	int iReturnCode=DIAGLIB_OK;

	FILE *pfile;
	if(NULL == (pfile=getFile(type)))
		return RETURN_LOG_INTERNAL_ERROR;

	unsigned long i=0;
	size_t iMaxSep=0;
	size_t iMaxPad=0;
	size_t iLen=0;

	wchar_t *buff=NULL;

	buff= new wchar_t[wcslen(text)+1];
	wcscpy_s(buff,wcslen(text)+1,text);

	if(uppercase)
	{
		for(i=0;i<wcslen(text);i++)
			buff[i]=toupper(buff[i]);
	}

	iLen=wcslen(buff);
	if(iLen)
		iLen+=2;

	//Print in File
	if(REPORT_WIDTH<iLen)
	{
		iMaxSep=0;
		iMaxPad=0;
	}
	else if(padding>0 && REPORT_WIDTH >= iLen + 2*padding)
	{
		iMaxPad=padding;
		iMaxSep=(REPORT_WIDTH - iLen) / 2 - iMaxPad;
	}
	else
	{
		size_t iLeft=(REPORT_WIDTH - iLen) / 2;
		iMaxPad=(padding*2*iLeft)/REPORT_WIDTH;
		iMaxSep=(REPORT_WIDTH - iLen) / 2 - iMaxPad;
	}

	for(i=0;i<iMaxSep;i++) fwprintf_s(pfile,L"%lc",c);
	for(i=0;i<iMaxPad;i++) fwprintf_s(pfile,L" ");

	if(iLen)
		fwprintf_s(pfile,L" %ls ",buff);

	for(i=0;i<iMaxPad;i++) fwprintf_s(pfile,L" ");
	iMaxSep=REPORT_WIDTH<iLen?0:REPORT_WIDTH - iLen - iMaxSep - 2*iMaxPad;
	for(i=0;i<iMaxSep;i++) fwprintf_s(pfile,L"%lc",c);

	fwprintf_s(pfile,L"\n");

	delete[] buff;

	return iReturnCode;
}

////////////////////////////////////////////////////////////////////////////////////////////////
int reportPrintHex(Report_TYPE type, const wchar_t *title, const unsigned char *buffer, unsigned long len, const wchar_t sep)
{
	int iReturnCode=DIAGLIB_OK;

	FILE *pfile;
	if(NULL == (pfile=getFile(type)))
		return RETURN_LOG_INTERNAL_ERROR;

	reportPrintTitle1(type, title, sep);

	unsigned long i=0;
	unsigned long line=0;

	for(i=0,line=0;i<len;i++,line++)
	{
		if(line==REPORT_WIDTH/3)
		{
			fwprintf_s(pfile,L"\n");
			line=0;
		}

		fwprintf_s(pfile,L"%02x ",buffer[i]);
	}

	fwprintf_s(pfile,L"\n");

	return iReturnCode;
}

////////////////////////////////////////////////////////////////////////////////////////////////
int reportPrint(Report_TYPE type, const wchar_t *format, ...)
{
	int iReturnCode=DIAGLIB_OK;

	FILE *pfile;
	if(NULL == (pfile=getFile(type)))
		return RETURN_LOG_INTERNAL_ERROR;

	va_list args;
	va_start(args, format);
	
	vfwprintf_s(pfile, format, args);
	
	va_end(args);

	return iReturnCode;
}

////////////////////////////////////////////////////////////////////////////////////////////////
int reportPrintHeader1(Report_TYPE type, const wchar_t *text, const wchar_t sep)
{
	int iReturnCode=DIAGLIB_OK;

	if(DIAGLIB_OK != (iReturnCode=reportPrintLine(type, L"", sep, 0))) return iReturnCode;
	if(DIAGLIB_OK != (iReturnCode=reportPrintLine(type, L"", sep, 0, 30))) return iReturnCode;
	if(DIAGLIB_OK != (iReturnCode=reportPrintLine(type, text,sep, 1, 35))) return iReturnCode;
	if(DIAGLIB_OK != (iReturnCode=reportPrintLine(type, L"", sep, 0 ,30))) return iReturnCode;
	if(DIAGLIB_OK != (iReturnCode=reportPrintLine(type, L"", sep, 0))) return iReturnCode;

	return iReturnCode;
}

////////////////////////////////////////////////////////////////////////////////////////////////
int reportPrintHeader2(Report_TYPE type, const wchar_t *text, const wchar_t sep)
{
	int iReturnCode=DIAGLIB_OK;

	if(DIAGLIB_OK != (iReturnCode=reportPrintLine(type, L"",sep, 0))) return iReturnCode;
	if(DIAGLIB_OK != (iReturnCode=reportPrintLine(type, text,sep, 1, 15))) return iReturnCode;
	if(DIAGLIB_OK != (iReturnCode=reportPrintLine(type, L"",sep, 0))) return iReturnCode;

	return iReturnCode;
}

////////////////////////////////////////////////////////////////////////////////////////////////
int reportPrintTitle1(Report_TYPE type, const wchar_t *text, const wchar_t sep)
{
	int iReturnCode=DIAGLIB_OK;

	if(DIAGLIB_OK != (iReturnCode=reportPrintLine(type, text,sep, 1))) return iReturnCode;

	return iReturnCode;
}

////////////////////////////////////////////////////////////////////////////////////////////////
int reportPrintTitle2(Report_TYPE type, const wchar_t *text, const wchar_t sep)
{
	int iReturnCode=DIAGLIB_OK;

	if(DIAGLIB_OK != (iReturnCode=reportPrintLine(type, text,sep, 0))) return iReturnCode;

	return iReturnCode;
}

////////////////////////////////////////////////////////////////////////////////////////////////
int reportPrintSeparator(Report_TYPE type, const wchar_t sep)
{
	int iReturnCode=DIAGLIB_OK;

	if(DIAGLIB_OK != (iReturnCode=reportPrintLine(type, L"",sep, 0))) return iReturnCode;

	return iReturnCode;
}

////////////////////////////////////////////////////////////////////////////////////////////////
int reportPrintComment(Report_TYPE type, const wchar_t *text)
{
	int iReturnCode=DIAGLIB_OK;

	FILE *pfile;
	if(NULL == (pfile=getFile(type)))
		return RETURN_LOG_ERROR(DIAGLIB_ERR_INTERNAL);;

	fwprintf_s(pfile,L"---> %ls\n", text);

	return iReturnCode;
}

////////////////////////////////////////////////////////////////////////////////////////////////
int reportPrintResult(Report_TYPE type, const wchar_t *text)
{
	int iReturnCode=DIAGLIB_OK;

	FILE *pfile;
	if(NULL == (pfile=getFile(type)))
		return RETURN_LOG_ERROR(DIAGLIB_ERR_INTERNAL);;

//	fwprintf_s(pfile,L"%ls\n\n", text);
	fwprintf_s(pfile,L"%ls\n", text);

	return iReturnCode;
}

////////////////////////////////////////////////////////////////////////////////////////////////
int reportUnloadResources()
{
	int iReturnCode=DIAGLIB_OK;

	//Close res main and cpl
	if(g_pfile_level1)
	{
		if(0 != fclose(g_pfile_level1))
		{
			LOG_ERRORCODE(L"Failed to close the file",errno);
		}
		g_pfile_level1=NULL;
	}
	
	if(g_pfile_level2)
	{
		if(0 != fclose(g_pfile_level2))
		{
			LOG_ERRORCODE(L"Failed to close the file",errno);
		}
		g_pfile_level2=NULL;
	}
	
	if(g_pfile_level3)
	{
		if(0 != fclose(g_pfile_level3))
		{
			LOG_ERRORCODE(L"Failed to close the file",errno);
		}
		g_pfile_level3=NULL;
	}

	return iReturnCode;
}

////////////////////////////////////////////////////////////////////////////////////////////////
int reportFinalize(const wchar_t *wzReportAbstract,const wchar_t *wzReportTotal)
{
	int iReturnCode=DIAGLIB_OK;

	if(!g_wsReportTotal.empty())
	{
		LOG_ERROR(L"reportFinalize already be done");
		return RETURN_LOG_BAD_FUNCTION_CALL;
	}
	
	if(DIAGLIB_OK != (iReturnCode=reportPrintFileSeparator(REPORT_TYPE_MAIN)))
		return iReturnCode;

	//Initialize FinalReport
	if(wzReportTotal==NULL)
	{
		folderGetPath(FOLDER_TEMP, &g_wsReportTotal);
		g_wsReportTotal.append(REPORT_TOTAL);	
	}
	else if(wcslen(wzReportTotal)==0)
	{
		return RETURN_LOG_BAD_FUNCTION_CALL;	
	}
	else
	{
		g_wsReportTotal.assign(wzReportTotal);
	}

	if(wzReportAbstract==NULL)
	{
		folderGetPath(FOLDER_TEMP, &g_wsReportAbstract);
		g_wsReportAbstract.append(REPORT_ABSTRACT);	
	}
	else if(wcslen(wzReportAbstract)==0)
	{
		g_wsReportTotal.clear();
		return RETURN_LOG_BAD_FUNCTION_CALL;	
	}
	else
	{
		g_wsReportAbstract.assign(wzReportAbstract);
	}

	reportUnloadResources();

	errno_t err;

	FILE *fWrite = NULL;
	FILE *fWriteAbstract = NULL;
	FILE *fRead = NULL;
	wchar_t line[REPORT_WIDTH+1];

	//Open Final report for writing
	for(int i=0;i<REPORT_OPEN_ATTEMPT_COUNT;i++)
	{
		err = _wfopen_s(&fWrite, g_wsReportTotal.c_str(), L"w" FILE_ENCODING);
		if (!fWrite)
		{
			LOG_ERRORCODE(L"_wfopen_s failed",err);
			return RETURN_LOG_ERROR(DIAGLIB_ERR_FILE_CREATE_FAILED);
		}
		if (fWrite)
			break;
		else
			Sleep(50);
	}

	//Open Result report for writing
	for(int i=0;i<REPORT_OPEN_ATTEMPT_COUNT;i++)
	{
		err = _wfopen_s(&fWriteAbstract, g_wsReportAbstract.c_str(), L"w" FILE_ENCODING);
		if (!fWriteAbstract)
		{
			LOG_ERRORCODE(L"_wfopen_s failed",err);
			return RETURN_LOG_ERROR(DIAGLIB_ERR_FILE_CREATE_FAILED);
		}
		if (fWriteAbstract)
			break;
		else
			Sleep(50);
	}


	//Open res for reading
	for(int i=0;i<REPORT_OPEN_ATTEMPT_COUNT;i++)
	{
		err = _wfopen_s(&fRead, g_wsReportLevel1.c_str(), L"r" FILE_ENCODING);
		if (!fRead)
		{
			LOG_ERRORCODE(L"_wfopen_s failed",err);
			return DIAGLIB_ERR_FILE_OPEN_FAILED;
		}

		if (fRead)
			break;
		else
			Sleep(50);
	}

	//write content into res
	while( !feof( fRead ) )
	{
		if( fgetws( line, REPORT_WIDTH+1, fRead ) == NULL)
		{
			break;
		}
		fwprintf_s(fWrite,L"%ls", line);
		fwprintf_s(fWriteAbstract,L"%ls", line);
    }

	//close Res
	if(0 != fclose(fRead))
	{
		LOG_ERRORCODE(L"Failed to close the file",errno);
	}
	fRead=NULL;

	//close ResultReport
	if(0 != fclose(fWriteAbstract))
	{
		LOG_ERRORCODE(L"Failed to close the file",errno);
	}
	fWriteAbstract=NULL;

	//delete Res
	fileDelete(g_wsReportLevel1);
	g_wsReportLevel1.clear();

	//Open main for reading
	for(int i=0;i<REPORT_OPEN_ATTEMPT_COUNT;i++)
	{
		err = _wfopen_s(&fRead, g_wsReportLevel2.c_str(), L"r" FILE_ENCODING);
		if (!fRead)
		{
			LOG_ERRORCODE(L"_wfopen_s failed",err);
			return DIAGLIB_ERR_FILE_OPEN_FAILED;
		}

		if (fRead)
			break;
		else
			Sleep(50);
	}

	//write content into res
	while( !feof( fRead ) )
	{
		if( fgetws( line, REPORT_WIDTH+1, fRead ) == NULL)
		{
			break;
		}
		fwprintf_s(fWrite,L"%ls", line);
    }

	//close main
	if(0 != fclose(fRead))
	{
		LOG_ERRORCODE(L"Failed to close the file",errno);
	}
	fRead=NULL;

	//delete main
	fileDelete(g_wsReportLevel2);
	g_wsReportLevel2.clear();

	//Open cpl for reading
	for(int i=0;i<REPORT_OPEN_ATTEMPT_COUNT;i++)
	{
		err = _wfopen_s(&fRead, g_wsReportLevel3.c_str(), L"r" FILE_ENCODING);
		if (!fRead)
		{
			LOG_ERRORCODE(L"_wfopen_s failed",err);
			return DIAGLIB_ERR_FILE_OPEN_FAILED;
		}

		if (fRead)
			break;
		else
			Sleep(50);
	}

	//write content into res
	while( !feof( fRead ) )
	{
		if( fgetws( line, REPORT_WIDTH+1, fRead ) == NULL)
		{
			break;
		}
		fwprintf_s(fWrite,L"%ls", line);
    }

	//close cpl
	if(0 != fclose(fRead))
	{
		LOG_ERRORCODE(L"Failed to close the file",errno);
	}
	fRead=NULL;

	//delete cpl
	fileDelete(g_wsReportLevel3);
	g_wsReportLevel3.clear();

	//WARNING NO MORE LOGGING AFTER THIS POINT
	//Adding the log to the report
	logFinalize();

	const wchar_t *logFileName = NULL;

	if(DIAGLIB_OK == logGetFileName(&logFileName))
	{
		for(int i=0;i<REPORT_OPEN_ATTEMPT_COUNT;i++)
		{
			err = _wfopen_s(&fRead, logFileName, L"r" FILE_ENCODING);
			if (!fRead)
			{
				return DIAGLIB_ERR_FILE_OPEN_FAILED;
			}

			if (fRead)
				break;
			else
				Sleep(50);
		}

		fwprintf_s(fWrite,L"\n\n");
		fwprintf_s(fWrite,L"-------------------\n");
		fwprintf_s(fWrite,L"--- LOG CONTENT ---\n");
		fwprintf_s(fWrite,L"-------------------\n");

		//write content into res
		while( !feof( fRead ) )
		{
			if( fgetws( line, REPORT_WIDTH+1, fRead ) == NULL)
			{
				break;
			}
			fwprintf_s(fWrite,L"%ls", line);
		}

		//close main
		if(0 != fclose(fRead))
		{
			//LOG_ERRORCODE(L"Failed to close the file",errno);
		}
		fRead=NULL;
	}

	//close FinalReport
	if(0 != fclose(fWrite))
	{
		//LOG_ERRORCODE(L"Failed to close the file",errno);
	}
	fWrite=NULL;


	return iReturnCode;
}

////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// PRIVATE FUNCTIONS ////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
FILE *getFile(Report_TYPE type)
{
	if(type!=REPORT_TYPE_MAIN && type!=REPORT_TYPE_COMPLEMENT && type!=REPORT_TYPE_RESULT)
	{
		return NULL;	
	}

	if(g_pfile_level1 == NULL || g_pfile_level2 == NULL || g_pfile_level3 == NULL)
		reportLoadResources();

	switch(type)
	{
	case REPORT_TYPE_RESULT:
		return g_pfile_level1;
	case REPORT_TYPE_MAIN:
		return g_pfile_level2;
	case REPORT_TYPE_COMPLEMENT:
		return g_pfile_level3;
	default:
		return NULL;
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////
int reportPrintFileSeparator(Report_TYPE type)
{
	int iReturnCode=DIAGLIB_OK;

	if(DIAGLIB_OK != (iReturnCode=reportPrintLine(type, L"",L'<', 0))) return iReturnCode;
	if(DIAGLIB_OK != (iReturnCode=reportPrintLine(type, L"",L'>', 0))) return iReturnCode;

	return iReturnCode;
}