From: Bastian Dehn Date: Sat, 2 Mar 2024 17:38:59 +0000 (+0100) Subject: add tim whitespace before value X-Git-Tag: v1.0.0^2~144^2~14 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=37f7f5f9b1b53e9df5932e5ec140d13605677673;p=sane-kds-s2000w-net.git add tim whitespace before value --- diff --git a/src/kds_s2000w_config.c b/src/kds_s2000w_config.c index c9951a5..d23ff29 100644 --- a/src/kds_s2000w_config.c +++ b/src/kds_s2000w_config.c @@ -15,6 +15,24 @@ typedef struct { char* value; } config_value; +void trim_whitespace_before(config_value* value) +{ + int before = 0; + while(value->value[before] == ' ') { + before++; + } + + int new_length = value->value_length - before; + char* new_value = malloc(sizeof(char) * new_length); + memcpy(new_value, value->value + before, new_length); + + + free(value->value); + value->value = NULL; + value->value = new_value; + value->value_length = new_length; +} + void get_line(const char* config_stream, config_line* line) { while(config_stream[line->length] != '\n') { @@ -67,8 +85,9 @@ void loadConfig(program_config* config, const char* config_stream) get_line(config_stream, &line); get_key(&line, &value); get_value(&line, &value); + trim_whitespace_before(&value); - config->scanner_url = malloc(sizeof(char) * value.key_length); + config->scanner_url = malloc(sizeof(char) * value.value_length); memcpy(config->scanner_url, value.value, value.value_length); free(line.line);