From 030338f1bd5b9b4d78e6a4159761e4c325d4f5fa Mon Sep 17 00:00:00 2001 From: PartialVolume Date: Mon, 30 Mar 2020 16:01:16 +0100 Subject: [PATCH] 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. --- src/gui.c | 65 +++++++-------------------------------------------- src/gui.h | 2 ++ src/logging.c | 8 +++---- 3 files changed, 15 insertions(+), 60 deletions(-) diff --git a/src/gui.c b/src/gui.c index f1f963b..ae48f16 100644 --- a/src/gui.c +++ b/src/gui.c @@ -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 ); diff --git a/src/gui.h b/src/gui.h index fdaf731..4dc7564 100644 --- a/src/gui.h +++ b/src/gui.h @@ -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_ */ diff --git a/src/logging.c b/src/logging.c index 060c7f6..189c8e6 100644 --- a/src/logging.c +++ b/src/logging.c @@ -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 {