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.

207 lines
5.0 KiB

  1. #include <assert.h>
  2. #include <iostream.h>
  3. #include "CoComp.Hxx"
  4. bool CompareBuffer( char* pBuff1, char* pBuff2, unsigned long nLen);
  5. void WriteLine(HANDLE file, char* pBuff, int nLen);
  6. extern unsigned long g_ulAppRetVal;
  7. CCompareCoClass::CCompareCoClass(char* pCurBuf, char* pRefBuf, HANDLE fileDiff, char* pszClassName )
  8. {
  9. _pCurBuf = pCurBuf;
  10. _pRefBuf = pRefBuf;
  11. _fileDiff = fileDiff;
  12. _pszClassName = pszClassName;
  13. _pCurList = new CAutoArray<LINEINFO>;
  14. _pRefList = new CAutoArray<LINEINFO>;
  15. CreateLineIndex(_pCurList, _pCurBuf);
  16. CreateLineIndex(_pRefList, _pRefBuf);
  17. _bFirstTime = true;
  18. }
  19. CCompareCoClass::~CCompareCoClass()
  20. {
  21. delete _pCurList;
  22. delete _pRefList;
  23. }
  24. void CCompareCoClass::FindAdditionsAndChanges()
  25. {
  26. long lIdx;
  27. long lTmp;
  28. LINEINFO lineCur;
  29. LINEINFO lineRef;
  30. char* szBuff = new char[128];
  31. //check for additions and alterations
  32. for ( lIdx = 0; lIdx< (int)_pCurList->Size(); lIdx++ )
  33. {
  34. _pCurList->GetAt( lIdx, &lineCur );
  35. for ( lTmp=0; lTmp<_pRefList->Size(); lTmp++ )
  36. {
  37. _pRefList->GetAt( lTmp, &lineRef );
  38. //compare the names of two methods to find if they are comparable
  39. //in respect to other aspects of their declarations.
  40. if (( !lineRef.fUsed ) &&
  41. ( CompareBuffer(&_pCurBuf[lineCur.ulNameStart],
  42. &_pRefBuf[lineRef.ulNameStart],
  43. max(lineCur.ulNameEnd-lineCur.ulNameStart,
  44. lineRef.ulNameEnd-lineRef.ulNameStart)+ 1)))
  45. {
  46. //we have found a match. Mark it so that we don't compare anymore
  47. lineRef.fUsed = true;
  48. _pRefList->Set( lTmp, lineRef );
  49. break;
  50. }
  51. lineRef.fUsed = false;
  52. }
  53. //did we find a match.
  54. if ( lTmp == _pRefList->Size() )
  55. {
  56. char* pszName = new char[lineCur.ulNameEnd-lineCur.ulNameStart+1];
  57. for (lTmp=lineCur.ulNameStart; lTmp<(long)lineCur.ulNameEnd; lTmp++)
  58. {
  59. pszName[lTmp-lineCur.ulNameStart] = _pCurBuf[lTmp];
  60. }
  61. pszName[lTmp-lineCur.ulNameStart] = 0;
  62. //if it is the first time, put the banner in.
  63. if ( _bFirstTime )
  64. {
  65. lstrcpy( szBuff, "\ncoclass ");
  66. lstrcat( szBuff, _pszClassName);
  67. lstrcat( szBuff, "\n-----------------------------\n" );
  68. lstrcat( szBuff, "Additions and changes:" );
  69. WriteLine( _fileDiff, szBuff, -1 );
  70. _bFirstTime = false;
  71. }
  72. //this either has changed, or it's a new line.
  73. lstrcpy( szBuff, _pszClassName);
  74. lstrcat( szBuff, " : " );
  75. lstrcat( szBuff, pszName );
  76. lstrcat( szBuff, " added");
  77. WriteLine( _fileDiff, szBuff, -1);
  78. // ferhane: Although this is a change, it does not break COM rules.
  79. // We need to return a success code but report anyway.
  80. // g_ulAppRetVal |= CHANGE_ADDTOCOCLASS;
  81. delete pszName;
  82. }
  83. }
  84. delete [] szBuff;
  85. }
  86. void CCompareCoClass::FindRemovals()
  87. {
  88. long lIdx;
  89. long lTmp;
  90. LINEINFO lineRef;
  91. char* szBuff = new char[128];
  92. bool bFirstRemoval= true;
  93. for ( lIdx=0; lIdx< (int)_pRefList->Size(); lIdx++ )
  94. {
  95. //get the record
  96. _pRefList->GetAt( lIdx, &lineRef);
  97. //is the record marked ?
  98. if (!lineRef.fUsed)
  99. {
  100. //get the real name of the interface
  101. char* pszName = new char[lineRef.ulNameEnd-lineRef.ulNameStart+1];
  102. for (lTmp=lineRef.ulNameStart; lTmp<(long)lineRef.ulNameEnd; lTmp++)
  103. {
  104. pszName[lTmp-lineRef.ulNameStart] = _pRefBuf[lTmp];
  105. }
  106. pszName[lTmp-lineRef.ulNameStart] = 0; //terminate the string
  107. //if it is the first time, put the banner in.
  108. if ( _bFirstTime )
  109. {
  110. lstrcpy( szBuff, "coclass ");
  111. lstrcat( szBuff, _pszClassName);
  112. lstrcat( szBuff, "\n-----------------------------" );
  113. WriteLine( _fileDiff, szBuff, -1 );
  114. _bFirstTime = false;
  115. }
  116. if ( bFirstRemoval )
  117. {
  118. WriteLine( _fileDiff, "Removals:", -1);
  119. bFirstRemoval = false;
  120. }
  121. lstrcpy( szBuff, _pszClassName );
  122. lstrcat( szBuff, " : ");
  123. lstrcat( szBuff, pszName );
  124. lstrcat( szBuff, " has been removed." );
  125. WriteLine( _fileDiff, szBuff, -1);
  126. g_ulAppRetVal |= CHANGE_REMOVEFROMCOCLASS;
  127. delete [] pszName;
  128. WriteLine( _fileDiff, " ", -1 );
  129. }
  130. }
  131. delete [] szBuff;
  132. }
  133. //
  134. //
  135. //
  136. void CCompareCoClass::CreateLineIndex( CAutoArray<LINEINFO>* pList, char* pBuf)
  137. {
  138. LINEINFO lineinfo = {0};
  139. unsigned long ulIdx = 0;
  140. unsigned long ulLastSpace = 0;
  141. char chSearch = '{'; //look for the start of the declaration
  142. while ( pBuf[ulIdx] != 0 )
  143. {
  144. if ( pBuf[ulIdx] == chSearch )
  145. {
  146. switch (chSearch)
  147. {
  148. case '{':
  149. ulIdx+=2; //skip over the CR/LF
  150. //these values are not used and there is no need to use
  151. //CPU time to set them.
  152. // lineinfo.ulAttrStart = 0;
  153. // lineinfo.ulAttrEnd = 0;
  154. // lineinfo.ulParamStart=0;
  155. // lineinfo.ulParamEnd=0;
  156. lineinfo.ulNameStart = ulIdx+1;
  157. chSearch = ';';
  158. break;
  159. case ';':
  160. //finish logging this line
  161. lineinfo.ulNameEnd = ulIdx;
  162. pList->Append(lineinfo);
  163. //prepare for the next line
  164. ulIdx+=2;
  165. lineinfo.ulNameStart = ulIdx+1;
  166. break;
  167. }
  168. }
  169. ulIdx++;
  170. }
  171. }