From a1297f3644244dfab64f60c7acaaf5733a8a184b Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 8 Sep 2019 18:44:14 -0500 Subject: [PATCH] Cleanup: move private functions into separate files --- .../fss_basic_list_read/c/fss_basic_list_read.c | 287 +------------------- .../c/private-fss_basic_list_read.c | 288 +++++++++++++++++++++ .../c/private-fss_basic_list_read.h | 23 ++ level_3/fss_basic_list_read/data/build/settings | 2 +- level_3/fss_basic_read/c/fss_basic_read.c | 182 +------------ level_3/fss_basic_read/c/private-fss_basic_read.c | 183 +++++++++++++ level_3/fss_basic_read/c/private-fss_basic_read.h | 23 ++ level_3/fss_basic_read/data/build/settings | 2 +- level_3/fss_extended_read/c/fss_extended_read.c | 185 +------------ .../c/private-fss_extended_read.c | 186 +++++++++++++ .../c/private-fss_extended_read.h | 23 ++ level_3/fss_extended_read/data/build/settings | 2 +- 12 files changed, 732 insertions(+), 654 deletions(-) create mode 100644 level_3/fss_basic_list_read/c/private-fss_basic_list_read.c create mode 100644 level_3/fss_basic_list_read/c/private-fss_basic_list_read.h create mode 100644 level_3/fss_basic_read/c/private-fss_basic_read.c create mode 100644 level_3/fss_basic_read/c/private-fss_basic_read.h create mode 100644 level_3/fss_extended_read/c/private-fss_extended_read.c create mode 100644 level_3/fss_extended_read/c/private-fss_extended_read.h 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 5e44f23..b8d551e 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 @@ -1,4 +1,5 @@ #include +#include "private-fss_basic_list_read.h" #ifdef __cplusplus extern "C" { @@ -30,8 +31,6 @@ extern "C" { #endif // _di_fss_basic_list_read_print_help_ #ifndef _di_fss_basic_list_read_main_ - f_return_status fss_basic_list_read_main_process_file(const f_console_arguments arguments, fss_basic_list_read_data *data, const f_string filename, const f_string_length target) __attribute__((visibility ("internal"))); - f_return_status fss_basic_list_read_main(const f_console_arguments arguments, fss_basic_list_read_data *data) { f_status status = f_none; @@ -206,290 +205,6 @@ extern "C" { fss_basic_list_read_delete_data(data); return status; } - - f_return_status fss_basic_list_read_main_process_file(const f_console_arguments arguments, fss_basic_list_read_data *data, const f_string filename, const f_string_length target) { - f_status status = f_none; - f_status status2 = f_none; - - f_string_length current = 0; - f_string_length found = 0; - - { - f_string_location input = f_string_location_initialize; - - input.start = 0; - input.stop = data->buffer.used - 1; - - status = fll_fss_basic_list_read(&data->buffer, &input, &data->objects, &data->contents); - - if (f_status_is_error(status)) { - status = f_status_set_fine(status); - - if (status == f_invalid_parameter) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fll_fss_basic_list_read() for the file '%s'", filename); - } - else if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - } - else if (status == f_incomplete_utf_on_stop) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: error occured on invalid UTF-8 character at stop position (at %d).", input.start); - } - else if (status == f_incomplete_utf_on_eos) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: error occured on invalid UTF-8 character at end of string (at %d).", input.start); - } - else { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_basic_list_read() for the file '%s'", f_status_set_error(status), filename); - } - - fss_basic_list_read_delete_data(data); - return f_status_set_error(status); - } - else if (status == f_no_data_on_stop || status == f_no_data_on_eos) { - // clear buffers, then attempt the next file - f_macro_fss_contents_delete(status2, data->contents); - f_macro_fss_objects_delete(status2, data->objects); - f_macro_string_dynamic_delete(status2, data->buffer); - - return f_status_set_warning(status); - } - } - - // now that all of the files have been read, process the objects and contents - if (data->parameters[fss_basic_list_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_list_read_parameter_name].result == f_console_result_none) { - fprintf(f_standard_output, "%u\n", (unsigned int) data->objects.used); - } - else { - current = 0; - - if (data->parameters[fss_basic_list_read_parameter_name].result == f_console_result_none) { - if (data->parameters[fss_basic_list_read_parameter_object].result == f_console_result_none) { - for (; current < data->objects.used; current++) { - if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional && found == target)) { - - if (data->parameters[fss_basic_list_read_parameter_size].result == f_console_result_found) { - if (data->contents.array[current].used > 0) { - f_string_length counter = data->contents.array[current].array[0].start; - f_string_length size = 0; - - for (; counter <= data->contents.array[current].array[0].stop; counter++) { - if (data->buffer.string[counter] == f_string_eol) size++; - } // for - - // the last newline is never present - size++; - - fprintf(f_standard_output, "%u\n", (unsigned int) size); - } - else { - fprintf(f_standard_output, "0\n"); - } - } - else if (data->parameters[fss_basic_list_read_parameter_line].result == f_console_result_additional) { - if (data->contents.array[current].used > 0) { - f_string_length counter = data->contents.array[current].array[0].start; - f_string_length position = 0; - f_string_length target = (f_string_length) atoll(arguments.argv[data->parameters[fss_basic_list_read_parameter_line].additional.array[0]]); - f_string_location range = f_string_location_initialize; - - // use an invalid range to communicate range not found - range.start = 1; - range.stop = 0; - - for (; counter <= data->contents.array[current].array[0].stop; counter++) { - if (position == target) { - range.start = counter; - - // explicit use of < instead of <= is done here so that the range.stop will always be accurate - for (; counter < data->contents.array[current].array[0].stop; counter++) { - if (data->buffer.string[counter] == f_string_eol) { - break; - } - } // for - - range.stop = counter; - break; - } - - if (data->buffer.string[counter] == f_string_eol) { - position++; - } - } // for - - if (range.start <= range.stop) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, range); - } - } - } - else { - if (data->contents.array[current].used > 0) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->contents.array[current].array[0]); - fprintf(f_standard_output, "\n"); - } - } - } - - if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional) { - if (found == target) { - break; - } - else { - found++; - } - } - } // for - } - else { - for (; current < data->objects.used; current++) { - if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional && found == target)) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[current]); - fprintf(f_standard_output, "\n"); - } - - if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional) { - if (found == target) { - break; - } - else { - found++; - } - } - } // for - } - } - else { - current = 0; - - f_string_length total = 0; - f_string_length name_length = 0; - f_string_length argv_length = 0; - - if (data->parameters[fss_basic_list_read_parameter_name].result == f_console_result_additional) { - argv_length = strlen(arguments.argv[data->parameters[fss_basic_list_read_parameter_name].additional.array[0]]); - - if (data->parameters[fss_basic_list_read_parameter_object].result == f_console_result_none) { - for (; current < data->objects.used; current++) { - name_length = data->objects.array[current].stop - data->objects.array[current].start + 1; - - if (name_length == argv_length) { - if (fl_string_compare(data->buffer.string + data->objects.array[current].start, arguments.argv[data->parameters[fss_basic_list_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) { - - if (data->parameters[fss_basic_list_read_parameter_size].result == f_console_result_found) { - if (data->contents.array[current].used > 0) { - f_string_length counter = data->contents.array[current].array[0].start; - f_string_length size = 0; - - for (; counter <= data->contents.array[current].array[0].stop; counter++) { - if (data->buffer.string[counter] == f_string_eol) size++; - } // for - - // the last newline is never present - size++; - - fprintf(f_standard_output, "%u\n", (unsigned int) size); - } - else { - fprintf(f_standard_output, "0\n"); - } - } - else if (data->parameters[fss_basic_list_read_parameter_line].result == f_console_result_additional) { - if (data->contents.array[current].used > 0) { - f_string_length counter = data->contents.array[current].array[0].start; - f_string_length position = 0; - f_string_length target = (f_string_length) atoll(arguments.argv[data->parameters[fss_basic_list_read_parameter_line].additional.array[0]]); - f_string_location range = f_string_location_initialize; - - // use an invalid range to communicate range not found - range.start = 1; - range.stop = 0; - - for (; counter <= data->contents.array[current].array[0].stop; counter++) { - if (position == target) { - range.start = counter; - - // explicit use of < instead of <= is done here so that the range.stop will always be accurate - for (; counter < data->contents.array[current].array[0].stop; counter++) { - if (data->buffer.string[counter] == f_string_eol) { - break; - } - } // for - - range.stop = counter; - break; - } - - if (data->buffer.string[counter] == f_string_eol) { - position++; - } - } // for - - if (range.start <= range.stop) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, range); - } - } - } - else { - if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional && found == target)) { - if (data->parameters[fss_basic_list_read_parameter_total].result == f_console_result_found) { - total++; - } - else { - if (data->contents.array[current].used > 0) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->contents.array[current].array[0]); - fprintf(f_standard_output, "\n"); - } - } - } - } - - if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional) { - if (found == target) { - break; - } - else { - found++; - } - } - } - } - } // for - - if (data->parameters[fss_basic_list_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none) { - fprintf(f_standard_output, f_string_length_printf "\n", total); - } - } - else { - // when and because the object parameter is specified, the name parameter refers to the content instead of the object - // therefore, make the search on the content and display the object - for (; current < data->contents.used; current++) { - if (data->contents.array[current].used > 0) { - name_length = data->contents.array[current].array[0].stop - data->contents.array[current].array[0].start + 1; - - if (name_length == argv_length) { - if (fl_string_compare(data->buffer.string + data->contents.array[current].array[0].start, arguments.argv[data->parameters[fss_basic_list_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) { - if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional && found == target)) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[current]); - fprintf(f_standard_output, "\n"); - } - - if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional) { - if (found == target) { - break; - } - else { - found++; - } - } - } - } - } - } // for - } - } - } - } - - return f_none; - } #endif // _di_fss_basic_list_read_main_ #ifndef _di_fss_basic_list_read_delete_data_ 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 new file mode 100644 index 0000000..789eeb4 --- /dev/null +++ b/level_3/fss_basic_list_read/c/private-fss_basic_list_read.c @@ -0,0 +1,288 @@ +#include +#include "private-fss_basic_list_read.h" + +#ifndef _di_fss_basic_list_read_main_process_file_ + f_return_status fss_basic_list_read_main_process_file(const f_console_arguments arguments, fss_basic_list_read_data *data, const f_string filename, const f_string_length target) { + f_status status = f_none; + f_status status2 = f_none; + + f_string_length current = 0; + f_string_length found = 0; + + { + f_string_location input = f_string_location_initialize; + + input.start = 0; + input.stop = data->buffer.used - 1; + + status = fll_fss_basic_list_read(&data->buffer, &input, &data->objects, &data->contents); + + if (f_status_is_error(status)) { + status = f_status_set_fine(status); + + if (status == f_invalid_parameter) { + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fll_fss_basic_list_read() for the file '%s'", filename); + } + else if (status == f_allocation_error || status == f_reallocation_error) { + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); + } + else if (status == f_incomplete_utf_on_stop) { + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: error occured on invalid UTF-8 character at stop position (at %d).", input.start); + } + else if (status == f_incomplete_utf_on_eos) { + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: error occured on invalid UTF-8 character at end of string (at %d).", input.start); + } + else { + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_basic_list_read() for the file '%s'", f_status_set_error(status), filename); + } + + fss_basic_list_read_delete_data(data); + return f_status_set_error(status); + } + else if (status == f_no_data_on_stop || status == f_no_data_on_eos) { + // clear buffers, then attempt the next file + f_macro_fss_contents_delete(status2, data->contents); + f_macro_fss_objects_delete(status2, data->objects); + f_macro_string_dynamic_delete(status2, data->buffer); + + return f_status_set_warning(status); + } + } + + // now that all of the files have been read, process the objects and contents + if (data->parameters[fss_basic_list_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_list_read_parameter_name].result == f_console_result_none) { + fprintf(f_standard_output, "%u\n", (unsigned int) data->objects.used); + } + else { + current = 0; + + if (data->parameters[fss_basic_list_read_parameter_name].result == f_console_result_none) { + if (data->parameters[fss_basic_list_read_parameter_object].result == f_console_result_none) { + for (; current < data->objects.used; current++) { + if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional && found == target)) { + + if (data->parameters[fss_basic_list_read_parameter_size].result == f_console_result_found) { + if (data->contents.array[current].used > 0) { + f_string_length counter = data->contents.array[current].array[0].start; + f_string_length size = 0; + + for (; counter <= data->contents.array[current].array[0].stop; counter++) { + if (data->buffer.string[counter] == f_string_eol) size++; + } // for + + // the last newline is never present + size++; + + fprintf(f_standard_output, "%u\n", (unsigned int) size); + } + else { + fprintf(f_standard_output, "0\n"); + } + } + else if (data->parameters[fss_basic_list_read_parameter_line].result == f_console_result_additional) { + if (data->contents.array[current].used > 0) { + f_string_length counter = data->contents.array[current].array[0].start; + f_string_length position = 0; + f_string_length target = (f_string_length) atoll(arguments.argv[data->parameters[fss_basic_list_read_parameter_line].additional.array[0]]); + f_string_location range = f_string_location_initialize; + + // use an invalid range to communicate range not found + range.start = 1; + range.stop = 0; + + for (; counter <= data->contents.array[current].array[0].stop; counter++) { + if (position == target) { + range.start = counter; + + // explicit use of < instead of <= is done here so that the range.stop will always be accurate + for (; counter < data->contents.array[current].array[0].stop; counter++) { + if (data->buffer.string[counter] == f_string_eol) { + break; + } + } // for + + range.stop = counter; + break; + } + + if (data->buffer.string[counter] == f_string_eol) { + position++; + } + } // for + + if (range.start <= range.stop) { + f_print_string_dynamic_partial(f_standard_output, data->buffer, range); + } + } + } + else { + if (data->contents.array[current].used > 0) { + f_print_string_dynamic_partial(f_standard_output, data->buffer, data->contents.array[current].array[0]); + fprintf(f_standard_output, "\n"); + } + } + } + + if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional) { + if (found == target) { + break; + } + else { + found++; + } + } + } // for + } + else { + for (; current < data->objects.used; current++) { + if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional && found == target)) { + f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[current]); + fprintf(f_standard_output, "\n"); + } + + if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional) { + if (found == target) { + break; + } + else { + found++; + } + } + } // for + } + } + else { + current = 0; + + f_string_length total = 0; + f_string_length name_length = 0; + f_string_length argv_length = 0; + + if (data->parameters[fss_basic_list_read_parameter_name].result == f_console_result_additional) { + argv_length = strlen(arguments.argv[data->parameters[fss_basic_list_read_parameter_name].additional.array[0]]); + + if (data->parameters[fss_basic_list_read_parameter_object].result == f_console_result_none) { + for (; current < data->objects.used; current++) { + name_length = data->objects.array[current].stop - data->objects.array[current].start + 1; + + if (name_length == argv_length) { + if (fl_string_compare(data->buffer.string + data->objects.array[current].start, arguments.argv[data->parameters[fss_basic_list_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) { + + if (data->parameters[fss_basic_list_read_parameter_size].result == f_console_result_found) { + if (data->contents.array[current].used > 0) { + f_string_length counter = data->contents.array[current].array[0].start; + f_string_length size = 0; + + for (; counter <= data->contents.array[current].array[0].stop; counter++) { + if (data->buffer.string[counter] == f_string_eol) size++; + } // for + + // the last newline is never present + size++; + + fprintf(f_standard_output, "%u\n", (unsigned int) size); + } + else { + fprintf(f_standard_output, "0\n"); + } + } + else if (data->parameters[fss_basic_list_read_parameter_line].result == f_console_result_additional) { + if (data->contents.array[current].used > 0) { + f_string_length counter = data->contents.array[current].array[0].start; + f_string_length position = 0; + f_string_length target = (f_string_length) atoll(arguments.argv[data->parameters[fss_basic_list_read_parameter_line].additional.array[0]]); + f_string_location range = f_string_location_initialize; + + // use an invalid range to communicate range not found + range.start = 1; + range.stop = 0; + + for (; counter <= data->contents.array[current].array[0].stop; counter++) { + if (position == target) { + range.start = counter; + + // explicit use of < instead of <= is done here so that the range.stop will always be accurate + for (; counter < data->contents.array[current].array[0].stop; counter++) { + if (data->buffer.string[counter] == f_string_eol) { + break; + } + } // for + + range.stop = counter; + break; + } + + if (data->buffer.string[counter] == f_string_eol) { + position++; + } + } // for + + if (range.start <= range.stop) { + f_print_string_dynamic_partial(f_standard_output, data->buffer, range); + } + } + } + else { + if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional && found == target)) { + if (data->parameters[fss_basic_list_read_parameter_total].result == f_console_result_found) { + total++; + } + else { + if (data->contents.array[current].used > 0) { + f_print_string_dynamic_partial(f_standard_output, data->buffer, data->contents.array[current].array[0]); + fprintf(f_standard_output, "\n"); + } + } + } + } + + if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional) { + if (found == target) { + break; + } + else { + found++; + } + } + } + } + } // for + + if (data->parameters[fss_basic_list_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none) { + fprintf(f_standard_output, f_string_length_printf "\n", total); + } + } + else { + // when and because the object parameter is specified, the name parameter refers to the content instead of the object + // therefore, make the search on the content and display the object + for (; current < data->contents.used; current++) { + if (data->contents.array[current].used > 0) { + name_length = data->contents.array[current].array[0].stop - data->contents.array[current].array[0].start + 1; + + if (name_length == argv_length) { + if (fl_string_compare(data->buffer.string + data->contents.array[current].array[0].start, arguments.argv[data->parameters[fss_basic_list_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) { + if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional && found == target)) { + f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[current]); + fprintf(f_standard_output, "\n"); + } + + if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional) { + if (found == target) { + break; + } + else { + found++; + } + } + } + } + } + } // for + } + } + } + } + + return f_none; + } +#endif // _di_fss_basic_list_read_main_process_file_ diff --git a/level_3/fss_basic_list_read/c/private-fss_basic_list_read.h b/level_3/fss_basic_list_read/c/private-fss_basic_list_read.h new file mode 100644 index 0000000..85709c7 --- /dev/null +++ b/level_3/fss_basic_list_read/c/private-fss_basic_list_read.h @@ -0,0 +1,23 @@ +/** + * FLL - Level 3 + * + * Project: FSS + * API Version: 0.5 + * Licenses: lgplv2.1 + */ +#ifndef _PRIVATE_fss_basic_list_read_h +#define _PRIVATE_fss_basic_list_read_h + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} // extern "C" +#endif + +#ifndef _di_fss_basic_list_read_main_process_file_ + extern f_return_status fss_basic_list_read_main_process_file(const f_console_arguments arguments, fss_basic_list_read_data *data, const f_string filename, const f_string_length target) f_gcc_attribute_visibility_internal; +#endif // _di_fss_basic_list_read_main_process_file_ + +#endif // _PRIVATE_fss_basic_list_read_h diff --git a/level_3/fss_basic_list_read/data/build/settings b/level_3/fss_basic_list_read/data/build/settings index 2f6bcb2..b8d57e2 100644 --- a/level_3/fss_basic_list_read/data/build/settings +++ b/level_3/fss_basic_list_read/data/build/settings @@ -13,7 +13,7 @@ build_libraries -lc build_libraries_fll -lfll_program -lfll_fss -lfll_execute -lfl_string -lfl_status -lfl_fss -lf_conversion -lfl_file -lfl_directory -lfl_console -lf_utf -lfl_color -lf_file -lf_print -lf_pipe -lf_console -lf_memory #build_libraries_fll-level -lfll_2 -lfll_1 -lfll_0 #build_libraries_fll-monolithic -lfll -build_sources_library fss_basic_list_read.c +build_sources_library fss_basic_list_read.c private-fss_basic_list_read.c build_sources_program main.c build_sources_headers fss_basic_list_read.h build_sources_bash 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 fe7b1f7..a552a31 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.c +++ b/level_3/fss_basic_read/c/fss_basic_read.c @@ -1,4 +1,5 @@ #include +#include "private-fss_basic_read.h" #ifdef __cplusplus extern "C" { @@ -28,8 +29,6 @@ extern "C" { #endif // _di_fss_basic_read_print_help_ #ifndef _di_fss_basic_read_main_ - f_return_status fss_basic_read_main_process_file(const f_console_arguments arguments, fss_basic_read_data *data, const f_string filename, const f_string_length target) f_gcc_attribute_visibility_internal; - f_return_status fss_basic_read_main(const f_console_arguments arguments, fss_basic_read_data *data) { f_status status = f_none; @@ -212,185 +211,6 @@ extern "C" { fss_basic_read_delete_data(data); return status; } - - f_return_status fss_basic_read_main_process_file(const f_console_arguments arguments, fss_basic_read_data *data, const f_string filename, const f_string_length target) { - f_status status = f_none; - f_status status2 = f_none; - - f_string_length current = 0; - f_string_length found = 0; - - { - f_string_location input = f_string_location_initialize; - - input.start = 0; - input.stop = data->buffer.used - 1; - - status = fll_fss_basic_read(&data->buffer, &input, &data->objects, &data->contents); - - if (f_status_is_error(status)) { - status = f_status_set_fine(status); - - if (status == f_invalid_parameter) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fll_fss_basic_list_read() for the file '%s'", filename); - } - else if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - } - else if (status == f_incomplete_utf_on_stop) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: error occured on invalid UTF-8 character at stop position (at %d).", input.start); - } - else if (status == f_incomplete_utf_on_eos) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: error occured on invalid UTF-8 character at end of string (at %d).", input.start); - } - else { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_basic_list_read() for the file '%s'", f_status_set_error(status), filename); - } - - fss_basic_read_delete_data(data); - return f_status_set_error(status); - } - else if (status == f_no_data_on_stop || status == f_no_data_on_eos) { - // clear buffers, then attempt the next file - f_macro_fss_contents_delete(status2, data->contents); - f_macro_fss_objects_delete(status2, data->objects); - f_macro_string_dynamic_delete(status2, data->buffer); - - return f_status_set_warning(status); - } - } - - // now that the file has been read, process the objects and contents - if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_read_parameter_name].result == f_console_result_none) { - fprintf(f_standard_output, "%u\n", (unsigned int) data->objects.used); - } - else { - current = 0; - - if (data->parameters[fss_basic_read_parameter_name].result == f_console_result_none) { - if (data->parameters[fss_basic_read_parameter_object].result == f_console_result_none) { - for (; current < data->objects.used; current++) { - if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional && found == target)) { - if (data->contents.array[current].used > 0) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->contents.array[current].array[0]); - fprintf(f_standard_output, "\n"); - } - else { - // for all objects with no data, print a newline - fprintf(f_standard_output, "\n"); - } - } - - if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional) { - if (found == target) { - break; - } - else { - found++; - } - } - } // for - } - else { - for (; current < data->objects.used; current++) { - if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional && found == target)) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[current]); - fprintf(f_standard_output, "\n"); - } - - if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional) { - if (found == target) { - break; - } - else { - found++; - } - } - } // for - } - } - else { - current = 0; - - f_string_length total = 0; - f_string_length name_length = 0; - f_string_length argv_length = 0; - - if (data->parameters[fss_basic_read_parameter_name].result == f_console_result_additional) { - argv_length = strlen(arguments.argv[data->parameters[fss_basic_read_parameter_name].additional.array[0]]); - - if (data->parameters[fss_basic_read_parameter_object].result == f_console_result_none) { - for (; current < data->objects.used; current++) { - name_length = data->objects.array[current].stop - data->objects.array[current].start + 1; - - if (name_length == argv_length) { - if (fl_string_compare(data->buffer.string + data->objects.array[current].start, arguments.argv[data->parameters[fss_basic_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) { - - if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional && found == target)) { - if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found) { - total++; - } - else { - if (data->contents.array[current].used > 0) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->contents.array[current].array[0]); - fprintf(f_standard_output, "\n"); - } - else { - // for all objects with no data, print a newline - fprintf(f_standard_output, "\n"); - } - } - } - - if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional) { - if (found == target) { - break; - } - else { - found++; - } - } - } - } - } // for - - if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_read_parameter_count].result == f_console_result_none) { - fprintf(f_standard_output, f_string_length_printf "\n", total); - } - } - else { - // when and because the object parameter is specified, the name parameter refers to the content instead of the object - // therefore, make the search on the content and display the object - for (; current < data->contents.used; current++) { - if (data->contents.array[current].used > 0) { - name_length = data->contents.array[current].array[0].stop - data->contents.array[current].array[0].start + 1; - - if (name_length == argv_length) { - if (fl_string_compare(data->buffer.string + data->contents.array[current].array[0].start, arguments.argv[data->parameters[fss_basic_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) { - if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional && found == target)) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[current]); - fprintf(f_standard_output, "\n"); - } - - if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional) { - if (found == target) { - break; - } - else { - found++; - } - } - } - } - } - } // for - } - } - } - } - - return f_none; - } #endif // _di_fss_basic_read_main_ #ifndef _di_fss_basic_read_delete_data_ 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 new file mode 100644 index 0000000..6c75279 --- /dev/null +++ b/level_3/fss_basic_read/c/private-fss_basic_read.c @@ -0,0 +1,183 @@ +#include +#include "private-fss_basic_read.h" + +#ifndef _di_fss_basic_read_main_process_file_ + f_return_status fss_basic_read_main_process_file(const f_console_arguments arguments, fss_basic_read_data *data, const f_string filename, const f_string_length target) { + f_status status = f_none; + f_status status2 = f_none; + + f_string_length current = 0; + f_string_length found = 0; + + { + f_string_location input = f_string_location_initialize; + + input.start = 0; + input.stop = data->buffer.used - 1; + + status = fll_fss_basic_read(&data->buffer, &input, &data->objects, &data->contents); + + if (f_status_is_error(status)) { + status = f_status_set_fine(status); + + if (status == f_invalid_parameter) { + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fll_fss_basic_list_read() for the file '%s'", filename); + } + else if (status == f_allocation_error || status == f_reallocation_error) { + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); + } + else if (status == f_incomplete_utf_on_stop) { + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: error occured on invalid UTF-8 character at stop position (at %d).", input.start); + } + else if (status == f_incomplete_utf_on_eos) { + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: error occured on invalid UTF-8 character at end of string (at %d).", input.start); + } + else { + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_basic_list_read() for the file '%s'", f_status_set_error(status), filename); + } + + fss_basic_read_delete_data(data); + return f_status_set_error(status); + } + else if (status == f_no_data_on_stop || status == f_no_data_on_eos) { + // clear buffers, then attempt the next file + f_macro_fss_contents_delete(status2, data->contents); + f_macro_fss_objects_delete(status2, data->objects); + f_macro_string_dynamic_delete(status2, data->buffer); + + return f_status_set_warning(status); + } + } + + // now that the file has been read, process the objects and contents + if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_read_parameter_name].result == f_console_result_none) { + fprintf(f_standard_output, "%u\n", (unsigned int) data->objects.used); + } + else { + current = 0; + + if (data->parameters[fss_basic_read_parameter_name].result == f_console_result_none) { + if (data->parameters[fss_basic_read_parameter_object].result == f_console_result_none) { + for (; current < data->objects.used; current++) { + if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional && found == target)) { + if (data->contents.array[current].used > 0) { + f_print_string_dynamic_partial(f_standard_output, data->buffer, data->contents.array[current].array[0]); + fprintf(f_standard_output, "\n"); + } + else { + // for all objects with no data, print a newline + fprintf(f_standard_output, "\n"); + } + } + + if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional) { + if (found == target) { + break; + } + else { + found++; + } + } + } // for + } + else { + for (; current < data->objects.used; current++) { + if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional && found == target)) { + f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[current]); + fprintf(f_standard_output, "\n"); + } + + if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional) { + if (found == target) { + break; + } + else { + found++; + } + } + } // for + } + } + else { + current = 0; + + f_string_length total = 0; + f_string_length name_length = 0; + f_string_length argv_length = 0; + + if (data->parameters[fss_basic_read_parameter_name].result == f_console_result_additional) { + argv_length = strlen(arguments.argv[data->parameters[fss_basic_read_parameter_name].additional.array[0]]); + + if (data->parameters[fss_basic_read_parameter_object].result == f_console_result_none) { + for (; current < data->objects.used; current++) { + name_length = data->objects.array[current].stop - data->objects.array[current].start + 1; + + if (name_length == argv_length) { + if (fl_string_compare(data->buffer.string + data->objects.array[current].start, arguments.argv[data->parameters[fss_basic_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) { + + if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional && found == target)) { + if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found) { + total++; + } + else { + if (data->contents.array[current].used > 0) { + f_print_string_dynamic_partial(f_standard_output, data->buffer, data->contents.array[current].array[0]); + fprintf(f_standard_output, "\n"); + } + else { + // for all objects with no data, print a newline + fprintf(f_standard_output, "\n"); + } + } + } + + if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional) { + if (found == target) { + break; + } + else { + found++; + } + } + } + } + } // for + + if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_read_parameter_count].result == f_console_result_none) { + fprintf(f_standard_output, f_string_length_printf "\n", total); + } + } + else { + // when and because the object parameter is specified, the name parameter refers to the content instead of the object + // therefore, make the search on the content and display the object + for (; current < data->contents.used; current++) { + if (data->contents.array[current].used > 0) { + name_length = data->contents.array[current].array[0].stop - data->contents.array[current].array[0].start + 1; + + if (name_length == argv_length) { + if (fl_string_compare(data->buffer.string + data->contents.array[current].array[0].start, arguments.argv[data->parameters[fss_basic_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) { + if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional && found == target)) { + f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[current]); + fprintf(f_standard_output, "\n"); + } + + if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional) { + if (found == target) { + break; + } + else { + found++; + } + } + } + } + } + } // for + } + } + } + } + + return f_none; + } +#endif // _di_fss_basic_read_main_process_file_ diff --git a/level_3/fss_basic_read/c/private-fss_basic_read.h b/level_3/fss_basic_read/c/private-fss_basic_read.h new file mode 100644 index 0000000..8958e15 --- /dev/null +++ b/level_3/fss_basic_read/c/private-fss_basic_read.h @@ -0,0 +1,23 @@ +/** + * FLL - Level 3 + * + * Project: FSS + * API Version: 0.5 + * Licenses: lgplv2.1 + */ +#ifndef _PRIVATE_fss_basic_read_h +#define _PRIVATE_fss_basic_read_h + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} // extern "C" +#endif + +#ifndef _di_fss_basic_read_main_process_file_ + extern f_return_status fss_basic_read_main_process_file(const f_console_arguments arguments, fss_basic_read_data *data, const f_string filename, const f_string_length target) f_gcc_attribute_visibility_internal; +#endif // _di_fss_basic_read_main_process_file_ + +#endif // _PRIVATE_fss_basic_read_h diff --git a/level_3/fss_basic_read/data/build/settings b/level_3/fss_basic_read/data/build/settings index 9743404..a645866 100644 --- a/level_3/fss_basic_read/data/build/settings +++ b/level_3/fss_basic_read/data/build/settings @@ -13,7 +13,7 @@ build_libraries -lc build_libraries_fll -lfll_program -lfll_fss -lfll_execute -lfl_string -lfl_status -lfl_fss -lf_conversion -lfl_file -lfl_directory -lfl_console -lf_utf -lfl_color -lf_file -lf_print -lf_pipe -lf_console -lf_memory #build_libraries_fll-level -lfll_2 -lfll_1 -lfll_0 #build_libraries_fll-monolithic -lfll -build_sources_library fss_basic_read.c +build_sources_library fss_basic_read.c private-fss_basic_read.c build_sources_program main.c build_sources_headers fss_basic_read.h build_sources_bash 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 87aeeb6..cc080ca 100644 --- a/level_3/fss_extended_read/c/fss_extended_read.c +++ b/level_3/fss_extended_read/c/fss_extended_read.c @@ -1,4 +1,5 @@ #include +#include "private-fss_extended_read.h" #ifdef __cplusplus extern "C" { @@ -29,8 +30,6 @@ extern "C" { #endif // _di_fss_extended_read_print_help_ #ifndef _di_fss_extended_read_main_ - f_return_status fss_extended_read_main_process_file(const f_console_arguments arguments, fss_extended_read_data *data, const f_string filename, const f_string_length target, const f_string_length select) f_gcc_attribute_visibility_internal; - f_return_status fss_extended_read_main(const f_console_arguments arguments, fss_extended_read_data *data) { f_status status = f_none; @@ -211,188 +210,6 @@ extern "C" { fss_extended_read_delete_data(data); return status; } - - f_return_status fss_extended_read_main_process_file(const f_console_arguments arguments, fss_extended_read_data *data, const f_string filename, const f_string_length target, const f_string_length select) { - f_status status = f_none; - f_status status2 = f_none; - - f_string_length current = 0; - f_string_length found = 0; - - { - f_string_location input = f_string_location_initialize; - - input.start = 0; - input.stop = data->buffer.used - 1; - - status = fll_fss_extended_read(&data->buffer, &input, &data->objects, &data->contents); - - if (f_status_is_error(status)) { - status = f_status_set_fine(status); - - if (status == f_invalid_parameter) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fll_fss_extended_read() for the file '%s'", filename); - } - else if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - } - else if (status == f_incomplete_utf_on_stop) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: error occured on invalid UTF-8 character at stop position (at %d).", input.start); - } - else if (status == f_incomplete_utf_on_eos) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: error occured on invalid UTF-8 character at end of string (at %d).", input.start); - } - else { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_extended_read() for the file '%s'", f_status_set_error(status), filename); - } - - fss_extended_read_delete_data(data); - return f_status_set_error(status); - } - else if (status == f_no_data_on_stop || status == f_no_data_on_eos) { - // clear buffers, then attempt the next file - f_macro_fss_contents_delete(status2, data->contents); - f_macro_fss_objects_delete(status2, data->objects); - f_macro_string_dynamic_delete(status2, data->buffer); - - return f_status_set_warning(status); - } - } - - // now that all of the files have been read, process the objects and contents - if (data->parameters[fss_extended_read_parameter_total].result == f_console_result_found && data->parameters[fss_extended_read_parameter_name].result == f_console_result_none) { - fprintf(f_standard_output, "%u\n", (unsigned int) data->objects.used); - } - else { - current = 0; - - if (data->parameters[fss_extended_read_parameter_name].result == f_console_result_none) { - if (data->parameters[fss_extended_read_parameter_object].result == f_console_result_none) { - for (; current < data->objects.used; current++) { - if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_none || (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional && found == target)) { - if (data->contents.array[current].used > select) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->contents.array[current].array[select]); - fprintf(f_standard_output, "\n"); - } - else { - // for all objects with no data, print a newline - fprintf(f_standard_output, "\n"); - } - } - - if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional) { - if (found == target) { - break; - } - else { - found++; - } - } - } // for - } - else { - for (; current < data->objects.used; current++) { - if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_none || (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional && found == target)) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[current]); - fprintf(f_standard_output, "\n"); - } - - if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional) { - if (found == target) { - break; - } - else { - found++; - } - } - } // for - } - } else { - current = 0; - - f_string_length total = 0; - f_string_length name_length = 0; - f_string_length argv_length = 0; - - if (data->parameters[fss_extended_read_parameter_name].result == f_console_result_additional) { - argv_length = strlen(arguments.argv[data->parameters[fss_extended_read_parameter_name].additional.array[0]]); - - if (data->parameters[fss_extended_read_parameter_object].result == f_console_result_none) { - for (; current < data->objects.used; current++) { - name_length = data->objects.array[current].stop - data->objects.array[current].start + 1; - - if (name_length == argv_length) { - if (fl_string_compare(data->buffer.string + data->objects.array[current].start, arguments.argv[data->parameters[fss_extended_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) { - - if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_none || (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional && found == target)) { - if (data->parameters[fss_extended_read_parameter_total].result == f_console_result_found) { - total++; - } - else { - if (data->contents.array[current].used > select) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->contents.array[current].array[select]); - fprintf(f_standard_output, "\n"); - } - else { - // for all objects with no data, print a newline - fprintf(f_standard_output, "\n"); - } - } - } - - if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional) { - if (data->parameters[fss_extended_read_parameter_total].result == f_console_result_found) { - total = data->contents.array[current].used; - } - - if (found == target) { - break; - } - else { - found++; - } - } - } - } - } // for - - if (data->parameters[fss_extended_read_parameter_total].result == f_console_result_found) { - fprintf(f_standard_output, f_string_length_printf "\n", total); - } - } - else { - // when and because the object parameter is specified, the name parameter refers to the content instead of the object - // therefore, make the search on the content and display the object - for (; current < data->contents.used; current++) { - if (data->contents.array[current].used > select) { - name_length = data->contents.array[current].array[select].stop - data->contents.array[current].array[select].start + 1; - - if (name_length == argv_length) { - if (fl_string_compare(data->buffer.string + data->contents.array[current].array[select].start, arguments.argv[data->parameters[fss_extended_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) { - if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_none || (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional && found == target)) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[current]); - fprintf(f_standard_output, "\n"); - } - - if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional) { - if (found == target) { - break; - } - else { - found++; - } - } - } - } - } - } // for - } - } - } - } - - return f_none; - } #endif // _di_fss_extended_read_main_ #ifndef _di_fss_extended_read_delete_data_ 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 new file mode 100644 index 0000000..343be0d --- /dev/null +++ b/level_3/fss_extended_read/c/private-fss_extended_read.c @@ -0,0 +1,186 @@ +#include +#include "private-fss_extended_read.h" + +#ifndef _di_fss_extended_read_main_process_file_ + f_return_status fss_extended_read_main_process_file(const f_console_arguments arguments, fss_extended_read_data *data, const f_string filename, const f_string_length target, const f_string_length select) { + f_status status = f_none; + f_status status2 = f_none; + + f_string_length current = 0; + f_string_length found = 0; + + { + f_string_location input = f_string_location_initialize; + + input.start = 0; + input.stop = data->buffer.used - 1; + + status = fll_fss_extended_read(&data->buffer, &input, &data->objects, &data->contents); + + if (f_status_is_error(status)) { + status = f_status_set_fine(status); + + if (status == f_invalid_parameter) { + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fll_fss_extended_read() for the file '%s'", filename); + } + else if (status == f_allocation_error || status == f_reallocation_error) { + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); + } + else if (status == f_incomplete_utf_on_stop) { + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: error occured on invalid UTF-8 character at stop position (at %d).", input.start); + } + else if (status == f_incomplete_utf_on_eos) { + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: error occured on invalid UTF-8 character at end of string (at %d).", input.start); + } + else { + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_extended_read() for the file '%s'", f_status_set_error(status), filename); + } + + fss_extended_read_delete_data(data); + return f_status_set_error(status); + } + else if (status == f_no_data_on_stop || status == f_no_data_on_eos) { + // clear buffers, then attempt the next file + f_macro_fss_contents_delete(status2, data->contents); + f_macro_fss_objects_delete(status2, data->objects); + f_macro_string_dynamic_delete(status2, data->buffer); + + return f_status_set_warning(status); + } + } + + // now that all of the files have been read, process the objects and contents + if (data->parameters[fss_extended_read_parameter_total].result == f_console_result_found && data->parameters[fss_extended_read_parameter_name].result == f_console_result_none) { + fprintf(f_standard_output, "%u\n", (unsigned int) data->objects.used); + } + else { + current = 0; + + if (data->parameters[fss_extended_read_parameter_name].result == f_console_result_none) { + if (data->parameters[fss_extended_read_parameter_object].result == f_console_result_none) { + for (; current < data->objects.used; current++) { + if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_none || (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional && found == target)) { + if (data->contents.array[current].used > select) { + f_print_string_dynamic_partial(f_standard_output, data->buffer, data->contents.array[current].array[select]); + fprintf(f_standard_output, "\n"); + } + else { + // for all objects with no data, print a newline + fprintf(f_standard_output, "\n"); + } + } + + if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional) { + if (found == target) { + break; + } + else { + found++; + } + } + } // for + } + else { + for (; current < data->objects.used; current++) { + if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_none || (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional && found == target)) { + f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[current]); + fprintf(f_standard_output, "\n"); + } + + if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional) { + if (found == target) { + break; + } + else { + found++; + } + } + } // for + } + } else { + current = 0; + + f_string_length total = 0; + f_string_length name_length = 0; + f_string_length argv_length = 0; + + if (data->parameters[fss_extended_read_parameter_name].result == f_console_result_additional) { + argv_length = strlen(arguments.argv[data->parameters[fss_extended_read_parameter_name].additional.array[0]]); + + if (data->parameters[fss_extended_read_parameter_object].result == f_console_result_none) { + for (; current < data->objects.used; current++) { + name_length = data->objects.array[current].stop - data->objects.array[current].start + 1; + + if (name_length == argv_length) { + if (fl_string_compare(data->buffer.string + data->objects.array[current].start, arguments.argv[data->parameters[fss_extended_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) { + + if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_none || (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional && found == target)) { + if (data->parameters[fss_extended_read_parameter_total].result == f_console_result_found) { + total++; + } + else { + if (data->contents.array[current].used > select) { + f_print_string_dynamic_partial(f_standard_output, data->buffer, data->contents.array[current].array[select]); + fprintf(f_standard_output, "\n"); + } + else { + // for all objects with no data, print a newline + fprintf(f_standard_output, "\n"); + } + } + } + + if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional) { + if (data->parameters[fss_extended_read_parameter_total].result == f_console_result_found) { + total = data->contents.array[current].used; + } + + if (found == target) { + break; + } + else { + found++; + } + } + } + } + } // for + + if (data->parameters[fss_extended_read_parameter_total].result == f_console_result_found) { + fprintf(f_standard_output, f_string_length_printf "\n", total); + } + } + else { + // when and because the object parameter is specified, the name parameter refers to the content instead of the object + // therefore, make the search on the content and display the object + for (; current < data->contents.used; current++) { + if (data->contents.array[current].used > select) { + name_length = data->contents.array[current].array[select].stop - data->contents.array[current].array[select].start + 1; + + if (name_length == argv_length) { + if (fl_string_compare(data->buffer.string + data->contents.array[current].array[select].start, arguments.argv[data->parameters[fss_extended_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) { + if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_none || (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional && found == target)) { + f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[current]); + fprintf(f_standard_output, "\n"); + } + + if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional) { + if (found == target) { + break; + } + else { + found++; + } + } + } + } + } + } // for + } + } + } + } + + return f_none; + } +#endif // _di_fss_extended_read_main_process_file_ diff --git a/level_3/fss_extended_read/c/private-fss_extended_read.h b/level_3/fss_extended_read/c/private-fss_extended_read.h new file mode 100644 index 0000000..fb6f99c --- /dev/null +++ b/level_3/fss_extended_read/c/private-fss_extended_read.h @@ -0,0 +1,23 @@ +/** + * FLL - Level 3 + * + * Project: FSS + * API Version: 0.5 + * Licenses: lgplv2.1 + */ +#ifndef _PRIVATE_fss_extended_read_h +#define _PRIVATE_fss_extended_read_h + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_fss_extended_read_main_process_file_ + extern f_return_status fss_extended_read_main_process_file(const f_console_arguments arguments, fss_extended_read_data *data, const f_string filename, const f_string_length target, const f_string_length select) f_gcc_attribute_visibility_internal; +#endif // _di_fss_extended_read_main_process_file_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _PRIVATE_fss_extended_read_h diff --git a/level_3/fss_extended_read/data/build/settings b/level_3/fss_extended_read/data/build/settings index 554b231..1b4a0fa 100644 --- a/level_3/fss_extended_read/data/build/settings +++ b/level_3/fss_extended_read/data/build/settings @@ -13,7 +13,7 @@ build_libraries -lc build_libraries_fll -lfll_program -lfll_fss -lfll_execute -lfl_string -lfl_status -lfl_fss -lf_conversion -lfl_file -lfl_directory -lfl_console -lf_utf -lfl_color -lf_file -lf_print -lf_pipe -lf_console -lf_memory #build_libraries_fll-level -lfll_2 -lfll_1 -lfll_0 #build_libraries_fll-monolithic -lfll -build_sources_library fss_extended_read.c +build_sources_library fss_extended_read.c private-fss_extended_read.c build_sources_program main.c build_sources_headers fss_extended_read.h build_sources_bash -- 1.8.3.1