# HG changeset patch # User Daniele Nicolodi # Date 1386950668 -3600 # Node ID 2479ad53982ba98f473ead7807e204edae9b9e68 # Parent 5bba1d1c3b46b1a86f30404902134567f89e53e1 User iterface tweaks. Better thousands separators number formatting function. diff -r 5bba1d1c3b46 -r 2479ad53982b FXAnalyse.c --- a/FXAnalyse.c Fri Dec 13 17:03:36 2013 +0100 +++ b/FXAnalyse.c Fri Dec 13 17:04:28 2013 +0100 @@ -159,20 +159,25 @@ static int LoggingPanel; -// format and add thousands separator */ -char * thousands(char *buffer, int len, char *fmt, double val) +char * thousands(char *buffer, int size, char *fmt, double val) { - int c = snprintf(buffer, len, fmt, val); - char *p = strchr(buffer, '.'); - int n = buffer + c - p; - while (p > (buffer + 3)) { - // shift by 3 digits - p -= 3; - n += 4; - // make space for separator - memmove(p + 1, p, n); - // insert thousand separator - *p = ' '; + // compute how many separators we need + int nsep = (int)(log10(fabs(val)+1.0))/3; + // format value + int len = snprintf(buffer, size, fmt, val); + char *src = buffer + len + 1; + char *dst = src + nsep; + // copy till decimal separator + while (*src != '.') + *dst-- = *src--; + // copy till the beginning inserting separators + int n = -1; + while (1) { + *dst-- = *src--; + if (isdigit(*src) && (++n) && ((n % 3) == 0)) + *dst-- = ' '; + if (src == buffer) + break; } return buffer; } diff -r 5bba1d1c3b46 -r 2479ad53982b FXAnalyse.h --- a/FXAnalyse.h Fri Dec 13 17:03:36 2013 +0100 +++ b/FXAnalyse.h Fri Dec 13 17:04:28 2013 +0100 @@ -132,18 +132,19 @@ #define PANEL_DECORATION 95 /* control type: deco, callback function: (none) */ #define PANEL_DECORATION_3 96 /* control type: deco, callback function: (none) */ #define PANEL_TEXTMSG_6 97 /* control type: textMsg, callback function: (none) */ -#define PANEL_TEXTMSG_7 98 /* control type: textMsg, callback function: (none) */ -#define PANEL_DECORATION_4 99 /* control type: deco, callback function: (none) */ -#define PANEL_DECORATION_7 100 /* control type: deco, callback function: (none) */ -#define PANEL_DECORATION_6 101 /* control type: deco, callback function: (none) */ -#define PANEL_DECORATION_5 102 /* control type: deco, callback function: (none) */ -#define PANEL_TEXTMSG_20 103 /* control type: textMsg, callback function: (none) */ -#define PANEL_TEXTMSG_19 104 /* control type: textMsg, callback function: (none) */ -#define PANEL_MATH4 105 /* control type: string, callback function: (none) */ -#define PANEL_MATH5 106 /* control type: string, callback function: (none) */ -#define PANEL_MATH3 107 /* control type: string, callback function: (none) */ -#define PANEL_MATH2 108 /* control type: string, callback function: (none) */ -#define PANEL_MATH1 109 /* control type: string, callback function: (none) */ +#define PANEL_TEXTMSG_21 98 /* control type: textMsg, callback function: (none) */ +#define PANEL_TEXTMSG_7 99 /* control type: textMsg, callback function: (none) */ +#define PANEL_DECORATION_4 100 /* control type: deco, callback function: (none) */ +#define PANEL_DECORATION_7 101 /* control type: deco, callback function: (none) */ +#define PANEL_DECORATION_6 102 /* control type: deco, callback function: (none) */ +#define PANEL_DECORATION_5 103 /* control type: deco, callback function: (none) */ +#define PANEL_TEXTMSG_20 104 /* control type: textMsg, callback function: (none) */ +#define PANEL_TEXTMSG_19 105 /* control type: textMsg, callback function: (none) */ +#define PANEL_MATH4 106 /* control type: string, callback function: (none) */ +#define PANEL_MATH5 107 /* control type: string, callback function: (none) */ +#define PANEL_MATH3 108 /* control type: string, callback function: (none) */ +#define PANEL_MATH2 109 /* control type: string, callback function: (none) */ +#define PANEL_MATH1 110 /* control type: string, callback function: (none) */ /* Control Arrays: */ diff -r 5bba1d1c3b46 -r 2479ad53982b FXAnalyse.uir Binary file FXAnalyse.uir has changed