Simplify read_menu_items - wmenu - 🔧 fork of wmenu
 (HTM) git clone git@git.drkhsh.at/wmenu.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 0db7efe2324a4b2656fa117d9c7bdf84fc7fcbc1
 (DIR) parent e8782db9c840e42827dafa4ec1ca9849f91b9b59
 (HTM) Author: adnano <me@adnano.co>
       Date:   Tue, 27 Feb 2024 11:34:17 -0500
       
       Simplify read_menu_items
       
       Diffstat:
         M menu.c                              |      16 +++++++++-------
       
       1 file changed, 9 insertions(+), 7 deletions(-)
       ---
 (DIR) diff --git a/menu.c b/menu.c
       @@ -293,20 +293,22 @@ static void match_items(struct menu *menu) {
        
        // Read menu items from standard input.
        void read_menu_items(struct menu *menu) {
       -        char buf[sizeof menu->input], *p;
       -        struct item *item, **end;
       +        char buf[sizeof menu->input];
        
       -        for(end = &menu->items; fgets(buf, sizeof buf, stdin); *end = item, end = &item->next) {
       -                if((p = strchr(buf, '\n'))) {
       +        struct item **next = &menu->items;
       +        while (fgets(buf, sizeof buf, stdin)) {
       +                char *p = strchr(buf, '\n');
       +                if (p) {
                                *p = '\0';
                        }
       -                item = malloc(sizeof *item);
       +                struct item *item = calloc(1, sizeof *item);
                        if (!item) {
                                return;
                        }
       -
                        item->text = strdup(buf);
       -                item->next = item->prev_match = item->next_match = NULL;
       +
       +                *next = item;
       +                next = &item->next;
                }
        
                calc_widths(menu);