DPrint.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. ** Command & Conquer Renegade(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. * FILE
  21. * DPrint.cpp
  22. *
  23. * DESCRIPTION
  24. * Debug printing mechanism
  25. *
  26. * PROGRAMMER
  27. * Denzil E. Long, Jr.
  28. *
  29. * VERSION INFO
  30. * $Author: Byon_g $
  31. * $Revision: 2 $
  32. * $Modtime: 2/13/01 11:02a $
  33. * $Archive: /Commando/Code/Scripts/DPrint.cpp $
  34. *
  35. ****************************************************************************/
  36. #ifdef _DEBUG
  37. #include "dprint.h"
  38. #include <windows.h>
  39. #include <stdio.h>
  40. #include <stdarg.h>
  41. #include <assert.h>
  42. #include "scriptcommands.h"
  43. extern ScriptCommands* Commands;
  44. #define LOGFILE_NAME "ScriptLog"
  45. /****************************************************************************
  46. *
  47. * NAME
  48. * DPrint(String, ArgList...)
  49. *
  50. * DESCRIPTION
  51. * Ouput debug print messages to the debugger and log file.
  52. *
  53. * INPUTS
  54. * String - String to output.
  55. * ArgList - Argument list
  56. *
  57. * RESULT
  58. * NONE
  59. *
  60. ****************************************************************************/
  61. void __cdecl DebugPrint(const char* string, ...)
  62. {
  63. static char _buffer[1024];
  64. static char _filename[512] = "";
  65. if (string != NULL)
  66. {
  67. va_list va;
  68. // Format string
  69. va_start(va, string);
  70. vsprintf(&_buffer[0], string, va);
  71. va_end(va);
  72. if (Commands != NULL)
  73. {
  74. // Send string to commando executable
  75. Commands->Debug_Message(_buffer);
  76. }
  77. else
  78. {
  79. // Send string to debugger
  80. OutputDebugString(_buffer);
  81. }
  82. #if 0
  83. HANDLE file = INVALID_HANDLE_VALUE;
  84. // Open log file
  85. if (strlen(_filename) == 0)
  86. {
  87. char path[_MAX_PATH];
  88. char drive[_MAX_DRIVE];
  89. char dir[_MAX_DIR];
  90. GetModuleFileName(GetModuleHandle(NULL), &path[0], sizeof(path));
  91. _splitpath(path, drive, dir, NULL, NULL);
  92. _makepath(_filename, drive, dir, LOGFILE_NAME, "txt");
  93. file = CreateFile(_filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
  94. FILE_ATTRIBUTE_NORMAL, NULL);
  95. }
  96. else
  97. {
  98. file = CreateFile(_filename, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
  99. FILE_ATTRIBUTE_NORMAL, NULL);
  100. }
  101. // Insert carriage return after newlines
  102. int i = 0;
  103. while (_buffer[i] != '\0')
  104. {
  105. if (_buffer[i] == '\n')
  106. {
  107. int end = strlen(_buffer);
  108. assert((end + 1) <= sizeof(_buffer));
  109. while (end >= i)
  110. {
  111. _buffer[end + 1] = _buffer[end];
  112. end--;
  113. }
  114. _buffer[i] = '\r';
  115. i++;
  116. }
  117. i++;
  118. }
  119. // Send string to log file
  120. if (file != INVALID_HANDLE_VALUE)
  121. {
  122. DWORD written;
  123. SetFilePointer(file, 0, NULL, FILE_END);
  124. WriteFile(file, &_buffer[0], strlen(_buffer), &written, NULL);
  125. CloseHandle(file);
  126. }
  127. #endif
  128. }
  129. }
  130. #endif // _DEBUG