]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add tim whitespace before value
authorBastian Dehn <hhaalo@arcor.de>
Sat, 2 Mar 2024 17:38:59 +0000 (18:38 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 2 Mar 2024 17:38:59 +0000 (18:38 +0100)
src/kds_s2000w_config.c

index c9951a5731474507db886b67f04acaca049173df..d23ff291023605028aacd9cb501fd3c121395633 100644 (file)
@@ -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);