Browse Source

Bugfix: Use UTF-8 for micro prefix internally (and in logging)

Luke Dashjr 11 years ago
parent
commit
bc0e27c83a
3 changed files with 27 additions and 18 deletions
  1. 22 14
      miner.c
  2. 4 4
      miner.h
  3. 1 0
      util.h

+ 22 - 14
miner.c

@@ -3194,15 +3194,24 @@ int format_unit3(char *buf, size_t sz, enum bfu_floatprec fprec, const char *mea
 			_SNP("%u", (unsigned int)hashrate);
 	}
 	
-	switch (fmt) {
-	case H2B_SPACED:
-		_SNP(" ");
-	case H2B_SHORT:
-		_SNP("%c%s", _unitchar[unit], measurement);
-	default:
-		break;
-	case H2B_SHORTV:
-		_SNP("%.1s%s", (unit == _unitbase) ? "" : &_unitchar[unit], measurement);
+	if (fmt != H2B_NOUNIT)
+	{
+		char uc[3] = {_unitchar[unit], '\0'};
+		switch (fmt) {
+			case H2B_SPACED:
+				_SNP(" ");
+			default:
+				break;
+			case H2B_SHORTV:
+				if (isspace(uc[0]))
+					uc[0] = '\0';
+		}
+		
+		if (uc[0] == '\xb5')
+			// Convert to UTF-8
+			snprintf(uc, sizeof(uc), "%s", U8_MICRO);
+		
+		_SNP("%s%s", uc, measurement);
 	}
 	
 	return rv;
@@ -3651,17 +3660,15 @@ void bfg_waddstr(WINDOW *win, const char *s)
 		if (p != s)
 			waddnstr(win, s, p - s);
 		w = utf8_decode(p, &wlen);
-		if (unlikely(p[0] == '\xb5'))  // HACK for Mu (SI prefix micro-)
-		{
-			w = unicode_micro;
-			wlen = 1;
-		}
 		s = p += wlen;
 		switch(w)
 		{
 			// NOTE: U+F000-U+F7FF are reserved for font hacks
 			case '\0':
 				return;
+			case 0xb5:  // micro symbol
+				w = unicode_micro;
+				goto default_addch;
 			case 0xf000:  // "bad" off
 				wattroff(win, attr_bad);
 				break;
@@ -3688,6 +3695,7 @@ void bfg_waddstr(WINDOW *win, const char *s)
 				if (w > WCHAR_MAX || !iswprint(w))
 					w = '*';
 			default:
+default_addch:
 				if (w > WCHAR_MAX || !(iswprint(w) || w == '\n'))
 				{
 #if REPLACEMENT_CHAR <= WCHAR_MAX

+ 4 - 4
miner.h

@@ -440,10 +440,10 @@ struct cgminer_pool_stats {
 #define PRIprepr "-6s"
 #define PRIpreprv "s"
 
-#define ALLOC_H2B_NOUNIT  5
-#define ALLOC_H2B_SHORT   6
-#define ALLOC_H2B_SPACED  7
-#define ALLOC_H2B_SHORTV  6
+#define ALLOC_H2B_NOUNIT  6
+#define ALLOC_H2B_SHORT   7
+#define ALLOC_H2B_SPACED  8
+#define ALLOC_H2B_SHORTV  7
 
 
 struct cgpu_info {

+ 1 - 0
util.h

@@ -480,6 +480,7 @@ struct timeval *select_timeout(struct timeval *tvp_timeout, struct timeval *tvp_
 
 #define REPLACEMENT_CHAR (0xFFFD)
 #define U8_DEGREE "\xc2\xb0"
+#define U8_MICRO  "\xc2\xb5"
 #define U8_HLINE  "\xe2\x94\x80"
 #define U8_BTEE   "\xe2\x94\xb4"
 extern int utf8_len(uint8_t);