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.

95 lines
1.9 KiB

  1. /*++
  2. Copyright (C) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. namenode.cpp
  5. Abstract:
  6. Implements the named data node list.
  7. --*/
  8. #include "wtypes.h"
  9. #include "namenode.h"
  10. BOOL
  11. CNamedNodeList::FindByName (
  12. IN LPCTSTR pszName,
  13. IN INT iNameOffset,
  14. OUT PCNamedNode *ppnodeRet
  15. )
  16. {
  17. PCNamedNode pnodePrev = NULL;
  18. PCNamedNode pnode = m_pnodeFirst;
  19. INT iStat = 1;
  20. // search til match or insertion position found
  21. while (pnode != NULL && (iStat = lstrcmpi(pszName, (LPCTSTR)((CHAR*)pnode + iNameOffset))) > 0) {
  22. pnodePrev = pnode;
  23. pnode = pnode->m_pnodeNext;
  24. }
  25. // if match, return matched node
  26. if (iStat == 0) {
  27. *ppnodeRet = pnode;
  28. return TRUE;
  29. }
  30. // else return insertion point
  31. else {
  32. *ppnodeRet = pnodePrev;
  33. return FALSE;
  34. }
  35. }
  36. void
  37. CNamedNodeList::Add (
  38. IN PCNamedNode pnodeNew,
  39. IN PCNamedNode pnodePos
  40. )
  41. {
  42. // if position specified, insert after it
  43. if (pnodePos != NULL) {
  44. pnodeNew->m_pnodeNext = pnodePos->m_pnodeNext;
  45. pnodePos->m_pnodeNext = pnodeNew;
  46. if (pnodePos == m_pnodeLast)
  47. m_pnodeLast = pnodeNew;
  48. }
  49. // else place first in list
  50. else if (m_pnodeFirst != NULL) {
  51. pnodeNew->m_pnodeNext = m_pnodeFirst;
  52. m_pnodeFirst = pnodeNew;
  53. }
  54. else {
  55. m_pnodeFirst = pnodeNew;
  56. m_pnodeLast = pnodeNew;
  57. }
  58. }
  59. void
  60. CNamedNodeList::Remove (
  61. IN PCNamedNode pnode
  62. )
  63. {
  64. PCNamedNode pnodePrev = NULL;
  65. PCNamedNode pnodeTemp = m_pnodeFirst;
  66. while (pnodeTemp != NULL && pnodeTemp != pnode) {
  67. pnodePrev = pnodeTemp;
  68. pnodeTemp = pnodeTemp->m_pnodeNext;
  69. }
  70. if (pnodeTemp == NULL)
  71. return;
  72. if (pnodePrev)
  73. pnodePrev->m_pnodeNext = pnode->m_pnodeNext;
  74. else
  75. m_pnodeFirst = pnode->m_pnodeNext;
  76. if (pnode == m_pnodeLast)
  77. m_pnodeLast = pnodePrev;
  78. }