/* Copyright (c) 2002-2012 Croteam Ltd. This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "Engine/StdH.h" #include #include #include #include #include #include #include #include CConsole *_pConsole = NULL; extern INDEX con_iLastLines; BOOL con_bCapture = FALSE; CTString con_strCapture = ""; // Constructor. CConsole::CConsole(void) { con_strBuffer = NULL; con_strLineBuffer = NULL; con_atmLines = NULL; con_fLog = NULL; } // Destructor. CConsole::~CConsole(void) { ASSERT(this!=NULL); if (con_fLog!=NULL) { fclose(con_fLog); con_fLog = NULL; } if (con_strBuffer!=NULL) { FreeMemory(con_strBuffer); } if (con_strLineBuffer!=NULL) { FreeMemory(con_strLineBuffer); } if (con_atmLines!=NULL) { FreeMemory(con_atmLines); } } // Initialize the console. void CConsole::Initialize(const CTFileName &fnmLog, INDEX ctCharsPerLine, INDEX ctLines) { con_csConsole.cs_iIndex = -1; // synchronize access to console CTSingleLock slConsole(&con_csConsole, TRUE); // allocate the buffer con_ctCharsPerLine = ctCharsPerLine; con_ctLines = ctLines; con_ctLinesPrinted = 0; // note: we add +1 for '\n' perline and +1 '\0' at the end of buffer con_strBuffer = (char *)AllocMemory((ctCharsPerLine+1)*ctLines+1); con_strLineBuffer = (char *)AllocMemory(ctCharsPerLine+2); // includes '\n' and '\0' con_atmLines = (TIME*)AllocMemory((ctLines+1)*sizeof(TIME)); // make it empty for(INDEX iLine=0; iLine=con_ctLinesPrinted) { return ""; } ASSERT(iLine>=0 && iLine=0 && iLineGetRealTimeTick():0.0f; } // scroll buffer up, discarding lines at the start void CConsole::ScrollBufferUp(INDEX ctLines) { ASSERT(this!=NULL); ASSERT(ctLines>0 && ctLinesPutString(strBuffer); } // Add a string of text to console void CPutString(const char *strString) { if (_pConsole==NULL) { return; } _pConsole->PutString(strString); } // Get number of lines newer than given time INDEX CON_NumberOfLinesAfter(TIME tmLast) { if (_pConsole==NULL) { return 0; } return _pConsole->NumberOfLinesAfter(tmLast); } // Get one of last lines CTString CON_GetLastLine(INDEX iLine) { if (_pConsole==NULL) { return ""; } return _pConsole->GetLastLine(iLine); } // Discard timing info for last lines void CON_DiscardLastLineTimes(void) { if (_pConsole==NULL) { return; } _pConsole->DiscardLastLineTimes(); } // Get current console buffer. const char *CON_GetBuffer(void) { if (_pConsole==NULL) { return ""; } return _pConsole->GetBuffer(); } INDEX CON_GetBufferSize(void) { if (_pConsole==NULL) { return 1; } return _pConsole->GetBufferSize(); }