MiniLog.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: MiniLog.cpp ///////////////////////////////////////////////////////////
  24. // Alternative logging
  25. // Author: Matthew D. Campbell, January 2003
  26. ////////////////////////////////////////////////////////////////////////////////
  27. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  28. #include "Common/MiniLog.h"
  29. #ifdef DEBUG_LOGGING
  30. LogClass::LogClass(const char *fname)
  31. {
  32. char buffer[ _MAX_PATH ];
  33. GetModuleFileName( NULL, buffer, sizeof( buffer ) );
  34. char *pEnd = buffer + strlen( buffer );
  35. while( pEnd != buffer )
  36. {
  37. if( *pEnd == '\\' )
  38. {
  39. *pEnd = 0;
  40. break;
  41. }
  42. pEnd--;
  43. }
  44. AsciiString fullPath;
  45. fullPath.format("%s\\%s", buffer, fname);
  46. m_fp = fopen(fullPath.str(), "wt");
  47. }
  48. LogClass::~LogClass()
  49. {
  50. if (m_fp)
  51. {
  52. fclose(m_fp);
  53. }
  54. }
  55. void LogClass::log(const char *fmt, ...)
  56. {
  57. static char buf[1024];
  58. static Int lastFrame = 0;
  59. static Int lastIndex = 0;
  60. if (lastFrame != TheGameLogic->getFrame())
  61. {
  62. lastFrame = TheGameLogic->getFrame();
  63. lastIndex = 0;
  64. }
  65. va_list va;
  66. va_start( va, fmt );
  67. _vsnprintf(buf, 1024, fmt, va );
  68. buf[1023] = 0;
  69. va_end( va );
  70. char *tmp = buf;
  71. while (tmp && *tmp)
  72. {
  73. if (*tmp == '\r' || *tmp == '\n')
  74. {
  75. *tmp = ' ';
  76. }
  77. ++tmp;
  78. }
  79. fprintf(m_fp, "%d:%d %s\n", lastFrame, lastIndex++, buf);
  80. fflush(m_fp);
  81. }
  82. #endif // DEBUG_LOGGING