src = data;
cln = clean_data;
+ /*
+ * Copy a legit floating point number to clean_data buffer
+ * starting from *src and ending to next ':'. If no legit
+ * number could be found, put a 'U' there instead to make
+ * rrdtool to understand this datapoint is undefined.
+ */
+
while (src < data + RRD_DATA_MAX_LEN && *src) {
minus = 0;
+
+ /* skip any non_numbers but not ':' */
+ while (*src && !isdigit(*src) && *src != '-' && *src != ':')
+ src++;
+
if (*src == '-') {
src++;
minus = 1;
}
+ /* Now find the end of the number */
end = skip_numbers(src);
+ /* Floating point numberrs may have a dot with more numbers */
if (*end == '.') {
end++;
end = skip_numbers(end);
}
- if (*end == ':' || !*end) {
+ /*
+ * Now we have gone past the number, there should be a
+ * colon or zero byte. If src == end, there was no
+ * number and the entry is undefined instead.
+ */
+ if ((*end == ':' || !*end) && src != end) {
if (minus) {
*cln = '-';
cln++;
}
+
+ /*
+ * Copy the legit number and start copying the
+ * next one
+ */
for (; src <= end; src++, cln++)
*cln = *src;
goto next;
}
+ /* Skip over whatever junk there might be */
while (*end != ':' && *end)
end++;
+
+ /* Mark the entry as undefined */
*cln = 'U';
cln++;
*cln = ':';
entries++;
}
+ /*
+ * If last entry was undefined, we need to remove the extra
+ * colon at the end
+ */
+ if (*(cln - 1) == ':')
+ cln--;
+ *cln = '\0';
+
strncpy(data, clean_data, RRD_DATA_MAX_LEN);
return entries;
}