+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include "kds_s2000w_config.h"
+typedef struct {
+ int length;
+ char* line;
+} config_line;
+
+typedef struct {
+ int key_length;
+ int value_length;
+ char* key;
+ char* value;
+} config_value;
+
+void get_line(const char* config_stream, config_line* line)
+{
+ while(config_stream[line->length] != '\n') {
+ line->length++;
+ }
+ line->length++;
+
+ line->line = malloc(sizeof(char) * line->length);
+ memcpy(line->line, config_stream, line->length - 1);
+ line->line[line->length - 1] = '\0';
+}
+
+void get_key(const char* line, config_value* value)
+{
+ value->key_length = 0;
+ while(line[value->key_length] != '=') {
+ value->key_length++;
+ }
+
+ value->key = malloc(sizeof(char) * value->key_length);
+ memcpy(value->key, line, value->key_length - 1);
+ value->key[value->key_length - 1] = '\0';
+}
+
+void get_value(char* line, config_value* value)
+{
+ int i = 0;
+ while (line[i] != '=') {
+ i++;
+ }
+}
+
void loadConfig(program_config* config, const char* config_stream)
{
- config->scanner_url = config_stream;
+ config_line line;
+ line.length = 0;
+ line.line = NULL;
+ config_value value;
+ value.key_length = 0;
+ value.key = NULL;
+ value.value_length = 0;
+ value.value = NULL;
+
+ get_line(config_stream, &line);
+ get_key(line.line, &value);
+
+ config->scanner_url = malloc(sizeof(char) * value.key_length);
+ memcpy(config->scanner_url, value.key, value.key_length);
+
+ free(line.line);
+ line.line = NULL;
+ line.length = 0;
}
\ No newline at end of file
START_TEST(kds_s2000w_config_read_parameter)
{
- const char* input_stream = "scanner_url = http://scanner.example.com";
+ const char* input_stream = "scanner_url = http://scanner.example.com\n";
program_config* config = malloc(sizeof(program_config));
loadConfig(config, input_stream);