titlelist.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "main.h"
  2. TITLELISTTYPE TitleListTerminator;
  3. TITLELISTTYPE *TitleLinkedList = &TitleListTerminator;
  4. void initTitleList(void)
  5. {
  6. TitleListTerminator.Next = NULL;
  7. TitleListTerminator.timer = 0;
  8. }
  9. /* -----------------------------------------------------------------------------------------------
  10. Adds an entry in the list
  11. -----------------------------------------------------------------------------------------------*/
  12. TITLELISTTYPE *newTitleListEntry(void)
  13. {
  14. TITLELISTTYPE *TitleObject = (TITLELISTTYPE *)calloc(1,sizeof(TITLELISTTYPE)); /* Allocate new entry */
  15. TitleObject->Next = (void *)TitleLinkedList; /* New entry's next is old list _head */
  16. TitleLinkedList = TitleObject; /* new _head is new entry */
  17. return TitleObject; /* return pointer to new entry */
  18. }
  19. /* -----------------------------------------------------------------------------------------------
  20. Removes an entry from the list
  21. -----------------------------------------------------------------------------------------------*/
  22. void removeTitleListEntry(TITLELISTTYPE *Entry)
  23. {
  24. TITLELISTTYPE *TitleObject = TitleLinkedList;
  25. if (TitleObject == &TitleListTerminator) return; /* List is empty */
  26. if (TitleObject == (void *)Entry)
  27. {
  28. TitleLinkedList = (TITLELISTTYPE *)TitleObject->Next;
  29. free(TitleObject);
  30. }
  31. else
  32. while (TitleObject->Next) /* While not terminator */
  33. {
  34. if ((TITLELISTTYPE *)(TitleObject->Next) == (void *)Entry) /* If next entry is what we're looking for */
  35. {
  36. TitleObject->Next = ((TITLELISTTYPE *)(TitleObject->Next))->Next; /* Skip one entry */
  37. free(Entry); /* free the entry we dont' want anymore */
  38. }
  39. TitleObject = (TITLELISTTYPE *)TitleObject->Next; /* Get next entry */
  40. }
  41. }
  42. void clearTitleList()
  43. {
  44. TITLELISTTYPE *TitleObject = TitleLinkedList;
  45. if (TitleObject == &TitleListTerminator) return; /* List is empty */
  46. while (TitleObject->Next) /* While not terminator */
  47. {
  48. TITLELISTTYPE *KillMe=TitleObject;
  49. TitleObject = (TITLELISTTYPE *)KillMe->Next; /* Get next entry */
  50. free(KillMe);
  51. }
  52. TitleLinkedList = &TitleListTerminator;
  53. }