Skip to content

Commit

Permalink
Add 1k divider for numerical output
Browse files Browse the repository at this point in the history
  • Loading branch information
niclas committed Mar 20, 2019
1 parent ace9d96 commit dce795b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ This release was tested against MarIuX.

## Revision History

### Version 3.0p12 - Mar 20 2019
- use , as 1k divider for numerical output
- Niclas Hofmann, `niclas@molgen.mpg.de`

### Version 3.0p11 - Jan 23 2019
- remove newline in window title
- Niclas Hofmann, `niclas@molgen.mpg.de`
Expand Down
2 changes: 1 addition & 1 deletion version.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define XDU_VERSION "3.0p11"
#define XDU_VERSION "3.0p12"
49 changes: 43 additions & 6 deletions xwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,46 @@ void xrepaint_noclear()
repaint(xwa.width, xwa.height);
}

void readable_float(float number, char* number_label)
{
char number_string[1024];
int i, j, length;
sprintf(number_string, "%.2f", number);
length = (strlen(number_string) - 3) / 4 + strlen(number_string);

for (i = 0, j = 0; i < length; ++i) {
if ((length - 3 - i) % 4 == 0 && i < length - 3) {
number_label[i] = ',';
continue;
}
number_label[i] = number_string[j++];
}
number_label[length] = 0;
}

void readable_long_long(long long number, char* number_label)
{
char number_string[1024];
int i, j, length;
sprintf(number_string, "%lld", number);
length = (strlen(number_string) - 1) / 3 + strlen(number_string);

for (i = 0, j = 0; i < length; ++i) {
if ((length - i) % 4 == 0 && i != 0) {
number_label[i] = ',';
continue;
}
number_label[i] = number_string[j++];
}
number_label[length] = 0;
}

void xdrawrect(char* name, long long size, int x, int y, int width, int height)
{
int textx,
texty;
char label[1024];
char number_label[1024];
XCharStruct overall;
int ascent,
descent,
Expand All @@ -509,21 +544,23 @@ void xdrawrect(char* name, long long size, int x, int y, int width, int height)

switch (res.showsize) {
case 1:
sprintf(label, "%s (%lldk)", name, size);
readable_long_long(size, number_label);
sprintf(label, "%s (%sk)", name, number_label);
name = label;
break;
case 2:
sprintf(label, "%s (%.2fM)", name, (double)size / (double)1024);
readable_float((double)size / (double)1024, number_label);
sprintf(label, "%s (%sM)", name, number_label);
name = label;
break;
case 3:
sprintf(label, "%s (%.2fG)", name,
(double)size / (double)(1024 * 1024));
readable_float((double)size / (double)(1024 * 1024), number_label);
sprintf(label, "%s (%sG)", name, number_label);
name = label;
break;
case 4:
sprintf(label, "%s (%.2fT)", name,
(double)size / (double)(1024 * 1024 * 1024));
readable_float((double)size / (double)(1024 * 1024 * 1024), number_label);
sprintf(label, "%s (%sT)", name, number_label);
name = label;
break;
default:
Expand Down

0 comments on commit dce795b

Please sign in to comment.