aboutsummaryrefslogtreecommitdiff
path: root/config-parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'config-parser.c')
-rw-r--r--config-parser.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/config-parser.c b/config-parser.c
index 5e403f8..075ef47 100644
--- a/config-parser.c
+++ b/config-parser.c
@@ -17,6 +17,7 @@ Result parse_config(int argc, char* argv[]) {
Config tmp;
tmp.precision = 0;
tmp.human_readable = false;
+ tmp.help = false;
size_t i = 1;
char* argument;
@@ -25,6 +26,16 @@ Result parse_config(int argc, char* argv[]) {
argument = argv[i];
int comp1 = strcmp(argument, "--precision") == 0;
if (
+ strcmp(argument, "--help") == 0
+ || strcmp(argument, "-?") == 0
+ ) {
+ tmp.help = true;
+ } else if (
+ strcmp(argument, "--human-readable") == 0
+ || strcmp(argument, "-h") == 0
+ ) {
+ tmp.human_readable = true;
+ } else if (
comp1 || strncmp(argument, "-p", 2) == 0
) {
if (precision != NULL) {
@@ -54,21 +65,6 @@ Result parse_config(int argc, char* argv[]) {
return res;
}
precision = argv[i];
- } else if (
- strcmp(argument, "--human-readable") == 0
- || strcmp(argument, "-h") == 0
- ) {
- if (tmp.human_readable != false) {
- char* error_msg = malloc(52);
- snprintf(
- error_msg,
- 52,
- "human readability can't be specified multiple times"
- );
- res.result = error_msg;
- return res;
- }
- tmp.human_readable = true;
} else {
size_t msg_size = 21 + strlen(argument);
char* error_msg = malloc(msg_size);
@@ -126,8 +122,9 @@ Result parse_config(int argc, char* argv[]) {
}
Config* conf = malloc(sizeof(int) + sizeof(bool));
- conf->precision = tmp.precision;
+ conf->help = tmp.help;
conf->human_readable = tmp.human_readable;
+ conf->precision = tmp.precision;
res.success = true;
res.result = conf;