mydebug.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. #include <stdlib.h>
  19. #include "mydebug.h"
  20. #include "streamer.h"
  21. #include "odevice.h"
  22. // static MyMsgManager *msg_manager=NULL;
  23. // static int paranoid_enabled=0;
  24. static ostream *paranoid_ostream=NULL;
  25. static Streamer paranoid_streamer;
  26. // Don't dare touch this semaphore in application code!
  27. #ifdef USE_SEM
  28. Sem4 MyDebugLibSemaphore;
  29. #else
  30. CritSec MyDebugLibSemaphore;
  31. #endif
  32. int MyMsgManager::setAllStreams(OutputDevice *device)
  33. {
  34. if (device==NULL)
  35. return(1);
  36. MYDEBUGLOCK;
  37. paranoid_streamer.setOutputDevice(device);
  38. delete(paranoid_ostream);
  39. paranoid_ostream=new ostream(&paranoid_streamer);
  40. MYDEBUGUNLOCK;
  41. return(0);
  42. }
  43. int MyMsgManager::setParanoidStream(OutputDevice *device)
  44. {
  45. if (device==NULL)
  46. return(1);
  47. MYDEBUGLOCK;
  48. paranoid_streamer.setOutputDevice(device);
  49. delete(paranoid_ostream);
  50. paranoid_ostream=new ostream(&paranoid_streamer);
  51. MYDEBUGUNLOCK;
  52. return(0);
  53. }
  54. ostream *MyMsgManager::paranoidStream(void)
  55. {
  56. return(paranoid_ostream);
  57. }
  58. int MyMsgManager::ReplaceAllStreams(FileD * output_device, char *device_filename, char *copy_filename)
  59. {
  60. MYDEBUGLOCK;
  61. delete(paranoid_ostream);
  62. if (output_device != NULL)
  63. {
  64. delete(output_device);
  65. output_device = NULL;
  66. }
  67. rename(device_filename, copy_filename);
  68. // FileD new_device(device_filename);
  69. output_device = new FileD(device_filename);
  70. paranoid_streamer.setOutputDevice(output_device);
  71. paranoid_ostream = new ostream(&paranoid_streamer);
  72. MYDEBUGUNLOCK;
  73. return(0);
  74. }