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.

86 lines
1.7 KiB

  1. /* Copyright (c) 1998 Microsoft Corporation */
  2. /*
  3. * @DOC DMusic16
  4. *
  5. * @MODULE List.c - Generic list management |
  6. */
  7. #include <windows.h>
  8. #include <mmsystem.h>
  9. #include "dmusic16.h"
  10. #include "debug.h"
  11. #ifdef DEBUG
  12. STATIC BOOL PASCAL IsNodeInList(NPLINKNODE pHead, NPLINKNODE pNode);
  13. #endif
  14. /* @func Insert a node into a linked list.
  15. *
  16. */
  17. VOID PASCAL
  18. ListInsert(
  19. NPLINKNODE *pHead, /* @parm A pointer to the list head */
  20. NPLINKNODE pNode) /* @parm A pointer to the node to insert */
  21. {
  22. assert(!IsNodeInList(*pHead, pNode));
  23. if (*pHead)
  24. {
  25. (*pHead)->pPrev = pNode;
  26. }
  27. pNode->pNext = *pHead;
  28. pNode->pPrev = NULL;
  29. *pHead = pNode;
  30. }
  31. /* @func Remove a node into a linked list.
  32. *
  33. * @comm
  34. *
  35. * The node must exist in the list. The debug version which check for this.
  36. */
  37. VOID PASCAL
  38. ListRemove(
  39. NPLINKNODE *pHead, /* @parm A pointer to the list head */
  40. NPLINKNODE pNode) /* @parm A pointer to the node to delete */
  41. {
  42. assert(IsNodeInList(*pHead, pNode));
  43. if (pNode->pPrev)
  44. {
  45. pNode->pPrev->pNext = pNode->pNext;
  46. }
  47. else
  48. {
  49. *pHead = pNode->pNext;
  50. }
  51. if (pNode->pNext)
  52. {
  53. pNode->pNext->pPrev = pNode->pPrev;
  54. }
  55. }
  56. #ifdef DEBUG
  57. /* @func Determine if a node is in a linked list.
  58. *
  59. */
  60. STATIC BOOL PASCAL
  61. IsNodeInList(
  62. NPLINKNODE pHead, /* @parm A pointer to the first node in the list */
  63. NPLINKNODE pNode) /* @parm A pointer to the node to look for in the list */
  64. {
  65. for (; pHead; pHead = pHead->pNext)
  66. {
  67. if (pHead == pNode)
  68. {
  69. return TRUE;
  70. }
  71. }
  72. return FALSE;
  73. }
  74. #endif