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.

72 lines
1.6 KiB

  1. #include "stdafx.h"
  2. #include "mon.h"
  3. CCommonSection gCommonSections;
  4. int compareCommonSection(LPCOMMON_SECTION p1, LPCOMMON_SECTION p2)
  5. {
  6. return (stricmp(p1->sectName, p2->sectName));
  7. }
  8. CCommonSection::CCommonSection()
  9. {
  10. m_sections.RemoveAll();
  11. }
  12. CCommonSection::~CCommonSection()
  13. {
  14. ClearAll();
  15. }
  16. VOID CCommonSection::ClearAll(VOID)
  17. {
  18. for (int i = 0; i < m_sections.GetSize(); i++)
  19. delete((LPCOMMON_SECTION)m_sections[i]);
  20. m_sections.RemoveAll();
  21. }
  22. LPCOMMON_SECTION CCommonSection::AddOneSection(LPSTR sectName, LPSTR contents)
  23. {
  24. LPCOMMON_SECTION pNewSection = new(COMMON_SECTION);
  25. if (pNewSection == NULL)
  26. {
  27. ASSERT(FALSE);
  28. return NULL;
  29. }
  30. strcpy(pNewSection->sectName, sectName);
  31. strcpy(pNewSection->contents, contents);
  32. LPSTR pEndSectName = pNewSection->sectName + lstrlen(pNewSection->sectName);
  33. int dupSectCount = 1;
  34. int comp = 1;
  35. for (int i = 0; i < m_sections.GetSize(); i++)
  36. {
  37. LPCOMMON_SECTION pSection = (LPCOMMON_SECTION)m_sections[i];
  38. comp = compareCommonSection(pNewSection, pSection);
  39. if (comp > 0)
  40. continue;
  41. else if (comp < 0)
  42. break;
  43. if (stricmp(pNewSection->contents, pSection->contents) == 0)
  44. break;
  45. ///////////////////////////////////////////////////////////////
  46. // Come here, we found a section with same section name but
  47. // different contents. Need rename the section Name to make
  48. // it distinct
  49. sprintf(pEndSectName, "%c", 'A'+dupSectCount);
  50. dupSectCount++;
  51. }
  52. if (comp == 0)
  53. {
  54. delete pNewSection;
  55. }
  56. else
  57. {
  58. m_sections.InsertAt(i, (LPVOID)pNewSection);
  59. }
  60. return (LPCOMMON_SECTION)m_sections[i];
  61. }