aboutsummaryrefslogtreecommitdiff
path: root/config-parser.c
diff options
context:
space:
mode:
authorJoel Kronqvist <joelkronqvist@proton.me>2024-04-10 16:54:50 +0300
committerJoel Kronqvist <joelkronqvist@proton.me>2024-04-11 16:01:36 +0300
commita793df3e2a07c65f36fb2f5f43d2c51ab0c47bf2 (patch)
tree49858b1ef415ce16c843c4fbb4ab7eccaa73033d /config-parser.c
parent4ff6a08d73f0ef1e2fcb7a93a74cc6fa66c24e2b (diff)
downloadstdu-a793df3e2a07c65f36fb2f5f43d2c51ab0c47bf2.tar.gz
stdu-a793df3e2a07c65f36fb2f5f43d2c51ab0c47bf2.zip
Added help message & fixed blocksize bug
The bug was caused by integer overflow with too large precisions.
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;