Use nwipe's nomenclature function

Benefits include:

1. Standard fixed width output for disk
throughput, combined throughput and disk
capacity. Allows for better column alignment
when wiping multiple drives.

2. Removal of about 40 lines of duplicated code.
This commit is contained in:
PartialVolume
2020-03-30 16:01:16 +01:00
parent eee523d3d1
commit 030338f1bd
3 changed files with 15 additions and 60 deletions

View File

@@ -2079,15 +2079,7 @@ void* nwipe_gui_status( void* ptr )
nwipe_misc_thread_data = nwipe_thread_data_ptr->nwipe_misc_thread_data;
count = nwipe_misc_thread_data->nwipe_selected;
/* Throughput print formats. */
char* nwipe_tera = "%llu TB/s";
char* nwipe_giga = "%llu GB/s";
char* nwipe_mega = "%llu MB/s";
char* nwipe_kilo = "%llu KB/s";
char* nwipe_unit = "%llu B/s";
/* The throughput format pointer. */
char* nwipe_format;
char nomenclature_result_str[NOMENCLATURE_RESULT_STR_SIZE]; /* temporary usage */
/* Spinner character */
char spinner_string[2];
@@ -2444,26 +2436,10 @@ void* nwipe_gui_status( void* ptr )
}
}
if( c[i]->throughput >= INT64_C( 1000000000000 ) )
{
wprintw( main_window, "[%llu TB/s] ", c[i]->throughput / INT64_C( 1000000000000 ) );
}
else if( c[i]->throughput >= INT64_C( 1000000000 ) )
{
wprintw( main_window, "[%llu GB/s] ", c[i]->throughput / INT64_C( 1000000000 ) );
}
else if( c[i]->throughput >= INT64_C( 1000000 ) )
{
wprintw( main_window, "[%llu MB/s] ", c[i]->throughput / INT64_C( 1000000 ) );
}
else if( c[i]->throughput >= INT64_C( 1000 ) )
{
wprintw( main_window, "[%llu KB/s] ", c[i]->throughput / INT64_C( 1000 ) );
}
else
{
wprintw( main_window, "[%llu B/s] ", c[i]->throughput / INT64_C( 1 ) );
}
/* Determine throughput nomenclature for this drive and output drives throughput to GUI */
Determine_C_B_nomenclature( c[i]->throughput, nomenclature_result_str, NOMENCLATURE_RESULT_STR_SIZE );
wprintw( main_window, "[%s/s] ", nomenclature_result_str );
/* Insert whitespace. */
yy += 1;
@@ -2509,37 +2485,14 @@ void* nwipe_gui_status( void* ptr )
nwipe_throughput = nwipe_misc_thread_data->throughput;
if( nwipe_throughput >= INT64_C( 1000000000000 ) )
{
nwipe_throughput /= INT64_C( 1000000000000 );
nwipe_format = nwipe_tera;
}
else if( nwipe_throughput >= INT64_C( 1000000000 ) )
{
nwipe_throughput /= INT64_C( 1000000000 );
nwipe_format = nwipe_giga;
}
else if( nwipe_throughput >= INT64_C( 1000000 ) )
{
nwipe_throughput /= INT64_C( 1000000 );
nwipe_format = nwipe_mega;
}
else if( nwipe_throughput >= INT64_C( 1000 ) )
{
nwipe_throughput /= INT64_C( 1000 );
nwipe_format = nwipe_kilo;
}
else
{
nwipe_throughput /= INT64_C( 1 );
nwipe_format = nwipe_unit;
}
/* Determine the nomenclature for the combined throughput */
Determine_C_B_nomenclature( nwipe_throughput, nomenclature_result_str, NOMENCLATURE_RESULT_STR_SIZE );
/* Print the combined throughput. */
mvwprintw( stats_window, NWIPE_GUI_STATS_THROUGHPUT_Y, NWIPE_GUI_STATS_THROUGHPUT_X, "Throughput:" );
mvwprintw(
stats_window, NWIPE_GUI_STATS_THROUGHPUT_Y, NWIPE_GUI_STATS_TAB, nwipe_format, nwipe_throughput );
stats_window, NWIPE_GUI_STATS_THROUGHPUT_Y, NWIPE_GUI_STATS_TAB, "%s/s", nomenclature_result_str );
/* Change the current time into a delta. */
nwipe_time_now -= nwipe_time_start;
@@ -2586,7 +2539,7 @@ void* nwipe_gui_status( void* ptr )
/* Print the error count. */
mvwprintw( stats_window, NWIPE_GUI_STATS_ERRORS_Y, NWIPE_GUI_STATS_ERRORS_X, "Errors:" );
mvwprintw(
stats_window, NWIPE_GUI_STATS_ERRORS_Y, NWIPE_GUI_STATS_TAB, "%llu", nwipe_misc_thread_data->errors );
stats_window, NWIPE_GUI_STATS_ERRORS_Y, NWIPE_GUI_STATS_TAB, " %llu", nwipe_misc_thread_data->errors );
/* Add a border. */
box( stats_window, 0, 0 );

View File

@@ -45,4 +45,6 @@ int spinner( nwipe_context_t** ptr, int ); // Return the next spinner character
int compute_stats( void* ptr );
void nwipe_update_speedring( nwipe_speedring_t* speedring, u64 speedring_done, time_t speedring_now );
#define NOMENCLATURE_RESULT_STR_SIZE 8
#endif /* GUI_H_ */

View File

@@ -772,19 +772,19 @@ void Determine_C_B_nomenclature( u64 speed, char* result, int result_array_size
/* Determine the size of throughput so that the correct nomenclature can be used */
if( speed >= INT64_C( 1000000000000 ) )
{
snprintf( result, result_array_size, "%3lluTB", speed / INT64_C( 1000000000000 ) );
snprintf( result, result_array_size, "%3llu TB", speed / INT64_C( 1000000000000 ) );
}
else if( speed >= INT64_C( 1000000000 ) )
{
snprintf( result, result_array_size, "%3lluGB", speed / INT64_C( 1000000000 ) );
snprintf( result, result_array_size, "%3llu GB", speed / INT64_C( 1000000000 ) );
}
else if( speed >= INT64_C( 1000000 ) )
{
snprintf( result, result_array_size, "%3lluMB", speed / INT64_C( 1000000 ) );
snprintf( result, result_array_size, "%3llu MB", speed / INT64_C( 1000000 ) );
}
else if( speed >= INT64_C( 1000 ) )
{
snprintf( result, result_array_size, "%3lluKB", speed / INT64_C( 1000 ) );
snprintf( result, result_array_size, "%3llu KB", speed / INT64_C( 1000 ) );
}
else
{