klist.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* tripl/klist.c
  2. *
  3. * This file is part of tripl.
  4. *
  5. * tripl is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * tripl is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with tripl. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. #include <stddef.h>
  19. #include <klist.h>
  20. struct klist_node *klist_find_value(struct klist_node *head, int value) {
  21. struct klist_node *t;
  22. for (t = head; t; t = t->next)
  23. if (t->value == value)
  24. return t;
  25. return NULL;
  26. }
  27. void klist_init(struct klist_node *head) {
  28. head->xmask = 0;
  29. head->next = head;
  30. head->prev = head;
  31. head->value = 0;
  32. head->payload = NULL;
  33. head->data = NULL;
  34. return;
  35. }
  36. void klist_add(struct klist_node *head, struct klist_node *new) {
  37. /* head->prev: the last. */
  38. new->prev = head->prev;
  39. new->next = head;
  40. /* head->prev->next: (was) the head */
  41. head->prev->next = new;
  42. head->prev = new;
  43. return;
  44. }
  45. void klist_del(struct klist_node *head, struct klist_node *will_del) {
  46. will_del->prev->next = will_del->next;
  47. will_del->next->prev = will_del->prev;
  48. return;
  49. }