From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 1/2] string_list: Add string_list_for_each_entry macro
Date: Thu, 3 Jul 2014 09:40:45 +0200 [thread overview]
Message-ID: <1404373246-10075-1-git-send-email-s.hauer@pengutronix.de> (raw)
To ease iterating over a string_list.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
include/stringlist.h | 3 +++
lib/stringlist.c | 6 +++---
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/include/stringlist.h b/include/stringlist.h
index 8738137..127998c 100644
--- a/include/stringlist.h
+++ b/include/stringlist.h
@@ -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 */
diff --git a/lib/stringlist.c b/lib/stringlist.c
index a8af15d..cc84944 100644
--- a/lib/stringlist.c
+++ b/lib/stringlist.c
@@ -64,7 +64,7 @@ int string_list_contains(struct string_list *sl, char *str)
{
struct string_list *entry;
- list_for_each_entry(entry, &sl->list, list) {
+ string_list_for_each_entry(entry, sl) {
if (!strcmp(str, entry->str))
return 1;
}
@@ -77,7 +77,7 @@ void string_list_print_by_column(struct string_list *sl)
int len = 0, num, i;
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;
if (l > len)
len = l;
@@ -91,7 +91,7 @@ void string_list_print_by_column(struct string_list *sl)
num = 1;
i = 0;
- list_for_each_entry(entry, &sl->list, list) {
+ string_list_for_each_entry(entry, sl) {
if (!(++i % num))
printf("%s\n", entry->str);
else
--
2.0.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next reply other threads:[~2014-07-03 7:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-03 7:40 Sascha Hauer [this message]
2014-07-03 7:40 ` [PATCH 2/2] ls: sort files with -l Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1404373246-10075-1-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox