Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: buffer.cxx
  7. //
  8. // Contents: An ASCII text-buffer for outputting to a debug stream
  9. //
  10. // Classes: CTextBufferA
  11. //
  12. // History: 11-Jul-95 t-stevan Created
  13. //
  14. //
  15. //----------------------------------------------------------------------------
  16. #include <windows.h>
  17. #include "buffer.hxx"
  18. // *** CTextBufferA ***
  19. //+-------------------------------------------------------------------------
  20. //
  21. // Member: CTextBufferA::operator<< (const char *)
  22. //
  23. // Synopsis: String Insertion operator
  24. //
  25. // Arguments: [pStr] - string to insert into stream
  26. //
  27. // Returns: reference to this stream
  28. //
  29. // Algorithm: inserts pStr into buffer, if not enough room, flushes buffer
  30. //
  31. // History: 11-Jul-95 t-stevan Created
  32. //
  33. //--------------------------------------------------------------------------
  34. CTextBufferA &CTextBufferA::operator<<(const char *pStr)
  35. {
  36. char *pszEnd;
  37. pszEnd = m_szBuffer+cBufferSize;
  38. // copy until we hit a null byte, flushing the buffer as we go if we fill up
  39. while((*m_pszPos++ = *pStr++) != '\0')
  40. {
  41. if(m_pszPos == pszEnd)
  42. {
  43. Flush(); // resets m_pszPos
  44. }
  45. }
  46. // we subtract one from m_pszPos because we don't want the null byte
  47. // to be printed out!
  48. m_pszPos--;
  49. return *this;
  50. }
  51. //+-------------------------------------------------------------------------
  52. //
  53. // Member: CTextBufferA::Insert
  54. //
  55. // Synopsis: Counted String Insertion operator
  56. //
  57. // Arguments: [pStr] - string to insert into stream
  58. // [nCount] - number of characters to insert into stream
  59. //
  60. //
  61. // Algorithm: inserts pStr into buffer, if not enough room, flushes buffer
  62. //
  63. // History: 11-Jul-95 t-stevan Created
  64. //
  65. //--------------------------------------------------------------------------
  66. void CTextBufferA::Insert(const char *pStr, size_t nCount)
  67. {
  68. char *pszEnd;
  69. pszEnd = m_szBuffer+cBufferSize;
  70. // copy until we hit a null byte, flushing the buffer as we go if we fill up
  71. while(nCount > 0)
  72. {
  73. *m_pszPos++ = *pStr++;
  74. nCount--;
  75. if(m_pszPos == pszEnd)
  76. {
  77. Flush(); // resets m_pszPos
  78. }
  79. }
  80. }
  81. //+-------------------------------------------------------------------------
  82. //
  83. // Member: CTextBufferA::Revert
  84. //
  85. // Synopsis: Revert to a previous state of the buffer, if there have
  86. // been no flushes since then
  87. //
  88. // Arguments: [bc] - a buffer context to retrieve the previous state from
  89. //
  90. // History: 11-Jul-95 t-stevan Created
  91. //
  92. //--------------------------------------------------------------------------
  93. BOOL CTextBufferA::Revert(const BufferContext &bc)
  94. {
  95. if(bc.wRef == m_wFlushes)
  96. {
  97. // we haven't flushed since this snapshot, we can revert
  98. if(((char *) bc.dwContext) < m_szBuffer || ((char *) bc.dwContext) >= (m_szBuffer+cBufferSize))
  99. {
  100. return FALSE; // still can't revert, because the pointer is not correct!
  101. }
  102. m_pszPos = (char *) bc.dwContext;
  103. *(m_pszPos+1) = '\0';
  104. return TRUE;
  105. }
  106. return FALSE;
  107. }