Module: wine Branch: master Commit: 6cf8e6bd77f6d3c98f39740ce9c789762a7eb52c URL: http://source.winehq.org/git/wine.git/?a=commit;h=6cf8e6bd77f6d3c98f39740ce9...
Author: Dan Hipschman dsh@linux.ucla.edu Date: Tue Jun 5 18:48:21 2007 -0700
list.h: Add macros for reverse iteration.
---
include/wine/list.h | 24 ++++++++++++++++++++++++ 1 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/include/wine/list.h b/include/wine/list.h index dede5b4..b018a1f 100644 --- a/include/wine/list.h +++ b/include/wine/list.h @@ -196,6 +196,30 @@ static inline void list_move_head( struct list *dst, struct list *src ) (cursor) = (cursor2), \ (cursor2) = LIST_ENTRY((cursor)->field.next, type, field))
+/* iterate through the list in reverse order */ +#define LIST_FOR_EACH_REV(cursor,list) \ + for ((cursor) = (list)->prev; (cursor) != (list); (cursor) = (cursor)->prev) + +/* iterate through the list in reverse order, with safety against removal */ +#define LIST_FOR_EACH_SAFE_REV(cursor, cursor2, list) \ + for ((cursor) = (list)->prev, (cursor2) = (cursor)->prev; \ + (cursor) != (list); \ + (cursor) = (cursor2), (cursor2) = (cursor)->prev) + +/* iterate through the list in reverse order using a list entry */ +#define LIST_FOR_EACH_ENTRY_REV(elem, list, type, field) \ + for ((elem) = LIST_ENTRY((list)->prev, type, field); \ + &(elem)->field != (list); \ + (elem) = LIST_ENTRY((elem)->field.prev, type, field)) + +/* iterate through the list in reverse order using a list entry, with safety against removal */ +#define LIST_FOR_EACH_ENTRY_SAFE_REV(cursor, cursor2, list, type, field) \ + for ((cursor) = LIST_ENTRY((list)->prev, type, field), \ + (cursor2) = LIST_ENTRY((cursor)->field.prev, type, field); \ + &(cursor)->field != (list); \ + (cursor) = (cursor2), \ + (cursor2) = LIST_ENTRY((cursor)->field.prev, type, field)) + /* macros for statically initialized lists */ #define LIST_INIT(list) { &(list), &(list) }