diff options
author | nirav <nirav@teisuu.com> | 2019-03-07 01:27:55 +0530 |
---|---|---|
committer | Dandelion <nirav@teisuu.com> | 2019-03-07 01:27:55 +0530 |
commit | 6dd58a30761eca36544c4e815b36907eab084949 (patch) | |
tree | c1bc857a14fffe6f35f7405f133c0ed114aec1a4 /src/option.c | |
download | ap_client-6dd58a30761eca36544c4e815b36907eab084949.tar.gz ap_client-6dd58a30761eca36544c4e815b36907eab084949.zip |
Initial commit
Diffstat (limited to 'src/option.c')
-rw-r--r-- | src/option.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/option.c b/src/option.c new file mode 100644 index 0000000..011bd94 --- /dev/null +++ b/src/option.c @@ -0,0 +1,64 @@ +#define _POSIX_C_SOURCE 200809L +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.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" + " -f Use fullscreen mode 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, "hvif")) != -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; + break; + case 'f': + _options.fullscreen = true; + break; + } + } + + if (optind >= argc) { + print_usage(); + exit(EXIT_FAILURE); + } + + _options.file_name = argv[optind]; +} |