|
@@ -2510,9 +2510,12 @@ enum h2bs_fmt {
|
|
|
static const size_t h2bs_fmt_size[] = {6, 10, 11};
|
|
static const size_t h2bs_fmt_size[] = {6, 10, 11};
|
|
|
|
|
|
|
|
static
|
|
static
|
|
|
-char *format_unit(char *buf, bool floatprec, const char *measurement, enum h2bs_fmt fmt, float hashrate, signed char unitin)
|
|
|
|
|
|
|
+int format_unit2(char *buf, size_t sz, bool floatprec, const char *measurement, enum h2bs_fmt fmt, float hashrate, signed char unitin)
|
|
|
{
|
|
{
|
|
|
|
|
+ char *s = buf;
|
|
|
unsigned char prec, i, unit;
|
|
unsigned char prec, i, unit;
|
|
|
|
|
+ int rv = 0;
|
|
|
|
|
+
|
|
|
if (unitin == -1)
|
|
if (unitin == -1)
|
|
|
{
|
|
{
|
|
|
unit = 0;
|
|
unit = 0;
|
|
@@ -2530,27 +2533,24 @@ char *format_unit(char *buf, bool floatprec, const char *measurement, enum h2bs_
|
|
|
prec = 1;
|
|
prec = 1;
|
|
|
else
|
|
else
|
|
|
prec = 2;
|
|
prec = 2;
|
|
|
- sprintf(buf, "%5.*f", prec, hashrate);
|
|
|
|
|
- i = 5;
|
|
|
|
|
|
|
+ _SNP("%5.*f", prec, hashrate);
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
- {
|
|
|
|
|
- sprintf(buf, "%3d", (int)hashrate);
|
|
|
|
|
- i = 3;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ _SNP("%3d", (int)hashrate);
|
|
|
|
|
|
|
|
switch (fmt) {
|
|
switch (fmt) {
|
|
|
case H2B_SPACED:
|
|
case H2B_SPACED:
|
|
|
- buf[i++] = ' ';
|
|
|
|
|
|
|
+ _SNP(" ");
|
|
|
case H2B_SHORT:
|
|
case H2B_SHORT:
|
|
|
- buf[i++] = _unitchar[unit];
|
|
|
|
|
- strcpy(&buf[i], measurement);
|
|
|
|
|
|
|
+ _SNP("%c%s", _unitchar[unit], measurement);
|
|
|
default:
|
|
default:
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return buf;
|
|
|
|
|
|
|
+ return rv;
|
|
|
}
|
|
}
|
|
|
|
|
+#define format_unit(buf, floatprec, measurement, fmt, rate, unitin) \
|
|
|
|
|
+ (void)format_unit2(buf, SSIZE_MAX, floatprec, measurement, fmt, rate, unitin);
|
|
|
|
|
|
|
|
static
|
|
static
|
|
|
char *_multi_format_unit(char **buflist, bool floatprec, const char *measurement, enum h2bs_fmt fmt, const char *delim, int count, const float *numbers, bool isarray)
|
|
char *_multi_format_unit(char **buflist, bool floatprec, const char *measurement, enum h2bs_fmt fmt, const char *delim, int count, const float *numbers, bool isarray)
|
|
@@ -2589,23 +2589,33 @@ char *_multi_format_unit(char **buflist, bool floatprec, const char *measurement
|
|
|
#define multi_format_unit(buf, floatprec, measurement, fmt, delim, count, ...) _multi_format_unit((char *[]){buf}, floatprec, measurement, fmt, delim, count, (float[]){ __VA_ARGS__ }, false)
|
|
#define multi_format_unit(buf, floatprec, measurement, fmt, delim, count, ...) _multi_format_unit((char *[]){buf}, floatprec, measurement, fmt, delim, count, (float[]){ __VA_ARGS__ }, false)
|
|
|
#define multi_format_unit_array(buflist, floatprec, measurement, fmt, count, ...) (void)_multi_format_unit(buflist, floatprec, measurement, fmt, NULL, count, (float[]){ __VA_ARGS__ }, true)
|
|
#define multi_format_unit_array(buflist, floatprec, measurement, fmt, count, ...) (void)_multi_format_unit(buflist, floatprec, measurement, fmt, NULL, count, (float[]){ __VA_ARGS__ }, true)
|
|
|
|
|
|
|
|
-static const char *
|
|
|
|
|
-percentf2(double p, double t, char *buf)
|
|
|
|
|
|
|
+static
|
|
|
|
|
+int percentf3(char * const buf, size_t sz, double p, const double t)
|
|
|
{
|
|
{
|
|
|
|
|
+ char *s = buf;
|
|
|
|
|
+ int rv = 0;
|
|
|
if (!p)
|
|
if (!p)
|
|
|
- return "none";
|
|
|
|
|
|
|
+ _SNP("none");
|
|
|
|
|
+ else
|
|
|
if (t <= p)
|
|
if (t <= p)
|
|
|
- return "100%";
|
|
|
|
|
|
|
+ _SNP("100%%");
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
p /= t;
|
|
p /= t;
|
|
|
if (p < 0.01)
|
|
if (p < 0.01)
|
|
|
- sprintf(buf, ".%02.0f%%", p * 10000); // ".01%"
|
|
|
|
|
|
|
+ _SNP(".%02.0f%%", p * 10000); // ".01%"
|
|
|
else
|
|
else
|
|
|
if (p < 0.1)
|
|
if (p < 0.1)
|
|
|
- sprintf(buf, "%.1f%%", p * 100); // "9.1%"
|
|
|
|
|
|
|
+ _SNP("%.1f%%", p * 100); // "9.1%"
|
|
|
else
|
|
else
|
|
|
- sprintf(buf, "%3.0f%%", p * 100); // " 99%"
|
|
|
|
|
- return buf;
|
|
|
|
|
|
|
+ _SNP("%3.0f%%", p * 100); // " 99%"
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return rv;
|
|
|
}
|
|
}
|
|
|
|
|
+#define percentf2(p, t, buf) (percentf3(buf, SIZE_MAX, p, t), buf)
|
|
|
#define percentf(p, t, buf) percentf2(p, p + t, buf)
|
|
#define percentf(p, t, buf) percentf2(p, p + t, buf)
|
|
|
|
|
|
|
|
#ifdef HAVE_CURSES
|
|
#ifdef HAVE_CURSES
|