?? errorlog.cpp
字號:
#ifdef __BORLANDC__
#include <vcl.h>
#pragma hdrstop
#endif
#include "stdafx.h"
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys\types.h>
#include <sys\stat.h>
#include <string.h>
#include <io.h>
#ifdef __BORLANDC__
#include <io.h>
#include <fcntl.h>
#include <dos.h>
#include <dir.h>
#else
#define MAXPATH _MAX_PATH
#define MAXDRIVE _MAX_DRIVE
#define MAXDIR _MAX_DIR
#define MAXFILE _MAX_FNAME
#define MAXEXT _MAX_EXT
#define fnsplit _splitpath
#define fnmerge _makepath
#endif
#include "errorlog.h"
/*
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys\types.h>
#include <sys\stat.h>
#include <string.h>
#ifdef __BORLANDC__
#include <io.h>
#include <fcntl.h>
#include <dos.h>
#include <dir.h>
#else
#define MAXPATH _MAX_PATH
#define MAXDRIVE _MAX_DRIVE
#define MAXDIR _MAX_DIR
#define MAXFILE _MAX_FNAME
#define MAXEXT _MAX_EXT
#define fnsplit _splitpath
#define fnmerge _makepath
#endif
#include "errorlog.h"
*/
class TErrorlog
{
public:
TErrorlog();
char m_errorlog[1024];
};
TErrorlog::TErrorlog()
{
char temp[MAXPATH];
char drive[MAXDRIVE];
char dir[MAXDIR];
char file[MAXFILE];
char ext[MAXEXT];
#ifdef __BORLANDC__
int fh;
struct ftime f;
struct date d;
#else
time_t t;
struct tm tmlocal, f_tmlocal;
struct _stat buf;
#endif
#ifdef __BORLANDC__
fnsplit(Application->ExeName.c_str(), drive, dir, file, ext);
#else
// _splitpath(ppp, drive, dir, file, ext);
_splitpath(_pgmptr, drive, dir, file, ext); // ???????????
#endif
// strcat(dir, "..\\log\\");
strcat(dir, ".\\");
strcpy(ext, ".log");
#ifdef __BORLANDC__
fnmerge(m_errorlog, drive, dir, file, ext);
#else
_makepath(m_errorlog, drive, dir, file, ext);
#endif
if(_access(m_errorlog, 0) != 0)
return;
#ifdef __BORLANDC__
getdate(&d);
fh = ::open(m_errorlog, O_BINARY | O_RDONLY);
if(fh == -1)
return;
getftime(fh, &f);
close(fh);
if(((int)(f.ft_year + 1980) == (int)d.da_year)
&& ((int)f.ft_month == (int)d.da_mon)
&& ((int)f.ft_day == (int)d.da_day))
return;
sprintf(ext, ".%d", f.ft_day);
fnmerge(temp, drive, dir, file, ext);
#else
t = ::time(&t);
tmlocal = *(::localtime(&t));
_stat(m_errorlog, &buf);
f_tmlocal = *(::localtime(&(buf.st_ctime)));
if((f_tmlocal.tm_year == tmlocal.tm_year) && (f_tmlocal.tm_mon == tmlocal.tm_mon) && (f_tmlocal.tm_mday == tmlocal.tm_mday))
return;
sprintf(ext, ".%d", f_tmlocal.tm_mday);
_makepath(temp, drive, dir, file, ext);
#endif
unlink(temp);
rename(m_errorlog, temp);;
}
static TErrorlog errorlog;
const char * GetErrorLogFileName()
{
return errorlog.m_errorlog;
}
#ifdef __BORLANDC__
#pragma package(smart_init)
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -