diff options
author | nirav <nirav@teisuu.com> | 2018-10-21 18:24:26 +0530 |
---|---|---|
committer | Dandelion <nirav@teisuu.com> | 2018-10-21 18:24:26 +0530 |
commit | 62cdffbb4d3e93d6785f3054f7fa81b7cc8b6de7 (patch) | |
tree | 821e20b2f978890f7b9e6d6a99209a85669a842e /src/option.c | |
parent | f8f3159f9b98b024043bd8de2c5e15dd2adf03ca (diff) | |
download | im-62cdffbb4d3e93d6785f3054f7fa81b7cc8b6de7.tar.gz im-62cdffbb4d3e93d6785f3054f7fa81b7cc8b6de7.zip |
Added command line option parsing, info bar is now visible by default
Diffstat (limited to 'src/option.c')
-rw-r--r-- | src/option.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/option.c b/src/option.c new file mode 100644 index 0000000..66a99f0 --- /dev/null +++ b/src/option.c @@ -0,0 +1,58 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include "option.h" + +static const char version[] = "qwe version 0.01"; +static const char usage[] = + "Usage: qwe [options...] <file>\n" + "\n" + " -i Hide info bar by default.\n" + " -h Show help message and quit.\n" + " -v Show the version number and quit.\n"; + +void print_usage() +{ + printf("%s\n", usage); +} + +void print_version() +{ + printf("%s\n", version); +} + +struct option _options; +const struct option *options = (const struct option *)&_options; + +void parse_options(int argc, char **argv) +{ + // default options + _options.fullscreen = false; + _options.show_info = true; + + // override options from commandline parameters + int opt; + while ((opt = getopt(argc, argv, "hvi")) != -1) { + switch (opt) { + case '?': + print_usage(); + exit(EXIT_FAILURE); + case 'h': + print_usage(); + exit(EXIT_SUCCESS); + case 'v': + print_version(); + exit(EXIT_SUCCESS); + case 'i': + _options.show_info = false; + } + } + + if (optind >= argc) { + print_usage(); + exit(EXIT_FAILURE); + } + + _options.file_name = argv[optind]; +} |