Simplify read_menu_items
This commit is contained in:
parent
e8782db9c8
commit
0db7efe232
1 changed files with 9 additions and 7 deletions
16
menu.c
16
menu.c
|
@ -293,20 +293,22 @@ static void match_items(struct menu *menu) {
|
||||||
|
|
||||||
// Read menu items from standard input.
|
// Read menu items from standard input.
|
||||||
void read_menu_items(struct menu *menu) {
|
void read_menu_items(struct menu *menu) {
|
||||||
char buf[sizeof menu->input], *p;
|
char buf[sizeof menu->input];
|
||||||
struct item *item, **end;
|
|
||||||
|
|
||||||
for(end = &menu->items; fgets(buf, sizeof buf, stdin); *end = item, end = &item->next) {
|
struct item **next = &menu->items;
|
||||||
if((p = strchr(buf, '\n'))) {
|
while (fgets(buf, sizeof buf, stdin)) {
|
||||||
|
char *p = strchr(buf, '\n');
|
||||||
|
if (p) {
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
}
|
}
|
||||||
item = malloc(sizeof *item);
|
struct item *item = calloc(1, sizeof *item);
|
||||||
if (!item) {
|
if (!item) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
item->text = strdup(buf);
|
item->text = strdup(buf);
|
||||||
item->next = item->prev_match = item->next_match = NULL;
|
|
||||||
|
*next = item;
|
||||||
|
next = &item->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
calc_widths(menu);
|
calc_widths(menu);
|
||||||
|
|
Loading…
Add table
Reference in a new issue