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 | }; |
Jonathan Nieder | 9cba13c | 2011-03-16 02:08:34 -0500 | [diff] [blame] | 8 | struct string_list { |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 9 | struct string_list_item *items; |
| 10 | unsigned int nr, alloc; |
| 11 | unsigned int strdup_strings:1; |
| 12 | }; |
| 13 | |
Thiago Farina | 183113a | 2010-07-04 16:46:19 -0300 | [diff] [blame] | 14 | #define STRING_LIST_INIT_NODUP { NULL, 0, 0, 0 } |
| 15 | #define STRING_LIST_INIT_DUP { NULL, 0, 0, 1 } |
| 16 | |
Julian Phillips | cb944f6 | 2010-06-26 00:41:33 +0100 | [diff] [blame] | 17 | void print_string_list(const struct string_list *p, const char *text); |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 18 | void string_list_clear(struct string_list *list, int free_util); |
| 19 | |
Marius Storm-Olsen | cfa1ee6 | 2009-02-08 15:34:28 +0100 | [diff] [blame] | 20 | /* Use this function to call a custom clear function on each util pointer */ |
| 21 | /* The string associated with the util pointer is passed as the second argument */ |
| 22 | typedef void (*string_list_clear_func_t)(void *p, const char *str); |
| 23 | void string_list_clear_func(struct string_list *list, string_list_clear_func_t clearfunc); |
| 24 | |
Alex Riesen | 8d31635 | 2010-07-03 14:40:04 +0200 | [diff] [blame] | 25 | /* Use this function or the macro below to iterate over each item */ |
Jay Soffian | c6f5a7a | 2009-02-25 03:32:18 -0500 | [diff] [blame] | 26 | typedef int (*string_list_each_func_t)(struct string_list_item *, void *); |
Julian Phillips | b684e97 | 2010-06-26 00:41:34 +0100 | [diff] [blame] | 27 | int for_each_string_list(struct string_list *list, |
| 28 | string_list_each_func_t, void *cb_data); |
Alex Riesen | 8d31635 | 2010-07-03 14:40:04 +0200 | [diff] [blame] | 29 | #define for_each_string_list_item(item,list) \ |
| 30 | for (item = (list)->items; item < (list)->items + (list)->nr; ++item) |
Jay Soffian | c6f5a7a | 2009-02-25 03:32:18 -0500 | [diff] [blame] | 31 | |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 32 | /* Use these functions only on sorted lists: */ |
| 33 | 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] | 34 | int string_list_find_insert_index(const struct string_list *list, const char *string, |
| 35 | int negative_existing_index); |
Julian Phillips | 78a395d | 2010-06-26 00:41:35 +0100 | [diff] [blame] | 36 | struct string_list_item *string_list_insert(struct string_list *list, const char *string); |
Julian Phillips | aadceea | 2010-06-26 00:41:36 +0100 | [diff] [blame] | 37 | struct string_list_item *string_list_insert_at_index(struct string_list *list, |
| 38 | int insert_at, const char *string); |
Julian Phillips | e8c8b71 | 2010-06-26 00:41:37 +0100 | [diff] [blame] | 39 | struct string_list_item *string_list_lookup(struct string_list *list, const char *string); |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 40 | |
| 41 | /* Use these functions only on unsorted lists: */ |
Julian Phillips | 1d2f80f | 2010-06-26 00:41:38 +0100 | [diff] [blame] | 42 | struct string_list_item *string_list_append(struct string_list *list, const char *string); |
Johannes Schindelin | c455c87 | 2008-07-21 19:03:49 +0100 | [diff] [blame] | 43 | void sort_string_list(struct string_list *list); |
| 44 | 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] | 45 | struct string_list_item *unsorted_string_list_lookup(struct string_list *list, |
| 46 | const char *string); |
Johannes Sixt | 86d4b52 | 2011-08-11 23:20:00 -0600 | [diff] [blame] | 47 | void unsorted_string_list_delete_item(struct string_list *list, int i, int free_util); |
Thiago Farina | 0afcb5f | 2010-01-08 17:45:08 -0500 | [diff] [blame] | 48 | #endif /* STRING_LIST_H */ |