diff options
Diffstat (limited to 'apps/plugins/mpegplayer/mpeg_misc.c')
-rw-r--r-- | apps/plugins/mpegplayer/mpeg_misc.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/apps/plugins/mpegplayer/mpeg_misc.c b/apps/plugins/mpegplayer/mpeg_misc.c index 8e6ccf650f..e201aa69c7 100644 --- a/apps/plugins/mpegplayer/mpeg_misc.c +++ b/apps/plugins/mpegplayer/mpeg_misc.c | |||
@@ -102,3 +102,63 @@ uint32_t muldiv_uint32(uint32_t multiplicand, | |||
102 | 102 | ||
103 | return UINT32_MAX; /* Saturate */ | 103 | return UINT32_MAX; /* Saturate */ |
104 | } | 104 | } |
105 | |||
106 | |||
107 | /** Lists **/ | ||
108 | |||
109 | /* Does the list have any members? */ | ||
110 | bool list_is_empty(void **list) | ||
111 | { | ||
112 | return *list == NULL; | ||
113 | } | ||
114 | |||
115 | /* Is the item inserted into a particular list? */ | ||
116 | bool list_is_member(void **list, void *item) | ||
117 | { | ||
118 | return *rb->find_array_ptr(list, item) != NULL; | ||
119 | } | ||
120 | |||
121 | /* Removes an item from a list - returns true if item was found | ||
122 | * and thus removed. */ | ||
123 | bool list_remove_item(void **list, void *item) | ||
124 | { | ||
125 | return rb->remove_array_ptr(list, item) != -1; | ||
126 | } | ||
127 | |||
128 | /* Adds a list item, insert last, if not already present. */ | ||
129 | void list_add_item(void **list, void *item) | ||
130 | { | ||
131 | void **item_p = rb->find_array_ptr(list, item); | ||
132 | if (*item_p == NULL) | ||
133 | *item_p = item; | ||
134 | } | ||
135 | |||
136 | /* Clears the entire list. */ | ||
137 | void list_clear_all(void **list) | ||
138 | { | ||
139 | while (*list != NULL) | ||
140 | *list++ = NULL; | ||
141 | } | ||
142 | |||
143 | /* Enumerate all items in the array, passing each item in turn to the | ||
144 | * callback as well as the data value. The current item may be safely | ||
145 | * removed. Other changes during enumeration are undefined. The callback | ||
146 | * may return 'false' to stop the enumeration early. */ | ||
147 | void list_enum_items(void **list, | ||
148 | list_enum_callback_t callback, | ||
149 | intptr_t data) | ||
150 | { | ||
151 | for (;;) | ||
152 | { | ||
153 | void *item = *list; | ||
154 | |||
155 | if (item == NULL) | ||
156 | break; | ||
157 | |||
158 | if (callback != NULL && !callback(item, data)) | ||
159 | break; | ||
160 | |||
161 | if (*list == item) | ||
162 | list++; /* Item still there */ | ||
163 | } | ||
164 | } | ||