// TermLog.cpp: implementation of the CTermLog class. // ////////////////////////////////////////////////////////////////////// #include "StdAfx.h" #include "TermLog.h" #include "EditEnter.h" #include "Resource.h" #include "MainDlg.h" #include #include #include #include #include #include #include using namespace std; #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CTermLog::CTermLog() { m_nMarkNumber = 0; m_nPauseSetOn = 0; m_bPauseOn = false; m_bLogBufferFull = false; } CTermLog::~CTermLog() { } /* The next two methods are used to add a command line to the log. If the log is full, one line is erased from the top of the log. */ void CTermLog::LogCommand(string p_sCommandLine) { string sLine=p_sCommandLine; if( m_bLogBufferFull ) { if( m_LogLines.size() > 0 ) m_LogLines.erase( m_LogLines.begin() ); } m_LogLines.push_back(sLine); } void CTermLog::LogResponse(string p_sResponseLine) { string sLine=p_sResponseLine; this->LogCommand(sLine); } /* Adds a command line. */ void CTermLog::SendCommand(string p_sCommandLine) { m_Commands.push_back(p_sCommandLine); } /* Adds a mark line to the log. */ void CTermLog::AddMark(int p_nLineNumber) { std::ostringstream oss; oss << m_nMarkNumber; m_LogLines.push_back("------------------- MARK "+ oss.str() + " ---------------"); m_nMarkNumber++; } /* Saves the log in a file. */ void CTermLog::SaveLog(string p_sFileName) const { try { ofstream FileOutput( p_sFileName.c_str() ); if ( !FileOutput ) return; int m=m_LogLines.size(); for ( int i=0; iDelete(); } } /* Saves the commands in a file. */ void CTermLog::SaveTerminal(string p_sFileName) const { try { ofstream FileOutput( p_sFileName.c_str() ); if ( !FileOutput ) { return; } for( int i=0; iDelete(); } } /* Open and read a command file to the commnands window */ void CTermLog::LoadCommandFile(string p_sCommandFile) { try{ string sLine; ifstream FileInput( p_sCommandFile.c_str() ); //Test whether file opens if ( !FileInput ) { return; } m_Commands.clear(); while ( getline(FileInput, sLine) ) { if ( sLine[0] == ';' ) continue; //if the line starts with ';', it's a comment line m_Commands.push_back(sLine); } FileInput.close(); } catch (CException* e) { e->Delete(); } } /* Pause the log */ void CTermLog::Pause() { SetPauseSetOn( m_LogLines.size() ); m_bPauseOn = true; } /* Unpause the log */ void CTermLog::Continue() { m_bPauseOn = false; } /* Get the last line of the log */ string CTermLog::GetLastLogLine() const { int n; n = m_LogLines.size()-1; return m_LogLines[n]; } /* Get the last line of the commands */ string CTermLog::GetLastCommandLine() const { int n; n = m_Commands.size()-1; return m_Commands[n]; } /* Empty the log */ void CTermLog::ClearLog() { m_LogLines.clear(); m_nMarkNumber = 0; }