Skip to content
Myr

main.c

This file

Path

main.c

2,452 lines · 90.1 KiB · C

Last changed by

cache: fix incorrect cache write error messageNicholas Rodrigues Lordellobefore adoptionb320e2f

History of this file

Take it

1#include <stdlib.h>2#include <stdio.h>3#include <stdbool.h>4#include <string.h>5#include <getopt.h>6#include <errno.h>7#include <threads.h>89#include <locale.h>10#include <libgen.h>1112#include <sys/types.h>13#include <sys/mman.h>14#include <sys/stat.h>15#include <sys/file.h>16#include <sys/epoll.h>17#include <sys/eventfd.h>18#include <sys/time.h>19#include <fcntl.h>20#include <dirent.h>2122#include <tllist.h>23#include <fcft/fcft.h>2425#define LOG_MODULE "fuzzel"26#define LOG_ENABLE_DBG 027#include "log.h"28#include "application.h"29#include "char32.h"30#include "config.h"31#include "dmenu.h"32#include "event.h"33#include "fdm.h"34#include "key-binding.h"35#include "match.h"36#include "path.h"37#include "render.h"38#include "shm.h"39#include "version.h"40#include "wayland.h"41#include "xdg.h"42#include "xmalloc.h"43#include "xsnprintf.h"4445#include "timing.h"4647#define max(x, y) ((x) > (y) ? (x) : (y))48#define min(x, y) ((x)  < (y) ? (x) : (y))4950struct context {51    struct config *conf;52    const char *cache_path;53    struct wayland *wayl;54    struct render *render;55    struct matches *matches;56    struct application_list *apps;5758    icon_theme_list_t *themes;59    int icon_size;60    mtx_t *icon_lock;6162    const char *select_initial;63    const size_t select_initial_idx;6465    int event_fd;66    int dmenu_abort_fd;6768    struct {69        struct {70            struct timespec *start;71            struct timespec *stop;72        } apps;73        struct {74            struct timespec *start;75            struct timespec *stop;76        } icons_theme;77        struct {78            struct timespec *start;79            struct timespec *stop;80        } icons;81    } timing;82};8384struct cache_entry {85    char *id;86    char32_t *title;87    size_t count;88};8990static void91read_cache(const char *path, struct application_list *apps, bool dmenu)92{93    if (path == NULL && dmenu) {94        /* Don't thrash "normal" cache in dmenu mode */95        return;96    }9798    struct stat st;99    FILE *f = NULL;100101    if (path == NULL) {102        path = xdg_cache_dir();103        if (path == NULL) {104            LOG_WARN("failed to get cache directory: not saving popularity cache");105            return;106        }107108        int cache_dir_fd = open(path, O_DIRECTORY | O_CLOEXEC);109        if (cache_dir_fd == -1) {110            LOG_ERRNO("%s: failed to open", path);111            return;112        }113114        int fd = -1;115        if (fstatat(cache_dir_fd, "fuzzel", &st, 0) < 0 ||116            (fd = openat(cache_dir_fd, "fuzzel", O_RDONLY | O_CLOEXEC)) < 0 ||117            (f = fdopen(fd, "r")) == NULL)118        {119            close(cache_dir_fd);120            if (fd >= 0)121                close(fd);122123            if (errno != ENOENT)124                LOG_ERRNO("%s/fuzzel: failed to open", path);125            return;126        }127        close(cache_dir_fd);128    } else {129        if (stat(path, &st) < 0 || (f = fopen(path, "re")) == NULL)130        {131            if (errno != ENOENT)132                LOG_ERRNO("%s: failed to open", path);133            return;134        }135    }136137    tll(struct cache_entry) cache_entries = tll_init();138139    size_t line_sz = 0;140    char *line = NULL;141142    while (true) {143        errno = 0;144        ssize_t bytes = getline(&line, &line_sz, f);145146        if (bytes < 0) {147            if (errno != 0) {148                LOG_ERRNO("failed to read cache");149                fclose(f);150                free(line);151                return;152            }153154            /* Done */155            break;156        }157158        if (line[bytes - 1] == '\n')159            line[bytes - 1] = '\0';160161        /* Parse each line ("<title>|<count>") */162        char *ptr = NULL;163        const char *id = strtok_r(line, "|", &ptr);164        const char *count_str = strtok_r(NULL, "|", &ptr);165166        if (id == NULL || count_str == NULL) {167            LOG_ERR("invalid cache entry (cache corrupt?): %s", line);168            continue;169        }170171        int count;172        sscanf(count_str, "%u", &count);173174        struct cache_entry entry = {175            .id = dmenu ? NULL : xstrdup(id),176            .title = dmenu ? ambstoc32(id) : NULL,177            .count = count,178        };179        tll_push_back(cache_entries, entry);180    }181182    free(line);183    fclose(f);184185    /* Loop all applications, and search for a matching cache entry */186    for (size_t i = 0; i < apps->count; i++) {187        struct application *app = apps->v[i];188189        if ((!dmenu && app->id == NULL) || (dmenu && app->title == NULL)) {190            continue;191        }192193        tll_foreach(cache_entries, it) {194            const struct cache_entry *e = &it->item;195            if ((!dmenu && e->id == NULL) || (dmenu && e->title == NULL))196                continue;197198            if ((!dmenu && strcmp(app->id, e->id) == 0) ||199                (dmenu && c32cmp(app->title, e->title) == 0))200            {201                app->count = e->count;202203                free(e->id);204                free(e->title);205                tll_remove(cache_entries, it);206                break;207            }208        }209    }210211    /* Free all un-matched cache entries */212    tll_foreach(cache_entries, it) {213        free(it->item.id);214        tll_remove(cache_entries, it);215    }216}217218static void219write_cache(const char *path, const struct application_list *apps, bool dmenu)220{221    if (path == NULL && dmenu) {222        /* Don't thrash "normal" cache in dmenu mode */223        return;224    }225226    int fd = -1;227228    if (path == NULL) {229        path = xdg_cache_dir();230        if (path == NULL) {231            LOG_WARN("failed to get cache directory: not saving popularity cache");232            return;233        }234235        int cache_dir_fd = open(path, O_DIRECTORY | O_CLOEXEC);236        if (cache_dir_fd == -1) {237            LOG_ERRNO("%s: failed to open", path);238            return;239        }240241        if ((fd = openat(cache_dir_fd, "fuzzel", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644)) == -1) {242            close(cache_dir_fd);243            LOG_ERRNO("%s/fuzzel: failed to open", path);244            return;245        }246        close(cache_dir_fd);247    } else {248        if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644)) == -1) {249            LOG_ERRNO("%s: failed to open", path);250            return;251        }252    }253254    for (size_t i = 0; i < apps->count; i++) {255        if (apps->v[i]->count == 0)256            continue;257258        if (!apps->v[i]->visible)259            continue;260261        if (!dmenu && apps->v[i]->id == NULL)262            continue;263264        if (dmenu && apps->v[i]->title == NULL)265            continue;266267        if (!dmenu) {268            const char *id = apps->v[i]->id;269            const size_t id_len = strlen(id);270271            if (write(fd, id, id_len) != id_len) {272                LOG_ERRNO("failed to write cache");273                break;274            }275        } else {276            const char32_t *title = apps->v[i]->title;277            char *u8_title = ac32tombs(title);278279            if (u8_title != NULL) {280                const size_t title_len = strlen(u8_title);281                if (write(fd, u8_title, title_len) != title_len) {282                    LOG_ERRNO("failed to write cache");283                    break;284                }285286                free(u8_title);287            }288        }289290        char count_as_str[11];291        const size_t count_len = xsnprintf(292            count_as_str, sizeof(count_as_str), "%u", apps->v[i]->count);293294        if (write(fd, "|", 1) != 1 ||295            write(fd, count_as_str, count_len) != count_len ||296            write(fd, "\n", 1) != 1)297        {298            LOG_ERRNO("failed to write cache");299            break;300        }301    }302303    close(fd);304}305306static const char *307version_and_features(void)308{309    static char buf[256];310    xsnprintf(buf, sizeof(buf), "version: %s %ccairo %cpng %csvg%s %cassertions",311             FUZZEL_VERSION,312#if defined(FUZZEL_ENABLE_CAIRO)313             '+',314#else315             '-',316#endif317#if defined(FUZZEL_ENABLE_PNG_LIBPNG)318             '+',319#else320             '-',321#endif322#if defined(FUZZEL_ENABLE_SVG_NANOSVG)323             '+', "(nanosvg)",324#elif defined(FUZZEL_ENABLE_SVG_LIBRSVG)325             '+', "(librsvg)",326#elif defined(FUZZEL_ENABLE_SVG_RESVG)327             '+', "(resvg)",328#else329             '-', "",330#endif331#if !defined(NDEBUG)332             '+'333#else334             '-'335#endif336        );337    return buf;338}339340static void341print_usage(const char *prog_name)342{343    printf("Usage: %s [OPTION]...\n", prog_name);344    printf("\n");345    printf("Options:\n");346    printf("     --config=PATH               load configuration from PATH\n"347           "                                 (XDG_CONFIG_HOME/fuzzel/fuzzel.ini)\n"348           "     --check-config              verify configuration, exit with 0 if ok,\n"349           "                                 otherwise exit with 1\n"350           "     --cache=PATH                load most recently launched applications from\n"351           "                                 PATH (XDG_CACHE_HOME/fuzzel)\n"352           "     --override=[section.].key=VALUE  override configuration value\n"353           "  -n,--namespace=NAMESPACE       layer shell surface namespace\n"354           "  -o,--output=OUTPUT             output (monitor) to display on (none)\n"355           "  -f,--font=FONT                 font name and style, in FontConfig format\n"356           "                                 (monospace)\n"357           "     --use-bold                  allow fuzzel to use bold fonts\n"358           "  -D,--dpi-aware=no|yes|auto     enable or disable DPI aware rendering (auto)\n"359           "     --icon-theme=NAME           icon theme name (\"default\")\n"360           "  -I,--no-icons                  do not render any icons\n"361           "     --hide-before-typing    hide application list until something is typed\n"362           "  -F,--fields=FIELDS             comma separated list of XDG Desktop entry\n"363           "                                 fields to match\n"364           "  -p,--prompt=PROMPT             string to use as input prompt (\"> \")\n"365           "     --prompt-only=PROMPT        same as --prompt, but in dmenu mode it does not\n"366           "                                 wait for STDIN, and implies --lines=0\n"367           "     --placeholder=TEXT          placeholder text in input box\n"368           "     --search=TEXT               initial search/filter string\n"369           "     --password=[CHARACTER]      render all input as CHARACTER ('*' by default)\n"370           "     --mesg                      show informational message above the prompt\n"371           "     --mesg-mode=wrap|expand     how to deal with message lines longer than\n"372           "                                 the ui (wrap)\n"373           "  -T,--terminal                  terminal command to use when launching\n"374           "                                 'terminal' programs, e.g. \"xterm -e\".\n"375           "                                 Not used in dmenu mode (not set)\n"376           "  -a,--anchor                    window anchor (center)\n"377           "     --x-margin=MARGIN           horizontal margin, in pixels (0)\n"378           "     --y-margin=MARGIN           vertical margin, in pixels (0)\n"379           "     --select=STRING             select first entry that matches the given\n"380           "                                 string\n"381           "     --auto-select               automatically select when only one match\n"382           "                                 remains\n"383           "     --select-index=INDEX        select the entry with index, not compatible with --select\n"384           "  -l,--lines                     number of matches to show\n"385           "     --minimal-lines             adjust the number of lines to the\n"386           "                                 minimum of --lines and the number\n"387           "                                 of input lines (dmenu mode only)\n"388           "     --hide-prompt               hide the prompt line, making the window\n"389           "                                 smaller (input still accepted)\n"390           "  -w,--width                     window width, in characters (margins and\n"391           "                                 borders not included)\n"392           "     --tabs=INT                  number of spaces a tab is expanded to (8)\n"393           "  -x,--horizontal-pad=PAD        horizontal padding, in pixels (40)\n"394           "  -y,--vertical-pad=PAD          vertical padding, in pixels (8)\n"395           "  -P,--inner-pad=PAD             vertical padding between prompt and match list,\n"396           "                                 in pixels (0)\n"397           "  -b,--background-color=HEX      background color (fdf6e3ff)\n"398           "  -t,--text-color=HEX            text color of matched entries (657b83ff)\n"399           "     --prompt-color=HEX          text color of the prompt (586e75ff)\n"400           "     --placeholder-color=HEX     text color of the placeholder text (93a1a1)\n"401           "     --message-color=HEX         text color of the message (657b83ff)\n"402           "     --input-color=HEX           text color of the input string (657b83ff)\n"403           "  -m,--match-color=HEX           color of matched substring (cb4b16ff)\n"404           "  -s,--selection-color=HEX       background color of selected item (eee8d5ff)\n"405           "  -S,--selection-text-color=HEX  text color of selected item (586e75ff)\n"406           "  -M,--selection-match-color=HEX color of matched substring in selection\n"407           "                                 (cb4b16ff)\n"408           "     --selection-radius          border radius of the selected entry (0)\n"409           "     --counter-color             color of the match count (93a1a1)\n"410           "  -B,--border-width=INT          width of border, in pixels (1)\n"411           "  -r,--border-radius=INT         amount of corner \"roundness\" (10)\n"412           "  -C,--border-color=HEX          border color (002b36ff)\n"413           "     --show-actions              include desktop actions in the list\n"414           "     --match-mode=exact|fzf|fuzzy how to match what you type against the entries\n"415           "     --filter-desktop            filter desktop entries based on XDG_CURRENT\n"416           "     --fuzzy-min-length=VALUE    search strings shorter than this will not be\n"417           "                                 fuzzy matched (3)\n"418           "     --fuzzy-max-length-discrepancy=VALUE  maximum allowed length discrepancy\n"419           "                                           between a fuzzy match and the search\n"420           "                                           criteria. Larger values mean more\n"421           "                                           fuzzy matches (2)\n"422           "     --fuzzy-max-distance=VALUE  maximum levenshtein distance between a fuzzy\n"423           "                                 match and the search criteria. Larger values\n"424           "                                 mean more fuzzy matches\n"425           "     --line-height=HEIGHT        override line height from font metrics\n"426           "     --letter-spacing=AMOUNT     additional letter spacing\n"427           "     --layer=top|overlay         which layer to render the fuzzel window on\n"428           "                                 (top)\n"429           "     --keyboard-focus=exclusive|on-demand  keyboard focus mode (exclusive)\n"430           "     --no-exit-on-keyboard-focus-loss  do not exit when losing keyboard focus\n"431           "     --launch-prefix=COMMAND     prefix to add before argv of executed program\n"432           "     --list-executables-in-path  include executables from PATH in the list\n"433           "     --render-workers=N          number of threads to use for rendering\n"434           "     --match-workers=N           number of threads to use for matching\n"435           "     --no-sort                   do not sort the result\n"436           "     --counter                   display the match count\n"437           "     --delayed-filter-ms=TIME_MS time in ms before refiltering after a keystroke\n"438           "                                 (300)\n"439           "     --delayed-filter-limit=N    used delayed refiltering when the number of\n"440           "                                 matches exceeds this number (10000)\n"441           "     --scaling-filter=FILTER     filter to use when down scaling PNGs\n"442           "  -d,--dmenu                     dmenu compatibility mode\n"443           "     --dmenu0                    like --dmenu, but input is NUL separated\n"444           "                                 instead of newline separated\n"445           "     --index                     print selected entry's index instead of of the \n"446           "                                 entry's text (dmenu mode only)\n"447           "     --with-nth=N|FMT            display the N:th column (tab separated by\n"448           "                                 default) of each input line (dmenu only)\n"449           "     --accept-nth=N|FMT          output the N:th column (tab separated by\n"450           "                                 default) of each input line (dmenu only)\n"451           "     --match-nth=N|FMT           match against the N:th column (tab separated by\n"452           "                                 default) of each input line, instead of what is\n"453           "                                 being displayed (dmenu only)\n"454           "     --nth-delimiter=CHARACTER   field (column) character, for --with-nth and\n"455           "                                 --accept-nth\n"456           "     --only-match                do not allow custom entries, only return a\n"457           "                                 selected item\n"458           "  -R,--no-run-if-empty           exit immediately without showing UI if stdin\n"459           "                                 is empty (dmenu mode only)\n"460           "     --log-level={info|warning|error|none}\n"461           "                                 log level (warning)\n"462           "     --log-colorize=[never|always|auto]\n"463           "                                 enable/disable colorization of log output on\n"464           "                                 stderr\n"465           "     --log-no-syslog             disable syslog logging\n"466           "     --print-timing-info         print timing information, to help debug\n"467           "                                 performance issues\n"468           "     --no-mouse                  disable mouse input\n"469           "  -v,--version                   show the version number and quit\n");470471    printf("\n");472    printf("All colors are RGBA - i.e. 8-digit hex values, without prefix.\n");473}474475static void476font_reloaded(struct wayland *wayl, struct fcft_font *font, void *data)477{478    struct context *ctx = data;479    const struct config *conf = ctx->conf;480481    applications_flush_text_run_cache(ctx->apps);482    render_flush_text_run_cache(ctx->render);483484    mtx_lock(ctx->icon_lock);485    {486        ctx->icon_size = render_icon_size(ctx->render);487488        if (conf->icons_enabled) {489            icon_lookup_application_icons(490                *ctx->themes, ctx->icon_size, ctx->apps);491492            if (conf->dmenu.enabled) {493                dmenu_try_icon_list(ctx->apps, *ctx->themes, ctx->icon_size);494            }495        }496    }497    mtx_unlock(ctx->icon_lock);498}499500static bool501pt_or_px_from_string(const char  *s, struct pt_or_px *res)502{503    const size_t len = strlen(s);504    if (len >= 2 && s[len - 2] == 'p' && s[len - 1] == 'x') {505        errno = 0;506        char *end = NULL;507508        long value = strtol(s, &end, 10);509        if (!(errno == 0 && end == s + len - 2)) {510            fprintf(stderr, "%s: not a valid pixel value\n", s);511            return false;512        }513514        res->pt = 0;515        res->px = value;516    } else {517        errno = 0;518        char *end = NULL;519520        float value = strtof(s, &end);521        if (!(errno == 0 && *end == '\0')) {522            fprintf(stderr, "%s: not a valid point value\n", s);523            return false;524        }525        res->pt = value;526        res->px = 0;527    }528529    return true;530}531532static char *533lock_file_name(void)534{535    const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");536    if (xdg_runtime_dir == NULL)537        xdg_runtime_dir = "/tmp";538539    const char *wayland_display = getenv("WAYLAND_DISPLAY");540    if (wayland_display == NULL)541        return NULL;542543    char *path = xasprintf("%s/fuzzel-%s.lock", xdg_runtime_dir, wayland_display);544    LOG_DBG("lock file: %s", path);545    return path;546}547548static bool549acquire_file_lock(const char *path, int *fd)550{551    *fd = open(path, O_WRONLY | O_CREAT | O_CLOEXEC, 0644);552    if (*fd < 0) {553        /* Warn, but allow running anyway */554        LOG_WARN("%s: failed to create lock file: %s", path, strerror(errno));555        return true;556    }557558    if (flock(*fd, LOCK_EX | LOCK_NB) < 0) {559        if (errno == EWOULDBLOCK) {560            /* The file is locked and the LOCK_NB flag was selected */561            LOG_ERR("%s: failed to acquire lock: fuzzel already running?", path);562            return false;563        }564    }565566    return true;567}568569/* THREAD */570static int571populate_apps(void *_ctx)572{573    struct context *ctx = _ctx;574    const char *cache_path = ctx->cache_path;575    struct application_list *apps = ctx->apps;576    const struct config *conf = ctx->conf;577    const char *icon_theme = conf->icon_theme;578    const char *terminal = conf->terminal;579    bool actions_enabled = conf->actions_enabled;580    bool dmenu_enabled = conf->dmenu.enabled;581    bool icons_enabled = conf->icons_enabled;582    char dmenu_delim = conf->dmenu.delim;583    char dmenu_nth_delim = conf->dmenu.nth_delim;584    const char *dmenu_with_nth_format = conf->dmenu.with_nth_format;585    const char *dmenu_match_nth_format = conf->dmenu.match_nth_format;586    bool filter_desktop = conf->filter_desktop;587    bool list_exec_in_path = conf->list_executables_in_path;588    char_list_t desktops = tll_init();589    char *saveptr = NULL;590591    if (filter_desktop) {592        char *xdg_current_desktop = getenv("XDG_CURRENT_DESKTOP");593        if (xdg_current_desktop && strlen(xdg_current_desktop) != 0) {594            xdg_current_desktop = xstrdup(xdg_current_desktop);595            for (char *desktop = strtok_r(xdg_current_desktop, ":", &saveptr);596                 desktop != NULL;597                 desktop = strtok_r(NULL, ":", &saveptr))598                {599                    tll_push_back(desktops, xstrdup(desktop));600                }601            free(xdg_current_desktop);602        }603    }604605    ctx->timing.apps.start = time_begin();606607    if (dmenu_enabled) {608        if (!conf->prompt_only) {609            dmenu_load_entries(610                apps, dmenu_delim, dmenu_with_nth_format, dmenu_match_nth_format,611                dmenu_nth_delim, ctx->event_fd, ctx->dmenu_abort_fd);612            read_cache(cache_path, apps, true);613        }614    } else {615        xdg_find_programs(terminal, actions_enabled, filter_desktop, &desktops, apps);616        if (list_exec_in_path)617            path_find_programs(apps);618        read_cache(cache_path, apps, false);619    }620    tll_free_and_free(desktops, free);621622    ctx->timing.apps.stop = time_end();623624    int r = send_event(ctx->event_fd, EVENT_APPS_ALL_LOADED);625    if (r != 0)626        return r;627628    if (icons_enabled) {629        ctx->timing.icons_theme.start = time_begin();630        icon_theme_list_t icon_themes = icon_load_theme(icon_theme, !dmenu_enabled);631        if (tll_length(icon_themes) > 0)632            LOG_INFO("theme: %s", tll_front(icon_themes).name);633        else634            LOG_WARN("%s: icon theme not found", icon_theme);635        ctx->timing.icons_theme.stop = time_end();636637        ctx->timing.icons.start = time_begin();638        mtx_lock(ctx->icon_lock);639        {640            *ctx->themes = icon_themes;641            if (ctx->icon_size > 0) {642                icon_lookup_application_icons(643                    *ctx->themes, ctx->icon_size, apps);644645                if (dmenu_enabled) {646                    dmenu_try_icon_list(apps, *ctx->themes, ctx->icon_size);647                }648            }649        }650        mtx_unlock(ctx->icon_lock);651        ctx->timing.icons.stop = time_end();652653        r = send_event(ctx->event_fd, EVENT_ICONS_LOADED);654        if (r != 0)655            return r;656    }657658    return 0;659}660661static bool662process_event(struct context *ctx, enum event_type event)663{664    const struct config *conf = ctx->conf;665    struct wayland *wayl = ctx->wayl;666    struct application_list *apps = ctx->apps;667    struct matches *matches = ctx->matches;668    const char *select = ctx->select_initial;669    const size_t select_idx = ctx->select_initial_idx;670671    switch (event) {672    case EVENT_APPS_SOME_LOADED:673    case EVENT_APPS_ALL_LOADED: {674        if (event == EVENT_APPS_ALL_LOADED) {675            time_finish(676                ctx->timing.apps.start, ctx->timing.apps.stop, "apps loaded");677        }678        /* Update matches list, then refresh the GUI */679        matches_set_applications(matches, apps);680681        if (event == EVENT_APPS_ALL_LOADED) {682            if (conf->dmenu.exit_immediately_if_empty && apps->count == 0)683                return false;684685            matches_all_applications_loaded(matches);686687            if (conf->dmenu.enabled && conf->minimal_lines) {688                const size_t effective_lines = min(apps->count, conf->lines);689                matches_max_matches_per_page_set(matches, effective_lines);690                ctx->conf->lines = effective_lines;691                wayl_resized(wayl);692            }693694            wayl_ready_to_display(wayl);695        }696697        const size_t match_count = matches_get_count(matches);698        const size_t matches_per_page = matches_max_matches_per_page(matches);699700        if (conf->match_counter ||701            event == EVENT_APPS_ALL_LOADED ||702            match_count < matches_per_page)703        {704            /*705             * Only update matches if706             *   a) we're displaying a match counter707             *   b) all applications have been loaded708             *   c) a partial load will cause more matches to be displayed709             */710            matches_update_no_delay(matches);711            if (select_idx != 0) {712                if (!matches_selected_set(matches, select_idx)) {713                    LOG_ERR("couldn't select entry at index %zu", select_idx);714                    return false;715                }716            }717            else718                matches_selected_select(matches, select);719        }720721        /*722         * Allow displaying the menu if:723         *   --no-run-if-empty is NOT enabled, OR we have at least one entry724         * AND725         *   --minimal-lines is NOT enabled, OR we have at least --lines number of entries726         *727         * In short, display the window as soon as we are sure we728         * won't exit automatically (due to --no-run-if-empty), and we729         * know its final size.730         */731        if ((!conf->dmenu.exit_immediately_if_empty || apps->count > 0) &&732            (!(conf->dmenu.enabled && conf->minimal_lines) ||733             apps->count >= conf->lines))734        {735            wayl_ready_to_display(wayl);736        }737        break;738    }739740    case EVENT_ICONS_LOADED:741        /* Just need to refresh the GUI */742        time_finish(ctx->timing.icons_theme.start, ctx->timing.icons_theme.stop,743                    "icon themes loaded");744        time_finish(ctx->timing.icons.start, ctx->timing.icons.stop,745                    "icon paths resolved");746        matches_icons_loaded(matches);747        break;748749    default:750        LOG_ERR("unknown event: %llx", (long long)event);751        return false;752    }753754    wayl_refresh(wayl);755756    if (event == EVENT_APPS_ALL_LOADED)757        wayl_check_auto_select(wayl);758759    return true;760}761762/*763 * Called when the application list has been populated764 */765static bool766fdm_apps_populated(struct fdm *fdm, int fd, int events, void *data)767{768    struct context *ctx = data;769    uint64_t last_event = EVENT_INVALID;770    uint64_t event = EVENT_INVALID;771772    while (true) {773        ssize_t bytes = read(fd, &event, sizeof(event));774        if (bytes == 0) {775            if (event != EVENT_INVALID) {776                if (!process_event(ctx, event))777                    return false;778            }779            break;780        }781782        if (bytes != (ssize_t)sizeof(event)) {783            if (bytes < 0) {784                if (errno == EAGAIN) {785                    if (event != EVENT_INVALID) {786                        if (!process_event(ctx, event))787                            return false;788                    }789                    break;790                }791                LOG_ERRNO("failed to read event FD");792            } else793                LOG_ERR("partial read from event FD");794            return false;795        }796797        /* Coalesce multiple, identical events */798        if (last_event != EVENT_INVALID) {799            if (event != last_event) {800                if (!process_event(ctx, last_event))801                    return false;802            }803        }804805        last_event = event;806    }807808    return true;809}810811int812main(int argc, char *const *argv)813{814    time_init();815816    #define OPT_LETTER_SPACING               256817    #define OPT_LAUNCH_PREFIX                257818    #define OPT_SHOW_ACTIONS                 258819    #define OPT_MATCH_MODE                   259820    #define OPT_FUZZY_MIN_LENGTH             260821    #define OPT_FUZZY_MAX_LENGTH_DISCREPANCY 261822    #define OPT_FUZZY_MAX_DISTANCE           262823    #define OPT_DMENU_INDEX                  263824    #define OPT_LOG_LEVEL                    264825    #define OPT_LOG_COLORIZE                 265826    #define OPT_LOG_NO_SYSLOG                266827    #define OPT_PASSWORD                     267828    #define OPT_CONFIG                       268829    #define OPT_LAYER                        269830    #define OPT_ICON_THEME                   270831    #define OPT_KEYBOARD_FOCUS               271832    #define OPT_NO_EXIT_ON_KB_LOSS           272833    #define OPT_TABS                         273834    #define OPT_DMENU_NULL                   274835    #define OPT_FILTER_DESKTOP               275836    #define OPT_CHECK_CONFIG                 276837    #define OPT_SELECT                       277838    #define OPT_SELECT_INDEX                 278839    #define OPT_LIST_EXECS_IN_PATH           279840    #define OPT_X_MARGIN                     280841    #define OPT_Y_MARGIN                     281842    #define OPT_CACHE                        282843    #define OPT_RENDER_WORKERS               283844    #define OPT_PROMPT_COLOR                 284845    #define OPT_INPUT_COLOR                  285846    #define OPT_PROMPT_ONLY                  286847    #define OPT_COUNTER_COLOR                287848    #define OPT_USE_BOLD                     288849    #define OPT_MATCH_WORKERS                289850    #define OPT_NO_SORT                      290851    #define OPT_DELAYED_FILTER_MS            291852    #define OPT_DELAYED_FILTER_LIMIT         292853    #define OPT_PLACEHOLDER                  293854    #define OPT_PLACEHOLDER_COLOR            294855    #define OPT_SEARCH_TEXT                  295856    #define OPT_COUNTER                      296857    #define OPT_HIDE_WHEN_PROMPT_EMPTY       297858    #define OPT_DMENU_WITH_NTH               298859    #define OPT_DMENU_ACCEPT_NTH             299860    #define OPT_GAMMA_CORRECT                300861    #define OPT_PRINT_TIMINGS                301862    #define OPT_SCALING_FILTER               302863    #define OPT_MINIMAL_LINES                303864    #define OPT_HIDE_PROMPT                  304865    #define OPT_AUTO_SELECT                  305866    #define OPT_SELECTION_RADIUS             306867    #define OPT_NO_MOUSE                     307868    #define OPT_DMENU_NTH_DELIM              308869    #define OPT_DMENU_MATCH_NTH              309870    #define OPT_DMENU_ONLY_MATCH             310871    #define OPT_DMENU_MESSAGE                311872    #define OPT_DMENU_MESSAGE_MODE           312873    #define OPT_MESSAGE_COLOR                313874    #define OPT_GENERIC_OVERRIDE             314875876    static const struct option longopts[] = {877        {"config",               required_argument, 0, OPT_CONFIG},878        {"check-config",         no_argument,       0, OPT_CHECK_CONFIG},879        {"namespace",            required_argument, 0, 'n'},880        {"cache",                required_argument, 0, OPT_CACHE},881        {"output"  ,             required_argument, 0, 'o'},882        {"font",                 required_argument, 0, 'f'},883        {"use-bold",             no_argument,       0, OPT_USE_BOLD},884        {"dpi-aware",            required_argument, 0, 'D'},885        {"gamma-correct",        no_argument,       0, OPT_GAMMA_CORRECT},886        {"icon-theme",           required_argument, 0, OPT_ICON_THEME},887        {"no-icons",             no_argument,       0, 'I'},888        {"hide-before-typing", no_argument,     0, OPT_HIDE_WHEN_PROMPT_EMPTY},889        {"fields",               required_argument, 0, 'F'},890        {"password",             optional_argument, 0, OPT_PASSWORD},891        {"anchor",               required_argument, 0, 'a'},892        {"x-margin",             required_argument, 0, OPT_X_MARGIN},893        {"y-margin",             required_argument, 0, OPT_Y_MARGIN},894        {"select",               required_argument, 0, OPT_SELECT},895        {"select-index",         required_argument, 0, OPT_SELECT_INDEX},896        {"lines",                required_argument, 0, 'l'},897        {"minimal-lines",        no_argument,       0, OPT_MINIMAL_LINES},898        {"hide-prompt",          no_argument,       0, OPT_HIDE_PROMPT},899        {"width",                required_argument, 0, 'w'},900        {"tabs",                 required_argument, 0, OPT_TABS},901        {"horizontal-pad",       required_argument, 0, 'x'},902        {"vertical-pad",         required_argument, 0, 'y'},903        {"inner-pad",            required_argument, 0, 'P'},904        {"background-color",     required_argument, 0, 'b'},905        {"text-color",           required_argument, 0, 't'},906        {"message-color",        required_argument, 0, OPT_MESSAGE_COLOR},907        {"prompt-color",         required_argument, 0, OPT_PROMPT_COLOR},908        {"placeholder-color",    required_argument, 0, OPT_PLACEHOLDER_COLOR},909        {"input-color",          required_argument, 0, OPT_INPUT_COLOR},910        {"match-color",          required_argument, 0, 'm'},911        {"selection-color",      required_argument, 0, 's'},912        {"selection-text-color", required_argument, 0, 'S'},913        {"selection-match-color",required_argument, 0, 'M'},914        {"selection-radius",     required_argument, 0, OPT_SELECTION_RADIUS},915        {"counter-color",        required_argument, 0, OPT_COUNTER_COLOR},916        {"border-width",         required_argument, 0, 'B'},917        {"border-radius",        required_argument, 0, 'r'},918        {"border-color",         required_argument, 0, 'C'},919        {"prompt",               required_argument, 0, 'p'},920        {"prompt-only",          required_argument, 0, OPT_PROMPT_ONLY},921        {"placeholder",          required_argument, 0, OPT_PLACEHOLDER},922        {"search",               required_argument, 0, OPT_SEARCH_TEXT},923        {"terminal",             required_argument, 0, 'T'},924        {"show-actions",         no_argument,       0, OPT_SHOW_ACTIONS},925        {"match-mode",           required_argument, 0, OPT_MATCH_MODE},926        {"filter-desktop",       optional_argument, 0, OPT_FILTER_DESKTOP},927        {"fuzzy-min-length",     required_argument, 0, OPT_FUZZY_MIN_LENGTH},928        {"fuzzy-max-length-discrepancy", required_argument, 0, OPT_FUZZY_MAX_LENGTH_DISCREPANCY},929        {"fuzzy-max-distance",   required_argument, 0, OPT_FUZZY_MAX_DISTANCE},930        {"line-height",          required_argument, 0, 'H'},931        {"letter-spacing",       required_argument, 0, OPT_LETTER_SPACING},932        {"launch-prefix",        required_argument, 0, OPT_LAUNCH_PREFIX},933        {"layer",                required_argument, 0, OPT_LAYER},934        {"keyboard-focus",       required_argument, 0, OPT_KEYBOARD_FOCUS},935        {"no-exit-on-keyboard-focus-loss",   no_argument, 0, OPT_NO_EXIT_ON_KB_LOSS},936        {"list-executables-in-path",         no_argument, 0, OPT_LIST_EXECS_IN_PATH},937        {"render-workers",       required_argument, 0, OPT_RENDER_WORKERS},938        {"match-workers",        required_argument, 0, OPT_MATCH_WORKERS},939        {"no-sort",              no_argument,       0, OPT_NO_SORT},940        {"counter",              no_argument,       0, OPT_COUNTER},941        {"delayed-filter-ms",    required_argument, 0, OPT_DELAYED_FILTER_MS},942        {"delayed-filter-limit", required_argument, 0, OPT_DELAYED_FILTER_LIMIT},943        {"scaling-filter",       required_argument, 0, OPT_SCALING_FILTER},944        {"auto-select",          no_argument,       0, OPT_AUTO_SELECT},945        {"no-mouse",             no_argument,       0, OPT_NO_MOUSE},946947        /* dmenu mode */948        {"dmenu",                no_argument,       0, 'd'},949        {"dmenu0",               no_argument,       0, OPT_DMENU_NULL},950        {"no-run-if-empty",      no_argument,       0, 'R'},951        {"index",                no_argument,       0, OPT_DMENU_INDEX},952        {"nth-delimiter",        required_argument, 0, OPT_DMENU_NTH_DELIM},953        {"with-nth",             required_argument, 0, OPT_DMENU_WITH_NTH},954        {"accept-nth",           required_argument, 0, OPT_DMENU_ACCEPT_NTH},955        {"match-nth",            required_argument, 0, OPT_DMENU_MATCH_NTH},956        {"only-match",           no_argument,       0, OPT_DMENU_ONLY_MATCH},957        {"mesg",                 required_argument, 0, OPT_DMENU_MESSAGE},958        {"mesg-mode",            required_argument, 0, OPT_DMENU_MESSAGE_MODE},959960        /* Misc */961        {"override",             required_argument, 0, OPT_GENERIC_OVERRIDE},962        {"log-level",            required_argument, 0, OPT_LOG_LEVEL},963        {"log-colorize",         optional_argument, 0, OPT_LOG_COLORIZE},964        {"log-no-syslog",        no_argument,       0, OPT_LOG_NO_SYSLOG},965        {"version",              no_argument,       0, 'v'},966        {"print-timing-info",    no_argument,       0, OPT_PRINT_TIMINGS},967        {"help",                 no_argument,       0, 'h'},968        {NULL,                   no_argument,       0, 0},969    };970971    bool check_config = false;972    const char *config_path = NULL;973    enum log_class log_level = LOG_CLASS_WARNING;974    enum log_colorize log_colorize = LOG_COLORIZE_AUTO;975    bool log_syslog = true;976    const char *select = NULL;977    size_t select_idx = 0;978    config_override_t generic_overrides = tll_init();979980    struct {981        struct config conf;982983        bool dpi_aware_set:1;984        bool gamma_correct_set:1;985        bool match_fields_set:1;986        bool icons_disabled_set:1;987        bool hide_when_prompt_empty_set:1;988        bool anchor_set:1;989        bool x_margin_set : 1;990        bool y_margin_set : 1;991        bool lines_set:1;992        bool minimal_lines_set:1;993        bool hide_prompt_set:1;994        bool chars_set:1;995        bool tabs_set:1;996        bool pad_x_set:1;997        bool pad_y_set:1;998        bool pad_inner_set:1;999        bool background_color_set:1;1000        bool text_color_set:1;1001        bool message_color_set:1;1002        bool prompt_color_set:1;1003        bool input_color_set:1;1004        bool match_color_set:1;1005        bool selection_color_set:1;1006        bool selection_text_color_set:1;1007        bool selection_match_color_set:1;1008        bool selection_border_radius_set:1;1009        bool counter_color_set:1;1010        bool border_color_set:1;1011        bool border_size_set:1;1012        bool border_radius_set:1;1013        bool actions_enabled_set:1;1014        bool filter_desktop_set:1;1015        bool match_mode_set:1;1016        bool fuzzy_min_length_set:1;1017        bool fuzzy_max_length_discrepancy_set:1;1018        bool fuzzy_max_distance_set:1;1019        bool line_height_set:1;1020        bool letter_spacing_set:1;1021        bool dmenu_enabled_set:1;1022        bool dmenu_mode_set:1;1023        bool dmenu_exit_immediately_if_empty_set:1;1024        bool dmenu_delim_set:1;1025        bool dmenu_nth_delim_set:1;1026        bool dmenu_with_nth_set:1;1027        bool dmenu_accept_nth_set:1;1028        bool dmenu_match_nth_set:1;1029        bool dmenu_only_match_set:1;1030        bool mesg_mode_set:1;1031        bool layer_set:1;1032        bool keyboard_focus_set:1;1033        bool no_exit_on_keyboard_focus_loss_set:1;1034        bool render_workers_set:1;1035        bool match_workers_set:1;1036        bool prompt_only_set:1;1037        bool use_bold_set:1;1038        bool no_sort_set:1;1039        bool delayed_filter_ms_set:1;1040        bool delayed_filter_limit_set:1;1041        bool placeholder_color_set:1;1042        bool counter_set:1;1043        bool print_timing_info_set:1;1044        bool scaling_filter_set:1;1045        bool no_mouse_set:1;1046    } cmdline_overrides = {{0}};10471048    setlocale(LC_CTYPE, "");1049    setlocale(LC_MESSAGES, "");10501051    /* Auto-enable dmenu mode if invoked through a ‘dmenu’ symlink */1052    if (argv[0] != NULL) {1053        char *copy = xstrdup(argv[0]);1054        const char *name = basename(copy);1055        if (name != NULL && strcmp(name, "dmenu") == 0) {1056            cmdline_overrides.conf.dmenu.enabled = true;1057            cmdline_overrides.dmenu_enabled_set = true;1058        }10591060        free(copy);1061    }10621063    while (true) {1064        int c = getopt_long(argc, argv, ":n:o:f:D:IF:ia:l:w:x:y:p:P:b:t:m:s:S:M:B:r:C:T:dRvh", longopts, NULL);1065        if (c == -1)1066            break;10671068        switch (c) {1069        case OPT_CONFIG:1070            config_path = optarg;1071            break;10721073        case OPT_CHECK_CONFIG:1074            check_config = true;1075            break;10761077        case 'n':1078            cmdline_overrides.conf.namespace = optarg;1079            break;10801081        case OPT_CACHE:1082            cmdline_overrides.conf.cache_path = optarg;1083            break;10841085        case 'o':1086            cmdline_overrides.conf.output = optarg;1087            break;10881089        case 'f':1090            cmdline_overrides.conf.font = optarg;1091            break;10921093        case OPT_USE_BOLD:1094            cmdline_overrides.conf.use_bold = true;1095            cmdline_overrides.use_bold_set = true;1096            break;10971098        case 'D':1099            if (strcmp(optarg, "auto") == 0)1100                cmdline_overrides.conf.dpi_aware = DPI_AWARE_AUTO;1101            else if (strcmp(optarg, "no") == 0)1102                cmdline_overrides.conf.dpi_aware = DPI_AWARE_NO;1103            else if (strcmp(optarg, "yes") == 0)1104                cmdline_overrides.conf.dpi_aware = DPI_AWARE_YES;1105            else {1106                fprintf(1107                    stderr,1108                    "%s: invalid value for dpi-aware: "1109                    "must be one of 'auto', 'no', or 'yes'\n",1110                    optarg);1111                return EXIT_FAILURE;1112            }1113            cmdline_overrides.dpi_aware_set = true;1114            break;11151116        case OPT_GAMMA_CORRECT:1117            cmdline_overrides.conf.gamma_correct = true;1118            cmdline_overrides.gamma_correct_set = true;1119            break;11201121        case 'i':1122            /* Ignore (this flag means case insensitive search in1123             * other fuzzel-like utilities) */1124            break;11251126        case OPT_ICON_THEME:1127            cmdline_overrides.conf.icon_theme = optarg;1128            break;11291130        case 'I':1131            cmdline_overrides.conf.icons_enabled = false;1132            cmdline_overrides.icons_disabled_set = true;1133            break;11341135        case OPT_HIDE_WHEN_PROMPT_EMPTY:1136            cmdline_overrides.conf.hide_when_prompt_empty = true;1137            cmdline_overrides.hide_when_prompt_empty_set = true;1138            break;11391140        case 'F': {1141            static const struct {1142                const char *name;1143                enum match_fields value;1144            } map[] = {1145                {"filename", MATCH_FILENAME},1146                {"name", MATCH_NAME},1147                {"generic", MATCH_GENERIC},1148                {"exec", MATCH_EXEC},1149                {"categories", MATCH_CATEGORIES},1150                {"keywords", MATCH_KEYWORDS},1151                {"comment", MATCH_COMMENT},1152            };11531154            cmdline_overrides.conf.match_fields = 0;1155            for (const char *f = strtok(optarg, ", ");1156                 f != NULL;1157                 f = strtok(NULL, ", "))1158            {1159                enum match_fields field = 0;11601161                for (size_t i = 0; i < ALEN(map); i++) {1162                    if (strcmp(f, map[i].name) == 0) {1163                        field = map[i].value;1164                        break;1165                    }1166                }11671168                if (field > 0)1169                    cmdline_overrides.conf.match_fields |= field;1170                else {1171                    char valid_names[128] = {0};1172                    size_t idx = 0;1173                    for (size_t i = 0; i < ALEN(map); i++) {1174                        idx += xsnprintf(1175                            &valid_names[idx], sizeof(valid_names) - idx,1176                            "'%s', ", map[i].name);1177                    }11781179                    valid_names[idx - 2] = '\0';11801181                    fprintf(1182                        stderr,1183                        "%s: invalid field name: must be one of %s\n",1184                        f, valid_names);1185                    return EXIT_FAILURE;1186                }1187            }1188            cmdline_overrides.match_fields_set = true;1189            break;1190        }11911192        case OPT_PASSWORD: {1193            char32_t password_char = U'\0';1194            if (optarg != NULL) {1195                char32_t *wide_optarg = ambstoc32(optarg);1196                if (wide_optarg == NULL){1197                    fprintf(stderr, "%s: invalid password character\n", optarg);1198                    return EXIT_FAILURE;1199                }12001201                if (c32len(wide_optarg) > 1) {1202                    fprintf(1203                        stderr,1204                        "%s: password character must be a single character\n",1205                        optarg);1206                    free(wide_optarg);1207                    return EXIT_FAILURE;1208                }12091210                password_char = wide_optarg[0];1211                free(wide_optarg);1212                cmdline_overrides.conf.password_mode.character_set = true;1213            }12141215            cmdline_overrides.conf.password_mode.enabled = true;1216            cmdline_overrides.conf.password_mode.character = password_char;1217            break;1218        }12191220        case 'T':1221            cmdline_overrides.conf.terminal = optarg;1222            break;12231224        case 'a': {1225            enum anchors anchor;1226            bool valid_anchor = false;12271228            for (size_t i = 0; anchors_map[i].name != NULL; i++) {1229                if (strcmp(optarg, anchors_map[i].name) == 0) {1230                    anchor = anchors_map[i].value;1231                    valid_anchor = true;1232                    break;1233                }1234            }12351236            if (!valid_anchor) {1237                fprintf(stderr, "%s: invalid anchor\n", optarg);1238                return EXIT_FAILURE;1239            }12401241            cmdline_overrides.conf.anchor = anchor;1242            cmdline_overrides.anchor_set = true;1243            break;1244        }12451246        case OPT_X_MARGIN:1247          if (sscanf(optarg, "%u", &cmdline_overrides.conf.margin.x) != 1) {1248            fprintf(stderr, "%s: invalid horizontal margin\n", optarg);1249            return EXIT_FAILURE;1250          }1251          cmdline_overrides.x_margin_set = true;1252          break;12531254        case OPT_Y_MARGIN:1255          if (sscanf(optarg, "%u", &cmdline_overrides.conf.margin.y) != 1) {1256            fprintf(stderr, "%s: invalid vertical margin\n", optarg);1257            return EXIT_FAILURE;1258          }1259          cmdline_overrides.y_margin_set = true;1260          break;12611262        case OPT_SELECT:1263            select = optarg;1264            break;12651266        case OPT_SELECT_INDEX:1267            if (sscanf(optarg, "%zu", &select_idx) != 1) {1268                fprintf(1269                    stderr,1270                    "%s: invalid selected index (must be an integer)\n",1271                    optarg);1272                return EXIT_FAILURE;1273            }1274            break;12751276        case 'l':1277            if (sscanf(optarg, "%u", &cmdline_overrides.conf.lines) != 1) {1278                fprintf(stderr, "%s: invalid line count\n", optarg);1279                return EXIT_FAILURE;1280            }1281            cmdline_overrides.lines_set = true;1282            break;12831284        case OPT_MINIMAL_LINES:1285            cmdline_overrides.conf.minimal_lines = true;1286            cmdline_overrides.minimal_lines_set = true;1287            break;12881289        case OPT_HIDE_PROMPT:1290            cmdline_overrides.conf.hide_prompt = true;1291            cmdline_overrides.hide_prompt_set = true;1292            break;12931294        case 'w':1295            if (sscanf(optarg, "%u", &cmdline_overrides.conf.chars) != 1) {1296                fprintf(stderr, "%s: invalid width\n", optarg);1297                return EXIT_FAILURE;1298            }1299            cmdline_overrides.chars_set = true;1300            break;13011302        case OPT_TABS:1303            if (sscanf(optarg, "%u", &cmdline_overrides.conf.tabs) != 1) {1304                fprintf(stderr, "%s: invalid tab count\n", optarg);1305                return EXIT_FAILURE;1306            }1307            cmdline_overrides.tabs_set = true;1308            break;13091310        case 'x':1311            if (sscanf(optarg, "%u", &cmdline_overrides.conf.pad.x) != 1) {1312                fprintf(stderr, "%s: invalid padding\n", optarg);1313                return EXIT_FAILURE;1314            }1315            cmdline_overrides.pad_x_set = true;1316            break;13171318        case 'y':1319            if (sscanf(optarg, "%u", &cmdline_overrides.conf.pad.y) != 1) {1320                fprintf(stderr, "%s: invalid padding\n", optarg);1321                return EXIT_FAILURE;1322            }1323            cmdline_overrides.pad_y_set = true;1324            break;13251326        case 'P':1327            if (sscanf(optarg, "%u", &cmdline_overrides.conf.pad.inner) != 1) {1328                fprintf(stderr, "%s: invalid padding\n", optarg);1329                return EXIT_FAILURE;1330            }1331            cmdline_overrides.pad_inner_set = true;1332            break;13331334        case 'p':1335            free(cmdline_overrides.conf.prompt);1336            cmdline_overrides.conf.prompt = ambstoc32(optarg);13371338            if (cmdline_overrides.conf.prompt == NULL) {1339                fprintf(stderr, "%s: invalid prompt\n", optarg);1340                return EXIT_FAILURE;1341            }13421343            break;13441345        case OPT_PROMPT_ONLY:1346            free(cmdline_overrides.conf.prompt);1347            cmdline_overrides.conf.prompt = ambstoc32(optarg);13481349            if (cmdline_overrides.conf.prompt == NULL) {1350                fprintf(stderr, "%s: invalid prompt\n", optarg);1351                return EXIT_FAILURE;1352            }13531354            cmdline_overrides.prompt_only_set = true;1355            cmdline_overrides.conf.prompt_only = true;1356            break;13571358        case OPT_PLACEHOLDER:1359            free(cmdline_overrides.conf.placeholder);1360            cmdline_overrides.conf.placeholder = ambstoc32(optarg);13611362            if (cmdline_overrides.conf.placeholder == NULL) {1363                fprintf(stderr, "%s: invalid placeholder\n", optarg);1364                return EXIT_FAILURE;1365            }13661367            break;13681369        case OPT_SEARCH_TEXT:1370            free(cmdline_overrides.conf.search_text);1371            cmdline_overrides.conf.search_text = ambstoc32(optarg);13721373            if (cmdline_overrides.conf.search_text == NULL) {1374                fprintf(stderr, "%s: invalid search text\n", optarg);1375                return EXIT_FAILURE;1376            }13771378            break;13791380        case 'b': {1381            const char *clr_start = optarg;1382            if (clr_start[0] == '#')1383                clr_start++;13841385            errno = 0;1386            char *end = NULL;1387            uint32_t background = strtoul(clr_start, &end, 16);1388            if (errno != 0 || end == NULL || *end != '\0' || (end - clr_start) != 8) {1389                fprintf(stderr, "background-color: %s: invalid color\n",1390                        optarg);1391                return EXIT_FAILURE;1392            }1393            cmdline_overrides.conf.colors.background =1394                conf_hex_to_rgba(background);1395            cmdline_overrides.background_color_set = true;1396            break;1397        }13981399        case 't': {1400            const char *clr_start = optarg;1401            if (clr_start[0] == '#')1402                clr_start++;14031404            errno = 0;1405            char *end = NULL;1406            uint32_t text_color = strtoul(clr_start, &end, 16);1407            if (errno != 0 || end == NULL || *end != '\0' || (end - clr_start) != 8) {1408                fprintf(stderr, "text-color: %s: invalid color\n", optarg);1409                return EXIT_FAILURE;1410            }1411            cmdline_overrides.conf.colors.text = conf_hex_to_rgba(text_color);1412            cmdline_overrides.text_color_set = true;1413            break;1414        }14151416        case OPT_MESSAGE_COLOR: {1417            const char *clr_start = optarg;1418            if (clr_start[0] == '#')1419                clr_start++;14201421            errno = 0;1422            char *end = NULL;1423            uint32_t message_color = strtoul(clr_start, &end, 16);1424            if (errno != 0 || end == NULL || *end != '\0' || (end - clr_start) != 8) {1425                fprintf(stderr, "message-color: %s: invalid color\n", optarg);1426                return EXIT_FAILURE;1427            }1428            cmdline_overrides.conf.colors.message = conf_hex_to_rgba(message_color);1429            cmdline_overrides.message_color_set = true;1430            break;1431        }14321433        case OPT_PROMPT_COLOR: {1434            const char *clr_start = optarg;1435            if (clr_start[0] == '#')1436                clr_start++;14371438            errno = 0;1439            char *end = NULL;1440            uint32_t prompt_color = strtoul(clr_start, &end, 16);1441            if (errno != 0 || end == NULL || *end != '\0' || (end - clr_start) != 8) {1442                fprintf(stderr, "prompt-color: %s: invalid color\n", optarg);1443                return EXIT_FAILURE;1444            }1445            cmdline_overrides.conf.colors.prompt = conf_hex_to_rgba(prompt_color);1446            cmdline_overrides.prompt_color_set = true;1447            break;1448        }14491450        case OPT_PLACEHOLDER_COLOR: {1451            const char *clr_start = optarg;1452            if (clr_start[0] == '#')1453                clr_start++;14541455            errno = 0;1456            char *end = NULL;1457            uint32_t placeholder_color = strtoul(clr_start, &end, 16);1458            if (errno != 0 || end == NULL || *end != '\0' || (end - clr_start) != 8) {1459                fprintf(stderr, "placeholder-color: %s: invalid color\n", optarg);1460                return EXIT_FAILURE;1461            }1462            cmdline_overrides.conf.colors.placeholder = conf_hex_to_rgba(placeholder_color);1463            cmdline_overrides.placeholder_color_set = true;1464            break;1465        }14661467        case OPT_INPUT_COLOR: {1468            const char *clr_start = optarg;1469            if (clr_start[0] == '#')1470                clr_start++;14711472            errno = 0;1473            char *end = NULL;1474            uint32_t input_color = strtoul(clr_start, &end, 16);1475            if (errno != 0 || end == NULL || *end != '\0' || (end - clr_start) != 8) {1476                fprintf(stderr, "prompt-color: %s: invalid color\n", optarg);1477                return EXIT_FAILURE;1478            }1479            cmdline_overrides.conf.colors.input = conf_hex_to_rgba(input_color);1480            cmdline_overrides.input_color_set = true;1481            break;1482        }14831484        case 'm': {1485            const char *clr_start = optarg;1486            if (clr_start[0] == '#')1487                clr_start++;14881489            errno = 0;1490            char *end = NULL;1491            uint32_t match_color = strtoul(clr_start, &end, 16);1492            if (errno != 0 || end == NULL || *end != '\0' || (end - clr_start) != 8) {1493                fprintf(stderr, "match-color: %s: invalid color\n", optarg);1494                return EXIT_FAILURE;1495            }1496            cmdline_overrides.conf.colors.match =1497                conf_hex_to_rgba(match_color);1498            cmdline_overrides.match_color_set = true;1499            break;1500        }15011502        case 's': {1503            const char *clr_start = optarg;1504            if (clr_start[0] == '#')1505                clr_start++;15061507            errno = 0;1508            char *end = NULL;1509            uint32_t selection_color = strtoul(clr_start, &end, 16);1510            if (errno != 0 || end == NULL || *end != '\0' || (end - clr_start) != 8) {1511                fprintf(stderr, "selection-color: %s: invalid color\n", optarg);1512                return EXIT_FAILURE;1513            }1514            cmdline_overrides.conf.colors.selection =1515                conf_hex_to_rgba(selection_color);1516            cmdline_overrides.selection_color_set = true;1517            break;1518        }15191520        case 'S': {1521            const char *clr_start = optarg;1522            if (clr_start[0] == '#')1523                clr_start++;15241525            errno = 0;1526            char *end = NULL;1527            uint32_t selection_text_color = strtoul(clr_start, &end, 16);1528            if (errno != 0 || end == NULL || *end != '\0' || (end - clr_start) != 8) {1529                fprintf(stderr, "selection-text-color: %s: invalid color\n",1530                        optarg);1531                return EXIT_FAILURE;1532            }1533            cmdline_overrides.conf.colors.selection_text =1534                conf_hex_to_rgba(selection_text_color);1535            cmdline_overrides.selection_text_color_set = true;1536            break;1537        }15381539        case OPT_SELECTION_RADIUS: {1540            if (sscanf(optarg, "%u", &cmdline_overrides.conf.selection_border.radius) != 1) {1541                fprintf(stderr, "%s: invalid selection border radius (must be an integer)\n",1542                        optarg);1543                return EXIT_FAILURE;1544            }1545            cmdline_overrides.selection_border_radius_set = true;1546            break;1547        }15481549        case 'M': {1550            const char *clr_start = optarg;1551            if (clr_start[0] == '#')1552                clr_start++;15531554            errno = 0;1555            char *end = NULL;1556            uint32_t selection_match_color = strtoul(clr_start, &end, 16);1557            if (errno != 0 || end == NULL || *end != '\0' || (end - clr_start) != 8) {1558                fprintf(stderr, "selection-match-color: %s: invalid color\n",1559                        optarg);1560                return EXIT_FAILURE;1561            }1562            cmdline_overrides.conf.colors.selection_match =1563                conf_hex_to_rgba(selection_match_color);1564            cmdline_overrides.selection_match_color_set = true;1565            break;1566        }15671568        case OPT_COUNTER_COLOR: {1569            const char *clr_start = optarg;1570            if (clr_start[0] == '#')1571                clr_start++;15721573            errno = 0;1574            char *end = NULL;1575            uint32_t count_color = strtoul(clr_start, &end, 16);1576            if (errno != 0 || end == NULL || *end != '\0' || (end - clr_start) != 8) {1577                fprintf(stderr, "counter-color: %s: invalid color\n",1578                        optarg);1579                return EXIT_FAILURE;1580            }1581            cmdline_overrides.conf.colors.counter = conf_hex_to_rgba(count_color);1582            cmdline_overrides.counter_color_set = true;1583            break;1584        }158515861587        case 'B':1588            if (sscanf(optarg, "%u", &cmdline_overrides.conf.border.size) != 1) {1589                fprintf(1590                    stderr,1591                    "%s: invalid border width (must be an integer)\n", optarg);1592                return EXIT_FAILURE;1593            }1594            cmdline_overrides.border_size_set = true;1595            break;15961597        case 'r':1598            if (sscanf(optarg, "%u", &cmdline_overrides.conf.border.radius) != 1) {1599                fprintf(stderr, "%s: invalid border radius (must be an integer)\n",1600                        optarg);1601                return EXIT_FAILURE;1602            }1603            cmdline_overrides.border_radius_set = true;1604            break;16051606        case 'C': {1607            const char *clr_start = optarg;1608            if (clr_start[0] == '#')1609                clr_start++;16101611            errno = 0;1612            char *end = NULL;1613            uint32_t border_color = strtoul(clr_start, &end, 16);1614            if (errno != 0 || end == NULL || *end != '\0' || (end - clr_start) != 8) {1615                fprintf(stderr, "border-color: %s: invalid color\n", optarg);1616                return EXIT_FAILURE;1617            }1618            cmdline_overrides.conf.colors.border =1619                conf_hex_to_rgba(border_color);1620            cmdline_overrides.border_color_set = true;1621            break;1622        }16231624        case OPT_SHOW_ACTIONS:1625            cmdline_overrides.actions_enabled_set = true;1626            cmdline_overrides.conf.actions_enabled = true;1627            break;16281629        case OPT_MATCH_MODE:1630            if (strcmp(optarg, "exact") == 0)1631                cmdline_overrides.conf.match_mode = MATCH_MODE_EXACT;1632            else if (strcmp(optarg, "fzf") == 0)1633                cmdline_overrides.conf.match_mode = MATCH_MODE_FZF;1634            else if (strcmp(optarg, "fuzzy") == 0)1635                cmdline_overrides.conf.match_mode = MATCH_MODE_FUZZY;1636            else {1637                fprintf(stderr, "%s: invalid match-mode. Must be 'exact', 'fuzzy' or 'fzf'\n", optarg);1638                return EXIT_FAILURE;1639            }16401641            cmdline_overrides.match_mode_set = true;1642            break;16431644        case OPT_FILTER_DESKTOP:1645            cmdline_overrides.filter_desktop_set = true;1646            if (optarg != NULL && strcasecmp(optarg, "no") == 0)1647                cmdline_overrides.conf.filter_desktop = false;1648            else if (optarg != NULL) {1649                fprintf(stderr, "%s: invalid filter-desktop option\n", optarg);1650                return EXIT_FAILURE;1651            }1652            else1653                cmdline_overrides.conf.filter_desktop = true;1654            break;16551656        case OPT_FUZZY_MIN_LENGTH:1657            if (sscanf(optarg, "%zu", &cmdline_overrides.conf.fuzzy.min_length) != 1) {1658                fprintf(1659                    stderr,1660                    "%s: invalid fuzzy min length (must be an integer)\n",1661                    optarg);1662                return EXIT_FAILURE;1663            }1664            cmdline_overrides.fuzzy_min_length_set = true;1665            break;16661667        case OPT_FUZZY_MAX_LENGTH_DISCREPANCY:1668            if (sscanf(optarg, "%zu", &cmdline_overrides.conf.fuzzy.max_length_discrepancy) != 1) {1669                fprintf(1670                    stderr,1671                    "%s: invalid fuzzy max length discrepancy "1672                    "(must be an integer)\n", optarg);1673                return EXIT_FAILURE;1674            }1675            cmdline_overrides.fuzzy_max_length_discrepancy_set = true;1676            break;16771678        case OPT_FUZZY_MAX_DISTANCE:1679            if (sscanf(optarg, "%zu", &cmdline_overrides.conf.fuzzy.max_distance) != 1) {1680                fprintf(1681                    stderr,1682                    "%s: invalid fuzzy max distance (must be an integer)\n",1683                    optarg);1684                return EXIT_FAILURE;1685            }1686            cmdline_overrides.fuzzy_max_distance_set = true;1687            break;16881689        case OPT_LIST_EXECS_IN_PATH:1690            cmdline_overrides.conf.list_executables_in_path = true;1691            break;16921693        case 'H': { /* line-height */1694            if (!pt_or_px_from_string(optarg, &cmdline_overrides.conf.line_height))1695                return EXIT_FAILURE;1696            cmdline_overrides.line_height_set = true;1697            break;1698        }16991700        case OPT_LETTER_SPACING: {1701            if (!pt_or_px_from_string(optarg, &cmdline_overrides.conf.letter_spacing))1702                return EXIT_FAILURE;1703            cmdline_overrides.letter_spacing_set = true;1704            break;1705        }17061707        case OPT_LAUNCH_PREFIX: {1708            cmdline_overrides.conf.launch_prefix = optarg;1709            break;1710        }17111712        case OPT_LAYER:1713            if (strcasecmp(optarg, "top") == 0)1714                cmdline_overrides.conf.layer = ZWLR_LAYER_SHELL_V1_LAYER_TOP;1715            else if (strcasecmp(optarg, "overlay") == 0)1716                cmdline_overrides.conf.layer = ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY;1717            else {1718                fprintf(1719                    stderr,1720                    "%s: invalid layer. Must be one of 'top', 'overlay'\n",1721                    optarg);1722                return EXIT_FAILURE;1723            }1724            cmdline_overrides.layer_set = true;1725            break;17261727        case OPT_KEYBOARD_FOCUS:1728            if (strcasecmp(optarg, "exclusive") == 0)1729                cmdline_overrides.conf.keyboard_focus = ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE;1730            else if (strcasecmp(optarg, "on-demand") == 0)1731                cmdline_overrides.conf.keyboard_focus = ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND;1732            else {1733                fprintf(1734                    stderr,1735                    "%s: invalid keyboard-focus. Must be one of 'exclusive', 'on-demand'\n",1736                    optarg);1737                return EXIT_FAILURE;1738            }1739            cmdline_overrides.keyboard_focus_set = true;1740            break;17411742        case OPT_NO_EXIT_ON_KB_LOSS:1743            cmdline_overrides.conf.exit_on_kb_focus_loss = false;1744            cmdline_overrides.no_exit_on_keyboard_focus_loss_set = true;1745            break;17461747        case 'd':1748            cmdline_overrides.conf.dmenu.enabled = true;1749            cmdline_overrides.dmenu_enabled_set = true;1750            break;17511752        case OPT_DMENU_NULL:1753            cmdline_overrides.conf.dmenu.enabled = true;1754            cmdline_overrides.conf.dmenu.delim = '\0';1755            cmdline_overrides.dmenu_enabled_set = true;1756            cmdline_overrides.dmenu_delim_set = true;1757            break;17581759        case 'R':1760            cmdline_overrides.conf.dmenu.exit_immediately_if_empty = true;1761            cmdline_overrides.dmenu_exit_immediately_if_empty_set = true;1762            break;17631764        case OPT_DMENU_INDEX:1765            cmdline_overrides.conf.dmenu.mode = DMENU_MODE_INDEX;1766            cmdline_overrides.dmenu_mode_set = true;1767            break;17681769        case OPT_DMENU_NTH_DELIM:1770            if (strlen(optarg) != 1) {1771                fprintf(1772                    stderr,1773                    "%s: invalid nth-delimiter. Must be a single ASCII character",1774                    optarg);1775                return EXIT_FAILURE;1776            }17771778            cmdline_overrides.conf.dmenu.nth_delim = optarg[0];1779            cmdline_overrides.dmenu_nth_delim_set = true;1780            break;17811782        case OPT_DMENU_WITH_NTH: {1783            free(cmdline_overrides.conf.dmenu.with_nth_format);1784            cmdline_overrides.conf.dmenu.with_nth_format = NULL;17851786            unsigned int with_nth_idx;1787            if (sscanf(optarg, "%u", &with_nth_idx) == 1) {1788                if (with_nth_idx == 0) {1789                    /* Do nothing more - i.e. leave it unset */1790                } else {1791                    cmdline_overrides.conf.dmenu.with_nth_format =1792                        xasprintf("{%u}", with_nth_idx);1793                }1794            } else if (optarg[0] != '\0')1795                cmdline_overrides.conf.dmenu.with_nth_format = xstrdup(optarg);1796            cmdline_overrides.dmenu_with_nth_set = true;1797            break;1798        }17991800        case OPT_DMENU_ACCEPT_NTH: {1801            free(cmdline_overrides.conf.dmenu.accept_nth_format);1802            cmdline_overrides.conf.dmenu.accept_nth_format = NULL;18031804            unsigned int accept_nth_idx;1805            if (sscanf(optarg, "%u", &accept_nth_idx) == 1) {1806                if (accept_nth_idx == 0) {1807                    /* Do nothing more - i.e. leave it unset */1808                } else {1809                    cmdline_overrides.conf.dmenu.accept_nth_format =1810                        xasprintf("{%u}", accept_nth_idx);1811                }1812            } else if (optarg[0] != '\0')1813                cmdline_overrides.conf.dmenu.accept_nth_format = xstrdup(optarg);18141815            cmdline_overrides.dmenu_accept_nth_set = true;1816            break;1817        }18181819        case OPT_DMENU_MATCH_NTH: {1820            free(cmdline_overrides.conf.dmenu.match_nth_format);1821            cmdline_overrides.conf.dmenu.match_nth_format = NULL;18221823            unsigned int match_nth_idx;1824            if (sscanf(optarg, "%u", &match_nth_idx) == 1) {1825                if (match_nth_idx == 0) {1826                    /* Do nothing more - i.e. leave it unset */1827                } else {1828                    cmdline_overrides.conf.dmenu.match_nth_format =1829                        xasprintf("{%u}", match_nth_idx);1830                }1831            } else if (optarg[0] != '\0')1832                cmdline_overrides.conf.dmenu.match_nth_format = xstrdup(optarg);18331834            cmdline_overrides.dmenu_match_nth_set = true;1835            break;1836        }18371838        case OPT_DMENU_ONLY_MATCH:1839            cmdline_overrides.conf.dmenu.only_match = true;1840            cmdline_overrides.dmenu_only_match_set = true;1841            break;18421843        case OPT_DMENU_MESSAGE:1844            free(cmdline_overrides.conf.message);1845            cmdline_overrides.conf.message = ambstoc32(optarg);18461847            if (cmdline_overrides.conf.message == NULL) {1848                fprintf(stderr, "%s: invalid dmenu message\n", optarg);1849                return EXIT_FAILURE;1850            }18511852            break;18531854        case OPT_DMENU_MESSAGE_MODE:1855            if (strcmp(optarg, "wrap") == 0)1856                cmdline_overrides.conf.message_mode = MESSAGE_MODE_WRAP;1857            else if (strcmp(optarg, "expand") == 0)1858                cmdline_overrides.conf.message_mode = MESSAGE_MODE_EXPAND;1859            else {1860                fprintf(stderr, "%s: invalid mesg-mode. Must be 'wrap' or 'expand'\n", optarg);1861                return EXIT_FAILURE;1862            }18631864            cmdline_overrides.mesg_mode_set = true;1865            break;18661867        case OPT_LOG_LEVEL: {1868            int lvl = log_level_from_string(optarg);1869            if (lvl < 0) {1870                fprintf(1871                    stderr,1872                    "--log-level: %s: argument must be one of %s\n",1873                    optarg, log_level_string_hint());1874                return EXIT_FAILURE;1875            }1876            log_level = lvl;1877            break;1878        }18791880        case OPT_LOG_COLORIZE:1881            if (optarg == NULL || strcmp(optarg, "auto") == 0)1882                log_colorize = LOG_COLORIZE_AUTO;1883            else if (strcmp(optarg, "never") == 0)1884                log_colorize = LOG_COLORIZE_NEVER;1885            else if (strcmp(optarg, "always") == 0)1886                log_colorize = LOG_COLORIZE_ALWAYS;1887            else {1888                fprintf(stderr, "--log-colorize: %s: argument must be one of 'never', 'always' or 'auto'\n", optarg);1889                return EXIT_FAILURE;1890            }1891            break;18921893        case OPT_LOG_NO_SYSLOG:1894            log_syslog = false;1895            break;18961897        case OPT_RENDER_WORKERS:1898            if (sscanf(optarg, "%hu", &cmdline_overrides.conf.render_worker_count) != 1) {1899                fprintf(1900                    stderr,1901                    "%s: invalid value for render-workers (must be an integer)\n",1902                    optarg);1903                return EXIT_FAILURE;1904            }19051906            cmdline_overrides.render_workers_set = true;1907            break;19081909        case OPT_MATCH_WORKERS:1910            if (sscanf(optarg, "%hu", &cmdline_overrides.conf.match_worker_count) != 1) {1911                fprintf(1912                    stderr,1913                    "%s: invalid value for match-workers (must be an integer)\n",1914                    optarg);1915                return EXIT_FAILURE;1916            }19171918            cmdline_overrides.match_workers_set = true;1919            break;19201921        case OPT_NO_SORT:1922            cmdline_overrides.conf.sort_result = false;1923            cmdline_overrides.no_sort_set = true;1924            break;19251926        case OPT_COUNTER:1927            cmdline_overrides.conf.match_counter = true;1928            cmdline_overrides.counter_set = true;1929            break;19301931        case OPT_DELAYED_FILTER_MS:1932            if (sscanf(optarg, "%u", &cmdline_overrides.conf.delayed_filter_ms) != 1) {1933                fprintf(stderr, "%s: invalid delayed-filter-ms (must be an integer)\n",1934                        optarg);1935                return EXIT_FAILURE;1936            }1937            cmdline_overrides.delayed_filter_ms_set = true;1938            break;19391940        case OPT_DELAYED_FILTER_LIMIT:1941            if (sscanf(optarg, "%u", &cmdline_overrides.conf.delayed_filter_limit) != 1) {1942                fprintf(stderr, "%s: invalid delayed-filter-limit (must be an integer)\n",1943                        optarg);1944                return EXIT_FAILURE;1945            }1946            cmdline_overrides.delayed_filter_limit_set = true;1947            break;19481949        case OPT_SCALING_FILTER:1950            if (strcmp(optarg, "none") == 0)1951                cmdline_overrides.conf.png_scaling_filter = SCALING_FILTER_NONE;1952            else if (strcmp(optarg, "nearest") == 0)1953                cmdline_overrides.conf.png_scaling_filter = SCALING_FILTER_NEAREST;1954            else if (strcmp(optarg, "bilinear") == 0)1955                cmdline_overrides.conf.png_scaling_filter = SCALING_FILTER_BILINEAR;1956            else if (strcmp(optarg, "box") == 0)1957                cmdline_overrides.conf.png_scaling_filter = SCALING_FILTER_BOX;1958            else if (strcmp(optarg, "linear") == 0)1959                cmdline_overrides.conf.png_scaling_filter = SCALING_FILTER_LINEAR;1960            else if (strcmp(optarg, "cubic") == 0)1961                cmdline_overrides.conf.png_scaling_filter = SCALING_FILTER_CUBIC;1962            else if (strcmp(optarg, "lanczos2") == 0)1963                cmdline_overrides.conf.png_scaling_filter = SCALING_FILTER_LANCZOS2;1964            else if (strcmp(optarg, "lanczos3") == 0)1965                cmdline_overrides.conf.png_scaling_filter = SCALING_FILTER_LANCZOS3;1966            else if (strcmp(optarg, "lanczos3-stretched") == 0)1967                cmdline_overrides.conf.png_scaling_filter = SCALING_FILTER_LANCZOS3_STRETCHED;1968            else {1969                fprintf(stderr, "%s: invalid scaling-filter", optarg);1970                return EXIT_FAILURE;1971            }1972            cmdline_overrides.scaling_filter_set = true;1973            break;19741975        case OPT_PRINT_TIMINGS:1976            cmdline_overrides.conf.print_timing_info = true;1977            cmdline_overrides.print_timing_info_set = true;1978            break;19791980        case OPT_AUTO_SELECT:1981            cmdline_overrides.conf.auto_select = true;1982            break;19831984        case OPT_NO_MOUSE:1985            cmdline_overrides.conf.enable_mouse = false;1986            cmdline_overrides.no_mouse_set = true;1987            break;19881989        case OPT_GENERIC_OVERRIDE:1990            tll_push_back(generic_overrides, strdup(optarg));1991            break;19921993        case 'v':1994            printf("fuzzel %s\n", version_and_features());1995            return EXIT_SUCCESS;19961997        case 'h':1998            print_usage(argv[0]);1999            return EXIT_SUCCESS;2000

The first 2,000 of 2,452 lines.