mirror of
https://github.com/amadvance/snapraid.git
synced 2026-11-30 03:47:05 -05:00
Group print functions
This commit is contained in:
parent
11a8e301f4
commit
34d02d4b41
4 changed files with 94 additions and 82 deletions
|
|
@ -596,60 +596,6 @@ static double raid_prob_of_one_or_more_failures(double array_failure_rate, doubl
|
|||
return poisson_prob_n_or_more_failures(raid_failure_rate, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a string with space padding.
|
||||
*/
|
||||
static void printl(const char* str, size_t pad)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
printf("%s", str);
|
||||
|
||||
len = strlen(str);
|
||||
|
||||
while (len < pad) {
|
||||
putchar(' ');
|
||||
++len;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a probability with space padding.
|
||||
*/
|
||||
static void printp(double v, size_t pad)
|
||||
{
|
||||
char buf[64];
|
||||
const char* s = "%";
|
||||
|
||||
if (v > 0.1)
|
||||
snprintf(buf, sizeof(buf), "%5.2f%s", v, s);
|
||||
else if (v > 0.01)
|
||||
snprintf(buf, sizeof(buf), "%6.3f%s", v, s);
|
||||
else if (v > 0.001)
|
||||
snprintf(buf, sizeof(buf), "%7.4f%s", v, s);
|
||||
else if (v > 0.0001)
|
||||
snprintf(buf, sizeof(buf), "%8.5f%s", v, s);
|
||||
else if (v > 0.00001)
|
||||
snprintf(buf, sizeof(buf), "%9.6f%s", v, s);
|
||||
else if (v > 0.000001)
|
||||
snprintf(buf, sizeof(buf), "%10.7f%s", v, s);
|
||||
else if (v > 0.0000001)
|
||||
snprintf(buf, sizeof(buf), "%11.8f%s", v, s);
|
||||
else if (v > 0.00000001)
|
||||
snprintf(buf, sizeof(buf), "%12.9f%s", v, s);
|
||||
else if (v > 0.000000001)
|
||||
snprintf(buf, sizeof(buf), "%13.10f%s", v, s);
|
||||
else if (v > 0.0000000001)
|
||||
snprintf(buf, sizeof(buf), "%14.11f%s", v, s);
|
||||
else if (v > 0.00000000001)
|
||||
snprintf(buf, sizeof(buf), "%15.12f%s", v, s);
|
||||
else if (v > 0.000000000001)
|
||||
snprintf(buf, sizeof(buf), "%16.13f%s", v, s);
|
||||
else
|
||||
snprintf(buf, sizeof(buf), "%17.14f%s", v, s);
|
||||
printl(buf, pad);
|
||||
}
|
||||
|
||||
static void state_smart(unsigned n, tommy_list* low)
|
||||
{
|
||||
tommy_node* i;
|
||||
|
|
|
|||
|
|
@ -4136,34 +4136,6 @@ void state_usage_parity(struct snapraid_state* state, unsigned* waiting_map, uns
|
|||
state->tick_last = now;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a repeated char.
|
||||
*/
|
||||
static void printc(char c, size_t pad)
|
||||
{
|
||||
while (pad) {
|
||||
putchar(c);
|
||||
--pad;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a string with space padding.
|
||||
*/
|
||||
static void printr(const char* str, size_t pad)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
len = strlen(str);
|
||||
|
||||
while (len < pad) {
|
||||
putchar(' ');
|
||||
++len;
|
||||
}
|
||||
|
||||
printf("%s", str);
|
||||
}
|
||||
|
||||
#define USAGE_COLUMN 60
|
||||
|
||||
void state_usage_graph(struct snapraid_state* state, struct snapraid_io* io, unsigned current, unsigned oldest)
|
||||
|
|
|
|||
|
|
@ -302,6 +302,76 @@ void msg_flush(void)
|
|||
unlock_msg();
|
||||
}
|
||||
|
||||
void printc(char c, size_t pad)
|
||||
{
|
||||
while (pad) {
|
||||
putchar(c);
|
||||
--pad;
|
||||
}
|
||||
}
|
||||
|
||||
void printr(const char* str, size_t pad)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
len = strlen(str);
|
||||
|
||||
while (len < pad) {
|
||||
putchar(' ');
|
||||
++len;
|
||||
}
|
||||
|
||||
printf("%s", str);
|
||||
}
|
||||
|
||||
void printl(const char* str, size_t pad)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
printf("%s", str);
|
||||
|
||||
len = strlen(str);
|
||||
|
||||
while (len < pad) {
|
||||
putchar(' ');
|
||||
++len;
|
||||
}
|
||||
}
|
||||
|
||||
void printp(double v, size_t pad)
|
||||
{
|
||||
char buf[64];
|
||||
const char* s = "%";
|
||||
|
||||
if (v > 0.1)
|
||||
snprintf(buf, sizeof(buf), "%5.2f%s", v, s);
|
||||
else if (v > 0.01)
|
||||
snprintf(buf, sizeof(buf), "%6.3f%s", v, s);
|
||||
else if (v > 0.001)
|
||||
snprintf(buf, sizeof(buf), "%7.4f%s", v, s);
|
||||
else if (v > 0.0001)
|
||||
snprintf(buf, sizeof(buf), "%8.5f%s", v, s);
|
||||
else if (v > 0.00001)
|
||||
snprintf(buf, sizeof(buf), "%9.6f%s", v, s);
|
||||
else if (v > 0.000001)
|
||||
snprintf(buf, sizeof(buf), "%10.7f%s", v, s);
|
||||
else if (v > 0.0000001)
|
||||
snprintf(buf, sizeof(buf), "%11.8f%s", v, s);
|
||||
else if (v > 0.00000001)
|
||||
snprintf(buf, sizeof(buf), "%12.9f%s", v, s);
|
||||
else if (v > 0.000000001)
|
||||
snprintf(buf, sizeof(buf), "%13.10f%s", v, s);
|
||||
else if (v > 0.0000000001)
|
||||
snprintf(buf, sizeof(buf), "%14.11f%s", v, s);
|
||||
else if (v > 0.00000000001)
|
||||
snprintf(buf, sizeof(buf), "%15.12f%s", v, s);
|
||||
else if (v > 0.000000000001)
|
||||
snprintf(buf, sizeof(buf), "%16.13f%s", v, s);
|
||||
else
|
||||
snprintf(buf, sizeof(buf), "%17.14f%s", v, s);
|
||||
printl(buf, pad);
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of buffers for esc().
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -186,6 +186,30 @@ void msg_verbose(const char* format, ...) __attribute__((format(attribute_printf
|
|||
*/
|
||||
void msg_flush(void);
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/* print */
|
||||
|
||||
/**
|
||||
* Print a repeated char.
|
||||
*/
|
||||
void printc(char c, size_t pad);
|
||||
|
||||
/**
|
||||
* Print a string with right space padding.
|
||||
*/
|
||||
void printr(const char* str, size_t pad);
|
||||
|
||||
/**
|
||||
* Print a string with left space padding.
|
||||
*/
|
||||
void printl(const char* str, size_t pad);
|
||||
|
||||
/**
|
||||
* Print a probability with space padding.
|
||||
*/
|
||||
void printp(double v, size_t pad);
|
||||
|
||||
/****************************************************************************/
|
||||
/* escape */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue