From bdb76808ee3397e9fd3d382fb0e9c8ace7cc8f13 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 30 Mar 2022 23:16:55 -0500 Subject: [PATCH] Update: Move the program data into the main for control. Move parameter initialization and deallocation for FLL program data into main.c. --- level_3/byte_dump/c/byte_dump.c | 124 +++----- level_3/byte_dump/c/byte_dump.h | 6 +- level_3/byte_dump/c/common.c | 12 - level_3/byte_dump/c/common.h | 72 ----- level_3/byte_dump/c/main.c | 8 +- level_3/byte_dump/c/private-byte_dump.c | 542 ++++++++++++++++---------------- level_3/byte_dump/c/private-byte_dump.h | 6 +- level_3/byte_dump/c/private-common.c | 24 +- level_3/byte_dump/c/private-common.h | 42 ++- 9 files changed, 376 insertions(+), 460 deletions(-) diff --git a/level_3/byte_dump/c/byte_dump.c b/level_3/byte_dump/c/byte_dump.c index 5f31edd..78cc792 100644 --- a/level_3/byte_dump/c/byte_dump.c +++ b/level_3/byte_dump/c/byte_dump.c @@ -74,14 +74,10 @@ extern "C" { #endif // _di_byte_dump_print_help_ #ifndef _di_byte_dump_main_ - f_status_t byte_dump_main(byte_dump_main_t * const main, const f_console_arguments_t *arguments) { + f_status_t byte_dump_main(fll_program_data_t * const main, const f_console_arguments_t *arguments) { f_status_t status = F_none; - f_console_parameter_t parameters[] = byte_dump_console_parameter_t_initialize; - main->parameters.array = parameters; - main->parameters.used = byte_dump_total_parameters_d; - // Identify priority of color parameters. { f_console_parameter_id_t ids[3] = { byte_dump_parameter_no_color_e, byte_dump_parameter_light_e, byte_dump_parameter_dark_e }; @@ -112,8 +108,6 @@ extern "C" { if (F_status_is_error(status)) { fll_error_print(main->error, F_status_set_fine(status), "fll_program_parameter_process", F_true); - byte_dump_main_delete(main); - return F_status_set_error(status); } } @@ -129,8 +123,6 @@ extern "C" { if (F_status_is_error(status)) { fll_error_print(main->error, F_status_set_fine(status), "f_console_parameter_prioritize_right", F_true); - byte_dump_main_delete(main); - return status; } @@ -156,6 +148,10 @@ extern "C" { } } + byte_dump_data_t data = byte_dump_data_t_initialize; + data.main = main; + data.argv = main->parameters.arguments.array; + // Identify priority of mode parameters. { f_console_parameter_id_t ids[5] = { byte_dump_parameter_hexidecimal_e, byte_dump_parameter_duodecimal_e, byte_dump_parameter_octal_e, byte_dump_parameter_binary_e, byte_dump_parameter_decimal_e }; @@ -167,25 +163,23 @@ extern "C" { if (F_status_is_error(status)) { fll_error_print(main->error, F_status_set_fine(status), "f_console_parameter_prioritize_right", F_true); - byte_dump_main_delete(main); - return F_status_set_error(status); } if (choice == byte_dump_parameter_hexidecimal_e) { - main->mode = byte_dump_mode_hexidecimal_e; + data.mode = byte_dump_mode_hexidecimal_e; } else if (choice == byte_dump_parameter_duodecimal_e) { - main->mode = byte_dump_mode_duodecimal_e; + data.mode = byte_dump_mode_duodecimal_e; } else if (choice == byte_dump_parameter_octal_e) { - main->mode = byte_dump_mode_octal_e; + data.mode = byte_dump_mode_octal_e; } else if (choice == byte_dump_parameter_binary_e) { - main->mode = byte_dump_mode_binary_e; + data.mode = byte_dump_mode_binary_e; } else if (choice == byte_dump_parameter_decimal_e) { - main->mode = byte_dump_mode_decimal_e; + data.mode = byte_dump_mode_decimal_e; } } @@ -200,19 +194,17 @@ extern "C" { if (F_status_is_error(status)) { fll_error_print(main->error, F_status_set_fine(status), "f_console_parameter_prioritize_right", F_true); - byte_dump_main_delete(main); - return F_status_set_error(status); } if (choice == byte_dump_parameter_normal_e) { - main->presentation = byte_dump_presentation_normal_e; + data.presentation = byte_dump_presentation_normal_e; } else if (choice == byte_dump_parameter_simple_e) { - main->presentation = byte_dump_presentation_simple_e; + data.presentation = byte_dump_presentation_simple_e; } else if (choice == byte_dump_parameter_classic_e) { - main->presentation = byte_dump_presentation_classic_e; + data.presentation = byte_dump_presentation_classic_e; } } @@ -227,38 +219,30 @@ extern "C" { if (F_status_is_error(status)) { fll_error_print(main->error, F_status_set_fine(status), "f_console_parameter_prioritize_right", F_true); - byte_dump_main_delete(main); - return F_status_set_error(status); } if (choice == byte_dump_parameter_narrow_e) { - if (main->options & byte_dump_option_wide_d) { - main->options -= byte_dump_option_wide_d; + if (data.options & byte_dump_option_wide_d) { + data.options -= byte_dump_option_wide_d; } } else if (choice == byte_dump_parameter_wide_e) { - main->options |= byte_dump_option_wide_d; + data.options |= byte_dump_option_wide_d; } } - f_string_static_t * const argv = main->parameters.arguments.array; - status = F_none; if (main->parameters.array[byte_dump_parameter_help_e].result == f_console_result_found_e) { byte_dump_print_help(main->output.to, main->context); - byte_dump_main_delete(main); - return F_none; } if (main->parameters.array[byte_dump_parameter_version_e].result == f_console_result_found_e) { fll_program_print_version(main->output.to, byte_dump_program_version_s); - byte_dump_main_delete(main); - return F_none; } @@ -272,8 +256,6 @@ extern "C" { funlockfile(main->error.to.stream); - byte_dump_main_delete(main); - return F_status_set_error(F_parameter); } @@ -281,7 +263,7 @@ extern "C" { const f_array_length_t index = main->parameters.array[byte_dump_parameter_width_e].values.array[main->parameters.array[byte_dump_parameter_width_e].values.used - 1]; f_number_unsigned_t number = 0; - status = fl_conversion_dynamic_to_number_unsigned(argv[index], &number); + status = fl_conversion_dynamic_to_number_unsigned(data.argv[index], &number); if (F_status_is_error(status) || number < 1 || number >= 0xfb) { flockfile(main->error.to.stream); @@ -296,14 +278,12 @@ extern "C" { funlockfile(main->error.to.stream); - byte_dump_main_delete(main); - if (F_status_is_error(status)) return status; return F_status_set_error(F_parameter); } - main->width = (uint8_t) number; + data.width = (uint8_t) number; } if (main->parameters.array[byte_dump_parameter_first_e].result == f_console_result_found_e) { @@ -315,8 +295,6 @@ extern "C" { funlockfile(main->error.to.stream); - byte_dump_main_delete(main); - return F_status_set_error(F_parameter); } @@ -324,7 +302,7 @@ extern "C" { const f_array_length_t index = main->parameters.array[byte_dump_parameter_first_e].values.array[main->parameters.array[byte_dump_parameter_first_e].values.used - 1]; f_number_unsigned_t number = 0; - status = fl_conversion_dynamic_to_number_unsigned(argv[index], &number); + status = fl_conversion_dynamic_to_number_unsigned(data.argv[index], &number); if (F_status_is_error(status) || number > F_number_t_size_unsigned_d) { flockfile(main->error.to.stream); @@ -339,14 +317,12 @@ extern "C" { funlockfile(main->error.to.stream); - byte_dump_main_delete(main); - if (F_status_is_error(status)) return status; return F_status_set_error(F_parameter); } - main->first = number; + data.first = number; } if (main->parameters.array[byte_dump_parameter_last_e].result == f_console_result_found_e) { @@ -358,8 +334,6 @@ extern "C" { funlockfile(main->error.to.stream); - byte_dump_main_delete(main); - return F_status_set_error(F_parameter); } @@ -367,7 +341,7 @@ extern "C" { const f_array_length_t index = main->parameters.array[byte_dump_parameter_last_e].values.array[main->parameters.array[byte_dump_parameter_last_e].values.used - 1]; f_number_unsigned_t number = 0; - status = fl_conversion_dynamic_to_number_unsigned(argv[index], &number); + status = fl_conversion_dynamic_to_number_unsigned(data.argv[index], &number); if (F_status_is_error(status) || number < 0 || number > F_number_t_size_unsigned_d) { flockfile(main->error.to.stream); @@ -382,18 +356,16 @@ extern "C" { funlockfile(main->error.to.stream); - byte_dump_main_delete(main); - if (F_status_is_error(status)) return status; return F_status_set_error(F_parameter); } - main->last = number; + data.last = number; } if (main->parameters.array[byte_dump_parameter_first_e].result == f_console_result_additional_e && main->parameters.array[byte_dump_parameter_last_e].result == f_console_result_additional_e) { - if (main->first > main->last) { + if (data.first > data.last) { flockfile(main->error.to.stream); fl_print_format("%[%QThe parameter '%]", main->error.to.stream, main->context.set.error, main->error.prefix, main->context.set.error); @@ -404,13 +376,11 @@ extern "C" { funlockfile(main->error.to.stream); - byte_dump_main_delete(main); - return F_status_set_error(F_parameter); } // Store last position as a relative offset from first instead of an absolute position. - main->last = (main->last - main->first) + 1; + data.last = (data.last - data.first) + 1; } if (main->process_pipe) { @@ -424,19 +394,19 @@ extern "C" { f_print_dynamic_raw(f_string_eol_s, main->output.to.stream); fl_print_format("%[Piped Byte Dump: (in ", main->output.to.stream, main->context.set.title); - if (main->mode == byte_dump_mode_hexidecimal_e) { + if (data.mode == byte_dump_mode_hexidecimal_e) { f_print_dynamic_raw(byte_dump_print_strings_hexidecimal_s, main->output.to.stream); } - else if (main->mode == byte_dump_mode_duodecimal_e) { + else if (data.mode == byte_dump_mode_duodecimal_e) { f_print_dynamic_raw(byte_dump_print_strings_duodecimal_s, main->output.to.stream); } - else if (main->mode == byte_dump_mode_octal_e) { + else if (data.mode == byte_dump_mode_octal_e) { f_print_dynamic_raw(byte_dump_print_strings_octal_s, main->output.to.stream); } - else if (main->mode == byte_dump_mode_binary_e) { + else if (data.mode == byte_dump_mode_binary_e) { f_print_dynamic_raw(byte_dump_print_strings_binary_s, main->output.to.stream); } - else if (main->mode == byte_dump_mode_decimal_e) { + else if (data.mode == byte_dump_mode_decimal_e) { f_print_dynamic_raw(byte_dump_print_strings_decimal_s, main->output.to.stream); } @@ -444,13 +414,11 @@ extern "C" { funlockfile(main->output.to.stream); - status = byte_dump_file(main, f_string_empty_s, file); + status = byte_dump_file(&data, f_string_empty_s, file); if (F_status_is_error(status)) { fll_error_print(main->error, F_status_set_fine(status), "byte_dump_file", F_true); - byte_dump_main_delete(main); - return status; } } @@ -463,7 +431,7 @@ extern "C" { for (f_array_length_t counter = 0; counter < main->parameters.remaining.used; ++counter) { - status = f_file_exists(argv[main->parameters.remaining.array[counter]]); + status = f_file_exists(data.argv[main->parameters.remaining.array[counter]]); if (status == F_false) { status = F_status_set_error(F_file_found_not); @@ -474,15 +442,13 @@ extern "C" { missing_files = status; } - fll_error_file_print(main->error, F_status_set_fine(status), "f_file_exists", F_true, argv[main->parameters.remaining.array[counter]], f_file_operation_open_s, fll_error_file_type_file_e); + fll_error_file_print(main->error, F_status_set_fine(status), "f_file_exists", F_true, data.argv[main->parameters.remaining.array[counter]], f_file_operation_open_s, fll_error_file_type_file_e); } } // for if (missing_files != F_none) { status = F_status_set_error(missing_files); - byte_dump_main_delete(main); - return status; } } @@ -491,12 +457,10 @@ extern "C" { for (f_array_length_t counter = 0; counter < main->parameters.remaining.used; ++counter) { - status = f_file_stream_open(argv[main->parameters.remaining.array[counter]], f_string_empty_s, &file); + status = f_file_stream_open(data.argv[main->parameters.remaining.array[counter]], f_string_empty_s, &file); if (F_status_is_error(status)) { - fll_error_file_print(main->error, F_status_set_fine(status), "f_file_open", F_true, argv[main->parameters.remaining.array[counter]], f_file_operation_open_s, fll_error_file_type_file_e); - - byte_dump_main_delete(main); + fll_error_file_print(main->error, F_status_set_fine(status), "f_file_open", F_true, data.argv[main->parameters.remaining.array[counter]], f_file_operation_open_s, fll_error_file_type_file_e); return status; } @@ -504,21 +468,21 @@ extern "C" { flockfile(main->output.to.stream); fl_print_format("%r%[Byte Dump of: %]%[", main->output.to.stream, f_string_eol_s, main->context.set.title, main->context.set.title, main->context.set.notable); - fl_print_format("%Q%] %[(in ", main->output.to.stream, argv[main->parameters.remaining.array[counter]], main->context.set.notable, main->context.set.title); + fl_print_format("%Q%] %[(in ", main->output.to.stream, data.argv[main->parameters.remaining.array[counter]], main->context.set.notable, main->context.set.title); - if (main->mode == byte_dump_mode_hexidecimal_e) { + if (data.mode == byte_dump_mode_hexidecimal_e) { f_print_dynamic_raw(byte_dump_print_strings_hexidecimal_s, main->output.to.stream); } - else if (main->mode == byte_dump_mode_duodecimal_e) { + else if (data.mode == byte_dump_mode_duodecimal_e) { f_print_dynamic_raw(byte_dump_print_strings_duodecimal_s, main->output.to.stream); } - else if (main->mode == byte_dump_mode_octal_e) { + else if (data.mode == byte_dump_mode_octal_e) { f_print_dynamic_raw(byte_dump_print_strings_octal_s, main->output.to.stream); } - else if (main->mode == byte_dump_mode_binary_e) { + else if (data.mode == byte_dump_mode_binary_e) { f_print_dynamic_raw(byte_dump_print_strings_binary_s, main->output.to.stream); } - else if (main->mode == byte_dump_mode_decimal_e) { + else if (data.mode == byte_dump_mode_decimal_e) { f_print_dynamic_raw(byte_dump_print_strings_decimal_s, main->output.to.stream); } @@ -526,7 +490,7 @@ extern "C" { funlockfile(main->output.to.stream); - status = byte_dump_file(main, argv[main->parameters.remaining.array[counter]], file); + status = byte_dump_file(&data, data.argv[main->parameters.remaining.array[counter]], file); f_file_stream_close(F_true, &file); @@ -542,12 +506,10 @@ extern "C" { } else { if (main->error.verbosity != f_console_verbosity_quiet_e) { - fll_error_file_print(main->error, F_status_set_fine(status), "byte_dump_file", F_true, argv[main->parameters.remaining.array[counter]], f_file_operation_process_s, fll_error_file_type_file_e); + fll_error_file_print(main->error, F_status_set_fine(status), "byte_dump_file", F_true, data.argv[main->parameters.remaining.array[counter]], f_file_operation_process_s, fll_error_file_type_file_e); } } - byte_dump_main_delete(main); - return status; } } // for @@ -562,8 +524,6 @@ extern "C" { status = F_status_set_error(F_parameter); } - byte_dump_main_delete(main); - return status; } #endif // _di_byte_dump_main_ diff --git a/level_3/byte_dump/c/byte_dump.h b/level_3/byte_dump/c/byte_dump.h index 37e4c61..11e107f 100644 --- a/level_3/byte_dump/c/byte_dump.h +++ b/level_3/byte_dump/c/byte_dump.h @@ -73,8 +73,6 @@ extern "C" { /** * Execute main program. * - * Be sure to call byte_dump_main_delete() after executing this. - * * @param main * The main program data. * @param arguments @@ -95,11 +93,9 @@ extern "C" { * F_parameter (with error bit) on an argument error. * * Status codes (with error bit) are returned on any problem. - * - * @see byte_dump_main_delete() */ #ifndef _di_byte_dump_main_ - extern f_status_t byte_dump_main(byte_dump_main_t * const main, const f_console_arguments_t *arguments); + extern f_status_t byte_dump_main(fll_program_data_t * const main, const f_console_arguments_t *arguments); #endif // _di_byte_dump_main_ #ifdef __cplusplus diff --git a/level_3/byte_dump/c/common.c b/level_3/byte_dump/c/common.c index ce344ba..a9659c7 100644 --- a/level_3/byte_dump/c/common.c +++ b/level_3/byte_dump/c/common.c @@ -67,18 +67,6 @@ extern "C" { const f_string_static_t byte_dump_long_classic_s = macro_f_string_static_t_initialize(BYTE_DUMP_long_classic_s, 0, BYTE_DUMP_long_classic_s_length); #endif // _di_byte_dump_parameters_ -#ifndef _di_byte_dump_main_delete_ - f_status_t byte_dump_main_delete(byte_dump_main_t * const main) { - - f_console_parameters_delete(&main->parameters); - - macro_f_color_context_t_delete_simple(main->context); - macro_f_color_context_t_clear(main->context) - - return F_none; - } -#endif // _di_byte_dump_main_delete_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/byte_dump/c/common.h b/level_3/byte_dump/c/common.h index d4a61b8..a75ef87 100644 --- a/level_3/byte_dump/c/common.h +++ b/level_3/byte_dump/c/common.h @@ -336,78 +336,6 @@ extern "C" { #define byte_dump_total_parameters_d 25 #endif // _di_byte_dump_parameters_ -/** - * The main program data. - * - * parameters: The state of pre-defined parameters passed to the program. - * process_pipe: Designate whether or not to process the input pipe. - * output: The output file for general printing. - * error: The output file for error printing. - * warning: The output file for warning printing. - * signal: The process signal management structure. - * context: The color context. - */ -#ifndef _di_byte_dump_main_t_ - typedef struct { - f_console_parameters_t parameters; - - uint16_t signal_check; - bool process_pipe; - - fl_print_t output; - fl_print_t error; - fl_print_t warning; - - f_signal_t signal; - - uint64_t first; - uint64_t last; - uint8_t width; - uint8_t mode; - uint8_t presentation; - uint8_t options; - - f_color_context_t context; - } byte_dump_main_t; - - #define byte_dump_main_t_initialize \ - { \ - f_console_parameters_t_initialize, \ - 0, \ - F_false, \ - fl_print_t_initialize, \ - macro_fl_print_t_initialize_error(), \ - macro_fl_print_t_initialize_warning(), \ - f_signal_t_initialize, \ - 0, \ - 0, \ - 8, \ - byte_dump_option_wide_d, \ - byte_dump_mode_hexidecimal_e, \ - byte_dump_presentation_normal_e, \ - f_color_context_t_initialize, \ - } -#endif // _di_byte_dump_main_t_ - -/** - * Deallocate main. - * - * Be sure to call this after executing byte_dump_main(). - * - * @param main - * The main program data. - * - * @return - * F_none on success. - * - * Status codes (with error bit) are returned on any problem. - * - * @see byte_dump_main() - */ -#ifndef _di_byte_dump_main_delete_ - extern f_status_t byte_dump_main_delete(byte_dump_main_t * const main); -#endif // _di_byte_dump_main_delete_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/byte_dump/c/main.c b/level_3/byte_dump/c/main.c index 02dc1a0..62c3db4 100644 --- a/level_3/byte_dump/c/main.c +++ b/level_3/byte_dump/c/main.c @@ -3,7 +3,11 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { const f_console_arguments_t arguments = macro_f_console_arguments_t_initialize(argc, argv, envp); - byte_dump_main_t data = byte_dump_main_t_initialize; + fll_program_data_t data = fll_program_data_t_initialize; + + f_console_parameter_t parameters[] = byte_dump_console_parameter_t_initialize; + data.parameters.array = parameters; + data.parameters.used = byte_dump_total_parameters_d; if (f_pipe_input_exists()) { data.process_pipe = F_true; @@ -13,6 +17,8 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { const f_status_t status = byte_dump_main(&data, &arguments); + fll_program_data_delete(&data); + fll_program_standard_setdown(&data.signal); if (F_status_is_error(status)) return 1; diff --git a/level_3/byte_dump/c/private-byte_dump.c b/level_3/byte_dump/c/private-byte_dump.c index ea3a29b..99cf142 100644 --- a/level_3/byte_dump/c/private-byte_dump.c +++ b/level_3/byte_dump/c/private-byte_dump.c @@ -7,7 +7,7 @@ extern "C" { #endif #ifndef _di_byte_dump_file_ - f_status_t byte_dump_file(byte_dump_main_t * const main, const f_string_static_t file_name, const f_file_t file) { + f_status_t byte_dump_file(byte_dump_data_t * const data, const f_string_static_t file_name, const f_file_t file) { f_status_t status = F_none; @@ -28,43 +28,43 @@ extern "C" { // Store the current character main until it can be printed. f_utf_string_dynamic_t characters = f_utf_string_dynamic_t_initialize; - f_utf_char_t character_array[main->width]; + f_utf_char_t character_array[data->width]; f_array_length_t character_current = 0; // The row starts based on the first byte starting point and how many columns of bytes are displayed per row. - if (main->first) { - cell.row = main->first / main->width; - offset = main->first % main->width; + if (data->first) { + cell.row = data->first / data->width; + offset = data->first % data->width; // fseek() cannot be used on a PIPE, so read instead of seek. if (file_name.used) { - byte_get = fseek(file.stream, main->first, SEEK_SET); + byte_get = fseek(file.stream, data->first, SEEK_SET); } else { - f_char_t skip[main->first]; + f_char_t skip[data->first]; - byte_get = fread(skip, sizeof(f_char_t), main->first, file.stream); + byte_get = fread(skip, sizeof(f_char_t), data->first, file.stream); } } - memset(&character_array, 0, sizeof(f_utf_char_t) * main->width); + memset(&character_array, 0, sizeof(f_utf_char_t) * data->width); characters.string = character_array; characters.used = 0; - characters.size = main->width; + characters.size = data->width; // Record when a character is invalid. - f_char_t invalid[main->width]; - memset(&invalid, 0, sizeof(f_char_t) * main->width); + f_char_t invalid[data->width]; + memset(&invalid, 0, sizeof(f_char_t) * data->width); if (byte_get >= 0) { for (;;) { - if (!((++main->signal_check) % byte_dump_signal_check_d)) { - if (byte_dump_signal_received(main)) { + if (!((++data->main->signal_check) % byte_dump_signal_check_d)) { + if (byte_dump_signal_received(data)) { return F_status_set_error(F_interrupt); } - main->signal_check = 0; + data->main->signal_check = 0; } byte_get = getc(file.stream); @@ -82,7 +82,7 @@ extern "C" { if (character_reset) { characters.used = 0; character_reset = F_false; - memset(&invalid, 0, sizeof(f_char_t) * main->width); + memset(&invalid, 0, sizeof(f_char_t) * data->width); } character_current = characters.used++; @@ -146,165 +146,165 @@ extern "C" { } } - flockfile(main->output.to.stream); + flockfile(data->main->output.to.stream); - if (byte_dump_print_character_fragment(main, characters, invalid, width_utf, 1, &previous, &cell, &offset) == F_true) { + if (byte_dump_print_character_fragment(data, characters, invalid, width_utf, 1, &previous, &cell, &offset) == F_true) { character_reset = F_true; } if (width_utf > 1) { - if (byte_dump_print_character_fragment(main, characters, invalid, width_utf, 2, &previous, &cell, &offset) == F_true) { + if (byte_dump_print_character_fragment(data, characters, invalid, width_utf, 2, &previous, &cell, &offset) == F_true) { character_reset = F_true; } if (width_utf > 2) { - if (byte_dump_print_character_fragment(main, characters, invalid, width_utf, 3, &previous, &cell, &offset) == F_true) { + if (byte_dump_print_character_fragment(data, characters, invalid, width_utf, 3, &previous, &cell, &offset) == F_true) { character_reset = F_true; } if (width_utf > 3) { - if (byte_dump_print_character_fragment(main, characters, invalid, width_utf, 4, &previous, &cell, &offset) == F_true) { + if (byte_dump_print_character_fragment(data, characters, invalid, width_utf, 4, &previous, &cell, &offset) == F_true) { character_reset = F_true; } } } - if (main->last) { + if (data->last) { position += width_utf; - if (position >= main->last) { - funlockfile(main->output.to.stream); + if (position >= data->last) { + funlockfile(data->main->output.to.stream); break; } } } - else if (main->last) { + else if (data->last) { ++position; - if (position >= main->last) { - funlockfile(main->output.to.stream); + if (position >= data->last) { + funlockfile(data->main->output.to.stream); break; } } - funlockfile(main->output.to.stream); + funlockfile(data->main->output.to.stream); width_utf = -1; } // for } - flockfile(main->output.to.stream); + flockfile(data->main->output.to.stream); // Print placeholders to fill out the remaining line and then optionally print the text block. - if (cell.column && cell.column < main->width) { + if (cell.column && cell.column < data->width) { previous.bytes = 0; previous.invalid = 0; - while (cell.column < main->width) { + while (cell.column < data->width) { - if (main->parameters.array[byte_dump_parameter_unicode_e].result == f_console_result_found_e) { - f_print_terminated(" ", main->output.to.stream); + if (data->main->parameters.array[byte_dump_parameter_unicode_e].result == f_console_result_found_e) { + f_print_terminated(" ", data->main->output.to.stream); } - else if (main->mode == byte_dump_mode_hexidecimal_e) { - f_print_terminated(" ", main->output.to.stream); + else if (data->mode == byte_dump_mode_hexidecimal_e) { + f_print_terminated(" ", data->main->output.to.stream); } - else if (main->mode == byte_dump_mode_duodecimal_e) { - f_print_terminated(" ", main->output.to.stream); + else if (data->mode == byte_dump_mode_duodecimal_e) { + f_print_terminated(" ", data->main->output.to.stream); } - else if (main->mode == byte_dump_mode_octal_e) { - f_print_terminated(" ", main->output.to.stream); + else if (data->mode == byte_dump_mode_octal_e) { + f_print_terminated(" ", data->main->output.to.stream); } - else if (main->mode == byte_dump_mode_binary_e) { - f_print_terminated(" ", main->output.to.stream); + else if (data->mode == byte_dump_mode_binary_e) { + f_print_terminated(" ", data->main->output.to.stream); } - else if (main->mode == byte_dump_mode_decimal_e) { - f_print_terminated(" ", main->output.to.stream); + else if (data->mode == byte_dump_mode_decimal_e) { + f_print_terminated(" ", data->main->output.to.stream); } ++cell.column; - if (cell.column < main->width) { - if (main->parameters.array[byte_dump_parameter_unicode_e].result == f_console_result_found_e) { + if (cell.column < data->width) { + if (data->main->parameters.array[byte_dump_parameter_unicode_e].result == f_console_result_found_e) { if (!(cell.column % 4)) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } - else if (main->mode == byte_dump_mode_hexidecimal_e) { + else if (data->mode == byte_dump_mode_hexidecimal_e) { if (!(cell.column % 8)) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } - else if (main->mode == byte_dump_mode_duodecimal_e) { + else if (data->mode == byte_dump_mode_duodecimal_e) { if (!(cell.column % 6)) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } - else if (main->mode == byte_dump_mode_octal_e) { + else if (data->mode == byte_dump_mode_octal_e) { if (!(cell.column % 6)) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } - else if (main->mode == byte_dump_mode_binary_e) { + else if (data->mode == byte_dump_mode_binary_e) { if (!(cell.column % 6)) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } - else if (main->mode == byte_dump_mode_decimal_e) { + else if (data->mode == byte_dump_mode_decimal_e) { if (!(cell.column % 6)) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } } } // while - if (main->parameters.array[byte_dump_parameter_text_e].result == f_console_result_found_e) { - byte_dump_print_text(main, characters, invalid, &previous, &offset); + if (data->main->parameters.array[byte_dump_parameter_text_e].result == f_console_result_found_e) { + byte_dump_print_text(data, characters, invalid, &previous, &offset); } else { - f_print_dynamic_raw(f_string_eol_s, main->output.to.stream); + f_print_dynamic_raw(f_string_eol_s, data->main->output.to.stream); } } - f_print_dynamic_raw(f_string_eol_s, main->output.to.stream); + f_print_dynamic_raw(f_string_eol_s, data->main->output.to.stream); - funlockfile(main->output.to.stream); + funlockfile(data->main->output.to.stream); // Make sure to flush standard out to help prevent standard error from causing problems. - fflush(main->output.to.stream); + fflush(data->main->output.to.stream); if (found_invalid_utf) { - flockfile(main->error.to.stream); + flockfile(data->main->error.to.stream); - fl_print_format("%[Invalid UTF-8 codes were detected for file '%]", main->error.to.stream, main->context.set.error, main->context.set.error); - fl_print_format("%[%Q%]", main->error.to.stream, main->context.set.notable, file_name.used ? file_name : f_string_ascii_minus_s, main->context.set.notable); - fl_print_format("%['.%]%r%r", main->error.to.stream, main->context.set.error, main->context.set.error, f_string_eol_s, f_string_eol_s); + fl_print_format("%[Invalid UTF-8 codes were detected for file '%]", data->main->error.to.stream, data->main->context.set.error, data->main->context.set.error); + fl_print_format("%[%Q%]", data->main->error.to.stream, data->main->context.set.notable, file_name.used ? file_name : f_string_ascii_minus_s, data->main->context.set.notable); + fl_print_format("%['.%]%r%r", data->main->error.to.stream, data->main->context.set.error, data->main->context.set.error, f_string_eol_s, f_string_eol_s); - funlockfile(main->error.to.stream); + funlockfile(data->main->error.to.stream); } if (ferror(file.stream)) { // @todo determine what the error is and display it. - flockfile(main->error.to.stream); + flockfile(data->main->error.to.stream); - fl_print_format("%[%Qread() failed for '%]", main->error.to.stream, main->context.set.error, main->error.prefix, main->context.set.error); - fl_print_format("%[%Q%]", main->error.to.stream, main->context.set.notable, file_name.used ? file_name : f_string_ascii_minus_s, main->context.set.notable); - fl_print_format("%['.%]%r%r", main->error.to.stream, main->context.set.error, main->context.set.error, f_string_eol_s, f_string_eol_s); + fl_print_format("%[%Qread() failed for '%]", data->main->error.to.stream, data->main->context.set.error, data->main->error.prefix, data->main->context.set.error); + fl_print_format("%[%Q%]", data->main->error.to.stream, data->main->context.set.notable, file_name.used ? file_name : f_string_ascii_minus_s, data->main->context.set.notable); + fl_print_format("%['.%]%r%r", data->main->error.to.stream, data->main->context.set.error, data->main->context.set.error, f_string_eol_s, f_string_eol_s); - funlockfile(main->error.to.stream); + funlockfile(data->main->error.to.stream); status = F_status_set_error(F_failure); } - fflush(main->error.to.stream); + fflush(data->main->error.to.stream); return status; } #endif // _di_byte_dump_file_ #ifndef _di_byte_dump_print_character_fragment_ - bool byte_dump_print_character_fragment(byte_dump_main_t * const main, const f_utf_string_static_t characters, const f_char_t invalid[], const uint8_t width_utf, const f_char_t byte_current, byte_dump_previous_t *previous, byte_dump_cell_t *cell, f_char_t *offset) { + bool byte_dump_print_character_fragment(byte_dump_data_t * const data, const f_utf_string_static_t characters, const f_char_t invalid[], const uint8_t width_utf, const f_char_t byte_current, byte_dump_previous_t *previous, byte_dump_cell_t *cell, f_char_t *offset) { f_char_t byte = 0; @@ -326,65 +326,65 @@ extern "C" { } if (!cell->column) { - fl_print_format("%[%016_UL%] ", main->output.to.stream, main->context.set.notable, cell->row, main->context.set.notable); + fl_print_format("%[%016_UL%] ", data->main->output.to.stream, data->main->context.set.notable, cell->row, data->main->context.set.notable); if (*offset) { f_char_t offset_to_print = *offset; // Pad the buffer with spaces to hide any skipped bytes (skipped via --first). - while (offset_to_print && cell->column < main->width) { + while (offset_to_print && cell->column < data->width) { - if (main->parameters.array[byte_dump_parameter_unicode_e].result == f_console_result_found_e) { - f_print_terminated(" ", main->output.to.stream); + if (data->main->parameters.array[byte_dump_parameter_unicode_e].result == f_console_result_found_e) { + f_print_terminated(" ", data->main->output.to.stream); } - else if (main->mode == byte_dump_mode_hexidecimal_e) { - f_print_terminated(" ", main->output.to.stream); + else if (data->mode == byte_dump_mode_hexidecimal_e) { + f_print_terminated(" ", data->main->output.to.stream); } - else if (main->mode == byte_dump_mode_duodecimal_e) { - f_print_terminated(" ", main->output.to.stream); + else if (data->mode == byte_dump_mode_duodecimal_e) { + f_print_terminated(" ", data->main->output.to.stream); } - else if (main->mode == byte_dump_mode_octal_e) { - f_print_terminated(" ", main->output.to.stream); + else if (data->mode == byte_dump_mode_octal_e) { + f_print_terminated(" ", data->main->output.to.stream); } - else if (main->mode == byte_dump_mode_binary_e) { - f_print_terminated(" ", main->output.to.stream); + else if (data->mode == byte_dump_mode_binary_e) { + f_print_terminated(" ", data->main->output.to.stream); } - else if (main->mode == byte_dump_mode_decimal_e) { - f_print_terminated(" ", main->output.to.stream); + else if (data->mode == byte_dump_mode_decimal_e) { + f_print_terminated(" ", data->main->output.to.stream); } --offset_to_print; ++cell->column; - if (cell->column < main->width) { - if (main->parameters.array[byte_dump_parameter_unicode_e].result == f_console_result_found_e) { + if (cell->column < data->width) { + if (data->main->parameters.array[byte_dump_parameter_unicode_e].result == f_console_result_found_e) { if (!(cell->column % 4)) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } - else if (main->mode == byte_dump_mode_hexidecimal_e) { + else if (data->mode == byte_dump_mode_hexidecimal_e) { if (!(cell->column % 8)) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } - else if (main->mode == byte_dump_mode_duodecimal_e) { + else if (data->mode == byte_dump_mode_duodecimal_e) { if (!(cell->column % 6)) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } - else if (main->mode == byte_dump_mode_octal_e) { + else if (data->mode == byte_dump_mode_octal_e) { if (!(cell->column % 6)) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } - else if (main->mode == byte_dump_mode_binary_e) { + else if (data->mode == byte_dump_mode_binary_e) { if (!(cell->column % 4)) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } - else if (main->mode == byte_dump_mode_decimal_e) { + else if (data->mode == byte_dump_mode_decimal_e) { if (!(cell->column % 6)) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } } @@ -392,8 +392,8 @@ extern "C" { } } - if (cell->column < main->width) { - if (main->parameters.array[byte_dump_parameter_unicode_e].result == f_console_result_found_e && !invalid[character_current]) { + if (cell->column < data->width) { + if (data->main->parameters.array[byte_dump_parameter_unicode_e].result == f_console_result_found_e && !invalid[character_current]) { if (byte_current == 1) { uint32_t unicode = 0; @@ -425,73 +425,73 @@ extern "C" { } if (width_utf < 4) { - fl_print_format(" U+%04_U ", main->output.to.stream, unicode); + fl_print_format(" U+%04_U ", data->main->output.to.stream, unicode); } else { - fl_print_format(" U+%06_U ", main->output.to.stream, unicode); + fl_print_format(" U+%06_U ", data->main->output.to.stream, unicode); } } else { // Pad the characters that are incomplete fragments of an already printed valid Unicode. - f_print_terminated(" ", main->output.to.stream); + f_print_terminated(" ", data->main->output.to.stream); } } else { - if (main->mode == byte_dump_mode_hexidecimal_e) { - if (main->parameters.array[byte_dump_parameter_unicode_e].result == f_console_result_found_e) { - f_print_terminated(" ", main->output.to.stream); + if (data->mode == byte_dump_mode_hexidecimal_e) { + if (data->main->parameters.array[byte_dump_parameter_unicode_e].result == f_console_result_found_e) { + f_print_terminated(" ", data->main->output.to.stream); } if (invalid[character_current]) { - fl_print_format(" %[%02_uii%]", main->output.to.stream, main->context.set.error, (uint8_t) byte, main->context.set.error); + fl_print_format(" %[%02_uii%]", data->main->output.to.stream, data->main->context.set.error, (uint8_t) byte, data->main->context.set.error); } else { - fl_print_format(" %02_uii", main->output.to.stream, (uint8_t) byte); + fl_print_format(" %02_uii", data->main->output.to.stream, (uint8_t) byte); } } - else if (main->mode == byte_dump_mode_duodecimal_e) { - if (main->parameters.array[byte_dump_parameter_unicode_e].result == f_console_result_found_e) { - f_print_terminated(" ", main->output.to.stream); + else if (data->mode == byte_dump_mode_duodecimal_e) { + if (data->main->parameters.array[byte_dump_parameter_unicode_e].result == f_console_result_found_e) { + f_print_terminated(" ", data->main->output.to.stream); } if (invalid[character_current]) { - fl_print_format(" %[%03&uii%]", main->output.to.stream, main->context.set.error, (uint8_t) byte, main->context.set.error); + fl_print_format(" %[%03&uii%]", data->main->output.to.stream, data->main->context.set.error, (uint8_t) byte, data->main->context.set.error); } else { - fl_print_format(" %03&uii", main->output.to.stream, (uint8_t) byte); + fl_print_format(" %03&uii", data->main->output.to.stream, (uint8_t) byte); } } - else if (main->mode == byte_dump_mode_octal_e) { - if (main->parameters.array[byte_dump_parameter_unicode_e].result == f_console_result_found_e) { - f_print_terminated(" ", main->output.to.stream); + else if (data->mode == byte_dump_mode_octal_e) { + if (data->main->parameters.array[byte_dump_parameter_unicode_e].result == f_console_result_found_e) { + f_print_terminated(" ", data->main->output.to.stream); } if (invalid[character_current]) { - fl_print_format(" %[%03@uii%]", main->output.to.stream, main->context.set.error, (uint8_t) byte, main->context.set.error); + fl_print_format(" %[%03@uii%]", data->main->output.to.stream, data->main->context.set.error, (uint8_t) byte, data->main->context.set.error); } else { - fl_print_format(" %03@uii", main->output.to.stream, (uint8_t) byte); + fl_print_format(" %03@uii", data->main->output.to.stream, (uint8_t) byte); } } - else if (main->mode == byte_dump_mode_binary_e) { + else if (data->mode == byte_dump_mode_binary_e) { if (invalid[character_current]) { - fl_print_format(" %[%08!uii%]", main->output.to.stream, main->context.set.error, (uint8_t) byte, main->context.set.error); + fl_print_format(" %[%08!uii%]", data->main->output.to.stream, data->main->context.set.error, (uint8_t) byte, data->main->context.set.error); } else { - fl_print_format(" %08!uii", main->output.to.stream, (uint8_t) byte); + fl_print_format(" %08!uii", data->main->output.to.stream, (uint8_t) byte); } } - else if (main->mode == byte_dump_mode_decimal_e) { - if (main->parameters.array[byte_dump_parameter_unicode_e].result == f_console_result_found_e) { - f_print_terminated(" ", main->output.to.stream); + else if (data->mode == byte_dump_mode_decimal_e) { + if (data->main->parameters.array[byte_dump_parameter_unicode_e].result == f_console_result_found_e) { + f_print_terminated(" ", data->main->output.to.stream); } if (invalid[character_current]) { - fl_print_format(" %[%3uii%]", main->output.to.stream, main->context.set.error, (uint8_t) byte, main->context.set.error); + fl_print_format(" %[%3uii%]", data->main->output.to.stream, data->main->context.set.error, (uint8_t) byte, data->main->context.set.error); } else { - fl_print_format(" %3uii", main->output.to.stream, (uint8_t) byte); + fl_print_format(" %3uii", data->main->output.to.stream, (uint8_t) byte); } } } @@ -499,7 +499,7 @@ extern "C" { ++cell->column; } - if (cell->column == main->width) { + if (cell->column == data->width) { uint8_t bytes = 0; if (byte_current < width_utf) { @@ -508,11 +508,11 @@ extern "C" { reset = F_true; - if (main->parameters.array[byte_dump_parameter_text_e].result == f_console_result_found_e) { - byte_dump_print_text(main, characters, invalid, previous, offset); + if (data->main->parameters.array[byte_dump_parameter_text_e].result == f_console_result_found_e) { + byte_dump_print_text(data, characters, invalid, previous, offset); } else { - f_print_dynamic_raw(f_string_eol_s, main->output.to.stream); + f_print_dynamic_raw(f_string_eol_s, data->main->output.to.stream); } cell->column = 0; @@ -528,34 +528,34 @@ extern "C" { } } else { - if (main->parameters.array[byte_dump_parameter_unicode_e].result == f_console_result_found_e) { + if (data->main->parameters.array[byte_dump_parameter_unicode_e].result == f_console_result_found_e) { if (!(cell->column % 4)) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } - else if (main->mode == byte_dump_mode_hexidecimal_e) { + else if (data->mode == byte_dump_mode_hexidecimal_e) { if (!(cell->column % 8)) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } - else if (main->mode == byte_dump_mode_duodecimal_e) { + else if (data->mode == byte_dump_mode_duodecimal_e) { if (!(cell->column % 6)) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } - else if (main->mode == byte_dump_mode_octal_e) { + else if (data->mode == byte_dump_mode_octal_e) { if (!(cell->column % 6)) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } - else if (main->mode == byte_dump_mode_binary_e) { + else if (data->mode == byte_dump_mode_binary_e) { if (!(cell->column % 4)) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } - else if (main->mode == byte_dump_mode_decimal_e) { + else if (data->mode == byte_dump_mode_decimal_e) { if (!(cell->column % 6)) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } } @@ -565,7 +565,7 @@ extern "C" { #endif // _di_byte_dump_print_character_fragment_ #ifndef _di_byte_dump_print_text_ - void byte_dump_print_text(byte_dump_main_t * const main, const f_utf_string_static_t characters, const f_char_t invalid[], byte_dump_previous_t *previous, f_char_t *offset) { + void byte_dump_print_text(byte_dump_data_t * const data, const f_utf_string_static_t characters, const f_char_t invalid[], byte_dump_previous_t *previous, f_char_t *offset) { f_char_t c = 0; uint8_t at = 0; @@ -574,16 +574,16 @@ extern "C" { f_char_t byte[5] = { 0, 0, 0, 0, 0 }; - fl_print_format(" %[%r%] ", main->output.to.stream, main->context.set.notable, byte_dump_character_wall_s, main->context.set.notable); + fl_print_format(" %[%r%] ", data->main->output.to.stream, data->main->context.set.notable, byte_dump_character_wall_s, data->main->context.set.notable); if (*offset) { - if (main->parameters.array[byte_dump_parameter_classic_e].result == f_console_result_found_e) { - while (*offset && at < main->width) { + if (data->main->parameters.array[byte_dump_parameter_classic_e].result == f_console_result_found_e) { + while (*offset && at < data->width) { - f_print_dynamic_raw(f_string_ascii_period_s, main->output.to.stream); + f_print_dynamic_raw(f_string_ascii_period_s, data->main->output.to.stream); - if (main->options & byte_dump_option_wide_d) { - f_print_dynamic_raw(f_string_ascii_space_s, main->output.to.stream); + if (data->options & byte_dump_option_wide_d) { + f_print_dynamic_raw(f_string_ascii_space_s, data->main->output.to.stream); } --(*offset); @@ -591,23 +591,23 @@ extern "C" { } // while } else { - if (main->parameters.array[byte_dump_parameter_placeholder_e].result == f_console_result_found_e) { - for (; *offset && at < main->width; --(*offset), ++at) { + if (data->main->parameters.array[byte_dump_parameter_placeholder_e].result == f_console_result_found_e) { + for (; *offset && at < data->width; --(*offset), ++at) { - fl_print_format("%[%r%]", main->output.to.stream, main->context.set.warning, byte_dump_character_placeholder_s, main->context.set.warning); + fl_print_format("%[%r%]", data->main->output.to.stream, data->main->context.set.warning, byte_dump_character_placeholder_s, data->main->context.set.warning); - if (main->options & byte_dump_option_wide_d) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + if (data->options & byte_dump_option_wide_d) { + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } // for } else { - for (; *offset && at < main->width; --(*offset), ++at) { + for (; *offset && at < data->width; --(*offset), ++at) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); - if (main->options & byte_dump_option_wide_d) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + if (data->options & byte_dump_option_wide_d) { + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } // for } @@ -615,39 +615,39 @@ extern "C" { } // Print placeholders for the remaining fragments of UTF-8 characters printed on previous lines. - if (at < main->width) { + if (at < data->width) { uint8_t bytes_overflow = 0; - if (previous->bytes - 1 > main->width) { - bytes_overflow = previous->bytes - 1 - main->width; + if (previous->bytes - 1 > data->width) { + bytes_overflow = previous->bytes - 1 - data->width; } if (previous->bytes) { - if (main->parameters.array[byte_dump_parameter_placeholder_e].result == f_console_result_found_e) { - for (; at < previous->bytes && at < main->width; ++at) { + if (data->main->parameters.array[byte_dump_parameter_placeholder_e].result == f_console_result_found_e) { + for (; at < previous->bytes && at < data->width; ++at) { if (previous->invalid) { - fl_print_format("%[%r%]", main->output.to.stream, main->context.set.error, byte_dump_character_placeholder_s, main->context.set.error); + fl_print_format("%[%r%]", data->main->output.to.stream, data->main->context.set.error, byte_dump_character_placeholder_s, data->main->context.set.error); } - else if (main->parameters.array[byte_dump_parameter_classic_e].result == f_console_result_found_e) { - f_print_dynamic_raw(f_string_ascii_period_s, main->output.to.stream); + else if (data->main->parameters.array[byte_dump_parameter_classic_e].result == f_console_result_found_e) { + f_print_dynamic_raw(f_string_ascii_period_s, data->main->output.to.stream); } else { - fl_print_format("%[%r%]", main->output.to.stream, main->context.set.warning, byte_dump_character_placeholder_s, main->context.set.warning); + fl_print_format("%[%r%]", data->main->output.to.stream, data->main->context.set.warning, byte_dump_character_placeholder_s, data->main->context.set.warning); } - if (main->options & byte_dump_option_wide_d) { - f_print_dynamic_raw(f_string_ascii_space_s, main->output.to.stream); + if (data->options & byte_dump_option_wide_d) { + f_print_dynamic_raw(f_string_ascii_space_s, data->main->output.to.stream); } } // for } else { - for (; at < previous->bytes && at < main->width; ++at) { + for (; at < previous->bytes && at < data->width; ++at) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); - if (main->options & byte_dump_option_wide_d) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + if (data->options & byte_dump_option_wide_d) { + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } // for } @@ -662,21 +662,21 @@ extern "C" { } } - for (uint8_t i = 0; i < characters.used && at < main->width; ++i, ++at) { + for (uint8_t i = 0; i < characters.used && at < data->width; ++i, ++at) { c = macro_f_utf_char_t_to_char_1(characters.string[i]); width_utf = macro_f_utf_byte_width_is(c); if (invalid[i]) { - fl_print_format("%[%r%]", main->output.to.stream, main->context.set.error, byte_dump_character_incomplete_s, main->context.set.error); + fl_print_format("%[%r%]", data->main->output.to.stream, data->main->context.set.error, byte_dump_character_incomplete_s, data->main->context.set.error); - if (main->options & byte_dump_option_wide_d) { - f_print_dynamic_raw(f_string_ascii_space_s, main->output.to.stream); + if (data->options & byte_dump_option_wide_d) { + f_print_dynamic_raw(f_string_ascii_space_s, data->main->output.to.stream); } } else if (f_utf_character_is_control(characters.string[i]) == F_true) { - if (main->presentation == byte_dump_presentation_normal_e) { - fl_print_format("%[%[", main->output.to.stream, main->context.set.notable, main->context.set.warning); + if (data->presentation == byte_dump_presentation_normal_e) { + fl_print_format("%[%[", data->main->output.to.stream, data->main->context.set.notable, data->main->context.set.warning); if (width_utf) { byte[0] = c; @@ -702,82 +702,82 @@ extern "C" { byte[1] = 0; } - f_print_safely(byte, width_utf, main->output.to.stream); + f_print_safely(byte, width_utf, data->main->output.to.stream); } else { - f_print_character_safely(c, main->output.to.stream); + f_print_character_safely(c, data->main->output.to.stream); } - fl_print_format("%]%]", main->output.to.stream, main->context.set.warning, main->context.set.notable); + fl_print_format("%]%]", data->main->output.to.stream, data->main->context.set.warning, data->main->context.set.notable); - if (main->options & byte_dump_option_wide_d) { + if (data->options & byte_dump_option_wide_d) { if (f_utf_character_is_wide(characters.string[i]) != F_true) { - f_print_dynamic_raw(f_string_ascii_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_ascii_space_s, data->main->output.to.stream); } } } else { - if (main->presentation == byte_dump_presentation_simple_e) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + if (data->presentation == byte_dump_presentation_simple_e) { + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); if (width_utf > 1) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); if (width_utf > 2) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); if (width_utf > 3) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } } } - else if (main->presentation == byte_dump_presentation_classic_e) { - f_print_dynamic_raw(f_string_ascii_period_s, main->output.to.stream); + else if (data->presentation == byte_dump_presentation_classic_e) { + f_print_dynamic_raw(f_string_ascii_period_s, data->main->output.to.stream); if (width_utf > 1) { - f_print_dynamic_raw(f_string_ascii_period_s, main->output.to.stream); + f_print_dynamic_raw(f_string_ascii_period_s, data->main->output.to.stream); if (width_utf > 2) { - f_print_dynamic_raw(f_string_ascii_period_s, main->output.to.stream); + f_print_dynamic_raw(f_string_ascii_period_s, data->main->output.to.stream); if (width_utf > 3) { - f_print_dynamic_raw(f_string_ascii_period_s, main->output.to.stream); + f_print_dynamic_raw(f_string_ascii_period_s, data->main->output.to.stream); } } } } - if (main->options & byte_dump_option_wide_d) { - f_print_dynamic_raw(f_string_ascii_space_s, main->output.to.stream); + if (data->options & byte_dump_option_wide_d) { + f_print_dynamic_raw(f_string_ascii_space_s, data->main->output.to.stream); } } } else if (f_utf_character_is_whitespace(characters.string[i]) == F_true) { - if (main->parameters.array[byte_dump_parameter_classic_e].result == f_console_result_found_e) { - f_print_dynamic_raw(f_string_ascii_period_s, main->output.to.stream); + if (data->main->parameters.array[byte_dump_parameter_classic_e].result == f_console_result_found_e) { + f_print_dynamic_raw(f_string_ascii_period_s, data->main->output.to.stream); } else { - fl_print_format("%[%[%r%]%]", main->output.to.stream, main->context.set.notable, main->context.set.warning, f_print_sequence_space_s, main->context.set.warning, main->context.set.notable); + fl_print_format("%[%[%r%]%]", data->main->output.to.stream, data->main->context.set.notable, data->main->context.set.warning, f_print_sequence_space_s, data->main->context.set.warning, data->main->context.set.notable); } - if (main->options & byte_dump_option_wide_d) { - f_print_dynamic_raw(f_string_ascii_space_s, main->output.to.stream); + if (data->options & byte_dump_option_wide_d) { + f_print_dynamic_raw(f_string_ascii_space_s, data->main->output.to.stream); } } else if (f_utf_character_is_zero_width(characters.string[i]) == F_true) { - if (main->presentation == byte_dump_presentation_classic_e) { - f_print_dynamic_raw(f_string_ascii_period_s, main->output.to.stream); + if (data->presentation == byte_dump_presentation_classic_e) { + f_print_dynamic_raw(f_string_ascii_period_s, data->main->output.to.stream); } - else if (main->parameters.array[byte_dump_parameter_placeholder_e].result == f_console_result_found_e) { - fl_print_format("%[%[%r%]%]", main->output.to.stream, main->context.set.notable, main->context.set.warning, byte_dump_character_placeholder_s, main->context.set.warning, main->context.set.notable); + else if (data->main->parameters.array[byte_dump_parameter_placeholder_e].result == f_console_result_found_e) { + fl_print_format("%[%[%r%]%]", data->main->output.to.stream, data->main->context.set.notable, data->main->context.set.warning, byte_dump_character_placeholder_s, data->main->context.set.warning, data->main->context.set.notable); } else { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } - if (main->options & byte_dump_option_wide_d) { - f_print_dynamic_raw(f_string_ascii_space_s, main->output.to.stream); + if (data->options & byte_dump_option_wide_d) { + f_print_dynamic_raw(f_string_ascii_space_s, data->main->output.to.stream); } } else if (width_utf) { @@ -787,10 +787,10 @@ extern "C" { // Print invalid placeholder for invalid UTF-8 widths. if (invalid[i]) { - fl_print_format("%[%r%]", main->output.to.stream, main->context.set.error, byte_dump_character_incomplete_s, main->context.set.error); + fl_print_format("%[%r%]", data->main->output.to.stream, data->main->context.set.error, byte_dump_character_incomplete_s, data->main->context.set.error); } else { - fl_print_format("%[%r%]", main->output.to.stream, main->context.set.warning, byte_dump_character_incomplete_s, main->context.set.warning); + fl_print_format("%[%r%]", data->main->output.to.stream, data->main->context.set.warning, byte_dump_character_incomplete_s, data->main->context.set.warning); } } else if (width_utf == 2) { @@ -801,17 +801,17 @@ extern "C" { // Use space to represent Specials codes. // 0xefbfbd00 is excluded because it is printable (and is the "Replacement Character" code). - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } else if (characters.string[i] >= 0xe290a700 && characters.string[i] <= 0xe290bf00) { // Use space to represent Control Pictues codes that are not currently defined but are reserved. - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } else if (characters.string[i] >= 0xee808000 && characters.string[i] <= 0xefa3bf00) { // Use space to represent Private Use Area codes. - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } else { print = F_true; @@ -820,124 +820,124 @@ extern "C" { else if (characters.string[i] >= 0xf09c80a0 && characters.string[i] <= 0xf09c80bd) { // Use space to represent Variation Selectors Supplement codes. - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } else if (characters.string[i] >= 0xf3b08080 && characters.string[i] <= 0xf3bfbfbf) { // Use space to represent Supplemental Private Use Area-A codes. - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } else if (characters.string[i] >= 0xf4808080 && characters.string[i] <= 0xf48fbfbf) { // Use space to represent Supplemental Private Use Area-B codes. - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } else { print = F_true; } if (print) { - f_print_character(c, main->output.to.stream); + f_print_character(c, data->main->output.to.stream); if (width_utf > 1) { - f_print_character(macro_f_utf_char_t_to_char_2(characters.string[i]), main->output.to.stream); + f_print_character(macro_f_utf_char_t_to_char_2(characters.string[i]), data->main->output.to.stream); if (width_utf > 2) { - f_print_character(macro_f_utf_char_t_to_char_3(characters.string[i]), main->output.to.stream); + f_print_character(macro_f_utf_char_t_to_char_3(characters.string[i]), data->main->output.to.stream); if (width_utf > 3) { - f_print_character(macro_f_utf_char_t_to_char_4(characters.string[i]), main->output.to.stream); + f_print_character(macro_f_utf_char_t_to_char_4(characters.string[i]), data->main->output.to.stream); } } } if (f_utf_character_is_combining(characters.string[i]) == F_true) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } - if (main->options & byte_dump_option_wide_d) { + if (data->options & byte_dump_option_wide_d) { if (width_utf == 1 || f_utf_character_is_wide(characters.string[i]) != F_true) { - f_print_dynamic_raw(f_string_ascii_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_ascii_space_s, data->main->output.to.stream); } } } else { - if (main->options & byte_dump_option_wide_d) { - f_print_dynamic_raw(f_string_ascii_space_s, main->output.to.stream); + if (data->options & byte_dump_option_wide_d) { + f_print_dynamic_raw(f_string_ascii_space_s, data->main->output.to.stream); } } } else { - f_print_character(c, main->output.to.stream); + f_print_character(c, data->main->output.to.stream); - if (main->options & byte_dump_option_wide_d) { - f_print_dynamic_raw(f_string_ascii_space_s, main->output.to.stream); + if (data->options & byte_dump_option_wide_d) { + f_print_dynamic_raw(f_string_ascii_space_s, data->main->output.to.stream); } } // Print placeholders when using UTF-8 characters to simulate the spaces bytes used for the character. - if (width_utf > 1 && at + 1 < main->width) { - if (main->parameters.array[byte_dump_parameter_placeholder_e].result == f_console_result_found_e) { + if (width_utf > 1 && at + 1 < data->width) { + if (data->main->parameters.array[byte_dump_parameter_placeholder_e].result == f_console_result_found_e) { if (invalid[i]) { - fl_print_format("%[%r%]", main->output.to.stream, main->context.set.error, byte_dump_character_placeholder_s, main->context.set.error); + fl_print_format("%[%r%]", data->main->output.to.stream, data->main->context.set.error, byte_dump_character_placeholder_s, data->main->context.set.error); } - else if (main->parameters.array[byte_dump_parameter_classic_e].result == f_console_result_found_e) { - f_print_dynamic_raw(f_string_ascii_period_s, main->output.to.stream); + else if (data->main->parameters.array[byte_dump_parameter_classic_e].result == f_console_result_found_e) { + f_print_dynamic_raw(f_string_ascii_period_s, data->main->output.to.stream); } else { - fl_print_format("%[%r%]", main->output.to.stream, main->context.set.warning, byte_dump_character_placeholder_s, main->context.set.warning); + fl_print_format("%[%r%]", data->main->output.to.stream, data->main->context.set.warning, byte_dump_character_placeholder_s, data->main->context.set.warning); } } else { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } - if (main->options & byte_dump_option_wide_d) { - f_print_dynamic_raw(f_string_ascii_space_s, main->output.to.stream); + if (data->options & byte_dump_option_wide_d) { + f_print_dynamic_raw(f_string_ascii_space_s, data->main->output.to.stream); } ++at; - if (width_utf > 2 && at + 1 < main->width) { - if (main->parameters.array[byte_dump_parameter_placeholder_e].result == f_console_result_found_e) { + if (width_utf > 2 && at + 1 < data->width) { + if (data->main->parameters.array[byte_dump_parameter_placeholder_e].result == f_console_result_found_e) { if (invalid[i]) { - fl_print_format("%[%r%]", main->output.to.stream, main->context.set.error, byte_dump_character_placeholder_s, main->context.set.error); + fl_print_format("%[%r%]", data->main->output.to.stream, data->main->context.set.error, byte_dump_character_placeholder_s, data->main->context.set.error); } - else if (main->parameters.array[byte_dump_parameter_classic_e].result == f_console_result_found_e) { - f_print_dynamic_raw(f_string_ascii_period_s, main->output.to.stream); + else if (data->main->parameters.array[byte_dump_parameter_classic_e].result == f_console_result_found_e) { + f_print_dynamic_raw(f_string_ascii_period_s, data->main->output.to.stream); } else { - fl_print_format("%[%r%]", main->output.to.stream, main->context.set.warning, byte_dump_character_placeholder_s, main->context.set.warning); + fl_print_format("%[%r%]", data->main->output.to.stream, data->main->context.set.warning, byte_dump_character_placeholder_s, data->main->context.set.warning); } } else { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } - if (main->options & byte_dump_option_wide_d) { - f_print_dynamic_raw(f_string_ascii_space_s, main->output.to.stream); + if (data->options & byte_dump_option_wide_d) { + f_print_dynamic_raw(f_string_ascii_space_s, data->main->output.to.stream); } ++at; - if (width_utf > 3 && at + 1 < main->width) { - if (main->parameters.array[byte_dump_parameter_placeholder_e].result == f_console_result_found_e) { + if (width_utf > 3 && at + 1 < data->width) { + if (data->main->parameters.array[byte_dump_parameter_placeholder_e].result == f_console_result_found_e) { if (invalid[i]) { - fl_print_format("%[%r%]", main->output.to.stream, main->context.set.error, byte_dump_character_placeholder_s, main->context.set.error); + fl_print_format("%[%r%]", data->main->output.to.stream, data->main->context.set.error, byte_dump_character_placeholder_s, data->main->context.set.error); } - else if (main->parameters.array[byte_dump_parameter_classic_e].result == f_console_result_found_e) { - f_print_dynamic_raw(f_string_ascii_period_s, main->output.to.stream); + else if (data->main->parameters.array[byte_dump_parameter_classic_e].result == f_console_result_found_e) { + f_print_dynamic_raw(f_string_ascii_period_s, data->main->output.to.stream); } else { - fl_print_format("%[%r%]", main->output.to.stream, main->context.set.warning, byte_dump_character_placeholder_s, main->context.set.warning); + fl_print_format("%[%r%]", data->main->output.to.stream, data->main->context.set.warning, byte_dump_character_placeholder_s, data->main->context.set.warning); } } else { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } - if (main->options & byte_dump_option_wide_d) { - f_print_dynamic_raw(f_string_ascii_space_s, main->output.to.stream); + if (data->options & byte_dump_option_wide_d) { + f_print_dynamic_raw(f_string_ascii_space_s, data->main->output.to.stream); } ++at; @@ -947,36 +947,36 @@ extern "C" { } // for // Print placeholder for the remaining parts of the line. - if (main->parameters.array[byte_dump_parameter_placeholder_e].result == f_console_result_found_e) { - for (; at < main->width; ++at) { + if (data->main->parameters.array[byte_dump_parameter_placeholder_e].result == f_console_result_found_e) { + for (; at < data->width; ++at) { if (invalid[at]) { - fl_print_format("%[%r%]", main->output.to.stream, main->context.set.error, byte_dump_character_placeholder_s, main->context.set.error); + fl_print_format("%[%r%]", data->main->output.to.stream, data->main->context.set.error, byte_dump_character_placeholder_s, data->main->context.set.error); } - else if (main->parameters.array[byte_dump_parameter_classic_e].result == f_console_result_found_e) { - f_print_dynamic_raw(f_string_ascii_period_s, main->output.to.stream); + else if (data->main->parameters.array[byte_dump_parameter_classic_e].result == f_console_result_found_e) { + f_print_dynamic_raw(f_string_ascii_period_s, data->main->output.to.stream); } else { - fl_print_format("%[%r%]", main->output.to.stream, main->context.set.warning, byte_dump_character_placeholder_s, main->context.set.warning); + fl_print_format("%[%r%]", data->main->output.to.stream, data->main->context.set.warning, byte_dump_character_placeholder_s, data->main->context.set.warning); } - if (main->options & byte_dump_option_wide_d) { - f_print_dynamic_raw(f_string_ascii_space_s, main->output.to.stream); + if (data->options & byte_dump_option_wide_d) { + f_print_dynamic_raw(f_string_ascii_space_s, data->main->output.to.stream); } } // for } else { - for (; at < main->width; ++at) { + for (; at < data->width; ++at) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); - if (main->options & byte_dump_option_wide_d) { - f_print_dynamic_raw(f_string_space_s, main->output.to.stream); + if (data->options & byte_dump_option_wide_d) { + f_print_dynamic_raw(f_string_space_s, data->main->output.to.stream); } } // for } - fl_print_format(" %[%r%]%r", main->output.to.stream, main->context.set.notable, byte_dump_character_wall_s, main->context.set.notable, f_string_eol_s); + fl_print_format(" %[%r%]%r", data->main->output.to.stream, data->main->context.set.notable, byte_dump_character_wall_s, data->main->context.set.notable, f_string_eol_s); } #endif // _di_byte_dump_print_text_ diff --git a/level_3/byte_dump/c/private-byte_dump.h b/level_3/byte_dump/c/private-byte_dump.h index 6dac3d6..5d77097 100644 --- a/level_3/byte_dump/c/private-byte_dump.h +++ b/level_3/byte_dump/c/private-byte_dump.h @@ -30,7 +30,7 @@ extern "C" { * F_interrupt (with error bit) on receiving a process signal, such as an interrupt signal. */ #ifndef _di_byte_dump_file_ - extern f_status_t byte_dump_file(byte_dump_main_t * const main, const f_string_static_t file_name, const f_file_t file) F_attribute_visibility_internal_d; + extern f_status_t byte_dump_file(byte_dump_data_t * const data, const f_string_static_t file_name, const f_file_t file) F_attribute_visibility_internal_d; #endif // _di_byte_dump_file_ /** @@ -71,7 +71,7 @@ extern "C" { * @see byte_dump_print_text() */ #ifndef _di_byte_dump_print_character_fragment_ - extern bool byte_dump_print_character_fragment(byte_dump_main_t * const main, const f_utf_string_static_t characters, const f_char_t invalid[], const uint8_t width_utf, const f_char_t byte_current, byte_dump_previous_t *previous, byte_dump_cell_t *cell, f_char_t *offset) F_attribute_visibility_internal_d; + extern bool byte_dump_print_character_fragment(byte_dump_data_t * const data, const f_utf_string_static_t characters, const f_char_t invalid[], const uint8_t width_utf, const f_char_t byte_current, byte_dump_previous_t *previous, byte_dump_cell_t *cell, f_char_t *offset) F_attribute_visibility_internal_d; #endif // _di_byte_dump_print_character_fragment_ /** @@ -93,7 +93,7 @@ extern "C" { * Will be reduced to 0 once used. */ #ifndef _di_byte_dump_print_text_ - extern void byte_dump_print_text(byte_dump_main_t * const main, const f_utf_string_static_t characters, const f_char_t invalid[], byte_dump_previous_t *previous, f_char_t *offset) F_attribute_visibility_internal_d; + extern void byte_dump_print_text(byte_dump_data_t * const data, const f_utf_string_static_t characters, const f_char_t invalid[], byte_dump_previous_t *previous, f_char_t *offset) F_attribute_visibility_internal_d; #endif // _di_byte_dump_print_text_ #ifdef __cplusplus diff --git a/level_3/byte_dump/c/private-common.c b/level_3/byte_dump/c/private-common.c index b6cda39..6cad075 100644 --- a/level_3/byte_dump/c/private-common.c +++ b/level_3/byte_dump/c/private-common.c @@ -6,27 +6,27 @@ extern "C" { #endif #ifndef _di_byte_dump_print_signal_received_ - void byte_dump_print_signal_received(byte_dump_main_t * const main, const f_status_t signal) { + void byte_dump_print_signal_received(byte_dump_data_t * const data, const f_status_t signal) { - if (main->warning.verbosity != f_console_verbosity_verbose_e) return; + if (data->main->warning.verbosity != f_console_verbosity_verbose_e) return; // Must flush and reset color because the interrupt may have interrupted the middle of a print function. - fflush(main->warning.to.stream); + fflush(data->main->warning.to.stream); - flockfile(main->warning.to.stream); + flockfile(data->main->warning.to.stream); - fl_print_format("%]%r%r%[Received signal code %]", main->warning.to.stream, main->context.set.reset, f_string_eol_s, f_string_eol_s, main->context.set.warning, main->context.set.warning); - fl_print_format("%[%i%]", main->warning.to.stream, main->context.set.notable, signal, main->context.set.notable); - fl_print_format("%[.%]%r", main->warning.to.stream, main->context.set.warning, main->context.set.warning, f_string_eol_s); + fl_print_format("%]%r%r%[Received signal code %]", data->main->warning.to.stream, data->main->context.set.reset, f_string_eol_s, f_string_eol_s, data->main->context.set.warning, data->main->context.set.warning); + fl_print_format("%[%i%]", data->main->warning.to.stream, data->main->context.set.notable, signal, data->main->context.set.notable); + fl_print_format("%[.%]%r", data->main->warning.to.stream, data->main->context.set.warning, data->main->context.set.warning, f_string_eol_s); - funlockfile(main->warning.to.stream); + funlockfile(data->main->warning.to.stream); } #endif // _di_byte_dump_print_signal_received_ #ifndef _di_byte_dump_signal_received_ - f_status_t byte_dump_signal_received(byte_dump_main_t * const main) { + f_status_t byte_dump_signal_received(byte_dump_data_t * const data) { - if (main->signal.id == -1) { + if (data->main->signal.id == -1) { return F_false; } @@ -34,7 +34,7 @@ extern "C" { memset(&information, 0, sizeof(struct signalfd_siginfo)); - if (f_signal_read(main->signal, 0, &information) == F_signal) { + if (f_signal_read(data->main->signal, 0, &information) == F_signal) { switch (information.ssi_signo) { case F_signal_abort: case F_signal_broken_pipe: @@ -42,7 +42,7 @@ extern "C" { case F_signal_interrupt: case F_signal_quit: case F_signal_termination: - byte_dump_print_signal_received(main, information.ssi_signo); + byte_dump_print_signal_received(data, information.ssi_signo); return information.ssi_signo; } diff --git a/level_3/byte_dump/c/private-common.h b/level_3/byte_dump/c/private-common.h index b5833e0..ad8ade3 100644 --- a/level_3/byte_dump/c/private-common.h +++ b/level_3/byte_dump/c/private-common.h @@ -13,6 +13,44 @@ extern "C" { #endif /** + * The program data. + * + * argv: The argument structure in the progam data parameters for simplifying syntax. + * first: The first position. + * last: The last position. + * main: The main program data. + * mode: The digit representation mode. + * options: Additional options. + * presentation: The presentation mode. + * width: The number of columns. + */ +#ifndef _di_byte_dump_data_t_ + typedef struct { + fll_program_data_t *main; + f_string_static_t *argv; + + uint64_t first; + uint64_t last; + uint8_t width; + uint8_t mode; + uint8_t presentation; + uint8_t options; + } byte_dump_data_t; + + #define byte_dump_data_t_initialize \ + { \ + 0, \ + 0, \ + 0, \ + 0, \ + 8, \ + byte_dump_mode_hexidecimal_e, \ + byte_dump_presentation_normal_e, \ + byte_dump_option_wide_d, \ + } +#endif // _di_byte_dump_data_t_ + +/** * A main structure for character row and column position (cell). * * column: The column position associated with the character cell. @@ -64,7 +102,7 @@ extern "C" { * The signal received. */ #ifndef _di_byte_dump_print_signal_received_ - extern void byte_dump_print_signal_received(byte_dump_main_t * const main, const f_status_t signal) F_attribute_visibility_internal_d; + extern void byte_dump_print_signal_received(byte_dump_data_t * const data, const f_status_t signal) F_attribute_visibility_internal_d; #endif // _di_byte_dump_print_signal_received_ /** @@ -82,7 +120,7 @@ extern "C" { * @see f_signal_read() */ #ifndef _di_byte_dump_signal_received_ - extern f_status_t byte_dump_signal_received(byte_dump_main_t * const main) F_attribute_visibility_internal_d; + extern f_status_t byte_dump_signal_received(byte_dump_data_t * const data) F_attribute_visibility_internal_d; #endif // _di_byte_dump_signal_received_ #ifdef __cplusplus -- 1.8.3.1