2010-02-12 10:45:22 +00:00
|
|
|
/* radare - LGPL - Copyright 2010 nibble <.ds@gmail.com> */
|
|
|
|
|
2014-03-27 15:34:17 +00:00
|
|
|
#ifndef R2_FLIST_H
|
|
|
|
#define R2_FLIST_H
|
2010-02-12 10:45:22 +00:00
|
|
|
|
2013-06-18 10:09:23 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2010-02-12 10:45:22 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2010-02-15 21:59:26 +00:00
|
|
|
//#include <r_types.h>
|
2010-02-12 10:45:22 +00:00
|
|
|
|
|
|
|
#define r_flist_t void**
|
|
|
|
#define RFList void**
|
2010-02-15 21:59:26 +00:00
|
|
|
|
|
|
|
#ifdef R_API
|
2012-01-31 01:45:17 +00:00
|
|
|
R_API void **r_flist_resize(void **it, int n);
|
2011-06-14 02:49:10 +00:00
|
|
|
#define r_flist_rewind(it) while(it!=*it) it--; it++;
|
2010-02-12 10:45:22 +00:00
|
|
|
#define r_flist_next(it) *it!=0
|
|
|
|
#define r_flist_get(it) *(it++)
|
|
|
|
#define r_flist_unref(x) x
|
|
|
|
|
2010-02-15 21:59:26 +00:00
|
|
|
#define r_flist_iterator(x) x
|
|
|
|
/*
|
|
|
|
static inline void **r_flist_iterator(void **it) {
|
|
|
|
r_flist_iterator(it);
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2010-02-12 10:45:22 +00:00
|
|
|
static inline void **r_flist_init(void **it, int n) {
|
|
|
|
*it = it;
|
|
|
|
memset (++it, 0, (n+1) * sizeof (void*));
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void **r_flist_new(int n) {
|
|
|
|
void **it;
|
|
|
|
if (!(it = (void **)malloc ((n+2) * sizeof (void*))))
|
|
|
|
return NULL;
|
|
|
|
return r_flist_init (it, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void **r_flist_prev(void **it) {
|
|
|
|
void **p = it--;
|
|
|
|
return (it==*it)?p:it;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void r_flist_set(void **it, int idx, void *data) {
|
|
|
|
r_flist_rewind (it);
|
|
|
|
it[idx] = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void r_flist_delete(void **it, int idx) {
|
|
|
|
r_flist_rewind (it);
|
|
|
|
free (it[idx]);
|
|
|
|
for(it += idx; *it; it++) *it = *(it+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define r_flist_foreach(it, pos) \
|
|
|
|
r_flist_rewind(it); \
|
|
|
|
while (r_flist_next (it) && (pos = r_flist_get (it)))
|
|
|
|
|
|
|
|
static inline 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
|
|
|
|
2013-02-06 10:47:31 +00:00
|
|
|
static inline int r_flist_length (void **it) {
|
2013-02-06 09:35:23 +00:00
|
|
|
void *pos;
|
|
|
|
int len = 0;
|
|
|
|
r_flist_foreach (it, pos)
|
|
|
|
len++;
|
|
|
|
return len;
|
|
|
|
}
|
2010-02-15 21:59:26 +00:00
|
|
|
#endif
|
2010-02-12 10:45:22 +00:00
|
|
|
|
2013-06-18 10:09:23 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-02-12 10:45:22 +00:00
|
|
|
#endif
|