OLOG.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. // Filename : OLOG.CPP
  21. // Description : logging class
  22. // Owner : Gilbert
  23. #include <OLOG.h>
  24. #include <stdio.h>
  25. #include <OFILE.h>
  26. // -------- begin of function Log::Log ----------//
  27. Log::Log()
  28. {
  29. }
  30. // -------- end of function Log::Log ----------//
  31. Log::~Log()
  32. {
  33. }
  34. // -------- begin of function Log::mark_begin ----------//
  35. void Log::mark_begin()
  36. {
  37. // text_buffer[0] stores the latest log
  38. text_buffer[0].clear();
  39. *(text_buffer[0].reserve(sizeof(char))) = '\0'; // put a null character in the buffer
  40. }
  41. // -------- end of function Log::mark_begin ----------//
  42. // -------- begin of function Log::mark_end ----------//
  43. void Log::mark_end()
  44. {
  45. // enable next line to trace hang
  46. // dump();
  47. // rotate buffers
  48. text_buffer[LOG_VERSION-1].clear();
  49. *(text_buffer[LOG_VERSION-1].reserve(sizeof(char))) = '\0'; // put a null character in the buffer
  50. for(int n = LOG_VERSION-1; n > 0; --n)
  51. {
  52. text_buffer[n].swap(text_buffer[n-1]);
  53. }
  54. }
  55. // -------- end of function Log::mark_end ----------//
  56. // -------- begin of function Log::mark ----------//
  57. void Log::mark(char *msg, char *file, int line)
  58. {
  59. log_text = msg;
  60. log_file = file;
  61. log_line = line;
  62. String t(log_text);
  63. t += "\r\n";
  64. strcpy( text_buffer[0].reserve(t.len())-1, t ); // minus 1 to remove the '\0' at the end
  65. }
  66. // -------- end of function Log::mark ----------//
  67. // -------- begin of function Log::mark ----------//
  68. void Log::mark(int n , char *file, int line)
  69. {
  70. log_text = n;
  71. log_file = file;
  72. log_line = line;
  73. String t(log_text);
  74. t += "\r\n";
  75. strcpy( text_buffer[0].reserve(t.len())-1, t );
  76. }
  77. // -------- end of function Log::mark ----------//
  78. // -------- begin of function Log::dump ----------//
  79. void Log::dump()
  80. {
  81. // write old_buffer
  82. char filename[20];
  83. strcpy(filename, "AM_A.LOG");
  84. File f;
  85. for(int n = LOG_VERSION-1; n >= 0; --n, filename[3]++) // AM_A.LOG, AM_B.LOG ...
  86. {
  87. f.file_create(filename);
  88. f.file_write( text_buffer[n].queue_buf, text_buffer[n].length() );
  89. f.file_close();
  90. }
  91. }
  92. // -------- end of function Log::dump ----------//
  93. // -------- begin of function Log::debug_log ----------//
  94. void Log::debug_log(char *msg)
  95. {
  96. String s;
  97. s = msg;
  98. s += "\r\n";
  99. OutputDebugString(s);
  100. }
  101. void Log::debug_log(int n)
  102. {
  103. String s;
  104. s = n;
  105. s += "\r\n";
  106. OutputDebugString(s);
  107. }
  108. // -------- end of function Log::debug_log ----------//