]> git.itanic.dy.fi Git - log-plotter/blobdiff - config.c
data.c: Reset time stamp when starting new log
[log-plotter] / config.c
index 1dcc9c859224d394fd30d64e369417470cea1dbf..5f1f633564524004b7eef0dd70cf9144570e2487 100644 (file)
--- a/config.c
+++ b/config.c
@@ -102,9 +102,8 @@ static struct variable_value *prepare_slot_for_insertion(
        return &v[i];
 }
 
-static int store_str_variable_value_to_array(const char *variable,
-                                       const char *value,
-                                       struct plotter_config *cfg)
+int store_str_variable_value_to_array(const char *variable, const char *value,
+                               struct plotter_config *cfg)
 {
        struct variable_value *v;
 
@@ -247,7 +246,7 @@ static char *get_value_for_variable(char *variable,
 
 static int replace_variable_with_value(char *str, size_t len,
                                char *variable_start, char *variable_end,
-                               const char *value)
+                               const char *value, char **endptr)
 {
        int value_len = strlen(value);
        char *from, *to;
@@ -265,6 +264,8 @@ static int replace_variable_with_value(char *str, size_t len,
                from = variable_end + 1;
                to = variable_start + value_len;
 
+               *endptr = to;
+
                while (*from) {
                        *to = *from;
                        from++;
@@ -301,6 +302,8 @@ static int replace_variable_with_value(char *str, size_t len,
                        to--;
                }
 
+               *endptr = from;
+
                /*
                 * use memcpy to avoid NULL terminating prematurely
                 * the target string
@@ -343,7 +346,6 @@ int replace_variables_with_values(char *str, size_t len,
 
                variable_end = ptr;
                *ptr = 0;
-               ptr++;
 
                value = get_value_for_variable(variable_start, cfg);
                if (!value) {
@@ -358,7 +360,7 @@ int replace_variables_with_values(char *str, size_t len,
                        continue;
                }
                overflow = replace_variable_with_value(str, len, replace_start,
-                                       variable_end, value);
+                                       variable_end, value, &ptr);
        }
 
        if (overflow)