From 6b13542f74844f2b0cb8ba8b62a656f4a1af5aa1 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sat, 2 Mar 2024 21:00:58 +0100 Subject: [PATCH] read with wile loop config --- src/kds_s2000w_config.c | 52 ++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/src/kds_s2000w_config.c b/src/kds_s2000w_config.c index 4323737..373f916 100644 --- a/src/kds_s2000w_config.c +++ b/src/kds_s2000w_config.c @@ -166,34 +166,32 @@ void loadConfig(program_config* config, const char* config_stream) int stream_pos = 0; - get_line(config_stream, &line, &stream_pos); - get_key(&line, &value); - get_value(&line, &value); - trim_config_value(&value); - - if (strcmp(value.key, "scanner_url") == 0) { - config->scanner_url = malloc(sizeof(char) * value.value_length); - memcpy(config->scanner_url, value.value, value.value_length); - } - - free(line.line); - line.line = NULL; - line.length = 0; - free(value.key); - value.key = NULL; - value.key_length = 0; - free(value.value); - value.value = NULL; - value.value_length = 0; - - get_line(config_stream, &line, &stream_pos); - get_key(&line, &value); - get_value(&line, &value); - trim_config_value(&value); - if (strcmp(value.key, "username") == 0) { - config->username = malloc(sizeof(char) * value.value_length); - memcpy(config->username, value.value, value.value_length); + while(strlen(config_stream) > stream_pos) { + free(line.line); + line.line = NULL; + line.length = 0; + free(value.key); + value.key = NULL; + value.key_length = 0; + free(value.value); + value.value = NULL; + value.value_length = 0; + + get_line(config_stream, &line, &stream_pos); + get_key(&line, &value); + get_value(&line, &value); + trim_config_value(&value); + + if (strcmp(value.key, "scanner_url") == 0) { + config->scanner_url = malloc(sizeof(char) * value.value_length); + memcpy(config->scanner_url, value.value, value.value_length); + } + + if (strcmp(value.key, "username") == 0) { + config->username = malloc(sizeof(char) * value.value_length); + memcpy(config->username, value.value, value.value_length); + } } free(line.line); -- 2.39.5