1
0
mirror of https://git.disroot.org/80486DX2-66/polonium.git synced 2024-11-27 01:02:02 +05:30

feature: enable verbose output conditionally

This commit is contained in:
Intel A80486DX2-66 2024-11-22 18:40:36 +03:00
parent 1b7e2d4088
commit 1faeb7404a
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B
3 changed files with 26 additions and 14 deletions

View File

@ -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 {

View File

@ -100,6 +100,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 ||
@ -156,19 +157,23 @@ Corrupter_Result corrupt_file(Corrupter_Param* param) {
// initialize the PRNG
mt_seed(param->seed);
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;
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;
return result;
}

View File

@ -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 "