fix bug or at least improve "to_bytes" variable so that it works with non-integers...
authorCreamy Goodness <lance.colton@gmail.com>
Thu, 16 Dec 2010 04:39:57 +0000 (21:39 -0700)
committerCreamy Goodness <lance.colton@gmail.com>
Sat, 18 Dec 2010 21:48:51 +0000 (14:48 -0700)
src/conky.c

index 1bef267..cc92a0b 100644 (file)
@@ -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);
                        }