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.

148 lines
3.2 KiB

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