From: Creamy Goodness Date: Thu, 16 Dec 2010 04:39:57 +0000 (-0700) Subject: fix bug or at least improve "to_bytes" variable so that it works with non-integers... X-Git-Url: http://vcs.maemo.org/git/?p=monky;a=commitdiff_plain;h=174c256c81a027a2ea406f5f37dc036fac0a524b fix bug or at least improve "to_bytes" variable so that it works with non-integers. a value like 3.21G would have been returned as-is instead of converted to bytes, for example. --- diff --git a/src/conky.c b/src/conky.c index 1bef267..cc92a0b 100644 --- a/src/conky.c +++ b/src/conky.c @@ -2296,18 +2296,26 @@ void generate_text_internal(char *p, int p_max_size, } } } - OBJ(to_bytes) { + OBJ(to_bytes) {//commented code is original - not working when input value contains a decimal point char buf[max_user_text]; - long long bytes; + //long long bytes; + long double bytes; char unit[16]; // 16 because we can also have long names (like mega-bytes) generate_text_internal(buf, max_user_text, *obj->sub, cur); - if(sscanf(buf, "%lli%s", &bytes, unit) == 2 && strlen(unit) < 16){ - if(strncasecmp("b", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes); - else if(strncasecmp("k", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024); - else if(strncasecmp("m", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024); - else if(strncasecmp("g", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024 * 1024); - else if(strncasecmp("t", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024 * 1024 * 1024); +// if(sscanf(buf, "%lli%s", &bytes, unit) == 2 && strlen(unit) < 16){ +// if(strncasecmp("b", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes); +// else if(strncasecmp("k", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024); +// else if(strncasecmp("m", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024); +// else if(strncasecmp("g", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024 * 1024); +// else if(strncasecmp("t", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024 * 1024 * 1024 * 1024); +// } + if(sscanf(buf, "%Lf%s", &bytes, unit) == 2 && strlen(unit) < 16){ + if(strncasecmp("b", unit, 1) == 0) snprintf(buf, max_user_text, "%Lf", bytes); + else if(strncasecmp("k", unit, 1) == 0) snprintf(buf, max_user_text, "%Lf", bytes * 1024); + else if(strncasecmp("m", unit, 1) == 0) snprintf(buf, max_user_text, "%Lf", bytes * 1024 * 1024); + else if(strncasecmp("g", unit, 1) == 0) snprintf(buf, max_user_text, "%Lf", bytes * 1024 * 1024 * 1024); + else if(strncasecmp("t", unit, 1) == 0) snprintf(buf, max_user_text, "%Lf", bytes * 1024 * 1024 * 1024 * 1024); } snprintf(p, p_max_size, "%s", buf); }