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.

133 lines
2.8 KiB

  1. //+--------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: strlist.cxx
  7. //
  8. // Contents: CStrList implementation
  9. //
  10. //---------------------------------------------------------------
  11. #include "headers.cxx"
  12. #include <string.h>
  13. //+--------------------------------------------------------------
  14. //
  15. // Member: CStrList::CStrList, public
  16. //
  17. // Synopsis: Ctor
  18. //
  19. //---------------------------------------------------------------
  20. CStrList::CStrList(void)
  21. {
  22. _pseHead = NULL;
  23. }
  24. //+--------------------------------------------------------------
  25. //
  26. // Member: CStrList::~CStrList, public
  27. //
  28. // Synopsis: Dtor
  29. //
  30. //---------------------------------------------------------------
  31. CStrList::~CStrList(void)
  32. {
  33. Empty();
  34. }
  35. //+--------------------------------------------------------------
  36. //
  37. // Member: CStrList::Add, public
  38. //
  39. // Synopsis: Adds a string to the list
  40. //
  41. // Arguments: [ptcs] - String
  42. //
  43. // Returns: Pointer to entry or NULL
  44. //
  45. //---------------------------------------------------------------
  46. SStrEntry *CStrList::Add(OLECHAR *ptcs)
  47. {
  48. SStrEntry *pse;
  49. // One char of string already counted in sizeof
  50. pse = (SStrEntry *)new
  51. char[sizeof(SStrEntry)+olecslen(ptcs)*sizeof(OLECHAR)];
  52. if (pse == NULL)
  53. return NULL;
  54. pse->pseNext = _pseHead;
  55. pse->psePrev = NULL;
  56. if (_pseHead)
  57. _pseHead->psePrev = pse;
  58. _pseHead = pse;
  59. olecscpy(pse->atc, ptcs);
  60. return pse;
  61. }
  62. //+--------------------------------------------------------------
  63. //
  64. // Member: CStrList::Remove, public
  65. //
  66. // Synopsis: Removes an entry from the list
  67. //
  68. // Arguments: [pse] - Entry
  69. //
  70. //---------------------------------------------------------------
  71. void CStrList::Remove(SStrEntry *pse)
  72. {
  73. if (pse->psePrev)
  74. pse->psePrev->pseNext = pse->pseNext;
  75. else
  76. _pseHead = pse->pseNext;
  77. if (pse->pseNext)
  78. pse->pseNext->psePrev = pse->psePrev;
  79. delete pse;
  80. }
  81. //+--------------------------------------------------------------
  82. //
  83. // Member: CStrList::Find, public
  84. //
  85. // Synopsis: Attempts to find a string in the list
  86. //
  87. // Arguments: [ptcs] - String
  88. //
  89. // Returns: Entry or NULL
  90. //
  91. //---------------------------------------------------------------
  92. SStrEntry *CStrList::Find(OLECHAR *ptcs)
  93. {
  94. SStrEntry *pse;
  95. for (pse = _pseHead; pse; pse = pse->pseNext)
  96. if (!olecscmp(ptcs, pse->atc))
  97. return pse;
  98. return NULL;
  99. }
  100. //+--------------------------------------------------------------
  101. //
  102. // Member: CStrList::Empty, public
  103. //
  104. // Synopsis: Frees all elements in list
  105. //
  106. //---------------------------------------------------------------
  107. void CStrList::Empty(void)
  108. {
  109. SStrEntry *pse;
  110. while (_pseHead)
  111. {
  112. pse = _pseHead->pseNext;
  113. delete _pseHead;
  114. _pseHead = pse;
  115. }
  116. }