📄 errprintfile_h.h
字号:
//---------------------------------------------------------------------------
//-------- ErrPrintFile_H.h -------------------------------------------------
//---------------------------------------------------------------------------
#ifndef ErrPrintFile_H.h // 防止被重复引用
#define ErrPrintFile_H.h
//---------------------------------------------------------------------------
#include "JsGlobal_H.h"
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// "错误输出文件"管理器。(收集和打印错误信息。)
// 这里的"文件"不一定就是磁盘文件,也可以是stdout,即屏幕。
//---------------------------------------------------------------------------
class ErrPrintFile
{
private:
Jstring FileName; // 文件名,可以是空(NULL)。空为默认值,代表stdout。
FILE* FilePt; // 默认值为stdout。
public:
ErrPrintFile():FilePt(stdout) {} // constructor
~ErrPrintFile() {} // destructor
// -------- public functions ---------
void SetEPfile(ERR &err, const Jstring& fname);
FILE* GetEPfile() { return FilePt; } // end GetEPfile
bool Open(); // 打开"文件"。
void Close(); // 关闭"文件"。
void Suicide(); // 删除"文件"。
bool IsEPScreen()const { return (FilePt == stdout); } // end IsEPScreen
}; // end class ErrPrintFile
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// 打开文件。注意,FileName不能为空。它改变了FilePt。
//---------------------------------------------------------------------------
inline bool ErrPrintFile::Open()
{ FilePt = fopen(FileName(), "w");
if(FilePt == NULL) { printf("\nOpen file %s error.", FileName()); } // endif
return (bool)FilePt; // <==> FilePt!=NULL为true, FilePt==NULL为false.
} // end Open
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// 关闭"文件"。
//---------------------------------------------------------------------------
inline void ErrPrintFile::Close()
{ if(fclose(FilePt) && FilePt != NULL)
{ printf("\nClose file %s error.", FileName()); } // endif
else
{ DebugMsg(printf("\nErrors have been written to %s.",FileName());) } // end else
} // end Close
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// 注意这里err:如果fname为空串或者没有发生错误,err的值并没有改变。
// 所以调用前,err应该是OK_no_Err。
// FileName内容受影响。
//---------------------------------------------------------------------------
inline void ErrPrintFile::SetEPfile(ERR &err, const Jstring& fname)
{ if( fname.IsNotEmpty() )
{ FileName = fname; // 磁盘文件名。
if( !Open() ) { err = Have_Errs; } // endif
if(FilePt == NULL) { FilePt = stdout; } // endif
} // endif
// else do nothing.
} // end SetEPfile
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
inline void ErrPrintFile::Suicide()
{ remove(FileName());
} // end Suicide
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
// Written by JamesyFront. ZLGmcu Dev.Co.Ltd. 2002.
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -