From: Kevin Day Date: Sun, 8 Sep 2019 23:25:31 +0000 (-0500) Subject: Refactor: ename bit_dump to byte_dump X-Git-Tag: 0.5.0~440 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=96f0b2308a17178833a4353271b422ae1a9f3b8b;p=fll Refactor: ename bit_dump to byte_dump This program is operating on a per byte basis. The name 'byte_dump' makes more sense than 'bit_dump'. --- diff --git a/level_3/bit_dump/c/bit_dump.h b/level_3/bit_dump/c/bit_dump.h deleted file mode 100644 index 816b68d..0000000 --- a/level_3/bit_dump/c/bit_dump.h +++ /dev/null @@ -1,260 +0,0 @@ -/** - * FLL - Level 3 - * - * Project: Bit Dump - * API Version: 0.5 - * Licenses: lgplv2.1 - * - * This is intendend to support Unicode 12.1. - * - * When using "text" mode, this program attempts to translate UTF-8 sequences such that certain codes don't cause printing problems. - * There may be cases where there are unknown codes that get printed and the invalid UTF-8 marker may be displayed not by this program but instead by the shell or some other program. - * This can potentially be seen with the program "less". - * The solution is to add the invalid character codes to this project so that this project can properly print the invalid UTF-8 marker and therefore properly display the information. - */ -#ifndef _bit_dump_h - -// libc includes -#include -#include -#include -#include - -// fll-0 includes -#include -#include -#include -#include -#include -#include -#include -#include - -// fll-1 includes -#include -#include -#include -#include - -// fll-2 includes -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _di_bit_dump_version_ - #define bit_dump_major_version "0" - #define bit_dump_minor_version "5" - #define bit_dump_micro_version "0" - #define bit_dump_version bit_dump_major_version "." bit_dump_minor_version "." bit_dump_micro_version -#endif // _di_bit_dump_version_ - -#ifndef _di_bit_dump_name_ - #define bit_dump_name "bit_dump" - #define bit_dump_name_long "Bit Dump" -#endif // _di_bit_dump_name_ - -#ifndef _di_bit_dump_default_allocation_step_ - // provide a UTF-8 friendly allocation step. - #define bit_dump_default_allocation_step 4 -#endif // _di_bit_dump_default_allocation_step_ - -#ifndef _di_bit_dump_defines_ - enum { - bit_dump_mode_hexidecimal, - bit_dump_mode_octal, - bit_dump_mode_binary, - bit_dump_mode_decimal, - }; - - #define bit_dump_sequence_acknowledge "␆" - #define bit_dump_sequence_backspace "␈" - #define bit_dump_sequence_bell "␇" - #define bit_dump_sequence_cancel "␘" - #define bit_dump_sequence_carriage_return "␍" - #define bit_dump_sequence_data_link_escape "␐" - #define bit_dump_sequence_delete "␡" - #define bit_dump_sequence_device_control_1 "␑" - #define bit_dump_sequence_device_control_2 "␒" - #define bit_dump_sequence_device_control_3 "␓" - #define bit_dump_sequence_device_control_4 "␔" - #define bit_dump_sequence_end_of_enquiry "␅" - #define bit_dump_sequence_end_of_medium "␙" - #define bit_dump_sequence_end_of_text "␃" - #define bit_dump_sequence_end_of_transmission "␄" - #define bit_dump_sequence_end_of_transmission_block "␗" - #define bit_dump_sequence_escape "␛" - #define bit_dump_sequence_file_separator "␜" - #define bit_dump_sequence_form_feed "␌" - #define bit_dump_sequence_group_separator "␝" - #define bit_dump_sequence_line_feed "␊" - #define bit_dump_sequence_negative_acknowledge "␕" - #define bit_dump_sequence_new_line "␤" - #define bit_dump_sequence_null "␀" - #define bit_dump_sequence_record_separator "␞" - #define bit_dump_sequence_shift_in "␏" - #define bit_dump_sequence_shift_out "␎" - #define bit_dump_sequence_space "␠" - #define bit_dump_sequence_start_of_header "␁" - #define bit_dump_sequence_start_of_text "␂" - #define bit_dump_sequence_substitute "␚" - #define bit_dump_sequence_synchronous_idle "␖" - #define bit_dump_sequence_tab "␉" - #define bit_dump_sequence_tab_vertical "␋" - #define bit_dump_sequence_unit_separator "␟" - #define bit_dump_sequence_utf_bom "␂" - - #define bit_dump_character_wall "|" - #define bit_dump_character_placeholder "␣" // other likely choices: (substitute form 1: '␚', substitute form 2: '␦'). - #define bit_dump_character_incomplete "�" - #define bit_dump_character_unused "�" - - #define bit_dump_short_binary "b" - #define bit_dump_short_decimal "d" - #define bit_dump_short_hexdecimal "x" - #define bit_dump_short_octal "o" - - #define bit_dump_short_first "f" - #define bit_dump_short_last "l" - #define bit_dump_short_text "t" - #define bit_dump_short_width "w" - #define bit_dump_short_placeholder "p" - - #define bit_dump_long_binary "binary" - #define bit_dump_long_decimal "decimal" - #define bit_dump_long_hexidecimal "hexidecimal" - #define bit_dump_long_octal "octal" - - #define bit_dump_long_first "first" // first offset byte size. - #define bit_dump_long_last "last" // last offset byte size. - #define bit_dump_long_width "width" // number of characters to display per row. - - #define bit_dump_long_text "text" // display text - #define bit_dump_long_placeholder "placeholder" // display (colored) placeholders to signify codes that are UTF-8 fragments. - - enum { - bit_dump_parameter_help, - bit_dump_parameter_light, - bit_dump_parameter_dark, - bit_dump_parameter_no_color, - bit_dump_parameter_version, - - bit_dump_parameter_binary, - bit_dump_parameter_decimal, - bit_dump_parameter_hexidecimal, - bit_dump_parameter_octal, - - bit_dump_parameter_first, - bit_dump_parameter_last, - bit_dump_parameter_width, - - bit_dump_parameter_text, - bit_dump_parameter_placeholder, - }; - - #define bit_dump_console_parameter_initialize \ - { \ - f_console_parameter_initialize(f_console_standard_short_help, f_console_standard_long_help, 0, 0, f_console_type_normal), \ - f_console_parameter_initialize(f_console_standard_short_light, f_console_standard_long_light, 0, 0, f_console_type_inverse), \ - f_console_parameter_initialize(f_console_standard_short_dark, f_console_standard_long_dark, 0, 0, f_console_type_inverse), \ - f_console_parameter_initialize(f_console_standard_short_no_color, f_console_standard_long_no_color, 0, 0, f_console_type_inverse), \ - f_console_parameter_initialize(f_console_standard_short_version, f_console_standard_long_version, 0, 0, f_console_type_inverse), \ - f_console_parameter_initialize(bit_dump_short_binary, bit_dump_long_binary, 0, 0, f_console_type_normal), \ - f_console_parameter_initialize(bit_dump_short_decimal, bit_dump_long_decimal, 0, 0, f_console_type_normal), \ - f_console_parameter_initialize(bit_dump_short_hexdecimal, bit_dump_long_hexidecimal, 0, 0, f_console_type_normal), \ - f_console_parameter_initialize(bit_dump_short_octal, bit_dump_long_octal, 0, 0, f_console_type_normal), \ - f_console_parameter_initialize(bit_dump_short_first, bit_dump_long_first, 0, 1, f_console_type_normal), \ - f_console_parameter_initialize(bit_dump_short_last, bit_dump_long_last, 0, 1, f_console_type_normal), \ - f_console_parameter_initialize(bit_dump_short_width, bit_dump_long_width, 0, 1, f_console_type_normal), \ - f_console_parameter_initialize(bit_dump_short_text, bit_dump_long_text, 0, 0, f_console_type_normal), \ - f_console_parameter_initialize(bit_dump_short_placeholder, bit_dump_long_placeholder, 0, 0, f_console_type_normal), \ - } - - #define bit_dump_total_parameters 14 -#endif // _di_bit_dump_defines_ - -#ifndef _di_bit_dump_data_ - typedef struct { - f_console_parameter parameters[bit_dump_total_parameters]; - - f_string_lengths remaining; - f_bool process_pipe; - - uint64_t first; - uint64_t last; - uint8_t width; - uint8_t mode; - - fl_color_context context; - } bit_dump_data; - - #define bit_dump_data_initialize \ - { \ - bit_dump_console_parameter_initialize, \ - f_string_lengths_initialize, \ - f_false, \ - 0, \ - 0, \ - 8, \ - bit_dump_mode_hexidecimal, \ - fl_color_context_initialize, \ - } -#endif // _di_bit_dump_data_ - -/** - * Print help to standard output. - * - * @param data - * The program data. - * - * @return - * f_none on success. - */ -#ifndef _di_bit_dump_print_help_ - extern f_return_status bit_dump_print_help(const bit_dump_data data); -#endif // _di_bit_dump_print_help_ - -/** - * Execute main program. - * - * Be sure to call bit_dump_delete_data() after executing this. - * - * @param arguments - * The parameters passed to the process. - * @param data - * The program data. - * - * @return - * f_none on success. - * Status codes (with error bit) are returned on any problem. - * - * @see bit_dump_delete_data() - */ -#ifndef _di_bit_dump_main_ - extern f_return_status bit_dump_main(const f_console_arguments arguments, bit_dump_data *data); -#endif // _di_bit_dump_main_ - -/** - * Deallocate data. - * - * Be sure to call this after executing bit_dump_main(). - * - * @param data - * The program data. - * - * @return - * f_none on success. - * Status codes (with error bit) are returned on any problem. - * - * @see bit_dump_main() - */ -#ifndef _di_bit_dump_delete_data_ - extern f_return_status bit_dump_delete_data(bit_dump_data *data); -#endif // _di_bit_dump_delete_data_ - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // _bit_dump_h diff --git a/level_3/bit_dump/c/bit_dump.c b/level_3/byte_dump/c/byte_dump.c similarity index 63% rename from level_3/bit_dump/c/bit_dump.c rename to level_3/byte_dump/c/byte_dump.c index 60aa9ba..6c52202 100644 --- a/level_3/bit_dump/c/bit_dump.c +++ b/level_3/byte_dump/c/byte_dump.c @@ -1,13 +1,13 @@ -#include -#include "private-bit_dump.h" +#include +#include "private-byte_dump.h" #ifdef __cplusplus extern "C" { #endif -#ifndef _di_bit_dump_print_help_ - f_return_status bit_dump_print_help(const bit_dump_data data) { - fll_program_print_help_header(data.context, bit_dump_name_long, bit_dump_version); +#ifndef _di_byte_dump_print_help_ + f_return_status byte_dump_print_help(const byte_dump_data data) { + fll_program_print_help_header(data.context, byte_dump_name_long, byte_dump_version); fll_program_print_help_option(data.context, f_console_standard_short_help, f_console_standard_long_help, f_console_symbol_short_enable, f_console_symbol_long_enable, " Print this help message."); fll_program_print_help_option(data.context, f_console_standard_short_light, f_console_standard_long_light, f_console_symbol_short_disable, f_console_symbol_long_disable, " Output using colors that show up better on light backgrounds"); @@ -17,75 +17,75 @@ extern "C" { printf("%c", f_string_eol); - fll_program_print_help_option(data.context, bit_dump_short_binary, bit_dump_long_binary, f_console_symbol_short_enable, f_console_symbol_long_enable, " Display binary representation."); - fll_program_print_help_option(data.context, bit_dump_short_decimal, bit_dump_long_decimal, f_console_symbol_short_enable, f_console_symbol_long_enable, " Display decimal representation."); - fll_program_print_help_option(data.context, bit_dump_short_hexdecimal, bit_dump_long_hexidecimal, f_console_symbol_short_enable, f_console_symbol_long_enable, "Display hexadecimal representation."); - fll_program_print_help_option(data.context, bit_dump_short_octal, bit_dump_long_octal, f_console_symbol_short_enable, f_console_symbol_long_enable, " Display octal representation."); + fll_program_print_help_option(data.context, byte_dump_short_binary, byte_dump_long_binary, f_console_symbol_short_enable, f_console_symbol_long_enable, " Display binary representation."); + fll_program_print_help_option(data.context, byte_dump_short_decimal, byte_dump_long_decimal, f_console_symbol_short_enable, f_console_symbol_long_enable, " Display decimal representation."); + fll_program_print_help_option(data.context, byte_dump_short_hexdecimal, byte_dump_long_hexidecimal, f_console_symbol_short_enable, f_console_symbol_long_enable, "Display hexadecimal representation."); + fll_program_print_help_option(data.context, byte_dump_short_octal, byte_dump_long_octal, f_console_symbol_short_enable, f_console_symbol_long_enable, " Display octal representation."); - fll_program_print_help_usage(data.context, bit_dump_name, "filename(s)"); + fll_program_print_help_usage(data.context, byte_dump_name, "filename(s)"); printf("When using the "); - fl_color_print(f_standard_output, data.context.notable, data.context.reset, "--%s", bit_dump_long_text); + fl_color_print(f_standard_output, data.context.notable, data.context.reset, "--%s", byte_dump_long_text); printf(" option, some UTF-8 characters may be replaced by your instance and cause display alignment issues."); printf("%c%c", f_string_eol, f_string_eol); printf("Special UTF-8 characters and non-spacing UTF-8 characters may be replaced with a space (or a placeholder when the "); - fl_color_print(f_standard_output, data.context.notable, data.context.reset, "--%s", bit_dump_long_placeholder); + fl_color_print(f_standard_output, data.context.notable, data.context.reset, "--%s", byte_dump_long_placeholder); printf(" option is used)."); printf("%c%c", f_string_eol, f_string_eol); return f_none; } -#endif // _di_bit_dump_print_help_ +#endif // _di_byte_dump_print_help_ -#ifndef _di_bit_dump_main_ - f_return_status bit_dump_main(const f_console_arguments arguments, bit_dump_data *data) { +#ifndef _di_byte_dump_main_ + f_return_status byte_dump_main(const f_console_arguments arguments, byte_dump_data *data) { f_status status = f_none; { - f_console_parameters parameters = { data->parameters, bit_dump_total_parameters }; + f_console_parameters parameters = { data->parameters, byte_dump_total_parameters }; f_console_parameter_ids choices = f_console_parameter_ids_initialize; { - f_console_parameter_id ids[3] = { bit_dump_parameter_no_color, bit_dump_parameter_light, bit_dump_parameter_dark }; + f_console_parameter_id ids[3] = { byte_dump_parameter_no_color, byte_dump_parameter_light, byte_dump_parameter_dark }; choices.id = ids; choices.used = 3; status = fll_program_process_parameters(arguments, parameters, choices, &data->remaining, &data->context); if (f_status_is_error(status)) { - bit_dump_delete_data(data); + byte_dump_delete_data(data); return f_status_set_error(status); } } { - f_console_parameter_id ids[4] = { bit_dump_parameter_hexidecimal, bit_dump_parameter_octal, bit_dump_parameter_binary, bit_dump_parameter_decimal }; - f_console_parameter_id choice = bit_dump_parameter_hexidecimal; + f_console_parameter_id ids[4] = { byte_dump_parameter_hexidecimal, byte_dump_parameter_octal, byte_dump_parameter_binary, byte_dump_parameter_decimal }; + f_console_parameter_id choice = byte_dump_parameter_hexidecimal; choices.id = ids; choices.used = 4; status = fl_console_parameter_prioritize(parameters, choices, &choice); if (f_status_is_error(status)) { - bit_dump_delete_data(data); + byte_dump_delete_data(data); return f_status_set_error(status); } - if (choice == bit_dump_parameter_hexidecimal) { - data->mode = bit_dump_mode_hexidecimal; + if (choice == byte_dump_parameter_hexidecimal) { + data->mode = byte_dump_mode_hexidecimal; } - else if (choice == bit_dump_parameter_octal) { - data->mode = bit_dump_mode_octal; + else if (choice == byte_dump_parameter_octal) { + data->mode = byte_dump_mode_octal; } - else if (choice == bit_dump_parameter_binary) { - data->mode = bit_dump_mode_binary; + else if (choice == byte_dump_parameter_binary) { + data->mode = byte_dump_mode_binary; } - else if (choice == bit_dump_parameter_decimal) { - data->mode = bit_dump_mode_decimal; + else if (choice == byte_dump_parameter_decimal) { + data->mode = byte_dump_mode_decimal; } } } @@ -93,61 +93,61 @@ extern "C" { status = f_none; // execute parameter results. - if (data->parameters[bit_dump_parameter_help].result == f_console_result_found) { - bit_dump_print_help(*data); + if (data->parameters[byte_dump_parameter_help].result == f_console_result_found) { + byte_dump_print_help(*data); } - else if (data->parameters[bit_dump_parameter_version].result == f_console_result_found) { - fll_program_print_version(bit_dump_version); + else if (data->parameters[byte_dump_parameter_version].result == f_console_result_found) { + fll_program_print_version(byte_dump_version); } else if (data->remaining.used > 0 || data->process_pipe) { - if (data->parameters[bit_dump_parameter_width].result == f_console_result_found) { + if (data->parameters[byte_dump_parameter_width].result == f_console_result_found) { fl_color_print_line(f_standard_output, data->context.error, data->context.reset, "Width option was specified but no width was given."); - bit_dump_delete_data(data); + byte_dump_delete_data(data); return f_status_set_error(status); } - else if (data->parameters[bit_dump_parameter_width].result == f_console_result_additional) { - uint64_t number = atoll(arguments.argv[data->parameters[bit_dump_parameter_width].additional.array[0]]); + else if (data->parameters[byte_dump_parameter_width].result == f_console_result_additional) { + uint64_t number = atoll(arguments.argv[data->parameters[byte_dump_parameter_width].additional.array[0]]); if (number < 1 || number >= 0xfb) { fl_color_print_line(f_standard_output, data->context.error, data->context.reset, "Width option can only be a number between 0 and 251."); - bit_dump_delete_data(data); + byte_dump_delete_data(data); return f_status_set_error(status); } data->width = (uint8_t) number; } - if (data->parameters[bit_dump_parameter_first].result == f_console_result_found) { + if (data->parameters[byte_dump_parameter_first].result == f_console_result_found) { fl_color_print_line(f_standard_output, data->context.error, data->context.reset, "First option was specified but no number was given."); - bit_dump_delete_data(data); + byte_dump_delete_data(data); return f_status_set_error(status); } - else if (data->parameters[bit_dump_parameter_first].result == f_console_result_additional) { - uint64_t number = atoll(arguments.argv[data->parameters[bit_dump_parameter_first].additional.array[0]]); + else if (data->parameters[byte_dump_parameter_first].result == f_console_result_additional) { + uint64_t number = atoll(arguments.argv[data->parameters[byte_dump_parameter_first].additional.array[0]]); if (number < 1 || number >= 0xffffffffffffffff) { fl_color_print_line(f_standard_output, data->context.error, data->context.reset, "First option can only be a number between 0 and 18446744073709551615."); - bit_dump_delete_data(data); + byte_dump_delete_data(data); return f_status_set_error(status); } data->first = number; } - if (data->parameters[bit_dump_parameter_last].result == f_console_result_found) { + if (data->parameters[byte_dump_parameter_last].result == f_console_result_found) { fl_color_print_line(f_standard_output, data->context.error, data->context.reset, "Last option was specified but no number was given."); - bit_dump_delete_data(data); + byte_dump_delete_data(data); return f_status_set_error(status); } - else if (data->parameters[bit_dump_parameter_last].result == f_console_result_additional) { - uint64_t number = atoll(arguments.argv[data->parameters[bit_dump_parameter_last].additional.array[0]]); + else if (data->parameters[byte_dump_parameter_last].result == f_console_result_additional) { + uint64_t number = atoll(arguments.argv[data->parameters[byte_dump_parameter_last].additional.array[0]]); if (number < 1 || number >= 0xffffffffffffffff) { fl_color_print_line(f_standard_output, data->context.error, data->context.reset, "Last option can only be a number between 0 and 18446744073709551615."); - bit_dump_delete_data(data); + byte_dump_delete_data(data); return f_status_set_error(status); } @@ -161,7 +161,7 @@ extern "C" { fl_color_print(f_standard_output, data->context.notable, data->context.reset, "%d", data->last); fl_color_print_line(f_standard_output, data->context.error, data->context.reset, ")."); - bit_dump_delete_data(data); + byte_dump_delete_data(data); return f_status_set_error(status); } @@ -181,14 +181,14 @@ extern "C" { missing_files = status; } - bit_dump_print_file_error(data->context, status, "f_file_exists", arguments.argv[data->remaining.array[counter]]); + byte_dump_print_file_error(data->context, status, "f_file_exists", arguments.argv[data->remaining.array[counter]]); } } // for if (missing_files != f_none) { status = f_status_set_error(missing_files); - bit_dump_delete_data(data); + byte_dump_delete_data(data); return status; } } @@ -198,8 +198,8 @@ extern "C" { status = f_file_open(&file, arguments.argv[data->remaining.array[counter]]); if (f_status_is_error(status)) { - bit_dump_print_file_error(data->context, status, "f_file_open", arguments.argv[data->remaining.array[counter]]); - bit_dump_delete_data(data); + byte_dump_print_file_error(data->context, status, "f_file_open", arguments.argv[data->remaining.array[counter]]); + byte_dump_delete_data(data); return status; } @@ -208,27 +208,27 @@ extern "C" { fl_color_print(f_standard_output, data->context.notable, data->context.reset, "%s", arguments.argv[data->remaining.array[counter]]); fl_color_print(f_standard_output, data->context.title, data->context.reset, " (in "); - if (data->mode == bit_dump_mode_hexidecimal) { + if (data->mode == byte_dump_mode_hexidecimal) { fl_color_print(f_standard_output, data->context.title, data->context.reset, "Hexidecimal"); } - else if (data->mode == bit_dump_mode_octal) { + else if (data->mode == byte_dump_mode_octal) { fl_color_print(f_standard_output, data->context.title, data->context.reset, "Octal"); } - else if (data->mode == bit_dump_mode_binary) { + else if (data->mode == byte_dump_mode_binary) { fl_color_print(f_standard_output, data->context.title, data->context.reset, "Binary"); } - else if (data->mode == bit_dump_mode_decimal) { + else if (data->mode == byte_dump_mode_decimal) { fl_color_print(f_standard_output, data->context.title, data->context.reset, "Decimal"); } fl_color_print_line(f_standard_output, data->context.title, data->context.reset, ")"); - status = bit_dump_file(*data, arguments.argv[data->remaining.array[counter]], file); + status = byte_dump_file(*data, arguments.argv[data->remaining.array[counter]], file); f_file_close(&file); if (f_status_is_error(status)) { - bit_dump_delete_data(data); + byte_dump_delete_data(data); return status; } } // for @@ -242,16 +242,16 @@ extern "C" { status = f_status_set_error(f_invalid_parameter); } - bit_dump_delete_data(data); + byte_dump_delete_data(data); return status; } -#endif // _di_bit_dump_main_ +#endif // _di_byte_dump_main_ -#ifndef _di_bit_dump_delete_data_ - f_return_status bit_dump_delete_data(bit_dump_data *data) { +#ifndef _di_byte_dump_delete_data_ + f_return_status byte_dump_delete_data(byte_dump_data *data) { f_status status = f_none; - for (f_string_length i = 0; i < bit_dump_total_parameters; i++) { + for (f_string_length i = 0; i < byte_dump_total_parameters; i++) { f_macro_string_lengths_delete(status, data->parameters[i].additional); } // for @@ -260,7 +260,7 @@ extern "C" { return f_none; } -#endif // _di_bit_dump_delete_data_ +#endif // _di_byte_dump_delete_data_ #ifdef __cplusplus } // extern "C" diff --git a/level_3/byte_dump/c/byte_dump.h b/level_3/byte_dump/c/byte_dump.h new file mode 100644 index 0000000..a08b08b --- /dev/null +++ b/level_3/byte_dump/c/byte_dump.h @@ -0,0 +1,260 @@ +/** + * FLL - Level 3 + * + * Project: Byte Dump + * API Version: 0.5 + * Licenses: lgplv2.1 + * + * This is intendend to support Unicode 12.1. + * + * When using "text" mode, this program attempts to translate UTF-8 sequences such that certain codes don't cause printing problems. + * There may be cases where there are unknown codes that get printed and the invalid UTF-8 marker may be displayed not by this program but instead by the shell or some other program. + * This can potentially be seen with the program "less". + * The solution is to add the invalid character codes to this project so that this project can properly print the invalid UTF-8 marker and therefore properly display the information. + */ +#ifndef _byte_dump_h + +// libc includes +#include +#include +#include +#include + +// fll-0 includes +#include +#include +#include +#include +#include +#include +#include +#include + +// fll-1 includes +#include +#include +#include +#include + +// fll-2 includes +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_byte_dump_version_ + #define byte_dump_major_version "0" + #define byte_dump_minor_version "5" + #define byte_dump_micro_version "0" + #define byte_dump_version byte_dump_major_version "." byte_dump_minor_version "." byte_dump_micro_version +#endif // _di_byte_dump_version_ + +#ifndef _di_byte_dump_name_ + #define byte_dump_name "byte_dump" + #define byte_dump_name_long "Byte Dump" +#endif // _di_byte_dump_name_ + +#ifndef _di_byte_dump_default_allocation_step_ + // provide a UTF-8 friendly allocation step. + #define byte_dump_default_allocation_step 4 +#endif // _di_byte_dump_default_allocation_step_ + +#ifndef _di_byte_dump_defines_ + enum { + byte_dump_mode_hexidecimal, + byte_dump_mode_octal, + byte_dump_mode_binary, + byte_dump_mode_decimal, + }; + + #define byte_dump_sequence_acknowledge "␆" + #define byte_dump_sequence_backspace "␈" + #define byte_dump_sequence_bell "␇" + #define byte_dump_sequence_cancel "␘" + #define byte_dump_sequence_carriage_return "␍" + #define byte_dump_sequence_data_link_escape "␐" + #define byte_dump_sequence_delete "␡" + #define byte_dump_sequence_device_control_1 "␑" + #define byte_dump_sequence_device_control_2 "␒" + #define byte_dump_sequence_device_control_3 "␓" + #define byte_dump_sequence_device_control_4 "␔" + #define byte_dump_sequence_end_of_enquiry "␅" + #define byte_dump_sequence_end_of_medium "␙" + #define byte_dump_sequence_end_of_text "␃" + #define byte_dump_sequence_end_of_transmission "␄" + #define byte_dump_sequence_end_of_transmission_block "␗" + #define byte_dump_sequence_escape "␛" + #define byte_dump_sequence_file_separator "␜" + #define byte_dump_sequence_form_feed "␌" + #define byte_dump_sequence_group_separator "␝" + #define byte_dump_sequence_line_feed "␊" + #define byte_dump_sequence_negative_acknowledge "␕" + #define byte_dump_sequence_new_line "␤" + #define byte_dump_sequence_null "␀" + #define byte_dump_sequence_record_separator "␞" + #define byte_dump_sequence_shift_in "␏" + #define byte_dump_sequence_shift_out "␎" + #define byte_dump_sequence_space "␠" + #define byte_dump_sequence_start_of_header "␁" + #define byte_dump_sequence_start_of_text "␂" + #define byte_dump_sequence_substitute "␚" + #define byte_dump_sequence_synchronous_idle "␖" + #define byte_dump_sequence_tab "␉" + #define byte_dump_sequence_tab_vertical "␋" + #define byte_dump_sequence_unit_separator "␟" + #define byte_dump_sequence_utf_bom "␂" + + #define byte_dump_character_wall "|" + #define byte_dump_character_placeholder "␣" // other likely choices: (substitute form 1: '␚', substitute form 2: '␦'). + #define byte_dump_character_incomplete "�" + #define byte_dump_character_unused "�" + + #define byte_dump_short_binary "b" + #define byte_dump_short_decimal "d" + #define byte_dump_short_hexdecimal "x" + #define byte_dump_short_octal "o" + + #define byte_dump_short_first "f" + #define byte_dump_short_last "l" + #define byte_dump_short_text "t" + #define byte_dump_short_width "w" + #define byte_dump_short_placeholder "p" + + #define byte_dump_long_binary "binary" + #define byte_dump_long_decimal "decimal" + #define byte_dump_long_hexidecimal "hexidecimal" + #define byte_dump_long_octal "octal" + + #define byte_dump_long_first "first" // first offset byte size. + #define byte_dump_long_last "last" // last offset byte size. + #define byte_dump_long_width "width" // number of characters to display per row. + + #define byte_dump_long_text "text" // display text + #define byte_dump_long_placeholder "placeholder" // display (colored) placeholders to signify codes that are UTF-8 fragments. + + enum { + byte_dump_parameter_help, + byte_dump_parameter_light, + byte_dump_parameter_dark, + byte_dump_parameter_no_color, + byte_dump_parameter_version, + + byte_dump_parameter_binary, + byte_dump_parameter_decimal, + byte_dump_parameter_hexidecimal, + byte_dump_parameter_octal, + + byte_dump_parameter_first, + byte_dump_parameter_last, + byte_dump_parameter_width, + + byte_dump_parameter_text, + byte_dump_parameter_placeholder, + }; + + #define byte_dump_console_parameter_initialize \ + { \ + f_console_parameter_initialize(f_console_standard_short_help, f_console_standard_long_help, 0, 0, f_console_type_normal), \ + f_console_parameter_initialize(f_console_standard_short_light, f_console_standard_long_light, 0, 0, f_console_type_inverse), \ + f_console_parameter_initialize(f_console_standard_short_dark, f_console_standard_long_dark, 0, 0, f_console_type_inverse), \ + f_console_parameter_initialize(f_console_standard_short_no_color, f_console_standard_long_no_color, 0, 0, f_console_type_inverse), \ + f_console_parameter_initialize(f_console_standard_short_version, f_console_standard_long_version, 0, 0, f_console_type_inverse), \ + f_console_parameter_initialize(byte_dump_short_binary, byte_dump_long_binary, 0, 0, f_console_type_normal), \ + f_console_parameter_initialize(byte_dump_short_decimal, byte_dump_long_decimal, 0, 0, f_console_type_normal), \ + f_console_parameter_initialize(byte_dump_short_hexdecimal, byte_dump_long_hexidecimal, 0, 0, f_console_type_normal), \ + f_console_parameter_initialize(byte_dump_short_octal, byte_dump_long_octal, 0, 0, f_console_type_normal), \ + f_console_parameter_initialize(byte_dump_short_first, byte_dump_long_first, 0, 1, f_console_type_normal), \ + f_console_parameter_initialize(byte_dump_short_last, byte_dump_long_last, 0, 1, f_console_type_normal), \ + f_console_parameter_initialize(byte_dump_short_width, byte_dump_long_width, 0, 1, f_console_type_normal), \ + f_console_parameter_initialize(byte_dump_short_text, byte_dump_long_text, 0, 0, f_console_type_normal), \ + f_console_parameter_initialize(byte_dump_short_placeholder, byte_dump_long_placeholder, 0, 0, f_console_type_normal), \ + } + + #define byte_dump_total_parameters 14 +#endif // _di_byte_dump_defines_ + +#ifndef _di_byte_dump_data_ + typedef struct { + f_console_parameter parameters[byte_dump_total_parameters]; + + f_string_lengths remaining; + f_bool process_pipe; + + uint64_t first; + uint64_t last; + uint8_t width; + uint8_t mode; + + fl_color_context context; + } byte_dump_data; + + #define byte_dump_data_initialize \ + { \ + byte_dump_console_parameter_initialize, \ + f_string_lengths_initialize, \ + f_false, \ + 0, \ + 0, \ + 8, \ + byte_dump_mode_hexidecimal, \ + fl_color_context_initialize, \ + } +#endif // _di_byte_dump_data_ + +/** + * Print help to standard output. + * + * @param data + * The program data. + * + * @return + * f_none on success. + */ +#ifndef _di_byte_dump_print_help_ + extern f_return_status byte_dump_print_help(const byte_dump_data data); +#endif // _di_byte_dump_print_help_ + +/** + * Execute main program. + * + * Be sure to call byte_dump_delete_data() after executing this. + * + * @param arguments + * The parameters passed to the process. + * @param data + * The program data. + * + * @return + * f_none on success. + * Status codes (with error bit) are returned on any problem. + * + * @see byte_dump_delete_data() + */ +#ifndef _di_byte_dump_main_ + extern f_return_status byte_dump_main(const f_console_arguments arguments, byte_dump_data *data); +#endif // _di_byte_dump_main_ + +/** + * Deallocate data. + * + * Be sure to call this after executing byte_dump_main(). + * + * @param data + * The 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_delete_data_ + extern f_return_status byte_dump_delete_data(byte_dump_data *data); +#endif // _di_byte_dump_delete_data_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _byte_dump_h diff --git a/level_3/bit_dump/c/main.c b/level_3/byte_dump/c/main.c similarity index 63% rename from level_3/bit_dump/c/main.c rename to level_3/byte_dump/c/main.c index b20d152..7818477 100644 --- a/level_3/bit_dump/c/main.c +++ b/level_3/byte_dump/c/main.c @@ -1,14 +1,14 @@ -#include +#include int main(const int argc, const f_string *argv) { const f_console_arguments arguments = { argc, argv }; - bit_dump_data data = bit_dump_data_initialize; + byte_dump_data data = byte_dump_data_initialize; if (f_pipe_exists()) { data.process_pipe = f_true; } - f_status status = bit_dump_main(arguments, &data); + f_status status = byte_dump_main(arguments, &data); if (f_status_is_error(status)) { return 1; diff --git a/level_3/bit_dump/c/private-bit_dump.c b/level_3/byte_dump/c/private-byte_dump.c similarity index 78% rename from level_3/bit_dump/c/private-bit_dump.c rename to level_3/byte_dump/c/private-byte_dump.c index 26d3b42..27bb179 100644 --- a/level_3/bit_dump/c/private-bit_dump.c +++ b/level_3/byte_dump/c/private-byte_dump.c @@ -1,11 +1,11 @@ /** * Private source file for firewall.c. */ -#include -#include "private-bit_dump.h" +#include +#include "private-byte_dump.h" -#ifndef _di_bit_dump_file_ - f_return_status bit_dump_file(const bit_dump_data data, const f_string file_name, f_file file) { +#ifndef _di_byte_dump_file_ + f_return_status byte_dump_file(const byte_dump_data data, const f_string file_name, f_file file) { f_status status = f_none; uint64_t position = data.first; @@ -142,22 +142,22 @@ invalid[character_current] = width_utf; } - if (bit_dump_print_character_fragment(data, characters, invalid, width_utf, 1, &previous_bytes, &previous_invalid, &column, &row)) { + if (byte_dump_print_character_fragment(data, characters, invalid, width_utf, 1, &previous_bytes, &previous_invalid, &column, &row)) { character_reset = f_true; } if (width_utf > 1) { - if (bit_dump_print_character_fragment(data, characters, invalid, width_utf, 2, &previous_bytes, &previous_invalid, &column, &row) == f_true) { + if (byte_dump_print_character_fragment(data, characters, invalid, width_utf, 2, &previous_bytes, &previous_invalid, &column, &row) == f_true) { character_reset = f_true; } if (width_utf > 2) { - if (bit_dump_print_character_fragment(data, characters, invalid, width_utf, 3, &previous_bytes, &previous_invalid, &column, &row)) { + if (byte_dump_print_character_fragment(data, characters, invalid, width_utf, 3, &previous_bytes, &previous_invalid, &column, &row)) { character_reset = f_true; } if (width_utf > 3) { - if (bit_dump_print_character_fragment(data, characters, invalid, width_utf, 4, &previous_bytes, &previous_invalid, &column, &row)) { + if (byte_dump_print_character_fragment(data, characters, invalid, width_utf, 4, &previous_bytes, &previous_invalid, &column, &row)) { character_reset = f_true; } } @@ -176,39 +176,39 @@ previous_invalid = 0; while (column < data.width) { - if (data.mode == bit_dump_mode_hexidecimal) { + if (data.mode == byte_dump_mode_hexidecimal) { printf(" "); } - else if (data.mode == bit_dump_mode_octal) { + else if (data.mode == byte_dump_mode_octal) { printf(" "); } - else if (data.mode == bit_dump_mode_binary) { + else if (data.mode == byte_dump_mode_binary) { printf(" "); } - else if (data.mode == bit_dump_mode_decimal) { + else if (data.mode == byte_dump_mode_decimal) { printf(" "); } column++; if (column < data.width) { - if (data.mode == bit_dump_mode_hexidecimal && column % 8 == 0) { + if (data.mode == byte_dump_mode_hexidecimal && column % 8 == 0) { printf(" "); } - else if (data.mode == bit_dump_mode_octal && column % 6 == 0) { + else if (data.mode == byte_dump_mode_octal && column % 6 == 0) { printf(" "); } - else if (data.mode == bit_dump_mode_binary && column % 4 == 0) { + else if (data.mode == byte_dump_mode_binary && column % 4 == 0) { printf(" "); } - else if (data.mode == bit_dump_mode_decimal && column % 6 == 0) { + else if (data.mode == byte_dump_mode_decimal && column % 6 == 0) { printf(" "); } } } // while - if (data.parameters[bit_dump_parameter_text].result == f_console_result_found) { - bit_dump_print_text(data, characters, invalid, &previous_bytes, &previous_invalid); + if (data.parameters[byte_dump_parameter_text].result == f_console_result_found) { + byte_dump_print_text(data, characters, invalid, &previous_bytes, &previous_invalid); } else { printf("%c", f_string_eol); @@ -240,10 +240,10 @@ return status; } -#endif // _di_bit_dump_file_ +#endif // _di_byte_dump_file_ -#ifndef _di_bit_dump_print_character_fragment_ - f_bool bit_dump_print_character_fragment(const bit_dump_data data, const f_utf_string_dynamic characters, const uint8_t invalid[], const int8_t width_utf, const int8_t byte_current, uint8_t *previous_bytes, uint8_t *previous_invalid, uint8_t *column, uint64_t *row) { +#ifndef _di_byte_dump_print_character_fragment_ + f_bool byte_dump_print_character_fragment(const byte_dump_data data, const f_utf_string_dynamic characters, const uint8_t invalid[], const int8_t width_utf, const int8_t byte_current, uint8_t *previous_bytes, uint8_t *previous_invalid, uint8_t *column, uint64_t *row) { uint8_t byte = 0; f_bool reset = f_false; @@ -267,7 +267,7 @@ fl_color_print(f_standard_output, data.context.notable, data.context.reset, "%016X ", (uint64_t) *row); } - if (data.mode == bit_dump_mode_hexidecimal) { + if (data.mode == byte_dump_mode_hexidecimal) { if (invalid[character_current]) { fl_color_print(f_standard_output, data.context.error, data.context.reset, " %02x", (uint8_t) byte); } @@ -275,7 +275,7 @@ printf(" %02x", (uint8_t) byte); } } - else if (data.mode == bit_dump_mode_octal) { + else if (data.mode == byte_dump_mode_octal) { if (invalid[character_current]) { fl_color_print(f_standard_output, data.context.error, data.context.reset, " %03o", (uint8_t) byte); } @@ -283,7 +283,7 @@ printf(" %03o", (uint8_t) byte); } } - else if (data.mode == bit_dump_mode_binary) { + else if (data.mode == byte_dump_mode_binary) { char binary_string[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; binary_string[0] = ((byte >> 7) & 0x01) ? '1' : '0'; @@ -302,7 +302,7 @@ printf(" %s", binary_string); } } - else if (data.mode == bit_dump_mode_decimal) { + else if (data.mode == byte_dump_mode_decimal) { if (invalid[character_current]) { fl_color_print(f_standard_output, data.context.error, data.context.reset, " %3d", (uint8_t) byte); } @@ -322,8 +322,8 @@ reset = f_true; - if (data.parameters[bit_dump_parameter_text].result == f_console_result_found) { - bit_dump_print_text(data, characters, invalid, previous_bytes, previous_invalid); + if (data.parameters[byte_dump_parameter_text].result == f_console_result_found) { + byte_dump_print_text(data, characters, invalid, previous_bytes, previous_invalid); } else { printf("%c", f_string_eol); @@ -341,30 +341,30 @@ *previous_invalid = invalid[character_current]; } } - else if (data.mode == bit_dump_mode_hexidecimal && *column % 8 == 0) { + else if (data.mode == byte_dump_mode_hexidecimal && *column % 8 == 0) { printf(" "); } - else if (data.mode == bit_dump_mode_octal && *column % 6 == 0) { + else if (data.mode == byte_dump_mode_octal && *column % 6 == 0) { printf(" "); } - else if (data.mode == bit_dump_mode_binary && *column % 4 == 0) { + else if (data.mode == byte_dump_mode_binary && *column % 4 == 0) { printf(" "); } - else if (data.mode == bit_dump_mode_decimal && *column % 6 == 0) { + else if (data.mode == byte_dump_mode_decimal && *column % 6 == 0) { printf(" "); } return reset; } -#endif // _di_bit_dump_print_character_fragment_ +#endif // _di_byte_dump_print_character_fragment_ -#ifndef _di_bit_dump_print_text_ - void bit_dump_print_text(const bit_dump_data data, const f_utf_string_dynamic characters, const uint8_t invalid[], uint8_t *previous_bytes, uint8_t *previous_invalid) { +#ifndef _di_byte_dump_print_text_ + void byte_dump_print_text(const byte_dump_data data, const f_utf_string_dynamic characters, const uint8_t invalid[], uint8_t *previous_bytes, uint8_t *previous_invalid) { uint8_t j = 0; uint8_t output = 0; uint8_t width_utf = 0; - fl_color_print(f_standard_output, data.context.notable, data.context.reset, " %s ", bit_dump_character_wall); + fl_color_print(f_standard_output, data.context.notable, data.context.reset, " %s ", byte_dump_character_wall); // Print placeholders for the remaining fragments of UTF-8 characters printed on previous lines. { @@ -375,13 +375,13 @@ } if (*previous_bytes > 0) { - if (data.parameters[bit_dump_parameter_placeholder].result == f_console_result_found) { + if (data.parameters[byte_dump_parameter_placeholder].result == f_console_result_found) { for (; j < *previous_bytes && j < data.width; j++) { if (*previous_invalid) { - fl_color_print(f_standard_output, data.context.error, data.context.reset, "%s", bit_dump_character_placeholder); + fl_color_print(f_standard_output, data.context.error, data.context.reset, "%s", byte_dump_character_placeholder); } else { - fl_color_print(f_standard_output, data.context.warning, data.context.reset, "%s", bit_dump_character_placeholder); + fl_color_print(f_standard_output, data.context.warning, data.context.reset, "%s", byte_dump_character_placeholder); } } // for } @@ -406,116 +406,116 @@ width_utf = f_macro_utf_byte_width_is(output); if (invalid[i]) { - fl_color_print(f_standard_output, data.context.error, data.context.reset, "%s", bit_dump_character_incomplete); + fl_color_print(f_standard_output, data.context.error, data.context.reset, "%s", byte_dump_character_incomplete); } else if (output == 0) { - printf("%s", bit_dump_sequence_null); + printf("%s", byte_dump_sequence_null); } else if (output == 1) { - printf("%s", bit_dump_sequence_start_of_header); + printf("%s", byte_dump_sequence_start_of_header); } else if (output == 2) { - printf("%s", bit_dump_sequence_start_of_text); + printf("%s", byte_dump_sequence_start_of_text); } else if (output == 3) { - printf("%s", bit_dump_sequence_end_of_text); + printf("%s", byte_dump_sequence_end_of_text); } else if (output == 4) { - printf("%s", bit_dump_sequence_end_of_transmission); + printf("%s", byte_dump_sequence_end_of_transmission); } else if (output == 5) { - printf("%s", bit_dump_sequence_end_of_enquiry); + printf("%s", byte_dump_sequence_end_of_enquiry); } else if (output == 6) { - printf("%s", bit_dump_sequence_acknowledge); + printf("%s", byte_dump_sequence_acknowledge); } else if (output == 7) { - printf("%s", bit_dump_sequence_bell); + printf("%s", byte_dump_sequence_bell); } else if (output == 8) { - printf("%s", bit_dump_sequence_backspace); + printf("%s", byte_dump_sequence_backspace); } else if (output == 9) { - printf("%s", bit_dump_sequence_tab); + printf("%s", byte_dump_sequence_tab); } else if (output == 10) { - printf("%s", bit_dump_sequence_new_line); + printf("%s", byte_dump_sequence_new_line); } else if (output == 11) { - printf("%s", bit_dump_sequence_tab_vertical); + printf("%s", byte_dump_sequence_tab_vertical); } else if (output == 12) { - printf("%s", bit_dump_sequence_form_feed); + printf("%s", byte_dump_sequence_form_feed); } else if (output == 13) { - printf("%s", bit_dump_sequence_carriage_return); + printf("%s", byte_dump_sequence_carriage_return); } else if (output == 14) { - printf("%s", bit_dump_sequence_shift_out); + printf("%s", byte_dump_sequence_shift_out); } else if (output == 15) { - printf("%s", bit_dump_sequence_shift_in); + printf("%s", byte_dump_sequence_shift_in); } else if (output == 16) { - printf("%s", bit_dump_sequence_data_link_escape); + printf("%s", byte_dump_sequence_data_link_escape); } else if (output == 17) { - printf("%s", bit_dump_sequence_device_control_1); + printf("%s", byte_dump_sequence_device_control_1); } else if (output == 18) { - printf("%s", bit_dump_sequence_device_control_2); + printf("%s", byte_dump_sequence_device_control_2); } else if (output == 19) { - printf("%s", bit_dump_sequence_device_control_3); + printf("%s", byte_dump_sequence_device_control_3); } else if (output == 20) { - printf("%s", bit_dump_sequence_device_control_4); + printf("%s", byte_dump_sequence_device_control_4); } else if (output == 21) { - printf("%s", bit_dump_sequence_negative_acknowledge); + printf("%s", byte_dump_sequence_negative_acknowledge); } else if (output == 22) { - printf("%s", bit_dump_sequence_synchronous_idle); + printf("%s", byte_dump_sequence_synchronous_idle); } else if (output == 23) { - printf("%s", bit_dump_sequence_end_of_transmission_block); + printf("%s", byte_dump_sequence_end_of_transmission_block); } else if (output == 24) { - printf("%s", bit_dump_sequence_cancel); + printf("%s", byte_dump_sequence_cancel); } else if (output == 25) { - printf("%s", bit_dump_sequence_end_of_medium); + printf("%s", byte_dump_sequence_end_of_medium); } else if (output == 26) { - printf("%s", bit_dump_sequence_substitute); + printf("%s", byte_dump_sequence_substitute); } else if (output == 27) { - printf("%s", bit_dump_sequence_escape); + printf("%s", byte_dump_sequence_escape); } else if (output == 28) { - printf("%s", bit_dump_sequence_file_separator); + printf("%s", byte_dump_sequence_file_separator); } else if (output == 29) { - printf("%s", bit_dump_sequence_group_separator); + printf("%s", byte_dump_sequence_group_separator); } else if (output == 30) { - printf("%s", bit_dump_sequence_record_separator); + printf("%s", byte_dump_sequence_record_separator); } else if (output == 31) { - printf("%s", bit_dump_sequence_unit_separator); + printf("%s", byte_dump_sequence_unit_separator); } else if (output == 32) { - printf("%s", bit_dump_sequence_space); + printf("%s", byte_dump_sequence_space); } else if (output == 127) { - printf("%s", bit_dump_sequence_delete); + printf("%s", byte_dump_sequence_delete); } else if (f_utf_is_whitespace_character(characters.string[i]) == f_true) { - printf("%s", bit_dump_sequence_space); + printf("%s", byte_dump_sequence_space); } else if (width_utf == 2 && characters.string[i] == 0xc0800000) { // This is an "Overlong Null" and is a valid NULL character. - printf("%s", bit_dump_sequence_null); + printf("%s", byte_dump_sequence_null); } else if (width_utf == 2 && characters.string[i] >= 0xcc800000 && characters.string[i] <= 0xcdaf0000) { // Combining characters should not be combined here, instead display a space. @@ -580,15 +580,15 @@ printf(" "); } else if (characters.string[i] == f_utf_character_mask_bom) { - fl_color_print(f_standard_output, data.context.warning, data.context.reset, "%s", bit_dump_sequence_utf_bom); + fl_color_print(f_standard_output, data.context.warning, data.context.reset, "%s", byte_dump_sequence_utf_bom); } else if (width_utf == 1) { // print invalid placeholder for invalid UTF-8 widths. if (invalid[i]) { - fl_color_print(f_standard_output, data.context.error, data.context.reset, "%s", bit_dump_character_incomplete); + fl_color_print(f_standard_output, data.context.error, data.context.reset, "%s", byte_dump_character_incomplete); } else { - fl_color_print(f_standard_output, data.context.warning, data.context.reset, "%s", bit_dump_character_incomplete); + fl_color_print(f_standard_output, data.context.warning, data.context.reset, "%s", byte_dump_character_incomplete); } } else if (width_utf > 0) { @@ -615,12 +615,12 @@ // When using UTF-8 characters, the character columns will not line up, so print placeholders to simulate the bytes that are not printed, if necessary for alignment. if (width_utf > 1 && j + 1 < data.width) { - if (data.parameters[bit_dump_parameter_placeholder].result == f_console_result_found) { + if (data.parameters[byte_dump_parameter_placeholder].result == f_console_result_found) { if (invalid[i]) { - fl_color_print(f_standard_output, data.context.error, data.context.reset, "%s", bit_dump_character_placeholder); + fl_color_print(f_standard_output, data.context.error, data.context.reset, "%s", byte_dump_character_placeholder); } else { - fl_color_print(f_standard_output, data.context.warning, data.context.reset, "%s", bit_dump_character_placeholder); + fl_color_print(f_standard_output, data.context.warning, data.context.reset, "%s", byte_dump_character_placeholder); } } else { @@ -630,12 +630,12 @@ j++; if (width_utf > 2 && j + 1 < data.width) { - if (data.parameters[bit_dump_parameter_placeholder].result == f_console_result_found) { + if (data.parameters[byte_dump_parameter_placeholder].result == f_console_result_found) { if (invalid[i]) { - fl_color_print(f_standard_output, data.context.error, data.context.reset, "%s", bit_dump_character_placeholder); + fl_color_print(f_standard_output, data.context.error, data.context.reset, "%s", byte_dump_character_placeholder); } else { - fl_color_print(f_standard_output, data.context.warning, data.context.reset, "%s", bit_dump_character_placeholder); + fl_color_print(f_standard_output, data.context.warning, data.context.reset, "%s", byte_dump_character_placeholder); } } else { @@ -645,12 +645,12 @@ j++; if (width_utf > 3 && j + 1 < data.width) { - if (data.parameters[bit_dump_parameter_placeholder].result == f_console_result_found) { + if (data.parameters[byte_dump_parameter_placeholder].result == f_console_result_found) { if (invalid[i]) { - fl_color_print(f_standard_output, data.context.error, data.context.reset, "%s", bit_dump_character_placeholder); + fl_color_print(f_standard_output, data.context.error, data.context.reset, "%s", byte_dump_character_placeholder); } else { - fl_color_print(f_standard_output, data.context.warning, data.context.reset, "%s", bit_dump_character_placeholder); + fl_color_print(f_standard_output, data.context.warning, data.context.reset, "%s", byte_dump_character_placeholder); } } else { @@ -664,13 +664,13 @@ } // for // Print placeholder for the remaining parts of the line. - if (data.parameters[bit_dump_parameter_placeholder].result == f_console_result_found) { + if (data.parameters[byte_dump_parameter_placeholder].result == f_console_result_found) { for (; j < data.width; j++) { if (invalid[j]) { - fl_color_print(f_standard_output, data.context.error, data.context.reset, "%s", bit_dump_character_placeholder); + fl_color_print(f_standard_output, data.context.error, data.context.reset, "%s", byte_dump_character_placeholder); } else { - fl_color_print(f_standard_output, data.context.warning, data.context.reset, "%s", bit_dump_character_placeholder); + fl_color_print(f_standard_output, data.context.warning, data.context.reset, "%s", byte_dump_character_placeholder); } } // for } @@ -683,10 +683,10 @@ fl_color_print(f_standard_output, data.context.notable, data.context.reset, " |"); printf("%c", f_string_eol); } -#endif // _di_bit_dump_file_ +#endif // _di_byte_dump_file_ -#ifndef _di_bit_dump_print_file_error_ - void bit_dump_print_file_error(const fl_color_context context, const f_status status, const f_string function, const f_string file_name) { +#ifndef _di_byte_dump_print_file_error_ + void byte_dump_print_file_error(const fl_color_context context, const f_status status, const f_string function, const f_string file_name) { f_status error = f_status_set_fine(status); if (error == f_false) { @@ -753,4 +753,4 @@ fl_color_print(f_standard_error, context.notable, context.reset, "%s", file_name); fl_color_print_line(f_standard_error, context.error, context.reset, "'."); } -#endif // _di_bit_dump_print_file_error_ +#endif // _di_byte_dump_print_file_error_ diff --git a/level_3/bit_dump/c/private-bit_dump.h b/level_3/byte_dump/c/private-byte_dump.h similarity index 69% rename from level_3/bit_dump/c/private-bit_dump.h rename to level_3/byte_dump/c/private-byte_dump.h index ceb8119..180fa57 100644 --- a/level_3/bit_dump/c/private-bit_dump.h +++ b/level_3/byte_dump/c/private-byte_dump.h @@ -1,12 +1,12 @@ /** * FLL - Level 3 * - * Project: Bit Dump + * Project: Byte Dump * API Version: 0.5 * Licenses: lgplv2.1 */ -#ifndef _PRIVATE_bit_dump_h -#define _PRIVATE_bit_dump_h +#ifndef _PRIVATE_byte_dump_h +#define _PRIVATE_byte_dump_h #ifdef __cplusplus extern "C" { @@ -30,9 +30,9 @@ extern "C" { * f_none on success. * f_failure (with error bit) on failure, usually when read() fails. */ -#ifndef _di_bit_dump_file_ - extern f_return_status bit_dump_file(const bit_dump_data data, const f_string file_name, f_file file); -#endif // _di_bit_dump_file_ +#ifndef _di_byte_dump_file_ + extern f_return_status byte_dump_file(const byte_dump_data data, const f_string file_name, f_file file); +#endif // _di_byte_dump_file_ /** * Print a single character hex code and if the width is reached properly terminate the line. @@ -59,16 +59,16 @@ extern "C" { * @param column * The current column that the character is being printed on. * This value is incremented to represent that the character is printed. - * When the max width is reached bit_dump_print_text() is called and this value is reset. + * When the max width is reached byte_dump_print_text() is called and this value is reset. * @param row * The current row that the character is being printed on. - * When the max width is reached bit_dump_print_text() is called and this value is incremented. + * When the max width is reached byte_dump_print_text() is called and this value is incremented. * - * @see bit_dump_print_text() + * @see byte_dump_print_text() */ -#ifndef _di_bit_dump_print_character_fragment_ - extern f_bool bit_dump_print_character_fragment(const bit_dump_data data, const f_utf_string_dynamic characters, const uint8_t invalid[], const int8_t width_utf, const int8_t byte_current, uint8_t *previous_bytes, uint8_t *previous_invalid, uint8_t *column, uint64_t *row); -#endif // _di_bit_dump_print_character_fragment_ +#ifndef _di_byte_dump_print_character_fragment_ + extern f_bool byte_dump_print_character_fragment(const byte_dump_data data, const f_utf_string_dynamic characters, const uint8_t invalid[], const int8_t width_utf, const int8_t byte_current, uint8_t *previous_bytes, uint8_t *previous_invalid, uint8_t *column, uint64_t *row); +#endif // _di_byte_dump_print_character_fragment_ /** @@ -90,9 +90,9 @@ extern "C" { * The specific invalid value provided representing the overflowed bytes. * This is used to print the placeholders. */ -#ifndef _di_bit_dump_print_text_ - extern void bit_dump_print_text(const bit_dump_data data, const f_utf_string_dynamic characters, const uint8_t invalid[], uint8_t *previous_bytes, uint8_t *previous_invalid); -#endif // _di_bit_dump_print_text_ +#ifndef _di_byte_dump_print_text_ + extern void byte_dump_print_text(const byte_dump_data data, const f_utf_string_dynamic characters, const uint8_t invalid[], uint8_t *previous_bytes, uint8_t *previous_invalid); +#endif // _di_byte_dump_print_text_ /** * Print error messages related to a file. @@ -110,8 +110,8 @@ extern "C" { * f_true if error has been printed. * f_false if error has not been printed. */ -#ifndef _di_bit_dump_print_file_error_ - extern void bit_dump_print_file_error(const fl_color_context context, const f_status status, const f_string function, const f_string file_name); -#endif // _di_bit_dump_print_file_error_ +#ifndef _di_byte_dump_print_file_error_ + extern void byte_dump_print_file_error(const fl_color_context context, const f_status status, const f_string function, const f_string file_name); +#endif // _di_byte_dump_print_file_error_ -#endif // _PRIVATE_bit_dump_h +#endif // _PRIVATE_byte_dump_h diff --git a/level_3/bit_dump/data/build/dependencies b/level_3/byte_dump/data/build/dependencies similarity index 100% rename from level_3/bit_dump/data/build/dependencies rename to level_3/byte_dump/data/build/dependencies diff --git a/level_3/bit_dump/data/build/settings b/level_3/byte_dump/data/build/settings similarity index 80% rename from level_3/bit_dump/data/build/settings rename to level_3/byte_dump/data/build/settings index 20f93fc..0521c90 100644 --- a/level_3/bit_dump/data/build/settings +++ b/level_3/byte_dump/data/build/settings @@ -1,6 +1,6 @@ # fss-0000 -project_name bit_dump +project_name byte_dump project_level 3 version_major 0 @@ -13,9 +13,9 @@ build_libraries -lc build_libraries_fll -lfll_program -lfl_utf -lfl_string -lfl_file -lfl_console -lfl_color -lf_utf -lf_print -lf_pipe -lf_file -lf_conversion -lf_console -lf_memory #build_libraries_fll-level -lfll_2 -lfll_1 -lfll_0 #build_libraries_fll-monolithic -lfll -build_sources_library bit_dump.c private-bit_dump.c +build_sources_library byte_dump.c private-byte_dump.c build_sources_program main.c -build_sources_headers bit_dump.h +build_sources_headers byte_dump.h build_sources_bash build_sources_settings build_shared yes @@ -29,4 +29,4 @@ flags_all -z now -g flags_shared flags_static flags_library -fPIC -flags_program -fPIE -lbit_dump +flags_program -fPIE -lbyte_dump