blob: 921818e44a542e9aa1f8398d950121cb39fb5c24 [file] [log] [blame]
Arnaldo Carvalho de Melo25903402009-06-30 19:01:20 -03001#ifndef STRLIST_H_
2#define STRLIST_H_
3
Arnaldo Carvalho de Melo43cbcd82009-07-01 12:28:37 -03004#include <linux/rbtree.h>
Arnaldo Carvalho de Melo25903402009-06-30 19:01:20 -03005#include <stdbool.h>
6
7struct str_node {
8 struct rb_node rb_node;
9 const char *s;
10};
11
12struct strlist {
13 struct rb_root entries;
Arnaldo Carvalho de Melo27d0fd42009-07-11 12:18:34 -030014 unsigned int nr_entries;
15 bool dupstr;
Arnaldo Carvalho de Melo25903402009-06-30 19:01:20 -030016};
17
18struct strlist *strlist__new(bool dupstr, const char *slist);
19void strlist__delete(struct strlist *self);
20
21void strlist__remove(struct strlist *self, struct str_node *sn);
22int strlist__load(struct strlist *self, const char *filename);
23int strlist__add(struct strlist *self, const char *str);
24
Arnaldo Carvalho de Melo27d0fd42009-07-11 12:18:34 -030025struct str_node *strlist__entry(const struct strlist *self, unsigned int idx);
Arnaldo Carvalho de Melo25903402009-06-30 19:01:20 -030026bool strlist__has_entry(struct strlist *self, const char *entry);
27
28static inline bool strlist__empty(const struct strlist *self)
29{
Arnaldo Carvalho de Melo27d0fd42009-07-11 12:18:34 -030030 return self->nr_entries == 0;
31}
32
33static inline unsigned int strlist__nr_entries(const struct strlist *self)
34{
35 return self->nr_entries;
Arnaldo Carvalho de Melo25903402009-06-30 19:01:20 -030036}
37
38int strlist__parse_list(struct strlist *self, const char *s);
39#endif /* STRLIST_H_ */