2013-01-22 04:06:12 +00:00
|
|
|
/* radare - LGPL - Copyright 2010-2013 - pancake */
|
2013-02-06 09:35:23 +00:00
|
|
|
// XXX. this is dupped inside the r_flist.h for optimizations
|
2010-02-15 21:59:26 +00:00
|
|
|
|
2012-06-07 01:41:21 +00:00
|
|
|
int r_flist_iterator(void **x) {
|
|
|
|
return *x!=0;
|
|
|
|
}
|
|
|
|
void** r_flist_next(void **x) {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
void** r_flist_get(void **x) {
|
|
|
|
return *(x++);
|
|
|
|
}
|
2011-09-21 17:51:09 +00:00
|
|
|
// XXX: forced free?? We need RFlist struct here
|
2010-02-15 21:59:26 +00:00
|
|
|
#include <r_types.h>
|
|
|
|
//#include <r_flist.h>
|
|
|
|
// NOTE: reimplemnetation of r_flist in C (if no R_API defined)
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
#define r_flist_t void**
|
|
|
|
#define RFList void**
|
2018-08-30 11:16:50 +00:00
|
|
|
#define r_flist_rewind(it) for (; (it)!=*(it); (it)--) {} (it)++
|
|
|
|
#define r_flist_next(it) *(it)!=0
|
|
|
|
#define r_flist_get(it) *((it)++)
|
2010-02-15 21:59:26 +00:00
|
|
|
#define r_flist_iterator(x) x
|
|
|
|
#define r_flist_unref(x) x
|
|
|
|
#endif
|
|
|
|
|
|
|
|
R_API void **r_flist_new(int n) {
|
|
|
|
void **it;
|
2017-04-17 20:02:04 +00:00
|
|
|
if (!(it = (void **)calloc (n + 2, sizeof (void*)))) {
|
2010-02-15 21:59:26 +00:00
|
|
|
return NULL;
|
2017-04-17 20:02:04 +00:00
|
|
|
}
|
2010-05-20 15:40:58 +00:00
|
|
|
*it = it;
|
|
|
|
memset (++it, 0, (n+1) * sizeof (void*));
|
|
|
|
return it;
|
2010-02-15 21:59:26 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 01:45:17 +00:00
|
|
|
// XXX. this is wrong :?
|
|
|
|
R_API void **r_flist_resize(void **it, int n) {
|
|
|
|
r_flist_rewind (it);
|
|
|
|
it--;
|
|
|
|
it = realloc (it, ((n+2) * sizeof (void*)));
|
|
|
|
*it = it;
|
|
|
|
return it+1;
|
|
|
|
}
|
|
|
|
|
2010-02-15 21:59:26 +00:00
|
|
|
R_API void **r_flist_prev(void **it) {
|
|
|
|
void **p = it--;
|
|
|
|
return (it==*it)?p:it;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API void r_flist_set(void **it, int idx, void *data) {
|
|
|
|
r_flist_rewind (it);
|
|
|
|
it[idx] = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API void r_flist_delete(void **it, int idx) {
|
|
|
|
r_flist_rewind (it);
|
|
|
|
free (it[idx]);
|
2012-01-31 01:45:17 +00:00
|
|
|
it[idx] = NULL;
|
2018-09-13 08:17:26 +00:00
|
|
|
for (it += idx; *it; it++) {
|
|
|
|
*it = *(it + 1);
|
|
|
|
}
|
2010-02-15 21:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define r_flist_foreach(it, pos) \
|
|
|
|
r_flist_rewind(it); \
|
2018-08-30 11:16:50 +00:00
|
|
|
while (r_flist_next (it) && ((pos) = r_flist_get (it)))
|
2010-02-15 21:59:26 +00:00
|
|
|
|
|
|
|
R_API void r_flist_free(void **it) {
|
|
|
|
void *pos;
|
|
|
|
r_flist_foreach (it, pos)
|
|
|
|
free (pos);
|
|
|
|
r_flist_rewind (it);
|
|
|
|
free (--it);
|
|
|
|
}
|
2013-02-06 09:35:23 +00:00
|
|
|
|
|
|
|
R_API int r_flist_length (void **it) {
|
|
|
|
void *pos;
|
|
|
|
int len = 0;
|
|
|
|
r_flist_foreach (it, pos)
|
|
|
|
len++;
|
|
|
|
return len;
|
|
|
|
}
|