tUse item list provided at runtime rather than hardcode it - xmenu - drop-down menu for X11
 (HTM) git clone git://git.z3bra.org/xmenu.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
 (DIR) commit bf59d1b7d425a118abedc02bd29fd04a55460bfd
 (DIR) parent 9db050cb33f34dcdd6862d71240b7e1593bfcaa5
 (HTM) Author: Willy Goiffon <dev@z3bra.org>
       Date:   Thu, 21 Nov 2019 13:58:51 +0100
       
       Use item list provided at runtime rather than hardcode it
       
       Diffstat:
         M config.def.h                        |       8 --------
         M xmenu.c                             |      11 +++++++++--
       
       2 files changed, 9 insertions(+), 10 deletions(-)
       ---
 (DIR) diff --git a/config.def.h b/config.def.h
       t@@ -4,11 +4,3 @@ uint32_t foreground = 0xc1eafe;
        
        /* font used for entries */
        char *font = "monospace:pixelsize=16";
       -
       -char *entries[] = {
       -        "new",
       -        "close",
       -        "reshape",
       -        "snarf",
       -        "plumb",
       -};
 (DIR) diff --git a/xmenu.c b/xmenu.c
       t@@ -29,11 +29,12 @@ size_t nent = 0;
        size_t maxwidth = 0;
        size_t maxheight = 0;
        struct geom menu = { 0, 0, 0, 0 };
       +char **entries;
        
        void
        usage(FILE *fd, char *name)
        {
       -        fprintf(fd, "usage: %s [-hd]\n", name);
       +        fprintf(fd, "usage: %s [-hd] item..\n", name);
        }
        
        int
       t@@ -258,6 +259,11 @@ main(int argc, char *argv[])
                        break;
                } ARGEND;
        
       +        if (!argc) {
       +                usage(stderr, argv0);
       +                return -1;
       +        }
       +
                dpy = xcb_connect(NULL, NULL);
                if (xcb_connection_has_error(dpy))
                        return -1;
       t@@ -271,7 +277,8 @@ main(int argc, char *argv[])
        
                xft_loadfont(font, dpi);
        
       -        for (nent = 0; entries[nent]; nent++) {
       +        entries = argv;
       +        for (nent = 0; nent < (size_t)argc; nent++) {
                        maxwidth  = MAX(xft_txtw(entries[nent]), maxwidth);
                        maxheight = MAX(xft_txth(entries[nent]), maxheight);
                }