X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=src%2Frrd_diff.c;h=2b5cb6678a60429be0628b8505bc531a8c43fb5b;hp=62f08aade7f65c95814f1848b52406da8e596d10;hb=d4110e29da41ce702bcc3327e86768c6f266915e;hpb=2e6c98e893777e4abf7b05cb4ecf81dde088cdb8 diff --git a/src/rrd_diff.c b/src/rrd_diff.c index 62f08aa..2b5cb66 100644 --- a/src/rrd_diff.c +++ b/src/rrd_diff.c @@ -1,5 +1,5 @@ /***************************************************************************** - * RRDtool 1.2.19 Copyright by Tobi Oetiker, 1997-2007 + * RRDtool 1.3.2 Copyright by Tobi Oetiker, 1997-2008 * This code is stolen from rateup (mrtg-2.x) by Dave Rand ***************************************************************************** * diff calculate the difference between two very long integers available as @@ -35,48 +35,52 @@ * *****************************************************************************/ +#include #include "rrd_tool.h" -double -rrd_diff(char *a, char *b) +double rrd_diff( + char *a, + char *b) { - char res[LAST_DS_LEN+1], *a1, *b1, *r1, *fix; - int c,x,m; - char a_neg=0, b_neg=0; - double result; - - while (!(isdigit((int)*a) || *a==0)) { - if(*a=='-') - a_neg = 1; + char res[LAST_DS_LEN + 1], *a1, *b1, *r1, *fix; + int c, x, m; + char a_neg = 0, b_neg = 0; + double result; + + while (!(isdigit((int) *a) || *a == 0)) { + if (*a == '-') + a_neg = 1; a++; } - fix=a; - while (isdigit((int)*fix)) - fix++; - *fix = 0; /* maybe there is some non digit data in the string */ - while (!(isdigit((int)*b) || *b==0)) { - if(*b=='-') - b_neg = 1; + fix = a; + while (isdigit((int) *fix)) + fix++; + *fix = 0; /* maybe there is some non digit data in the string */ + while (!(isdigit((int) *b) || *b == 0)) { + if (*b == '-') + b_neg = 1; b++; } - fix=b; - while (isdigit((int)*fix)) - fix++; - *fix = 0; /* maybe there is some non digit data in the string */ - if(!isdigit((int)*a) || !isdigit((int)*b)) - return DNAN; - if(a_neg+b_neg == 1) /* can not handle numbers with different signs yet */ - return DNAN; - a1 = &a[strlen(a)-1]; - m = max(strlen(a),strlen(b)); - if (m > LAST_DS_LEN) return DNAN; /* result string too short */ + fix = b; + while (isdigit((int) *fix)) + fix++; + *fix = 0; /* maybe there is some non digit data in the string */ + if (!isdigit((int) *a) || !isdigit((int) *b)) + return DNAN; + if (a_neg + b_neg == 1) /* can not handle numbers with different signs yet */ + return DNAN; + a1 = &a[strlen(a) - 1]; + m = max(strlen(a), strlen(b)); + if (m > LAST_DS_LEN) + return DNAN; /* result string too short */ - r1 = &res[m+1]; - for (b1 = res;b1 <= r1; b1++) *b1 = ' '; - b1 = &b[strlen(b)-1]; - r1[1] = 0; /* Null terminate result */ + r1 = &res[m + 1]; + for (b1 = res; b1 <= r1; b1++) + *b1 = ' '; + b1 = &b[strlen(b) - 1]; + r1[1] = 0; /* Null terminate result */ c = 0; - for (x=0; x= a && b1 >= b) { *r1 = ((*a1 - c) - *b1) + '0'; } else if (a1 >= a) { @@ -86,33 +90,34 @@ rrd_diff(char *a, char *b) } if (*r1 < '0') { *r1 += 10; - c=1; - } else - if (*r1 > '9') { /* 0 - 10 */ - *r1 -= 10; - c=1; - } else { - c=0; + c = 1; + } else if (*r1 > '9') { /* 0 - 10 */ + *r1 -= 10; + c = 1; + } else { + c = 0; } - a1--;b1--;r1--; + a1--; + b1--; + r1--; } if (c) { - r1 = &res[m+1]; - for (x=0; isdigit((int)*r1) && x '9') { *r1 -= 10; - c=1; + c = 1; } else { - c=0; + c = 0; } } result = -atof(res); } else result = atof(res); - if(a_neg+b_neg==2) /* both are negatives, reverse sign */ + if (a_neg + b_neg == 2) /* both are negatives, reverse sign */ result = -result; - + return result; -} +}