mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-12 19:06:36 +00:00
Merge pull request #227 from alessandro-g89/master
Improve to_bytes to work with input values with a decimal point
This commit is contained in:
commit
4cb9ab8ab7
@ -733,16 +733,16 @@ void free_stock(struct text_object *obj)
|
|||||||
void print_to_bytes(struct text_object *obj, char *p, int p_max_size)
|
void print_to_bytes(struct text_object *obj, char *p, int p_max_size)
|
||||||
{
|
{
|
||||||
std::vector<char> buf(max_user_text.get(*state));
|
std::vector<char> buf(max_user_text.get(*state));
|
||||||
long long bytes;
|
long double bytes;
|
||||||
char unit[16]; // 16 because we can also have long names (like mega-bytes)
|
char unit[16]; // 16 because we can also have long names (like mega-bytes)
|
||||||
|
|
||||||
generate_text_internal(&(buf[0]), max_user_text.get(*state), *obj->sub);
|
generate_text_internal(&(buf[0]), max_user_text.get(*state), *obj->sub);
|
||||||
if(sscanf(&(buf[0]), "%lli%s", &bytes, unit) == 2 && strlen(unit) < 16){
|
if(sscanf(&(buf[0]), "%Lf%s", &bytes, unit) == 2 && strlen(unit) < 16){
|
||||||
if(strncasecmp("b", unit, 1) == 0) snprintf(&(buf[0]), max_user_text.get(*state), "%lli", bytes);
|
if(strncasecmp("b", unit, 1) == 0) snprintf(&(buf[0]), max_user_text.get(*state), "%Lf", bytes);
|
||||||
else if(strncasecmp("k", unit, 1) == 0) snprintf(&(buf[0]), max_user_text.get(*state), "%lli", bytes * 1024);
|
else if(strncasecmp("k", unit, 1) == 0) snprintf(&(buf[0]), max_user_text.get(*state), "%Lf", bytes * 1024);
|
||||||
else if(strncasecmp("m", unit, 1) == 0) snprintf(&(buf[0]), max_user_text.get(*state), "%lli", bytes * 1024 * 1024);
|
else if(strncasecmp("m", unit, 1) == 0) snprintf(&(buf[0]), max_user_text.get(*state), "%Lf", bytes * 1024 * 1024);
|
||||||
else if(strncasecmp("g", unit, 1) == 0) snprintf(&(buf[0]), max_user_text.get(*state), "%lli", bytes * 1024 * 1024 * 1024);
|
else if(strncasecmp("g", unit, 1) == 0) snprintf(&(buf[0]), max_user_text.get(*state), "%Lf", bytes * 1024 * 1024 * 1024);
|
||||||
else if(strncasecmp("t", unit, 1) == 0) snprintf(&(buf[0]), max_user_text.get(*state), "%lli", bytes * 1024 * 1024 * 1024 * 1024);
|
else if(strncasecmp("t", unit, 1) == 0) snprintf(&(buf[0]), max_user_text.get(*state), "%Lf", bytes * 1024 * 1024 * 1024 * 1024);
|
||||||
}
|
}
|
||||||
snprintf(p, p_max_size, "%s", &(buf[0]));
|
snprintf(p, p_max_size, "%s", &(buf[0]));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user