Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #22 from niclas/master
Add 1k divider for numerical output (Issue 20)
  • Loading branch information
wwwutz committed Mar 21, 2019
2 parents 3af8e44 + 99a44dd commit fd01be5
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 10 deletions.
4 changes: 4 additions & 0 deletions README.md
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
@@ -1 +1 @@
#define XDU_VERSION "3.0p11"
#define XDU_VERSION "3.0p12"
80 changes: 71 additions & 9 deletions xwin.c
Expand Up @@ -35,6 +35,8 @@
#include <stdlib.h> /* for exit() */
#endif

#include <sys/time.h>

/*
* IMPORTS: routines that this module vectors out to
*/
Expand Down Expand Up @@ -67,6 +69,11 @@ extern void xdrawrect();
*/
static void help_popup();
static void help_popdown();
static struct timeval last_repaint;
static long int timediff(struct timeval* t1, struct timeval* t2)
{
return 1000000 * (t2->tv_sec - t1->tv_sec) + t2->tv_usec - t1->tv_usec;
}

static String fallback_resources[] = {
"*window.width: 600",
Expand Down Expand Up @@ -338,10 +345,20 @@ static void
c_resize(Widget w, XtPointer data, XEvent* event, Boolean* continue_to_dispatch)
{
UNUSED(w, data, event, continue_to_dispatch);
/*
* printf("Resize\n");
*/
/*
* printf("Resize\n");
*/
long int diff;
struct timeval t;

gettimeofday(&t, NULL);
diff = timediff(&last_repaint, &t);

if (diff < (long int)50000)
return;
xrepaint();

gettimeofday(&last_repaint, NULL);
}

static void
Expand All @@ -351,6 +368,14 @@ c_repaint(Widget w, XtPointer data, XEvent* event, Boolean* continue_to_dispatch
/*
* printf("Expose\n");
*/
long int diff;
struct timeval t;

gettimeofday(&t, NULL);
diff = timediff(&last_repaint, &t);

if (diff < (long int)50000)
return;
xrepaint_noclear();
}

Expand Down Expand Up @@ -491,11 +516,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 +569,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 fd01be5

Please sign in to comment.