menu: simplify usage for clients
[barebox-mini2440.git] / lib / stringlist.c
blob9ccf8fa836e6a700fec502d57494b72b8f2ac5ae
1 #include <common.h>
2 #include <xfuncs.h>
3 #include <malloc.h>
4 #include <stringlist.h>
6 int string_list_add(struct string_list *sl, char *str)
8 struct string_list *new;
10 new = xmalloc(sizeof(struct string_list) + strlen(str) + 1);
12 strcpy(new->str, str);
14 list_add_tail(&new->list, &sl->list);
16 return 0;
19 void string_list_print_by_column(struct string_list *sl)
21 int len = 0, num, i;
22 struct string_list *entry;
24 list_for_each_entry(entry, &sl->list, list) {
25 int l = strlen(entry->str) + 4;
26 if (l > len)
27 len = l;
30 if (!len)
31 return;
33 num = 80 / (len + 1);
34 if (len == 0)
35 len = 1;
37 i = 0;
38 list_for_each_entry(entry, &sl->list, list) {
39 if (!(++i % num))
40 printf("%s\n", entry->str);
41 else
42 printf("%-*s", len, entry->str);
44 if (i % num)
45 printf("\n");