Arnaldo Carvalho de Melo | 2590340 | 2009-06-30 19:01:20 -0300 | [diff] [blame] | 1 | #ifndef STRLIST_H_ |
| 2 | #define STRLIST_H_ |
| 3 | |
Arnaldo Carvalho de Melo | 43cbcd8 | 2009-07-01 12:28:37 -0300 | [diff] [blame] | 4 | #include <linux/rbtree.h> |
Arnaldo Carvalho de Melo | 2590340 | 2009-06-30 19:01:20 -0300 | [diff] [blame] | 5 | #include <stdbool.h> |
| 6 | |
| 7 | struct str_node { |
| 8 | struct rb_node rb_node; |
| 9 | const char *s; |
| 10 | }; |
| 11 | |
| 12 | struct strlist { |
| 13 | struct rb_root entries; |
Arnaldo Carvalho de Melo | 27d0fd4 | 2009-07-11 12:18:34 -0300 | [diff] [blame] | 14 | unsigned int nr_entries; |
| 15 | bool dupstr; |
Arnaldo Carvalho de Melo | 2590340 | 2009-06-30 19:01:20 -0300 | [diff] [blame] | 16 | }; |
| 17 | |
| 18 | struct strlist *strlist__new(bool dupstr, const char *slist); |
| 19 | void strlist__delete(struct strlist *self); |
| 20 | |
| 21 | void strlist__remove(struct strlist *self, struct str_node *sn); |
| 22 | int strlist__load(struct strlist *self, const char *filename); |
| 23 | int strlist__add(struct strlist *self, const char *str); |
| 24 | |
Arnaldo Carvalho de Melo | 27d0fd4 | 2009-07-11 12:18:34 -0300 | [diff] [blame] | 25 | struct str_node *strlist__entry(const struct strlist *self, unsigned int idx); |
Arnaldo Carvalho de Melo | 2590340 | 2009-06-30 19:01:20 -0300 | [diff] [blame] | 26 | bool strlist__has_entry(struct strlist *self, const char *entry); |
| 27 | |
| 28 | static inline bool strlist__empty(const struct strlist *self) |
| 29 | { |
Arnaldo Carvalho de Melo | 27d0fd4 | 2009-07-11 12:18:34 -0300 | [diff] [blame] | 30 | return self->nr_entries == 0; |
| 31 | } |
| 32 | |
| 33 | static inline unsigned int strlist__nr_entries(const struct strlist *self) |
| 34 | { |
| 35 | return self->nr_entries; |
Arnaldo Carvalho de Melo | 2590340 | 2009-06-30 19:01:20 -0300 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | int strlist__parse_list(struct strlist *self, const char *s); |
| 39 | #endif /* STRLIST_H_ */ |