| 1 | /* |
| 2 | Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com> |
| 3 | |
| 4 | This program is free software; you can redistribute it and/or modify |
| 5 | it under the terms of the GNU Lesser General Public License as published by |
| 6 | the Free Software Foundation; either version 2.1 of the License, or |
| 7 | (at your option) any later version. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | GNU Lesser General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU Lesser General Public License |
| 15 | along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
| 18 | #define SLIST_ADD(list, item) \ |
| 19 | do { \ |
| 20 | (item)->next = (*list); \ |
| 21 | (*list) = (item); \ |
| 22 | } while (0); |
| 23 | |
| 24 | #define SLIST_ADD_END(list, item) \ |
| 25 | if ((*list) == NULL) { \ |
| 26 | SLIST_ADD((list), (item)); \ |
| 27 | } else { \ |
| 28 | void *head = (*list); \ |
| 29 | while ((*list)->next) \ |
| 30 | (*list) = (*list)->next; \ |
| 31 | (*list)->next = (item); \ |
| 32 | (item)->next = NULL; \ |
| 33 | (*list) = head; \ |
| 34 | } |
| 35 | |
| 36 | #define SLIST_REMOVE(list, item) \ |
| 37 | if ((*list) == (item)) { \ |
| 38 | (*list) = (item)->next; \ |
| 39 | } else { \ |
| 40 | void *head = (*list); \ |
| 41 | while ((*list)->next && (*list)->next != (item)) \ |
| 42 | (*list) = (*list)->next; \ |
| 43 | if ((*list)->next != NULL) { \ |
| 44 | (*list)->next = (*list)->next->next; \ |
| 45 | } \ |
| 46 | (*list) = head; \ |
| 47 | } |
| 48 | |
| 49 | |
| 50 | |
| 51 | |