Thiago Farina | 0afcb5f | 2010-01-08 17:45:08 -0500 | [diff] [blame] | 1 | #ifndef STRING_LIST_H |
| 2 | #define STRING_LIST_H |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 3 | |
| 4 | struct string_list_item { |
| 5 | char *string; |
| 6 | void *util; |
| 7 | }; |
| 8 | struct string_list |
| 9 | { |
| 10 | struct string_list_item *items; |
| 11 | unsigned int nr, alloc; |
| 12 | unsigned int strdup_strings:1; |
| 13 | }; |
| 14 | |
| 15 | void print_string_list(const char *text, const struct string_list *p); |
| 16 | void string_list_clear(struct string_list *list, int free_util); |
| 17 | |
Marius Storm-Olsen | cfa1ee6 | 2009-02-08 15:34:28 +0100 | [diff] [blame] | 18 | /* Use this function to call a custom clear function on each util pointer */ |
| 19 | /* The string associated with the util pointer is passed as the second argument */ |
| 20 | typedef void (*string_list_clear_func_t)(void *p, const char *str); |
| 21 | void string_list_clear_func(struct string_list *list, string_list_clear_func_t clearfunc); |
| 22 | |
Jay Soffian | c6f5a7a | 2009-02-25 03:32:18 -0500 | [diff] [blame] | 23 | /* Use this function to iterate over each item */ |
| 24 | typedef int (*string_list_each_func_t)(struct string_list_item *, void *); |
| 25 | int for_each_string_list(string_list_each_func_t, |
| 26 | struct string_list *list, void *cb_data); |
| 27 | |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 28 | /* Use these functions only on sorted lists: */ |
| 29 | int string_list_has_string(const struct string_list *list, const char *string); |
Marius Storm-Olsen | cfa1ee6 | 2009-02-08 15:34:28 +0100 | [diff] [blame] | 30 | int string_list_find_insert_index(const struct string_list *list, const char *string, |
| 31 | int negative_existing_index); |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 32 | struct string_list_item *string_list_insert(const char *string, struct string_list *list); |
Marius Storm-Olsen | cfa1ee6 | 2009-02-08 15:34:28 +0100 | [diff] [blame] | 33 | struct string_list_item *string_list_insert_at_index(int insert_at, |
| 34 | const char *string, struct string_list *list); |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 35 | struct string_list_item *string_list_lookup(const char *string, struct string_list *list); |
| 36 | |
| 37 | /* Use these functions only on unsorted lists: */ |
| 38 | struct string_list_item *string_list_append(const char *string, struct string_list *list); |
| 39 | void sort_string_list(struct string_list *list); |
| 40 | int unsorted_string_list_has_string(struct string_list *list, const char *string); |
Stephen Boyd | e242148 | 2010-03-24 00:16:02 -0700 | [diff] [blame] | 41 | struct string_list_item *unsorted_string_list_lookup(struct string_list *list, |
| 42 | const char *string); |
Thiago Farina | 0afcb5f | 2010-01-08 17:45:08 -0500 | [diff] [blame] | 43 | #endif /* STRING_LIST_H */ |