hex-editor/src/util.c

44 lines
1.1 KiB
C

#include "util.h"
#include <gint/display.h>
#include <stdio.h>
void please_wait(void)
{
int w, h;
char const *message = "Please wait...";
dsize(message, NULL, &w, &h);
int x = DWIDTH / 2;
int y = DHEIGHT / 2;
int mx = 14, bx = 8;
int my = 12, by = 6;
drect(x - w/2 - mx, y - h/2 - my, x + w/2 + mx, y + h/2 + my, C_WHITE);
drect_border(x - w/2 - bx, y - h/2 - by, x + w/2 + bx, y + h/2 + by,
C_WHITE, 1, C_BLACK);
dtext_opt(x, y, C_BLACK, C_NONE, DTEXT_CENTER, DTEXT_MIDDLE, message, -1);
dupdate();
}
char const *human_size(int size, char *str)
{
static char default_buffer[64];
if(str == NULL)
str = default_buffer;
char digits[16];
sprintf(digits, "%d", size);
if(size < 1000) /* 1 kB */
sprintf(str, "%d B", size);
else if(size < 10000) /* 10 kB */
sprintf(str, "%d.%d kB", size / 1000, (size / 100) % 10);
else if(size < 1000000) /* 1 MB */
sprintf(str, "%d kB", size / 1000);
else
sprintf(str, "%d.%d MB", size / 1000000, (size / 100000) % 10);
return str;
}