From b188bba65b86de73af19788c3e058eaae038e1d6 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 22 Aug 2021 22:41:24 -0500 Subject: [PATCH] Progress: Continue string and convert changes, fixing bugs. Convert firewall and the fss read programs. Update byte_dump, contoller, and fake. Add -O2 optimization by default. --- level_3/byte_dump/c/byte_dump.c | 33 +- level_3/controller/c/controller.c | 8 +- level_3/fake/c/fake.c | 30 +- level_3/firewall/c/firewall.c | 123 +++--- level_3/firewall/c/firewall.h | 7 +- level_3/firewall/c/private-common.c | 70 ++++ level_3/firewall/c/private-common.h | 80 ++++ level_3/firewall/c/private-firewall.c | 450 ++++++++------------- level_3/firewall/c/private-firewall.h | 14 +- level_3/firewall/data/build/dependencies | 2 + level_3/firewall/data/build/settings | 4 +- .../fss_basic_list_read/c/fss_basic_list_read.c | 265 +++++------- .../fss_basic_list_read/c/fss_basic_list_read.h | 3 + .../c/private-fss_basic_list_read.c | 128 ++++-- .../fss_basic_list_read/data/build/dependencies | 1 + level_3/fss_basic_list_read/data/build/settings | 4 +- level_3/fss_basic_read/c/fss_basic_read.c | 265 +++++------- level_3/fss_basic_read/c/fss_basic_read.h | 3 + level_3/fss_basic_read/c/private-fss_basic_read.c | 66 +-- level_3/fss_basic_read/data/build/dependencies | 1 + level_3/fss_basic_read/data/build/settings | 4 +- .../c/fss_embedded_list_read.c | 317 +++++++-------- .../c/fss_embedded_list_read.h | 3 + .../c/private-fss_embedded_list_read.c | 93 +++-- .../fss_embedded_list_read/data/build/dependencies | 1 + level_3/fss_embedded_list_read/data/build/settings | 4 +- .../c/fss_extended_list_read.c | 265 +++++------- .../c/fss_extended_list_read.h | 3 + .../c/private-fss_extended_list_read.c | 82 ++-- .../fss_extended_list_read/data/build/dependencies | 1 + level_3/fss_extended_list_read/data/build/settings | 4 +- level_3/fss_extended_read/c/fss_extended_read.c | 265 +++++------- level_3/fss_extended_read/c/fss_extended_read.h | 3 + .../c/private-fss_extended_read.c | 71 ++-- level_3/fss_extended_read/data/build/dependencies | 3 +- level_3/fss_extended_read/data/build/settings | 4 +- 36 files changed, 1318 insertions(+), 1362 deletions(-) diff --git a/level_3/byte_dump/c/byte_dump.c b/level_3/byte_dump/c/byte_dump.c index 52d1c65..fc7f7b9 100644 --- a/level_3/byte_dump/c/byte_dump.c +++ b/level_3/byte_dump/c/byte_dump.c @@ -54,38 +54,15 @@ extern "C" { fll_program_print_help_usage(output, context, byte_dump_name, "filename(s)"); - f_print_terminated(" When using the ", output.stream); - fl_print_format("%[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_text, context.set.notable); - f_print_terminated(" option, some UTF-8 characters may be replaced by your instance and cause display alignment issues.", output.stream); + fl_print_format(" When using the %[%s%s%] option, some UTF-8 characters may be replaced by your instance and cause display alignment issues.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_text, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - f_print_character(f_string_eol_s[0], output.stream); - f_print_character(f_string_eol_s[0], output.stream); - - f_print_terminated(" Special UTF-8 characters and non-spacing UTF-8 characters may be replaced with a space (or a placeholder when the ", output.stream); - fl_print_format("%[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_placeholder, context.set.notable); - f_print_terminated(" option is used).", output.stream); - - f_print_character(f_string_eol_s[0], output.stream); - f_print_character(f_string_eol_s[0], output.stream); + fl_print_format(" Special UTF-8 characters and non-spacing UTF-8 characters may be replaced with a space (or a placeholder when the %[%s%s%] option is used).%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_placeholder, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - f_print_terminated(" UTF-8 \"Combining\" characters might have a space appended to allow a proper display but this may cause copy and paste issues.", output.stream); + fl_print_format(" UTF-8 \"Combining\" characters might have a space appended to allow a proper display but this may cause copy and paste issues.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - f_print_character(f_string_eol_s[0], output.stream); - f_print_character(f_string_eol_s[0], output.stream); + fl_print_format(" When %[%s%s%] is used, any UTF-8 sequences will still be printed in full should any part is found within the requested range.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_last, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - f_print_terminated(" When ", output.stream); - fl_print_format("%[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_last, context.set.notable); - f_print_terminated(" is used, any UTF-8 sequences will still be printed in full should any part is found within the requested range.", output.stream); - - f_print_character(f_string_eol_s[0], output.stream); - f_print_character(f_string_eol_s[0], output.stream); - - f_print_terminated(" When using the ", output.stream); - fl_print_format("%[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_unicode, context.set.notable); - f_print_terminated(" option, invalid Unicode will fallback to being displayed using one of the other modes.", output.stream); - - f_print_character(f_string_eol_s[0], output.stream); - f_print_character(f_string_eol_s[0], output.stream); + fl_print_format(" When using the %[%s%s%] option, invalid Unicode will fallback to being displayed using one of the other modes.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_unicode, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); funlockfile(output.stream); diff --git a/level_3/controller/c/controller.c b/level_3/controller/c/controller.c index 08c6503..42a58da 100644 --- a/level_3/controller/c/controller.c +++ b/level_3/controller/c/controller.c @@ -40,12 +40,8 @@ extern "C" { fll_program_print_help_usage(output, context, controller_name, "entry"); - f_print_terminated(" When both the ", output.stream); - fl_print_format("%[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, controller_long_simulate, context.set.notable); - f_print_terminated(" parameter and the ", output.stream); - fl_print_format("%[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, controller_long_validate, context.set.notable); - f_print_terminated(" parameter are specified, then additional information on each would be executed rule is printed but no simulation is performed.", output.stream); - f_print_character(f_string_eol_s[0], output.stream); + fl_print_format(" When both the %[%s%s%] parameter and the", output.stream, context.set.notable, f_console_symbol_long_enable_s, controller_long_simulate, context.set.notable); + fl_print_format(" %[%s%s%] parameter are specified, then additional information on each would be executed rule is printed but no simulation is performed.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, controller_long_validate, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); funlockfile(output.stream); diff --git a/level_3/fake/c/fake.c b/level_3/fake/c/fake.c index 240ba0d..4eb1c1a 100644 --- a/level_3/fake/c/fake.c +++ b/level_3/fake/c/fake.c @@ -61,31 +61,19 @@ extern "C" { fll_program_print_help_usage(output, context, fake_name, "operation"); - f_print_terminated(" When performing the ", output.stream); - fl_print_format("%[%s%]", output.stream, context.set.notable, fake_other_operation_build, context.set.notable); - f_print_terminated(" operation, the ", output.stream); - fl_print_format("%[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fake_long_mode, context.set.notable); - fl_print_format(" parameter specifies a name (limited to alpha-numeric, underscore, and dash) to be used in addition to the global.%c", output.stream, f_string_eol_s[0]); - - f_print_terminated(" For example, when a ", output.stream); - fl_print_format("%[%s%]", output.stream, context.set.notable, fake_make_parameter_variable_mode, context.set.notable); + fl_print_format(" When performing the %[%s%] operation, the", output.stream, context.set.notable, fake_other_operation_build, context.set.notable); + fl_print_format(" %[%s%s%] parameter specifies a name (limited to alpha-numeric, underscore, and dash) to be used in addition to the global.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fake_long_mode, context.set.notable, f_string_eol_s[0]); + + fl_print_format(" For example, when a %[%s%]", output.stream, context.set.notable, fake_make_parameter_variable_mode, context.set.notable); fl_print_format(" of 'fll_monolithic' is specified, build libraries from both 'build_libraries' and 'build_libraries-fll_monolithic' are used (but not 'build_libraries-fll_level').%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - f_print_terminated(" When specifying the ", output.stream); - fl_print_format("%[%s%]", output.stream, context.set.notable, fake_make_parameter_variable_fakefile, context.set.notable); - f_print_terminated(" or the ", output.stream); - fl_print_format("%[%s%]", output.stream, context.set.notable, fake_make_parameter_variable_settings, context.set.notable); + fl_print_format(" When specifying the %[%s%] or the %[%s%]", output.stream, context.set.notable, fake_make_parameter_variable_fakefile, context.set.notable, context.set.notable, fake_make_parameter_variable_settings, context.set.notable); fl_print_format(" parameters, the filenames are relative to the data build directory, unless a path is used.%c", output.stream, f_string_eol_s[0]); - f_print_terminated(" For example, with '", output.stream); - fl_print_format("%[%s%s my_fakefile%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fake_long_fakefile, context.set.notable); - f_print_terminated("' the fakefile at '", output.stream); - fl_print_format("%[./%s%smy_fakefile%]", output.stream, context.set.notable, fake_default_path_data, fake_default_path_build, context.set.notable); - f_print_terminated("' would be used, however with '", output.stream); - fl_print_format("%[%s%s ./my_fakefile%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fake_long_fakefile, context.set.notable); - f_print_terminated("' the fakefile at '", output.stream); - fl_print_format("%[./my_fakefile%]", output.stream, context.set.notable, context.set.notable); - fl_print_format("' would be used.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); + fl_print_format(" For example, with '%[%s%s my_fakefile%]' the fakefile at", output.stream, context.set.notable, f_console_symbol_long_enable_s, fake_long_fakefile, context.set.notable); + fl_print_format(" '%[./%s%smy_fakefile%]' would be used, however with", output.stream, context.set.notable, fake_default_path_data, fake_default_path_build, context.set.notable); + fl_print_format(" '%[%s%s ./my_fakefile%]' the fakefile at", output.stream, context.set.notable, f_console_symbol_long_enable_s, fake_long_fakefile, context.set.notable); + fl_print_format(" '%[./my_fakefile%]' would be used.%c%c", output.stream, context.set.notable, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); funlockfile(output.stream); diff --git a/level_3/firewall/c/firewall.c b/level_3/firewall/c/firewall.c index dddfd40..bdb11f5 100644 --- a/level_3/firewall/c/firewall.c +++ b/level_3/firewall/c/firewall.c @@ -15,6 +15,8 @@ extern "C" { #ifndef _di_firewall_print_help_ f_status_t firewall_print_help(const f_file_t output, const f_color_context_t context) { + flockfile(output.stream); + fll_program_print_help_header(output, context, firewall_name_long, firewall_version); fll_program_print_help_option(output, context, f_console_standard_short_help_s, f_console_standard_long_help_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Print this help message."); @@ -27,31 +29,17 @@ extern "C" { fll_program_print_help_option(output, context, f_console_standard_short_debug_s, f_console_standard_long_debug_s, f_console_symbol_short_disable_s, f_console_symbol_long_disable_s, " Enable debugging, inceasing verbosity beyond normal output."); fll_program_print_help_option(output, context, f_console_standard_short_version_s, f_console_standard_long_version_s, f_console_symbol_short_disable_s, f_console_symbol_long_disable_s, " Print only the version number."); - fprintf(output.stream, "%c%c", f_string_eol_s[0], f_string_eol_s[0]); - f_color_print(output.stream, context.set.important, " Available Commands: "); - - fprintf(output.stream, "%c ", f_string_eol_s[0]); - f_color_print(output.stream, context.set.standout, firewall_command_start); - fprintf(output.stream, " Turn on the firewall"); - - fprintf(output.stream, "%c ", f_string_eol_s[0]); - f_color_print(output.stream, context.set.standout, firewall_command_stop); - fprintf(output.stream, " Turn off the firewall"); - - fprintf(output.stream, "%c ", f_string_eol_s[0]); - f_color_print(output.stream, context.set.standout, firewall_command_restart); - fprintf(output.stream, " Turn off and then turn on the firewall"); - - fprintf(output.stream, "%c ", f_string_eol_s[0]); - f_color_print(output.stream, context.set.standout, firewall_command_lock); - fprintf(output.stream, " Prevent all communication"); - - fprintf(output.stream, "%c ", f_string_eol_s[0]); - f_color_print(output.stream, context.set.standout, firewall_command_show); - fprintf(output.stream, " Show active firewall settings"); + fl_print_format("%c%c %[Available Commands:%] ", output.stream, f_string_eol_s[0], f_string_eol_s[0], context.set.important, context.set.important); + fl_print_format("%c %[%s%] Turn on the firewall.", output.stream, context.set.standout, firewall_command_start, context.set.standout); + fl_print_format("%c %[%s%] Turn off the firewall.", output.stream, context.set.standout, firewall_command_stop, context.set.standout); + fl_print_format("%c %[%s%] Turn off and then turn on the firewall.", output.stream, context.set.standout, firewall_command_restart, context.set.standout); + fl_print_format("%c %[%s%] Prevent all communication.", output.stream, context.set.standout, firewall_command_lock, context.set.standout); + fl_print_format("%c %[%s%] Show active firewall settings.", output.stream, context.set.standout, firewall_command_show, context.set.standout); fll_program_print_help_usage(output, context, firewall_name, "command"); + funlockfile(output.stream); + return F_none; } #endif // _di_firewall_print_help_ @@ -72,9 +60,12 @@ extern "C" { if (main->context.set.error.before) { main->error.context = main->context.set.error; main->error.notable = main->context.set.notable; + + main->warning.context = main->context.set.warning; + main->warning.notable = main->context.set.notable; } else { - f_color_set_t *sets[] = { &main->error.context, &main->error.notable, 0 }; + f_color_set_t *sets[] = { &main->error.context, &main->error.notable, &main->warning.context, &main->warning.notable, 0 }; fll_program_parameter_process_empty(&main->context, sets); } @@ -100,15 +91,19 @@ extern "C" { if (choice == firewall_parameter_verbosity_quiet) { main->error.verbosity = f_console_verbosity_quiet; + main->warning.verbosity = f_console_verbosity_quiet; } else if (choice == firewall_parameter_verbosity_normal) { main->error.verbosity = f_console_verbosity_normal; + main->warning.verbosity = f_console_verbosity_normal; } else if (choice == firewall_parameter_verbosity_verbose) { main->error.verbosity = f_console_verbosity_verbose; + main->warning.verbosity = f_console_verbosity_verbose; } else if (choice == firewall_parameter_verbosity_debug) { main->error.verbosity = f_console_verbosity_debug; + main->warning.verbosity = f_console_verbosity_debug; } } @@ -213,7 +208,14 @@ extern "C" { if (strncmp("nat", arguments.argv[main->remaining.array[counter]], 4) != 0) { if (strncmp("mangle", arguments.argv[main->remaining.array[counter]], 7) != 0) { if (strncmp("ports", arguments.argv[main->remaining.array[counter]], 6) != 0) { - f_color_print(f_type_warning, main->context.set.warning, "%s'%s' is not a valid show option%c", fll_error_print_warning, arguments.argv[main->remaining.array[counter]], f_string_eol_s[0]); + flockfile(main->warning.to.stream); + + fl_print_format("%c%[%S'%]", main->warning.to.stream, f_string_eol_s[0], main->warning.context, main->warning.prefix, main->warning.context); + fl_print_format("%[%S%]", main->warning.to.stream, main->warning.notable, arguments.argv[main->remaining.array[counter]], main->warning.notable); + fl_print_format("%[' is not a valid show option.%]%c", main->warning.to.stream, main->warning.context, main->warning.context, f_string_eol_s[0]); + + funlockfile(main->warning.to.stream); + fflush(main->warning.to.stream); } else { show_ports = F_true; @@ -232,7 +234,7 @@ extern "C" { macro_f_string_dynamics_t_resize(status, parameters, 7); if (F_status_is_error(status)) { - f_color_print(main->error.to.stream, main->context.set.error, "%sUnable to allocate memory.%c", fll_error_print_error, f_string_eol_s[0]); + firewall_print_error_on_allocation_failure(main->error); firewall_delete_local_data(&local); firewall_main_delete(main); @@ -240,9 +242,7 @@ extern "C" { } if (show_nat) { - f_color_print(main->output.stream, main->context.set.standout, "=========================== "); - f_color_print(main->output.stream, main->context.set.title, "NAT"); - f_color_print(main->output.stream, main->context.set.standout, " ============================%c", f_string_eol_s[0]); + fll_print_format("%[===========================%] %[NAT%] %[============================%]%c", main->output.stream, main->context.set.standout, main->context.set.standout, main->context.set.title, main->context.set.title, main->context.set.standout, main->context.set.standout, f_string_eol_s[0]); fflush(main->output.stream); parameters.used = 6; @@ -268,14 +268,12 @@ extern "C" { exit(return_code); } - fprintf(main->output.stream, "\n"); + fll_print_character(f_string_eol_s[0], main->output.stream); fflush(main->output.stream); } if (F_status_is_error_not(status) && show_mangle) { - f_color_print(main->output.stream, main->context.set.standout, "========================== "); - f_color_print(main->output.stream, main->context.set.title, "MANGLE"); - f_color_print(main->output.stream, main->context.set.standout, " ==========================%c", f_string_eol_s[0]); + fll_print_format("%[==========================%] %[MANGLE%] %[==========================%]%c", main->output.stream, main->context.set.standout, main->context.set.standout, main->context.set.title, main->context.set.title, main->context.set.standout, main->context.set.standout, f_string_eol_s[0]); fflush(main->output.stream); parameters.used = 6; @@ -301,14 +299,12 @@ extern "C" { exit(return_code); } - fprintf(main->output.stream, "\n"); + fll_print_character(f_string_eol_s[0], main->output.stream); fflush(main->output.stream); } if (F_status_is_error_not(status) && show_ports) { - f_color_print(main->output.stream, main->context.set.standout, "========================== "); - f_color_print(main->output.stream, main->context.set.title, "FILTER"); - f_color_print(main->output.stream, main->context.set.standout, " ==========================%c", f_string_eol_s[0]); + fll_print_format("%[==========================%] %[FILTER%] %[==========================%]%c", main->output.stream, main->context.set.standout, main->context.set.standout, main->context.set.title, main->context.set.title, main->context.set.standout, main->context.set.standout, f_string_eol_s[0]); fflush(main->output.stream); parameters.used = 4; @@ -330,7 +326,7 @@ extern "C" { exit(return_code); } - fprintf(main->output.stream, "\n"); + fll_print_character(f_string_eol_s[0], main->output.stream); fflush(main->output.stream); } @@ -338,23 +334,10 @@ extern "C" { status = F_status_set_fine(status); if (status == F_memory_not) { - f_color_print(main->error.to.stream, main->context.set.error, "%sUnable to allocate memory.%c", fll_error_print_error, f_string_eol_s[0]); + firewall_print_error_on_allocation_failure(main->error); } else { - f_color_print(main->error.to.stream, main->context.set.error, "%sFailed to perform requested %s operation:%c", fll_error_print_error, firewall_tool_iptables, f_string_eol_s[0]); - fprintf(f_type_error, " "); - - f_array_length_t i = 0; - - f_color_print_code(f_type_error, main->context.error); - - fprintf(f_type_error, "%s ", firewall_tool_iptables); - for (; i < parameters.used; ++i) { - fprintf(f_type_error, "%s ", parameters.array[i].string); - } // for - - f_color_print_code(f_type_error, main->context.reset); - fprintf(f_type_error, "\n"); + firewall_print_error_on_operation(main->error, firewall_tool_iptables, parameters); } status = F_status_set_error(status); @@ -387,14 +370,16 @@ extern "C" { if (F_status_is_error(status)) { status = F_status_set_fine(status); - if (status == F_memory_not) { - f_color_print(main->error.to.stream, main->context.set.error, "%sUnable to allocate memory.%c", fll_error_print_error, f_string_eol_s[0]); - } - else if (status == F_data_not) { - f_color_print(main->error.to.stream, main->context.set.error, "%sCould not find any network devices%c", fll_error_print_error, f_string_eol_s[0]); - } - else if (status == F_failure) { - f_color_print(main->error.to.stream, main->context.set.error, "%sFailed to read the device directory '%s'%c", fll_error_print_error, network_devices, f_string_eol_s[0]); + if (main->error.verbosity != f_console_verbosity_quiet) { + if (status == F_memory_not) { + firewall_print_error_on_allocation_failure(main->error); + } + else if (status == F_data_not) { + fll_print_format("%c%[%sCould not find any network devices.%]%c", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context, f_string_eol_s[0]); + } + else if (status == F_failure) { + fll_print_format("%c%[%sFailed to read the device directory '%s'.%]%c", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, network_devices, main->error.context, f_string_eol_s[0]); + } } firewall_delete_local_data(&local); @@ -407,6 +392,7 @@ extern "C" { f_array_length_t i = 0; for (; i < main->devices.used; ++i) { + if (fl_string_compare((f_string_t) firewall_device_loop, main->devices.array[i].string, firewall_device_loop_length + 1, main->devices.array[i].used) == F_equal_to) { f_string_dynamic_t swap_string = main->devices.array[i]; @@ -477,7 +463,10 @@ extern "C" { return status; } else { - f_color_print(main->error.to.stream, main->context.set.error, "%sFailed to perform lock request because the lock instructions are missing from: %s.%c", fll_error_print_error, network_path firewall_file_other, f_string_eol_s[0]); + + if (main->error.verbosity != f_console_verbosity_quiet) { + fll_print_format("%c%[%sFailed to perform lock request because the lock instructions are missing from: %s.%]%c", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, network_path firewall_file_other, main->error.context, f_string_eol_s[0]); + } firewall_delete_local_data(&local); firewall_main_delete(main); @@ -517,7 +506,9 @@ extern "C" { } } else { - f_color_print(main->error.to.stream, main->context.set.error, "%sFailed to perform stop request because the lock instructions are missing from: %s.", fll_error_print_error, network_path firewall_file_other, f_string_eol_s[0]); + if (main->error.verbosity != f_console_verbosity_quiet) { + fll_print_format("%c%[%sFailed to perform stop request because the lock instructions are missing from: %s.%]%c", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, network_path firewall_file_other, main->error.context, f_string_eol_s[0]); + } firewall_delete_local_data(&local); firewall_main_delete(main); @@ -595,7 +586,8 @@ extern "C" { macro_f_string_dynamic_t_resize(status, file_path, network_path_length + main->devices.array[i].used + firewall_file_suffix_length + 1); if (F_status_is_error(status)) { - f_color_print(main->error.to.stream, main->context.set.error, "%sUnable to allocate memory.%c", fll_error_print_error, f_string_eol_s[0]); + firewall_print_error_on_allocation_failure(main->error); + firewall_delete_local_data(&local); firewall_main_delete(main); return status; @@ -709,7 +701,10 @@ extern "C" { firewall_delete_local_data(&local); } else { - f_color_print(main->error.to.stream, main->context.set.error, "%sYou did not pass a command%c", fll_error_print_error, f_string_eol_s[0]); + if (main->error.verbosity != f_console_verbosity_quiet) { + fll_print_format("%c%[%sYou did not pass a command.%]%c", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context, f_string_eol_s[0]); + } + status = F_status_set_error(F_parameter); } diff --git a/level_3/firewall/c/firewall.h b/level_3/firewall/c/firewall.h index 5bfef04..7a8dae1 100644 --- a/level_3/firewall/c/firewall.h +++ b/level_3/firewall/c/firewall.h @@ -35,6 +35,7 @@ // fll-1 includes #include #include +#include // fll-2 includes #include @@ -42,6 +43,7 @@ #include #include #include +#include #include #ifdef __cplusplus @@ -225,7 +227,6 @@ extern "C" { firewall_parameter_verbosity_normal, firewall_parameter_verbosity_verbose, firewall_parameter_verbosity_debug, - firewall_parameter_version, firewall_parameter_command_start, @@ -261,8 +262,8 @@ extern "C" { f_console_parameter_t_initialize(f_console_standard_short_quiet_s, f_console_standard_long_quiet_s, 0, 0, f_console_type_inverse), \ f_console_parameter_t_initialize(f_console_standard_short_normal_s, f_console_standard_long_normal_s, 0, 0, f_console_type_inverse), \ f_console_parameter_t_initialize(f_console_standard_short_verbose_s, f_console_standard_long_verbose_s, 0, 0, f_console_type_inverse), \ - f_console_parameter_t_initialize(f_console_standard_short_version_s, f_console_standard_long_version_s, 0, 0, f_console_type_inverse), \ f_console_parameter_t_initialize(f_console_standard_short_debug_s, f_console_standard_long_debug_s, 0, 0, f_console_type_inverse), \ + f_console_parameter_t_initialize(f_console_standard_short_version_s, f_console_standard_long_version_s, 0, 0, f_console_type_inverse), \ f_console_parameter_t_initialize(0, 0, firewall_command_start, F_false, f_console_type_other), \ f_console_parameter_t_initialize(0, 0, firewall_command_stop, F_false, f_console_type_other), \ f_console_parameter_t_initialize(0, 0, firewall_command_restart, F_false, f_console_type_other), \ @@ -282,6 +283,7 @@ extern "C" { f_file_t output; fll_error_print_t error; + fll_error_print_t warning; f_string_dynamics_t chains; f_string_dynamics_t devices; @@ -296,6 +298,7 @@ extern "C" { F_false, \ macro_f_file_t_initialize2(f_type_output, f_type_descriptor_output, f_file_flag_write_only), \ fll_error_print_t_initialize, \ + macro_fll_error_print_t_initialize_warning(), \ f_string_dynamics_t_initialize, \ f_string_dynamics_t_initialize, \ f_color_context_t_initialize, \ diff --git a/level_3/firewall/c/private-common.c b/level_3/firewall/c/private-common.c index 5fb28f6..062c6c8 100644 --- a/level_3/firewall/c/private-common.c +++ b/level_3/firewall/c/private-common.c @@ -5,6 +5,76 @@ extern "C" { #endif +void firewall_print_debug_tool(const fll_error_print_t output, const f_string_t tool, const f_string_dynamics_t arguments) { + + if (output.verbosity != f_console_verbosity_debug) return; + + flockfile(output.to.stream); + + fl_print_format("%[%s", output.to.stream, output.context, tool); + + for (f_array_length_t i = 0; i < arguments.used; ++i) { + fl_print_format(" %Q", output.to.stream, arguments.array[i]); + } // for + + fl_print_format("%]%c", output.to.stream, output.context, f_string_eol_s[0]); + + funlockfile(output.to.stream); +} + +void firewall_print_error_on_allocation_failure(const fll_error_print_t output) { + + if (output.verbosity == f_console_verbosity_quiet) return; + + fll_print_format("%c%[%sUnable to allocate memory.%]%c", output.to.stream, f_string_eol_s[0], output.context, output.prefix, output.context, f_string_eol_s[0]); +} + +void firewall_print_error_on_invalid_parameter(const fll_error_print_t output, const f_string_t function) { + + if (output.verbosity == f_console_verbosity_quiet) return; + + fll_print_format("%c%[%sInvalid parameter when calling %S().%]%c", output.to.stream, f_string_eol_s[0], output.context, output.prefix, function, output.context, f_string_eol_s[0]); +} + +void firewall_print_error_on_invalid_parameter_for_file(const fll_error_print_t output, const f_string_t function, const f_string_t filename) { + + if (output.verbosity == f_console_verbosity_quiet) return; + + fll_print_format("%c%[%sInvalid parameter when calling %S() for the file '%S'.%]%c", output.to.stream, f_string_eol_s[0], output.context, output.prefix, function, filename, output.context, f_string_eol_s[0]); +} + +void firewall_print_error_on_operation(const fll_error_print_t output, const f_string_t tool, const f_string_dynamics_t arguments) { + + if (output.verbosity == f_console_verbosity_quiet) return; + + flockfile(output.to.stream); + + fl_print_format("%c%[%sFailed to perform requested %s operation:%]", output.to.stream, f_string_eol_s[0], output.context, output.prefix, tool, output.context); + fl_print_format("%c %[%s", output.to.stream, f_string_eol_s[0], output.context, tool); + + for (f_array_length_t i = 0; i < arguments.used; ++i) { + fl_print_format(" %Q", output.to.stream, arguments.array[i]); + } // for + + fl_print_format("%]%c", output.to.stream, output.context, f_string_eol_s[0]); + + funlockfile(output.to.stream); +} + +void firewall_print_error_on_unhandled(const fll_error_print_t output, const f_string_t function, const f_status_t status) { + + if (output.verbosity == f_console_verbosity_quiet) return; + + fll_print_format("%c%[%sAn unhandled error (%ui) has occurred while calling %S().%]%c", output.to.stream, f_string_eol_s[0], output.context, output.prefix, status, function, output.context, f_string_eol_s[0]); +} + +void firewall_print_error_on_unhandled_for_file(const fll_error_print_t output, const f_string_t function, const f_status_t status, const f_string_t filename) { + + if (output.verbosity == f_console_verbosity_quiet) return; + + fll_print_format("%c%[%sAn unhandled error (%ui) has occurred while calling %S() for the file '%S'.%]%c", output.to.stream, f_string_eol_s[0], output.context, output.prefix, status, function, filename, output.context, f_string_eol_s[0]); +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/firewall/c/private-common.h b/level_3/firewall/c/private-common.h index f402c80..73ebb1e 100644 --- a/level_3/firewall/c/private-common.h +++ b/level_3/firewall/c/private-common.h @@ -99,6 +99,86 @@ typedef struct { \ macro_f_string_dynamic_t_clear(argument); +/** + * Print debug information about tool execution. + * + * @param output + * The output to print to. + * @param tool + * The iptables tool. + * @param arguments + * The arguments passed to the tool. + */ +extern void firewall_print_debug_tool(const fll_error_print_t output, const f_string_t tool, const f_string_dynamics_t arguments) f_attribute_visibility_internal; + +/** + * Print an memory allocation error. + * + * @param output + * The output to print to. + */ +extern void firewall_print_error_on_allocation_failure(const fll_error_print_t output) f_attribute_visibility_internal; + +/** + * Print an invalid parameter error for the given function. + * + * @param output + * The output to print to. + * @param function + * The function that failed. + */ +extern void firewall_print_error_on_invalid_parameter(const fll_error_print_t output, const f_string_t function) f_attribute_visibility_internal; + +/** + * Print an invalid parameter error for the given function. + * + * @param output + * The output to print to. + * @param function + * The function that failed. + * @param filename + * The name of the file. + */ +extern void firewall_print_error_on_invalid_parameter_for_file(const fll_error_print_t output, const f_string_t function, const f_string_t filename) f_attribute_visibility_internal; + +/** + * Print an error about the given operation failed. + * + * @param output + * The output to print to. + * @param tool + * The iptables tool that failed. + * @param arguments + * The arguments passed to the tool. + */ +extern void firewall_print_error_on_operation(const fll_error_print_t output, const f_string_t tool, const f_string_dynamics_t arguments) f_attribute_visibility_internal; + +/** + * Print an unhandled error for the given function. + * + * @param output + * The output to print to. + * @param function + * The function that failed. + * @param status + * The failure status code. + */ +extern void firewall_print_error_on_unhandled(const fll_error_print_t output, const f_string_t function, const f_status_t status) f_attribute_visibility_internal; + +/** + * Print an unhandled error for the given function for some given file. + * + * @param output + * The output to print to. + * @param function + * The function that failed. + * @param status + * The failure status code. + * @param filename + * The name of the file. + */ +extern void firewall_print_error_on_unhandled_for_file(const fll_error_print_t output, const f_string_t function, const f_status_t status, const f_string_t filename) f_attribute_visibility_internal; + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/firewall/c/private-firewall.c b/level_3/firewall/c/private-firewall.c index 56dfa48..3a90c84 100644 --- a/level_3/firewall/c/private-firewall.c +++ b/level_3/firewall/c/private-firewall.c @@ -72,8 +72,9 @@ f_status_t firewall_perform_commands(const firewall_local_data_t local, const fi // process chain rule if (length >= firewall_chain_length && fl_string_compare(local.buffer.string + local.rule_objects.array[i].start, (f_string_t) firewall_chain, length, firewall_chain_length) == F_equal_to) { if (chain == firewall_chain_custom_id) { + // custom chains can only apply to themselves, so silently ignore chain commands specified within a custom chain. - fprintf(f_type_warning, "%sAt line %llu, the chain option is meaningle ss inside of a custom chain.", fll_error_print_warning, i); + fll_print_format("%c%[%sAt line %ul, the chain option is meaningless inside of a custom chain.%]%c", main.warning.to.stream, f_string_eol_s[0], main.warning.context, main.warning.prefix, i, main.warning.context, f_string_eol_s[0]); continue; } @@ -282,36 +283,38 @@ f_status_t firewall_perform_commands(const firewall_local_data_t local, const fi } // process rule rule, if the remaining rule does not match as firewall_rule, then it is an invalid rule. else if (length < firewall_rule_length || fl_string_compare(local.buffer.string + local.rule_objects.array[i].start, (f_string_t) firewall_rule, length, firewall_rule_length) == F_equal_to_not) { - if (length > 0) { - f_color_print_code(f_type_warning, main.context.warning); - fprintf(f_type_warning, "%sAt line %llu, the object '", fll_error_print_warning, i); - f_print(f_type_warning, local.buffer.string + local.rule_objects.array[i].start, length); - fprintf(f_type_warning, "' is invalid"); - f_color_print_code(f_type_warning, main.context.reset); + if (length) { + flockfile(main.warning.to.stream); + + fl_print_format("%c%[%sAt line %ul, the object '%]%[", main.warning.to.stream, f_string_eol_s[0], main.warning.context, main.warning.prefix, i, main.warning.context, main.warning.notable); + f_print(local.buffer.string + local.rule_objects.array[i].start, length, main.warning.to.stream); + fl_print_format("%]%[' is invalid.%]%c", main.warning.to.stream, main.warning.notable, main.warning.context, main.warning.context, f_string_eol_s[0]); + + funlockfile(main.warning.to.stream); } else { - fprintf(f_type_warning, "%sAt line %llu, the object is missing", fll_error_print_warning, i); + fll_print_format("%c%[%sAt line %ul, the object is missing.%]%c", main.warning.to.stream, f_string_eol_s[0], main.warning.context, main.warning.prefix, i, main.warning.context, f_string_eol_s[0]); } - fprintf(f_type_warning, "\n"); continue; } if (invalid) { length = macro_firewall_structure_size(local.rule_objects, i); - if (length > 0) { - f_color_print_code(f_type_warning, main.context.warning); - fprintf(f_type_warning, "%sAt line %llu, the object '", fll_error_print_warning, i); - f_print(f_type_warning, local.buffer.string + local.rule_objects.array[i].start, length); - fprintf(f_type_warning, "' has invalid content '"); - f_print(f_type_warning, local.buffer.string + local.rule_contents.array[i].array[0].start, macro_firewall_structure_size(local.rule_contents.array[i], 0)); - fprintf(f_type_warning, "'"); - f_color_print_code(f_type_warning, main.context.reset); - fprintf(f_type_warning, "\n"); + if (length) { + flockfile(main.warning.to.stream); + + fl_print_format("%c%[%sAt line %ul, the object '%]%[", main.warning.to.stream, f_string_eol_s[0], main.warning.context, main.warning.prefix, i, main.warning.context, main.warning.notable); + f_print(local.buffer.string + local.rule_objects.array[i].start, length, main.warning.to.stream); + fl_print_format("%]%[' has invalid content '%]%[", main.warning.to.stream, main.warning.notable, main.warning.context, main.warning.context, main.warning.notable); + f_print(local.buffer.string + local.rule_contents.array[i].array[0].start, macro_firewall_structure_size(local.rule_contents.array[i], 0), main.warning.to.stream); + fl_print_format("%]%['.%]%c", main.warning.to.stream, main.warning.notable, main.warning.context, main.warning.context, f_string_eol_s[0]); + + funlockfile(main.warning.to.stream); } else { - f_color_print(f_type_warning, main.context.set.warning, "%sAt line %llu, the object has no content%c", fll_error_print_warning, i, f_string_eol_s[0]); + fll_print_format("%c%[%sAt line %ul, the object has no content.%]%c", main.warning.to.stream, f_string_eol_s[0], main.warning.context, main.warning.prefix, i, main.warning.context, f_string_eol_s[0]); } continue; @@ -554,12 +557,13 @@ f_status_t firewall_perform_commands(const firewall_local_data_t local, const fi else { length = macro_firewall_structure_size(local.rule_objects, i); - f_color_print_code(f_type_warning, main.context.warning); - fprintf(f_type_warning, "%sAt line %llu, the object '", fll_error_print_warning, i); - f_print(f_type_warning, local.buffer.string + local.rule_objects.array[i].start, length); - fprintf(f_type_warning, "' has no content"); - f_color_print_code(f_type_warning, main.context.reset); - fprintf(f_type_warning, "\n"); + flockfile(main.warning.to.stream); + + fl_print_format("%c%[%sAt line %ul, the object '%]%[", main.warning.to.stream, f_string_eol_s[0], main.warning.context, main.warning.prefix, i, main.warning.context, main.warning.notable); + f_print(local.buffer.string + local.rule_objects.array[i].start, length, main.warning.to.stream); + fl_print_format("%]%[' has no content.%]%c", main.warning.to.stream, main.warning.notable, main.warning.context, main.warning.context, f_string_eol_s[0]); + + funlockfile(main.warning.to.stream); break; } @@ -589,24 +593,34 @@ f_status_t firewall_perform_commands(const firewall_local_data_t local, const fi status = F_status_set_fine(status); if (status == F_parameter) { - f_color_print(main.error.to.stream, main.context.set.error, "%sInvalid parameter when calling f_file_open()%c", fll_error_print_error, f_string_eol_s[0]); + if (main.error.verbosity != f_console_verbosity_quiet) { + firewall_print_error_on_invalid_parameter(main.error, "f_file_open"); + } } else if (status == F_file_found_not) { + // the file does not have to exist - f_color_print(f_type_warning, main.context.set.warning, "%sCannot find the file '%.*s'%c", fll_error_print_warning, file_path.used, file_path.string, f_string_eol_s[0]); + if (main.error.verbosity != f_console_verbosity_verbose || main.error.verbosity == f_console_verbosity_debug) { + fll_print_format("%c%[%sCannot find the file '%Q'.%]%c", main.warning.to.stream, f_string_eol_s[0], main.warning.context, main.warning.prefix, file_path, main.warning.context, f_string_eol_s[0]); + } + status = F_none; } else if (status == F_file_open) { - f_color_print(main.error.to.stream, main.context.set.error, "%sUnable to open the file '%.*s'%c", fll_error_print_error, file_path.used, file_path.string, f_string_eol_s[0]); + if (main.error.verbosity != f_console_verbosity_quiet) { + fll_print_format("%c%[%sUnable to open the file '%Q'.%]%c", main.error.to.stream, f_string_eol_s[0], main.error.context, main.error.prefix, file_path, main.error.context, f_string_eol_s[0]); + } } else if (status == F_file_descriptor) { - f_color_print(main.error.to.stream, main.context.set.error, "%sFile descriptor error while trying to open the file '%.*s'%c", fll_error_print_error, file_path.used, file_path.string, f_string_eol_s[0]); + if (main.error.verbosity != f_console_verbosity_quiet) { + fll_print_format("%c%[%sFile descriptor error while trying to open the file '%Q'.%]%c", main.error.to.stream, f_string_eol_s[0], main.error.context, main.error.prefix, file_path, main.error.context, f_string_eol_s[0]); + } } else if (status == F_memory_not) { - f_color_print(main.error.to.stream, main.context.set.error, "%sUnable to allocate memory.%c", fll_error_print_error, f_string_eol_s[0]); + firewall_print_error_on_allocation_failure(main.error); } else { - f_color_print(main.error.to.stream, main.context.set.error, "%sAn unhandled error (%u) has occurred while calling f_file_open()%c", fll_error_print_error, status, f_string_eol_s[0]); + firewall_print_error_on_unhandled(main.error, "f_file_open", status); } if (status != F_file_found_not) { @@ -623,26 +637,28 @@ f_status_t firewall_perform_commands(const firewall_local_data_t local, const fi if (F_status_is_error(status)) { status = F_status_set_fine(status); - if (status == F_parameter) { - f_color_print(main.error.to.stream, main.context.set.error, "%sInvalid parameter when calling f_file_read()%c", fll_error_print_error, f_string_eol_s[0]); - } - else if (status == F_number_overflow) { - f_color_print(main.error.to.stream, main.context.set.error, "%sInteger overflow while trying to buffer the file '%.*s'%c", fll_error_print_error, file_path.used, file_path.string, f_string_eol_s[0]); - } - else if (status == F_file_closed) { - f_color_print(main.error.to.stream, main.context.set.error, "%sThe file '%.*s' is no longer open%c", fll_error_print_error, file_path.used, file_path.string, f_string_eol_s[0]); - } - else if (status == F_file_seek) { - f_color_print(main.error.to.stream, main.context.set.error, "%sA seek error occurred while accessing the file '%.*s'%c", fll_error_print_error, file_path.used, file_path.string, f_string_eol_s[0]); - } - else if (status == F_file_read) { - f_color_print(main.error.to.stream, main.context.set.error, "%sA read error occurred while accessing the file '%.*s'%c", fll_error_print_error, file_path.used, file_path.string, f_string_eol_s[0]); - } - else if (status == F_memory_not) { - f_color_print(main.error.to.stream, main.context.set.error, "%sUnable to allocate memory.%c", fll_error_print_error, f_string_eol_s[0]); - } - else { - f_color_print(main.error.to.stream, main.context.set.error, "%sAn unhandled error (%u) has occurred while calling f_file_read()%c", fll_error_print_error, status, f_string_eol_s[0]); + if (main.error.verbosity != f_console_verbosity_quiet) { + if (status == F_parameter) { + firewall_print_error_on_invalid_parameter(main.error, "f_file_read"); + } + else if (status == F_number_overflow) { + fll_print_format("%c%[%sInteger overflow while trying to buffer the file '%Q'.%]%c", main.error.to.stream, f_string_eol_s[0], main.error.context, main.error.prefix, file_path, main.error.context, f_string_eol_s[0]); + } + else if (status == F_file_closed) { + fll_print_format("%c%[%sThe file '%Q' is no longer open.%]%c", main.error.to.stream, f_string_eol_s[0], main.error.context, main.error.prefix, file_path, main.error.context, f_string_eol_s[0]); + } + else if (status == F_file_seek) { + fll_print_format("%c%[%sA seek error occurred while accessing the file '%Q'.%]%c", main.error.to.stream, f_string_eol_s[0], main.error.context, main.error.prefix, file_path, main.error.context, f_string_eol_s[0]); + } + else if (status == F_file_read) { + fll_print_format("%c%[%sA read error occurred while accessing the file '%Q'.%]%c", main.error.to.stream, f_string_eol_s[0], main.error.context, main.error.prefix, file_path, main.error.context, f_string_eol_s[0]); + } + else if (status == F_memory_not) { + firewall_print_error_on_allocation_failure(main.error); + } + else { + firewall_print_error_on_unhandled(main.error, "f_file_read", status); + } } status = F_status_set_error(status); @@ -661,16 +677,16 @@ f_status_t firewall_perform_commands(const firewall_local_data_t local, const fi status = F_status_set_fine(status); if (status == F_parameter) { - f_color_print(main.error.to.stream, main.context.set.error, "%sInvalid parameter when calling fll_fss_basic_read() for the file '%.*s'%c", fll_error_print_error, file_path.used, file_path.string, f_string_eol_s[0]); + firewall_print_error_on_invalid_parameter_for_file(main.error, "fll_fss_basic_read", file_path.used ? file_path.string : ""); } else if (status == F_data_not_eos || status == F_data_not || status == F_data_not_stop) { // empty files are to be silently ignored } else if (status == F_memory_not) { - f_color_print(main.error.to.stream, main.context.set.error, "%sUnable to allocate memory.%c", fll_error_print_error, f_string_eol_s[0]); + firewall_print_error_on_allocation_failure(main.error); } else { - f_color_print(main.error.to.stream, main.context.set.error, "%sAn unhandled error (%u) has occurred while calling fll_fss_basic_read() for the file '%.*s'%c", fll_error_print_error, status, file_path.used, file_path.string, f_string_eol_s[0]); + firewall_print_error_on_unhandled_for_file(main.error, "fll_fss_basic_read", status, file_path.used ? file_path.string : ""); } status = F_status_set_error(status); @@ -712,7 +728,7 @@ f_status_t firewall_perform_commands(const firewall_local_data_t local, const fi } if (F_status_is_error(status)) { - f_color_print(main.error.to.stream, main.context.set.error, "%sUnable to allocate memory.%c", fll_error_print_error, f_string_eol_s[0]); + firewall_print_error_on_allocation_failure(main.error); macro_f_string_dynamic_t_delete_simple(ip_list_action); } @@ -733,7 +749,8 @@ f_status_t firewall_perform_commands(const firewall_local_data_t local, const fi macro_f_string_dynamic_t_resize(status, ip_argument, ip_length); if (F_status_is_error(status)) { - f_color_print(main.error.to.stream, main.context.set.error, "%sUnable to allocate memory.%c", fll_error_print_error, f_string_eol_s[0]); + firewall_print_error_on_allocation_failure(main.error); + break; } @@ -743,17 +760,7 @@ f_status_t firewall_perform_commands(const firewall_local_data_t local, const fi macro_firewall_append_argument_to_arguments(status, arguments, ip_argument) if (F_status_is_error(status)) break; - if (main.error.verbosity == f_console_verbosity_debug) { - f_color_print_code(f_type_debug, main.context.warning); - fprintf(f_type_debug, "%s ", current_tool); - - for (f_array_length_t i = 0; i < arguments.used; ++i) { - fprintf(f_type_debug, "%.*s ", arguments.array[i].used, arguments.array[i].string); - } // for - - f_color_print_code(f_type_debug, main.context.reset); - fprintf(f_type_debug, "\n"); - } + firewall_print_debug_tool(main.warning, current_tool, arguments); status = fll_execute_program((f_string_t) current_tool, arguments, 0, 0, (void *) &return_code); @@ -763,18 +770,7 @@ f_status_t firewall_perform_commands(const firewall_local_data_t local, const fi } if (status == F_failure) { - f_color_print(main.error.to.stream, main.context.set.error, "%sFailed to perform requested %s operation:%c", fll_error_print_error, current_tool, f_string_eol_s[0]); - fprintf(f_type_error, " "); - - f_color_print_code(f_type_error, main.context.error); - - fprintf(f_type_error, "%s ", current_tool); - for (f_array_length_t i = 0; i < arguments.used; ++i) { - fprintf(f_type_error, "%.*s ", arguments.array[i].used, arguments.array[i].string); - } // for - - f_color_print_code(f_type_error, main.context.reset); - fprintf(f_type_error, "\n"); + firewall_print_error_on_operation(main.error, current_tool, arguments); // remove ip_argument from arguments string. macro_f_string_dynamic_t_delete_simple(arguments.array[arguments.used--]); @@ -782,7 +778,7 @@ f_status_t firewall_perform_commands(const firewall_local_data_t local, const fi break; } else if (status == F_parameter) { - f_color_print(main.error.to.stream, main.context.set.error, "%sInvalid parameter when calling fll_execute_program()%c", fll_error_print_error, f_string_eol_s[0]); + firewall_print_error_on_invalid_parameter(main.error, "fll_execute_program"); // remove ip_argument from arguments string. macro_f_string_dynamic_t_delete_simple(arguments.array[arguments.used--]); @@ -813,17 +809,7 @@ f_status_t firewall_perform_commands(const firewall_local_data_t local, const fi if (status == F_failure || status == F_parameter) break; } else { - if (main.error.verbosity == f_console_verbosity_debug) { - f_color_print_code(f_type_debug, main.context.warning); - fprintf(f_type_debug, "%s ", current_tool); - - for (f_array_length_t i = 0; i < arguments.used; ++i) { - fprintf(f_type_debug, "%.*s ", arguments.array[i].used, arguments.array[i].string); - } // for - - f_color_print_code(f_type_debug, main.context.reset); - fprintf(f_type_debug, "\n"); - } + firewall_print_debug_tool(main.warning, current_tool, arguments); status = fll_execute_program(current_tool, arguments, 0, 0, (void *) &return_code); @@ -833,22 +819,13 @@ f_status_t firewall_perform_commands(const firewall_local_data_t local, const fi } if (status == F_failure) { - f_color_print(main.error.to.stream, main.context.set.error, "%sFailed to perform requested %s operation:%c", fll_error_print_error, current_tool, f_string_eol_s[0]); - fprintf(f_type_error, " "); - f_color_print_code(f_type_error, main.context.error); - - fprintf(f_type_error, "%s ", current_tool); - for (f_array_length_t i = 0; i < arguments.used; ++i) { - fprintf(f_type_error, "%.*s ", arguments.array[i].used, arguments.array[i].string); - } // for - - f_color_print_code(f_type_error, main.context.reset); - fprintf(f_type_error, "\n"); + firewall_print_error_on_operation(main.error, current_tool, arguments); break; } else if (status == F_parameter) { - f_color_print(main.error.to.stream, main.context.set.error, "%sInvalid parameter when calling fll_execute_program()%c", fll_error_print_error, f_string_eol_s[0]); + firewall_print_error_on_invalid_parameter(main.error, "fll_execute_program"); + break; } } @@ -892,7 +869,7 @@ f_status_t firewall_create_custom_chains(firewall_reserved_chains_t *reserved, f status = f_string_dynamics_resize(2, &arguments); if (F_status_is_error(status)) return status; - status = f_string_dynamic_resize(firewall_chain_create_command_length, &arguments.array[0]); + status = f_string_dynamic_resize(firewall_chain_create_command_length + 1, &arguments.array[0]); if (F_status_is_error(status)) { macro_f_string_dynamics_t_delete_simple(arguments); @@ -903,6 +880,7 @@ f_status_t firewall_create_custom_chains(firewall_reserved_chains_t *reserved, f macro_firewall_concat_string(arguments.array[0].string, firewall_chain_create_command, firewall_chain_create_command_length); arguments.array[0].used = firewall_chain_create_command_length; + arguments.array[0].string[firewall_chain_create_command_length] = 0; status = f_string_dynamic_increase(f_memory_default_allocation_small, &arguments.array[1]); @@ -999,7 +977,7 @@ f_status_t firewall_create_custom_chains(firewall_reserved_chains_t *reserved, f arguments.array[1].used = 0; if (length > arguments.array[1].size) { - macro_f_string_dynamic_t_resize(status, arguments.array[1], length); + macro_f_string_dynamic_t_resize(status, arguments.array[1], length + 1); if (F_status_is_error(status)) { macro_f_string_dynamics_t_delete_simple(arguments); @@ -1008,7 +986,7 @@ f_status_t firewall_create_custom_chains(firewall_reserved_chains_t *reserved, f } } - macro_f_string_dynamic_t_resize(status, main->chains.array[main->chains.used], length); + macro_f_string_dynamic_t_resize(status, main->chains.array[main->chains.used], length + 1); if (F_status_is_error(status)) { macro_f_string_dynamics_t_delete_simple(arguments); @@ -1018,7 +996,6 @@ f_status_t firewall_create_custom_chains(firewall_reserved_chains_t *reserved, f main->chains.array[main->chains.used].used = 0; local->chain_ids.array[i] = main->chains.used; - arguments.array[1].used = 0; j = local->chain_objects.array[i].start; // copy the string character by character, ignoring placeholders. @@ -1034,6 +1011,9 @@ f_status_t firewall_create_custom_chains(firewall_reserved_chains_t *reserved, f ++j; } // while + arguments.array[1].string[arguments.array[1].used] = 0; + main->chains.array[main->chains.used].string[main->chains.array[main->chains.used].used] = 0; + if (fl_string_compare(arguments.array[1].string, firewall_chain_forward, arguments.array[1].used, firewall_chain_forward_length) == F_equal_to) { create_chain = F_false; } @@ -1051,17 +1031,7 @@ f_status_t firewall_create_custom_chains(firewall_reserved_chains_t *reserved, f } if (create_chain) { - if (main->error.verbosity == f_console_verbosity_debug) { - f_color_print_code(f_type_debug, main->context.warning); - fprintf(f_type_debug, "%s ", firewall_tool_iptables); - - for (f_array_length_t i = 0; i < arguments.used; ++i) { - fprintf(f_type_debug, "%.*s ", arguments.array[i].used, arguments.array[i].string); - } // for - - f_color_print_code(f_type_debug, main->context.reset); - fprintf(f_type_debug, "\n"); - } + firewall_print_debug_tool(main->warning, firewall_tool_iptables, arguments); tool = firewall_program_iptables; status = fll_execute_program((f_string_t) firewall_tool_iptables, arguments, 0, 0, (void *) &return_code); @@ -1072,17 +1042,7 @@ f_status_t firewall_create_custom_chains(firewall_reserved_chains_t *reserved, f } if (F_status_is_error_not(status)) { - if (main->error.verbosity == f_console_verbosity_debug) { - f_color_print_code(f_type_debug, main->context.warning); - fprintf(f_type_debug, "%s ", firewall_tool_ip6tables); - - for (f_array_length_t i = 0; i < arguments.used; ++i) { - fprintf(f_type_debug, "%.*s ", arguments.array[i].used, arguments.array[i].string); - } // for - - f_color_print_code(f_type_debug, main->context.reset); - fprintf(f_type_debug, "\n"); - } + firewall_print_debug_tool(main->warning, firewall_tool_ip6tables, arguments); tool = firewall_program_ip6tables; status = fll_execute_program((f_string_t) firewall_tool_ip6tables, arguments, 0, 0, (void *) &return_code); @@ -1097,35 +1057,13 @@ f_status_t firewall_create_custom_chains(firewall_reserved_chains_t *reserved, f status = F_status_set_fine(status); if (status == F_failure) { - if (tool == firewall_program_iptables) { - f_color_print(main->error.to.stream, main->context.set.error, "%sFailed to perform requested %s operation:%c", fll_error_print_error, firewall_tool_iptables, f_string_eol_s[0]); - } - else if (tool == firewall_program_ip6tables) { - f_color_print(main->error.to.stream, main->context.set.error, "%sFailed to perform requested %s operation:%c", fll_error_print_error, firewall_tool_ip6tables, f_string_eol_s[0]); - } - - fprintf(f_type_error, " "); - f_color_print_code(f_type_error, main->context.error); - - if (tool == firewall_program_iptables) { - fprintf(f_type_error, "%s ", firewall_tool_iptables); - } - else if (tool == firewall_program_ip6tables) { - fprintf(f_type_error, "%s ", firewall_tool_ip6tables); - } - - for (f_array_length_t i = 0; i < arguments.used; ++i) { - fprintf(f_type_error, "%.*s ", arguments.array[i].used, arguments.array[i].string); - } // for - - f_color_print_code(f_type_error, main->context.reset); - fprintf(f_type_error, "\n"); + firewall_print_error_on_operation(main->error, tool == firewall_program_iptables ? firewall_tool_iptables : firewall_tool_ip6tables, arguments); } else if (status == F_parameter) { - f_color_print(main->error.to.stream, main->context.set.error, "%sInvalid parameter when calling fll_execute_program()%c", fll_error_print_error, f_string_eol_s[0]); + firewall_print_error_on_invalid_parameter(main->error, "fll_execute_program"); } else { - f_color_print(main->error.to.stream, main->context.set.error, "%sAn unhandled error (%u) has occurred while calling fll_execute_program()%c", fll_error_print_error, status, f_string_eol_s[0]); + firewall_print_error_on_unhandled(main->error, "fll_execute_program", status); } macro_f_string_dynamics_t_delete_simple(arguments); @@ -1161,17 +1099,7 @@ f_status_t firewall_delete_chains(const firewall_main_t main) { arguments.size = 1; arguments.used = 1; - if (main.error.verbosity == f_console_verbosity_debug) { - f_color_print_code(f_type_debug, main.context.warning); - fprintf(f_type_debug, "%s ", tools[i]); - - for (f_array_length_t i = 0; i < arguments.used; ++i) { - fprintf(f_type_debug, "%.*s ", arguments.array[i].used, arguments.array[i].string); - } // for - - f_color_print_code(f_type_debug, main.context.reset); - fprintf(f_type_debug, "\n"); - } + firewall_print_debug_tool(main.warning, tools[i], arguments); status = fll_execute_program(tools[i], arguments, 0, 0, (void *) &return_code); @@ -1184,24 +1112,13 @@ f_status_t firewall_delete_chains(const firewall_main_t main) { status = F_status_set_fine(status); if (status == F_failure) { - f_color_print(main.error.to.stream, main.context.set.error, "%sFailed to perform requested %s operation:%c", fll_error_print_error, tools[i], f_string_eol_s[0]); - - fprintf(f_type_error, " "); - f_color_print_code(f_type_error, main.context.error); - - fprintf(f_type_error, "%s ", tools[i]); - for (f_array_length_t i = 0; i < arguments.used; ++i) { - fprintf(f_type_error, "%.*s ", arguments.array[i].used, arguments.array[i].string); - } // for - - f_color_print_code(f_type_error, main.context.reset); - fprintf(f_type_error, "\n"); + firewall_print_error_on_operation(main.error, tools[i], arguments); } else if (status == F_parameter) { - f_color_print(main.error.to.stream, main.context.set.error, "%sInvalid parameter when calling fll_execute_program()%c", fll_error_print_error, f_string_eol_s[0]); + firewall_print_error_on_invalid_parameter(main.error, "fll_execute_program"); } else { - f_color_print(main.error.to.stream, main.context.set.error, "%sAn unhandled error (%u) has occurred while calling fll_execute_program()%c", fll_error_print_error, status, f_string_eol_s[0]); + firewall_print_error_on_unhandled(main.error, "fll_execute_program", status); } return status; @@ -1221,17 +1138,7 @@ f_status_t firewall_delete_chains(const firewall_main_t main) { arguments.size = 1; arguments.used = 1; - if (main.error.verbosity == f_console_verbosity_debug) { - f_color_print_code(f_type_debug, main.context.warning); - fprintf(f_type_debug, "%s ", tools[i]); - - for (f_array_length_t j = 0; j < arguments.used; ++j) { - fprintf(f_type_debug, "%.*s ", arguments.array[j].used, arguments.array[j].string); - } // for - - f_color_print_code(f_type_debug, main.context.reset); - fprintf(f_type_debug, "\n"); - } + firewall_print_debug_tool(main.warning, tools[i], arguments); status = fll_execute_program(tools[i], arguments, 0, 0, (void *) &return_code); @@ -1244,24 +1151,13 @@ f_status_t firewall_delete_chains(const firewall_main_t main) { status = F_status_set_fine(status); if (status == F_failure) { - f_color_print(main.error.to.stream, main.context.set.error, "%sFailed to perform requested %s operation:%c", fll_error_print_error, tools[i], f_string_eol_s[0]); - - fprintf(f_type_error, " "); - f_color_print_code(f_type_error, main.context.error); - - fprintf(f_type_error, "%s ", tools[i]); - for (f_array_length_t j = 0; j < arguments.used; ++j) { - fprintf(f_type_error, "%.*s ", arguments.array[j].used, arguments.array[j].string); - } // for - - f_color_print_code(f_type_error, main.context.reset); - fprintf(f_type_error, "\n"); + firewall_print_error_on_operation(main.error, tools[i], arguments); } else if (status == F_parameter) { - f_color_print(main.error.to.stream, main.context.set.error, "%sInvalid parameter when calling fll_execute_program()%c", fll_error_print_error, f_string_eol_s[0]); + firewall_print_error_on_invalid_parameter(main.error, "fll_execute_program"); } else { - f_color_print(main.error.to.stream, main.context.set.error, "%sAn unhandled error (%u) has occurred while calling fll_execute_program()%c", fll_error_print_error, status, f_string_eol_s[0]); + firewall_print_error_on_unhandled(main.error, "fll_execute_program", status); } return status; @@ -1302,18 +1198,7 @@ f_status_t firewall_default_lock(const firewall_main_t main) { for (f_array_length_t j = 0; j < 2; ++j) { int return_code = 0; - // print command when debugging. - if (main.error.verbosity == f_console_verbosity_debug) { - f_color_print_code(f_type_debug, main.context.warning); - fprintf(f_type_debug, "%s ", tools[j]); - - for (f_array_length_t k = 0; k < arguments.used; k++) { - fprintf(f_type_debug, "%.*s ", arguments.array[k].used, arguments.array[k].string); - } // for - - f_color_print_code(f_type_debug, main.context.reset); - fprintf(f_type_debug, "\n"); - } + firewall_print_debug_tool(main.warning, tools[j], arguments); status = fll_execute_program(tools[j], arguments, 0, 0, (void *) &return_code); @@ -1326,24 +1211,13 @@ f_status_t firewall_default_lock(const firewall_main_t main) { status = F_status_set_fine(status); if (status == F_failure) { - f_color_print(main.error.to.stream, main.context.set.error, "%sFailed to perform requested %s operation:%c", fll_error_print_error, tools[j], f_string_eol_s[0]); - - fprintf(f_type_error, " "); - f_color_print_code(f_type_error, main.context.error); - - fprintf(f_type_error, "%s ", tools[j]); - for (f_array_length_t k = 0; k < arguments.used; k++) { - fprintf(f_type_error, "%.*s ", arguments.array[k].used, arguments.array[k].string); - } // for - - f_color_print_code(f_type_error, main.context.reset); - fprintf(f_type_error, "\n"); + firewall_print_error_on_operation(main.error, tools[j], arguments); } else if (status == F_parameter) { - f_color_print(main.error.to.stream, main.context.set.error, "%sInvalid parameter when calling fll_execute_program()%c", fll_error_print_error, f_string_eol_s[0]); + firewall_print_error_on_invalid_parameter(main.error, "fll_execute_program"); } else { - f_color_print(main.error.to.stream, main.context.set.error, "%sAn unhandled error (%u) has occurred while calling fll_execute_program()%c", fll_error_print_error, status, f_string_eol_s[0]); + firewall_print_error_on_unhandled(main.error, "fll_execute_program", status); } return status; @@ -1362,28 +1236,30 @@ f_status_t firewall_buffer_rules(const f_string_t filename, const bool optional, if (F_status_is_error(status)) { status = F_status_set_fine(status); - if (optional) { - if (status == F_parameter) { - f_color_print(main->error.to.stream, main->context.set.error, "%sInvalid parameter when calling f_file_open().%c", fll_error_print_error, f_string_eol_s[0]); - } - else if (status != F_file_found_not && status != F_file_open && status != F_file_descriptor) { - f_color_print(main->error.to.stream, main->context.set.error, "%sAn unhandled error (%u) has occurred while calling f_file_open().%c", fll_error_print_error, status, f_string_eol_s[0]); - } - } else { - if (status == F_parameter) { - f_color_print(main->error.to.stream, main->context.set.error, "%sInvalid parameter when calling f_file_open().%c", fll_error_print_error, f_string_eol_s[0]); - } - else if (status == F_file_found_not) { - f_color_print(main->error.to.stream, main->context.set.error, "%sUnable to find the file '%s'.%c", fll_error_print_error, filename, f_string_eol_s[0]); - } - else if (status == F_file_open) { - f_color_print(main->error.to.stream, main->context.set.error, "%sUnable to open the file '%s'.%c", fll_error_print_error, filename, f_string_eol_s[0]); - } - else if (status == F_file_descriptor) { - f_color_print(main->error.to.stream, main->context.set.error, "%sFile descriptor error while trying to open the file '%s'.%c", fll_error_print_error, filename, f_string_eol_s[0]); - } - else { - f_color_print(main->error.to.stream, main->context.set.error, "%sAn unhandled error (%u) has occurred while calling f_file_open().%c", fll_error_print_error, status, f_string_eol_s[0]); + if (main->error.verbosity != f_console_verbosity_quiet) { + if (optional) { + if (status == F_parameter) { + firewall_print_error_on_invalid_parameter(main->error, "f_file_open"); + } + else if (status != F_file_found_not && status != F_file_open && status != F_file_descriptor) { + firewall_print_error_on_unhandled(main->error, "f_file_open", status); + } + } else { + if (status == F_parameter) { + firewall_print_error_on_invalid_parameter(main->error, "f_file_open"); + } + else if (status == F_file_found_not) { + fll_print_format("%c%[%sUnable to find the file '%S'.%]%c", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, filename, main->error.context, f_string_eol_s[0]); + } + else if (status == F_file_open) { + fll_print_format("%c%[%sUnable to open the file '%S'.%]%c", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, filename, main->error.context, f_string_eol_s[0]); + } + else if (status == F_file_descriptor) { + fll_print_format("%c%[%sFile descriptor error while trying to open the file '%S'.%]%c", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, filename, main->error.context, f_string_eol_s[0]); + } + else { + firewall_print_error_on_unhandled(main->error, "f_file_open", status); + } } } @@ -1397,26 +1273,28 @@ f_status_t firewall_buffer_rules(const f_string_t filename, const bool optional, if (F_status_is_error(status)) { status = F_status_set_fine(status); - if (status == F_parameter) { - f_color_print(main->error.to.stream, main->context.set.error, "%sInvalid parameter when calling f_file_read().%c", fll_error_print_error, f_string_eol_s[0]); - } - else if (status == F_number_overflow) { - f_color_print(main->error.to.stream, main->context.set.error, "%sInteger overflow while trying to buffer the file '%s'.%c", fll_error_print_error, filename, f_string_eol_s[0]); - } - else if (status == F_file_closed) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe file '%s' is no longer open.%c", fll_error_print_error, filename, f_string_eol_s[0]); - } - else if (status == F_file_seek) { - f_color_print(main->error.to.stream, main->context.set.error, "%sA seek error occurred while accessing the file '%s'.%c", fll_error_print_error, filename, f_string_eol_s[0]); - } - else if (status == F_file_read) { - f_color_print(main->error.to.stream, main->context.set.error, "%sA read error occurred while accessing the file '%s'.%c", fll_error_print_error, filename, f_string_eol_s[0]); - } - else if (status == F_memory_not) { - f_color_print(main->error.to.stream, main->context.set.error, "%sUnable to allocate memory.%c", fll_error_print_error, f_string_eol_s[0]); - } - else { - f_color_print(main->error.to.stream, main->context.set.error, "%sAn unhandled error (%u) has occurred while calling f_file_read().%c", fll_error_print_error, status, f_string_eol_s[0]); + if (main->error.verbosity != f_console_verbosity_quiet) { + if (status == F_parameter) { + firewall_print_error_on_invalid_parameter(main->error, "f_file_read"); + } + else if (status == F_number_overflow) { + fll_print_format("%c%[%sInteger overflow while trying to buffer the file '%S'.%]%c", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, filename, main->error.context, f_string_eol_s[0]); + } + else if (status == F_file_closed) { + fll_print_format("%c%[%sThe file '%S' is no longer open.%]%c", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, filename, main->error.context, f_string_eol_s[0]); + } + else if (status == F_file_seek) { + fll_print_format("%c%[%sA seek error occurred while accessing the file '%S'.%]%c", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, filename, main->error.context, f_string_eol_s[0]); + } + else if (status == F_file_read) { + fll_print_format("%c%[%sA read error occurred while accessing the file '%S'.%]%c", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, filename, main->error.context, f_string_eol_s[0]); + } + else if (status == F_memory_not) { + firewall_print_error_on_allocation_failure(main->error); + } + else { + firewall_print_error_on_unhandled(main->error, "f_file_read", status); + } } return status; @@ -1435,17 +1313,19 @@ f_status_t firewall_buffer_rules(const f_string_t filename, const bool optional, if (F_status_is_error(status)) { status = F_status_set_fine(status); - if (status == F_parameter) { - f_color_print(main->error.to.stream, main->context.set.error, "%sInvalid parameter when calling fll_fss_basic_list_read() for the file '%s'.%c", fll_error_print_error, filename, f_string_eol_s[0]); - } - else if (status == F_data_not_eos || status == F_data_not || status == F_data_not_stop) { - f_color_print(main->error.to.stream, main->context.set.error, "%sNo relevant main was found within the file '%s'.%c", fll_error_print_error, filename, f_string_eol_s[0]); - } - else if (status == F_memory_not) { - f_color_print(main->error.to.stream, main->context.set.error, "%sUnable to allocate memory.%c", fll_error_print_error, f_string_eol_s[0]); - } - else { - f_color_print(main->error.to.stream, main->context.set.error, "%sAn unhandled error (%u) has occurred while calling fll_fss_basic_list_read() for the file '%s'.%c", fll_error_print_error, status, filename, f_string_eol_s[0]); + if (main->error.verbosity != f_console_verbosity_quiet) { + if (status == F_parameter) { + firewall_print_error_on_invalid_parameter_for_file(main->error, "fll_fss_basic_list_read", filename); + } + else if (status == F_data_not_eos || status == F_data_not || status == F_data_not_stop) { + fll_print_format("%c%[%sNo relevant main was found within the file '%s'.%]%c", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, filename, main->error.context, f_string_eol_s[0]); + } + else if (status == F_memory_not) { + firewall_print_error_on_allocation_failure(main->error); + } + else { + firewall_print_error_on_unhandled_for_file(main->error, "fll_fss_basic_read", status, filename); + } } } else { @@ -1490,13 +1370,13 @@ f_status_t firewall_process_rules(f_string_range_t *range, firewall_local_data_t status = F_status_set_fine(status); if (status == F_memory_not) { - f_color_print(main->error.to.stream, main->context.set.error, "%sUnable to allocate memory.%c", fll_error_print_error, f_string_eol_s[0]); + firewall_print_error_on_allocation_failure(main->error); } else if (status == F_failure) { // the error message has already been displayed. } else { - f_color_print(main->error.to.stream, main->context.set.error, "%sAn unhandled error (%u) has occurred while calling firewall_perform_commands().%c", fll_error_print_error, status, f_string_eol_s[0]); + firewall_print_error_on_unhandled(main->error, "firewall_perform_commands", status); } macro_f_fss_objects_t_delete_simple(local->rule_objects); diff --git a/level_3/firewall/c/private-firewall.h b/level_3/firewall/c/private-firewall.h index 8bb836a..6347a0a 100644 --- a/level_3/firewall/c/private-firewall.h +++ b/level_3/firewall/c/private-firewall.h @@ -25,7 +25,7 @@ extern "C" { * * Status codes (with error bit) are returned on any problem. */ -f_status_t firewall_perform_commands(const firewall_local_data_t local, const firewall_main_t main) f_attribute_visibility_internal; +extern f_status_t firewall_perform_commands(const firewall_local_data_t local, const firewall_main_t main) f_attribute_visibility_internal; /** * Create custom chains. @@ -42,7 +42,7 @@ f_status_t firewall_perform_commands(const firewall_local_data_t local, const fi * * Status codes (with error bit) are returned on any problem. */ -f_status_t firewall_create_custom_chains(firewall_reserved_chains_t *reserved, firewall_local_data_t *local, firewall_main_t *main) f_attribute_visibility_internal; +extern f_status_t firewall_create_custom_chains(firewall_reserved_chains_t *reserved, firewall_local_data_t *local, firewall_main_t *main) f_attribute_visibility_internal; /** * Deallocate chains. @@ -55,7 +55,7 @@ f_status_t firewall_create_custom_chains(firewall_reserved_chains_t *reserved, f * * Status codes (with error bit) are returned on any problem. */ -f_status_t firewall_delete_chains(const firewall_main_t main) f_attribute_visibility_internal; +extern f_status_t firewall_delete_chains(const firewall_main_t main) f_attribute_visibility_internal; /** * Lock the firewall. @@ -68,7 +68,7 @@ f_status_t firewall_delete_chains(const firewall_main_t main) f_attribute_visibi * * Status codes (with error bit) are returned on any problem. */ -f_status_t firewall_default_lock(const firewall_main_t main) f_attribute_visibility_internal; +extern f_status_t firewall_default_lock(const firewall_main_t main) f_attribute_visibility_internal; /** * Buffer firewall rules. @@ -88,7 +88,7 @@ f_status_t firewall_default_lock(const firewall_main_t main) f_attribute_visibil * * Status codes (with error bit) are returned on any problem. */ -f_status_t firewall_buffer_rules(const f_string_t filename, const bool optional, firewall_local_data_t *local, firewall_main_t *main) f_attribute_visibility_internal; +extern f_status_t firewall_buffer_rules(const f_string_t filename, const bool optional, firewall_local_data_t *local, firewall_main_t *main) f_attribute_visibility_internal; /** * Process buffered rules. @@ -105,7 +105,7 @@ f_status_t firewall_buffer_rules(const f_string_t filename, const bool optional, * * Status codes (with error bit) are returned on any problem. */ -f_status_t firewall_process_rules(f_string_range_t *range, firewall_local_data_t *local, firewall_main_t *main) f_attribute_visibility_internal; +extern f_status_t firewall_process_rules(f_string_range_t *range, firewall_local_data_t *local, firewall_main_t *main) f_attribute_visibility_internal; /** * Delete allocated local data. @@ -118,7 +118,7 @@ f_status_t firewall_process_rules(f_string_range_t *range, firewall_local_data_t * * Status codes (with error bit) are returned on any problem. */ -f_status_t firewall_delete_local_data(firewall_local_data_t *local) f_attribute_visibility_internal; +extern f_status_t firewall_delete_local_data(firewall_local_data_t *local) f_attribute_visibility_internal; #ifdef __cplusplus } // extern "C" diff --git a/level_3/firewall/data/build/dependencies b/level_3/firewall/data/build/dependencies index 7bd6534..590d654 100644 --- a/level_3/firewall/data/build/dependencies +++ b/level_3/firewall/data/build/dependencies @@ -24,9 +24,11 @@ fl_control_group fl_conversion fl_environment fl_fss +fl_print fl_status fl_string fll_error fll_execute fll_fss +fll_print fll_program diff --git a/level_3/firewall/data/build/settings b/level_3/firewall/data/build/settings index a852845..7f92776 100644 --- a/level_3/firewall/data/build/settings +++ b/level_3/firewall/data/build/settings @@ -20,7 +20,7 @@ build_compiler gcc build_indexer ar build_language c build_libraries -lc -lcap -build_libraries-individual -lfll_error -lfll_execute -lfll_fss -lfll_program -lfl_console -lfl_control_group -lfl_conversion -lfl_environment -lfl_fss -lfl_status -lfl_string -lf_account -lf_capability -lf_color -lf_console -lf_control_group -lf_conversion -lf_directory -lf_environment -lf_file -lf_fss -lf_limit -lf_memory -lf_path -lf_pipe -lf_print -lf_signal -lf_string -lf_thread -lf_type_array -lf_utf +build_libraries-individual -lfll_error -lfll_execute -lfll_fss -lfll_print -lfll_program -lfl_console -lfl_control_group -lfl_conversion -lfl_environment -lfl_fss -lfl_print -lfl_status -lfl_string -lf_account -lf_capability -lf_color -lf_console -lf_control_group -lf_conversion -lf_directory -lf_environment -lf_file -lf_fss -lf_limit -lf_memory -lf_path -lf_pipe -lf_print -lf_signal -lf_string -lf_thread -lf_type_array -lf_utf build_libraries-level -lfll_2 -lfll_1 -lfll_0 build_libraries-monolithic -lfll build_sources_library firewall.c private-common.c private-firewall.c @@ -52,7 +52,7 @@ defines_all -D_libcap_legacy_only_ -D_pthread_attr_unsupported_ -D_pthread_sigqu defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -pthread -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -pthread -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_3/fss_basic_list_read/c/fss_basic_list_read.c b/level_3/fss_basic_list_read/c/fss_basic_list_read.c index f5299f3..99c6ff4 100644 --- a/level_3/fss_basic_list_read/c/fss_basic_list_read.c +++ b/level_3/fss_basic_list_read/c/fss_basic_list_read.c @@ -9,6 +9,8 @@ extern "C" { #ifndef _di_fss_basic_list_read_print_help_ f_status_t fss_basic_list_read_print_help(const f_file_t output, const f_color_context_t context) { + flockfile(output.stream); + fll_program_print_help_header(output, context, fss_basic_list_read_name_long, fss_basic_list_read_version); fll_program_print_help_option(output, context, f_console_standard_short_help_s, f_console_standard_long_help_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Print this help message."); @@ -21,7 +23,7 @@ extern "C" { fll_program_print_help_option(output, context, f_console_standard_short_debug_s, f_console_standard_long_debug_s, f_console_symbol_short_disable_s, f_console_symbol_long_disable_s, " Enable debugging, inceasing verbosity beyond normal output."); fll_program_print_help_option(output, context, f_console_standard_short_version_s, f_console_standard_long_version_s, f_console_symbol_short_disable_s, f_console_symbol_long_disable_s, " Print only the version number."); - fprintf(output.stream, "%c", f_string_eol_s[0]); + f_print_character(f_string_eol_s[0], output.stream); fll_program_print_help_option(output, context, fss_basic_list_read_short_at, fss_basic_list_read_long_at, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Select Object at this numeric index."); fll_program_print_help_option(output, context, fss_basic_list_read_short_content, fss_basic_list_read_long_content, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Print the Content (default)."); @@ -39,153 +41,75 @@ extern "C" { fll_program_print_help_usage(output, context, fss_basic_list_read_name, "filename(s)"); - f_color_print(output.stream, context.set.important, " Notes:"); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " This program will print the Content associated with the given Object and Content main based on the FSS-0002 Basic List standard.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " All numeric positions (indexes) start at 0 instead of 1.%c", f_string_eol_s[0]); - fprintf(output.stream, " For example, a file of 17 lines would range from 0 to 16.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" %[Notes:%]%c", output.stream, context.set.important, context.set.important, f_string_eol_s[0]); - fprintf(output.stream, " When using the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_depth); - fprintf(output.stream, " option, an order of operations is enforced on the parameters.%c", f_string_eol_s[0]); + fl_print_format(" This program will print the Content associated with the given Object and Content main based on the FSS-0002 Basic List standard.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " When this order of operations is in effect, parameters to the right of a depth parameter are influenced by that depth parameter:%c", f_string_eol_s[0]); + fl_print_format(" All numeric positions (indexes) start at 0 instead of 1.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" For example, a file of 17 lines would range from 0 to 16.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_at); - fprintf(output.stream, ": An Object index at the specified depth.%c", f_string_eol_s[0]); + fl_print_format(" When using the %[%s%s%] option, an order of operations is enforced on the parameters.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_depth, context.set.notable, f_string_eol_s[0]); - fprintf(output.stream, " "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_depth); - fprintf(output.stream, ": A new depth within the specified depth, indexed from the root.%c", f_string_eol_s[0]); + fl_print_format(" When this order of operations is in effect, parameters to the right of a depth parameter are influenced by that depth parameter:%c", output.stream, f_string_eol_s[0]); - fprintf(output.stream, " "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_name); - fprintf(output.stream, ": An Object name at the specified depth.%c", f_string_eol_s[0]); + fl_print_format(" %[%s%s%]: An Object index at the specified depth.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_at, context.set.notable, f_string_eol_s[0]); + fl_print_format(" %[%s%s%]: A new depth within the specified depth, indexed from the root.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_depth, context.set.notable, f_string_eol_s[0]); + fl_print_format(" %[%s%s%]: An Object name at the specified depth.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_name, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" The parameter %[%s%s%] must be in numeric order, but values in between may be skipped.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_depth, context.set.notable, f_string_eol_s[0]); + fl_print_format(" ('-d 0 -a 1 -d 2 -a 2' would specify index 1 at depth 0, any index at depth 1, and index 2 at depth 2.)%c", output.stream, f_string_eol_s[0]); + fl_print_format(" ('-d 2 -a 1 -d 0 -a 2' would be invalid because depth 2 is before depth 1.)%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " The parameter "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_depth); - fprintf(output.stream, " must be in numeric order, but values in between may be skipped.%c", f_string_eol_s[0]); - fprintf(output.stream, " ('-d 0 -a 1 -d 2 -a 2' would specify index 1 at depth 0, any index at depth 1, and index 2 at depth 2.)%c", f_string_eol_s[0]); - fprintf(output.stream, " ('-d 2 -a 1 -d 0 -a 2' would be invalid because depth 2 is before depth 1.)%c", f_string_eol_s[0]); + fl_print_format(" The parameter %[%s%s%] selects a Content column.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_select, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" Specify both %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_object, context.set.notable); + fl_print_format(" and the %[%s%s%] parameters to get the total objects.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_total, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " The parameter "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_select); - fprintf(output.stream, " selects a Content column.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " Specify both "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_object); - fprintf(output.stream, " and the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_total); - fprintf(output.stream, " parameters to get the total objects.%c", f_string_eol_s[0]); + fl_print_format(" When both %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_at, context.set.notable); + fl_print_format(" and %[%s%s%] parameters are specified (at the same depth),", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_name, context.set.notable); + fl_print_format(" the %[%s%s%] parameter value will be treated as a position relative to the specified", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_at, context.set.notable); + fl_print_format(" %[%s%s%] parameter value.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_name, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" This program may support parameters, such as %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_depth, context.set.notable); + fl_print_format(" or %[%s%s%], even if not supported by the standard.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_select, context.set.notable, f_string_eol_s[0]); + fl_print_format(" This is done to help ensure consistency for scripting.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " When both "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_at); - fprintf(output.stream, " and "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_name); - fprintf(output.stream, " parameters are specified (at the same depth), the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_at); - fprintf(output.stream, " parameter value will be treated as a position relative to the specified "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_name); - fprintf(output.stream, " parameter value.%c", f_string_eol_s[0]); + fl_print_format(" For parameters like %[%s%s%],", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_depth, context.set.notable); + fl_print_format(" if the standard doesn't support nested Content, then only a depth of 0 would be valid.%c", output.stream, f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" For parameters like %[%s%s%],", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_select, context.set.notable); + fl_print_format(" if the standard doesn't support multiple Content groups, then only a select of 0 would be valid.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " This program may support parameters, such as "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_depth); - fprintf(output.stream, " or "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_select); - fprintf(output.stream, ", even if not supported by the standard.%c", f_string_eol_s[0]); - fprintf(output.stream, " This is done to help ensure consistency for scripting.%c", f_string_eol_s[0]); + fl_print_format(" The parameter %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_trim, context.set.notable); + fl_print_format(" will remove leading and trailing whitespaces when selecting objects or when printing objects.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" When specifying both the %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_object, context.set.notable); + fl_print_format(" parameter and the %[%s%s%] parameter, the entire Object and Content are printed, including the formatting.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_content, context.set.notable, f_string_eol_s[0]); + fl_print_format(" Both the Object and Content printed are already escaped.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" Both the Object and Content are separated by an EOL.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " For parameters like "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_depth); - fprintf(output.stream, ", if the standard doesn't support nested Content, then only a depth of 0 would be valid.%c", f_string_eol_s[0]); + fl_print_format(" The parameter %[%s%s%] accepts the following:%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_delimit, context.set.notable, f_string_eol_s[0]); + fl_print_format(" - %[%s%]: Do not apply delimits.%c", output.stream, context.set.notable, fss_basic_list_read_delimit_mode_name_none, context.set.notable, f_string_eol_s[0]); + fl_print_format(" - %[%s%]: (default) Apply all delimits.%c", output.stream, context.set.notable, fss_basic_list_read_delimit_mode_name_all, context.set.notable, f_string_eol_s[0]); + fl_print_format(" - %[%s%]: Apply delimits for Objects.%c", output.stream, context.set.notable, fss_basic_list_read_delimit_mode_name_object, context.set.notable, f_string_eol_s[0]); + fl_print_format(" - A number, 0 or greater: apply delimits for Content at the specified depth.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" - A number, 0 or greater, followed by a %[%s%]: (such as '1+') apply delimits for Content at the specified depth and any greater depth (numerically).%c", output.stream, context.set.notable, fss_basic_list_read_delimit_mode_name_greater, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); + fl_print_format(" - A number, 0 or lesser, followed by a %[%s%]: (such as '1-') apply delimits for Content at the specified depth and any lesser depth (numerically).%c%c", output.stream, context.set.notable, fss_basic_list_read_delimit_mode_name_lesser, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " For parameters like "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_select); - fprintf(output.stream, ", if the standard doesn't support multiple Content groups, then only a select of 0 would be valid.%c", f_string_eol_s[0]); + fl_print_format(" The %[%s%s%] parameter may be specified multiple times to customize the delimit behavior.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_delimit, context.set.notable, f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" The %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_delimit, context.set.notable); + fl_print_format(" values %[%s%]", output.stream, context.set.notable, fss_basic_list_read_delimit_mode_name_none, context.set.notable); + fl_print_format(" and %[%s%],", output.stream, context.set.notable, fss_basic_list_read_delimit_mode_name_all, context.set.notable); + fl_print_format(" overrule all other delimit values.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " The parameter "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_trim); - fprintf(output.stream, " will remove leading and trailing whitespaces when selecting objects or when printing objects.%c", f_string_eol_s[0]); + fl_print_format(" The parameters %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_columns, context.set.notable); + fl_print_format(" and %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_select, context.set.notable); + fl_print_format(" refer to a Content column.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" The word \"column\" is being loosely defined to refer to a specific Content.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" This is not to be confused with a depth.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " When specifying both the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_object); - fprintf(output.stream, " parameter and the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_content); - fprintf(output.stream, " parameter, the entire Object and Content are printed, including the formatting.%c", f_string_eol_s[0]); - fprintf(output.stream, " Both the Object and Content printed are already escaped.%c", f_string_eol_s[0]); - fprintf(output.stream, " Both the Object and Content are separated by an EOL.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " The parameter "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_delimit); - fprintf(output.stream, " accepts the following:%c", f_string_eol_s[0]); - fprintf(output.stream, " - "); - f_color_print(output.stream, context.set.notable, "%s", fss_basic_list_read_delimit_mode_name_none); - fprintf(output.stream, ": Do not apply delimits.%c", f_string_eol_s[0]); - fprintf(output.stream, " - "); - f_color_print(output.stream, context.set.notable, "%s", fss_basic_list_read_delimit_mode_name_all); - fprintf(output.stream, ": (default) Apply all delimits.%c", f_string_eol_s[0]); - fprintf(output.stream, " - "); - f_color_print(output.stream, context.set.notable, "%s", fss_basic_list_read_delimit_mode_name_object); - fprintf(output.stream, ": Apply delimits for Objects.%c", f_string_eol_s[0]); - fprintf(output.stream, " - A number, 0 or greater: apply delimits for Content at the specified depth.%c", f_string_eol_s[0]); - fprintf(output.stream, " - A number, 0 or greater, followed by a "); - f_color_print(output.stream, context.set.notable, "%s", fss_basic_list_read_delimit_mode_name_greater); - fprintf(output.stream, ": (such as '1+') apply delimits for Content at the specified depth and any greater depth (numerically).%c", f_string_eol_s[0]); - fprintf(output.stream, " - A number, 0 or greater, followed by a "); - f_color_print(output.stream, context.set.notable, "%s", fss_basic_list_read_delimit_mode_name_lesser); - fprintf(output.stream, ": (such as '1-') apply delimits for Content at the specified depth and any lesser depth (numerically).%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " The "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_delimit); - fprintf(output.stream, " parameter may be specified multiple times to customize the delimit behavior.%c", f_string_eol_s[0]); - - fprintf(output.stream, " The "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_delimit); - fprintf(output.stream, " values "); - f_color_print(output.stream, context.set.notable, "%s", fss_basic_list_read_delimit_mode_name_none); - fprintf(output.stream, " and "); - f_color_print(output.stream, context.set.notable, "%s", fss_basic_list_read_delimit_mode_name_all); - fprintf(output.stream, ", overrule all other delimit values.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " The parameters "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_columns); - fprintf(output.stream, " and "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_select); - fprintf(output.stream, " refer to a Content column.%c", f_string_eol_s[0]); - fprintf(output.stream, " The word \"column\" is being loosely defined to refer to a specific Content.%c", f_string_eol_s[0]); - fprintf(output.stream, " This is not to be confused with a depth.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); + funlockfile(output.stream); return F_none; } @@ -208,9 +132,12 @@ extern "C" { if (main->context.set.error.before) { main->error.context = main->context.set.error; main->error.notable = main->context.set.notable; + + main->warning.context = main->context.set.warning; + main->warning.notable = main->context.set.notable; } else { - f_color_set_t *sets[] = { &main->error.context, &main->error.notable, 0 }; + f_color_set_t *sets[] = { &main->error.context, &main->error.notable, &main->warning.context, &main->warning.notable, 0 }; fll_program_parameter_process_empty(&main->context, sets); } @@ -238,15 +165,19 @@ extern "C" { if (choice == fss_basic_list_read_parameter_verbosity_quiet) { main->error.verbosity = f_console_verbosity_quiet; + main->warning.verbosity = f_console_verbosity_quiet; } else if (choice == fss_basic_list_read_parameter_verbosity_normal) { main->error.verbosity = f_console_verbosity_normal; + main->warning.verbosity = f_console_verbosity_normal; } else if (choice == fss_basic_list_read_parameter_verbosity_verbose) { main->error.verbosity = f_console_verbosity_verbose; + main->warning.verbosity = f_console_verbosity_verbose; } else if (choice == fss_basic_list_read_parameter_verbosity_debug) { main->error.verbosity = f_console_verbosity_debug; + main->warning.verbosity = f_console_verbosity_debug; } } @@ -311,9 +242,13 @@ extern "C" { for (f_array_length_t i = 0; i < 6; ++i) { if (main->parameters[parameter_code[i]].result == f_console_result_found) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe parameter '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, parameter_name[i]); - f_color_print(main->error.to.stream, main->context.set.error, "' requires a %s.%c", parameter_message[i], f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, parameter_name[i], main->error.notable); + fl_print_format("%[' requires a %s.%]%c", main->error.to.stream, main->error.context, parameter_message[i], main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); break; @@ -349,11 +284,15 @@ extern "C" { for (f_array_length_t i = 0; i < 5; ++i) { if (main->parameters[parameter_code[i]].result == parameter_match[i]) { - f_color_print(main->error.to.stream, main->context.set.error, "%sCannot specify the '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_columns); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter with the '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, parameter_name[i]); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sCannot specify the '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_columns, main->error.notable); + fl_print_format("%[' parameter with the '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, parameter_name[i], main->error.notable); + fl_print_format("%[' parameter.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); break; @@ -363,20 +302,28 @@ extern "C" { if (F_status_is_error_not(status) && main->parameters[fss_basic_list_read_parameter_pipe].result == f_console_result_found) { if (main->parameters[fss_basic_list_read_parameter_total].result == f_console_result_found) { - f_color_print(main->error.to.stream, main->context.set.error, "%sCannot specify the '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_pipe); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter with the '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_total); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sCannot specify the '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_pipe, main->error.notable); + fl_print_format("%[' parameter with the '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_total, main->error.notable); + fl_print_format("%[' parameter.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); } else if (main->parameters[fss_basic_list_read_parameter_line].result == f_console_result_additional) { - f_color_print(main->error.to.stream, main->context.set.error, "%sCannot specify the '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_pipe); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter with the '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_line); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sCannot specify the '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_pipe, main->error.notable); + fl_print_format("%[' parameter with the '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_line, main->error.notable); + fl_print_format("%[' parameter.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); } @@ -395,9 +342,13 @@ extern "C" { length = strnlen(arguments->argv[location], f_console_parameter_size); if (!length) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe value for the parameter '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_delimit); - f_color_print(main->error.to.stream, main->context.set.error, "' must not be empty.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe value for the parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_delimit, main->error.notable); + fl_print_format("%[' must not be empty.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); break; @@ -524,9 +475,13 @@ extern "C" { } if (F_status_is_error_not(status) && main->parameters[fss_basic_list_read_parameter_select].result == f_console_result_found) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_select); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter requires a positive number.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_select, main->error.notable); + fl_print_format("%[' parameter requires a positive number.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); fss_basic_list_read_depths_resize(0, &data.depths); @@ -642,7 +597,7 @@ extern "C" { fss_basic_list_read_data_delete_simple(&data); } else { - f_color_print(main->error.to.stream, main->context.set.error, "%sYou failed to specify one or more files.%c", fll_error_print_error, f_string_eol_s[0]); + fll_print_format("%c%[%sYou failed to specify one or more files.%]%c", main->error.to.stream, main->error.context, main->error.prefix, main->error.context, f_string_eol_s[0]); status = F_status_set_error(F_parameter); } diff --git a/level_3/fss_basic_list_read/c/fss_basic_list_read.h b/level_3/fss_basic_list_read/c/fss_basic_list_read.h index 57b7c97..f96c249 100644 --- a/level_3/fss_basic_list_read/c/fss_basic_list_read.h +++ b/level_3/fss_basic_list_read/c/fss_basic_list_read.h @@ -43,6 +43,7 @@ #include #include #include +#include #include #ifdef __cplusplus @@ -206,6 +207,7 @@ extern "C" { f_file_t output; fll_error_print_t error; + fll_error_print_t warning; f_color_context_t context; } fss_basic_list_read_main_t; @@ -217,6 +219,7 @@ extern "C" { F_false, \ macro_f_file_t_initialize2(f_type_output, f_type_descriptor_output, f_file_flag_write_only), \ fll_error_print_t_initialize, \ + macro_fll_error_print_t_initialize_warning(), \ f_color_context_t_initialize, \ } #endif // _di_fss_basic_list_read_main_t_ diff --git a/level_3/fss_basic_list_read/c/private-fss_basic_list_read.c b/level_3/fss_basic_list_read/c/private-fss_basic_list_read.c index 225bf4a..802cba1 100644 --- a/level_3/fss_basic_list_read/c/private-fss_basic_list_read.c +++ b/level_3/fss_basic_list_read/c/private-fss_basic_list_read.c @@ -162,9 +162,13 @@ extern "C" { if (!data->depths.array[i].value_name.used) { if (main->error.verbosity != f_console_verbosity_quiet) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_name); - f_color_print(main->error.to.stream, main->context.set.error, "' must not be an empty string.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_name, main->error.notable); + fl_print_format("%[' must not be an empty string.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); } return F_status_set_error(F_parameter); @@ -179,24 +183,32 @@ extern "C" { if (data->depths.array[i].depth == data->depths.array[j].depth) { if (main->error.verbosity != f_console_verbosity_quiet) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe value '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%llu", data->depths.array[i].depth); - f_color_print(main->error.to.stream, main->context.set.error, "' may only be specified once for the parameter '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_depth); - f_color_print(main->error.to.stream, main->context.set.error, "'.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe value '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%ul%]", main->error.to.stream, main->error.notable, data->depths.array[i].depth, main->error.notable); + fl_print_format("%[' may only be specified once for the parameter '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_depth, main->error.notable); + fl_print_format("%['.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); } return F_status_set_error(F_parameter); } else if (data->depths.array[i].depth > data->depths.array[j].depth) { if (main->error.verbosity != f_console_verbosity_quiet) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe parameter '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_list_read_long_depth); - f_color_print(main->error.to.stream, main->context.set.error, "' may not have the value '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%llu", data->depths.array[i].depth); - f_color_print(main->error.to.stream, main->context.set.error, "' before the value '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%llu", data->depths.array[j].depth); - f_color_print(main->error.to.stream, main->context.set.error, "'.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_basic_list_read_long_depth, main->error.notable); + fl_print_format("%[' may not have the value '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%ul%]", main->error.to.stream, main->error.notable, data->depths.array[i].depth, main->error.notable); + fl_print_format("%[' before the value '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%ul%]", main->error.to.stream, main->error.notable, data->depths.array[j].depth, main->error.notable); + fl_print_format("%['.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); } return F_status_set_error(F_parameter); @@ -242,8 +254,12 @@ extern "C" { } else if (status == F_data_not_stop || status == F_data_not_eos) { if (data->option & fss_basic_list_read_data_option_total) { + flockfile(main->output.stream); + fss_basic_list_read_print_zero(main); + funlockfile(main->output.stream); + return F_none; } @@ -284,12 +300,14 @@ extern "C" { } if ((data->option & fss_basic_list_read_data_option_object) || (data->option & fss_basic_list_read_data_option_content) && (data->contents.array[at].used || (data->option & fss_basic_list_read_data_option_empty))) { + flockfile(main->output.stream); + if (data->option & fss_basic_list_read_data_option_object) { if (data->option & fss_basic_list_read_data_option_trim) { - fl_print_trim_except_in_dynamic_partial(main->output.stream, data->buffer, data->objects.array[at], delimits_object, data->comments); + fl_print_trim_except_in_dynamic_partial(data->buffer, data->objects.array[at], delimits_object, data->comments, main->output.stream); } else { - f_print_except_in_dynamic_partial(main->output.stream, data->buffer, data->objects.array[at], delimits_object, data->comments); + f_print_except_in_dynamic_partial(data->buffer, data->objects.array[at], delimits_object, data->comments, main->output.stream); } fss_basic_list_read_print_object_end(main); @@ -298,12 +316,16 @@ extern "C" { if (data->option & fss_basic_list_read_data_option_content) { if (data->contents.array[at].used) { fss_basic_list_read_print_content_ignore(main); - f_print_except_in_dynamic_partial(main->output.stream, data->buffer, data->contents.array[at].array[0], delimits_content, data->comments); + + f_print_except_in_dynamic_partial(data->buffer, data->contents.array[at].array[0], delimits_content, data->comments, main->output.stream); + fss_basic_list_read_print_content_ignore(main); } } fss_basic_list_read_print_set_end(main); + + funlockfile(main->output.stream); } } #endif // _di_fss_basic_list_read_print_at_ @@ -316,10 +338,10 @@ extern "C" { } if (data->option & fss_basic_list_read_data_option_trim) { - fl_print_trim_except_dynamic_partial(main->output.stream, data->buffer, data->objects.array[at], delimits_object); + fl_print_trim_except_dynamic_partial(data->buffer, data->objects.array[at], delimits_object, main->output.stream); } else { - f_print_except_dynamic_partial(main->output.stream, data->buffer, data->objects.array[at], delimits_object); + f_print_except_dynamic_partial(data->buffer, data->objects.array[at], delimits_object, main->output.stream); } fss_basic_list_read_print_object_end(main); @@ -330,7 +352,7 @@ extern "C" { void fss_basic_list_read_print_content_ignore(fss_basic_list_read_main_t * const main) { if (main->parameters[fss_basic_list_read_parameter_pipe].result == f_console_result_found) { - fprintf(main->output.stream, "%c", fss_basic_list_read_pipe_content_ignore); + f_print_character(fss_basic_list_read_pipe_content_ignore, main->output.stream); } } #endif // _di_fss_basic_list_read_print_content_ignore_ @@ -339,14 +361,15 @@ extern "C" { void fss_basic_list_read_print_object_end(fss_basic_list_read_main_t * const main) { if (main->parameters[fss_basic_list_read_parameter_pipe].result == f_console_result_found) { - fprintf(main->output.stream, "%c", fss_basic_list_read_pipe_content_start); + f_print_character(fss_basic_list_read_pipe_content_start, main->output.stream); } else { if (main->parameters[fss_basic_list_read_parameter_content].result == f_console_result_found) { - fprintf(main->output.stream, "%c%c", f_fss_basic_list_open, f_fss_basic_list_open_end); + f_print_character(f_fss_basic_list_open, main->output.stream); + f_print_character(f_fss_basic_list_open_end, main->output.stream); } else { - fprintf(main->output.stream, "%c", f_fss_eol); + f_print_character(f_fss_eol, main->output.stream); } } } @@ -356,20 +379,22 @@ extern "C" { void fss_basic_list_read_print_set_end(fss_basic_list_read_main_t * const main) { if (main->parameters[fss_basic_list_read_parameter_pipe].result == f_console_result_found) { - fprintf(main->output.stream, "%c", fss_basic_list_read_pipe_content_end); + f_print_character(fss_basic_list_read_pipe_content_end, main->output.stream); } } #endif // _di_fss_basic_list_read_print_set_end_ #ifndef _di_fss_basic_list_read_print_one_ void fss_basic_list_read_print_one(fss_basic_list_read_main_t * const main) { - fprintf(main->output.stream, "1%c", f_string_eol_s[0]); + f_print_character(f_string_ascii_1_s[0], main->output.stream); + f_print_character(f_string_eol_s[0], main->output.stream); } #endif // _di_fss_basic_list_read_print_one_ #ifndef _di_fss_basic_list_read_print_zero_ void fss_basic_list_read_print_zero(fss_basic_list_read_main_t * const main) { - fprintf(main->output.stream, "0%c", f_string_eol_s[0]); + f_print_character(f_string_ascii_0_s[0], main->output.stream); + f_print_character(f_string_eol_s[0], main->output.stream); } #endif // _di_fss_basic_list_read_print_zero_ @@ -382,7 +407,11 @@ extern "C" { // This standard does not support multiple content groups. if ((data->option & fss_basic_list_read_data_option_select) && data->select) { if (main->parameters[fss_basic_list_read_parameter_total].result == f_console_result_found) { + flockfile(main->output.stream); + fss_basic_list_read_print_zero(main); + + funlockfile(main->output.stream); } return F_none; @@ -432,7 +461,11 @@ extern "C" { if (data->depths.array[0].value_at >= data->objects.used) { if (data->option & (fss_basic_list_read_data_option_columns | fss_basic_list_read_data_option_total)) { + flockfile(main->output.stream); + fss_basic_list_read_print_zero(main); + + funlockfile(main->output.stream); } return F_none; @@ -457,15 +490,19 @@ extern "C" { if (status == F_success) return F_none; } else if (data->option & fss_basic_list_read_data_option_columns) { - fprintf(main->output.stream, "%llu%c", data->contents.array[i].used, f_string_eol_s[0]); + fll_print_format("%ul%c", main->output.stream, data->contents.array[i].used, f_string_eol_s[0]); } else if (data->option & fss_basic_list_read_data_option_total) { + flockfile(main->output.stream); + if (data->contents.array[i].used) { fss_basic_list_read_print_one(main); } else { fss_basic_list_read_print_zero(main); } + + funlockfile(main->output.stream); } else { fss_basic_list_read_print_at(i, *delimits_object, *delimits_content, main, data); @@ -478,7 +515,11 @@ extern "C" { } // for if (data->option & fss_basic_list_read_data_option_total) { + flockfile(main->output.stream); + fss_basic_list_read_print_zero(main); + + funlockfile(main->output.stream); } return F_none; @@ -489,8 +530,12 @@ extern "C" { f_status_t fss_basic_list_read_process_columns(fss_basic_list_read_main_t * const main, fss_basic_list_read_data_t *data, bool names[]) { if (!(data->option & fss_basic_list_read_data_option_content)) { + flockfile(main->output.stream); + fss_basic_list_read_print_zero(main); + funlockfile(main->output.stream); + return F_none; } @@ -505,7 +550,7 @@ extern "C" { } } // for - fprintf(main->output.stream, "%llu%c", max, f_string_eol_s[0]); + fll_print_format("%ul%c", main->output.stream, max, f_string_eol_s[0]); return F_none; } @@ -516,6 +561,8 @@ extern "C" { if (data->option & fss_basic_list_read_data_option_object) { if (*line == data->line) { + flockfile(main->output.stream); + if (data->option & fss_basic_list_read_data_option_total) { fss_basic_list_read_print_one(main); } @@ -523,6 +570,8 @@ extern "C" { fss_basic_list_read_print_at_object(main, data, at, delimits_object); } + funlockfile(main->output.stream); + return F_success; } @@ -552,13 +601,17 @@ extern "C" { if (*line == data->line) { range.stop = i; + flockfile(main->output.stream); + if (data->option & fss_basic_list_read_data_option_total) { fss_basic_list_read_print_one(main); } else { - f_print_except_in_dynamic_partial(main->output.stream, data->buffer, range, delimits_content, data->comments); + f_print_except_in_dynamic_partial(data->buffer, range, delimits_content, data->comments, main->output.stream); } + funlockfile(main->output.stream); + return F_success; } @@ -575,16 +628,21 @@ extern "C" { ++(*line); if (*line == data->line) { + flockfile(main->output.stream); + if (data->option & fss_basic_list_read_data_option_total) { fss_basic_list_read_print_one(main); } else { range.stop = data->contents.array[at].array[0].stop; - f_print_except_in_dynamic_partial(main->output.stream, data->buffer, range, delimits_content, data->comments); - fprintf(main->output.stream, "%c", f_string_eol_s[0]); + //f_print_except_in_dynamic_partial(main->output.stream, data->buffer, range, delimits_content, data->comments); + //f_print_character(f_string_eol_s[0], main->output.stream); + fl_print_format("%/:;Q%c", main->output.stream, data->buffer, range, delimits_content, data->comments, f_string_eol_s[0]); } + funlockfile(main->output.stream); + return F_success; } } @@ -748,6 +806,8 @@ extern "C" { } } // for + flockfile(main->output.stream); + if (data->option & fss_basic_list_read_data_option_line) { if (data->line < total) { fss_basic_list_read_print_one(main); @@ -757,9 +817,11 @@ extern "C" { } } else { - fprintf(main->output.stream, "%llu%c", total, f_string_eol_s[0]); + fl_print_format("%ul%c", main->output.stream, total, f_string_eol_s[0]); } + funlockfile(main->output.stream); + return F_none; } #endif // _di_fss_basic_list_read_process_total_ diff --git a/level_3/fss_basic_list_read/data/build/dependencies b/level_3/fss_basic_list_read/data/build/dependencies index cc1beee..7c8767f 100644 --- a/level_3/fss_basic_list_read/data/build/dependencies +++ b/level_3/fss_basic_list_read/data/build/dependencies @@ -23,4 +23,5 @@ fl_string fll_error fll_file fll_fss +fll_print fll_program diff --git a/level_3/fss_basic_list_read/data/build/settings b/level_3/fss_basic_list_read/data/build/settings index 4d0978d..a7a1699 100644 --- a/level_3/fss_basic_list_read/data/build/settings +++ b/level_3/fss_basic_list_read/data/build/settings @@ -20,7 +20,7 @@ build_compiler gcc build_indexer ar build_language c build_libraries -lc -build_libraries-individual -lfll_error -lfll_file -lfll_fss -lfll_program -lfl_console -lfl_conversion -lfl_directory -lfl_fss -lfl_print -lfl_status -lfl_string -lf_color -lf_console -lf_conversion -lf_directory -lf_environment -lf_file -lf_fss -lf_memory -lf_path -lf_pipe -lf_print -lf_string -lf_type_array -lf_utf +build_libraries-individual -lfll_error -lfll_file -lfll_fss -lfll_print -lfll_program -lfl_console -lfl_conversion -lfl_directory -lfl_fss -lfl_print -lfl_status -lfl_string -lf_color -lf_console -lf_conversion -lf_directory -lf_environment -lf_file -lf_fss -lf_memory -lf_path -lf_pipe -lf_print -lf_string -lf_type_array -lf_utf build_libraries-level -lfll_2 -lfll_1 -lfll_0 build_libraries-monolithic -lfll build_sources_library fss_basic_list_read.c private-common.c private-fss_basic_list_read.c @@ -51,7 +51,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_3/fss_basic_read/c/fss_basic_read.c b/level_3/fss_basic_read/c/fss_basic_read.c index 0d3a8f2..7ae6323 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.c +++ b/level_3/fss_basic_read/c/fss_basic_read.c @@ -9,6 +9,8 @@ extern "C" { #ifndef _di_fss_basic_read_print_help_ f_status_t fss_basic_read_print_help(const f_file_t output, const f_color_context_t context) { + flockfile(output.stream); + fll_program_print_help_header(output, context, fss_basic_read_name_long, fss_basic_read_version); fll_program_print_help_option(output, context, f_console_standard_short_help_s, f_console_standard_long_help_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Print this help message."); @@ -21,7 +23,7 @@ extern "C" { fll_program_print_help_option(output, context, f_console_standard_short_debug_s, f_console_standard_long_debug_s, f_console_symbol_short_disable_s, f_console_symbol_long_disable_s, " Enable debugging, inceasing verbosity beyond normal output."); fll_program_print_help_option(output, context, f_console_standard_short_version_s, f_console_standard_long_version_s, f_console_symbol_short_disable_s, f_console_symbol_long_disable_s, " Print only the version number."); - fprintf(output.stream, "%c", f_string_eol_s[0]); + f_print_character(f_string_eol_s[0], output.stream); fll_program_print_help_option(output, context, fss_basic_read_short_at, fss_basic_read_long_at, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Select Object at this numeric index."); fll_program_print_help_option(output, context, fss_basic_read_short_content, fss_basic_read_long_content, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Print the Content (default)."); @@ -39,153 +41,75 @@ extern "C" { fll_program_print_help_usage(output, context, fss_basic_read_name, "filename(s)"); - f_color_print(output.stream, context.set.important, " Notes:"); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " This program will print the Content associated with the given Object and Content main based on the FSS-0000 Basic standard.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " All numeric positions (indexes) start at 0 instead of 1.%c", f_string_eol_s[0]); - fprintf(output.stream, " For example, a file of 17 lines would range from 0 to 16.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" %[Notes:%]%c", output.stream, context.set.important, context.set.important, f_string_eol_s[0]); - fprintf(output.stream, " When using the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_depth); - fprintf(output.stream, " option, an order of operations is enforced on the parameters.%c", f_string_eol_s[0]); + fl_print_format(" This program will print the Content associated with the given Object and Content main based on the FSS-0000 Basic standard.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " When this order of operations is in effect, parameters to the right of a depth parameter are influenced by that depth parameter:%c", f_string_eol_s[0]); + fl_print_format(" All numeric positions (indexes) start at 0 instead of 1.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" For example, a file of 17 lines would range from 0 to 16.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_at); - fprintf(output.stream, ": An Object index at the specified depth.%c", f_string_eol_s[0]); + fl_print_format(" When using the %[%s%s%] option, an order of operations is enforced on the parameters.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_depth, context.set.notable, f_string_eol_s[0]); - fprintf(output.stream, " "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_depth); - fprintf(output.stream, ": A new depth within the specified depth, indexed from the root.%c", f_string_eol_s[0]); + fl_print_format(" When this order of operations is in effect, parameters to the right of a depth parameter are influenced by that depth parameter:%c", output.stream, f_string_eol_s[0]); - fprintf(output.stream, " "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_name); - fprintf(output.stream, ": An Object name at the specified depth.%c", f_string_eol_s[0]); + fl_print_format(" %[%s%s%]: An Object index at the specified depth.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_at, context.set.notable, f_string_eol_s[0]); + fl_print_format(" %[%s%s%]: A new depth within the specified depth, indexed from the root.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_depth, context.set.notable, f_string_eol_s[0]); + fl_print_format(" %[%s%s%]: An Object name at the specified depth.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_name, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" The parameter %[%s%s%] must be in numeric order, but values in between may be skipped.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_depth, context.set.notable, f_string_eol_s[0]); + fl_print_format(" ('-d 0 -a 1 -d 2 -a 2' would specify index 1 at depth 0, any index at depth 1, and index 2 at depth 2.)%c", output.stream, f_string_eol_s[0]); + fl_print_format(" ('-d 2 -a 1 -d 0 -a 2' would be invalid because depth 2 is before depth 1.)%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " The parameter "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_depth); - fprintf(output.stream, " must be in numeric order, but values in between may be skipped.%c", f_string_eol_s[0]); - fprintf(output.stream, " ('-d 0 -a 1 -d 2 -a 2' would specify index 1 at depth 0, any index at depth 1, and index 2 at depth 2.)%c", f_string_eol_s[0]); - fprintf(output.stream, " ('-d 2 -a 1 -d 0 -a 2' would be invalid because depth 2 is before depth 1.)%c", f_string_eol_s[0]); + fl_print_format(" The parameter %[%s%s%] selects a Content column.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_select, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" Specify both %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_object, context.set.notable); + fl_print_format(" and the %[%s%s%] parameters to get the total objects.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_total, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " The parameter "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_select); - fprintf(output.stream, " selects a Content column.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " Specify both "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_object); - fprintf(output.stream, " and the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_total); - fprintf(output.stream, " parameters to get the total objects.%c", f_string_eol_s[0]); + fl_print_format(" When both %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_at, context.set.notable); + fl_print_format(" and %[%s%s%] parameters are specified (at the same depth),", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_name, context.set.notable); + fl_print_format(" the %[%s%s%] parameter value will be treated as a position relative to the specified", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_at, context.set.notable); + fl_print_format(" %[%s%s%] parameter value.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_name, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" This program may support parameters, such as %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_depth, context.set.notable); + fl_print_format(" or %[%s%s%], even if not supported by the standard.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_select, context.set.notable, f_string_eol_s[0]); + fl_print_format(" This is done to help ensure consistency for scripting.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " When both "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_at); - fprintf(output.stream, " and "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_name); - fprintf(output.stream, " parameters are specified (at the same depth), the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_at); - fprintf(output.stream, " parameter value will be treated as a position relative to the specified "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_name); - fprintf(output.stream, " parameter value.%c", f_string_eol_s[0]); + fl_print_format(" For parameters like %[%s%s%],", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_depth, context.set.notable); + fl_print_format(" if the standard doesn't support nested Content, then only a depth of 0 would be valid.%c", output.stream, f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" For parameters like %[%s%s%],", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_select, context.set.notable); + fl_print_format(" if the standard doesn't support multiple Content groups, then only a select of 0 would be valid.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " This program may support parameters, such as "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_depth); - fprintf(output.stream, " or "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_select); - fprintf(output.stream, ", even if not supported by the standard.%c", f_string_eol_s[0]); - fprintf(output.stream, " This is done to help ensure consistency for scripting.%c", f_string_eol_s[0]); + fl_print_format(" The parameter %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_trim, context.set.notable); + fl_print_format(" will remove leading and trailing whitespaces when selecting objects or when printing objects.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" When specifying both the %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_object, context.set.notable); + fl_print_format(" parameter and the %[%s%s%] parameter, the entire Object and Content are printed, including the formatting.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_content, context.set.notable, f_string_eol_s[0]); + fl_print_format(" Both the Object and Content printed are already escaped.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" Both the Object and Content are separated by a space.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " For parameters like "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_depth); - fprintf(output.stream, ", if the standard doesn't support nested Content, then only a depth of 0 would be valid.%c", f_string_eol_s[0]); + fl_print_format(" The parameter %[%s%s%] accepts the following:%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_delimit, context.set.notable, f_string_eol_s[0]); + fl_print_format(" - %[%s%]: Do not apply delimits.%c", output.stream, context.set.notable, fss_basic_read_delimit_mode_name_none, context.set.notable, f_string_eol_s[0]); + fl_print_format(" - %[%s%]: (default) Apply all delimits.%c", output.stream, context.set.notable, fss_basic_read_delimit_mode_name_all, context.set.notable, f_string_eol_s[0]); + fl_print_format(" - %[%s%]: Apply delimits for Objects.%c", output.stream, context.set.notable, fss_basic_read_delimit_mode_name_object, context.set.notable, f_string_eol_s[0]); + fl_print_format(" - A number, 0 or greater: apply delimits for Content at the specified depth.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" - A number, 0 or greater, followed by a %[%s%]: (such as '1+') apply delimits for Content at the specified depth and any greater depth (numerically).%c", output.stream, context.set.notable, fss_basic_read_delimit_mode_name_greater, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); + fl_print_format(" - A number, 0 or lesser, followed by a %[%s%]: (such as '1-') apply delimits for Content at the specified depth and any lesser depth (numerically).%c%c", output.stream, context.set.notable, fss_basic_read_delimit_mode_name_lesser, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " For parameters like "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_select); - fprintf(output.stream, ", if the standard doesn't support multiple Content groups, then only a select of 0 would be valid.%c", f_string_eol_s[0]); + fl_print_format(" The %[%s%s%] parameter may be specified multiple times to customize the delimit behavior.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_delimit, context.set.notable, f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" The %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_delimit, context.set.notable); + fl_print_format(" values %[%s%]", output.stream, context.set.notable, fss_basic_read_delimit_mode_name_none, context.set.notable); + fl_print_format(" and %[%s%],", output.stream, context.set.notable, fss_basic_read_delimit_mode_name_all, context.set.notable); + fl_print_format(" overrule all other delimit values.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " The parameter "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_trim); - fprintf(output.stream, " will remove leading and trailing whitespaces when selecting objects or when printing objects.%c", f_string_eol_s[0]); + fl_print_format(" The parameters %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_columns, context.set.notable); + fl_print_format(" and %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_basic_read_long_select, context.set.notable); + fl_print_format(" refer to a Content column.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" The word \"column\" is being loosely defined to refer to a specific Content.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" This is not to be confused with a depth.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " When specifying both the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_object); - fprintf(output.stream, " parameter and the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_content); - fprintf(output.stream, " parameter, the entire Object and Content are printed, including the formatting.%c", f_string_eol_s[0]); - fprintf(output.stream, " Both the Object and Content printed are already escaped.%c", f_string_eol_s[0]); - fprintf(output.stream, " Both the Object and Content are separated by a space.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " The parameter "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_delimit); - fprintf(output.stream, " accepts the following:%c", f_string_eol_s[0]); - fprintf(output.stream, " - "); - f_color_print(output.stream, context.set.notable, "%s", fss_basic_read_delimit_mode_name_none); - fprintf(output.stream, ": Do not apply delimits.%c", f_string_eol_s[0]); - fprintf(output.stream, " - "); - f_color_print(output.stream, context.set.notable, "%s", fss_basic_read_delimit_mode_name_all); - fprintf(output.stream, ": (default) Apply all delimits.%c", f_string_eol_s[0]); - fprintf(output.stream, " - "); - f_color_print(output.stream, context.set.notable, "%s", fss_basic_read_delimit_mode_name_object); - fprintf(output.stream, ": Apply delimits for Objects.%c", f_string_eol_s[0]); - fprintf(output.stream, " - A number, 0 or greater: apply delimits for Content at the specified depth.%c", f_string_eol_s[0]); - fprintf(output.stream, " - A number, 0 or greater, followed by a "); - f_color_print(output.stream, context.set.notable, "%s", fss_basic_read_delimit_mode_name_greater); - fprintf(output.stream, ": (such as '1+') apply delimits for Content at the specified depth and any greater depth (numerically).%c", f_string_eol_s[0]); - fprintf(output.stream, " - A number, 0 or greater, followed by a "); - f_color_print(output.stream, context.set.notable, "%s", fss_basic_read_delimit_mode_name_lesser); - fprintf(output.stream, ": (such as '1-') apply delimits for Content at the specified depth and any lesser depth (numerically).%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " The "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_delimit); - fprintf(output.stream, " parameter may be specified multiple times to customize the delimit behavior.%c", f_string_eol_s[0]); - - fprintf(output.stream, " The "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_delimit); - fprintf(output.stream, " values "); - f_color_print(output.stream, context.set.notable, "%s", fss_basic_read_delimit_mode_name_none); - fprintf(output.stream, " and "); - f_color_print(output.stream, context.set.notable, "%s", fss_basic_read_delimit_mode_name_all); - fprintf(output.stream, ", overrule all other delimit values.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " The parameters "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_columns); - fprintf(output.stream, " and "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_select); - fprintf(output.stream, " refer to a Content column.%c", f_string_eol_s[0]); - fprintf(output.stream, " The word \"column\" is being loosely defined to refer to a specific Content.%c", f_string_eol_s[0]); - fprintf(output.stream, " This is not to be confused with a depth.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); + funlockfile(output.stream); return F_none; } @@ -208,9 +132,12 @@ extern "C" { if (main->context.set.error.before) { main->error.context = main->context.set.error; main->error.notable = main->context.set.notable; + + main->warning.context = main->context.set.warning; + main->warning.notable = main->context.set.notable; } else { - f_color_set_t *sets[] = { &main->error.context, &main->error.notable, 0 }; + f_color_set_t *sets[] = { &main->error.context, &main->error.notable, &main->warning.context, &main->warning.notable, 0 }; fll_program_parameter_process_empty(&main->context, sets); } @@ -238,15 +165,19 @@ extern "C" { if (choice == fss_basic_read_parameter_verbosity_quiet) { main->error.verbosity = f_console_verbosity_quiet; + main->warning.verbosity = f_console_verbosity_quiet; } else if (choice == fss_basic_read_parameter_verbosity_normal) { main->error.verbosity = f_console_verbosity_normal; + main->warning.verbosity = f_console_verbosity_normal; } else if (choice == fss_basic_read_parameter_verbosity_verbose) { main->error.verbosity = f_console_verbosity_verbose; + main->warning.verbosity = f_console_verbosity_verbose; } else if (choice == fss_basic_read_parameter_verbosity_debug) { main->error.verbosity = f_console_verbosity_debug; + main->warning.verbosity = f_console_verbosity_debug; } } @@ -311,9 +242,13 @@ extern "C" { for (f_array_length_t i = 0; i < 6; ++i) { if (main->parameters[parameter_code[i]].result == f_console_result_found) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe parameter '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, parameter_name[i]); - f_color_print(main->error.to.stream, main->context.set.error, "' requires a %s.%c", parameter_message[i], f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, parameter_name[i], main->error.notable); + fl_print_format("%[' requires a %s.%]%c", main->error.to.stream, main->error.context, parameter_message[i], main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); break; @@ -349,11 +284,15 @@ extern "C" { for (f_array_length_t i = 0; i < 5; ++i) { if (main->parameters[parameter_code[i]].result == parameter_match[i]) { - f_color_print(main->error.to.stream, main->context.set.error, "%sCannot specify the '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_columns); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter with the '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, parameter_name[i]); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sCannot specify the '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_basic_read_long_columns, main->error.notable); + fl_print_format("%[' parameter with the '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, parameter_name[i], main->error.notable); + fl_print_format("%[' parameter.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); break; @@ -363,20 +302,28 @@ extern "C" { if (F_status_is_error_not(status) && main->parameters[fss_basic_read_parameter_pipe].result == f_console_result_found) { if (main->parameters[fss_basic_read_parameter_total].result == f_console_result_found) { - f_color_print(main->error.to.stream, main->context.set.error, "%sCannot specify the '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_pipe); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter with the '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_total); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sCannot specify the '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_basic_read_long_pipe, main->error.notable); + fl_print_format("%[' parameter with the '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_basic_read_long_total, main->error.notable); + fl_print_format("%[' parameter.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); } else if (main->parameters[fss_basic_read_parameter_line].result == f_console_result_additional) { - f_color_print(main->error.to.stream, main->context.set.error, "%sCannot specify the '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_pipe); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter with the '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_line); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sCannot specify the '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_basic_read_long_pipe, main->error.notable); + fl_print_format("%[' parameter with the '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_basic_read_long_line, main->error.notable); + fl_print_format("%[' parameter.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); } @@ -395,9 +342,13 @@ extern "C" { length = strnlen(arguments->argv[location], f_console_parameter_size); if (!length) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe value for the parameter '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_delimit); - f_color_print(main->error.to.stream, main->context.set.error, "' must not be empty.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe value for the parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_basic_read_long_delimit, main->error.notable); + fl_print_format("%[' must not be empty.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); break; @@ -524,9 +475,13 @@ extern "C" { } if (F_status_is_error_not(status) && main->parameters[fss_basic_read_parameter_select].result == f_console_result_found) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_select); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter requires a positive number.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_basic_read_long_select, main->error.notable); + fl_print_format("%[' parameter requires a positive number.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); fss_basic_read_depths_resize(0, &data.depths); @@ -642,7 +597,7 @@ extern "C" { fss_basic_read_data_delete_simple(&data); } else { - f_color_print(main->error.to.stream, main->context.set.error, "%sYou failed to specify one or more files.%c", fll_error_print_error, f_string_eol_s[0]); + fll_print_format("%c%[%sYou failed to specify one or more files.%]%c", main->error.to.stream, main->error.context, main->error.prefix, main->error.context, f_string_eol_s[0]); status = F_status_set_error(F_parameter); } diff --git a/level_3/fss_basic_read/c/fss_basic_read.h b/level_3/fss_basic_read/c/fss_basic_read.h index c9ad689..d5bb89c 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.h +++ b/level_3/fss_basic_read/c/fss_basic_read.h @@ -43,6 +43,7 @@ #include #include #include +#include #include #ifdef __cplusplus @@ -206,6 +207,7 @@ extern "C" { f_file_t output; fll_error_print_t error; + fll_error_print_t warning; f_color_context_t context; } fss_basic_read_main_t; @@ -217,6 +219,7 @@ extern "C" { F_false, \ macro_f_file_t_initialize2(f_type_output, f_type_descriptor_output, f_file_flag_write_only), \ fll_error_print_t_initialize, \ + macro_fll_error_print_t_initialize_warning(), \ f_color_context_t_initialize, \ } #endif // _di_fss_basic_read_main_t_ diff --git a/level_3/fss_basic_read/c/private-fss_basic_read.c b/level_3/fss_basic_read/c/private-fss_basic_read.c index f3f3a2e..0b3542f 100644 --- a/level_3/fss_basic_read/c/private-fss_basic_read.c +++ b/level_3/fss_basic_read/c/private-fss_basic_read.c @@ -139,9 +139,13 @@ extern "C" { if (!data->depths.array[i].value_name.used) { if (main->error.verbosity != f_console_verbosity_quiet) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_name); - f_color_print(main->error.to.stream, main->context.set.error, "' must not be an empty string.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_basic_read_long_name, main->error.notable); + fl_print_format("%[' must not be an empty string.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); } return F_status_set_error(F_parameter); @@ -156,24 +160,32 @@ extern "C" { if (data->depths.array[i].depth == data->depths.array[j].depth) { if (main->error.verbosity != f_console_verbosity_quiet) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe value '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%llu", data->depths.array[i].depth); - f_color_print(main->error.to.stream, main->context.set.error, "' may only be specified once for the parameter '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_depth); - f_color_print(main->error.to.stream, main->context.set.error, "'.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe value '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%ul%]", main->error.to.stream, main->error.notable, data->depths.array[i].depth, main->error.notable); + fl_print_format("%[' may only be specified once for the parameter '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_basic_read_long_depth, main->error.notable); + fl_print_format("%['.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); } return F_status_set_error(F_parameter); } else if (data->depths.array[i].depth > data->depths.array[j].depth) { if (main->error.verbosity != f_console_verbosity_quiet) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe parameter '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_depth); - f_color_print(main->error.to.stream, main->context.set.error, "' may not have the value '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%llu", data->depths.array[i].depth); - f_color_print(main->error.to.stream, main->context.set.error, "' before the value '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%llu", data->depths.array[j].depth); - f_color_print(main->error.to.stream, main->context.set.error, "'.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_basic_read_long_depth, main->error.notable); + fl_print_format("%[' may not have the value '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%ul%]", main->error.to.stream, main->error.notable, data->depths.array[i].depth, main->error.notable); + fl_print_format("%[' before the value '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%ul%]", main->error.to.stream, main->error.notable, data->depths.array[j].depth, main->error.notable); + fl_print_format("%['.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); } return F_status_set_error(F_parameter); @@ -260,12 +272,14 @@ extern "C" { } if ((data->option & fss_basic_read_data_option_object) || (data->option & fss_basic_read_data_option_content) && (data->contents.array[at].used || (data->option & fss_basic_read_data_option_empty))) { + flockfile(main->output.stream); + if (data->option & fss_basic_read_data_option_object) { if (data->option & fss_basic_read_data_option_trim) { - fl_print_trim_except_dynamic_partial(main->output.stream, data->buffer, data->objects.array[at], delimits_object); + fl_print_trim_except_dynamic_partial(data->buffer, data->objects.array[at], delimits_object, main->output.stream); } else { - f_print_except_dynamic_partial(main->output.stream, data->buffer, data->objects.array[at], delimits_object); + f_print_except_dynamic_partial(data->buffer, data->objects.array[at], delimits_object, main->output.stream); } if (data->option & fss_basic_read_data_option_content) { @@ -274,10 +288,12 @@ extern "C" { } if ((data->option & fss_basic_read_data_option_content) && data->contents.array[at].used) { - f_print_except_dynamic_partial(main->output.stream, data->buffer, data->contents.array[at].array[0], delimits_content); + f_print_except_dynamic_partial(data->buffer, data->contents.array[at].array[0], delimits_content, main->output.stream); } fss_basic_read_print_set_end(main); + + funlockfile(main->output.stream); } } #endif // _di_fss_basic_read_print_at_ @@ -286,17 +302,18 @@ extern "C" { void fss_basic_read_print_object_end(fss_basic_read_main_t * const main) { if (main->parameters[fss_basic_read_parameter_pipe].result == f_console_result_found) { - fprintf(main->output.stream, "%c", fss_basic_read_pipe_content_start); + f_print_character(fss_basic_read_pipe_content_start, main->output.stream); } else { - fprintf(main->output.stream, "%c", f_fss_space); + f_print_character(f_fss_space, main->output.stream); } } #endif // _di_fss_basic_read_print_object_end_ #ifndef _di_fss_basic_read_print_one_ void fss_basic_read_print_one(fss_basic_read_main_t * const main) { - fprintf(main->output.stream, "1%c", f_string_eol_s[0]); + f_print_character(f_string_ascii_1_s[0], main->output.stream); + f_print_character(f_string_eol_s[0], main->output.stream); } #endif // _di_fss_basic_read_print_one_ @@ -304,17 +321,18 @@ extern "C" { void fss_basic_read_print_set_end(fss_basic_read_main_t * const main) { if (main->parameters[fss_basic_read_parameter_pipe].result == f_console_result_found) { - fprintf(main->output.stream, "%c", fss_basic_read_pipe_content_end); + f_print_character(fss_basic_read_pipe_content_end, main->output.stream); } else { - fprintf(main->output.stream, "%c", f_fss_eol); + f_print_character(f_string_eol_s[0], main->output.stream); } } #endif // _di_fss_basic_read_print_set_end_ #ifndef _di_fss_basic_read_print_zero_ void fss_basic_read_print_zero(fss_basic_read_main_t * const main) { - fprintf(main->output.stream, "0%c", f_string_eol_s[0]); + f_print_character(f_string_ascii_0_s[0], main->output.stream); + f_print_character(f_string_eol_s[0], main->output.stream); } #endif // _di_fss_basic_read_print_zero_ diff --git a/level_3/fss_basic_read/data/build/dependencies b/level_3/fss_basic_read/data/build/dependencies index cc1beee..7c8767f 100644 --- a/level_3/fss_basic_read/data/build/dependencies +++ b/level_3/fss_basic_read/data/build/dependencies @@ -23,4 +23,5 @@ fl_string fll_error fll_file fll_fss +fll_print fll_program diff --git a/level_3/fss_basic_read/data/build/settings b/level_3/fss_basic_read/data/build/settings index 51234bf..941cf50 100644 --- a/level_3/fss_basic_read/data/build/settings +++ b/level_3/fss_basic_read/data/build/settings @@ -20,7 +20,7 @@ build_compiler gcc build_indexer ar build_language c build_libraries -lc -build_libraries-individual -lfll_error -lfll_file -lfll_fss -lfll_program -lfl_console -lfl_conversion -lfl_directory -lfl_fss -lfl_print -lfl_status -lfl_string -lf_color -lf_console -lf_conversion -lf_directory -lf_environment -lf_file -lf_fss -lf_memory -lf_path -lf_pipe -lf_print -lf_string -lf_type_array -lf_utf +build_libraries-individual -lfll_error -lfll_file -lfll_fss -lfll_print -lfll_program -lfl_console -lfl_conversion -lfl_directory -lfl_fss -lfl_print -lfl_status -lfl_string -lf_color -lf_console -lf_conversion -lf_directory -lf_environment -lf_file -lf_fss -lf_memory -lf_path -lf_pipe -lf_print -lf_string -lf_type_array -lf_utf build_libraries-level -lfll_2 -lfll_1 -lfll_0 build_libraries-monolithic -lfll build_sources_library fss_basic_read.c private-common.c private-fss_basic_read.c @@ -51,7 +51,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_3/fss_embedded_list_read/c/fss_embedded_list_read.c b/level_3/fss_embedded_list_read/c/fss_embedded_list_read.c index 26f4043..7e601f6 100644 --- a/level_3/fss_embedded_list_read/c/fss_embedded_list_read.c +++ b/level_3/fss_embedded_list_read/c/fss_embedded_list_read.c @@ -9,6 +9,8 @@ extern "C" { #ifndef _di_fss_embedded_list_read_print_help_ f_status_t fss_embedded_list_read_print_help(const f_file_t output, const f_color_context_t context) { + flockfile(output.stream); + fll_program_print_help_header(output, context, fss_embedded_list_read_name_long, fss_embedded_list_read_version); fll_program_print_help_option(output, context, f_console_standard_short_help_s, f_console_standard_long_help_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Print this help message."); @@ -21,7 +23,7 @@ extern "C" { fll_program_print_help_option(output, context, f_console_standard_short_debug_s, f_console_standard_long_debug_s, f_console_symbol_short_disable_s, f_console_symbol_long_disable_s, " Enable debugging, inceasing verbosity beyond normal output."); fll_program_print_help_option(output, context, f_console_standard_short_version_s, f_console_standard_long_version_s, f_console_symbol_short_disable_s, f_console_symbol_long_disable_s, " Print only the version number."); - fprintf(output.stream, "%c", f_string_eol_s[0]); + f_print_character(f_string_eol_s[0], output.stream); fll_program_print_help_option(output, context, fss_embedded_list_read_short_at, fss_embedded_list_read_long_at, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Select Object at this numeric index."); fll_program_print_help_option(output, context, fss_embedded_list_read_short_content, fss_embedded_list_read_long_content, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Print the Content (default)."); @@ -39,154 +41,76 @@ extern "C" { fll_program_print_help_usage(output, context, fss_embedded_list_read_name, "filename(s)"); - f_color_print(output.stream, context.set.important, " Notes:"); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " This program will print the Content associated with the given Object and Content main based on the FSS-0002 Basic List standard.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " All numeric positions (indexes) start at 0 instead of 1.%c", f_string_eol_s[0]); - fprintf(output.stream, " For example, a file of 17 lines would range from 0 to 16.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " When using the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_depth); - fprintf(output.stream, " option, an order of operations is enforced on the parameters.%c", f_string_eol_s[0]); - - fprintf(output.stream, " When this order of operations is in effect, parameters to the right of a depth parameter are influenced by that depth parameter:%c", f_string_eol_s[0]); - - fprintf(output.stream, " "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_at); - fprintf(output.stream, ": An Object index at the specified depth.%c", f_string_eol_s[0]); + fl_print_format(" %[Notes:%]%c", output.stream, context.set.important, context.set.important, f_string_eol_s[0]); - fprintf(output.stream, " "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_depth); - fprintf(output.stream, ": A new depth within the specified depth, indexed from the root.%c", f_string_eol_s[0]); + fl_print_format(" This program will print the Content associated with the given Object and Content main based on the FSS-0008 Embedded List standard.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_name); - fprintf(output.stream, ": An Object name at the specified depth.%c", f_string_eol_s[0]); + fl_print_format(" All numeric positions (indexes) start at 0 instead of 1.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" For example, a file of 17 lines would range from 0 to 16.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" When using the %[%s%s%] option, an order of operations is enforced on the parameters.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_depth, context.set.notable, f_string_eol_s[0]); - fprintf(output.stream, " The parameter "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_depth); - fprintf(output.stream, " must be in numeric order, but values in between may be skipped.%c", f_string_eol_s[0]); - fprintf(output.stream, " ('-d 0 -a 1 -d 2 -a 2' would specify index 1 at depth 0, any index at depth 1, and index 2 at depth 2.)%c", f_string_eol_s[0]); - fprintf(output.stream, " ('-d 2 -a 1 -d 0 -a 2' would be invalid because depth 2 is before depth 1.)%c", f_string_eol_s[0]); + fl_print_format(" When this order of operations is in effect, parameters to the right of a depth parameter are influenced by that depth parameter:%c", output.stream, f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" %[%s%s%]: An Object index at the specified depth.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_at, context.set.notable, f_string_eol_s[0]); + fl_print_format(" %[%s%s%]: A new depth within the specified depth, indexed from the root.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_depth, context.set.notable, f_string_eol_s[0]); + fl_print_format(" %[%s%s%]: An Object name at the specified depth.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_name, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " The parameter "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_select); - fprintf(output.stream, " selects a Content column.%c", f_string_eol_s[0]); + fl_print_format(" The parameter %[%s%s%] must be in numeric order, but values in between may be skipped.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_depth, context.set.notable, f_string_eol_s[0]); + fl_print_format(" ('-d 0 -a 1 -d 2 -a 2' would specify index 1 at depth 0, any index at depth 1, and index 2 at depth 2.)%c", output.stream, f_string_eol_s[0]); + fl_print_format(" ('-d 2 -a 1 -d 0 -a 2' would be invalid because depth 2 is before depth 1.)%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" The parameter %[%s%s%] selects a Content column.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_select, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " Specify both "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_object); - fprintf(output.stream, " and the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_total); - fprintf(output.stream, " parameters to get the total objects.%c", f_string_eol_s[0]); + fl_print_format(" Specify both %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_object, context.set.notable); + fl_print_format(" and the %[%s%s%] parameters to get the total objects.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_total, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" When both %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_at, context.set.notable); + fl_print_format(" and %[%s%s%] parameters are specified (at the same depth),", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_name, context.set.notable); + fl_print_format(" the %[%s%s%] parameter value will be treated as a position relative to the specified", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_at, context.set.notable); + fl_print_format(" %[%s%s%] parameter value.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_name, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " When both "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_at); - fprintf(output.stream, " and "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_name); - fprintf(output.stream, " parameters are specified (at the same depth), the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_at); - fprintf(output.stream, " parameter value will be treated as a position relative to the specified "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_name); - fprintf(output.stream, " parameter value.%c", f_string_eol_s[0]); + fl_print_format(" This program may support parameters, such as %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_depth, context.set.notable); + fl_print_format(" or %[%s%s%], even if not supported by the standard.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_select, context.set.notable, f_string_eol_s[0]); + fl_print_format(" This is done to help ensure consistency for scripting.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" For parameters like %[%s%s%],", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_depth, context.set.notable); + fl_print_format(" if the standard doesn't support nested Content, then only a depth of 0 would be valid.%c", output.stream, f_string_eol_s[0]); - fprintf(output.stream, " This program may support parameters, such as "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_depth); - fprintf(output.stream, " or "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_select); - fprintf(output.stream, ", even if not supported by the standard.%c", f_string_eol_s[0]); - fprintf(output.stream, " This is done to help ensure consistency for scripting.%c", f_string_eol_s[0]); + fl_print_format(" For parameters like %[%s%s%],", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_select, context.set.notable); + fl_print_format(" if the standard doesn't support multiple Content groups, then only a select of 0 would be valid.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" The parameter %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_trim, context.set.notable); + fl_print_format(" will remove leading and trailing whitespaces when selecting objects or when printing objects.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " For parameters like "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_depth); - fprintf(output.stream, ", if the standard doesn't support nested Content, then only a depth of 0 would be valid.%c", f_string_eol_s[0]); + fl_print_format(" When specifying both the %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_object, context.set.notable); + fl_print_format(" parameter and the %[%s%s%] parameter, the entire Object and Content are printed, including the formatting.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_content, context.set.notable, f_string_eol_s[0]); + fl_print_format(" Both the Object and Content printed are already escaped.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" Both the Object and Content are separated by an EOL.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " For parameters like "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_select); - fprintf(output.stream, ", if the standard doesn't support multiple Content groups, then only a select of 0 would be valid.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" The parameter %[%s%s%] accepts the following:%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_delimit, context.set.notable, f_string_eol_s[0]); + fl_print_format(" - %[%s%]: Do not apply delimits.%c", output.stream, context.set.notable, fss_embedded_list_read_delimit_mode_name_none, context.set.notable, f_string_eol_s[0]); + fl_print_format(" - %[%s%]: (default) Apply all delimits.%c", output.stream, context.set.notable, fss_embedded_list_read_delimit_mode_name_all, context.set.notable, f_string_eol_s[0]); + // @todo + //fl_print_format(" - %[%s%]: Apply delimits for Objects.%c", output.stream, context.set.notable, fss_embedded_list_read_delimit_mode_name_object, context.set.notable, f_string_eol_s[0]); + fl_print_format(" - A number, 0 or greater: apply delimits for Content at the specified depth.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" - A number, 0 or greater, followed by a %[%s%]: (such as '1+') apply delimits for Content at the specified depth and any greater depth (numerically).%c", output.stream, context.set.notable, fss_embedded_list_read_delimit_mode_name_greater, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); + fl_print_format(" - A number, 0 or lesser, followed by a %[%s%]: (such as '1-') apply delimits for Content at the specified depth and any lesser depth (numerically).%c%c", output.stream, context.set.notable, fss_embedded_list_read_delimit_mode_name_lesser, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " The parameter "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_trim); - fprintf(output.stream, " will remove leading and trailing whitespaces when selecting objects or when printing objects.%c", f_string_eol_s[0]); + fl_print_format(" The %[%s%s%] parameter may be specified multiple times to customize the delimit behavior.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_delimit, context.set.notable, f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" The %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_delimit, context.set.notable); + fl_print_format(" values %[%s%]", output.stream, context.set.notable, fss_embedded_list_read_delimit_mode_name_none, context.set.notable); + fl_print_format(" and %[%s%],", output.stream, context.set.notable, fss_embedded_list_read_delimit_mode_name_all, context.set.notable); + fl_print_format(" overrule all other delimit values.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " When specifying both the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_object); - fprintf(output.stream, " parameter and the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_content); - fprintf(output.stream, " parameter, the entire Object and Content are printed, including the formatting.%c", f_string_eol_s[0]); - fprintf(output.stream, " Both the Object and Content printed are already escaped.%c", f_string_eol_s[0]); - fprintf(output.stream, " Both the Object and Content are separated by an EOL.%c", f_string_eol_s[0]); + fl_print_format(" The parameters %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_columns, context.set.notable); + fl_print_format(" and %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_select, context.set.notable); + fl_print_format(" refer to a Content column.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" The word \"column\" is being loosely defined to refer to a specific Content.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" This is not to be confused with a depth.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " The parameter "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_delimit); - fprintf(output.stream, " accepts the following:%c", f_string_eol_s[0]); - fprintf(output.stream, " - "); - f_color_print(output.stream, context.set.notable, "%s", fss_embedded_list_read_delimit_mode_name_none); - fprintf(output.stream, ": Do not apply delimits.%c", f_string_eol_s[0]); - fprintf(output.stream, " - "); - f_color_print(output.stream, context.set.notable, "%s", fss_embedded_list_read_delimit_mode_name_all); - fprintf(output.stream, ": (default) Apply all delimits.%c", f_string_eol_s[0]); - // @todo - //fprintf(output.stream, " - "); - //f_color_print(output.stream, context.set.notable, "%s", fss_embedded_list_read_delimit_mode_name_object); - //fprintf(output.stream, ": Apply delimits for Objects.%c", f_string_eol_s[0]); - //fprintf(output.stream, " - A number, 0 or greater: apply delimits for Content at the specified depth.%c", f_string_eol_s[0]); - //fprintf(output.stream, " - A number, 0 or greater, followed by a "); - f_color_print(output.stream, context.set.notable, "%s", fss_embedded_list_read_delimit_mode_name_greater); - fprintf(output.stream, ": (such as '1+') apply delimits for Content at the specified depth and any greater depth (numerically).%c", f_string_eol_s[0]); - fprintf(output.stream, " - A number, 0 or greater, followed by a "); - f_color_print(output.stream, context.set.notable, "%s", fss_embedded_list_read_delimit_mode_name_lesser); - fprintf(output.stream, ": (such as '1-') apply delimits for Content at the specified depth and any lesser depth (numerically).%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " The "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_delimit); - fprintf(output.stream, " parameter may be specified multiple times to customize the delimit behavior.%c", f_string_eol_s[0]); - - fprintf(output.stream, " The "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_delimit); - fprintf(output.stream, " values "); - f_color_print(output.stream, context.set.notable, "%s", fss_embedded_list_read_delimit_mode_name_none); - fprintf(output.stream, " and "); - f_color_print(output.stream, context.set.notable, "%s", fss_embedded_list_read_delimit_mode_name_all); - fprintf(output.stream, ", overrule all other delimit values.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " The parameters "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_columns); - fprintf(output.stream, " and "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_select); - fprintf(output.stream, " refer to a Content column.%c", f_string_eol_s[0]); - fprintf(output.stream, " The word \"column\" is being loosely defined to refer to a specific Content.%c", f_string_eol_s[0]); - fprintf(output.stream, " This is not to be confused with a depth.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); + funlockfile(output.stream); return F_none; } @@ -208,9 +132,12 @@ extern "C" { if (main->context.set.error.before) { main->error.context = main->context.set.error; main->error.notable = main->context.set.notable; + + main->warning.context = main->context.set.warning; + main->warning.notable = main->context.set.notable; } else { - f_color_set_t *sets[] = { &main->error.context, &main->error.notable, 0 }; + f_color_set_t *sets[] = { &main->error.context, &main->error.notable, &main->warning.context, &main->warning.notable, 0 }; fll_program_parameter_process_empty(&main->context, sets); } @@ -236,15 +163,19 @@ extern "C" { if (choice == fss_embedded_list_read_parameter_verbosity_quiet) { main->error.verbosity = f_console_verbosity_quiet; + main->warning.verbosity = f_console_verbosity_quiet; } else if (choice == fss_embedded_list_read_parameter_verbosity_normal) { main->error.verbosity = f_console_verbosity_normal; + main->warning.verbosity = f_console_verbosity_normal; } else if (choice == fss_embedded_list_read_parameter_verbosity_verbose) { main->error.verbosity = f_console_verbosity_verbose; + main->warning.verbosity = f_console_verbosity_verbose; } else if (choice == fss_embedded_list_read_parameter_verbosity_debug) { main->error.verbosity = f_console_verbosity_debug; + main->warning.verbosity = f_console_verbosity_debug; } } @@ -267,11 +198,15 @@ extern "C" { if (F_status_is_error_not(status) && main->parameters[fss_embedded_list_read_parameter_total].result == f_console_result_found) { if (main->parameters[fss_embedded_list_read_parameter_columns].result == f_console_result_found) { - f_color_print(main->error.to.stream, main->context.set.error, "%sCannot specify the '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_total); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter with the '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_columns); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sCannot specify the '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_total, main->error.notable); + fl_print_format("%[' parameter with the '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_columns, main->error.notable); + fl_print_format("%[' parameter.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); } @@ -279,52 +214,76 @@ extern "C" { if (main->remaining.used > 0 || main->process_pipe) { if (main->parameters[fss_embedded_list_read_parameter_at].result == f_console_result_found) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe parameter '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_at); - f_color_print(main->error.to.stream, main->context.set.error, "' requires a positive number.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_at, main->error.notable); + fl_print_format("%[' requires a positive number.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); } if (F_status_is_error_not(status) && main->parameters[fss_embedded_list_read_parameter_depth].result == f_console_result_found) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe parameter '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_depth); - f_color_print(main->error.to.stream, main->context.set.error, "' requires a positive number.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_depth, main->error.notable); + fl_print_format("%[' requires a positive number.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); } if (F_status_is_error_not(status) && main->parameters[fss_embedded_list_read_parameter_line].result == f_console_result_additional) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe parameter '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_line); - f_color_print(main->error.to.stream, main->context.set.error, "' requires a positive number.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_line, main->error.notable); + fl_print_format("%[' requires a positive number.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); } if (F_status_is_error_not(status) && main->parameters[fss_embedded_list_read_parameter_name].result == f_console_result_found) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe parameter '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_name); - f_color_print(main->error.to.stream, main->context.set.error, "' requires a string.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_name, main->error.notable); + fl_print_format("%[' requires a string.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); } if (F_status_is_error_not(status) && main->parameters[fss_embedded_list_read_parameter_select].result == f_console_result_found) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe parameter '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_select); - f_color_print(main->error.to.stream, main->context.set.error, "' requires a positive number.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_select, main->error.notable); + fl_print_format("%[' requires a positive number.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); } if (main->parameters[fss_embedded_list_read_parameter_line].result == f_console_result_additional) { if (F_status_is_error_not(status) && main->parameters[fss_embedded_list_read_parameter_total].result == f_console_result_found) { - f_color_print(main->error.to.stream, main->context.set.error, "%sCannot specify the '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_line); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter with the '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_total); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sCannot specify the '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_line, main->error.notable); + fl_print_format("%[' parameter with the '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_total, main->error.notable); + fl_print_format("%[' parameter.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); } @@ -332,11 +291,15 @@ extern "C" { if (main->parameters[fss_embedded_list_read_parameter_pipe].result == f_console_result_found) { if (F_status_is_error_not(status) && main->parameters[fss_embedded_list_read_parameter_total].result == f_console_result_found) { - f_color_print(main->error.to.stream, main->context.set.error, "%sCannot specify the '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_pipe); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter with the '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_total); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sCannot specify the '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_pipe, main->error.notable); + fl_print_format("%[' parameter with the '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_total, main->error.notable); + fl_print_format("%[' parameter.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); } @@ -344,9 +307,13 @@ extern "C" { if (F_status_is_error_not(status)) { if (main->parameters[fss_embedded_list_read_parameter_delimit].result == f_console_result_found) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe parameter '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_delimit); - f_color_print(main->error.to.stream, main->context.set.error, "' requires a value.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_delimit, main->error.notable); + fl_print_format("%[' requires a value.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); } @@ -355,9 +322,13 @@ extern "C" { f_array_length_t length = strnlen(arguments.argv[location], f_console_parameter_size); if (length == 0) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe value for the parameter '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_delimit); - f_color_print(main->error.to.stream, main->context.set.error, "' must not be empty.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe value for the parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_delimit, main->error.notable); + fl_print_format("%[' must not be empty.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); } @@ -416,9 +387,13 @@ extern "C" { } if (F_status_is_error_not(status) && main->parameters[fss_embedded_list_read_parameter_select].result == f_console_result_found) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_select); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter requires a positive number.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_select, main->error.notable); + fl_print_format("%[' parameter requires a positive number.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); } @@ -512,7 +487,7 @@ extern "C" { macro_f_fss_comments_t_delete_simple(comments); } else { - f_color_print(main->error.to.stream, main->context.set.error, "%sYou failed to specify one or more files.%c", fll_error_print_error, f_string_eol_s[0]); + fll_print_format("%c%[%sYou failed to specify one or more files.%]%c", main->error.to.stream, main->error.context, main->error.prefix, main->error.context, f_string_eol_s[0]); status = F_status_set_error(F_parameter); } diff --git a/level_3/fss_embedded_list_read/c/fss_embedded_list_read.h b/level_3/fss_embedded_list_read/c/fss_embedded_list_read.h index c9f8aff..ea26317 100644 --- a/level_3/fss_embedded_list_read/c/fss_embedded_list_read.h +++ b/level_3/fss_embedded_list_read/c/fss_embedded_list_read.h @@ -43,6 +43,7 @@ #include #include #include +#include #include #ifdef __cplusplus @@ -187,6 +188,7 @@ extern "C" { f_file_t output; fll_error_print_t error; + fll_error_print_t warning; f_string_dynamic_t buffer; f_fss_nest_t nest; @@ -205,6 +207,7 @@ extern "C" { F_false, \ macro_f_file_t_initialize2(f_type_output, f_type_descriptor_output, f_file_flag_write_only), \ fll_error_print_t_initialize, \ + macro_fll_error_print_t_initialize_warning(), \ f_string_dynamic_t_initialize, \ f_fss_nest_t_initialize, \ f_string_quantity_t_initialize, \ diff --git a/level_3/fss_embedded_list_read/c/private-fss_embedded_list_read.c b/level_3/fss_embedded_list_read/c/private-fss_embedded_list_read.c index 67640aa..92412d4 100644 --- a/level_3/fss_embedded_list_read/c/private-fss_embedded_list_read.c +++ b/level_3/fss_embedded_list_read/c/private-fss_embedded_list_read.c @@ -107,6 +107,7 @@ extern "C" { if (F_status_is_error(status)) { fll_error_print(main.error, F_status_set_fine(status), "fss_embedded_list_read_main_preprocess_depth", F_true); + return status; } } @@ -130,6 +131,7 @@ extern "C" { if (F_status_is_error(status)) { fll_error_parameter_integer_print(main.error, F_status_set_fine(status), "fl_conversion_string_to_number_unsigned", F_true, fss_embedded_list_read_long_depth, arguments.argv[values_order[i]]); + return status; } } @@ -166,6 +168,7 @@ extern "C" { if (F_status_is_error(status)) { fll_error_print(main.error, F_status_set_fine(status), "fl_string_rip", F_true); + return status; } } @@ -174,6 +177,7 @@ extern "C" { if (F_status_is_error(status)) { fll_error_print(main.error, F_status_set_fine(status), "f_string_append", F_true); + return status; } } @@ -188,24 +192,30 @@ extern "C" { for (j = i + 1; j < depths->used; ++j) { if (depths->array[i].depth == depths->array[j].depth) { - fprintf(main.error.to.stream, "%c", f_string_eol_s[0]); - f_color_print(main.error.to.stream, main.context.set.error, "%sThe value '", fll_error_print_error); - f_color_print(main.error.to.stream, main.context.set.notable, "%llu", depths->array[i].depth); - f_color_print(main.error.to.stream, main.context.set.error, "' may only be specified once for the parameter '"); - f_color_print(main.error.to.stream, main.context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_depth); - f_color_print(main.error.to.stream, main.context.set.error, "'.%c", f_string_eol_s[0]); + flockfile(main.error.to.stream); + + fl_print_format("%c%[%sThe value '%]", main.error.to.stream, f_string_eol_s[0], main.error.context, main.error.prefix, main.error.context); + fl_print_format("%[%ul%]", main.error.to.stream, main.error.notable, depths->array[i].depth, main.error.notable); + fl_print_format("%[' may only be specified once for the parameter '%]", main.error.to.stream, main.error.notable, main.error.notable); + fl_print_format("%[%s%s%]", main.error.to.stream, main.error.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_depth, main.error.notable); + fl_print_format("%['.%]%c", main.error.to.stream, main.error.context, main.error.context, f_string_eol_s[0]); + + funlockfile(main.error.to.stream); return F_status_set_error(F_parameter); } else if (depths->array[i].depth > depths->array[j].depth) { - fprintf(main.error.to.stream, "%c", f_string_eol_s[0]); - f_color_print(main.error.to.stream, main.context.set.error, "%sThe parameter '", fll_error_print_error); - f_color_print(main.error.to.stream, main.context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_embedded_list_read_long_depth); - f_color_print(main.error.to.stream, main.context.set.error, "' may not have the value '"); - f_color_print(main.error.to.stream, main.context.set.notable, "%llu", depths->array[i].depth); - f_color_print(main.error.to.stream, main.context.set.error, "' before the value '"); - f_color_print(main.error.to.stream, main.context.set.notable, "%llu", depths->array[j].depth); - f_color_print(main.error.to.stream, main.context.set.error, "'.%c", f_string_eol_s[0]); + flockfile(main.error.to.stream); + + fl_print_format("%c%[%sThe parameter '%]", main.error.to.stream, f_string_eol_s[0], main.error.context, main.error.prefix, main.error.context); + fl_print_format("%[%s%s%]", main.error.to.stream, main.error.notable, f_console_symbol_long_enable_s, fss_embedded_list_read_long_depth, main.error.notable); + fl_print_format("%[' may not have the value '%]", main.error.to.stream, main.error.notable, main.error.notable); + fl_print_format("%[%ul%]", main.error.to.stream, main.error.notable, depths->array[i].depth, main.error.notable); + fl_print_format("%[' before the value '%]", main.error.to.stream, main.error.notable, main.error.notable); + fl_print_format("%[%ul%]", main.error.to.stream, main.error.notable, depths->array[j].depth, main.error.notable); + fl_print_format("%['.%]%c", main.error.to.stream, main.error.context, main.error.context, f_string_eol_s[0]); + + funlockfile(main.error.to.stream); return F_status_set_error(F_parameter); } @@ -240,7 +250,8 @@ extern "C" { macro_f_string_dynamic_t_delete_simple(main->buffer); if (main->parameters[fss_embedded_list_read_parameter_total].result == f_console_result_found) { - fprintf(main->output.stream, "0%c", f_string_eol_s[0]); + fll_print_format("0%c", main->output.stream, f_string_eol_s[0]); + return F_none; } @@ -268,7 +279,8 @@ extern "C" { // Requested depths cannot be greater than contents depth. if (depths.used > main->nest.used) { if (main->parameters[fss_embedded_list_read_parameter_total].result == f_console_result_found) { - fprintf(main->output.stream, "0%c", f_string_eol_s[0]); + fll_print_format("0%c", main->output.stream, f_string_eol_s[0]); + return F_none; } @@ -286,6 +298,7 @@ extern "C" { if (F_status_is_error(status)) { fll_error_parameter_integer_print(main->error, F_status_set_fine(status), "fl_conversion_string_to_number_unsigned", F_true, fss_embedded_list_read_long_select, arguments.argv[index]); + return status; } @@ -306,6 +319,7 @@ extern "C" { if (F_status_is_error(status)) { fll_error_parameter_integer_print(main->error, F_status_set_fine(status), "fl_conversion_string_to_number_unsigned", F_true, fss_embedded_list_read_long_line, arguments.argv[index]); + return status; } } @@ -481,34 +495,38 @@ extern "C" { ++total; } // for - fprintf(main->output.stream, "%llu%c", total, f_string_eol_s[0]); + fl_print_format("%lu%c", main->output.stream, total, f_string_eol_s[0]); return F_none; } - f_status_t (*print_object)(FILE *, const f_string_static_t, const f_string_range_t, const f_array_lengths_t) = &f_print_except_dynamic_partial; + f_status_t (*print_object)(const f_string_static_t, const f_string_range_t, const f_array_lengths_t, FILE *) = &f_print_except_dynamic_partial; if (main->parameters[fss_embedded_list_read_parameter_trim].result == f_console_result_found) { print_object = &fl_print_trim_except_dynamic_partial; } + flockfile(main->output.stream); + for (i = 0; i < items->used; ++i) { if (skip[i]) continue; - print_object(main->output.stream, main->buffer, items->array[i].object, *objects_delimits); + print_object(main->buffer, items->array[i].object, *objects_delimits, main->output.stream); if (main->parameters[fss_embedded_list_read_parameter_content].result == f_console_result_found) { fss_embedded_list_read_print_object_end(*main); if (items->array[i].content.used) { - f_print_except_dynamic_partial(main->output.stream, main->buffer, items->array[i].content.array[0], *contents_delimits); + f_print_except_dynamic_partial(main->buffer, items->array[i].content.array[0], *contents_delimits, main->output.stream); } } fss_embedded_list_read_print_set_end(*main); } // for + funlockfile(main->output.stream); + return F_none; } @@ -544,13 +562,16 @@ extern "C" { } // for } // for - fprintf(main->output.stream, "%llu%c", total, f_string_eol_s[0]); + fll_print_format("%lu%c", main->output.stream, total, f_string_eol_s[0]); + return F_none; } if (main->parameters[fss_embedded_list_read_parameter_line].result == f_console_result_additional) { f_array_length_t line_current = 0; + flockfile(main->output.stream); + for (; i < items->used; ++i) { if (skip[i]) continue; @@ -592,20 +613,24 @@ extern "C" { if (!main->buffer.string[j]) continue; if (main->buffer.string[j] == f_string_eol_s[0]) { - fprintf(main->output.stream, "%c", f_string_eol_s[0]); + f_print_character(f_string_eol_s[0], main->output.stream); break; } - fprintf(main->output.stream, "%c", main->buffer.string[j]); + f_print_character(main->buffer.string[j], main->output.stream); } // for break; } } // for + funlockfile(main->output.stream); + return F_none; } + flockfile(main->output.stream); + for (i = 0; i < items->used; ++i) { if (skip[i]) continue; @@ -618,13 +643,15 @@ extern "C" { continue; } - f_print_except_dynamic_partial(main->output.stream, main->buffer, items->array[i].content.array[0], *contents_delimits); + f_print_except_dynamic_partial(main->buffer, items->array[i].content.array[0], *contents_delimits, main->output.stream); if (main->parameters[fss_embedded_list_read_parameter_pipe].result == f_console_result_found) { - fprintf(main->output.stream, "%c", fss_embedded_list_read_pipe_content_end); + f_print_character(fss_embedded_list_read_pipe_content_end, main->output.stream); } } // for + funlockfile(main->output.stream); + return F_none; } #endif // _di_fss_embedded_list_read_main_process_for_depth_ @@ -633,14 +660,15 @@ extern "C" { void fss_embedded_list_read_print_object_end(const fss_embedded_list_read_main_t main) { if (main.parameters[fss_embedded_list_read_parameter_pipe].result == f_console_result_found) { - fprintf(main.output.stream, "%c", fss_embedded_list_read_pipe_content_start); + f_print_character(fss_embedded_list_read_pipe_content_start, main.output.stream); } else { if (main.parameters[fss_embedded_list_read_parameter_object].result == f_console_result_found && main.parameters[fss_embedded_list_read_parameter_content].result == f_console_result_found) { - fprintf(main.output.stream, "%c%c", f_fss_embedded_list_open, f_fss_embedded_list_open_end); + f_print_character(f_fss_embedded_list_open, main.output.stream); + f_print_character(f_fss_embedded_list_open_end, main.output.stream); } else { - fprintf(main.output.stream, "%c", f_fss_eol); + f_print_character(f_fss_eol, main.output.stream); } } } @@ -650,7 +678,7 @@ extern "C" { void fss_embedded_list_read_print_content_ignore(const fss_embedded_list_read_main_t main) { if (main.parameters[fss_embedded_list_read_parameter_pipe].result == f_console_result_found) { - fprintf(main.output.stream, "%c", fss_embedded_list_read_pipe_content_ignore); + f_print_character(fss_embedded_list_read_pipe_content_ignore, main.output.stream); } } #endif // _di_fss_embedded_list_read_print_content_ignore_ @@ -659,14 +687,15 @@ extern "C" { void fss_embedded_list_read_print_set_end(const fss_embedded_list_read_main_t main) { if (main.parameters[fss_embedded_list_read_parameter_pipe].result == f_console_result_found) { - fprintf(main.output.stream, "%c", fss_embedded_list_read_pipe_content_end); + f_print_character(fss_embedded_list_read_pipe_content_end, main.output.stream); } else { if (main.parameters[fss_embedded_list_read_parameter_object].result == f_console_result_found && main.parameters[fss_embedded_list_read_parameter_content].result == f_console_result_found) { - fprintf(main.output.stream, "%c%c", f_fss_embedded_list_close, f_fss_embedded_list_close_end); + f_print_character(f_fss_embedded_list_close, main.output.stream); + f_print_character(f_fss_embedded_list_close_end, main.output.stream); } else { - fprintf(main.output.stream, "%c", f_fss_eol); + f_print_character(f_fss_eol, main.output.stream); } } } diff --git a/level_3/fss_embedded_list_read/data/build/dependencies b/level_3/fss_embedded_list_read/data/build/dependencies index cc1beee..7c8767f 100644 --- a/level_3/fss_embedded_list_read/data/build/dependencies +++ b/level_3/fss_embedded_list_read/data/build/dependencies @@ -23,4 +23,5 @@ fl_string fll_error fll_file fll_fss +fll_print fll_program diff --git a/level_3/fss_embedded_list_read/data/build/settings b/level_3/fss_embedded_list_read/data/build/settings index 3cf06d2..27dfee3 100644 --- a/level_3/fss_embedded_list_read/data/build/settings +++ b/level_3/fss_embedded_list_read/data/build/settings @@ -20,7 +20,7 @@ build_compiler gcc build_indexer ar build_language c build_libraries -lc -build_libraries-individual -lfll_error -lfll_file -lfll_fss -lfll_program -lfl_console -lfl_conversion -lfl_directory -lfl_fss -lfl_print -lfl_status -lfl_string -lf_color -lf_console -lf_conversion -lf_directory -lf_environment -lf_file -lf_fss -lf_memory -lf_path -lf_pipe -lf_print -lf_string -lf_type_array -lf_utf +build_libraries-individual -lfll_error -lfll_file -lfll_fss -lfll_print -lfll_program -lfl_console -lfl_conversion -lfl_directory -lfl_fss -lfl_print -lfl_status -lfl_string -lf_color -lf_console -lf_conversion -lf_directory -lf_environment -lf_file -lf_fss -lf_memory -lf_path -lf_pipe -lf_print -lf_string -lf_type_array -lf_utf build_libraries-level -lfll_2 -lfll_1 -lfll_0 build_libraries-monolithic -lfll build_sources_library fss_embedded_list_read.c private-common.c private-fss_embedded_list_read.c @@ -51,7 +51,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_3/fss_extended_list_read/c/fss_extended_list_read.c b/level_3/fss_extended_list_read/c/fss_extended_list_read.c index b60473a..a4c8b18 100644 --- a/level_3/fss_extended_list_read/c/fss_extended_list_read.c +++ b/level_3/fss_extended_list_read/c/fss_extended_list_read.c @@ -9,6 +9,8 @@ extern "C" { #ifndef _di_fss_extended_list_read_print_help_ f_status_t fss_extended_list_read_print_help(const f_file_t output, const f_color_context_t context) { + flockfile(output.stream); + fll_program_print_help_header(output, context, fss_extended_list_read_name_long, fss_extended_list_read_version); fll_program_print_help_option(output, context, f_console_standard_short_help_s, f_console_standard_long_help_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Print this help message."); @@ -21,7 +23,7 @@ extern "C" { fll_program_print_help_option(output, context, f_console_standard_short_debug_s, f_console_standard_long_debug_s, f_console_symbol_short_disable_s, f_console_symbol_long_disable_s, " Enable debugging, inceasing verbosity beyond normal output."); fll_program_print_help_option(output, context, f_console_standard_short_version_s, f_console_standard_long_version_s, f_console_symbol_short_disable_s, f_console_symbol_long_disable_s, " Print only the version number."); - fprintf(output.stream, "%c", f_string_eol_s[0]); + f_print_character(f_string_eol_s[0], output.stream); fll_program_print_help_option(output, context, fss_extended_list_read_short_at, fss_extended_list_read_long_at, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Select Object at this numeric index."); fll_program_print_help_option(output, context, fss_extended_list_read_short_content, fss_extended_list_read_long_content, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Print the Content (default)."); @@ -39,153 +41,75 @@ extern "C" { fll_program_print_help_usage(output, context, fss_extended_list_read_name, "filename(s)"); - f_color_print(output.stream, context.set.important, " Notes:"); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " This program will print the Content associated with the given Object and Content main based on the FSS-0003 Extended List standard.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " All numeric positions (indexes) start at 0 instead of 1.%c", f_string_eol_s[0]); - fprintf(output.stream, " For example, a file of 17 lines would range from 0 to 16.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" %[Notes:%]%c", output.stream, context.set.important, context.set.important, f_string_eol_s[0]); - fprintf(output.stream, " When using the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_depth); - fprintf(output.stream, " option, an order of operations is enforced on the parameters.%c", f_string_eol_s[0]); + fl_print_format(" This program will print the Content associated with the given Object and Content main based on the FSS-0003 Extended List standard.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " When this order of operations is in effect, parameters to the right of a depth parameter are influenced by that depth parameter:%c", f_string_eol_s[0]); + fl_print_format(" All numeric positions (indexes) start at 0 instead of 1.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" For example, a file of 17 lines would range from 0 to 16.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_at); - fprintf(output.stream, ": An Object index at the specified depth.%c", f_string_eol_s[0]); + fl_print_format(" When using the %[%s%s%] option, an order of operations is enforced on the parameters.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_depth, context.set.notable, f_string_eol_s[0]); - fprintf(output.stream, " "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_depth); - fprintf(output.stream, ": A new depth within the specified depth, indexed from the root.%c", f_string_eol_s[0]); + fl_print_format(" When this order of operations is in effect, parameters to the right of a depth parameter are influenced by that depth parameter:%c", output.stream, f_string_eol_s[0]); - fprintf(output.stream, " "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_name); - fprintf(output.stream, ": An Object name at the specified depth.%c", f_string_eol_s[0]); + fl_print_format(" %[%s%s%]: An Object index at the specified depth.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_at, context.set.notable, f_string_eol_s[0]); + fl_print_format(" %[%s%s%]: A new depth within the specified depth, indexed from the root.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_depth, context.set.notable, f_string_eol_s[0]); + fl_print_format(" %[%s%s%]: An Object name at the specified depth.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_name, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" The parameter %[%s%s%] must be in numeric order, but values in between may be skipped.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_depth, context.set.notable, f_string_eol_s[0]); + fl_print_format(" ('-d 0 -a 1 -d 2 -a 2' would specify index 1 at depth 0, any index at depth 1, and index 2 at depth 2.)%c", output.stream, f_string_eol_s[0]); + fl_print_format(" ('-d 2 -a 1 -d 0 -a 2' would be invalid because depth 2 is before depth 1.)%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " The parameter "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_depth); - fprintf(output.stream, " must be in numeric order, but values in between may be skipped.%c", f_string_eol_s[0]); - fprintf(output.stream, " ('-d 0 -a 1 -d 2 -a 2' would specify index 1 at depth 0, any index at depth 1, and index 2 at depth 2.)%c", f_string_eol_s[0]); - fprintf(output.stream, " ('-d 2 -a 1 -d 0 -a 2' would be invalid because depth 2 is before depth 1.)%c", f_string_eol_s[0]); + fl_print_format(" The parameter %[%s%s%] selects a Content column.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_select, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" Specify both %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_object, context.set.notable); + fl_print_format(" and the %[%s%s%] parameters to get the total objects.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_total, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " The parameter "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_select); - fprintf(output.stream, " selects a Content column.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " Specify both "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_object); - fprintf(output.stream, " and the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_total); - fprintf(output.stream, " parameters to get the total objects.%c", f_string_eol_s[0]); + fl_print_format(" When both %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_at, context.set.notable); + fl_print_format(" and %[%s%s%] parameters are specified (at the same depth),", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_name, context.set.notable); + fl_print_format(" the %[%s%s%] parameter value will be treated as a position relative to the specified", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_at, context.set.notable); + fl_print_format(" %[%s%s%] parameter value.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_name, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" This program may support parameters, such as %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_depth, context.set.notable); + fl_print_format(" or %[%s%s%], even if not supported by the standard.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_select, context.set.notable, f_string_eol_s[0]); + fl_print_format(" This is done to help ensure consistency for scripting.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " When both "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_at); - fprintf(output.stream, " and "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_name); - fprintf(output.stream, " parameters are specified (at the same depth), the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_at); - fprintf(output.stream, " parameter value will be treated as a position relative to the specified "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_name); - fprintf(output.stream, " parameter value.%c", f_string_eol_s[0]); + fl_print_format(" For parameters like %[%s%s%],", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_depth, context.set.notable); + fl_print_format(" if the standard doesn't support nested Content, then only a depth of 0 would be valid.%c", output.stream, f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" For parameters like %[%s%s%],", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_select, context.set.notable); + fl_print_format(" if the standard doesn't support multiple Content groups, then only a select of 0 would be valid.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " This program may support parameters, such as "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_depth); - fprintf(output.stream, " or "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_select); - fprintf(output.stream, ", even if not supported by the standard.%c", f_string_eol_s[0]); - fprintf(output.stream, " This is done to help ensure consistency for scripting.%c", f_string_eol_s[0]); + fl_print_format(" The parameter %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_trim, context.set.notable); + fl_print_format(" will remove leading and trailing whitespaces when selecting objects or when printing objects.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" When specifying both the %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_object, context.set.notable); + fl_print_format(" parameter and the %[%s%s%] parameter, the entire Object and Content are printed, including the formatting.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_content, context.set.notable, f_string_eol_s[0]); + fl_print_format(" Both the Object and Content printed are already escaped.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" Both the Object and Content are separated by an EOL.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " For parameters like "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_depth); - fprintf(output.stream, ", if the standard doesn't support nested Content, then only a depth of 0 would be valid.%c", f_string_eol_s[0]); + fl_print_format(" The parameter %[%s%s%] accepts the following:%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_delimit, context.set.notable, f_string_eol_s[0]); + fl_print_format(" - %[%s%]: Do not apply delimits.%c", output.stream, context.set.notable, fss_extended_list_read_delimit_mode_name_none, context.set.notable, f_string_eol_s[0]); + fl_print_format(" - %[%s%]: (default) Apply all delimits.%c", output.stream, context.set.notable, fss_extended_list_read_delimit_mode_name_all, context.set.notable, f_string_eol_s[0]); + fl_print_format(" - %[%s%]: Apply delimits for Objects.%c", output.stream, context.set.notable, fss_extended_list_read_delimit_mode_name_object, context.set.notable, f_string_eol_s[0]); + fl_print_format(" - A number, 0 or greater: apply delimits for Content at the specified depth.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" - A number, 0 or greater, followed by a %[%s%]: (such as '1+') apply delimits for Content at the specified depth and any greater depth (numerically).%c", output.stream, context.set.notable, fss_extended_list_read_delimit_mode_name_greater, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); + fl_print_format(" - A number, 0 or lesser, followed by a %[%s%]: (such as '1-') apply delimits for Content at the specified depth and any lesser depth (numerically).%c%c", output.stream, context.set.notable, fss_extended_list_read_delimit_mode_name_lesser, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " For parameters like "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_select); - fprintf(output.stream, ", if the standard doesn't support multiple Content groups, then only a select of 0 would be valid.%c", f_string_eol_s[0]); + fl_print_format(" The %[%s%s%] parameter may be specified multiple times to customize the delimit behavior.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_delimit, context.set.notable, f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" The %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_delimit, context.set.notable); + fl_print_format(" values %[%s%]", output.stream, context.set.notable, fss_extended_list_read_delimit_mode_name_none, context.set.notable); + fl_print_format(" and %[%s%],", output.stream, context.set.notable, fss_extended_list_read_delimit_mode_name_all, context.set.notable); + fl_print_format(" overrule all other delimit values.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " The parameter "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_trim); - fprintf(output.stream, " will remove leading and trailing whitespaces when selecting objects or when printing objects.%c", f_string_eol_s[0]); + fl_print_format(" The parameters %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_columns, context.set.notable); + fl_print_format(" and %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_select, context.set.notable); + fl_print_format(" refer to a Content column.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" The word \"column\" is being loosely defined to refer to a specific Content.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" This is not to be confused with a depth.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " When specifying both the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_object); - fprintf(output.stream, " parameter and the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_content); - fprintf(output.stream, " parameter, the entire Object and Content are printed, including the formatting.%c", f_string_eol_s[0]); - fprintf(output.stream, " Both the Object and Content printed are already escaped.%c", f_string_eol_s[0]); - fprintf(output.stream, " Both the Object and Content are separated by an EOL.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " The parameter "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_delimit); - fprintf(output.stream, " accepts the following:%c", f_string_eol_s[0]); - fprintf(output.stream, " - "); - f_color_print(output.stream, context.set.notable, "%s", fss_extended_list_read_delimit_mode_name_none); - fprintf(output.stream, ": Do not apply delimits.%c", f_string_eol_s[0]); - fprintf(output.stream, " - "); - f_color_print(output.stream, context.set.notable, "%s", fss_extended_list_read_delimit_mode_name_all); - fprintf(output.stream, ": (default) Apply all delimits.%c", f_string_eol_s[0]); - fprintf(output.stream, " - "); - f_color_print(output.stream, context.set.notable, "%s", fss_extended_list_read_delimit_mode_name_object); - fprintf(output.stream, ": Apply delimits for Objects.%c", f_string_eol_s[0]); - fprintf(output.stream, " - A number, 0 or greater: apply delimits for Content at the specified depth.%c", f_string_eol_s[0]); - fprintf(output.stream, " - A number, 0 or greater, followed by a "); - f_color_print(output.stream, context.set.notable, "%s", fss_extended_list_read_delimit_mode_name_greater); - fprintf(output.stream, ": (such as '1+') apply delimits for Content at the specified depth and any greater depth (numerically).%c", f_string_eol_s[0]); - fprintf(output.stream, " - A number, 0 or greater, followed by a "); - f_color_print(output.stream, context.set.notable, "%s", fss_extended_list_read_delimit_mode_name_lesser); - fprintf(output.stream, ": (such as '1-') apply delimits for Content at the specified depth and any lesser depth (numerically).%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " The "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_delimit); - fprintf(output.stream, " parameter may be specified multiple times to customize the delimit behavior.%c", f_string_eol_s[0]); - - fprintf(output.stream, " The "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_delimit); - fprintf(output.stream, " values "); - f_color_print(output.stream, context.set.notable, "%s", fss_extended_list_read_delimit_mode_name_none); - fprintf(output.stream, " and "); - f_color_print(output.stream, context.set.notable, "%s", fss_extended_list_read_delimit_mode_name_all); - fprintf(output.stream, ", overrule all other delimit values.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " The parameters "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_columns); - fprintf(output.stream, " and "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_select); - fprintf(output.stream, " refer to a Content column.%c", f_string_eol_s[0]); - fprintf(output.stream, " The word \"column\" is being loosely defined to refer to a specific Content.%c", f_string_eol_s[0]); - fprintf(output.stream, " This is not to be confused with a depth.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); + funlockfile(output.stream); return F_none; } @@ -208,9 +132,12 @@ extern "C" { if (main->context.set.error.before) { main->error.context = main->context.set.error; main->error.notable = main->context.set.notable; + + main->warning.context = main->context.set.warning; + main->warning.notable = main->context.set.notable; } else { - f_color_set_t *sets[] = { &main->error.context, &main->error.notable, 0 }; + f_color_set_t *sets[] = { &main->error.context, &main->error.notable, &main->warning.context, &main->warning.notable, 0 }; fll_program_parameter_process_empty(&main->context, sets); } @@ -236,15 +163,19 @@ extern "C" { if (choice == fss_extended_list_read_parameter_verbosity_quiet) { main->error.verbosity = f_console_verbosity_quiet; + main->warning.verbosity = f_console_verbosity_quiet; } else if (choice == fss_extended_list_read_parameter_verbosity_normal) { main->error.verbosity = f_console_verbosity_normal; + main->warning.verbosity = f_console_verbosity_normal; } else if (choice == fss_extended_list_read_parameter_verbosity_verbose) { main->error.verbosity = f_console_verbosity_verbose; + main->warning.verbosity = f_console_verbosity_verbose; } else if (choice == fss_extended_list_read_parameter_verbosity_debug) { main->error.verbosity = f_console_verbosity_debug; + main->warning.verbosity = f_console_verbosity_debug; } } @@ -309,9 +240,13 @@ extern "C" { for (f_array_length_t i = 0; i < 6; ++i) { if (main->parameters[parameter_code[i]].result == f_console_result_found) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe parameter '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, parameter_name[i]); - f_color_print(main->error.to.stream, main->context.set.error, "' requires a %s.%c", parameter_message[i], f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, parameter_name[i], main->error.notable); + fl_print_format("%[' requires a %s.%]%c", main->error.to.stream, main->error.context, parameter_message[i], main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); break; @@ -347,11 +282,15 @@ extern "C" { for (f_array_length_t i = 0; i < 5; ++i) { if (main->parameters[parameter_code[i]].result == parameter_match[i]) { - f_color_print(main->error.to.stream, main->context.set.error, "%sCannot specify the '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_columns); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter with the '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, parameter_name[i]); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sCannot specify the '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_columns, main->error.notable); + fl_print_format("%[' parameter with the '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, parameter_name[i], main->error.notable); + fl_print_format("%[' parameter.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); break; @@ -361,20 +300,28 @@ extern "C" { if (F_status_is_error_not(status) && main->parameters[fss_extended_list_read_parameter_pipe].result == f_console_result_found) { if (main->parameters[fss_extended_list_read_parameter_total].result == f_console_result_found) { - f_color_print(main->error.to.stream, main->context.set.error, "%sCannot specify the '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_pipe); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter with the '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_total); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sCannot specify the '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_pipe, main->error.notable); + fl_print_format("%[' parameter with the '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_total, main->error.notable); + fl_print_format("%[' parameter.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); } else if (main->parameters[fss_extended_list_read_parameter_line].result == f_console_result_additional) { - f_color_print(main->error.to.stream, main->context.set.error, "%sCannot specify the '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_pipe); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter with the '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_line); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sCannot specify the '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_pipe, main->error.notable); + fl_print_format("%[' parameter with the '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_line, main->error.notable); + fl_print_format("%[' parameter.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); } @@ -393,9 +340,13 @@ extern "C" { length = strnlen(arguments->argv[location], f_console_parameter_size); if (!length) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe value for the parameter '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_delimit); - f_color_print(main->error.to.stream, main->context.set.error, "' must not be empty.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe value for the parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_delimit, main->error.notable); + fl_print_format("%[' must not be empty.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); break; @@ -522,9 +473,13 @@ extern "C" { } if (F_status_is_error_not(status) && main->parameters[fss_extended_list_read_parameter_select].result == f_console_result_found) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_select); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter requires a positive number.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_select, main->error.notable); + fl_print_format("%[' parameter requires a positive number.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); fss_extended_list_read_depths_resize(0, &data.depths); @@ -640,7 +595,7 @@ extern "C" { fss_extended_list_read_data_delete_simple(&data); } else { - f_color_print(main->error.to.stream, main->context.set.error, "%sYou failed to specify one or more files.%c", fll_error_print_error, f_string_eol_s[0]); + fll_print_format("%c%[%sYou failed to specify one or more files.%]%c", main->error.to.stream, main->error.context, main->error.prefix, main->error.context, f_string_eol_s[0]); status = F_status_set_error(F_parameter); } diff --git a/level_3/fss_extended_list_read/c/fss_extended_list_read.h b/level_3/fss_extended_list_read/c/fss_extended_list_read.h index 8d46c59..a37aba4 100644 --- a/level_3/fss_extended_list_read/c/fss_extended_list_read.h +++ b/level_3/fss_extended_list_read/c/fss_extended_list_read.h @@ -43,6 +43,7 @@ #include #include #include +#include #include #ifdef __cplusplus @@ -206,6 +207,7 @@ extern "C" { f_file_t output; fll_error_print_t error; + fll_error_print_t warning; f_color_context_t context; } fss_extended_list_read_main_t; @@ -217,6 +219,7 @@ extern "C" { F_false, \ macro_f_file_t_initialize2(f_type_output, f_type_descriptor_output, f_file_flag_write_only), \ fll_error_print_t_initialize, \ + macro_fll_error_print_t_initialize_warning(), \ f_color_context_t_initialize, \ } #endif // _di_fss_extended_list_read_main_t_ diff --git a/level_3/fss_extended_list_read/c/private-fss_extended_list_read.c b/level_3/fss_extended_list_read/c/private-fss_extended_list_read.c index 7d5be74..34fbde0 100644 --- a/level_3/fss_extended_list_read/c/private-fss_extended_list_read.c +++ b/level_3/fss_extended_list_read/c/private-fss_extended_list_read.c @@ -162,9 +162,13 @@ extern "C" { if (!data->depths.array[i].value_name.used) { if (main->error.verbosity != f_console_verbosity_quiet) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_name); - f_color_print(main->error.to.stream, main->context.set.error, "' must not be an empty string.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_name, main->error.notable); + fl_print_format("%[' must not be an empty string.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); } return F_status_set_error(F_parameter); @@ -179,24 +183,32 @@ extern "C" { if (data->depths.array[i].depth == data->depths.array[j].depth) { if (main->error.verbosity != f_console_verbosity_quiet) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe value '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%llu", data->depths.array[i].depth); - f_color_print(main->error.to.stream, main->context.set.error, "' may only be specified once for the parameter '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_depth); - f_color_print(main->error.to.stream, main->context.set.error, "'.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe value '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%ul%]", main->error.to.stream, main->error.notable, data->depths.array[i].depth, main->error.notable); + fl_print_format("%[' may only be specified once for the parameter '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_depth, main->error.notable); + fl_print_format("%['.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); } return F_status_set_error(F_parameter); } else if (data->depths.array[i].depth > data->depths.array[j].depth) { if (main->error.verbosity != f_console_verbosity_quiet) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe parameter '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_list_read_long_depth); - f_color_print(main->error.to.stream, main->context.set.error, "' may not have the value '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%llu", data->depths.array[i].depth); - f_color_print(main->error.to.stream, main->context.set.error, "' before the value '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%llu", data->depths.array[j].depth); - f_color_print(main->error.to.stream, main->context.set.error, "'.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_extended_list_read_long_depth, main->error.notable); + fl_print_format("%[' may not have the value '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%ul%]", main->error.to.stream, main->error.notable, data->depths.array[i].depth, main->error.notable); + fl_print_format("%[' before the value '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%ul%]", main->error.to.stream, main->error.notable, data->depths.array[j].depth, main->error.notable); + fl_print_format("%['.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); } return F_status_set_error(F_parameter); @@ -284,12 +296,14 @@ extern "C" { } if ((data->option & fss_extended_list_read_data_option_object) || ((data->option & fss_extended_list_read_data_option_content) && (data->contents.array[at].used && data->contents.array[at].array[0].start <= data->contents.array[at].array[0].stop || (data->option & fss_extended_list_read_data_option_empty)))) { + flockfile(main->output.stream); + if (data->option & fss_extended_list_read_data_option_object) { if (data->option & fss_extended_list_read_data_option_trim) { - fl_print_trim_except_dynamic_partial(main->output.stream, data->buffer, data->objects.array[at], delimits_object); + fl_print_trim_except_dynamic_partial(data->buffer, data->objects.array[at], delimits_object, main->output.stream); } else { - f_print_except_dynamic_partial(main->output.stream, data->buffer, data->objects.array[at], delimits_object); + f_print_except_dynamic_partial(data->buffer, data->objects.array[at], delimits_object, main->output.stream); } fss_extended_list_read_print_object_end(main, data); @@ -299,13 +313,17 @@ extern "C" { if (data->contents.array[at].used && data->contents.array[at].array[0].start <= data->contents.array[at].array[0].stop) { if (data->contents.array[at].used && data->contents.array[at].array[0].start <= data->contents.array[at].array[0].stop) { fss_extended_list_read_print_content_ignore(main); - f_print_except_in_dynamic_partial(main->output.stream, data->buffer, data->contents.array[at].array[0], delimits_content, data->comments); + + f_print_except_in_dynamic_partial(data->buffer, data->contents.array[at].array[0], delimits_content, data->comments, main->output.stream); + fss_extended_list_read_print_content_ignore(main); } } } fss_extended_list_read_print_set_end(main, data); + + funlockfile(main->output.stream); } } #endif // _di_fss_extended_list_read_print_at_ @@ -318,10 +336,10 @@ extern "C" { } if (data->option & fss_extended_list_read_data_option_trim) { - fl_print_trim_except_dynamic_partial(main->output.stream, data->buffer, data->objects.array[at], delimits_object); + fl_print_trim_except_dynamic_partial(data->buffer, data->objects.array[at], delimits_object, main->output.stream); } else { - f_print_except_dynamic_partial(main->output.stream, data->buffer, data->objects.array[at], delimits_object); + f_print_except_dynamic_partial(data->buffer, data->objects.array[at], delimits_object, main->output.stream); } fss_extended_list_read_print_object_end(main, data); @@ -332,7 +350,7 @@ extern "C" { void fss_extended_list_read_print_content_ignore(fss_extended_list_read_main_t * const main) { if (main->parameters[fss_extended_list_read_parameter_pipe].result == f_console_result_found) { - fprintf(main->output.stream, "%c", fss_extended_list_read_pipe_content_ignore); + f_print_character(fss_extended_list_read_pipe_content_ignore, main->output.stream); } } #endif // _di_fss_extended_list_read_print_content_ignore_ @@ -341,11 +359,12 @@ extern "C" { void fss_extended_list_read_print_object_end(fss_extended_list_read_main_t * const main, fss_extended_list_read_data_t * const data) { if (main->parameters[fss_extended_list_read_parameter_pipe].result == f_console_result_found) { - fprintf(main->output.stream, "%c", fss_extended_list_read_pipe_content_start); + f_print_character(fss_extended_list_read_pipe_content_start, main->output.stream); } else { if ((data->option & fss_extended_list_read_data_option_object) && (data->option & fss_extended_list_read_data_option_content)) { - fprintf(main->output.stream, "%c%c", f_fss_extended_list_open, f_fss_extended_list_open_end); + f_print_character(f_fss_extended_list_open, main->output.stream); + f_print_character(f_fss_extended_list_open_end, main->output.stream); } } } @@ -355,15 +374,16 @@ extern "C" { void fss_extended_list_read_print_set_end(fss_extended_list_read_main_t * const main, fss_extended_list_read_data_t * const data) { if (main->parameters[fss_extended_list_read_parameter_pipe].result == f_console_result_found) { - fprintf(main->output.stream, "%c", fss_extended_list_read_pipe_content_end); + f_print_character(fss_extended_list_read_pipe_content_end, main->output.stream); } else { if (data->option & fss_extended_list_read_data_option_object) { if (data->option & fss_extended_list_read_data_option_content) { - fprintf(main->output.stream, "%c%c", f_fss_extended_list_close, f_fss_extended_list_close_end); + f_print_character(f_fss_extended_list_close, main->output.stream); + f_print_character(f_fss_extended_list_close_end, main->output.stream); } else if (!(data->option & fss_extended_list_read_data_option_content)) { - fprintf(main->output.stream, "%c", f_fss_eol); + f_print_character(f_fss_eol, main->output.stream); } } } @@ -372,13 +392,15 @@ extern "C" { #ifndef _di_fss_extended_list_read_print_one_ void fss_extended_list_read_print_one(fss_extended_list_read_main_t * const main) { - fprintf(main->output.stream, "1%c", f_string_eol_s[0]); + f_print_character(f_string_ascii_1_s[0], main->output.stream); + f_print_character(f_string_eol_s[0], main->output.stream); } #endif // _di_fss_extended_list_read_print_one_ #ifndef _di_fss_extended_list_read_print_zero_ void fss_extended_list_read_print_zero(fss_extended_list_read_main_t * const main) { - fprintf(main->output.stream, "0%c", f_string_eol_s[0]); + f_print_character(f_string_ascii_0_s[0], main->output.stream); + f_print_character(f_string_eol_s[0], main->output.stream); } #endif // _di_fss_extended_list_read_print_zero_ @@ -609,7 +631,7 @@ extern "C" { fss_extended_list_read_print_one(main); } else { - f_print_except_in_dynamic_partial(main->output.stream, data->buffer, range, delimits_content, data->comments); + f_print_except_in_dynamic_partial(data->buffer, range, delimits_content, data->comments, main->output.stream); } return F_success; @@ -634,7 +656,7 @@ extern "C" { else { range.stop = data->contents.array[at].array[0].stop; - f_print_except_in_dynamic_partial(main->output.stream, data->buffer, range, delimits_content, data->comments); + f_print_except_in_dynamic_partial(data->buffer, range, delimits_content, data->comments, main->output.stream); fprintf(main->output.stream, "%c", f_string_eol_s[0]); } diff --git a/level_3/fss_extended_list_read/data/build/dependencies b/level_3/fss_extended_list_read/data/build/dependencies index cc1beee..7c8767f 100644 --- a/level_3/fss_extended_list_read/data/build/dependencies +++ b/level_3/fss_extended_list_read/data/build/dependencies @@ -23,4 +23,5 @@ fl_string fll_error fll_file fll_fss +fll_print fll_program diff --git a/level_3/fss_extended_list_read/data/build/settings b/level_3/fss_extended_list_read/data/build/settings index 3d551fc..3e60e17 100644 --- a/level_3/fss_extended_list_read/data/build/settings +++ b/level_3/fss_extended_list_read/data/build/settings @@ -20,7 +20,7 @@ build_compiler gcc build_indexer ar build_language c build_libraries -lc -build_libraries-individual -lfll_error -lfll_file -lfll_fss -lfll_program -lfl_console -lfl_conversion -lfl_directory -lfl_fss -lfl_print -lfl_status -lfl_string -lf_color -lf_console -lf_conversion -lf_directory -lf_environment -lf_file -lf_fss -lf_memory -lf_path -lf_pipe -lf_print -lf_string -lf_type_array -lf_utf +build_libraries-individual -lfll_error -lfll_file -lfll_fss -lfll_print -lfll_program -lfl_console -lfl_conversion -lfl_directory -lfl_fss -lfl_print -lfl_status -lfl_string -lf_color -lf_console -lf_conversion -lf_directory -lf_environment -lf_file -lf_fss -lf_memory -lf_path -lf_pipe -lf_print -lf_string -lf_type_array -lf_utf build_libraries-level -lfll_2 -lfll_1 -lfll_0 build_libraries-monolithic -lfll build_sources_library fss_extended_list_read.c private-common.c private-fss_extended_list_read.c @@ -51,7 +51,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_3/fss_extended_read/c/fss_extended_read.c b/level_3/fss_extended_read/c/fss_extended_read.c index 610b176..b66588f 100644 --- a/level_3/fss_extended_read/c/fss_extended_read.c +++ b/level_3/fss_extended_read/c/fss_extended_read.c @@ -9,6 +9,8 @@ extern "C" { #ifndef _di_fss_extended_read_print_help_ f_status_t fss_extended_read_print_help(const f_file_t output, const f_color_context_t context) { + flockfile(output.stream); + fll_program_print_help_header(output, context, fss_extended_read_name_long, fss_extended_read_version); fll_program_print_help_option(output, context, f_console_standard_short_help_s, f_console_standard_long_help_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Print this help message."); @@ -21,7 +23,7 @@ extern "C" { fll_program_print_help_option(output, context, f_console_standard_short_debug_s, f_console_standard_long_debug_s, f_console_symbol_short_disable_s, f_console_symbol_long_disable_s, " Enable debugging, inceasing verbosity beyond normal output."); fll_program_print_help_option(output, context, f_console_standard_short_version_s, f_console_standard_long_version_s, f_console_symbol_short_disable_s, f_console_symbol_long_disable_s, " Print only the version number."); - fprintf(output.stream, "%c", f_string_eol_s[0]); + f_print_character(f_string_eol_s[0], output.stream); fll_program_print_help_option(output, context, fss_extended_read_short_at, fss_extended_read_long_at, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Select Object at this numeric index."); fll_program_print_help_option(output, context, fss_extended_read_short_content, fss_extended_read_long_content, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Print the Content (default)."); @@ -39,153 +41,75 @@ extern "C" { fll_program_print_help_usage(output, context, fss_extended_read_name, "filename(s)"); - f_color_print(output.stream, context.set.important, " Notes:"); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " This program will print the Content associated with the given Object and Content main based on the FSS-0001 Extended standard.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " All numeric positions (indexes) start at 0 instead of 1.%c", f_string_eol_s[0]); - fprintf(output.stream, " For example, a file of 17 lines would range from 0 to 16.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" %[Notes:%]%c", output.stream, context.set.important, context.set.important, f_string_eol_s[0]); - fprintf(output.stream, " When using the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_depth); - fprintf(output.stream, " option, an order of operations is enforced on the parameters.%c", f_string_eol_s[0]); + fl_print_format(" This program will print the Content associated with the given Object and Content main based on the FSS-0001 Extended standard.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " When this order of operations is in effect, parameters to the right of a depth parameter are influenced by that depth parameter:%c", f_string_eol_s[0]); + fl_print_format(" All numeric positions (indexes) start at 0 instead of 1.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" For example, a file of 17 lines would range from 0 to 16.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_at); - fprintf(output.stream, ": An Object index at the specified depth.%c", f_string_eol_s[0]); + fl_print_format(" When using the %[%s%s%] option, an order of operations is enforced on the parameters.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_depth, context.set.notable, f_string_eol_s[0]); - fprintf(output.stream, " "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_depth); - fprintf(output.stream, ": A new depth within the specified depth, indexed from the root.%c", f_string_eol_s[0]); + fl_print_format(" When this order of operations is in effect, parameters to the right of a depth parameter are influenced by that depth parameter:%c", output.stream, f_string_eol_s[0]); - fprintf(output.stream, " "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_name); - fprintf(output.stream, ": An Object name at the specified depth.%c", f_string_eol_s[0]); + fl_print_format(" %[%s%s%]: An Object index at the specified depth.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_at, context.set.notable, f_string_eol_s[0]); + fl_print_format(" %[%s%s%]: A new depth within the specified depth, indexed from the root.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_depth, context.set.notable, f_string_eol_s[0]); + fl_print_format(" %[%s%s%]: An Object name at the specified depth.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_name, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" The parameter %[%s%s%] must be in numeric order, but values in between may be skipped.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_depth, context.set.notable, f_string_eol_s[0]); + fl_print_format(" ('-d 0 -a 1 -d 2 -a 2' would specify index 1 at depth 0, any index at depth 1, and index 2 at depth 2.)%c", output.stream, f_string_eol_s[0]); + fl_print_format(" ('-d 2 -a 1 -d 0 -a 2' would be invalid because depth 2 is before depth 1.)%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " The parameter "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_depth); - fprintf(output.stream, " must be in numeric order, but values in between may be skipped.%c", f_string_eol_s[0]); - fprintf(output.stream, " ('-d 0 -a 1 -d 2 -a 2' would specify index 1 at depth 0, any index at depth 1, and index 2 at depth 2.)%c", f_string_eol_s[0]); - fprintf(output.stream, " ('-d 2 -a 1 -d 0 -a 2' would be invalid because depth 2 is before depth 1.)%c", f_string_eol_s[0]); + fl_print_format(" The parameter %[%s%s%] selects a Content column.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_select, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" Specify both %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_object, context.set.notable); + fl_print_format(" and the %[%s%s%] parameters to get the total objects.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_total, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " The parameter "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_select); - fprintf(output.stream, " selects a Content column.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " Specify both "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_object); - fprintf(output.stream, " and the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_total); - fprintf(output.stream, " parameters to get the total objects.%c", f_string_eol_s[0]); + fl_print_format(" When both %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_at, context.set.notable); + fl_print_format(" and %[%s%s%] parameters are specified (at the same depth),", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_name, context.set.notable); + fl_print_format(" the %[%s%s%] parameter value will be treated as a position relative to the specified", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_at, context.set.notable); + fl_print_format(" %[%s%s%] parameter value.%c%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_name, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" This program may support parameters, such as %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_depth, context.set.notable); + fl_print_format(" or %[%s%s%], even if not supported by the standard.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_select, context.set.notable, f_string_eol_s[0]); + fl_print_format(" This is done to help ensure consistency for scripting.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " When both "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_at); - fprintf(output.stream, " and "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_name); - fprintf(output.stream, " parameters are specified (at the same depth), the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_at); - fprintf(output.stream, " parameter value will be treated as a position relative to the specified "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_name); - fprintf(output.stream, " parameter value.%c", f_string_eol_s[0]); + fl_print_format(" For parameters like %[%s%s%],", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_depth, context.set.notable); + fl_print_format(" if the standard doesn't support nested Content, then only a depth of 0 would be valid.%c", output.stream, f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" For parameters like %[%s%s%],", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_select, context.set.notable); + fl_print_format(" if the standard doesn't support multiple Content groups, then only a select of 0 would be valid.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " This program may support parameters, such as "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_depth); - fprintf(output.stream, " or "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_select); - fprintf(output.stream, ", even if not supported by the standard.%c", f_string_eol_s[0]); - fprintf(output.stream, " This is done to help ensure consistency for scripting.%c", f_string_eol_s[0]); + fl_print_format(" The parameter %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_trim, context.set.notable); + fl_print_format(" will remove leading and trailing whitespaces when selecting objects or when printing objects.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" When specifying both the %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_object, context.set.notable); + fl_print_format(" parameter and the %[%s%s%] parameter, the entire Object and Content are printed, including the formatting.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_content, context.set.notable, f_string_eol_s[0]); + fl_print_format(" Both the Object and Content printed are already escaped.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" Both the Object and Content are separated by a space.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " For parameters like "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_depth); - fprintf(output.stream, ", if the standard doesn't support nested Content, then only a depth of 0 would be valid.%c", f_string_eol_s[0]); + fl_print_format(" The parameter %[%s%s%] accepts the following:%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_delimit, context.set.notable, f_string_eol_s[0]); + fl_print_format(" - %[%s%]: Do not apply delimits.%c", output.stream, context.set.notable, fss_extended_read_delimit_mode_name_none, context.set.notable, f_string_eol_s[0]); + fl_print_format(" - %[%s%]: (default) Apply all delimits.%c", output.stream, context.set.notable, fss_extended_read_delimit_mode_name_all, context.set.notable, f_string_eol_s[0]); + fl_print_format(" - %[%s%]: Apply delimits for Objects.%c", output.stream, context.set.notable, fss_extended_read_delimit_mode_name_object, context.set.notable, f_string_eol_s[0]); + fl_print_format(" - A number, 0 or greater: apply delimits for Content at the specified depth.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" - A number, 0 or greater, followed by a %[%s%]: (such as '1+') apply delimits for Content at the specified depth and any greater depth (numerically).%c", output.stream, context.set.notable, fss_extended_read_delimit_mode_name_greater, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); + fl_print_format(" - A number, 0 or lesser, followed by a %[%s%]: (such as '1-') apply delimits for Content at the specified depth and any lesser depth (numerically).%c%c", output.stream, context.set.notable, fss_extended_read_delimit_mode_name_lesser, context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " For parameters like "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_select); - fprintf(output.stream, ", if the standard doesn't support multiple Content groups, then only a select of 0 would be valid.%c", f_string_eol_s[0]); + fl_print_format(" The %[%s%s%] parameter may be specified multiple times to customize the delimit behavior.%c", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_delimit, context.set.notable, f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); + fl_print_format(" The %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_delimit, context.set.notable); + fl_print_format(" values %[%s%]", output.stream, context.set.notable, fss_extended_read_delimit_mode_name_none, context.set.notable); + fl_print_format(" and %[%s%],", output.stream, context.set.notable, fss_extended_read_delimit_mode_name_all, context.set.notable); + fl_print_format(" overrule all other delimit values.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, " The parameter "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_trim); - fprintf(output.stream, " will remove leading and trailing whitespaces when selecting objects or when printing objects.%c", f_string_eol_s[0]); + fl_print_format(" The parameters %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_columns, context.set.notable); + fl_print_format(" and %[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, fss_extended_read_long_select, context.set.notable); + fl_print_format(" refer to a Content column.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" The word \"column\" is being loosely defined to refer to a specific Content.%c", output.stream, f_string_eol_s[0]); + fl_print_format(" This is not to be confused with a depth.%c%c", output.stream, f_string_eol_s[0], f_string_eol_s[0]); - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " When specifying both the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_object); - fprintf(output.stream, " parameter and the "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_content); - fprintf(output.stream, " parameter, the entire Object and Content are printed, including the formatting.%c", f_string_eol_s[0]); - fprintf(output.stream, " Both the Object and Content printed are already escaped.%c", f_string_eol_s[0]); - fprintf(output.stream, " Both the Object and Content are separated by a space.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " The parameter "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_delimit); - fprintf(output.stream, " accepts the following:%c", f_string_eol_s[0]); - fprintf(output.stream, " - "); - f_color_print(output.stream, context.set.notable, "%s", fss_extended_read_delimit_mode_name_none); - fprintf(output.stream, ": Do not apply delimits.%c", f_string_eol_s[0]); - fprintf(output.stream, " - "); - f_color_print(output.stream, context.set.notable, "%s", fss_extended_read_delimit_mode_name_all); - fprintf(output.stream, ": (default) Apply all delimits.%c", f_string_eol_s[0]); - fprintf(output.stream, " - "); - f_color_print(output.stream, context.set.notable, "%s", fss_extended_read_delimit_mode_name_object); - fprintf(output.stream, ": Apply delimits for Objects.%c", f_string_eol_s[0]); - fprintf(output.stream, " - A number, 0 or greater: apply delimits for Content at the specified depth.%c", f_string_eol_s[0]); - fprintf(output.stream, " - A number, 0 or greater, followed by a "); - f_color_print(output.stream, context.set.notable, "%s", fss_extended_read_delimit_mode_name_greater); - fprintf(output.stream, ": (such as '1+') apply delimits for Content at the specified depth and any greater depth (numerically).%c", f_string_eol_s[0]); - fprintf(output.stream, " - A number, 0 or greater, followed by a "); - f_color_print(output.stream, context.set.notable, "%s", fss_extended_read_delimit_mode_name_lesser); - fprintf(output.stream, ": (such as '1-') apply delimits for Content at the specified depth and any lesser depth (numerically).%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " The "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_delimit); - fprintf(output.stream, " parameter may be specified multiple times to customize the delimit behavior.%c", f_string_eol_s[0]); - - fprintf(output.stream, " The "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_delimit); - fprintf(output.stream, " values "); - f_color_print(output.stream, context.set.notable, "%s", fss_extended_read_delimit_mode_name_none); - fprintf(output.stream, " and "); - f_color_print(output.stream, context.set.notable, "%s", fss_extended_read_delimit_mode_name_all); - fprintf(output.stream, ", overrule all other delimit values.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); - - fprintf(output.stream, " The parameters "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_columns); - fprintf(output.stream, " and "); - f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_select); - fprintf(output.stream, " refer to a Content column.%c", f_string_eol_s[0]); - fprintf(output.stream, " The word \"column\" is being loosely defined to refer to a specific Content.%c", f_string_eol_s[0]); - fprintf(output.stream, " This is not to be confused with a depth.%c", f_string_eol_s[0]); - - fprintf(output.stream, "%c", f_string_eol_s[0]); + funlockfile(output.stream); return F_none; } @@ -207,9 +131,12 @@ extern "C" { if (main->context.set.error.before) { main->error.context = main->context.set.error; main->error.notable = main->context.set.notable; + + main->warning.context = main->context.set.warning; + main->warning.notable = main->context.set.notable; } else { - f_color_set_t *sets[] = { &main->error.context, &main->error.notable, 0 }; + f_color_set_t *sets[] = { &main->error.context, &main->error.notable, &main->warning.context, &main->warning.notable, 0 }; fll_program_parameter_process_empty(&main->context, sets); } @@ -237,15 +164,19 @@ extern "C" { if (choice == fss_extended_read_parameter_verbosity_quiet) { main->error.verbosity = f_console_verbosity_quiet; + main->warning.verbosity = f_console_verbosity_quiet; } else if (choice == fss_extended_read_parameter_verbosity_normal) { main->error.verbosity = f_console_verbosity_normal; + main->warning.verbosity = f_console_verbosity_normal; } else if (choice == fss_extended_read_parameter_verbosity_verbose) { main->error.verbosity = f_console_verbosity_verbose; + main->warning.verbosity = f_console_verbosity_verbose; } else if (choice == fss_extended_read_parameter_verbosity_debug) { main->error.verbosity = f_console_verbosity_debug; + main->warning.verbosity = f_console_verbosity_debug; } } @@ -310,9 +241,13 @@ extern "C" { for (f_array_length_t i = 0; i < 6; ++i) { if (main->parameters[parameter_code[i]].result == f_console_result_found) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe parameter '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, parameter_name[i]); - f_color_print(main->error.to.stream, main->context.set.error, "' requires a %s.%c", parameter_message[i], f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, parameter_name[i], main->error.notable); + fl_print_format("%[' requires a %s.%]%c", main->error.to.stream, main->error.context, parameter_message[i], main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); break; @@ -348,11 +283,15 @@ extern "C" { for (f_array_length_t i = 0; i < 5; ++i) { if (main->parameters[parameter_code[i]].result == parameter_match[i]) { - f_color_print(main->error.to.stream, main->context.set.error, "%sCannot specify the '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_columns); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter with the '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, parameter_name[i]); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sCannot specify the '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_extended_read_long_columns, main->error.notable); + fl_print_format("%[' parameter with the '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, parameter_name[i], main->error.notable); + fl_print_format("%[' parameter.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); break; @@ -362,20 +301,28 @@ extern "C" { if (F_status_is_error_not(status) && main->parameters[fss_extended_read_parameter_pipe].result == f_console_result_found) { if (main->parameters[fss_extended_read_parameter_total].result == f_console_result_found) { - f_color_print(main->error.to.stream, main->context.set.error, "%sCannot specify the '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_pipe); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter with the '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_total); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sCannot specify the '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_extended_read_long_pipe, main->error.notable); + fl_print_format("%[' parameter with the '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_extended_read_long_total, main->error.notable); + fl_print_format("%[' parameter.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); } else if (main->parameters[fss_extended_read_parameter_line].result == f_console_result_additional) { - f_color_print(main->error.to.stream, main->context.set.error, "%sCannot specify the '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_pipe); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter with the '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_line); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sCannot specify the '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_extended_read_long_pipe, main->error.notable); + fl_print_format("%[' parameter with the '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_extended_read_long_line, main->error.notable); + fl_print_format("%[' parameter.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); } @@ -394,9 +341,13 @@ extern "C" { length = strnlen(arguments->argv[location], f_console_parameter_size); if (!length) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe value for the parameter '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_delimit); - f_color_print(main->error.to.stream, main->context.set.error, "' must not be empty.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe value for the parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_extended_read_long_delimit, main->error.notable); + fl_print_format("%[' must not be empty.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); status = F_status_set_error(F_parameter); break; @@ -522,9 +473,13 @@ extern "C" { } if (F_status_is_error_not(status) && main->parameters[fss_extended_read_parameter_select].result == f_console_result_found) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_select); - f_color_print(main->error.to.stream, main->context.set.error, "' parameter requires a positive number.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_extended_read_long_select, main->error.notable); + fl_print_format("%[' parameter requires a positive number.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); fss_extended_read_depths_resize(0, &data.depths); @@ -640,7 +595,7 @@ extern "C" { fss_extended_read_data_delete_simple(&data); } else { - f_color_print(main->error.to.stream, main->context.set.error, "%sYou failed to specify one or more files.%c", fll_error_print_error, f_string_eol_s[0]); + fll_print_format("%c%[%sYou failed to specify one or more files.%]%c", main->error.to.stream, main->error.context, main->error.prefix, main->error.context, f_string_eol_s[0]); status = F_status_set_error(F_parameter); } diff --git a/level_3/fss_extended_read/c/fss_extended_read.h b/level_3/fss_extended_read/c/fss_extended_read.h index 9c890ef..88ae98d 100644 --- a/level_3/fss_extended_read/c/fss_extended_read.h +++ b/level_3/fss_extended_read/c/fss_extended_read.h @@ -43,6 +43,7 @@ #include #include #include +#include #include #ifdef __cplusplus @@ -207,6 +208,7 @@ extern "C" { f_file_t output; fll_error_print_t error; + fll_error_print_t warning; f_color_context_t context; } fss_extended_read_main_t; @@ -218,6 +220,7 @@ extern "C" { F_false, \ macro_f_file_t_initialize2(f_type_output, f_type_descriptor_output, f_file_flag_write_only), \ fll_error_print_t_initialize, \ + macro_fll_error_print_t_initialize_warning(), \ f_color_context_t_initialize, \ } #endif // _di_fss_extended_read_main_t_ diff --git a/level_3/fss_extended_read/c/private-fss_extended_read.c b/level_3/fss_extended_read/c/private-fss_extended_read.c index 779a7ea..a0db80c 100644 --- a/level_3/fss_extended_read/c/private-fss_extended_read.c +++ b/level_3/fss_extended_read/c/private-fss_extended_read.c @@ -166,9 +166,13 @@ extern "C" { if (!data->depths.array[i].value_name.used) { if (main->error.verbosity != f_console_verbosity_quiet) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_name); - f_color_print(main->error.to.stream, main->context.set.error, "' must not be an empty string.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_extended_read_long_name, main->error.notable); + fl_print_format("%[' must not be an empty string.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); } return F_status_set_error(F_parameter); @@ -183,24 +187,32 @@ extern "C" { if (data->depths.array[i].depth == data->depths.array[j].depth) { if (main->error.verbosity != f_console_verbosity_quiet) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe value '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%llu", data->depths.array[i].depth); - f_color_print(main->error.to.stream, main->context.set.error, "' may only be specified once for the parameter '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_depth); - f_color_print(main->error.to.stream, main->context.set.error, "'.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe value '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%ul%]", main->error.to.stream, main->error.notable, data->depths.array[i].depth, main->error.notable); + fl_print_format("%[' may only be specified once for the parameter '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_extended_read_long_depth, main->error.notable); + fl_print_format("%['.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); } return F_status_set_error(F_parameter); } else if (data->depths.array[i].depth > data->depths.array[j].depth) { if (main->error.verbosity != f_console_verbosity_quiet) { - f_color_print(main->error.to.stream, main->context.set.error, "%sThe parameter '", fll_error_print_error); - f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_extended_read_long_depth); - f_color_print(main->error.to.stream, main->context.set.error, "' may not have the value '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%llu", data->depths.array[i].depth); - f_color_print(main->error.to.stream, main->context.set.error, "' before the value '"); - f_color_print(main->error.to.stream, main->context.set.notable, "%llu", data->depths.array[j].depth); - f_color_print(main->error.to.stream, main->context.set.error, "'.%c", f_string_eol_s[0]); + flockfile(main->error.to.stream); + + fl_print_format("%c%[%sThe parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_extended_read_long_depth, main->error.notable); + fl_print_format("%[' may not have the value '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%ul%]", main->error.to.stream, main->error.notable, data->depths.array[i].depth, main->error.notable); + fl_print_format("%[' before the value '%]", main->error.to.stream, main->error.context, main->error.context); + fl_print_format("%[%ul%]", main->error.to.stream, main->error.notable, data->depths.array[j].depth, main->error.notable); + fl_print_format("%['.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + + funlockfile(main->error.to.stream); } return F_status_set_error(F_parameter); @@ -287,13 +299,15 @@ extern "C" { return; } + flockfile(main->output.stream); + if ((data->option & fss_extended_read_data_option_object) || (data->option & fss_extended_read_data_option_content) && (data->contents.array[at].used || (data->option & fss_extended_read_data_option_empty))) { if (data->option & fss_extended_read_data_option_object) { if (data->option & fss_extended_read_data_option_trim) { - fl_print_trim_except_dynamic_partial(main->output.stream, data->buffer, data->objects.array[at], delimits_object); + fl_print_trim_except_dynamic_partial(data->buffer, data->objects.array[at], delimits_object, main->output.stream); } else { - f_print_except_dynamic_partial(main->output.stream, data->buffer, data->objects.array[at], delimits_object); + f_print_except_dynamic_partial(data->buffer, data->objects.array[at], delimits_object, main->output.stream); } if (data->option & fss_extended_read_data_option_content) { @@ -308,7 +322,7 @@ extern "C" { if (data->select < data->contents.array[at].used) { content_printed = F_true; - f_print_except_dynamic_partial(main->output.stream, data->buffer, data->contents.array[at].array[data->select], delimits_content); + f_print_except_dynamic_partial(data->buffer, data->contents.array[at].array[data->select], delimits_content, main->output.stream); } } else { @@ -320,7 +334,7 @@ extern "C" { content_printed = F_true; - f_print_except_dynamic_partial(main->output.stream, data->buffer, data->contents.array[at].array[i], delimits_content); + f_print_except_dynamic_partial(data->buffer, data->contents.array[at].array[i], delimits_content, main->output.stream); if (i + 1 < data->contents.array[at].used && data->contents.array[at].array[i + 1].start <= data->contents.array[at].array[i + 1].stop) { fss_extended_read_print_content_end(main); @@ -332,6 +346,8 @@ extern "C" { if ((data->option & fss_extended_read_data_option_object) || (data->option & fss_extended_read_data_option_content) && (content_printed || (data->option & fss_extended_read_data_option_empty))) { fss_extended_read_print_set_end(main); } + + funlockfile(main->output.stream); } } #endif // _di_fss_extended_read_print_at_ @@ -378,10 +394,10 @@ extern "C" { void fss_extended_read_print_content_end(fss_extended_read_main_t * const main) { if (main->parameters[fss_extended_read_parameter_pipe].result == f_console_result_found) { - fprintf(main->output.stream, "%c", fss_extended_read_pipe_content_start); + f_print_character(fss_extended_read_pipe_content_start, main->output.stream); } else { - fprintf(main->output.stream, "%c", f_fss_space); + f_print_character(f_fss_space, main->output.stream); } } #endif // _di_fss_extended_read_print_content_end_ @@ -390,17 +406,18 @@ extern "C" { void fss_extended_read_print_object_end(fss_extended_read_main_t * const main) { if (main->parameters[fss_extended_read_parameter_pipe].result == f_console_result_found) { - fprintf(main->output.stream, "%c", fss_extended_read_pipe_content_end); + f_print_character(fss_extended_read_pipe_content_end, main->output.stream); } else { - fprintf(main->output.stream, "%c", f_fss_space); + f_print_character(f_fss_space, main->output.stream); } } #endif // _di_fss_extended_read_print_object_end_ #ifndef _di_fss_extended_read_print_one_ void fss_extended_read_print_one(fss_extended_read_main_t * const main) { - fprintf(main->output.stream, "1%c", f_string_eol_s[0]); + f_print_character(f_string_ascii_1_s[0], main->output.stream); + f_print_character(f_string_eol_s[0], main->output.stream); } #endif // _di_fss_extended_read_print_one_ @@ -408,17 +425,19 @@ extern "C" { void fss_extended_read_print_set_end(fss_extended_read_main_t * const main) { if (main->parameters[fss_extended_read_parameter_pipe].result == f_console_result_found) { - fprintf(main->output.stream, "%c", fss_extended_read_pipe_content_end); + f_print_character(fss_extended_read_pipe_content_end, main->output.stream); } else { fprintf(main->output.stream, "%c", f_fss_eol); + f_print_character(f_fss_eol, main->output.stream); } } #endif // _di_fss_extended_read_print_set_end_ #ifndef _di_fss_extended_read_print_zero_ void fss_extended_read_print_zero(fss_extended_read_main_t * const main) { - fprintf(main->output.stream, "0%c", f_string_eol_s[0]); + f_print_character(f_string_ascii_0_s[0], main->output.stream); + f_print_character(f_string_eol_s[0], main->output.stream); } #endif // _di_fss_extended_read_print_zero_ diff --git a/level_3/fss_extended_read/data/build/dependencies b/level_3/fss_extended_read/data/build/dependencies index d11524b..7c8767f 100644 --- a/level_3/fss_extended_read/data/build/dependencies +++ b/level_3/fss_extended_read/data/build/dependencies @@ -14,8 +14,8 @@ f_file f_fss f_pipe f_print -fl_conversion fl_console +fl_conversion fl_fss fl_print fl_status @@ -23,4 +23,5 @@ fl_string fll_error fll_file fll_fss +fll_print fll_program diff --git a/level_3/fss_extended_read/data/build/settings b/level_3/fss_extended_read/data/build/settings index 692e6bc..aa25095 100644 --- a/level_3/fss_extended_read/data/build/settings +++ b/level_3/fss_extended_read/data/build/settings @@ -20,7 +20,7 @@ build_compiler gcc build_indexer ar build_language c build_libraries -lc -build_libraries-individual -lfll_error -lfll_file -lfll_fss -lfll_program -lfl_console -lfl_conversion -lfl_directory -lfl_fss -lfl_print -lfl_status -lfl_string -lf_color -lf_console -lf_conversion -lf_directory -lf_environment -lf_file -lf_fss -lf_memory -lf_path -lf_pipe -lf_print -lf_string -lf_type_array -lf_utf +build_libraries-individual -lfll_error -lfll_file -lfll_fss -lfll_print -lfll_program -lfl_console -lfl_conversion -lfl_directory -lfl_fss -lfl_print -lfl_status -lfl_string -lf_color -lf_console -lf_conversion -lf_directory -lf_environment -lf_file -lf_fss -lf_memory -lf_path -lf_pipe -lf_print -lf_string -lf_type_array -lf_utf build_libraries-level -lfll_2 -lfll_1 -lfll_0 build_libraries-monolithic -lfll build_sources_library fss_extended_read.c private-common.c private-fss_extended_read.c @@ -51,7 +51,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC -- 1.8.3.1