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.

175 lines
4.0 KiB

  1. #include "precomp.h"
  2. //
  3. // COM.C
  4. // Common functions, simple
  5. //
  6. // Copyright(c) Microsoft 1997-
  7. //
  8. //
  9. // COM_BasedListInsertBefore(...)
  10. //
  11. // See com.h for description.
  12. //
  13. void COM_BasedListInsertBefore(PBASEDLIST pExisting, PBASEDLIST pNew)
  14. {
  15. PBASEDLIST pTemp;
  16. DebugEntry(COM_BasedListInsertBefore);
  17. //
  18. // Check for bad parameters.
  19. //
  20. ASSERT((pNew != NULL));
  21. ASSERT((pExisting != NULL));
  22. //
  23. // Find the item before pExisting:
  24. //
  25. pTemp = COM_BasedPrevListField(pExisting);
  26. ASSERT((pTemp != NULL));
  27. TRACE_OUT(("Inserting item at %#lx into list between %#lx and %#lx",
  28. pNew, pTemp, pExisting));
  29. //
  30. // Set its <next> field to point to the new item
  31. //
  32. pTemp->next = PTRBASE_TO_OFFSET(pNew, pTemp);
  33. pNew->prev = PTRBASE_TO_OFFSET(pTemp, pNew);
  34. //
  35. // Set <prev> field of pExisting to point to new item:
  36. //
  37. pExisting->prev = PTRBASE_TO_OFFSET(pNew, pExisting);
  38. pNew->next = PTRBASE_TO_OFFSET(pExisting, pNew);
  39. DebugExitVOID(COM_BasedListInsertBefore);
  40. } // COM_BasedListInsertBefore
  41. //
  42. // COM_BasedListInsertAfter(...)
  43. //
  44. // See com.h for description.
  45. //
  46. void COM_BasedListInsertAfter(PBASEDLIST pExisting, PBASEDLIST pNew)
  47. {
  48. PBASEDLIST pTemp;
  49. DebugEntry(COM_BasedListInsertAfter);
  50. //
  51. // Check for bad parameters.
  52. //
  53. ASSERT((pNew != NULL));
  54. ASSERT((pExisting != NULL));
  55. //
  56. // Find the item after pExisting:
  57. //
  58. pTemp = COM_BasedNextListField(pExisting);
  59. ASSERT((pTemp != NULL));
  60. TRACE_OUT(("Inserting item at %#lx into list between %#lx and %#lx",
  61. pNew, pExisting, pTemp));
  62. //
  63. // Set its <prev> field to point to the new item
  64. //
  65. pTemp->prev = PTRBASE_TO_OFFSET(pNew, pTemp);
  66. pNew->next = PTRBASE_TO_OFFSET(pTemp, pNew);
  67. //
  68. // Set <next> field of pExisting to point to new item:
  69. //
  70. pExisting->next = PTRBASE_TO_OFFSET(pNew, pExisting);
  71. pNew->prev = PTRBASE_TO_OFFSET(pExisting, pNew);
  72. DebugExitVOID(COM_BasedListInsertAfter);
  73. } // COM_BasedListInsertAfter
  74. //
  75. // COM_BasedListRemove(...)
  76. //
  77. // See com.h for description.
  78. //
  79. void COM_BasedListRemove(PBASEDLIST pListItem)
  80. {
  81. PBASEDLIST pNext = NULL;
  82. PBASEDLIST pPrev = NULL;
  83. DebugEntry(COM_BasedListRemove);
  84. //
  85. // Check for bad parameters.
  86. //
  87. ASSERT((pListItem != NULL));
  88. pPrev = COM_BasedPrevListField(pListItem);
  89. pNext = COM_BasedNextListField(pListItem);
  90. ASSERT((pPrev != NULL));
  91. ASSERT((pNext != NULL));
  92. TRACE_OUT(("Removing item at %#lx from list", pListItem));
  93. pPrev->next = PTRBASE_TO_OFFSET(pNext, pPrev);
  94. pNext->prev = PTRBASE_TO_OFFSET(pPrev, pNext);
  95. DebugExitVOID(COM_BasedListRemove);
  96. } // COM_BasedListRemove
  97. //
  98. //
  99. // List manipulation routines
  100. // COM_BasedListNext
  101. // COM_BasedListPrev
  102. // COM_BasedListFirst
  103. // COM_BasedListLast
  104. //
  105. //
  106. void FAR * COM_BasedListNext( PBASEDLIST pHead, void FAR * pEntry, UINT nOffset )
  107. {
  108. PBASEDLIST p;
  109. ASSERT(pHead != NULL);
  110. ASSERT(pEntry != NULL);
  111. p = COM_BasedNextListField(COM_BasedStructToField(pEntry, nOffset));
  112. return ((p == pHead) ? NULL : COM_BasedFieldToStruct(p, nOffset));
  113. }
  114. void FAR * COM_BasedListPrev ( PBASEDLIST pHead, void FAR * pEntry, UINT nOffset )
  115. {
  116. PBASEDLIST p;
  117. ASSERT(pHead != NULL);
  118. ASSERT(pEntry != NULL);
  119. p = COM_BasedPrevListField(COM_BasedStructToField(pEntry, nOffset));
  120. return ((p == pHead) ? NULL : COM_BasedFieldToStruct(p, nOffset));
  121. }
  122. void FAR * COM_BasedListFirst ( PBASEDLIST pHead, UINT nOffset )
  123. {
  124. return (COM_BasedListIsEmpty(pHead) ?
  125. NULL :
  126. COM_BasedFieldToStruct(COM_BasedNextListField(pHead), nOffset));
  127. }
  128. void FAR * COM_BasedListLast ( PBASEDLIST pHead, UINT nOffset )
  129. {
  130. return (COM_BasedListIsEmpty(pHead) ?
  131. NULL :
  132. COM_BasedFieldToStruct(COM_BasedPrevListField(pHead), nOffset));
  133. }