From 3821f4112826d6749296b586b110efafe9f02cb1 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Thu, 11 May 2023 22:09:58 -0500 Subject: [PATCH] Progress: Continue work on refactoring fss_*_read into fss_read. --- level_3/fss_read/c/basic/main.c | 4 +- level_3/fss_read/c/basic_list/main.c | 4 +- level_3/fss_read/c/embedded_list/main.c | 4 +- level_3/fss_read/c/extended/main.c | 4 +- level_3/fss_read/c/extended_list/main.c | 4 +- level_3/fss_read/c/main/common.c | 183 ++++++++++++++++++++++++++------ level_3/fss_read/c/main/common.h | 2 + level_3/fss_read/c/main/common/print.c | 4 + level_3/fss_read/c/main/common/print.h | 4 + level_3/fss_read/c/main/common/type.c | 9 ++ level_3/fss_read/c/main/common/type.h | 85 +++++++++++++-- level_3/fss_read/c/main/fss_read.c | 112 +++++-------------- level_3/fss_read/c/main/fss_read.h | 43 +++++++- level_3/fss_read/c/payload/fss_read.c | 12 +-- level_3/fss_read/c/payload/fss_read.h | 4 + level_3/fss_read/c/payload/main.c | 4 +- 16 files changed, 319 insertions(+), 163 deletions(-) diff --git a/level_3/fss_read/c/basic/main.c b/level_3/fss_read/c/basic/main.c index b740c36..1211f49 100644 --- a/level_3/fss_read/c/basic/main.c +++ b/level_3/fss_read/c/basic/main.c @@ -18,12 +18,10 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.setting.state.custom = (void *) &data; data.setting.standard = fss_read_basic_standard_s; - data.setting.process_content = &fss_read_basic_process_content; data.setting.process_help = &fss_read_basic_process_help; + data.setting.process_last_line = &fss_read_process_last_line; data.setting.process_normal = &fss_read_process_normal; - data.setting.process_object = &fss_read_basic_process_object; data.setting.process_pipe = &fss_read_process_pipe; - data.setting.process_set = &fss_read_process_set; f_console_parameter_t parameters[] = fss_read_console_parameter_t_initialize; data.program.parameters.array = parameters; diff --git a/level_3/fss_read/c/basic_list/main.c b/level_3/fss_read/c/basic_list/main.c index cc3c031..8b15c77 100644 --- a/level_3/fss_read/c/basic_list/main.c +++ b/level_3/fss_read/c/basic_list/main.c @@ -18,12 +18,10 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.setting.state.custom = (void *) &data; data.setting.standard = fss_read_basic_list_standard_s; - data.setting.process_content = &fss_read_basic_list_process_content; data.setting.process_help = &fss_read_basic_list_process_help; + data.setting.process_last_line = &fss_read_process_last_line; data.setting.process_normal = &fss_read_process_normal; - data.setting.process_object = &fss_read_basic_list_process_object; data.setting.process_pipe = &fss_read_process_pipe; - data.setting.process_set = &fss_read_process_set; f_console_parameter_t parameters[] = fss_read_console_parameter_t_initialize; data.program.parameters.array = parameters; diff --git a/level_3/fss_read/c/embedded_list/main.c b/level_3/fss_read/c/embedded_list/main.c index 499eb8b..4eed5ed 100644 --- a/level_3/fss_read/c/embedded_list/main.c +++ b/level_3/fss_read/c/embedded_list/main.c @@ -18,12 +18,10 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.setting.state.custom = (void *) &data; data.setting.standard = fss_read_embedded_list_standard_s; - data.setting.process_content = &fss_read_embedded_list_process_content; data.setting.process_help = &fss_read_embedded_list_process_help; + data.setting.process_last_line = &fss_read_process_last_line; data.setting.process_normal = &fss_read_process_normal; - data.setting.process_object = &fss_read_embedded_list_process_object; data.setting.process_pipe = &fss_read_process_pipe; - data.setting.process_set = &fss_read_process_set; data.setting.flag |= fss_read_main_flag_ignore_e; data.setting.flag |= fss_read_main_flag_content_multiple_e; diff --git a/level_3/fss_read/c/extended/main.c b/level_3/fss_read/c/extended/main.c index f0a733f..0d7a900 100644 --- a/level_3/fss_read/c/extended/main.c +++ b/level_3/fss_read/c/extended/main.c @@ -18,12 +18,10 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.setting.state.custom = (void *) &data; data.setting.standard = fss_read_extended_standard_s; - data.setting.process_content = &fss_read_extended_process_content; data.setting.process_help = &fss_read_extended_process_help; + data.setting.process_last_line = &fss_read_process_last_line; data.setting.process_normal = &fss_read_process_normal; - data.setting.process_object = &fss_read_extended_process_object; data.setting.process_pipe = &fss_read_process_pipe; - data.setting.process_set = &fss_read_process_set; data.setting.flag |= fss_read_main_flag_content_multiple_e; f_console_parameter_t parameters[] = fss_read_console_parameter_t_initialize; diff --git a/level_3/fss_read/c/extended_list/main.c b/level_3/fss_read/c/extended_list/main.c index 87cd830..3974995 100644 --- a/level_3/fss_read/c/extended_list/main.c +++ b/level_3/fss_read/c/extended_list/main.c @@ -18,12 +18,10 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.setting.state.custom = (void *) &data; data.setting.standard = fss_read_extended_list_standard_s; - data.setting.process_content = &fss_read_extended_list_process_content; data.setting.process_help = &fss_read_extended_list_process_help; + data.setting.process_last_line = &fss_read_process_last_line; data.setting.process_normal = &fss_read_process_normal; - data.setting.process_object = &fss_read_extended_list_process_object; data.setting.process_pipe = &fss_read_process_pipe; - data.setting.process_set = &fss_read_process_set; data.setting.flag |= fss_read_main_flag_ignore_e; f_console_parameter_t parameters[] = fss_read_console_parameter_t_initialize; diff --git a/level_3/fss_read/c/main/common.c b/level_3/fss_read/c/main/common.c index db21a15..8f9ddcc 100644 --- a/level_3/fss_read/c/main/common.c +++ b/level_3/fss_read/c/main/common.c @@ -241,17 +241,7 @@ extern "C" { for (i = 0; i < main->parameters.array[fss_read_parameter_delimit_e].values.used; ++i) { - if (!((++main->signal_check) % fss_read_signal_check_d)) { - if (fll_program_standard_signal_received(&main->program)) { - fll_program_print_signal_received(main->warning, main->signal_received); - - main->setting.state.status = F_status_set_error(F_interrupt); - - return; - } - - main->signal_check = 0; - } + if (fss_read_signal_check(main)) return; index = main->parameters.array[fss_read_parameter_delimit_e].values.array[i]; length = main->program.parameters.arguments.array[index].used; @@ -410,6 +400,153 @@ extern "C" { if (main->program.parameters.array[fss_read_parameter_trim_e].result & f_console_result_found_e) { main->setting.flag |= fss_read_main_flag_trim_e; } + + f_file_t file = f_file_t_initialize; + + if (main->pipe & fll_program_data_pipe_input_e) { + file.id = F_type_descriptor_input_d; + file.stream = F_type_input_d; + + main->setting.files.array[0].range.start = 0; + + main->setting.state.status = f_file_stream_read(file, &main->setting.buffer); + + if (F_status_is_error(main->setting.state.status)) { + if ((main->setting.flag & fss_read_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + + fll_error_file_print(&main->error, F_status_set_fine(main->setting.state.status), macro_fss_read_f(f_file_stream_read), fll_error_file_flag_fallback_e, f_string_ascii_minus_s, f_file_operation_read_s, fll_error_file_type_pipe_e); + + return; + } + + if (main->setting.buffer.used) { + main->setting.files.array[0].range.stop = main->setting.buffer.used - 1; + + if (main->setting.process_last_line) { + main->setting.process_last_line((void *) &main); + if (F_status_is_error(main->setting.state.status)) return; + } + } + else { + main->setting.files.array[0].range.start = 1; + } + } + + if (main->program.parameters.remaining.used) { + f_array_length_t index = 0; + off_t size_block = 0; + off_t size_file = 0; + off_t size_read = 0; + + for (i = 0; i < main->parameters.remaining.used; ++i) { + + if (fss_read_signal_check(main)) return; + + index = main->parameters.remaining.array[i]; + + main->setting.files.array[main->setting.files.used].name = main->program.parameters.arguments.array[index]; + main->setting.files.array[main->setting.files.used].range.start = main->setting.buffer.used; + + file.id = -1; + file.stream = 0; + + main->setting.state.status = f_file_stream_open(main->setting.files.array[main->setting.files.used].name, f_string_empty_s, &file); + + if (F_status_is_error(main->setting.state.status)) { + if ((main->setting.flag & fss_read_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + + fll_error_file_print(&main->error, F_status_set_fine(main->setting.state.status), macro_fss_read_f(f_file_stream_open), fll_error_file_flag_fallback_e, main->program.parameters.arguments.array[index], f_file_operation_open_s, fll_error_file_type_file_e); + + break; + } + + size_file = 0; + + main->setting.state.status = f_file_size_by_id(file.id, &size_file); + + if (F_status_is_error(main->setting.state.status)) { + if ((main->setting.flag & fss_read_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + + fll_error_file_print(&main->error, F_status_set_fine(main->setting.state.status), macro_fss_read_f(f_file_size_by_id), fll_error_file_flag_fallback_e, main->program.parameters.arguments.array[index], f_file_operation_read_s, fll_error_file_type_file_e); + + break; + } + + if (size_file) { + + // Enforce a max block read size to allow for interrupts to be processed between blocks. + if (size_file > fss_basic_list_read_block_max) { + file.size_read = fss_basic_list_read_block_read_large; + size_block = fss_basic_list_read_block_max; + + // Pre-allocate entire file buffer plus space for the terminating NULL. + f_string_dynamic_increase_by(size_file + (size_block - (size_file % size_block)) + 1, &main->setting.buffer); + } + else { + file.size_read = fss_basic_list_read_block_read_small; + size_block = size_file; + + // Pre-allocate entire file buffer plus space for the terminating NULL. + f_string_dynamic_increase_by(size_file + 1, &main->setting.buffer); + } + + if (F_status_is_error(main->setting.state.status)) { + if ((main->setting.flag & fss_read_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + + fll_error_file_print(&main->error, F_status_set_fine(main->setting.state.status), macro_fss_read_f(f_string_dynamic_increase_by), fll_error_file_flag_fallback_e, main->program.parameters.arguments.array[index], f_file_operation_process_s, fll_error_file_type_file_e); + + break; + } + + for (size_read = 0; size_read < size_file; size_read += size_block) { + + if (size_file > fss_basic_list_read_block_max && fss_read_signal_check(main)) break; + + main->setting.state.status = f_file_stream_read_until(file, size_block, &main->setting.buffer); + if (F_status_is_error(main->setting.state.status)) break; + } // for + + if (F_status_is_error(main->setting.state.status)) { + if (F_status_set_fine(status) != F_interrupt) { + if ((main->setting.flag & fss_read_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + + fll_error_file_print(&main->error, F_status_set_fine(main->setting.state.status), macro_fss_read_f(f_file_stream_read_until), fll_error_file_flag_fallback_e, main->program.parameters.arguments.array[index], f_file_operation_read_s, fll_error_file_type_file_e); + } + + break; + } + + f_file_stream_flush(file); + f_file_stream_close(&file); + + if (main->setting.buffer.used > main->setting.files.array[main->setting.files.used].range.start) { + main->setting.files.array[main->setting.files.used++].range.stop = main->setting.buffer.used - 1; + + if (main->setting.process_last_line) { + main->setting.process_last_line((void *) &main); + if (F_status_is_error(main->setting.state.status)) break; + } + } + } + else { + main->setting.files.array[main->setting.files.used].range.start = 1; + main->setting.files.array[main->setting.files.used].range.stop = 1; + } + } // for + + f_file_stream_flush(file); + f_file_stream_close(&file); + } } #endif // _di_fss_read_setting_load_ @@ -446,17 +583,7 @@ extern "C" { for (i = 0; i < data->depths.used; ++i) { - if (!((++main->signal_check) % fss_read_signal_check_d)) { - if (fll_program_standard_signal_received(&main->program)) { - fll_program_print_signal_received(main->warning, main->signal_received); - - main->setting.state.status = F_status_set_error(F_interrupt); - - return; - } - - main->signal_check = 0; - } + if (fss_read_signal_check(main)) return; data->depths.array[i].depth = 0; data->depths.array[i].index_at = 0; @@ -551,17 +678,7 @@ extern "C" { for (j = i + 1; j < data->depths.used; ++j) { - if (!((++main->signal_check) % fss_read_signal_check_d)) { - if (fll_program_standard_signal_received(&main->program)) { - fll_program_print_signal_received(main->warning, main->signal_received); - - main->setting.state.status = F_status_set_error(F_interrupt); - - return; - } - - main->signal_check = 0; - } + if (fss_read_signal_check(main)) return; if (data->depths.array[i].depth == data->depths.array[j].depth) { main->setting.state.status = F_status_set_error(F_parameter); diff --git a/level_3/fss_read/c/main/common.h b/level_3/fss_read/c/main/common.h index 0b8d077..ca7f0ae 100644 --- a/level_3/fss_read/c/main/common.h +++ b/level_3/fss_read/c/main/common.h @@ -44,6 +44,7 @@ extern "C" { * Errors (with error bit) from: fll_program_parameter_process_verbosity(). * * Errors (with error bit) from: fss_read_setting_load_depth(). @todo fss_read_depths_resize() is to be relocated to "callback". + * Errors (with error bit) from: fss_read_signal_check() * @param callback * (optional) Designate a function to call after performing the initial processing, but before printing help. * If the function returns F_done, then this function immediately returns, resetting status to F_none. @@ -56,6 +57,7 @@ extern "C" { * @see fll_program_parameter_process_verbosity() * * @see fss_read_setting_load_depth() @todo fss_read_depths_resize() is to be relocated to "callback". + * @see fss_read_signal_check() */ #ifndef _di_fss_read_setting_load_ extern void fss_read_setting_load(const f_console_arguments_t arguments, fss_read_main_t * const main, void (*callback)(const f_console_arguments_t arguments, fss_read_main_t * const main)); diff --git a/level_3/fss_read/c/main/common/print.c b/level_3/fss_read/c/main/common/print.c index d611b9a..4551b8a 100644 --- a/level_3/fss_read/c/main/common/print.c +++ b/level_3/fss_read/c/main/common/print.c @@ -8,10 +8,14 @@ extern "C" { const f_string_t fss_read_f_a[] = { "f_console_parameter_process", "f_file_read_block", + "f_file_size_by_id", "f_file_stream_open", + "f_file_stream_read", + "f_file_stream_read_until", "f_fss_is_space", "f_rip_dynamic", "f_string_dynamic_append", + "f_string_dynamic_append_assure", "f_string_dynamic_append_nulless", "f_string_dynamic_increase_by", "f_string_dynamics_increase", diff --git a/level_3/fss_read/c/main/common/print.h b/level_3/fss_read/c/main/common/print.h index 0d97880..a8b9573 100644 --- a/level_3/fss_read/c/main/common/print.h +++ b/level_3/fss_read/c/main/common/print.h @@ -41,10 +41,14 @@ extern "C" { enum { fss_read_f_f_console_parameter_process_e, fss_read_f_f_file_read_block_e, + fss_read_f_f_file_size_by_id_e, fss_read_f_f_file_stream_open_e, + fss_read_f_f_file_stream_read_e, + fss_read_f_f_file_stream_read_until_e, fss_read_f_f_fss_is_space_e, fss_read_f_f_rip_dynamic_e, fss_read_f_f_string_dynamic_append_e, + fss_read_f_f_string_dynamic_append_assure_e, fss_read_f_f_string_dynamic_append_nulless_e, fss_read_f_f_string_dynamic_increase_by_e, fss_read_f_f_string_dynamics_increase_e, diff --git a/level_3/fss_read/c/main/common/type.c b/level_3/fss_read/c/main/common/type.c index 50abdaf..b414df2 100644 --- a/level_3/fss_read/c/main/common/type.c +++ b/level_3/fss_read/c/main/common/type.c @@ -4,6 +4,15 @@ extern "C" { #endif +#ifndef _di_fss_read_depth_delete_ + void fss_read_depth_delete(fss_read_depth_t * const depth) { + + if (!depth) return; + + f_string_dynamic_resize(0, &depth->value_name); + } +#endif // _di_fss_read_depth_delete_ + #ifndef _di_fss_read_main_data_delete_ void fss_read_main_delete(fss_read_main_t * const main) { diff --git a/level_3/fss_read/c/main/common/type.h b/level_3/fss_read/c/main/common/type.h index 5f3af40..dc96f4f 100644 --- a/level_3/fss_read/c/main/common/type.h +++ b/level_3/fss_read/c/main/common/type.h @@ -17,6 +17,65 @@ extern "C" { #endif /** + * A structure of parameters applied at some depth. + * + * depth: The depth number in which this is to be processed at. + * + * index_at: Position of the "--at" parameter value in the argv list, when 0 there is no parameter. + * index_name: Position of the "--name" parameter value in the argv list, when 0 there is no parameter. + * + * value_at: The value of the "--at" parameter, already processed and ready to use, only when index_at > 0. + * value_name: The value of the "--name" parameter, already processed and ready to use, only when index_name > 0. + */ +#ifndef _di_fss_read_depth_t_ + typedef struct { + f_array_length_t depth; + + f_array_length_t index_at; + f_array_length_t index_name; + + f_number_unsigned_t value_at; + f_string_dynamic_t value_name; + } fss_read_depth_t; + + #define fss_read_depth_t_initialize \ + { \ + 0, \ + 0, \ + 0, \ + 0, \ + f_string_dynamic_t_initialize, \ + } + + #define macro_fss_read_depth_t_clear(structure) \ + structure.depth = 0; \ + structure.index_at = 0; \ + structure.index_name = 0; \ + structure.value_at = 0; \ + macro_f_string_dynamic_t_clear(structure.value_name) +#endif // _di_fss_read_depth_t_ + +/** + * An array of depth parameters. + * + * array: The array of depths. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_fss_read_depths_t_ + typedef struct { + fss_read_depth_t *array; + + f_array_length_t size; + f_array_length_t used; + } fss_read_depths_t; + + #define fss_read_depths_t_initialize { 0, 0, 0 } + + #define macro_fss_read_depths_t_clear(depths) macro_f_memory_structure_clear(depths) +#endif // _di_fss_read_depths_t_ + +/** * A structure for designating where within the buffer a particular file exists, using a statically allocated array. * * name: The name of the file representing the range. @@ -89,12 +148,10 @@ extern "C" { * delimits_content: The positions within the buffer representing Content character delimits. * comments: The positions within the buffer representing comments. * - * process_content: Process a single Content. - * process_help: Process help (generally printing help). - * process_normal: Process normally (data from parameters and files). - * process_object: Process a single Object. - * process_pipe: Process using the data from input pipe. - * process_set: Process a set of Object and one or more Content. + * process_help: Process help (generally printing help). + * process_last_line: Process printing last line if necessary when loading in a file (or pipe). + * process_normal: Process normally (data from parameters and files). + * process_pipe: Process using the data from input pipe. */ #ifndef _di_fss_read_setting_t_ typedef struct { @@ -122,12 +179,10 @@ extern "C" { f_fss_delimits_t delimits_content; f_fss_comments_t comments; - void (*process_content)(void * const main, const bool last); void (*process_help)(void * const main); + void (*process_last_line)(void * const main); void (*process_normal)(void * const main); - void (*process_object)(void * const main); void (*process_pipe)(void * const main); - void (*process_set)(void * const main); } fss_read_setting_t; #define fss_read_setting_t_initialize \ @@ -153,8 +208,6 @@ extern "C" { 0, \ 0, \ 0, \ - 0, \ - 0, \ } #endif // _di_fss_read_setting_t_ @@ -178,6 +231,16 @@ extern "C" { #endif // _di_fss_read_main_t_ /** + * Deallocate the read depth. + * + * @param depth + * The depth to deallocate. + */ +#ifndef _di_fss_read_depth_delete_ + extern void fss_read_depth_delete(fss_read_depth_t * const depth); +#endif // _di_fss_read_depth_delete_ + +/** * Deallocate main program data. * * @param setting_make diff --git a/level_3/fss_read/c/main/fss_read.c b/level_3/fss_read/c/main/fss_read.c index 930dad3..2852496 100644 --- a/level_3/fss_read/c/main/fss_read.c +++ b/level_3/fss_read/c/main/fss_read.c @@ -70,11 +70,32 @@ extern "C" { } #endif // _di_fss_read_main_ +#ifndef _di_fss_read_process_last_line_ + void fss_read_process_last_line(void * const void_main) { + + if (!void_main) return; + + fss_read_main_t * const main = (fss_read_main_t *) void_main; + + status = f_string_dynamic_append_assure(f_string_eol_s, &main->setting.buffer); + + if (F_status_is_error(status)) { + if ((main->setting.flag & fss_read_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + + fll_error_file_print(&main->error, F_status_set_fine(main->setting.state.status), macro_fss_read_f(f_string_dynamic_append_assure), fll_error_file_flag_fallback_e, f_string_ascii_minus_s, f_file_operation_read_s, fll_error_file_type_pipe_e); + } + } +#endif // _di_fss_read_process_last_line_ + #ifndef _di_fss_read_process_normal_ void fss_read_process_normal(void * const void_main) { if (!void_main) return; + // @todo this is entirely copied from fss_write and may not represent how fss_read needs to handle this. + fss_read_process_normal_data( (fss_read_main_t *) void_main, (((fss_read_main_t *) void_main)->setting.flag & fss_read_main_flag_object_e) @@ -91,6 +112,8 @@ extern "C" { fss_read_main_t * const main = (fss_read_main_t *) void_main; + // @todo this is entirely copied from fss_write and may not represent how fss_read needs to handle this. + main->setting.ignores = 0; main->setting.object = 0; main->setting.content = 0; @@ -99,16 +122,7 @@ extern "C" { if (length) { for (f_array_length_t i = 0; i < length; ++i) { - // @todo replace all signal checks with forked main process that independently checks and assigns main->program.signal_received. - if (!((++main->program.signal_check) % fss_read_signal_check_d)) { - if (fll_program_standard_signal_received(&main->program)) { - main->setting.state.status = F_status_set_error(F_interrupt); - - return; - } - - main->program.signal_check = 0; - } + if (fss_read_signal_check(main)) return; if (main->setting.objects.used) { main->setting.object = &main->setting.objects.array[i]; @@ -147,6 +161,8 @@ extern "C" { if (!main->setting.process_set) return; + // @todo this is entirely copied from fss_write and may not represent how fss_read needs to handle this. + if (main->program.message.verbosity > f_console_verbosity_error_e) { fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); } @@ -217,17 +233,7 @@ extern "C" { for (;;) { - if (!((++main->program.signal_check) % fss_read_signal_check_d)) { - if (fll_program_standard_signal_received(&main->program)) { - fll_program_print_signal_received(&main->program.warning, main->program.signal_received); - - main->setting.state.status = F_status_set_error(F_interrupt); - - break; - } - - main->program.signal_check = 0; - } + if (fss_read_signal_check(main)) break; if (range.start > range.stop) { if (status_pipe == F_none_eof) break; @@ -453,70 +459,6 @@ extern "C" { } #endif // _di_fss_read_process_pipe_ -#ifndef _di_fss_read_process_set_ - void fss_read_process_set(void * const void_main) { - - if (!void_main) return; - - fss_read_main_t * const main = (fss_read_main_t *) void_main; - - main->setting.buffer.used = 0; - - if ((!(main->setting.flag & fss_read_main_flag_partial_e) || (main->setting.flag & fss_read_main_flag_partial_e) && (main->setting.flag & fss_read_main_flag_object_e)) && main->setting.object || (main->setting.flag & fss_read_main_flag_object_open_e)) { - - if (main->setting.object) { - if (main->setting.object->used) { - main->setting.range.start = 0; - main->setting.range.stop = main->setting.object->used - 1; - } - else { - main->setting.range.start = 1; - main->setting.range.stop = 0; - } - } - - if (main->setting.process_object) { - main->setting.process_object(void_main); - if (F_status_is_error(main->setting.state.status)) return; - } - } - - if ((!(main->setting.flag & fss_read_main_flag_partial_e) || (main->setting.flag & fss_read_main_flag_partial_e) && (main->setting.flag & fss_read_main_flag_content_e)) && main->setting.contents || (main->setting.flag & (fss_read_main_flag_content_next_e | fss_read_main_flag_content_end_e))) { - - if (main->setting.process_content) { - if (main->setting.contents && main->setting.contents->used) { - for (f_array_length_t i = 0; i < main->setting.contents->used; ++i) { - - if (main->setting.contents->array[i].used) { - main->setting.range.start = 0; - main->setting.range.stop = main->setting.contents->array[i].used - 1; - } - else { - main->setting.range.start = 1; - main->setting.range.stop = 0; - } - - main->setting.content = &main->setting.contents->array[i]; - - main->setting.process_content(void_main, i + 1 == main->setting.contents->used); - if (F_status_is_error(main->setting.state.status)) return; - } // for - } - else { - main->setting.content = 0; - - main->setting.process_content(void_main, F_true); - if (F_status_is_error(main->setting.state.status)) return; - } - } - } - - if (main->setting.buffer.used) { - fll_print_dynamic(main->setting.buffer, main->program.output.to); - } - } -#endif // _di_fss_read_process_set_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/fss_read/c/main/fss_read.h b/level_3/fss_read/c/main/fss_read.h index 1b2f244..5860ab7 100644 --- a/level_3/fss_read/c/main/fss_read.h +++ b/level_3/fss_read/c/main/fss_read.h @@ -92,7 +92,34 @@ extern "C" { #endif // _di_fss_read_main_ /** - * Process normally, writing to the output for the assigned FSS format. + * Process the current buffer, guarantee that a newline exists at the end of the buffer. + * + * Most standards are new line sensitive. + * When appending files to the buffer, if the file lacks a final new line then this could break the format for files appended thereafter. + * + * @param main + * The program and settings data. + * Must be of type fss_read_main_t. + * + * This alters main.custom.setting.state.status: + * F_none on success. + * + * F_parameter (with error bit) if main is NULL or setting is NULL. + * + * Errors (with error bit) from: f_string_dynamic_append_assure(). + * + * Errors (with error bit) from: fss_read_signal_check(). + * + * @see f_string_dynamic_append_assure() + * + * @see fss_read_signal_check() + */ +#ifndef _di_fss_read_process_last_line_ + extern void fss_read_process_last_line(void * const void_main); +#endif // _di_fss_read_process_last_line_ + +/** + * Process normally, reading from the input for the assigned FSS format. * * @param main * The program and settings data. @@ -101,7 +128,7 @@ extern "C" { * This alters main.custom.setting.state.status: * status from fss_read_process_normal_data(). * - * Errors (with error bit) from fss_read_process_normal_data(). + * Errors (with error bit) from: fss_read_process_normal_data(). * * @see fss_read_process_normal_data() */ @@ -110,7 +137,7 @@ extern "C" { #endif // _di_fss_read_process_normal_ /** - * Process the data normally, writing to the output for the assigned FSS format. + * Process the data normally, reading from the input for the assigned FSS format. * * @param main * The program and settings data. @@ -118,9 +145,12 @@ extern "C" { * * This alters main.custom.setting.state.status: * F_none on success. - * F_interrupt on (exit) signal received. * * F_parameter (with error bit) if main is NULL or setting is NULL. + * + * Errors (with error bit) from: fss_read_signal_check(). + * + * @see fss_read_signal_check() */ #ifndef _di_fss_read_process_normal_data_ void fss_read_process_normal_data(void * const main, const f_array_length_t length); @@ -137,9 +167,12 @@ extern "C" { * F_none on success. * F_data_not on success but pipe contained no relevant data. * F_basic on success and the basic has been printed. - * F_interrupt on (exit) signal received. * * F_parameter (with error bit) if main is NULL or setting is NULL. + * + * Errors (with error bit) from: fss_read_signal_check(). + * + * @see fss_read_signal_check() */ #ifndef _di_fss_read_process_pipe_ extern void fss_read_process_pipe(void * const main); diff --git a/level_3/fss_read/c/payload/fss_read.c b/level_3/fss_read/c/payload/fss_read.c index bcd85d1..89685f0 100644 --- a/level_3/fss_read/c/payload/fss_read.c +++ b/level_3/fss_read/c/payload/fss_read.c @@ -86,17 +86,7 @@ extern "C" { for (;;) { - if (!((++main->program.signal_check) % fss_read_signal_check_d)) { - if (fll_program_standard_signal_received(&main->program)) { - fll_program_print_signal_received(&main->program.warning, main->program.signal_received); - - main->setting.state.status = F_status_set_error(F_interrupt); - - break; - } - - main->program.signal_check = 0; - } + if (fss_read_signal_check(main)) return; if (range.start > range.stop) { if (status_pipe == F_none_eof) break; diff --git a/level_3/fss_read/c/payload/fss_read.h b/level_3/fss_read/c/payload/fss_read.h index 31db3a3..6033db7 100644 --- a/level_3/fss_read/c/payload/fss_read.h +++ b/level_3/fss_read/c/payload/fss_read.h @@ -91,6 +91,10 @@ extern "C" { * F_interrupt on (exit) signal received. * * F_parameter (with error bit) if main is NULL or setting is NULL. + * + * Errors (with error bit) from: fss_read_signal_check(). + * + * @see fss_read_signal_check() */ #ifndef _di_fss_read_payload_process_pipe_ extern void fss_read_payload_process_pipe(void * const main); diff --git a/level_3/fss_read/c/payload/main.c b/level_3/fss_read/c/payload/main.c index ce4b54b..af54ccf 100644 --- a/level_3/fss_read/c/payload/main.c +++ b/level_3/fss_read/c/payload/main.c @@ -18,12 +18,10 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.setting.state.custom = (void *) &data; data.setting.standard = fss_read_payload_standard_s; - data.setting.process_content = 0; // Not used by payload. data.setting.process_help = &fss_read_payload_process_help; + data.setting.process_last_line = &fss_read_process_last_line; data.setting.process_normal = &fss_read_process_normal; - data.setting.process_object = 0; // Not used by payload. data.setting.process_pipe = &fss_read_payload_process_pipe; - data.setting.process_set = &fss_read_payload_process_set; f_console_parameter_t parameters[] = fss_read_console_parameter_t_initialize; data.program.parameters.array = parameters; -- 1.8.3.1