mirror of
https://git.disroot.org/80486DX2-66/polonium.git
synced 2024-12-27 07:30:23 +05:30
feature: enable verbose output conditionally
This commit is contained in:
parent
098644abe5
commit
4dea283b95
@ -14,7 +14,8 @@ enum configurations_bitshift {
|
|||||||
C_BITSHIFT_CONTENTS,
|
C_BITSHIFT_CONTENTS,
|
||||||
C_BITSHIFT_LINE_ENDINGS,
|
C_BITSHIFT_LINE_ENDINGS,
|
||||||
C_BITSHIFT_PRINTABLE,
|
C_BITSHIFT_PRINTABLE,
|
||||||
C_BITSHIFT_CUSTOM_SEED
|
C_BITSHIFT_CUSTOM_SEED,
|
||||||
|
C_BITSHIFT_VERBOSE
|
||||||
};
|
};
|
||||||
|
|
||||||
enum configurations {
|
enum configurations {
|
||||||
@ -22,7 +23,8 @@ enum configurations {
|
|||||||
C_CONTENTS = 1 << C_BITSHIFT_CONTENTS,
|
C_CONTENTS = 1 << C_BITSHIFT_CONTENTS,
|
||||||
C_LINE_ENDINGS = 1 << C_BITSHIFT_LINE_ENDINGS,
|
C_LINE_ENDINGS = 1 << C_BITSHIFT_LINE_ENDINGS,
|
||||||
C_PRINTABLE = 1 << C_BITSHIFT_PRINTABLE,
|
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 {
|
enum file_validation_status {
|
||||||
|
@ -79,6 +79,7 @@ Corrupter_Result corrupt_file(Corrupter_Param* param) {
|
|||||||
|
|
||||||
// copy and cast parameters
|
// copy and cast parameters
|
||||||
FILE* file = param->file;
|
FILE* file = param->file;
|
||||||
|
uint8_t config = param->config;
|
||||||
|
|
||||||
// refuse to operate on non-seekable streams
|
// refuse to operate on non-seekable streams
|
||||||
if (FSEEK_MACRO(file, FILE_OFFSET_C(0), SEEK_SET) != 0 ||
|
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
|
// initialize the PRNG
|
||||||
mt_seed(param->seed);
|
mt_seed(param->seed);
|
||||||
|
|
||||||
for (size_t pass = 0; pass < param->passes; pass++) {
|
if (READ_CONFIG(C_VERBOSE))
|
||||||
// display information
|
for (size_t pass = 0; pass < param->passes; pass++) {
|
||||||
printf("Pass: %zu/%zu", pass + 1, param->passes);
|
// display information
|
||||||
fflush(stdout);
|
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
|
puts(" [OK]");
|
||||||
for (file_offset_t i = start; i < end; i++)
|
}
|
||||||
CORRUPT_BYTE_MACRO;
|
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
|
// write the buffer to the file
|
||||||
rewind(file);
|
rewind(file);
|
||||||
|
@ -44,6 +44,7 @@ const char* ARG_CONTENTS = "-contents";
|
|||||||
const char* ARG_LINE_ENDINGS = "-line-endings";
|
const char* ARG_LINE_ENDINGS = "-line-endings";
|
||||||
const char* ARG_PRINTABLE = "-printable";
|
const char* ARG_PRINTABLE = "-printable";
|
||||||
const char* ARG_SEED = "-seed";
|
const char* ARG_SEED = "-seed";
|
||||||
|
const char* ARG_VERBOSE = "-verbose";
|
||||||
|
|
||||||
/* global variables */
|
/* global variables */
|
||||||
uint32_t PRNG_seed_value;
|
uint32_t PRNG_seed_value;
|
||||||
@ -230,7 +231,9 @@ int main(int argc, char** argv) {
|
|||||||
"\n"
|
"\n"
|
||||||
" -seed : Specify a 32-bit seed for the PRNG. If you want "
|
" -seed : Specify a 32-bit seed for the PRNG. If you want "
|
||||||
"to keep it\n"
|
"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,
|
||||||
program_name,
|
program_name,
|
||||||
UINT16_MAX,
|
UINT16_MAX,
|
||||||
@ -277,6 +280,8 @@ int main(int argc, char** argv) {
|
|||||||
LOOP_ACTION_CONFIG(SET_CONFIG, C_LINE_ENDINGS);
|
LOOP_ACTION_CONFIG(SET_CONFIG, C_LINE_ENDINGS);
|
||||||
} else if (ARG_MATCH(arg, ARG_PRINTABLE)) {
|
} else if (ARG_MATCH(arg, ARG_PRINTABLE)) {
|
||||||
LOOP_ACTION_CONFIG(SET_CONFIG, C_PRINTABLE);
|
LOOP_ACTION_CONFIG(SET_CONFIG, C_PRINTABLE);
|
||||||
|
} else if (ARG_MATCH(arg, ARG_VERBOSE)) {
|
||||||
|
LOOP_ACTION_CONFIG(SET_CONFIG, C_VERBOSE);
|
||||||
} else
|
} else
|
||||||
FATAL_ERROR_RET("Unknown command line parameter '%s'.\n"
|
FATAL_ERROR_RET("Unknown command line parameter '%s'.\n"
|
||||||
"Please invoke the program with argument %s to "
|
"Please invoke the program with argument %s to "
|
||||||
|
Loading…
Reference in New Issue
Block a user