changeset 127:2479ad53982b

User iterface tweaks. Better thousands separators number formatting function.
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Fri, 13 Dec 2013 17:04:28 +0100
parents 5bba1d1c3b46
children 8a69c40f10b2
files FXAnalyse.c FXAnalyse.h FXAnalyse.uir
diffstat 3 files changed, 31 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- 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;
 }
--- 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: */
Binary file FXAnalyse.uir has changed