/* Copyright (c) 2002-2012 Croteam Ltd. All rights reserved. */ #include "stdh.h" #include #include #include #include #include #include #include #include extern CConsole *_pConsole = NULL; extern INDEX con_iLastLines; extern BOOL con_bCapture = FALSE; extern CTString con_strCapture = ""; // Constructor. CConsole::CConsole(void) { con_strBuffer = NULL; con_strLineBuffer = NULL; con_atmLines = NULL; con_fLog = NULL; } // Destructor. CConsole::~CConsole(void) { if (this==NULL) { return; } 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) { if (this==NULL) { return; } 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(); }