Git 1.7.3 rc1
[git/mingw/4msysgit/kblees.git] / string-list.h
blob494693898b89fe2f8145b483ea7e366e9b1192c1
1 #ifndef STRING_LIST_H
2 #define STRING_LIST_H
4 struct string_list_item {
5 char *string;
6 void *util;
7 };
8 struct string_list
10 struct string_list_item *items;
11 unsigned int nr, alloc;
12 unsigned int strdup_strings:1;
15 #define STRING_LIST_INIT_NODUP { NULL, 0, 0, 0 }
16 #define STRING_LIST_INIT_DUP { NULL, 0, 0, 1 }
18 void print_string_list(const struct string_list *p, const char *text);
19 void string_list_clear(struct string_list *list, int free_util);
21 /* Use this function to call a custom clear function on each util pointer */
22 /* The string associated with the util pointer is passed as the second argument */
23 typedef void (*string_list_clear_func_t)(void *p, const char *str);
24 void string_list_clear_func(struct string_list *list, string_list_clear_func_t clearfunc);
26 /* Use this function or the macro below to iterate over each item */
27 typedef int (*string_list_each_func_t)(struct string_list_item *, void *);
28 int for_each_string_list(struct string_list *list,
29 string_list_each_func_t, void *cb_data);
30 #define for_each_string_list_item(item,list) \
31 for (item = (list)->items; item < (list)->items + (list)->nr; ++item)
33 /* Use these functions only on sorted lists: */
34 int string_list_has_string(const struct string_list *list, const char *string);
35 int string_list_find_insert_index(const struct string_list *list, const char *string,
36 int negative_existing_index);
37 struct string_list_item *string_list_insert(struct string_list *list, const char *string);
38 struct string_list_item *string_list_insert_at_index(struct string_list *list,
39 int insert_at, const char *string);
40 struct string_list_item *string_list_lookup(struct string_list *list, const char *string);
42 /* Use these functions only on unsorted lists: */
43 struct string_list_item *string_list_append(struct string_list *list, const char *string);
44 void sort_string_list(struct string_list *list);
45 int unsorted_string_list_has_string(struct string_list *list, const char *string);
46 struct string_list_item *unsorted_string_list_lookup(struct string_list *list,
47 const char *string);
48 #endif /* STRING_LIST_H */