insque.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. Copyright (C) 1993-1998, 2001-2012 Free Software Foundation, Inc.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. /* This file implements the emacs_insque and emacs_remque functions,
  14. clones of the insque and remque functions of BSD. They and all
  15. their callers have been renamed to emacs_mumble to allow us to
  16. include this file in the menu library on all systems. */
  17. #include "XMenuInt.h"
  18. struct qelem {
  19. struct qelem *q_forw;
  20. struct qelem *q_back;
  21. char q_data[1];
  22. };
  23. /* Insert ELEM into a doubly-linked list, after PREV. */
  24. void
  25. emacs_insque (void *velem, void *vprev)
  26. {
  27. struct qelem *elem = velem;
  28. struct qelem *prev = vprev;
  29. struct qelem *next = prev->q_forw;
  30. prev->q_forw = elem;
  31. if (next)
  32. next->q_back = elem;
  33. elem->q_forw = next;
  34. elem->q_back = prev;
  35. }
  36. /* Unlink ELEM from the doubly-linked list that it is in. */
  37. void
  38. emacs_remque (void *velem)
  39. {
  40. struct qelem *elem = velem;
  41. struct qelem *next = elem->q_forw;
  42. struct qelem *prev = elem->q_back;
  43. if (next)
  44. next->q_back = prev;
  45. if (prev)
  46. prev->q_forw = next;
  47. }