// last modified Thursday, May 08, 2003 #include "precompiled.h" #if 0 #include "LogFile.h" #include "lib.h" #include //------------------------------------------------- //Add a hyperlink to Link. //------------------------------------------------- PS_RESULT CLogFile::AddLink(string LinkText,string Link, string Colour) { if(m_IsFileOpen) { m_TheFile << "" << LinkText << "
"; } else { return PS_FAIL; } return PS_OK; } //------------------------------------------------- //Standard destructor. //------------------------------------------------- CLogFile::~CLogFile() { if(m_IsFileOpen) { m_TheFile << ""; m_TheFile.close(); if(m_HasFrame) { m_ErrorFile.close(); } m_IsFileOpen = false; } } //------------------------------------------------- //Standard constructor. //------------------------------------------------- CLogFile::CLogFile() { m_CurrentColour = "Black"; m_IsFileOpen = false; } //------------------------------------------------- // Constructor that opens a file. // 3rd parameter determines whether the error frame is shown. //------------------------------------------------- CLogFile::CLogFile(string FileName, string PageTitle, bool WithFrame) { Open(FileName,PageTitle,WithFrame); m_IsFileOpen = true; } //------------------------------------------------- //Closes the open files, if open. //------------------------------------------------- PS_RESULT CLogFile::Close() { if(m_IsFileOpen) { m_CurrentColour = "Black"; m_TheFile << ""; m_TheFile.close(); if(m_HasFrame) { m_ErrorFile.close(); } m_IsFileOpen = false; } else { return PS_FAIL; } return PS_OK; } //------------------------------------------------- //Inserts a horzontal divide in the page. //------------------------------------------------- PS_RESULT CLogFile::InsertDivide() { if(m_IsFileOpen) { m_TheFile << "
"; } else { return PS_FAIL; } return PS_OK; } //------------------------------------------------- //Opens an error file. If WithFrame is true then it constructs a framed page. //------------------------------------------------- PS_RESULT CLogFile::Open(string FileName, string PageTitle, bool WithFrame) { if(m_IsFileOpen) return PS_FAIL; m_HasFrame=false; m_CurrentColour = "Black"; //If there are no frames then create a normal page. if(!WithFrame) { FileName = FileName + ".html"; m_TheFile.open(FileName.c_str()); m_TheFile << "" << PageTitle << ""; } else { //Open a temporary file to write the frameset. ofstream TempStream; string TempString; TempString = FileName; TempString = FileName + ".html"; TempStream.open(TempString.c_str()); FileName = FileName + "b.html"; //Write the proper details to the frame file. TempStream << "" << PageTitle << ""; TempStream << ""; TempStream << ""; TempStream << ""; TempStream.close(); //Open the two pages to be displayed within the frames. m_TheFile.open(FileName.c_str()); m_ErrorFile.open("ErrorLinks.html"); m_FileName = FileName.c_str(); //Start writing the two pages that will be displayed. m_TheFile << "" << PageTitle << ""; m_ErrorFile << "" << PageTitle << ""; m_HasFrame = true; m_ErrNo = 0; } m_IsFileOpen = true; return PS_OK; } //------------------------------------------------- //Sets the current alignment. //------------------------------------------------- PS_RESULT CLogFile::SetAlignment(PS_TEXT_ALIGN Align) { if(m_IsFileOpen) { switch(Align){ case PS_ALIGN_LEFT: m_TheFile << "

"; break; case PS_ALIGN_CENTER: m_TheFile << "

"; break; case PS_ALIGN_RIGHT: m_TheFile << "

"; break; } } else { return PS_FAIL; } return PS_OK; } //------------------------------------------------- //Changes the current colour. //------------------------------------------------- PS_RESULT CLogFile::SetColour(string ColourName) { if(m_IsFileOpen) { m_CurrentColour = ColourName; m_TheFile << ""; } else { return PS_FAIL; } return PS_OK; } //------------------------------------------------- //Writes an error, always in red. //------------------------------------------------- PS_RESULT CLogFile::WriteError(string Text, PS_DISPLAY_SETTINGS displayOptions) { if(m_IsFileOpen) { //If there is a frame then add an anchor and link to the appropriate places. if(m_HasFrame) { m_TheFile << ""; m_ErrorFile << "Error: " << m_ErrNo << "
"; m_ErrNo++; } m_TheFile << "
" << Line(displayOptions) << Text << Date(displayOptions) << "
"; } else { return PS_FAIL; } return PS_OK; } PS_RESULT CLogFile::WriteError(string Text, PS_TEXT_ALIGN Align, PS_DISPLAY_SETTINGS displayOptions) { if(m_IsFileOpen) { SetAlignment(Align); //If there is a frame then add an anchor and link to the appropriate places. if(m_HasFrame) { m_TheFile << ""; m_ErrorFile << "Error: " << m_ErrNo << "
"; m_ErrNo++; } m_TheFile << "
" << Line(displayOptions) << Text << Date(displayOptions) << "


"; } else { return PS_FAIL; } return PS_OK; } //------------------------------------------------- //Writes a header in larger text. //------------------------------------------------- PS_RESULT CLogFile::WriteHeader(string Text, PS_DISPLAY_SETTINGS displayOptions) { if(m_IsFileOpen) { m_TheFile << "
" << Line(displayOptions) << Text << Date(displayOptions) << "
"; } else { return PS_FAIL; } return PS_OK; } //------------------------------------------------- //Writes a header in larger text, with alignment. //------------------------------------------------- PS_RESULT CLogFile::WriteHeader(string Text, PS_TEXT_ALIGN Align, PS_DISPLAY_SETTINGS displayOptions) { if(m_IsFileOpen) { SetAlignment(Align); m_TheFile << "
" << Line(displayOptions) << Text << Date(displayOptions) << "


"; } else { return PS_FAIL; } return PS_OK; } //------------------------------------------------- //Write a normal string. //------------------------------------------------- PS_RESULT CLogFile::WriteText(string Text, PS_DISPLAY_SETTINGS displayOptions) { if(m_IsFileOpen) { m_TheFile << Line(displayOptions) << Text << Date(displayOptions) << "
"; } else { return PS_FAIL; } return PS_OK; } //------------------------------------------------- //Write a normal string, with alignment. //------------------------------------------------- PS_RESULT CLogFile::WriteText(string Text, PS_TEXT_ALIGN Align, PS_DISPLAY_SETTINGS displayOptions) { if(m_IsFileOpen) { SetAlignment(Align); m_TheFile << Line(displayOptions) << Text << Date(displayOptions) << "


"; } else { return PS_FAIL; } return PS_OK; } //------------------------------------------------- //Retrieve a string to display the line number //------------------------------------------------- string CLogFile::Line(const PS_DISPLAY_SETTINGS &options) { string lineText; if (options.displayMode == PS_DISPLAY_MODE_SHOW_LINE_NUMBER ) { lineText = options.file; // jw: replaced _itoa. sprintf would be good here :P std::string str_line; std::stringstream ss; ss << options.line; ss >> str_line; lineText += ", Line "; lineText += str_line; lineText += ": "; } return lineText; } //------------------------------------------------- //Retrieve a string to display the date //------------------------------------------------- string CLogFile::Date(const PS_DISPLAY_SETTINGS &options) { string dateText; if (options.displayMode == PS_DISPLAY_MODE_SHOW_DATE ) { dateText = "   ("; dateText += options.date; dateText += ")"; } return dateText; } #endif