Add --levels option

This commit is contained in:
Dr-Noob
2020-06-22 13:17:00 +02:00
parent a2dab8129c
commit 0725e9d876
5 changed files with 53 additions and 21 deletions

View File

@@ -5,24 +5,27 @@
#define ARG_STR_STYLE "style"
#define ARG_STR_HELP "help"
#define ARG_STR_LEVELS "levels"
#define ARG_STR_VERSION "version"
#define ARG_CHAR_STYLE 's'
#define ARG_CHAR_HELP 'h'
#define ARG_CHAR_LEVELS 'l'
#define ARG_CHAR_VERSION 'v'
#define STYLE_STR_1 "default"
#define STYLE_STR_2 "dark"
#define STYLE_STR_3 "none"
struct args_struct {
int help_flag;
int version_flag;
bool levels_flag;
bool help_flag;
bool version_flag;
STYLE style;
};
static const char* SYTLES_STR_LIST[STYLES_COUNT] = { STYLE_STR_1, STYLE_STR_2, STYLE_STR_3 };
static struct args_struct args;
STYLE parseStyle(char* style) {
STYLE parse_style(char* style) {
int i = 0;
while(i != STYLES_COUNT && strcmp(SYTLES_STR_LIST[i],style) != 0)
i++;
@@ -32,34 +35,40 @@ STYLE parseStyle(char* style) {
return i;
}
STYLE getStyle() {
STYLE get_style() {
return args.style;
}
int showHelp() {
bool show_help() {
return args.help_flag;
}
int showVersion() {
bool show_version() {
return args.version_flag;
}
bool show_levels() {
return args.levels_flag;
}
bool verbose_enabled() {
return false;
}
bool parseArgs(int argc, char* argv[]) {
bool parse_args(int argc, char* argv[]) {
int c;
int digit_optind = 0;
int option_index = 0;
opterr = 0;
args.levels_flag = false;
args.help_flag = false;
args.style = STYLE_EMPTY;
static struct option long_options[] = {
{ARG_STR_STYLE, required_argument, 0, ARG_CHAR_STYLE },
{ARG_STR_HELP, no_argument, 0, ARG_CHAR_HELP },
{ARG_STR_LEVELS, no_argument, 0, ARG_CHAR_LEVELS },
{ARG_STR_VERSION, no_argument, 0, ARG_CHAR_VERSION },
{0, 0, 0, 0}
};
@@ -72,7 +81,7 @@ bool parseArgs(int argc, char* argv[]) {
printf("ERROR: Style option specified more than once\n");
return false;
}
args.style = parseStyle(optarg);
args.style = parse_style(optarg);
if(args.style == STYLE_INVALID) {
printf("ERROR: Invalid style '%s'\n",optarg);
return false;
@@ -85,6 +94,13 @@ bool parseArgs(int argc, char* argv[]) {
}
args.help_flag = true;
}
else if(c == ARG_CHAR_LEVELS) {
if(args.levels_flag) {
printf("ERROR: Levels option specified more than once\n");
return false;
}
args.levels_flag = true;
}
else if (c == ARG_CHAR_VERSION) {
if(args.version_flag) {
printf("ERROR: Version option specified more than once\n");