string_list: Add string_list_for_each_entry macro
To ease iterating over a string_list. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
9d6df51542
commit
6dd613f1bc
|
@ -29,4 +29,7 @@ static inline void string_list_free(struct string_list *sl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define string_list_for_each_entry(entry, sl) \
|
||||||
|
list_for_each_entry(entry, &(sl)->list, list)
|
||||||
|
|
||||||
#endif /* __STRINGLIST_H */
|
#endif /* __STRINGLIST_H */
|
||||||
|
|
|
@ -64,7 +64,7 @@ int string_list_contains(struct string_list *sl, char *str)
|
||||||
{
|
{
|
||||||
struct string_list *entry;
|
struct string_list *entry;
|
||||||
|
|
||||||
list_for_each_entry(entry, &sl->list, list) {
|
string_list_for_each_entry(entry, sl) {
|
||||||
if (!strcmp(str, entry->str))
|
if (!strcmp(str, entry->str))
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ void string_list_print_by_column(struct string_list *sl)
|
||||||
int len = 0, num, i;
|
int len = 0, num, i;
|
||||||
struct string_list *entry;
|
struct string_list *entry;
|
||||||
|
|
||||||
list_for_each_entry(entry, &sl->list, list) {
|
string_list_for_each_entry(entry, sl) {
|
||||||
int l = strlen(entry->str) + 4;
|
int l = strlen(entry->str) + 4;
|
||||||
if (l > len)
|
if (l > len)
|
||||||
len = l;
|
len = l;
|
||||||
|
@ -91,7 +91,7 @@ void string_list_print_by_column(struct string_list *sl)
|
||||||
num = 1;
|
num = 1;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
list_for_each_entry(entry, &sl->list, list) {
|
string_list_for_each_entry(entry, sl) {
|
||||||
if (!(++i % num))
|
if (!(++i % num))
|
||||||
printf("%s\n", entry->str);
|
printf("%s\n", entry->str);
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue