Browse Source

Split actual formatting from temperature_column_tail into new format_temperature[_sz]

Luke Dashjr 12 years ago
parent
commit
8d9ccda3c9
3 changed files with 32 additions and 9 deletions
  1. 10 9
      miner.c
  2. 18 0
      util.c
  3. 4 0
      util.h

+ 10 - 9
miner.c

@@ -2590,21 +2590,22 @@ void format_statline(char *buf, const char *cHr, const char *aHr, const char *uH
 static inline
 static inline
 void temperature_column_tail(char *buf, bool maybe_unicode, const float * const temp)
 void temperature_column_tail(char *buf, bool maybe_unicode, const float * const temp)
 {
 {
+	int sz;
 	if (!(use_unicode && have_unicode_degrees))
 	if (!(use_unicode && have_unicode_degrees))
 		maybe_unicode = false;
 		maybe_unicode = false;
 	if (temp && *temp > 0.)
 	if (temp && *temp > 0.)
-		if (maybe_unicode)
-			sprintf(buf, "%4.1f\xb0""C", *temp);
-		else
-			sprintf(buf, "%4.1fC", *temp);
+	{
+		format_temperature(buf, 4, true, maybe_unicode, *temp);
+		sz = 1;
+	}
 	else
 	else
 	{
 	{
-		if (temp)
-			strcpy(buf, "     ");
-		if (maybe_unicode)
-			strcat(buf, " ");
+		buf[0] = '\0';
+		sz = format_temperature_sz(4, maybe_unicode) + 1;
+		if (!temp)
+			sz -= 5;
 	}
 	}
-	strcat(buf, " | ");
+	tailsprintf(buf, "%*s| ", sz, "");
 }
 }
 
 
 void get_statline3(char *buf, struct cgpu_info *cgpu, bool for_curses, bool opt_show_procs)
 void get_statline3(char *buf, struct cgpu_info *cgpu, bool for_curses, bool opt_show_procs)

+ 18 - 0
util.c

@@ -1345,6 +1345,24 @@ double tdiff(struct timeval *end, struct timeval *start)
 	return end->tv_sec - start->tv_sec + (end->tv_usec - start->tv_usec) / 1000000.0;
 	return end->tv_sec - start->tv_sec + (end->tv_usec - start->tv_usec) / 1000000.0;
 }
 }
 
 
+
+int format_temperature(char * const buf, const int pad, const bool highprecision, const bool unicode, const float temp)
+{
+	return
+	sprintf(buf, "%*.*f%sC"
+	        , pad
+	        , (highprecision ? 1 : 0)
+	        , temp
+	        , (unicode ? "\xb0" : "")
+	);
+}
+
+int format_temperature_sz(const int numsz, const bool unicode)
+{
+	return numsz + (unicode ? 2 : 1);
+}
+
+
 bool extract_sockaddr(struct pool *pool, char *url)
 bool extract_sockaddr(struct pool *pool, char *url)
 {
 {
 	char *url_begin, *url_end, *ipv6_begin, *ipv6_end, *port_start = NULL;
 	char *url_begin, *url_end, *ipv6_begin, *ipv6_end, *port_start = NULL;

+ 4 - 0
util.h

@@ -340,6 +340,10 @@ struct timeval *select_timeout(struct timeval *tvp_timeout, struct timeval *tvp_
 }
 }
 
 
 
 
+extern int format_temperature(char * const buf, const int pad, const bool highprecision, const bool unicode, const float temp);
+extern int format_temperature_sz(const int numsz, const bool unicode);
+
+
 #define RUNONCE(rv)  do {  \
 #define RUNONCE(rv)  do {  \
 	static bool _runonce = false;  \
 	static bool _runonce = false;  \
 	if (_runonce)  \
 	if (_runonce)  \