Leaked source code of windows server 2003
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.

176 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 1991-1999 Microsoft Corporation
  3. Module Name:
  4. buffer.cxx
  5. Abstract:
  6. MIDL Compiler Buffer Manager Definition
  7. This class manages a collection of pre-allocated strings.
  8. Author:
  9. Donna Liu (donnali) 09-Nov-1990
  10. Revision History:
  11. 26-Feb-1992 donnali
  12. Moved toward NT coding style.
  13. --*/
  14. #pragma warning ( disable : 4514 4710 )
  15. #include "nulldefs.h"
  16. extern "C" {
  17. #include <stdio.h>
  18. #include <malloc.h>
  19. #include <string.h>
  20. }
  21. #include "buffer.hxx"
  22. #ifdef gaj_debug_buf
  23. extern void midl_debug (char *);
  24. #else
  25. #define midl_debug(s)
  26. #endif
  27. BufferManager::BufferManager(
  28. unsigned short usBufferSize
  29. )
  30. /*++
  31. Routine Description:
  32. This method constructs a BufferManager object.
  33. Arguments:
  34. usBufferSize - Supplies the size of each managed buffer.
  35. --*/
  36. {
  37. char ** pTemp = new (char *[usBufferSize]);
  38. usBufSize = usBufferSize;
  39. usTabSize = 0;
  40. pszTable = (char **)0;
  41. pHead = pTail = pSave = new BufferElement(
  42. NULL,
  43. NULL,
  44. pTemp);
  45. iHead = iTail = unsigned short(usBufSize - 2);
  46. }
  47. BufferManager::BufferManager(
  48. unsigned short usBufferSize,
  49. unsigned short usTableSize,
  50. const char * aStringTable[]
  51. )
  52. /*++
  53. Routine Description:
  54. This method constructs a BufferManager object.
  55. Arguments:
  56. usBufferSize - Supplies the size of each managed buffer.
  57. usTableSize - Supplies the size of the table containing string
  58. constants.
  59. aStringTable - Supplies the table containing string constants.
  60. --*/
  61. {
  62. char ** pTemp = new (char *[usBufferSize]);
  63. usBufSize = usBufferSize;
  64. usTabSize = usTableSize;
  65. pszTable = (char**) aStringTable;
  66. pHead = pTail = pSave = new BufferElement(
  67. NULL,
  68. NULL,
  69. pTemp);
  70. iHead = iTail = unsigned short(usBufSize - 2);
  71. }
  72. void BufferManager::Print(
  73. ISTREAM * pStream
  74. )
  75. /*++
  76. Routine Description:
  77. This method prints all the strings managed by a BufferManager
  78. to a file.
  79. Arguments:
  80. pStream - Supplies the output file handle.
  81. --*/
  82. {
  83. unsigned short usCount;
  84. BufferElement * pTemp;
  85. char BigBuffer[1000];
  86. char * pBigBufferNext;
  87. if (pHead == pTail)
  88. {
  89. pBigBufferNext = &BigBuffer[0];
  90. *pBigBufferNext = '\0';
  91. for (usCount = iHead ; usCount < iTail ; usCount++)
  92. {
  93. strcpy( pBigBufferNext, pHead->pBuffer[usCount] );
  94. pBigBufferNext += strlen( pBigBufferNext );
  95. }
  96. pStream->Write( BigBuffer );
  97. }
  98. else
  99. {
  100. pBigBufferNext = &BigBuffer[0];
  101. *pBigBufferNext = '\0';
  102. for (usCount = iHead ; usCount < usBufSize ; usCount++)
  103. {
  104. strcpy( pBigBufferNext, pHead->pBuffer[usCount] );
  105. pBigBufferNext += strlen( pBigBufferNext );
  106. }
  107. pStream->Write( BigBuffer );
  108. for (pTemp = pHead->GetNext() ;
  109. pTemp != pTail ;
  110. pTemp = pTemp->GetNext())
  111. {
  112. pBigBufferNext = &BigBuffer[0];
  113. *pBigBufferNext = '\0';
  114. for (usCount = 0 ; usCount < usBufSize ; usCount++)
  115. {
  116. strcpy( pBigBufferNext, pTemp->pBuffer[usCount] );
  117. pBigBufferNext += strlen( pBigBufferNext );
  118. }
  119. pStream->Write( BigBuffer );
  120. }
  121. pBigBufferNext = &BigBuffer[0];
  122. *pBigBufferNext = '\0';
  123. for (usCount = 0 ; usCount < iTail ; usCount++)
  124. {
  125. strcpy( pBigBufferNext, pTail->pBuffer[usCount] );
  126. pBigBufferNext += strlen( pBigBufferNext );
  127. }
  128. pStream->Write( BigBuffer );
  129. }
  130. Clear();
  131. }