diff options
author | John Hawthorn <john.hawthorn@gmail.com> | 2017-01-31 18:13:27 -0800 |
---|---|---|
committer | John Hawthorn <john.hawthorn@gmail.com> | 2017-01-31 18:25:35 -0800 |
commit | 5aeaaa3de01b98e935dab1367cf2a7900feaecf3 (patch) | |
tree | ea58351bc9ad08f36c5db15cd13359ca5a35f5f9 /src/options.c | |
parent | 15b29a48af2175f620d0acad00bac59d2d5d8630 (diff) |
Add -j option to control parallelism
Diffstat (limited to 'src/options.c')
-rw-r--r-- | src/options.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/options.c b/src/options.c index 41dbba1..1ef1550 100644 --- a/src/options.c +++ b/src/options.c @@ -15,6 +15,7 @@ static const char *usage_str = " -e, --show-matches=QUERY Output the sorted matches of QUERY\n" " -t, --tty=TTY Specify file to use as TTY device (default /dev/tty)\n" " -s, --show-scores Show the scores of each match\n" + " -j, --workers NUM Use NUM workers for searching. (default is number of CPU threads)\n" " -h, --help Display this help and exit\n" " -v, --version Output version information and exit\n"; @@ -44,13 +45,14 @@ void options_init(options_t *options) { options->num_lines = 10; options->scrolloff = 1; options->prompt = "> "; + options->workers = 0; } void options_parse(options_t *options, int argc, char *argv[]) { options_init(options); int c; - while ((c = getopt_long(argc, argv, "vhse:q:l:t:p:", longopts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "vhse:q:l:t:p:j:", longopts, NULL)) != -1) { switch (c) { case 'v': printf("%s " VERSION " (c) 2014 John Hawthorn\n", argv[0]); @@ -80,6 +82,12 @@ void options_parse(options_t *options, int argc, char *argv[]) { case 'p': options->prompt = optarg; break; + case 'j': + if (sscanf(optarg, "%u", &options->workers) != 1) { + usage(argv[0]); + exit(EXIT_FAILURE); + } + break; case 'l': { int l; if (!strcmp(optarg, "max")) { |