internal_io.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. /////////////////////////////////////////////////////////////////////////EA-V1
  19. // $File: //depot/GeneralsMD/Staging/code/Libraries/Source/debug/internal_io.h $
  20. // $Author: mhoffe $
  21. // $Revision: #1 $
  22. // $DateTime: 2003/07/03 11:55:26 $
  23. //
  24. // ©2003 Electronic Arts
  25. //
  26. // Internal header: I/O classes
  27. //////////////////////////////////////////////////////////////////////////////
  28. #ifdef _MSC_VER
  29. # pragma once
  30. #endif
  31. #ifndef INTERNAL_IO_H // Include guard
  32. #define INTERNAL_IO_H
  33. /// \internal \brief con debug I/O class
  34. class DebugIOCon: public DebugIOInterface
  35. {
  36. /**
  37. true if we allocated the console, false if there has already
  38. been a console
  39. */
  40. bool m_allocatedConsole;
  41. /**
  42. internal input buffer
  43. */
  44. char m_input[256];
  45. /**
  46. number of bytes in input buffer
  47. */
  48. unsigned m_inputUsed;
  49. /**
  50. Current read position. This variable is 0 while data is
  51. composed into m_input and >0 while multiple Read calls are
  52. received.
  53. */
  54. unsigned m_inputRead;
  55. public:
  56. explicit DebugIOCon(void);
  57. virtual ~DebugIOCon();
  58. virtual int Read(char *buf, int maxchar);
  59. virtual void Write(StringType type, const char *src, const char *str);
  60. virtual void EmergencyFlush(void) {}
  61. virtual void Execute(class Debug& dbg, const char *cmd, bool structuredCmd,
  62. unsigned argn, const char * const * argv);
  63. static DebugIOInterface *Create(void);
  64. virtual void Delete(void);
  65. };
  66. /// \internal \brief con flat I/O class
  67. class DebugIOFlat: public DebugIOInterface
  68. {
  69. /// \brief single output stream
  70. class OutputStream
  71. {
  72. OutputStream(const OutputStream&);
  73. OutputStream& operator=(const OutputStream&);
  74. /// output file name (dynamically allocated)
  75. char *m_fileName;
  76. /// output file handle (only if unlimited output buffer size)
  77. HANDLE m_fileHandle;
  78. /// file size limited?
  79. bool m_limitedFileSize;
  80. /// output buffer
  81. char *m_buffer;
  82. /// number of bytes in buffer
  83. unsigned m_bufferUsed;
  84. /// size of buffer (if m_limitedFileSize then m_bufferSize==m_maxSize)
  85. unsigned m_bufferSize;
  86. /// position of next free char in ring buffer (used if m_limitedFileSize)
  87. unsigned m_nextChar;
  88. // these are private so that we are forced to use Create/Destroy
  89. OutputStream(const char *filename, unsigned maxSize);
  90. ~OutputStream();
  91. /**
  92. \brief Writes some data to output stream.
  93. \param src string to write
  94. \param len number of bytes to write
  95. */
  96. void InternalWrite(const char *src, unsigned len);
  97. public:
  98. /**
  99. \brief Creates a new output stream instance.
  100. \param filename name of output file (will be overwritten if it exists)
  101. \param maxSize maximum size of output file, unlimited if 0
  102. */
  103. static OutputStream *Create(const char *filename, unsigned maxSize);
  104. /**
  105. \brief Destroys this object.
  106. If a path is given the file is copied to that path as well. If there
  107. is already a file with that name in the destination directory the
  108. current file is copied under a new unique name.
  109. \param path optional path to a destination directory
  110. */
  111. void Delete(const char *path=NULL);
  112. /**
  113. \brief Determines name of output stream.
  114. \return name of output stream
  115. */
  116. const char *GetFilename(void) { return m_fileName; }
  117. /**
  118. \brief Writes data to the output stream.
  119. \param src NUL delimited string to write
  120. */
  121. void Write(const char *src);
  122. /**
  123. \brief Flushes all buffered data.
  124. */
  125. void Flush(void);
  126. };
  127. /// \brief a single split structure
  128. struct SplitListEntry
  129. {
  130. /// next split
  131. SplitListEntry *next;
  132. /// for which string types?
  133. unsigned stringTypes;
  134. /// for which items?
  135. char items[256];
  136. /// split name
  137. char name[256];
  138. /// into which stream? (note: pointer not owned by this!)
  139. OutputStream *stream;
  140. };
  141. /// \brief List of output streams
  142. struct StreamListEntry
  143. {
  144. /// next entry
  145. StreamListEntry *next;
  146. /// which stream?
  147. OutputStream *stream;
  148. };
  149. /// first split
  150. SplitListEntry *m_firstSplit;
  151. /// end of split list pointer
  152. SplitListEntry **m_lastSplitPtr;
  153. /// first output stream (first is always the default output stream)
  154. StreamListEntry *m_firstStream;
  155. /// end of stream list pointer
  156. StreamListEntry **m_lastStreamPtr;
  157. /// base filename
  158. char m_baseFilename[256];
  159. /// copy location
  160. char m_copyDir[256];
  161. /**
  162. \brief Expands a magic filename into a real filename.
  163. \param src magic filename or real filename
  164. \param splitName split name, NULL for default stream
  165. \param buf output buffer, must have a size of at least 256 char's
  166. */
  167. static void ExpandMagic(const char *src, const char *splitName, char *buf);
  168. public:
  169. explicit DebugIOFlat(void);
  170. virtual ~DebugIOFlat();
  171. virtual int Read(char *buf, int maxchar) { return 0; }
  172. virtual void Write(StringType type, const char *src, const char *str);
  173. virtual void EmergencyFlush(void);
  174. virtual void Execute(class Debug& dbg, const char *cmd, bool structuredCmd,
  175. unsigned argn, const char * const * argv);
  176. static DebugIOInterface *Create(void);
  177. virtual void Delete(void);
  178. };
  179. /// \internal \brief net debug I/O class
  180. class DebugIONet: public DebugIOInterface
  181. {
  182. /// our pipe handle
  183. HANDLE m_pipe;
  184. public:
  185. explicit DebugIONet(void);
  186. virtual ~DebugIONet();
  187. virtual int Read(char *buf, int maxchar);
  188. virtual void Write(StringType type, const char *src, const char *str);
  189. virtual void EmergencyFlush(void);
  190. virtual void Execute(class Debug& dbg, const char *cmd, bool structuredCmd,
  191. unsigned argn, const char * const * argv);
  192. static DebugIOInterface *Create(void);
  193. virtual void Delete(void);
  194. };
  195. /// \internal \brief ods debug I/O class
  196. class DebugIOOds: public DebugIOInterface
  197. {
  198. public:
  199. explicit DebugIOOds(void) {}
  200. virtual int Read(char *buf, int maxchar) { return 0; }
  201. virtual void Write(StringType type, const char *src, const char *str);
  202. virtual void EmergencyFlush(void) {}
  203. virtual void Execute(class Debug& dbg, const char *cmd, bool structuredCmd,
  204. unsigned argn, const char * const * argv) {}
  205. static DebugIOInterface *Create(void);
  206. virtual void Delete(void);
  207. };
  208. #endif // INTERNAL_IO_H