diff --git a/include/common.h b/include/common.h index d9df028..54c4696 100644 --- a/include/common.h +++ b/include/common.h @@ -14,7 +14,8 @@ enum configurations_bitshift { C_BITSHIFT_CONTENTS, C_BITSHIFT_LINE_ENDINGS, C_BITSHIFT_PRINTABLE, - C_BITSHIFT_CUSTOM_SEED + C_BITSHIFT_CUSTOM_SEED, + C_BITSHIFT_VERBOSE }; enum configurations { @@ -22,7 +23,8 @@ enum configurations { C_CONTENTS = 1 << C_BITSHIFT_CONTENTS, C_LINE_ENDINGS = 1 << C_BITSHIFT_LINE_ENDINGS, C_PRINTABLE = 1 << C_BITSHIFT_PRINTABLE, - C_CUSTOM_SEED = 1 << C_BITSHIFT_CUSTOM_SEED + C_CUSTOM_SEED = 1 << C_BITSHIFT_CUSTOM_SEED, + C_VERBOSE = 1 << C_BITSHIFT_VERBOSE }; enum file_validation_status { diff --git a/src/corrupter.c b/src/corrupter.c index 7647e19..64cb960 100644 --- a/src/corrupter.c +++ b/src/corrupter.c @@ -79,6 +79,7 @@ Corrupter_Result corrupt_file(Corrupter_Param* param) { // copy and cast parameters FILE* file = param->file; + uint8_t config = param->config; // refuse to operate on non-seekable streams if (FSEEK_MACRO(file, FILE_OFFSET_C(0), SEEK_SET) != 0 || @@ -160,17 +161,23 @@ Corrupter_Result corrupt_file(Corrupter_Param* param) { // initialize the PRNG mt_seed(param->seed); - for (size_t pass = 0; pass < param->passes; pass++) { - // display information - printf("Pass: %zu/%zu", pass + 1, param->passes); - fflush(stdout); + if (READ_CONFIG(C_VERBOSE)) + for (size_t pass = 0; pass < param->passes; pass++) { + // display information + printf("Pass: %zu/%zu", pass + 1, param->passes); + fflush(stdout); - rewind(file); + // iterate over the file contents + for (file_offset_t i = start; i < end; i++) + CORRUPT_BYTE_MACRO; - // iterate over the file contents - for (file_offset_t i = start; i < end; i++) - CORRUPT_BYTE_MACRO; - } + puts(" [OK]"); + } + else + for (size_t pass = 0; pass < param->passes; pass++) + // iterate over the file contents + for (file_offset_t i = start; i < end; i++) + CORRUPT_BYTE_MACRO; // write the buffer to the file rewind(file); diff --git a/src/main.c b/src/main.c index 5b84cb5..8a6412b 100644 --- a/src/main.c +++ b/src/main.c @@ -44,6 +44,7 @@ const char* ARG_CONTENTS = "-contents"; const char* ARG_LINE_ENDINGS = "-line-endings"; const char* ARG_PRINTABLE = "-printable"; const char* ARG_SEED = "-seed"; +const char* ARG_VERBOSE = "-verbose"; /* global variables */ uint32_t PRNG_seed_value; @@ -230,7 +231,9 @@ int main(int argc, char** argv) { "\n" " -seed : Specify a 32-bit seed for the PRNG. If you want " "to keep it\n" - " random, set the option to `random`.\n", + " random, set the option to `random`.\n" + "\n" + " -verbose : Enable verbose output\n", program_name, program_name, UINT16_MAX, @@ -277,6 +280,8 @@ int main(int argc, char** argv) { LOOP_ACTION_CONFIG(SET_CONFIG, C_LINE_ENDINGS); } else if (ARG_MATCH(arg, ARG_PRINTABLE)) { LOOP_ACTION_CONFIG(SET_CONFIG, C_PRINTABLE); + } else if (ARG_MATCH(arg, ARG_VERBOSE)) { + LOOP_ACTION_CONFIG(SET_CONFIG, C_VERBOSE); } else FATAL_ERROR_RET("Unknown command line parameter '%s'.\n" "Please invoke the program with argument %s to "