From: Kevin Day Date: Wed, 1 Mar 2023 06:11:18 +0000 (-0600) Subject: Progress: Massive, but incomplete, refactor while originally focusing on Featureless... X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=33d3beb81959f27e2062202418e0c0af9167a87a;p=fll Progress: Massive, but incomplete, refactor while originally focusing on Featureless Make. Working on Featureless Make led to a need to refactor the directory recursion logic. This led to me finally getting around to what I knew that I would eventually do. Move the status returns into the state variable and use void returns. I have had and continue to have mixed feelings about this. This should, overall, be better long term for allowing more flexibility and fine-tuned control outside the project. The switch to void returns when having a state variable is done to reduce complexity and confusion over which "status" variable is the correct one. I would not that I also decided to move the "status" variable onto the state. I was originally very undecided whether I should do this and had previously opted to keep the "status" and "state" separate. Making more complicated projects has proven to me that it will be more maintainable just putting the status in the state. These changes have a cascading effect on most of the project and its programs. I got most of the projects done but I did not get around to fixing/updating the programs. As always, with changes this big, look out for regressions and stupid simple mistakes. The unit tests, once updated, will help find these problems. The FSS and IKI processing code, however, need more unit tests to better catch problems. These changes result in having the interrupt handler made more readily available. Follow up changes will be needed to add more interrupt checks where long running or variable length loops are used. The passing of "state" also reduces the number of times "f_state_t status" is needed and should reduce memory footprint to some degree. This has a runtime costs where now in all of these cases a pointer must be resolved to get to the status. This is to be treated as the cost of the newly provided flexibility. There are some related file structure changes. The recursion code has had a lot of redundancy removed. I did not have a chance to properly review the code. Manual testing on directory recursion operations like clone and copy will need to be performed. --- diff --git a/build/level_0/settings b/build/level_0/settings index b4766b3..e4a39e3 100644 --- a/build/level_0/settings +++ b/build/level_0/settings @@ -25,7 +25,7 @@ build_sources_library color.c private-color.c color/common.c build_sources_library console.c console/common.c private-console.c build_sources_library control_group.c control_group/common.c build_sources_library conversion.c private-conversion.c conversion/common.c -build_sources_library directory.c directory/common.c private-directory.c +build_sources_library directory.c directory/common.c directory/type.c private-directory.c directory/private-type.c build_sources_library environment.c build_sources_library execute.c build_sources_library file.c private-file.c file/common.c file/stream.c diff --git a/build/monolithic/settings b/build/monolithic/settings index dd01a5d..99bf6da 100644 --- a/build/monolithic/settings +++ b/build/monolithic/settings @@ -25,7 +25,7 @@ build_sources_library level_0/color.c level_0/private-color.c level_0/color/comm build_sources_library level_0/console.c level_0/console/common.c level_0/private-console.c build_sources_library level_0/control_group.c level_0/control_group/common.c build_sources_library level_0/conversion.c level_0/private-conversion.c level_0/conversion/common.c -build_sources_library level_0/directory.c level_0/directory/common.c level_0/private-directory.c +build_sources_library level_0/directory.c level_0/directory/common.c level_0/directory/type.c level_0/private-directory.c level_0/directory/private-type.c build_sources_library level_0/environment.c build_sources_library level_0/execute.c build_sources_library level_0/file.c level_0/private-file.c level_0/file/common.c level_0/file/stream.c diff --git a/build/stand_alone/fake.settings b/build/stand_alone/fake.settings index d77939f..3f155ed 100644 --- a/build/stand_alone/fake.settings +++ b/build/stand_alone/fake.settings @@ -67,9 +67,8 @@ build_sources_program fll/level_2/path.c build_sources_program fll/level_2/print.c build_sources_program fll/level_2/program.c fll/level_2/program/common.c fll/level_2/program/print.c fll/level_2/private-program.c -build_sources_program program/fake/main/build.c program/fake/main/clean.c program/fake/main/common.c program/fake/main/fake.c program/fake/main/make.c program/fake/main/print.c program/fake/main/print-error.c program/fake/main/print-warning.c program/fake/main/skeleton.c +build_sources_program program/fake/main/build.c program/fake/main/clean.c program/fake/main/common.c program/fake/main/fake.c program/fake/main/make.c program/fake/main/print.c program/fake/main/print-error.c program/fake/main/print-warning.c program/fake/main/print-verbose.c program/fake/main/skeleton.c build_sources_program program/fake/main/build/library.c program/fake/main/build/load.c program/fake/main/build/object.c program/fake/main/build/objects.c program/fake/main/build/print.c program/fake/main/build/print-error.c program/fake/main/build/print-verbose.c program/fake/main/build/print-warning.c program/fake/main/build/program.c program/fake/main/build/skeleton.c -build_sources_program program/fake/main/clean/print.c build_sources_program program/fake/main/common/define.c program/fake/main/common/enumeration.c program/fake/main/common/print.c program/fake/main/common/string.c program/fake/main/common/type.c build_sources_program program/fake/main/fake/path_generate.c build_sources_program program/fake/main/make/load_fakefile.c program/fake/main/make/load_parameters.c program/fake/main/make/operate_block.c program/fake/main/make/operate.c program/fake/main/make/operate_process.c program/fake/main/make/operate_process_type.c program/fake/main/make/operate_validate.c program/fake/main/make/operate_validate_type.c program/fake/main/make/print.c program/fake/main/make/print-error.c program/fake/main/make/print-verbose.c program/fake/main/make/print-warning.c diff --git a/level_0/f_account/c/account/accounts.h b/level_0/f_account/c/account/accounts.h index 83125c3..5f94925 100644 --- a/level_0/f_account/c/account/accounts.h +++ b/level_0/f_account/c/account/accounts.h @@ -213,7 +213,7 @@ extern "C" { /** * Resize the accounts array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -419,7 +419,7 @@ extern "C" { /** * Resize the string accountss array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_console/c/console.c b/level_0/f_console/c/console.c index 09854b0..89e207d 100644 --- a/level_0/f_console/c/console.c +++ b/level_0/f_console/c/console.c @@ -149,24 +149,33 @@ extern "C" { #endif // _di_f_console_parameter_prioritize_right_ #ifndef _di_f_console_parameter_process_ - f_status_t f_console_parameter_process(f_state_t state_passed, const f_console_arguments_t arguments, f_console_parameters_t * const parameters, void * const data) { + void f_console_parameter_process(const f_console_arguments_t arguments, f_console_parameters_t * const parameters, f_state_t * const state, void * const data) { #ifndef _di_level_0_parameter_checking_ - if (!parameters) return F_status_set_error(F_parameter); + if (!state) return; + if (!parameters) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_0_parameter_checking_ parameters->arguments.used = 0; - if (!arguments.argc || !arguments.argv || !arguments.argv[0]) return F_data_not; + if (!arguments.argc || !arguments.argv || !arguments.argv[0]) { + state->status = F_data_not; + + return; + } - f_console_parameter_state_t state = f_console_parameter_state_t_initialize; + f_console_parameter_state_t process = f_console_parameter_state_t_initialize; - state.state = (f_state_t) state_passed; + process.state = state; - state.status = f_string_dynamics_increase_by(arguments.argc, ¶meters->arguments); - if (F_status_is_error(state.status)) return state.status; + state->status = f_string_dynamics_increase_by(arguments.argc, ¶meters->arguments); + if (F_status_is_error(state->status)) return; - state.status = f_array_lengths_increase(state_passed.step_small, &state.needs); - if (F_status_is_error(state.status)) return state.status; + state->status = f_array_lengths_increase(state->step_small, &process.needs); + if (F_status_is_error(state->status)) return; // Append the program name parameter as a static string. parameters->arguments.array[parameters->arguments.used].string = arguments.argv[0]; @@ -174,7 +183,7 @@ extern "C" { parameters->arguments.array[parameters->arguments.used++].size = 0; // Parameter 0 represents the program name so skip it. - state.location = 1; + process.location = 1; f_array_length_t i = 0; f_array_length_t j = 0; @@ -182,356 +191,337 @@ extern "C" { f_utf_char_t utf_argument = 0; f_utf_char_t utf_console = 0; - while (state.location < arguments.argc && arguments.argv[state.location]) { + while (process.location < arguments.argc && arguments.argv[process.location]) { - if (state_passed.interrupt) { - state.status = state_passed.interrupt((void * const) &state_passed, 0); - - if (F_status_set_fine(state.status) == F_interrupt) { - state.status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void * const) state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } - parameters->arguments.array[parameters->arguments.used].string = arguments.argv[state.location]; - parameters->arguments.array[parameters->arguments.used].used = strnlen(arguments.argv[state.location], F_console_parameter_size_d); + parameters->arguments.array[parameters->arguments.used].string = arguments.argv[process.location]; + parameters->arguments.array[parameters->arguments.used].used = strnlen(arguments.argv[process.location], F_console_parameter_size_d); parameters->arguments.array[parameters->arguments.used++].size = 0; // Additional parameters must always follow what requests them. - if (state.needs.used) { + if (process.needs.used) { if (parameters->callback) { - state.type = f_console_parameter_state_type_need_e; - state.at = state.needs.array[0]; + process.type = f_console_parameter_state_type_need_e; + process.at = process.needs.array[0]; - parameters->callback(arguments, (void * const) parameters, &state, data); - if (F_status_is_error(state.status)) break; - if (state.status == F_break) break; - if (state.status == F_continue) continue; + parameters->callback(arguments, (void * const) parameters, &process, data); + if (F_status_is_error(state->status)) break; + if (state->status == F_break) break; + if (state->status == F_continue) continue; } else { - state.status = F_process; + state->status = F_process; } - if (state.status == F_process) { - i = state.needs.array[0]; + if (state->status == F_process) { + i = process.needs.array[0]; parameters->array[i].result |= f_console_result_value_e; - parameters->array[i].values.array[parameters->array[i].values.used++] = state.location++; + parameters->array[i].values.array[parameters->array[i].values.used++] = process.location++; } - --state.needs.used; + --process.needs.used; - for (i = 0; i < state.needs.used; ++i) { - state.needs.array[i] = state.needs.array[i + 1]; + for (i = 0; i < process.needs.used; ++i) { + process.needs.array[i] = process.needs.array[i + 1]; } // for - state.status = F_none; + state->status = F_none; continue; } if (parameters->callback) { - state.type = f_console_parameter_state_type_identify_e; - state.at = 0; + process.type = f_console_parameter_state_type_identify_e; + process.at = 0; - parameters->callback(arguments, (void * const) parameters, &state, data); - if (F_status_is_error(state.status)) break; - if (state.status == F_break) break; - if (state.status == F_continue) continue; + parameters->callback(arguments, (void * const) parameters, &process, data); + if (F_status_is_error(state->status)) break; + if (state->status == F_break) break; + if (state->status == F_continue) continue; } else { - state.status = F_process; + state->status = F_process; } - if (state.status == F_process) { - private_f_console_identify(arguments.argv[state.location], &state.result); + if (state->status == F_process) { + state->status = private_f_console_identify(arguments.argv[process.location], &process.result); + if (F_status_is_error(state->status)) break; } - state.found = F_false; - state.status = F_none; + process.found = F_false; + state->status = F_none; - if (state.result & f_console_result_short_e) { + if (process.result & f_console_result_short_e) { // Perform pre-process. - for (state.location_sub = 1; state.location_sub < parameters->arguments.array[state.location].used; ++state.location_sub) { + for (process.location_sub = 1; process.location_sub < parameters->arguments.array[process.location].used; ++process.location_sub) { - state.found = F_false; + process.found = F_false; for (i = 0; i < parameters->used; ++i) { - if (state_passed.interrupt) { - state.status = state_passed.interrupt((void * const) &state_passed, 0); - - if (F_status_set_fine(state.status) == F_interrupt) { - state.status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void * const) state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (parameters->array[i].flag & f_console_flag_disable_e) continue; - if ((state.result & f_console_result_normal_e) && !(parameters->array[i].flag & f_console_flag_normal_e)) continue; - if ((state.result & f_console_result_inverse_e) && !(parameters->array[i].flag & f_console_flag_inverse_e)) continue; + if ((process.result & f_console_result_normal_e) && !(parameters->array[i].flag & f_console_flag_normal_e)) continue; + if ((process.result & f_console_result_inverse_e) && !(parameters->array[i].flag & f_console_flag_inverse_e)) continue; if (!parameters->array[i].match_short.used && !parameters->array[i].match_short.string) continue; - if (arguments.argv[state.location][state.location_sub] != *parameters->array[i].match_short.string) continue; + if (arguments.argv[process.location][process.location_sub] != *parameters->array[i].match_short.string) continue; - state.width = macro_f_utf_byte_width_is(arguments.argv[state.location][state.location_sub]); + process.width = macro_f_utf_byte_width_is(arguments.argv[process.location][process.location_sub]); if (parameters->callback) { - state.type = f_console_parameter_state_type_short_preprocess_e; - state.at = i; + process.type = f_console_parameter_state_type_short_preprocess_e; + process.at = i; - parameters->callback(arguments, (void * const) parameters, &state, data); - if (F_status_is_error(state.status)) break; + parameters->callback(arguments, (void * const) parameters, &process, data); + if (F_status_is_error(state->status)) break; - if (state.status == F_break || state.status == F_continue) { - if (state.depth) { - --state.depth; + if (state->status == F_break || state->status == F_continue) { + if (process.depth) { + --process.depth; break; } - state.status = F_none; + state->status = F_none; - if (state.status == F_break) break; + if (state->status == F_break) break; continue; } } else { - state.status = F_process; + state->status = F_process; } - if (state.status == F_process) { - if (state.width) { + if (state->status == F_process) { + if (process.width) { utf_argument = 0; utf_console = 0; - state.status = f_utf_char_to_character(arguments.argv[state.location] + state.location_sub, parameters->arguments.array[state.location].used - state.location_sub, &utf_argument); - if (F_status_is_error(state.status)) break; + state->status = f_utf_char_to_character(arguments.argv[process.location] + process.location_sub, parameters->arguments.array[process.location].used - process.location_sub, &utf_argument); + if (F_status_is_error(state->status)) break; - state.status = f_utf_char_to_character(parameters->array[i].match_short.string, parameters->array[i].match_short.used, &utf_console); - if (F_status_is_error(state.status)) break; + state->status = f_utf_char_to_character(parameters->array[i].match_short.string, parameters->array[i].match_short.used, &utf_console); + if (F_status_is_error(state->status)) break; if (utf_argument != utf_console) continue; } } - state.found = F_true; + process.found = F_true; break; } // for - if (F_status_is_error(state.status)) break; + if (F_status_is_error(state->status)) break; - if (state.status == F_break || state.status == F_continue) { - if (state.depth) { - --state.depth; + if (state->status == F_break || state->status == F_continue) { + if (process.depth) { + --process.depth; break; } - state.status = F_none; + state->status = F_none; - if (state.status == F_break) break; + if (state->status == F_break) break; continue; } - if (!state.found) break; + if (!process.found) break; } // for - if (F_status_is_error(state.status)) break; + if (F_status_is_error(state->status)) break; - if (state.status == F_break || state.status == F_continue) { - state.depth = 0; - state.status = F_none; + if (state->status == F_break || state->status == F_continue) { + process.depth = 0; + state->status = F_none; - if (state.status == F_break) break; + if (state->status == F_break) break; continue; } // The entire string references valid parameters. - if (state.found) { - state.location_sub = 1; - state.needs.used = 0; + if (process.found) { + process.location_sub = 1; + process.needs.used = 0; - state.status = f_array_lengths_increase_by(parameters->arguments.array[state.location].used, &state.needs); - if (F_status_is_error(state.status)) break; + state->status = f_array_lengths_increase_by(parameters->arguments.array[process.location].used, &process.needs); + if (F_status_is_error(state->status)) break; - // The state.location_sub is used on a per-increment basis (such as 'tar -xcf', the '-' would have an increment of 1, therefore x, c, and f would all be three separate parameters). - while (state.location_sub < parameters->arguments.array[state.location].used) { + // The process.location_sub is used on a per-increment basis (such as 'tar -xcf', the '-' would have an increment of 1, therefore x, c, and f would all be three separate parameters). + while (process.location_sub < parameters->arguments.array[process.location].used) { - state.width = macro_f_utf_byte_width_is(arguments.argv[state.location][state.location_sub]); + process.width = macro_f_utf_byte_width_is(arguments.argv[process.location][process.location_sub]); - if (state.width) { + if (process.width) { utf_argument = 0; utf_console = 0; - state.status = f_utf_char_to_character(arguments.argv[state.location] + state.location_sub, parameters->arguments.array[state.location].used - state.location_sub, &utf_argument); - if (F_status_is_error(state.status)) break; + state->status = f_utf_char_to_character(arguments.argv[process.location] + process.location_sub, parameters->arguments.array[process.location].used - process.location_sub, &utf_argument); + if (F_status_is_error(state->status)) break; - state.status = f_utf_char_to_character(parameters->array[i].match_short.string, parameters->array[i].match_short.used, &utf_console); - if (F_status_is_error(state.status)) break; + state->status = f_utf_char_to_character(parameters->array[i].match_short.string, parameters->array[i].match_short.used, &utf_console); + if (F_status_is_error(state->status)) break; if (utf_argument != utf_console) continue; } else { - state.width = 1; + process.width = 1; } for (i = 0; i < parameters->used; ++i) { - if (state_passed.interrupt) { - state.status = state_passed.interrupt((void * const) &state_passed, 0); - - if (F_status_set_fine(state.status) == F_interrupt) { - state.status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void * const) state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (parameters->array[i].flag & f_console_flag_disable_e) continue; - if ((state.result & f_console_result_normal_e) && !(parameters->array[i].flag & f_console_flag_normal_e)) continue; - if ((state.result & f_console_result_inverse_e) && !(parameters->array[i].flag & f_console_flag_inverse_e)) continue; + if ((process.result & f_console_result_normal_e) && !(parameters->array[i].flag & f_console_flag_normal_e)) continue; + if ((process.result & f_console_result_inverse_e) && !(parameters->array[i].flag & f_console_flag_inverse_e)) continue; if (!parameters->array[i].match_short.used && !parameters->array[i].match_short.string) continue; - if (arguments.argv[state.location][state.location_sub] != *parameters->array[i].match_short.string) continue; + if (arguments.argv[process.location][process.location_sub] != *parameters->array[i].match_short.string) continue; if (parameters->callback) { - state.type = f_console_parameter_state_type_short_e; - state.at = i; + process.type = f_console_parameter_state_type_short_e; + process.at = i; - parameters->callback(arguments, (void * const) parameters, &state, data); - if (F_status_is_error(state.status)) break; + parameters->callback(arguments, (void * const) parameters, &process, data); + if (F_status_is_error(state->status)) break; - if (state.status == F_break || state.status == F_continue) { - if (state.depth) { - --state.depth; + if (state->status == F_break || state->status == F_continue) { + if (process.depth) { + --process.depth; break; } - state.status = F_none; + state->status = F_none; - if (state.status == F_break) break; + if (state->status == F_break) break; continue; } } else { - state.status = F_process; + state->status = F_process; } - if (state.status == F_process) { - state.status = f_array_lengths_increase(state_passed.step_small, ¶meters->array[i].locations); - if (F_status_is_error(state.status)) break; + if (state->status == F_process) { + state->status = f_array_lengths_increase(state->step_small, ¶meters->array[i].locations); + if (F_status_is_error(state->status)) break; - state.status = f_array_lengths_increase(state_passed.step_small, ¶meters->array[i].locations_sub); - if (F_status_is_error(state.status)) break; + state->status = f_array_lengths_increase(state->step_small, ¶meters->array[i].locations_sub); + if (F_status_is_error(state->status)) break; - if (parameters->array[i].location != state.location) { - parameters->array[i].locations.array[parameters->array[i].locations.used++] = state.location; + if (parameters->array[i].location != process.location) { + parameters->array[i].locations.array[parameters->array[i].locations.used++] = process.location; } - parameters->array[i].result |= state.result | f_console_result_found_e; - parameters->array[i].location = state.location; - parameters->array[i].location_sub = state.location_sub; - parameters->array[i].locations_sub.array[parameters->array[i].locations_sub.used++] = state.location_sub; + parameters->array[i].result |= process.result | f_console_result_found_e; + parameters->array[i].location = process.location; + parameters->array[i].location_sub = process.location_sub; + parameters->array[i].locations_sub.array[parameters->array[i].locations_sub.used++] = process.location_sub; for (j = 0; j < parameters->array[i].values_total; ++j) { - state.needs.array[state.needs.used++] = i; + process.needs.array[process.needs.used++] = i; } // for - state.status = f_array_lengths_increase_by(state.needs.used, ¶meters->array[i].values); - if (F_status_is_error(state.status)) break; + state->status = f_array_lengths_increase_by(process.needs.used, ¶meters->array[i].values); + if (F_status_is_error(state->status)) break; } - state.status = F_none; + state->status = F_none; break; } // for - if (F_status_is_error(state.status)) break; + if (F_status_is_error(state->status)) break; - if (state.status == F_break || state.status == F_continue) { - if (state.depth) { - --state.depth; + if (state->status == F_break || state->status == F_continue) { + if (process.depth) { + --process.depth; break; } - state.status = F_none; + state->status = F_none; - if (state.status == F_break) break; + if (state->status == F_break) break; continue; } - state.location_sub += state.width; + process.location_sub += process.width; } // while - if (state.status == F_break || state.status == F_continue) { - state.depth = 0; - state.status = F_none; + if (state->status == F_break || state->status == F_continue) { + process.depth = 0; + state->status = F_none; - if (state.status == F_break) break; + if (state->status == F_break) break; continue; } } } else { - if (state.result & f_console_result_long_e) { - state.location_sub = 2; - state.needs.used = 0; + if (process.result & f_console_result_long_e) { + process.location_sub = 2; + process.needs.used = 0; for (i = 0; i < parameters->used; ++i) { - if (state_passed.interrupt) { - state.status = state_passed.interrupt((void * const) &state_passed, 0); - - if (F_status_set_fine(state.status) == F_interrupt) { - state.status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void * const) state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (parameters->array[i].flag & f_console_flag_disable_e) continue; - if ((state.result & f_console_result_normal_e) && !(parameters->array[i].flag & f_console_flag_normal_e)) continue; - if ((state.result & f_console_result_inverse_e) && !(parameters->array[i].flag & f_console_flag_inverse_e)) continue; + if ((process.result & f_console_result_normal_e) && !(parameters->array[i].flag & f_console_flag_normal_e)) continue; + if ((process.result & f_console_result_inverse_e) && !(parameters->array[i].flag & f_console_flag_inverse_e)) continue; if (!parameters->array[i].match_long.used && !parameters->array[i].match_long.string) continue; - if (strncmp(&arguments.argv[state.location][state.location_sub], parameters->array[i].match_long.string, parameters->array[i].match_long.used + 1)) continue; + if (strncmp(&arguments.argv[process.location][process.location_sub], parameters->array[i].match_long.string, parameters->array[i].match_long.used + 1)) continue; if (parameters->callback) { - state.type = f_console_parameter_state_type_long_e; - state.at = i; + process.type = f_console_parameter_state_type_long_e; + process.at = i; - parameters->callback(arguments, (void * const) parameters, &state, data); - if (F_status_is_error(state.status)) break; + parameters->callback(arguments, (void * const) parameters, &process, data); + if (F_status_is_error(state->status)) break; - if (state.status == F_break || state.status == F_continue) { - if (state.depth) { - --state.depth; + if (state->status == F_break || state->status == F_continue) { + if (process.depth) { + --process.depth; break; } - state.status = F_none; + state->status = F_none; - if (state.status == F_break) break; + if (state->status == F_break) break; continue; } } else { - state.status = F_process; + state->status = F_process; } - state.found = F_true; + process.found = F_true; break; } // for @@ -539,156 +529,144 @@ extern "C" { else { for (i = 0; i < parameters->used; ++i) { - if (state_passed.interrupt) { - state.status = state_passed.interrupt((void * const) &state_passed, 0); - - if (F_status_set_fine(state.status) == F_interrupt) { - state.status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void * const) state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (parameters->array[i].flag & f_console_flag_disable_e) continue; if (!(parameters->array[i].flag & f_console_flag_simple_e)) continue; if (!parameters->array[i].match_simple.used && !parameters->array[i].match_simple.string) continue; - if (strncmp(arguments.argv[state.location], parameters->array[i].match_simple.string, parameters->array[i].match_simple.used + 1)) continue; + if (strncmp(arguments.argv[process.location], parameters->array[i].match_simple.string, parameters->array[i].match_simple.used + 1)) continue; if (parameters->callback) { - state.type = f_console_parameter_state_type_simple_e; - state.at = i; + process.type = f_console_parameter_state_type_simple_e; + process.at = i; - parameters->callback(arguments, (void * const) parameters, &state, data); - if (F_status_is_error(state.status)) break; + parameters->callback(arguments, (void * const) parameters, &process, data); + if (F_status_is_error(state->status)) break; - if (state.status == F_break || state.status == F_continue) { - if (state.depth) { - --state.depth; + if (state->status == F_break || state->status == F_continue) { + if (process.depth) { + --process.depth; break; } - state.status = F_none; + state->status = F_none; - if (state.status == F_break) break; + if (state->status == F_break) break; continue; } } else { - state.status = F_process; + state->status = F_process; } - state.found = F_true; + process.found = F_true; break; } // for } - if (F_status_is_error(state.status)) break; + if (F_status_is_error(state->status)) break; - if (state.status == F_break || state.status == F_continue) { - state.depth = 0; - state.status = F_none; + if (state->status == F_break || state->status == F_continue) { + process.depth = 0; + state->status = F_none; - if (state.status == F_break) break; + if (state->status == F_break) break; continue; } - if (state.status == F_process && state.found) { - state.status = f_array_lengths_increase(state_passed.step_small, ¶meters->array[i].locations); - if (F_status_is_error(state.status)) break; + if (state->status == F_process && process.found) { + state->status = f_array_lengths_increase(state->step_small, ¶meters->array[i].locations); + if (F_status_is_error(state->status)) break; - state.status = f_array_lengths_increase(state_passed.step_small, ¶meters->array[i].locations_sub); - if (F_status_is_error(state.status)) break; + state->status = f_array_lengths_increase(state->step_small, ¶meters->array[i].locations_sub); + if (F_status_is_error(state->status)) break; - parameters->array[i].result |= state.result | f_console_result_found_e; - parameters->array[i].location = state.location; + parameters->array[i].result |= process.result | f_console_result_found_e; + parameters->array[i].location = process.location; parameters->array[i].location_sub = 0; - parameters->array[i].locations.array[parameters->array[i].locations.used++] = state.location; + parameters->array[i].locations.array[parameters->array[i].locations.used++] = process.location; parameters->array[i].locations_sub.array[parameters->array[i].locations_sub.used++] = 0; for (j = 0; j < parameters->array[i].values_total; ++j) { - state.needs.array[state.needs.used++] = i; + process.needs.array[process.needs.used++] = i; } // for - state.status = f_array_lengths_increase_by(state.needs.used, ¶meters->array[i].values); - if (F_status_is_error(state.status)) break; + state->status = f_array_lengths_increase_by(process.needs.used, ¶meters->array[i].values); + if (F_status_is_error(state->status)) break; } - state.status = F_none; + state->status = F_none; } - if (F_status_is_error(state.status)) break; + if (F_status_is_error(state->status)) break; // Add the missed parameter to the remaining array. - if (!state.found) { + if (!process.found) { if (parameters->callback) { - state.type = f_console_parameter_state_type_miss_e; - state.at = 0; + process.type = f_console_parameter_state_type_miss_e; + process.at = 0; - parameters->callback(arguments, (void * const) parameters, &state, data); - if (F_status_is_error(state.status)) break; - if (state.status == F_break) break; - if (state.status == F_continue) continue; + parameters->callback(arguments, (void * const) parameters, &process, data); + if (F_status_is_error(state->status)) break; + if (state->status == F_break) break; + if (state->status == F_continue) continue; } else { - state.status = F_process; + state->status = F_process; } - if (state.status == F_process) { - state.status = f_array_lengths_increase(state_passed.step_small, ¶meters->remaining); - if (F_status_is_error(state.status)) break; + if (state->status == F_process) { + state->status = f_array_lengths_increase(state->step_small, ¶meters->remaining); + if (F_status_is_error(state->status)) break; - parameters->remaining.array[parameters->remaining.used++] = state.location; + parameters->remaining.array[parameters->remaining.used++] = process.location; } - state.status = F_none; + state->status = F_none; } - ++state.location; + ++process.location; } // while // Make sure the entire parameters arguments array is populated. if (parameters->callback) { - state.type = f_console_parameter_state_type_wrap_up_e; - state.at = 0; + process.type = f_console_parameter_state_type_wrap_up_e; + process.at = 0; - parameters->callback(arguments, (void * const) parameters, &state, data); + parameters->callback(arguments, (void * const) parameters, &process, data); } else { - state.status = F_process; + state->status = F_process; } - if (state.status == F_process) { - state.status = F_none; - - for (; state.location < arguments.argc && arguments.argv[state.location]; ++state.location) { - - if (state_passed.interrupt) { - state.status = state_passed.interrupt((void * const) &state_passed, 0); + if (state->status == F_process) { + state->status = F_none; - if (F_status_set_fine(state.status) == F_interrupt) { - state.status = F_status_set_error(F_interrupt); + for (; process.location < arguments.argc && arguments.argv[process.location]; ++process.location) { - break; - } + if (state->interrupt) { + state->interrupt((void * const) state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } - parameters->arguments.array[parameters->arguments.used].string = arguments.argv[state.location]; - parameters->arguments.array[parameters->arguments.used].used = strnlen(arguments.argv[state.location], F_console_parameter_size_d); + parameters->arguments.array[parameters->arguments.used].string = arguments.argv[process.location]; + parameters->arguments.array[parameters->arguments.used].used = strnlen(arguments.argv[process.location], F_console_parameter_size_d); parameters->arguments.array[parameters->arguments.used++].size = 0; } // for - if (F_status_is_error_not(state.status)) { - state.status = state.needs.used ? F_complete_not : F_none; + if (F_status_is_error_not(state->status)) { + state->status = process.needs.used ? F_complete_not : F_none; } } - f_array_lengths_resize(0, &state.needs); - - return state.status; + f_array_lengths_resize(0, &process.needs); } #endif // _di_f_console_parameter_process_ diff --git a/level_0/f_console/c/console.h b/level_0/f_console/c/console.h index 3055a27..ae05720 100644 --- a/level_0/f_console/c/console.h +++ b/level_0/f_console/c/console.h @@ -155,26 +155,26 @@ extern "C" { * * Any changes to this function may likely require changes to f_console_parameter_state_t and callbacks. * - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param arguments * The parameters passed to the process. * @param parameters * The console parameters to look for. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * + * This alters state.status: + * F_none on success. + * F_data_not if argc is 0, argv is a NULL pointer, or if argv[0] is NULL. + * F_complete_not if "values" parameters were expected but not found. + * + * F_array_too_large (with error bit) if a buffer would exceed max length. + * F_failure (with error bit) if width is not long enough to convert when processing arguments as UTF-8. + * F_interrupt (with error bit) if an interrupt is received via the state.interrupt callback. + * F_parameter (with error bit) if a parameter is invalid. * @param data * (optional) A variable passed to the callback, if provided. * Set to NULL to not use. * - * @return - * F_none on success. - * F_data_not if argc is 0, argv is a NULL pointer, or if argv[0] is NULL. - * F_complete_not if "values" parameters were expected but not found. - * - * F_array_too_large (with error bit) if a buffer would exceed max length. - * F_failure (with error bit) if width is not long enough to convert when processing arguments as UTF-8. - * F_interrupt (with error bit) if an interrupt is received via the state.interrupt callback. - * F_parameter (with error bit) if a parameter is invalid. - * * Errors (with error bit) from: f_array_lengths_increase(). * Errors (with error bit) from: f_array_lengths_increase_by(). * Errors (with error bit) from: f_string_dynamics_increase_by(). @@ -186,7 +186,7 @@ extern "C" { * @see f_utf_char_to_character() */ #ifndef _di_f_console_parameter_process_ - extern f_status_t f_console_parameter_process(f_state_t state, const f_console_arguments_t arguments, f_console_parameters_t * const parameters, void * const data); + extern void f_console_parameter_process(const f_console_arguments_t arguments, f_console_parameters_t * const parameters, f_state_t * const state, void * const data); #endif // _di_f_console_parameter_process_ #ifdef __cplusplus diff --git a/level_0/f_console/c/console/common.h b/level_0/f_console/c/console/common.h index 0119ac5..e2a6247 100644 --- a/level_0/f_console/c/console/common.h +++ b/level_0/f_console/c/console/common.h @@ -239,9 +239,8 @@ extern "C" { * width: Used like a cache to store width results such as from macro_f_utf_byte_width_is(). * found: Designate that the currently process parameter has been matched. * - * status: The return status. * result: The parameter result state determined by the appropriate f_console_identify() or similar call. - * state: The state information used during pocessing (this primarily utilizes the interrupt and the allocation steps). + * state: A pointer to the state information. * * at: The location in the parameters array currently being processed (not all types use this). * location: The current location within the argv array. @@ -318,9 +317,8 @@ extern "C" { uint8_t width; bool found; - f_status_t status; f_console_result_t result; - f_state_t state; + f_state_t *state; f_array_length_t at; f_array_length_t location; @@ -333,9 +331,8 @@ extern "C" { 0, \ 0, \ F_false, \ - F_none, \ f_console_result_t_initialize, \ - f_state_t_initialize, \ + 0, \ f_array_length_t_initialize, \ f_array_length_t_initialize, \ f_array_length_t_initialize, \ diff --git a/level_0/f_directory/c/directory.c b/level_0/f_directory/c/directory.c index fda3476..438d24b 100644 --- a/level_0/f_directory/c/directory.c +++ b/level_0/f_directory/c/directory.c @@ -165,7 +165,7 @@ extern "C" { for (; i < length; ++i) { - size = strnlen(listing[i]->d_name, F_directory_name_max_d); + size = strnlen(listing[i]->d_name, F_directory_max_name_d); // There is no reason to include "." and ".." in the directory listing. if (!strncmp(listing[i]->d_name, f_directory_back_s.string, f_directory_back_s.used + 1) || !strncmp(listing[i]->d_name, f_directory_current_s.string, f_directory_current_s.used + 1)) { @@ -174,7 +174,7 @@ extern "C" { continue; } - status = f_string_dynamics_increase(F_directory_default_allocation_step_d, names); + status = f_string_dynamics_increase(F_memory_default_allocation_small_d, names); if (F_status_is_error(status)) { for (; i < length; ++i) { diff --git a/level_0/f_directory/c/directory/common.h b/level_0/f_directory/c/directory/common.h index 7ed226d..c7a9546 100644 --- a/level_0/f_directory/c/directory/common.h +++ b/level_0/f_directory/c/directory/common.h @@ -79,20 +79,52 @@ extern "C" { /** * Provide limitations and related defines. * - * The directory max descriptors is more of a default than a rule. - * This is generally used for nftw() recursive operations to reduce the number of open file descriptors during recursion. + * The F_directory_max_list_d and F_directory_max_string_d parameters are used in recursive calls that general re-use memory space. + * These designate that there be a maximum size to preserve to keep from preserving exceptionally large memory allocation sizes. + * + * F_directory_max_*_d: + * - descriptors: The maximum directory descriptors, and is generally used for nftw(). + * - list: The maximum directory list length to preserve between recursive calls. + * - name: The maximum name of a directory. + * - recurse_depth: The maximum recursion depth. + * - string: The maximum directory list name length to preserve between recursive calls. */ -#ifndef _di_f_directory_d_ - #define F_directory_default_allocation_step_d F_memory_default_allocation_small_d - - #define F_directory_descriptors_max_d 255 +#ifndef _di_f_directory_max_d_ + #define F_directory_max_descriptors_d 255 + #define F_directory_max_recurse_depth_d 65535 + #define F_directory_max_list_d 2048 + #define F_directory_max_string_d 256 #ifdef NAME_MAX - #define F_directory_name_max_d NAME_MAX + #define F_directory_max_name_d NAME_MAX #else - #define F_directory_name_max_d 255 + #define F_directory_max_name_d 255 #endif // NAME_MAX -#endif // _di_f_directory_d_ +#endif // _di_f_directory_max_d_ + +/** + * Directory recurse flags. + * + * f_directory_recurse_flag_*: + * - none: No flags are set. + * - clone: Operate as clone instead of as copy, if applicable. + * - dereference: Dereference symbolic links rather than operating on the link itself. + * - exclusive: File flag requiring that a file does not already exist. + * - group: File flag representing copying the group. + * - owner: File flag representing copying the owner. + * - top: Operate on top directory and not just inside the directory. + */ +#ifndef _di_f_directory_recurse_flag_e_ + enum { + f_directory_recurse_flag_none_e = 0, + f_directory_recurse_flag_clone_e = 0x1, + f_directory_recurse_flag_dereference_e = 0x2, + f_directory_recurse_flag_exclusive_e = 0x4, + f_directory_recurse_flag_group_e = 0x8, + f_directory_recurse_flag_owner_e = 0x10, + f_directory_recurse_flag_top_e = 0x20, + }; // enum +#endif // _di_f_directory_recurse_flag_e_ #ifdef __cplusplus } // extern "C" diff --git a/level_0/f_directory/c/directory/private-type.c b/level_0/f_directory/c/directory/private-type.c new file mode 100644 index 0000000..0bc2d93 --- /dev/null +++ b/level_0/f_directory/c/directory/private-type.c @@ -0,0 +1,61 @@ +#include "../directory.h" +#include "private-type.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(_di_f_directory_statuss_adjust_) || !defined(_di_f_directory_statuss_decimate_by_) + f_status_t private_f_directory_statuss_adjust(const f_array_length_t length, f_directory_statuss_t * const statuss) { + + f_status_t status = F_none; + + for (f_array_length_t i = length; i < statuss->size; ++i) { + + status = f_string_dynamic_adjust(0, &statuss->array[i].path); + if (F_status_is_error(status)) return status; + } // for + + status = f_memory_adjust(statuss->size, length, sizeof(f_directory_status_t), (void **) & statuss->array); + + if (F_status_is_error_not(status)) { + statuss->size = length; + + if (statuss->used > statuss->size) { + statuss->used = length; + } + } + + if (F_status_is_error(status)) return status; + + return F_none; + } +#endif // !defined(_di_f_directory_statuss_adjust_) || !defined(_di_f_directory_statuss_decimate_by_) + +#if !defined(_di_f_directory_statuss_decrease_by_) || !defined(_di_f_directory_statuss_increase_) || !defined(_di_f_directory_statuss_increase_by_) || !defined(_di_f_directory_statuss_resize_) + f_status_t private_f_directory_statuss_resize(const f_array_length_t length, f_directory_statuss_t * const statuss) { + + f_status_t status = F_none; + + for (f_array_length_t i = length; i < statuss->size; ++i) { + + status = f_string_dynamic_resize(0, &statuss->array[i].path); + if (F_status_is_error(status)) return status; + } // for + + status = f_memory_resize(statuss->size, length, sizeof(f_directory_status_t), (void **) & statuss->array); + if (F_status_is_error(status)) return status; + + statuss->size = length; + + if (statuss->used > statuss->size) { + statuss->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_directory_statuss_decrease_by_) || !defined(_di_f_directory_statuss_increase_) || !defined(_di_f_directory_statuss_increase_by_) || !defined(_di_f_directory_statuss_resize_) + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_directory/c/directory/private-type.h b/level_0/f_directory/c/directory/private-type.h new file mode 100644 index 0000000..f79de9a --- /dev/null +++ b/level_0/f_directory/c/directory/private-type.h @@ -0,0 +1,75 @@ +/** + * FLL - Level 0 + * + * Project: Directory + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * These are provided for internal reduction in redundant code. + * These should not be exposed/used outside of this project. + */ +#ifndef _PRIVATE_F_directory_type_h +#define _PRIVATE_F_directory_type_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param statuss + * The statuss to adjust. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: f_memory_adjust(). + * Errors (with error bit) from: private_f_directory_status_adjust(). + * + * @see private_f_directory_status_adjust() + * + * @see f_directory_statuss_adjust() + * @see f_directory_statuss_decimate_by() + * @see f_memory_adjust() + */ +#if !defined(_di_f_directory_statuss_adjust_) || !defined(_di_f_directory_statuss_decimate_by_) + extern f_status_t private_f_directory_statuss_adjust(const f_array_length_t length, f_directory_statuss_t * const statuss) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_directory_statuss_adjust_) || !defined(_di_f_directory_statuss_decimate_by_) + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param statuss + * The statuss to resize. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: f_string_dynamic_resize(). + * + * @see f_string_dynamic_resize() + * + * @see f_directory_statuss_decrease_by() + * @see f_directory_statuss_increase() + * @see f_directory_statuss_increase_by() + * @see f_directory_statuss_resize() + * @see f_memory_resize() + */ +#if !defined(_di_f_directory_statuss_decrease_by_) || !defined(_di_f_directory_statuss_increase_) || !defined(_di_f_directory_statuss_increase_by_) || !defined(_di_f_directory_statuss_resize_) + extern f_status_t private_f_directory_statuss_resize(const f_array_length_t length, f_directory_statuss_t * const statuss) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_directory_statuss_decrease_by_) || !defined(_di_f_directory_statuss_increase_) || !defined(_di_f_directory_statuss_increase_by_) || !defined(_di_f_directory_statuss_resize_) + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _PRIVATE_F_directory_type_h diff --git a/level_0/f_directory/c/directory/type.c b/level_0/f_directory/c/directory/type.c new file mode 100644 index 0000000..3dd22b9 --- /dev/null +++ b/level_0/f_directory/c/directory/type.c @@ -0,0 +1,154 @@ +#include "../directory.h" +#include "private-type.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_directory_listing_delete_ + f_status_t f_directory_listing_delete(f_directory_listing_t * const listing) { + #ifndef _di_level_0_parameter_checking_ + if (!listing) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + f_string_dynamics_resize(0, &listing->block); + f_string_dynamics_resize(0, &listing->character); + f_string_dynamics_resize(0, &listing->directory); + f_string_dynamics_resize(0, &listing->regular); + f_string_dynamics_resize(0, &listing->link); + f_string_dynamics_resize(0, &listing->fifo); + f_string_dynamics_resize(0, &listing->socket); + f_string_dynamics_resize(0, &listing->unknown); + + return F_none; + } +#endif // _di_f_directory_listing_delete_ + +#ifndef _di_f_directory_listing_destroy_ + f_status_t f_directory_listing_destroy(f_directory_listing_t * const listing) { + #ifndef _di_level_0_parameter_checking_ + if (!listing) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + f_string_dynamics_adjust(0, &listing->block); + f_string_dynamics_adjust(0, &listing->character); + f_string_dynamics_adjust(0, &listing->directory); + f_string_dynamics_adjust(0, &listing->regular); + f_string_dynamics_adjust(0, &listing->link); + f_string_dynamics_adjust(0, &listing->fifo); + f_string_dynamics_adjust(0, &listing->socket); + f_string_dynamics_adjust(0, &listing->unknown); + + return F_none; + } +#endif // _di_f_directory_listing_destroy_ + +#ifndef _di_f_directory_recurse_delete_ + f_status_t f_directory_recurse_delete(f_directory_recurse_t * const recurse) { + #ifndef _di_level_0_parameter_checking_ + if (!recurse) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + f_directory_listing_delete(&recurse->listing); + + return F_none; + } +#endif // _di_f_directory_recurse_delete_ + +#ifndef _di_f_directory_recurse_destroy_ + f_status_t f_directory_recurse_destroy(f_directory_recurse_t * const recurse) { + #ifndef _di_level_0_parameter_checking_ + if (!recurse) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + f_directory_listing_destroy(&recurse->listing); + + return F_none; + } +#endif // _di_f_directory_recurse_destroy_ + +#ifndef _di_f_directory_statuss_adjust_ + f_status_t f_directory_statuss_adjust(const f_array_length_t length, f_directory_statuss_t * const statuss) { + #ifndef _di_level_0_parameter_checking_ + if (!statuss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_directory_statuss_adjust(length, statuss); + } +#endif // _di_f_directory_statuss_adjust_ + +#ifndef _di_f_directory_statuss_decimate_by_ + f_status_t f_directory_statuss_decimate_by(const f_array_length_t amount, f_directory_statuss_t * const statuss) { + #ifndef _di_level_0_parameter_checking_ + if (!statuss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (statuss->size - amount > 0) { + return private_f_directory_statuss_adjust(statuss->size - amount, statuss); + } + + return private_f_directory_statuss_adjust(0, statuss); + } +#endif // _di_f_directory_statuss_decimate_by_ + +#ifndef _di_f_directory_statuss_decrease_by_ + f_status_t f_directory_statuss_decrease_by(const f_array_length_t amount, f_directory_statuss_t * const statuss) { + #ifndef _di_level_0_parameter_checking_ + if (!statuss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (statuss->size - amount > 0) { + return private_f_directory_statuss_resize(statuss->size - amount, statuss); + } + + return private_f_directory_statuss_resize(0, statuss); + } +#endif // _di_f_directory_statuss_decrease_by_ + +#ifndef _di_f_directory_statuss_increase_ + f_status_t f_directory_statuss_increase(const f_array_length_t step, f_directory_statuss_t * const statuss) { + #ifndef _di_level_0_parameter_checking_ + if (!statuss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && statuss->used + 1 > statuss->size) { + f_array_length_t size = statuss->used + step; + + if (size > F_array_length_t_size_d) { + if (statuss->used + 1 > F_array_length_t_size_d) return F_status_set_error(F_array_too_large); + + size = F_array_length_t_size_d; + } + + return private_f_directory_statuss_resize(size, statuss); + } + + return F_data_not; + } +#endif // _di_f_directory_statuss_increase_ + +#ifndef _di_f_directory_statuss_increase_by_ + f_status_t f_directory_statuss_increase_by(const f_array_length_t amount, f_directory_statuss_t * const statuss) { + #ifndef _di_level_0_parameter_checking_ + if (!statuss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (statuss->used + amount > statuss->size) { + if (statuss->used + amount > F_array_length_t_size_d) return F_status_set_error(F_array_too_large); + + return private_f_directory_statuss_resize(statuss->used + amount, statuss); + } + + return F_data_not; + } +#endif // _di_f_directory_statuss_increase_by_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_directory/c/directory/type.h b/level_0/f_directory/c/directory/type.h index 821fa79..9b3647a 100644 --- a/level_0/f_directory/c/directory/type.h +++ b/level_0/f_directory/c/directory/type.h @@ -63,26 +63,6 @@ extern "C" { socket, \ unknown, \ } - - #define macro_f_directory_listing_t_delete_simple(listing) \ - macro_f_string_dynamics_t_delete_simple(listing.block) \ - macro_f_string_dynamics_t_delete_simple(listing.character) \ - macro_f_string_dynamics_t_delete_simple(listing.directory) \ - macro_f_string_dynamics_t_delete_simple(listing.regular) \ - macro_f_string_dynamics_t_delete_simple(listing.link) \ - macro_f_string_dynamics_t_delete_simple(listing.fifo) \ - macro_f_string_dynamics_t_delete_simple(listing.socket) \ - macro_f_string_dynamics_t_delete_simple(listing.unknown) - - #define macro_f_directory_listing_t_destroy_simple(listing) \ - macro_f_string_dynamics_t_destroy_simple(listing.block) \ - macro_f_string_dynamics_t_destroy_simple(listing.character) \ - macro_f_string_dynamics_t_destroy_simple(listing.directory) \ - macro_f_string_dynamics_t_destroy_simple(listing.regular) \ - macro_f_string_dynamics_t_destroy_simple(listing.link) \ - macro_f_string_dynamics_t_destroy_simple(listing.fifo) \ - macro_f_string_dynamics_t_destroy_simple(listing.socket) \ - macro_f_string_dynamics_t_destroy_simple(listing.unknown) #endif // _di_f_directory_listing_t_ /** @@ -102,22 +82,11 @@ extern "C" { #define f_directory_status_t_initialize { 0, f_string_dynamic_t_initialize } - #define macro_f_directory_status_t_initialize(status, path) { status, path } + #define macro_f_directory_status_t_initialize_1(status, path) { status, path } #define macro_f_directory_status_t_clear(directory) \ directory.status = 0; \ macro_f_string_dynamic_t_clear(directory.path); - - #define macro_f_directory_status_t_resize(status, statuses, new_length) macro_f_string_dynamic_t_resize(status, statuses.path, new_length) - #define macro_f_directory_status_t_adjust(status, statuses, new_length) macro_f_string_dynamic_t_adjust(status, statuses.path, new_length) - - #define macro_f_directory_status_t_delete_simple(statuses) macro_f_string_dynamic_t_delete_simple(statuses.path) - #define macro_f_directory_status_t_destroy_simple(statuses) macro_f_string_dynamic_t_destroy_simple(statuses.path) - - #define macro_f_directory_status_t_increase(status, step, values) macro_f_string_dynamic_t_increase(status, step, values) - #define macro_f_directory_status_t_increase_by(status, values, amount) macro_f_string_dynamic_t_increase_by(status, values, amount) - #define macro_f_directory_status_t_decrease_by(status, values, amount) macro_f_string_dynamic_t_decrease_by(status, values, amount) - #define macro_f_directory_status_t_decimate_by(status, values, amount) macro_f_string_dynamic_t_decimate_by(status, values, amount) #endif // _di_f_directory_status_t_ /** @@ -136,64 +105,325 @@ extern "C" { #define f_directory_statuss_t_initialize { 0, 0, 0 } - #define macro_f_directory_statuss_t_initialize(content, size, used) { array, size, used } - #define macro_f_directory_statuss_t_initialize2(array, length) { array, length, length } + #define macro_f_directory_statuss_t_initialize_1(content, size, used) { array, size, used } + #define macro_f_directory_statuss_t_initialize_2(array, length) { array, length, length } #define macro_f_directory_statuss_t_clear(structures) macro_f_memory_structures_clear(structures) - - #define macro_f_directory_statuss_t_resize(status, structures, new_length) \ - status = F_none; \ - if (new_length < structures.size) { \ - for (register f_array_length_t _macro__i = structures.size - new_length; _macro__i < structures.size; ++_macro__i) { \ - macro_f_directory_status_t_resize(status, structures.array[_macro__i], 0); \ - if (F_status_is_error(status)) break; \ - } \ - } \ - if (status == F_none) status = f_memory_resize(structures.size, new_length, sizeof(f_directory_status_t), (void **) & structures.array); \ - if (status == F_none) { \ - structures.size = new_length; \ - if (structures.used > structures.size) structures.used = new_length; \ - } - - #define macro_f_directory_statuss_t_adjust(status, structures, new_length) \ - status = F_none; \ - if (new_length < structures.size) { \ - for (register f_array_length_t _macro__i = structures.size - new_length; _macro__i < structures.size; ++_macro__i) { \ - macro_f_directory_status_t_adjust(status, structures.array[_macro__i], 0); \ - if (F_status_is_error(status)) break; \ - } \ - } \ - if (status == F_none) status = f_memory_adjust(structures.size, new_length, sizeof(f_directory_status_t), (void **) & structures.array); \ - if (status == F_none) { \ - structures.size = new_length; \ - if (structures.used > structures.size) structures.used = new_length; \ - } - - #define macro_f_directory_statuss_t_delete_simple(structures) \ - structures.used = structures.size; \ - while (structures.used) { \ - --structures.used; \ - macro_f_directory_status_t_delete_simple(structures.array[structures.used]); \ - } \ - if (!structures.size) { \ - if (f_memory_resize(structures.size, 0, sizeof(f_directory_status_t), (void **) & structures.array)) { \ - structures.size = 0; \ - } \ - } - - #define macro_f_directory_statuss_t_destroy_simple(structures) \ - structures.used = structures.size; \ - while (structures.used) { \ - --structures.used; \ - macro_f_directory_status_t_destroy_simple(structures.array[structures.used]); \ - } \ - if (!structures.size) { \ - if (f_memory_adjust(structures.size, 0, sizeof(f_directory_status_t), (void **) & structures.array)) { \ - structures.size = 0; \ - } \ - } #endif // _di_f_directory_statuss_t_ +/** + * A structure containing directory recursion information. + * + * The flag is processed as follows (using f_file_stat_flags_*_e): + * - f_file_stat_flag_exclusive_e: + * - If set, fail when file already exists. + * - If not set, do not fail if file already exists (existing file will be replaced). + * - f_file_stat_flag_reference_e: + * - If set, operate directly on a link rather than what it references. + * - If not set, dereference any links. + * + * For clone operations: + * - f_file_stat_flag_group_e: + * - If set, copy the group ids. + * - If not set, do not copy the group ids. + * - f_file_stat_flag_owner_e: + * - If set, copy the owner ids. + * - If not set, do not copy the owner ids. + * + * (For a clone operation, the file mode is always copied.) + * + * The failure() and verbose() callbacks provide full access to this f_directory_recurse_t structure. + * These callbacks must take care to properly modify the structure or they could cause security, integrity, or functionality problems. + * + * flag: A set of flags used exclusively by the directory recurse process (not to be confused with state.flag). + * max_depth: The maximum recursion depth to use. + * size_block: The default number of chunks to read at a time with each chunk being 1-byte (Must be greater than 0). + * depth: A number representing the depth recursed thus far (generally assigned internally). + * mode: A pointer to the mode, used for error handling and printing (generally assigned internally). + * state: A pointer to the state information. + * listing: A directory listing structure used internally to help reduce repeated memory allocation overhead. + * source: A pointer to the source string, used for error handling and printing (generally assigned internally). + * source_top: A pointer to the top source string, used for error handling and printing (generally assigned internally). + * destination: A pointer to the destination string, used for error handling and printing (generally assigned internally). + * destination_top: A pointer to the top destination string, used for error handling and printing (generally assigned internally). + * verbose: A callback used for printing verbose messages (Set to NULL to not use). + * + * The macro_f_directory_recurse_t_initialize_1() all arguments. + * The macro_f_directory_recurse_t_initialize_2() all arguments except for internally managed source, destination, mode, and depth. + */ +#ifndef _di_f_directory_recurse_t_ + typedef struct { + f_number_unsigned_t max_depth; + f_number_unsigned_t size_block; + uint8_t flag; + f_array_length_t depth; + + f_mode_t mode; + f_state_t state; + f_directory_listing_t listing; + + const f_string_static_t *source; + const f_string_static_t *source_top; + const f_string_static_t *destination; + const f_string_static_t *destination_top; + + void (*verbose)(const f_string_static_t source, const f_string_static_t destination, void * const recurse); + } f_directory_recurse_t; + + #define f_directory_recurse_t_initialize { \ + F_directory_max_recurse_depth_d, \ + F_file_default_read_size_d, \ + F_file_flag_write_only_d, \ + 0, \ + f_mode_t_initialize, \ + f_state_t_initialize, \ + f_directory_listing_t_initialize, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + } + + #define macro_f_directory_recurse_t_initialize_1(max_depth, size_block, flag, depth, mode, state, listing, source, source_top, destination, destination_top, verbose) { \ + max_depth, \ + size_block, \ + flag, \ + depth, \ + mode, \ + state, \ + listing, \ + source, \ + source_top, \ + destination, \ + destination_top, \ + verbose, \ + } + + #define macro_f_directory_recurse_t_initialize_2(max_depth, size_block, flag, depth, mode, state, verbose) { \ + max_depth, \ + size_block, \ + flag, \ + depth,\ + mode, \ + state, \ + f_directory_listing_t_initialize, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + verbose, \ + } +#endif // _di_f_directory_recurse_t_ + +/** + * Delete all arrays within the listing. + * + * @param listing + * The listing to fully delete. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_string_dynamics_resize(). + * + * @see f_string_dynamics_resize() + */ +#ifndef _di_f_directory_listing_delete_ + extern f_status_t f_directory_listing_delete(f_directory_listing_t * const listing); +#endif // _di_f_directory_listing_delete_ + +/** + * Destroy all arrays within the listing. + * + * @param listing + * The listing to fully destroy. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_string_dynamics_adjust(). + * + * @see f_string_dynamics_adjust() + */ +#ifndef _di_f_directory_listing_destroy_ + extern f_status_t f_directory_listing_destroy(f_directory_listing_t * const listing); +#endif // _di_f_directory_listing_destroy_ + +/** + * Delete all non-pointer based dynamic arrays within the recurse. + * + * @param recurse + * The recurse to fully delete. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_string_dynamics_resize(). + * + * @see f_string_dynamics_resize() + */ +#ifndef _di_f_directory_recurse_delete_ + extern f_status_t f_directory_recurse_delete(f_directory_recurse_t * const recurse); +#endif // _di_f_directory_recurse_delete_ + +/** + * Destroy all non-pointer based dynamic arrays within the recurse. + * + * @param recurse + * The recurse to fully destroy. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_string_dynamics_adjust(). + * + * @see f_string_dynamics_adjust() + */ +#ifndef _di_f_directory_recurse_destroy_ + extern f_status_t f_directory_recurse_destroy(f_directory_recurse_t * const recurse); +#endif // _di_f_directory_recurse_destroy_ + +/** + * Resize all parts of the directory statuss structure using the same length. + * + * @param length + * The new size to use. + * @param statuss + * The statuss structure to adjust. + * + * @return + * F_none on success. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_directory_statuss_adjust_ + extern f_status_t f_directory_statuss_adjust(const f_array_length_t length, f_directory_statuss_t * const statuss); +#endif // _di_f_directory_statuss_adjust_ + +/** + * Resize all parts of the directory statuss structure to a smaller size. + * + * This will resize making the array smaller based on (size - given length). + * If the given length is too small, then the resize will fail. + * This will not shrink the size to less than 0. + * + * @param amount + * A positive number representing how much to decimate the size by. + * @param statuss + * The statuss array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_directory_statuss_decimate_by_ + extern f_status_t f_directory_statuss_decimate_by(const f_array_length_t amount, f_directory_statuss_t * const statuss); +#endif // _di_f_directory_statuss_decimate_by_ + +/** + * Resize all parts of the directory statuss structure to a smaller size. + * + * This will resize making the array smaller based on (size - given length). + * If the given length is too small, then the resize will fail. + * This will not shrink the size to less than 0. + * + * @param amount + * A positive number representing how much to decrease the size by. + * @param statuss + * The statuss array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_directory_statuss_decrease_by_ + extern f_status_t f_directory_statuss_decrease_by(const f_array_length_t amount, f_directory_statuss_t * const statuss); +#endif // _di_f_directory_statuss_decrease_by_ + +/** + * Increase the size of all parts of the directory statuss structure, but only if necessary. + * + * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param statuss + * The statuss array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_directory_statuss_increase_ + extern f_status_t f_directory_statuss_increase(const f_array_length_t step, f_directory_statuss_t * const statuss); +#endif // _di_f_directory_statuss_increase_ + +/** + * Resize all parts of the directory statuss structure to a larger size. + * + * This will resize making the array larger based on the given length. + * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param amount + * A positive number representing how much to increase the size by. + * @param statuss + * The statuss array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + * F_array_too_large (with error bit) if the new array length is too large. + */ +#ifndef _di_f_directory_statuss_increase_by_ + extern f_status_t f_directory_statuss_increase_by(const f_array_length_t amount, f_directory_statuss_t * const statuss); +#endif // _di_f_directory_statuss_increase_by_ + +/** + * Resize all parts of the directory statuss structure using the same length. + * + * @param length + * The new size to use. + * @param statuss + * The directory status array to resize. + * + * @return + * F_none on success. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_directory_statuss_resize_ + extern f_status_t f_directory_statuss_resize(const f_array_length_t length, f_directory_statuss_t * const statuss); +#endif // _di_f_directory_statuss_resize_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_directory/data/build/settings b/level_0/f_directory/data/build/settings index 28b9b23..58bbbbc 100644 --- a/level_0/f_directory/data/build/settings +++ b/level_0/f_directory/data/build/settings @@ -20,7 +20,7 @@ build_language c build_libraries -lc build_libraries-individual -lf_memory -lf_string -build_sources_library directory.c directory/common.c private-directory.c +build_sources_library directory.c directory/common.c directory/type.c private-directory.c directory/private-type.c build_sources_headers directory.h directory/common.h directory/type.h diff --git a/level_0/f_directory/data/build/settings-mocks b/level_0/f_directory/data/build/settings-mocks index 50189b9..ac7e998 100644 --- a/level_0/f_directory/data/build/settings-mocks +++ b/level_0/f_directory/data/build/settings-mocks @@ -30,7 +30,7 @@ build_language c build_libraries -lc build_libraries-individual -lf_memory -lf_string -build_sources_library directory.c directory/common.c private-directory.c ../../tests/unit/c/mock-directory.c +build_sources_library directory.c directory/common.c directory/type.c private-directory.c directory/private-type.c ../../tests/unit/c/mock-directory.c build_sources_headers directory.h directory/common.h directory/type.h diff --git a/level_0/f_file/c/file.h b/level_0/f_file/c/file.h index 6fb1206..0eec160 100644 --- a/level_0/f_file/c/file.h +++ b/level_0/f_file/c/file.h @@ -1404,7 +1404,6 @@ extern "C" { * The path file name. * @param mode * The file mode to open in. - * Set to 0 to not use. * @param file * The data related to the file being opened. * This will be updated with the file descriptor. @@ -1450,7 +1449,6 @@ extern "C" { * The path file name. * @param mode * The file mode to open in. - * Set to 0 to not use. * @param file * The data related to the file being opened. * This will be updated with the file descriptor. diff --git a/level_0/f_file/c/file/common.h b/level_0/f_file/c/file/common.h index c09a58c..24a4794 100644 --- a/level_0/f_file/c/file/common.h +++ b/level_0/f_file/c/file/common.h @@ -456,10 +456,6 @@ extern "C" { /** * File flag related to file statistics. * - * These flags are meant to be bitwise for a uint8_t size type or larger. - * - * The f_file_stat_flag_none_e is expected to be 0, therefore it must be safe to use 0 directly. - * * f_file_stat_flag_*: * - none: No flags are set (enables non-exclusive and dereference). * - exclusive: Require that a file does not already exist. diff --git a/level_0/f_file/c/private-file.h b/level_0/f_file/c/private-file.h index 6eb9418..e0763a8 100644 --- a/level_0/f_file/c/private-file.h +++ b/level_0/f_file/c/private-file.h @@ -590,7 +590,6 @@ extern "C" { * The path file name. * @param mode * The file mode to open in. - * Set to 0 to not use. * @param file * The data related to the file being opened. * This will be updated with the file descriptor. @@ -623,7 +622,6 @@ extern "C" { * The path file name. * @param mode * The file mode to open in. - * Set to 0 to not use. * @param file * The data related to the file being opened. * This will be updated with the file descriptor. diff --git a/level_0/f_fss/c/fss.c b/level_0/f_fss/c/fss.c index 6ea1378..a937920 100644 --- a/level_0/f_fss/c/fss.c +++ b/level_0/f_fss/c/fss.c @@ -6,12 +6,22 @@ extern "C" { #endif #ifndef _di_f_fss_apply_delimit_ - f_status_t f_fss_apply_delimit(f_state_t state, const f_fss_delimits_t delimits, f_string_static_t * const buffer) { + void f_fss_apply_delimit(const f_fss_delimits_t delimits, f_string_static_t * const buffer, f_state_t * const state) { #ifndef _di_level_0_parameter_checking_ - if (!buffer) return F_status_set_error(F_parameter); + if (!state) return; + + if (!buffer) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_0_parameter_checking_ - if (!buffer->used) return F_data_not; + if (!buffer->used) { + state->status = F_data_not; + + return; + } for (f_array_length_t i = 0; i < delimits.used; ++i) { @@ -20,17 +30,27 @@ extern "C" { } } // for - return F_none; + state->status = F_none; } #endif // _di_f_fss_apply_delimit_ #ifndef _di_f_fss_apply_delimit_range_ - f_status_t f_fss_apply_delimit_range(f_state_t state, const f_fss_delimits_t delimits, const f_string_range_t range, f_string_static_t * const buffer) { + void f_fss_apply_delimit_range(const f_fss_delimits_t delimits, const f_string_range_t range, f_string_static_t * const buffer, f_state_t * const state) { #ifndef _di_level_0_parameter_checking_ - if (!buffer) return F_status_set_error(F_parameter); + if (!state) return; + + if (!buffer) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_0_parameter_checking_ - if (!buffer->used || range.start > range.stop || range.start >= buffer->used) return F_data_not; + if (!buffer->used || range.start > range.stop || range.start >= buffer->used) { + state->status = F_data_not; + + return; + } for (f_array_length_t i = 0; i < delimits.used; ++i) { @@ -39,17 +59,27 @@ extern "C" { } } // for - return F_none; + state->status = F_none; } #endif // _di_f_fss_apply_delimit_range_ #ifndef _di_f_fss_count_lines_ - f_status_t f_fss_count_lines(f_state_t state, const f_string_static_t buffer, const f_array_length_t before, f_array_length_t * const line) { + void f_fss_count_lines(const f_string_static_t buffer, const f_array_length_t before, f_array_length_t * const line, f_state_t * const state) { #ifndef _di_level_0_parameter_checking_ - if (!line) return F_status_set_error(F_parameter); + if (!state) return; + + if (!line) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_0_parameter_checking_ - if (!buffer.used) return F_data_not; + if (!buffer.used) { + state->status = F_data_not; + + return; + } for (f_array_length_t i = 0; i < before && i < buffer.used; i += macro_f_utf_byte_width(buffer.string[i])) { @@ -58,17 +88,27 @@ extern "C" { } } // for - return F_none; + state->status = F_none; } #endif // _di_f_fss_count_lines_ #ifndef _di_f_fss_count_lines_range_ - f_status_t f_fss_count_lines_range(f_state_t state, const f_string_static_t buffer, const f_string_range_t range, f_array_length_t * const line) { + void f_fss_count_lines_range(const f_string_static_t buffer, const f_string_range_t range, f_array_length_t * const line, f_state_t * const state) { #ifndef _di_level_0_parameter_checking_ - if (!line) return F_status_set_error(F_parameter); + if (!state) return; + + if (!line) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_0_parameter_checking_ - if (!buffer.used || range.start > range.stop || range.start >= buffer.used) return F_data_not; + if (!buffer.used || range.start > range.stop || range.start >= buffer.used) { + state->status = F_data_not; + + return; + } for (f_array_length_t i = range.start; i <= range.stop && i < buffer.used; i += macro_f_utf_byte_width(buffer.string[i])) { @@ -77,44 +117,51 @@ extern "C" { } } // for - return F_none; + state->status = F_none; } #endif // _di_f_fss_count_lines_range_ #ifndef _di_f_fss_fail_utf_ - f_status_t f_fss_fail_utf(f_state_t state, const f_status_t status) { + void f_fss_fail_utf(f_state_t * const state) { + #ifndef _di_level_0_parameter_checking_ + if (!state) return; + #endif // _di_level_0_parameter_checking_ - if (F_status_is_error(status)) { - if (F_status_set_fine(status) == F_utf_fragment || F_status_set_fine(status) == F_complete_not_utf || F_status_set_fine(status) == F_utf_not) { - if (!(state.flag & f_fss_state_flag_utf_fail_on_valid_not_e)) { - return F_status_set_fine(status); + if (F_status_is_error(state->status)) { + if (F_status_set_fine(state->status) == F_utf_fragment || F_status_set_fine(state->status) == F_complete_not_utf || F_status_set_fine(state->status) == F_utf_not) { + if (!(state->flag & f_fss_state_flag_utf_fail_on_valid_not_e)) { + state->status = F_status_set_fine(state->status); } } } - - return status; } #endif // _di_f_fss_fail_utf_ #ifndef _di_f_fss_fail_utf_to_false_ - f_status_t f_fss_fail_utf_to_false(f_state_t state, const f_status_t status) { + void f_fss_fail_utf_to_false(f_state_t * const state) { + #ifndef _di_level_0_parameter_checking_ + if (!state) return; + #endif // _di_level_0_parameter_checking_ - if (F_status_is_error(status)) { - if (F_status_set_fine(status) == F_utf_fragment || F_status_set_fine(status) == F_complete_not_utf || F_status_set_fine(status) == F_utf_not) { - if (!(state.flag & f_fss_state_flag_utf_fail_on_valid_not_e)) { - return F_false; + if (F_status_is_error(state->status)) { + if (F_status_set_fine(state->status) == F_utf_fragment || F_status_set_fine(state->status) == F_complete_not_utf || F_status_set_fine(state->status) == F_utf_not) { + if (!(state->flag & f_fss_state_flag_utf_fail_on_valid_not_e)) { + state->status = F_false; } } } - - return status; } #endif // _di_f_fss_fail_utf_to_false_ #ifndef _di_f_fss_is_combining_ - f_status_t f_fss_is_combining(f_state_t state, const f_string_static_t buffer, const f_string_range_t range) { + f_status_t f_fss_is_combining(const f_string_static_t buffer, const f_string_range_t range, f_state_t * const state) { + #ifndef _di_level_0_parameter_checking_ + if (!state) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ if (!buffer.used || range.start > range.stop || range.start >= buffer.used) { + state->status = F_data_not; + return F_false; } @@ -124,14 +171,24 @@ extern "C" { width_max = buffer.used - range.start; } - return f_fss_fail_utf_to_false(state, f_utf_is_combining(buffer.string + range.start, width_max)); + state->status = f_utf_is_combining(buffer.string + range.start, width_max); + if (state->status == F_true) return F_true; + + f_fss_fail_utf_to_false(state); + + return F_false; } #endif // _di_f_fss_is_combining_ #ifndef _di_f_fss_is_graph_ - f_status_t f_fss_is_graph(f_state_t state, const f_string_static_t buffer, const f_string_range_t range) { + f_status_t f_fss_is_graph(const f_string_static_t buffer, const f_string_range_t range, f_state_t * const state) { + #ifndef _di_level_0_parameter_checking_ + if (!state) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ if (!buffer.used || range.start > range.stop || range.start >= buffer.used) { + state->status = F_data_not; + return F_false; } @@ -141,14 +198,24 @@ extern "C" { width_max = buffer.used - range.start; } - return f_fss_fail_utf_to_false(state, f_utf_is_graph(buffer.string + range.start, width_max)); + state->status = f_utf_is_graph(buffer.string + range.start, width_max); + if (state->status == F_true) return F_true; + + f_fss_fail_utf_to_false(state); + + return F_false; } #endif // _di_f_fss_is_graph_ #ifndef _di_f_fss_is_space_ - f_status_t f_fss_is_space(f_state_t state, const f_string_static_t buffer, const f_string_range_t range) { + f_status_t f_fss_is_space(const f_string_static_t buffer, const f_string_range_t range, f_state_t * const state) { + #ifndef _di_level_0_parameter_checking_ + if (!state) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ if (!buffer.used || range.start > range.stop || range.start >= buffer.used) { + state->status = F_data_not; + return F_false; } @@ -158,30 +225,36 @@ extern "C" { width_max = buffer.used - range.start; } - f_status_t status = f_fss_fail_utf_to_false(state, f_utf_is_zero_width(buffer.string + range.start, width_max)); + state->status = f_utf_is_zero_width(buffer.string + range.start, width_max); + if (state->status != F_false) return F_false; - if (status != F_false) { - if (status == F_true) { - return F_false; - } + f_fss_fail_utf_to_false(state); - return status; - } + state->status = f_utf_is_whitespace(buffer.string + range.start, width_max, F_false); + if (state->status == F_true) return F_true; - status = f_fss_fail_utf_to_false(state, f_utf_is_whitespace(buffer.string + range.start, width_max, F_false)); + f_fss_fail_utf_to_false(state); - if (status == F_false) { - status = f_fss_fail_utf_to_false(state, f_utf_is_control(buffer.string + range.start, width_max)); + if (state->status == F_false) { + state->status = f_utf_is_control(buffer.string + range.start, width_max); + if (state->status == F_true) return F_true; + + f_fss_fail_utf_to_false(state); } - return status; + return F_false; } #endif // _di_f_fss_is_space_ #ifndef _di_f_fss_is_zero_width_ - f_status_t f_fss_is_zero_width(f_state_t state, const f_string_static_t buffer, const f_string_range_t range) { + f_status_t f_fss_is_zero_width(const f_string_static_t buffer, const f_string_range_t range, f_state_t * const state) { + #ifndef _di_level_0_parameter_checking_ + if (!state) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ if (!buffer.used || range.start > range.stop || range.start >= buffer.used) { + state->status = F_data_not; + return F_false; } @@ -191,57 +264,111 @@ extern "C" { width_max = buffer.used - range.start; } - return f_fss_fail_utf_to_false(state, f_utf_is_zero_width(buffer.string + range.start, width_max)); + state->status = f_utf_is_zero_width(buffer.string + range.start, width_max); + if (state->status == F_true) return F_true; + + f_fss_fail_utf_to_false(state); + + return F_false; } #endif // _di_f_fss_is_zero_width_ #ifndef _di_f_fss_seek_to_eol_ - f_status_t f_fss_seek_to_eol(f_state_t state, const f_string_dynamic_t buffer, f_string_range_t * const range) { + void f_fss_seek_to_eol(const f_string_dynamic_t buffer, f_string_range_t * const range, f_state_t * const state) { #ifndef _di_level_0_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_0_parameter_checking_ - if (!buffer.used || range->start > range->stop || range->start >= buffer.used) return F_data_not; + if (!buffer.used || range->start > range->stop || range->start >= buffer.used) { + state->status = F_data_not; + + return; + } for (;; ++range->start) { - if (range->start >= buffer.used) return F_none_eos; - if (range->start > range->stop) return F_none_stop; + if (range->start >= buffer.used) { + state->status = F_none_eos; + + return; + } + + if (range->start > range->stop) { + state->status = F_none_stop; + + return; + } + if (buffer.string[range->start] == f_fss_eol_s.string[0]) break; } // for - return F_none; + state->status = F_none; } #endif // _di_f_fss_seek_to_eol_ #ifndef _di_f_fss_skip_past_delimit_ - f_status_t f_fss_skip_past_delimit(f_state_t state, const f_string_static_t buffer, f_string_range_t * const range) { + void f_fss_skip_past_delimit(const f_string_static_t buffer, f_string_range_t * const range, f_state_t * const state) { #ifndef _di_level_0_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_0_parameter_checking_ - if (!buffer.used || range->start > range->stop || range->start >= buffer.used) return F_data_not; + if (!buffer.used || range->start > range->stop || range->start >= buffer.used) { + state->status = F_data_not; + + return; + } for (;; ++range->start) { - if (range->start >= buffer.used) return F_none_eos; - if (range->start > range->stop) return F_none_stop; + if (range->start >= buffer.used) { + state->status = F_none_eos; + + return; + } + + if (range->start > range->stop) { + state->status = F_none_stop; + + return; + } + if (buffer.string[range->start] != f_fss_placeholder_s.string[0]) break; } // for - return F_none; + state->status = F_none; } #endif // _di_f_fss_skip_past_delimit_ #ifndef _di_f_fss_skip_past_space_ - f_status_t f_fss_skip_past_space(f_state_t state, const f_string_static_t buffer, f_string_range_t * const range) { + void f_fss_skip_past_space(const f_string_static_t buffer, f_string_range_t * const range, f_state_t * const state) { #ifndef _di_level_0_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_0_parameter_checking_ - if (!buffer.used || range->start > range->stop || range->start >= buffer.used) return F_data_not; + if (!buffer.used || range->start > range->stop || range->start >= buffer.used) { + state->status = F_data_not; + + return; + } - f_status_t status = F_none; uint8_t width = 0; f_array_length_t width_max = (range->stop - range->start) + 1; @@ -250,9 +377,16 @@ extern "C" { } // Check that the first character is not a combining character. - status = f_fss_fail_utf_to_false(state, f_utf_is_combining(buffer.string + range->start, width_max)); - if (F_status_is_error(status)) return status; - if (status == F_true) return F_status_set_error(F_complete_not_utf_start); + state->status = f_utf_is_combining(buffer.string + range->start, width_max); + + f_fss_fail_utf_to_false(state); + if (F_status_is_error(state->status)) return; + + if (state->status == F_true) { + state->status = F_status_set_error(F_complete_not_utf_start); + + return; + } for (;;) { @@ -263,7 +397,9 @@ extern "C" { } if (buffer.string[range->start] == f_fss_eol_s.string[0]) { - return F_none_eol; + state->status = F_none_eol; + + return; } if (buffer.string[range->start] == f_fss_placeholder_s.string[0]) { @@ -272,42 +408,67 @@ extern "C" { continue; } - status = f_fss_fail_utf_to_false(state, f_utf_is_whitespace(buffer.string + range->start, width_max, F_false)); + state->status = f_utf_is_whitespace(buffer.string + range->start, width_max, F_false); + + f_fss_fail_utf_to_false(state); + + if (state->status == F_false) { + state->status = f_utf_is_control(buffer.string + range->start, width_max); - if (status == F_false) { - status = f_fss_fail_utf_to_false(state, f_utf_is_control(buffer.string + range->start, width_max)); + f_fss_fail_utf_to_false(state); - if (status == F_false) { - status = f_fss_fail_utf_to_false(state, f_utf_is_combining(buffer.string + range->start, width_max)); + if (state->status == F_false) { + state->status = f_utf_is_combining(buffer.string + range->start, width_max); - if (status == F_false) { - status = f_fss_fail_utf_to_false(state, f_utf_is_zero_width(buffer.string + range->start, width_max)); - if (status == F_false) return F_none; + f_fss_fail_utf_to_false(state); + + if (state->status == F_false) { + state->status = f_utf_is_zero_width(buffer.string + range->start, width_max); + + f_fss_fail_utf_to_false(state); + if (state->status == F_false) break; } } } - if (F_status_is_error(status)) return status; + if (F_status_is_error(state->status)) return; width = macro_f_utf_byte_width(buffer.string[range->start]); if (width > 1) { if (range->start + width >= buffer.used) { - return f_fss_fail_utf(state, F_status_set_error(F_complete_not_utf_eos)); + state->status = F_status_set_error(F_complete_not_utf_eos); + + f_fss_fail_utf(state); + + return; } if (range->start + width > range->stop) { - return f_fss_fail_utf(state, F_status_set_error(F_complete_not_utf_stop)); + state->status = F_status_set_error(F_complete_not_utf_stop); + + f_fss_fail_utf(state); + + return; } } range->start += width; - if (range->start >= buffer.used) return F_none_eos; - if (range->start > range->stop) return F_none_stop; + if (range->start >= buffer.used) { + state->status = F_none_eos; + + return; + } + + if (range->start > range->stop) { + state->status = F_none_stop; + + return; + } } // for - return F_none; + state->status = F_none; } #endif // _di_f_fss_skip_past_space_ diff --git a/level_0/f_fss/c/fss.h b/level_0/f_fss/c/fss.h index 898e00c..c514dae 100644 --- a/level_0/f_fss/c/fss.h +++ b/level_0/f_fss/c/fss.h @@ -39,21 +39,21 @@ extern "C" { * * Any delimits out of range (beyond the buffer.used) are ignored. * - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param delimits * An array of locations containing the delimits to apply within the buffer. * @param buffer * The string to process. + * @param state + * A state for providing flags and handling interrupts during long running operations. * - * @return - * F_none on success. - * F_data_not on success but buffer.used is 0. + * This alters state.status: + * F_none on success. + * F_data_not on success but buffer.used is 0. * - * F_parameter (with error bit) if a parameter is invalid. + * F_parameter (with error bit) if a parameter is invalid. */ #ifndef _di_f_fss_apply_delimit_ - extern f_status_t f_fss_apply_delimit(f_state_t state, const f_fss_delimits_t delimits, f_string_static_t * const buffer); + extern void f_fss_apply_delimit(const f_fss_delimits_t delimits, f_string_static_t * const buffer, f_state_t * const state); #endif // _di_f_fss_apply_delimit_ /** @@ -61,23 +61,23 @@ extern "C" { * * If the delimits are found to be (inclusively) within the range specified by range, then those delimits are applied. * - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param delimits * An array of locations containing the delimits to apply within the buffer. * @param range * The range in which to restrict which delimits to apply. * @param buffer * The string to process. + * @param state + * A state for providing flags and handling interrupts during long running operations. * - * @return - * F_none on success. - * F_data_not on success but buffer.used is 0. + * This alters state.status: + * F_none on success. + * F_data_not on success but buffer.used is 0. * - * F_parameter (with error bit) if a parameter is invalid. + * F_parameter (with error bit) if a parameter is invalid. */ #ifndef _di_f_fss_apply_delimit_range_ - extern f_status_t f_fss_apply_delimit_range(f_state_t state, const f_fss_delimits_t delimits, const f_string_range_t range, f_string_static_t * const buffer); + extern void f_fss_apply_delimit_range(const f_fss_delimits_t delimits, const f_string_range_t range, f_string_static_t * const buffer, f_state_t * const state); #endif // _di_f_fss_apply_delimit_range_ /** @@ -87,8 +87,6 @@ extern "C" { * * This does not initialize line, instead it only performs addition to line. * - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param buffer * The string to process. * @param before @@ -97,15 +95,17 @@ extern "C" { * The total lines found leading up to but not including before. * This value is not reset and only additions are performed. * When F_data_not is returned, this value is not altered. + * @param state + * A state for providing flags and handling interrupts during long running operations. * - * @return - * F_none on success. - * F_data_not on success but buffer.used is 0 (line is set to 0). + * This alters state.status: + * F_none on success. + * F_data_not on success but buffer.used is 0 (line is set to 0). * * F_parameter (with error bit) if a parameter is invalid. */ #ifndef _di_f_fss_count_lines_ - extern f_status_t f_fss_count_lines(f_state_t state, const f_string_static_t buffer, const f_array_length_t before, f_array_length_t * const line); + extern void f_fss_count_lines(const f_string_static_t buffer, const f_array_length_t before, f_array_length_t * const line, f_state_t * const state); #endif // _di_f_fss_count_lines_ /** @@ -115,8 +115,6 @@ extern "C" { * * This does not initialize line, instead it only performs addition to line. * - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param buffer * The string to process. * @param range @@ -125,15 +123,17 @@ extern "C" { * The total lines found leading up to but not including before. * This value is not reset and only additions are performed. * When F_data_not is returned, this value is not altered. + * @param state + * A state for providing flags and handling interrupts during long running operations. * - * @return - * F_none on success. - * F_data_not on success but the range.start is greater than buffer.used or buffer.used is 0 (line is set to 0). + * This alters state.status: + * F_none on success. + * F_data_not on success but the range.start is greater than buffer.used or buffer.used is 0 (line is set to 0). * - * F_parameter (with error bit) if a parameter is invalid. + * F_parameter (with error bit) if a parameter is invalid. */ #ifndef _di_f_fss_count_lines_range_ - extern f_status_t f_fss_count_lines_range(f_state_t state, const f_string_static_t buffer, const f_string_range_t range, f_array_length_t * const line); + extern void f_fss_count_lines_range(const f_string_static_t buffer, const f_string_range_t range, f_array_length_t * const line, f_state_t * const state); #endif // _di_f_fss_count_lines_range_ /** @@ -142,20 +142,19 @@ extern "C" { * When f_fss_state_flag_utf_fail_on_valid_not_e is set, UTF-8 failures are returned as is. * When f_fss_state_flag_utf_fail_on_valid_not_e is unset, UTF-8 failures are returned with the error bit removed. * - * @param state - * A state for providing flags and handling interrupts during long running operations. - * @param status - * The status code to check. - * This handles status codes (with error bit set): + * This handles status codes (with error bit set): * - F_complete_not_utf * - F_utf_fragment * - F_utf_not * - * @return - * Status is either directly passed through or the error bit is removed depending on state.flag. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * + * This alters state.status: + * Status is either directly passed through or the error bit is removed depending on state.flag. */ #ifndef _di_f_fss_fail_utf_ - extern f_status_t f_fss_fail_utf(f_state_t state, const f_status_t status); + extern void f_fss_fail_utf(f_state_t * const state); #endif // _di_f_fss_fail_utf_ /** @@ -164,20 +163,19 @@ extern "C" { * When f_fss_state_flag_utf_fail_on_valid_not_e is set, UTF-8 failures are returned as is. * When f_fss_state_flag_utf_fail_on_valid_not_e is unset, UTF-8 failures are replaced with F_false. * - * @param state - * A state for providing flags and handling interrupts during long running operations. - * @param status - * The status code to check. - * This handles status codes (with error bit set): + * This handles status codes (with error bit set): * - F_complete_not_utf * - F_utf_fragment * - F_utf_not * - * @return - * Status is either directly passed through or F_false is returned depending on state.flag. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * + * This alters state.status: + * Status is either directly passed through or F_false is returned depending on state.flag. */ #ifndef _di_f_fss_fail_utf_to_false_ - extern f_status_t f_fss_fail_utf_to_false(f_state_t state, const f_status_t status); + extern void f_fss_fail_utf_to_false(f_state_t * const state); #endif // _di_f_fss_fail_utf_to_false_ /** @@ -192,83 +190,97 @@ extern "C" { * U+0020 followed by U+0301 would result in the combination of the two being considered a graph rather than a space. * Given that NULL characters are ignored by the general FSS standard, combining characters are not considered to combine into NULL. * - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param buffer * The string to process. * @param range * The character at the start position will be checked against the graph. * @param header * The header data to populate with results of this function. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * + * This alters state.status: + * F_true if the character in the buffer is a combining character. + * F_false if the character in the buffer is not a combining character. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_utf_is_combining(). * * @return * F_true if the character in the buffer is a combining character. * F_false if the character in the buffer is not a combining character. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_utf_is_combining(). + * F_false is returned on any error. * * @see f_utf_is_combining() */ #ifndef _di_f_fss_is_combining_ - extern f_status_t f_fss_is_combining(f_state_t state, const f_string_static_t buffer, const f_string_range_t range); + extern f_status_t f_fss_is_combining(const f_string_static_t buffer, const f_string_range_t range, f_state_t * const state); #endif // _di_f_fss_is_combining_ /** * Identify whether or not a character in the buffer is a graph (ASCII or UTF-8) character. * - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param buffer * The string to process. * @param range * The character at the start position will be checked against the graph. * @param header * The header data to populate with results of this function. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * + * This alters state.status: + * F_true if the character in the buffer is a graph character. + * F_false if the character in the buffer is not a graph character. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_utf_is_graph(). * * @return * F_true if the character in the buffer is a graph character. * F_false if the character in the buffer is not a graph character. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_utf_is_graph(). + * F_false is returned on any error. * * @see f_utf_is_graph() */ #ifndef _di_f_fss_is_graph_ - extern f_status_t f_fss_is_graph(f_state_t state, const f_string_static_t buffer, const f_string_range_t range); + extern f_status_t f_fss_is_graph(const f_string_static_t buffer, const f_string_range_t range, f_state_t * const state); #endif // _di_f_fss_is_graph_ /** * Identify whether or not a character in the buffer is a non-zero-width whitespace or non-zero-width control (ASCII or UTF-8) character. * - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param buffer * The string to process. * @param range * The character at the start position will be checked against the graph. * @param header * The header data to populate with results of this function. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * + * This alters state.status: + * F_none on success. + * F_data_not on success but nothing is processed. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_utf_is_control(). + * Errors (with error bit) from: f_utf_is_whitespace(). + * Errors (with error bit) from: f_utf_is_zero_width(). * * @return * F_true if the character in the buffer is a space character. * F_false if the character in the buffer is not a space character. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_utf_is_control(). - * Errors (with error bit) from: f_utf_is_whitespace(). - * Errors (with error bit) from: f_utf_is_zero_width(). + * F_false is returned on any error. * * @see f_utf_is_control() * @see f_utf_is_whitespace() * @see f_utf_is_zero_width() */ #ifndef _di_f_fss_is_space_ - extern f_status_t f_fss_is_space(f_state_t state, const f_string_static_t buffer, const f_string_range_t range); + extern f_status_t f_fss_is_space(const f_string_static_t buffer, const f_string_range_t range, f_state_t * const state); #endif // _di_f_fss_is_space_ /** @@ -276,27 +288,32 @@ extern "C" { * * The NULL character (U+0000) is a zero-width character. * - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param buffer * The string to process. * @param range * The character at the start position will be checked against the graph. * @param header * The header data to populate with results of this function. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * + * This alters state.status: + * F_true if the character in the buffer is a zero-width character. + * F_false if the character in the buffer is not a zero-width character. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_utf_is_zero_width(). * * @return * F_true if the character in the buffer is a zero-width character. * F_false if the character in the buffer is not a zero-width character. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_utf_is_zero_width(). + * F_false is returned on any error. * * @see f_utf_is_zero_width() */ #ifndef _di_f_fss_is_zero_width_ - extern f_status_t f_fss_is_zero_width(f_state_t state, const f_string_static_t buffer, const f_string_range_t range); + extern f_status_t f_fss_is_zero_width(const f_string_static_t buffer, const f_string_range_t range, f_state_t * const state); #endif // _di_f_fss_is_zero_width_ /** @@ -307,47 +324,47 @@ extern "C" { * Combining characters after the EOL effectively make the EOL character a non-standard EOL. * For most, if not all, FSS standards, a combined EOL is not the same as a standard or normal EOL. * - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param buffer * The string to process. * @param range * The start and stop positions in the buffer being processed. * This increments range->start. + * @param state + * A state for providing flags and handling interrupts during long running operations. * - * @return - * F_none on success. - * F_data_not on success but buffer.used is 0, initial range.start is greater than range.stop, or initial range.start is greater than or equal to buffer.used. - * F_none_eos on success and EOS was reached. - * F_none_stop on success and stop point was reached. + * This alters state.status: + * F_none on success. + * F_data_not on success but buffer.used is 0, initial range.start is greater than range.stop, or initial range.start is greater than or equal to buffer.used. + * F_none_eos on success and EOS was reached. + * F_none_stop on success and stop point was reached. * - * F_parameter (with error bit) if a parameter is invalid. + * F_parameter (with error bit) if a parameter is invalid. */ #ifndef _di_f_fss_seek_to_eol_ - extern f_status_t f_fss_seek_to_eol(f_state_t state, const f_string_dynamic_t buffer, f_string_range_t * const range); + extern void f_fss_seek_to_eol(const f_string_dynamic_t buffer, f_string_range_t * const range, f_state_t * const state); #endif // _di_f_fss_seek_to_eol_ /** * Skip past all delimit placeholders until a non-delimit placeholder is reached. * - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param buffer * The string to process. * @param range * The start and stop positions in the buffer being processed. * This increments range->start. + * @param state + * A state for providing flags and handling interrupts during long running operations. * - * @return - * F_none on success. - * F_data_not on success but buffer.used is 0, initial range.start is greater than range.stop, or initial range.start is greater than or equal to buffer.used. - * F_none_eos on success and EOS was reached. - * F_none_stop on success and stop point was reached. + * This alters state.status: + * F_none on success. + * F_data_not on success but buffer.used is 0, initial range.start is greater than range.stop, or initial range.start is greater than or equal to buffer.used. + * F_none_eos on success and EOS was reached. + * F_none_stop on success and stop point was reached. * - * F_parameter (with error bit) if a parameter is invalid. + * F_parameter (with error bit) if a parameter is invalid. */ #ifndef _di_f_fss_skip_past_delimit_ - extern f_status_t f_fss_skip_past_delimit(f_state_t state, const f_string_static_t buffer, f_string_range_t * const range); + extern void f_fss_skip_past_delimit(const f_string_static_t buffer, f_string_range_t * const range, f_state_t * const state); #endif // _di_f_fss_skip_past_delimit_ /** @@ -356,30 +373,30 @@ extern "C" { * If the first character in the given range is a combining character, then because this will not skip past anything. * This is because combining characters apply from right to left. * - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param buffer * The string to process. * @param range * The start and stop positions in the buffer being processed. * This increments range->start. + * @param state + * A state for providing flags and handling interrupts during long running operations. * - * @return - * F_none on success. - * F_data_not on success but buffer.used is 0, initial range.start is greater than range.stop, or initial range.start is greater than or equal to buffer.used. - * F_none_eol on success and EOL was reached. - * F_none_eos on success and EOS was reached. - * F_none_stop on success and stop point was reached. - * - * F_complete_not_utf_eos (with error bit) if unable to get entire UTF-8 sequence due to EOS. - * F_complete_not_utf_start (with error bit) if the first character is a combining character. - * F_complete_not_utf_stop (with error bit) if unable to get entire UTF-8 sequence due to stop point reached. - * F_parameter (with error bit) if a parameter is invalid. + * This alters state.status: + * F_none on success. + * F_data_not on success but buffer.used is 0, initial range.start is greater than range.stop, or initial range.start is greater than or equal to buffer.used. + * F_none_eol on success and EOL was reached. + * F_none_eos on success and EOS was reached. + * F_none_stop on success and stop point was reached. + * + * F_complete_not_utf_eos (with error bit) if unable to get entire UTF-8 sequence due to EOS. + * F_complete_not_utf_start (with error bit) if the first character is a combining character. + * F_complete_not_utf_stop (with error bit) if unable to get entire UTF-8 sequence due to stop point reached. + * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_utf_is_combining(). - * Errors (with error bit) from: f_utf_is_control(). - * Errors (with error bit) from: f_utf_is_whitespace(). - * Errors (with error bit) from: f_utf_is_zero_width(). + * Errors (with error bit) from: f_utf_is_combining(). + * Errors (with error bit) from: f_utf_is_control(). + * Errors (with error bit) from: f_utf_is_whitespace(). + * Errors (with error bit) from: f_utf_is_zero_width(). * * @see f_utf_is_combining() * @see f_utf_is_control() @@ -387,7 +404,7 @@ extern "C" { * @see f_utf_is_zero_width() */ #ifndef _di_f_fss_skip_past_space_ - extern f_status_t f_fss_skip_past_space(f_state_t state, const f_string_static_t buffer, f_string_range_t * const range); + extern void f_fss_skip_past_space(const f_string_static_t buffer, f_string_range_t * const range, f_state_t * const state); #endif // _di_f_fss_skip_past_space_ #ifdef __cplusplus diff --git a/level_0/f_fss/c/fss/named.h b/level_0/f_fss/c/fss/named.h index cf4c703..9ff9580 100644 --- a/level_0/f_fss/c/fss/named.h +++ b/level_0/f_fss/c/fss/named.h @@ -183,7 +183,7 @@ extern "C" { /** * Resize all parts of the named structure to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -210,7 +210,7 @@ extern "C" { * @param length * The new size to use. * @param named - * The named structure to resize. + * The named array to resize. * * @return * F_none on success. @@ -311,7 +311,7 @@ extern "C" { /** * Resize the nameds array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_fss/c/fss/nest.h b/level_0/f_fss/c/fss/nest.h index 886d82c..f8cd2c9 100644 --- a/level_0/f_fss/c/fss/nest.h +++ b/level_0/f_fss/c/fss/nest.h @@ -277,7 +277,7 @@ extern "C" { /** * Resize the items array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -406,7 +406,7 @@ extern "C" { /** * Resize the nest array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -534,7 +534,7 @@ extern "C" { /** * Resize the nests array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_fss/c/fss/set.h b/level_0/f_fss/c/fss/set.h index 5cf73b0..2abcc98 100644 --- a/level_0/f_fss/c/fss/set.h +++ b/level_0/f_fss/c/fss/set.h @@ -251,7 +251,7 @@ extern "C" { /** * Resize the set array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -380,7 +380,7 @@ extern "C" { /** * Resize the set_quote array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set_quote max buffer size (F_array_length_t_size_d). * If already set_quote to the maximum buffer size, then the resize will fail. * @@ -509,7 +509,7 @@ extern "C" { /** * Resize the set_quotes array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -638,7 +638,7 @@ extern "C" { /** * Resize the sets array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_fss/c/private-fss.c b/level_0/f_fss/c/private-fss.c index a45d82f..feb4929 100644 --- a/level_0/f_fss/c/private-fss.c +++ b/level_0/f_fss/c/private-fss.c @@ -11,7 +11,9 @@ extern "C" { f_status_t status = F_none; for (f_array_length_t i = length; i < items->size; ++i) { - macro_f_fss_item_t_adjust(status, items->array[i], 0) + + status = f_string_ranges_adjust(0, &items->array[i].content); + if (F_status_is_error(status)) return status; } // for status = f_memory_adjust(items->size, length, sizeof(f_fss_item_t), (void **) & items->array); @@ -36,7 +38,9 @@ extern "C" { f_status_t status = F_none; for (f_array_length_t i = length; i < items->size; ++i) { - macro_f_fss_item_t_resize(status, items->array[i], 0) + + status = f_string_ranges_resize(0, &items->array[i].content); + if (F_status_is_error(status)) return status; } // for status = f_memory_resize(items->size, length, sizeof(f_fss_item_t), (void **) & items->array); @@ -94,6 +98,7 @@ extern "C" { f_status_t status = F_none; for (f_array_length_t i = length; i < nameds->size; ++i) { + status = private_f_fss_named_adjust(0, &nameds->array[i]); if (F_status_is_error(status)) return status; } // for @@ -120,6 +125,7 @@ extern "C" { f_status_t status = F_none; for (f_array_length_t i = length; i < nameds->size; ++i) { + status = private_f_fss_named_resize(0, &nameds->array[i]); if (F_status_is_error(status)) return status; } // for @@ -143,6 +149,7 @@ extern "C" { f_status_t status = F_none; for (f_array_length_t i = length; i < nest->size; ++i) { + status = private_f_fss_items_adjust(0, &nest->depth[i]); if (F_status_is_error(status)) return status; } // for @@ -169,6 +176,7 @@ extern "C" { f_status_t status = F_none; for (f_array_length_t i = length; i < nest->size; ++i) { + status = private_f_fss_items_resize(0, &nest->depth[i]); if (F_status_is_error(status)) return status; } // for @@ -192,6 +200,7 @@ extern "C" { f_status_t status = F_none; for (f_array_length_t i = length; i < nests->size; ++i) { + status = private_f_fss_nest_adjust(0, &nests->array[i]); if (F_status_is_error(status)) return status; } // for @@ -218,6 +227,7 @@ extern "C" { f_status_t status = F_none; for (f_array_length_t i = length; i < nests->size; ++i) { + status = private_f_fss_nest_resize(0, &nests->array[i]); if (F_status_is_error(status)) return status; } // for @@ -240,10 +250,10 @@ extern "C" { f_status_t status = F_none; - macro_f_fss_objects_t_adjust(status, set->objects, length); + status = f_string_ranges_adjust(length, &set->objects); if (F_status_is_error(status)) return status; - macro_f_fss_contents_t_adjust(status, set->contents, length); + status = f_string_rangess_adjust(length, &set->contents); if (F_status_is_error(status)) return status; return F_none; @@ -255,10 +265,10 @@ extern "C" { f_status_t status = F_none; - macro_f_fss_objects_t_resize(status, set->objects, length); + status = f_string_ranges_resize(length, &set->objects); if (F_status_is_error(status)) return status; - macro_f_fss_contents_t_resize(status, set->contents, length); + status = f_string_rangess_resize(length, &set->contents); if (F_status_is_error(status)) return status; return F_none; @@ -270,16 +280,16 @@ extern "C" { f_status_t status = F_none; - macro_f_fss_objects_t_adjust(status, set_quote->objects, length); + status = f_string_ranges_adjust(length, &set_quote->objects); if (F_status_is_error(status)) return status; - macro_f_fss_contents_t_adjust(status, set_quote->contents, length); + status = f_string_rangess_adjust(length, &set_quote->contents); if (F_status_is_error(status)) return status; - macro_f_uint8s_t_adjust(status, set_quote->objects_quote, length); + status = f_uint8s_adjust(length, &set_quote->objects_quote); if (F_status_is_error(status)) return status; - macro_f_uint8ss_t_adjust(status, set_quote->contents_quote, length); + status = f_uint8ss_adjust(length, &set_quote->contents_quote); if (F_status_is_error(status)) return status; return F_none; @@ -291,16 +301,16 @@ extern "C" { f_status_t status = F_none; - macro_f_fss_objects_t_resize(status, set_quote->objects, length); + status = f_string_ranges_resize(length, &set_quote->objects); if (F_status_is_error(status)) return status; - macro_f_fss_contents_t_resize(status, set_quote->contents, length); + status = f_string_rangess_resize(length, &set_quote->contents); if (F_status_is_error(status)) return status; - macro_f_uint8s_t_resize(status, set_quote->objects_quote, length); + status = f_uint8s_resize(length, &set_quote->objects_quote); if (F_status_is_error(status)) return status; - macro_f_uint8ss_t_resize(status, set_quote->contents_quote, length); + status = f_uint8ss_resize(length, &set_quote->contents_quote); if (F_status_is_error(status)) return status; return F_none; @@ -314,16 +324,16 @@ extern "C" { for (f_array_length_t i = length; i < set_quotes->size; ++i) { - macro_f_fss_objects_t_adjust(status, set_quotes->array[i].objects, 0); + status = f_string_ranges_adjust(0, &set_quotes->array[i].objects); if (F_status_is_error(status)) return status; - macro_f_fss_contents_t_adjust(status, set_quotes->array[i].contents, 0); + status = f_string_rangess_adjust(0, &set_quotes->array[i].contents); if (F_status_is_error(status)) return status; - macro_f_uint8s_t_adjust(status, set_quotes->array[i].objects_quote, 0); + status = f_uint8s_adjust(0, &set_quotes->array[i].objects_quote); if (F_status_is_error(status)) return status; - macro_f_uint8ss_t_adjust(status, set_quotes->array[i].contents_quote, 0); + status = f_uint8ss_adjust(0, &set_quotes->array[i].contents_quote); if (F_status_is_error(status)) return status; } // for @@ -350,16 +360,16 @@ extern "C" { for (f_array_length_t i = length; i < set_quotes->size; ++i) { - macro_f_fss_objects_t_resize(status, set_quotes->array[i].objects, 0); + status = f_string_ranges_resize(0, &set_quotes->array[i].objects); if (F_status_is_error(status)) return status; - macro_f_fss_contents_t_resize(status, set_quotes->array[i].contents, 0); + status = f_string_rangess_resize(0, &set_quotes->array[i].contents); if (F_status_is_error(status)) return status; - macro_f_uint8s_t_resize(status, set_quotes->array[i].objects_quote, 0); + status = f_uint8s_resize(0, &set_quotes->array[i].objects_quote); if (F_status_is_error(status)) return status; - macro_f_uint8ss_t_resize(status, set_quotes->array[i].contents_quote, 0); + status = f_uint8ss_resize(0, &set_quotes->array[i].contents_quote); if (F_status_is_error(status)) return status; } // for @@ -383,10 +393,10 @@ extern "C" { for (f_array_length_t i = length; i < sets->size; ++i) { - macro_f_fss_objects_t_adjust(status, sets->array[i].objects, 0); + status = f_string_ranges_adjust(0, &sets->array[i].objects); if (F_status_is_error(status)) return status; - macro_f_fss_contents_t_adjust(status, sets->array[i].contents, 0); + status = f_string_rangess_adjust(0, &sets->array[i].contents); if (F_status_is_error(status)) return status; } // for @@ -413,10 +423,10 @@ extern "C" { for (f_array_length_t i = length; i < sets->size; ++i) { - macro_f_fss_objects_t_resize(status, sets->array[i].objects, 0); + status = f_string_ranges_resize(0, &sets->array[i].objects); if (F_status_is_error(status)) return status; - macro_f_fss_contents_t_resize(status, sets->array[i].contents, 0); + status = f_string_rangess_resize(0, &sets->array[i].contents); if (F_status_is_error(status)) return status; } // for diff --git a/level_0/f_iki/c/iki.c b/level_0/f_iki/c/iki.c index f6be190..264e4ef 100644 --- a/level_0/f_iki/c/iki.c +++ b/level_0/f_iki/c/iki.c @@ -12,9 +12,7 @@ extern "C" { if (quote.string[0] != f_iki_syntax_quote_single_s.string[0] && quote.string[0] != f_iki_syntax_quote_double_s.string[0] && quote.string[0] != f_iki_syntax_quote_backtick_s.string[0]) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!content.used) { - return F_data_not; - } + if (!content.used) return F_data_not; return private_f_iki_content_partial_is(content.string, content.used, quote.string[0]); } @@ -27,17 +25,9 @@ extern "C" { if (quote.string[0] != f_iki_syntax_quote_single_s.string[0] && quote.string[0] != f_iki_syntax_quote_double_s.string[0] && quote.string[0] != f_iki_syntax_quote_backtick_s.string[0]) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!content.used) { - return F_data_not; - } - - if (range.start > range.stop) { - return F_data_not_stop; - } - - if (range.start >= content.used) { - return F_data_not_eos; - } + if (!content.used) return F_data_not; + if (range.start > range.stop) return F_data_not_stop; + if (range.start >= content.used) return F_data_not_eos; return private_f_iki_content_partial_is(content.string + range.start, (range.stop - range.start) + 1, quote.string[0]); } @@ -46,9 +36,7 @@ extern "C" { #ifndef _di_f_iki_object_is_ f_status_t f_iki_object_is(const f_string_static_t object) { - if (!object.used) { - return F_data_not; - } + if (!object.used) return F_data_not; return private_f_iki_object_partial_is(object.string, object.used); } @@ -57,35 +45,44 @@ extern "C" { #ifndef _di_f_iki_object_partial_is_ f_status_t f_iki_object_partial_is(const f_string_static_t object, const f_string_range_t range) { - if (!object.used) { - return F_data_not; - } - - if (range.start > range.stop) { - return F_data_not_stop; - } - - if (range.start >= object.used) { - return F_data_not_eos; - } + if (!object.used) return F_data_not; + if (range.start > range.stop) return F_data_not_stop; + if (range.start >= object.used) return F_data_not_eos; return private_f_iki_object_partial_is(object.string + range.start, (range.stop - range.start) + 1); } #endif // _di_f_iki_object_partial_is_ #ifndef _di_f_iki_read_ - f_status_t f_iki_read(const f_state_t state, f_string_static_t * const buffer, f_string_range_t * const range, f_iki_data_t * const data) { + void f_iki_read(f_string_static_t * const buffer, f_string_range_t * const range, f_iki_data_t * const data, f_state_t * const state) { #ifndef _di_level_0_parameter_checking_ - if (!buffer) return F_status_set_error(F_parameter); - if (!range) return F_status_set_error(F_parameter); - if (!data) return F_status_set_error(F_parameter); + if (!state) return; + + if (!buffer || !range || !data) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_0_parameter_checking_ - if (!buffer->used) return F_data_not; - if (range->start > range->stop) return F_data_not_stop; - if (range->start >= buffer->used) return F_data_not_eos; + if (!buffer->used) { + state->status = F_data_not; + + return; + } + + if (range->start > range->stop) { + state->status = F_data_not_stop; + + return; + } + + if (range->start >= buffer->used) { + state->status = F_data_not_eos; + + return; + } - f_status_t status = F_none; f_array_length_t width_max = 0; if (width_max > buffer->used - range->start) { @@ -104,58 +101,48 @@ extern "C" { // Find the start of the vocabulary name. while (range->start <= range->stop && range->start < buffer->used) { - if (state.interrupt) { - status = state.interrupt((void * const) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void * const) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } width_max = buffer->used - range->start; - status = f_utf_is_word_dash_plus(buffer->string + range->start, width_max, F_false); + state->status = f_utf_is_word_dash_plus(buffer->string + range->start, width_max, F_false); - if (F_status_is_error(status)) { - if (F_status_set_fine(status) == F_utf_fragment || F_status_set_fine(status) == F_complete_not_utf) { - if (state.flag & f_iki_state_flag_utf_fail_on_valid_not_e) break; + if (F_status_is_error(state->status)) { + if (F_status_set_fine(state->status) == F_utf_fragment || F_status_set_fine(state->status) == F_complete_not_utf) { + if (state->flag & f_iki_state_flag_utf_fail_on_valid_not_e) break; - status = F_false; + state->status = F_false; } else { break; } } - if (status == F_true) { + if (state->status == F_true) { found_vocabulary.start = range->start; found_vocabulary.stop = range->start; - status = f_utf_buffer_increment(*buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(*buffer, range, 1); + if (F_status_is_error(state->status)) break; - status = F_true; + state->status = F_true; break; } - status = f_utf_buffer_increment(*buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(*buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while // Find the end of the vocabulary name. - while (F_status_is_error_not(status) && range->start <= range->stop && range->start < buffer->used) { + while (F_status_is_error_not(state->status) && range->start <= range->stop && range->start < buffer->used) { - if (state.interrupt) { - status = state.interrupt((void * const) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void * const) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer->string[range->start] == f_iki_syntax_placeholder_s.string[0]) { @@ -166,18 +153,18 @@ extern "C" { if (buffer->string[range->start] == f_iki_syntax_separator_s.string[0]) { do { - status = f_utf_buffer_increment(*buffer, range, 1); - } while (F_status_is_fine(status) && buffer->string[range->start] == f_iki_syntax_placeholder_s.string[0] && range->start <= range->stop && range->start < buffer->used); + state->status = f_utf_buffer_increment(*buffer, range, 1); + } while (F_status_is_fine(state->status) && buffer->string[range->start] == f_iki_syntax_placeholder_s.string[0] && range->start <= range->stop && range->start < buffer->used); - if (F_status_is_error(status) || range->start > range->stop || range->start >= buffer->used) break; + if (F_status_is_error(state->status) || range->start > range->stop || range->start >= buffer->used) break; // Found a valid vocabulary name. if (buffer->string[range->start] == f_iki_syntax_quote_single_s.string[0] || buffer->string[range->start] == f_iki_syntax_quote_double_s.string[0] || buffer->string[range->start] == f_iki_syntax_quote_backtick_s.string[0]) { - status = F_true; + state->status = F_true; quote = buffer->string[range->start]; } else { - status = F_next; + state->status = F_next; } break; @@ -191,14 +178,9 @@ extern "C" { // The slash only needs to be delimited if it were to otherwise be a valid vocabulary name. while (range->start <= range->stop && range->start < buffer->used) { - if (state.interrupt) { - status = state.interrupt((void * const) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void * const) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer->string[range->start] == f_iki_syntax_placeholder_s.string[0]) { @@ -211,15 +193,15 @@ extern "C" { // Save delimit for a would-be valid IKI that is now delimited. if (buffer->string[range->start] == f_iki_syntax_quote_single_s.string[0] || buffer->string[range->start] == f_iki_syntax_quote_double_s.string[0] || buffer->string[range->start] == f_iki_syntax_quote_backtick_s.string[0]) { - status = f_array_lengths_increase(state.step_small, &data->delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase(state->step_small, &data->delimits); + if (F_status_is_error(state->status)) break; data->delimits.array[data->delimits.used++] = vocabulary_slash_first; ++range->start; } - status = F_next; + state->status = F_next; break; } @@ -228,56 +210,56 @@ extern "C" { separator_found = F_true; } else if (buffer->string[range->start] != f_iki_syntax_slash_s.string[0]) { - status = F_next; + state->status = F_next; break; } - status = f_utf_buffer_increment(*buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(*buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (status == F_true) break; - if (F_status_is_error(status) || range->start > range->stop || range->start >= buffer->used || status == F_next) break; + if (state->status == F_true) break; + if (F_status_is_error(state->status) || range->start > range->stop || range->start >= buffer->used || state->status == F_next) break; } else { width_max = buffer->used - range->start; - status = f_utf_is_word_dash_plus(buffer->string + range->start, width_max, F_false); + state->status = f_utf_is_word_dash_plus(buffer->string + range->start, width_max, F_false); - if (F_status_is_error(status)) { - if (F_status_set_fine(status) == F_utf_fragment || F_status_set_fine(status) == F_complete_not_utf) { - if (state.flag & f_iki_state_flag_utf_fail_on_valid_not_e) break; + if (F_status_is_error(state->status)) { + if (F_status_set_fine(state->status) == F_utf_fragment || F_status_set_fine(state->status) == F_complete_not_utf) { + if (state->flag & f_iki_state_flag_utf_fail_on_valid_not_e) break; - status = F_false; + state->status = F_false; } else { break; } } - if (status == F_true) { + if (state->status == F_true) { found_vocabulary.stop = range->start; } // Not a valid IKI vocabulary name. else { - status = f_utf_buffer_increment(*buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(*buffer, range, 1); + if (F_status_is_error(state->status)) break; - status = F_next; + state->status = F_next; break; } } - status = f_utf_buffer_increment(*buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(*buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status) || range->start > range->stop || range->start >= buffer->used) break; + if (F_status_is_error(state->status) || range->start > range->stop || range->start >= buffer->used) break; - if (status == F_next) { + if (state->status == F_next) { quote = 0; continue; @@ -289,14 +271,9 @@ extern "C" { while (range->start <= range->stop && range->start < buffer->used) { - if (state.interrupt) { - status = state.interrupt((void * const) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void * const) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer->string[range->start] == f_iki_syntax_placeholder_s.string[0]) { @@ -306,14 +283,14 @@ extern "C" { } if (buffer->string[range->start] == quote) { - status = f_string_ranges_increase(state.step_small, &data->variable); - if (F_status_is_error(status)) break; + state->status = f_string_ranges_increase(state->step_small, &data->variable); + if (F_status_is_error(state->status)) break; - status = f_string_ranges_increase(state.step_small, &data->vocabulary); - if (F_status_is_error(status)) break; + state->status = f_string_ranges_increase(state->step_small, &data->vocabulary); + if (F_status_is_error(state->status)) break; - status = f_string_ranges_increase(state.step_small, &data->content); - if (F_status_is_error(status)) break; + state->status = f_string_ranges_increase(state->step_small, &data->content); + if (F_status_is_error(state->status)) break; data->variable.array[data->variable.used].start = found_vocabulary.start; data->variable.array[data->variable.used++].stop = range->start; @@ -324,10 +301,17 @@ extern "C" { data->content.array[data->content.used].start = found_content; data->content.array[data->content.used++].stop = range->start - 1; - if (++range->start > range->stop) return F_none_stop; - if (range->start >= buffer->used) return F_none_eos; + if (++range->start > range->stop) { + state->status = F_none_stop; + } + else if (range->start >= buffer->used) { + state->status = F_none_eos; + } + else { + state->status = F_none; + } - return F_none; + return; } if (buffer->string[range->start] == f_iki_syntax_slash_s.string[0]) { @@ -351,8 +335,8 @@ extern "C" { ++content_slash_delimits; } - status = f_array_lengths_increase_by(content_slash_delimits, &data->delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase_by(content_slash_delimits, &data->delimits); + if (F_status_is_error(state->status)) break; content_range.start = content_slash_first; content_range.stop = range->stop; @@ -364,22 +348,22 @@ extern "C" { ++i; } - status = f_utf_buffer_increment(*buffer, (&content_range), 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(*buffer, (&content_range), 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) break; + if (F_status_is_error(state->status)) break; // Valid content's ending quote is not delimited, save and return. if (content_slash_total % 2 == 0) { - status = f_string_ranges_increase(state.step_small, &data->variable); - if (F_status_is_error(status)) break; + state->status = f_string_ranges_increase(state->step_small, &data->variable); + if (F_status_is_error(state->status)) break; - status = f_string_ranges_increase(state.step_small, &data->vocabulary); - if (F_status_is_error(status)) break; + state->status = f_string_ranges_increase(state->step_small, &data->vocabulary); + if (F_status_is_error(state->status)) break; - status = f_string_ranges_increase(state.step_small, &data->content); - if (F_status_is_error(status)) break; + state->status = f_string_ranges_increase(state->step_small, &data->content); + if (F_status_is_error(state->status)) break; data->variable.array[data->variable.used].start = found_vocabulary.start; data->variable.array[data->variable.used++].stop = range->start; @@ -390,10 +374,17 @@ extern "C" { data->content.array[data->content.used].start = found_content; data->content.array[data->content.used++].stop = range->start - 1; - if (++range->start > range->stop) return F_none_stop; - if (range->start >= buffer->used) return F_none_eos; + if (++range->start > range->stop) { + state->status = F_none_stop; + } + else if (range->start >= buffer->used) { + state->status = F_none_eos; + } + else { + state->status = F_none; + } - return F_none; + return; } break; @@ -403,42 +394,40 @@ extern "C" { ++content_slash_total; - status = f_utf_buffer_increment(*buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(*buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) break; + if (F_status_is_error(state->status)) break; } - status = f_utf_buffer_increment(*buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(*buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while quote = 0; } - if (F_status_is_error(status) || range->start > range->stop || range->start >= buffer->used) break; + if (F_status_is_error(state->status) || range->start > range->stop || range->start >= buffer->used) break; - status = f_utf_buffer_increment(*buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(*buffer, range, 1); + if (F_status_is_error(state->status)) break; } while (range->start <= range->stop && range->start < buffer->used); - if (F_status_set_fine(status) == F_complete_not_utf_eos || F_status_set_fine(status) == F_complete_not_utf_stop) { - if (!(state.flag & f_iki_state_flag_utf_fail_on_valid_not_e)) { - status = F_status_set_fine(status); + if (F_status_set_fine(state->status) == F_complete_not_utf_eos || F_status_set_fine(state->status) == F_complete_not_utf_stop) { + if (!(state->flag & f_iki_state_flag_utf_fail_on_valid_not_e)) { + state->status = F_status_set_fine(state->status); } } - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { data->delimits.used = delimits_used; - return status; + return; } - if (range->start > range->stop) return F_data_not_stop; - - return F_data_not_eos; + state->status = (range->start > range->stop) ? F_data_not_stop : F_data_not_eos; } #endif // _di_f_iki_read_ diff --git a/level_0/f_iki/c/iki.h b/level_0/f_iki/c/iki.h index d79b104..f34e0bd 100644 --- a/level_0/f_iki/c/iki.h +++ b/level_0/f_iki/c/iki.h @@ -134,15 +134,6 @@ extern "C" { * This will update the buffer at the given range with any placeholders to escaped data. * Calling this more than once on the same buffer range could result in multiple escaping. * - * @param state - * A state for providing flags and handling interrupts during long running operations. - * There is no print_error(). - * There is no functions structure. - * There is no data structure passed to these functions. - * - * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. - * Error bit designates an error but must be passed along with F_interrupt. - * All other statuses are ignored. * @param buffer * The string to process. * @param range @@ -152,26 +143,36 @@ extern "C" { * A start location past the stop location or buffer used means that the entire range was processed. * @param data * The IKI variable data. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * There is no print_error(). + * There is no functions structure. + * There is no data structure passed to these functions. + * This must not be NULL. * - * @return - * F_none on success and an IKI vocabulary name was found. - * F_none_eos on success and an IKI vocabulary name was found and end of string was reached. - * F_none_stop on success and an IKI vocabulary name was found and stop point was reached. - * F_complete_not_utf_eos on success but string ended on incomplete UTF-8 and f_iki_state_flag_utf_fail_on_valid_not_e is not set. - * F_complete_not_utf_stop on success but stop point reached on incomplete UTF-8 and f_iki_state_flag_utf_fail_on_valid_not_e is not set. - * F_data_not on success, but there were no IKI vocabulary names found. - * F_data_not_eos on success and EOS was reached, but there were no IKI vocabulary names found. - * F_data_not_stop on success and stop point was reached, but there were no IKI vocabulary names found. - * - * F_complete_not_utf_eos (with error bit) on success but string ended on incomplete UTF-8 and f_iki_state_flag_utf_fail_on_valid_not_e is set. - * F_complete_not_utf_stop (with error bit) on success but stop point reached on incomplete UTF-8 and f_iki_state_flag_utf_fail_on_valid_not_e is set. - * F_interrupt (with error bit) if stopping due to an interrupt. - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - * F_string_too_large (with error bit) if a string length is too large to store in the buffer. + * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. + * Error bit designates an error but must be passed along with F_interrupt. + * All other statuses are ignored. + * + * This alters state.status: + * F_none on success and an IKI vocabulary name was found. + * F_none_eos on success and an IKI vocabulary name was found and end of string was reached. + * F_none_stop on success and an IKI vocabulary name was found and stop point was reached. + * F_complete_not_utf_eos on success but string ended on incomplete UTF-8 and f_iki_state_flag_utf_fail_on_valid_not_e is not set. + * F_complete_not_utf_stop on success but stop point reached on incomplete UTF-8 and f_iki_state_flag_utf_fail_on_valid_not_e is not set. + * F_data_not on success, but there were no IKI vocabulary names found. + * F_data_not_eos on success and EOS was reached, but there were no IKI vocabulary names found. + * F_data_not_stop on success and stop point was reached, but there were no IKI vocabulary names found. + * + * F_complete_not_utf_eos (with error bit) on success but string ended on incomplete UTF-8 and f_iki_state_flag_utf_fail_on_valid_not_e is set. + * F_complete_not_utf_stop (with error bit) on success but stop point reached on incomplete UTF-8 and f_iki_state_flag_utf_fail_on_valid_not_e is set. + * F_interrupt (with error bit) if stopping due to an interrupt. + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + * F_string_too_large (with error bit) if a string length is too large to store in the buffer. */ #ifndef _di_f_iki_read_ - extern f_status_t f_iki_read(const f_state_t state, f_string_static_t * const buffer, f_string_range_t * const range, f_iki_data_t * const data); + extern void f_iki_read(f_string_static_t * const buffer, f_string_range_t * const range, f_iki_data_t * const data, f_state_t * const state); #endif // _di_f_iki_read_ #ifdef __cplusplus diff --git a/level_0/f_iki/c/iki/data.h b/level_0/f_iki/c/iki/data.h index a0d4a68..a21d97e 100644 --- a/level_0/f_iki/c/iki/data.h +++ b/level_0/f_iki/c/iki/data.h @@ -193,7 +193,7 @@ extern "C" { /** * Resize the iki_datas array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -372,7 +372,7 @@ extern "C" { /** * Resize the iki_datass array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_limit/c/limit/set.h b/level_0/f_limit/c/limit/set.h index 637c539..1e01e51 100644 --- a/level_0/f_limit/c/limit/set.h +++ b/level_0/f_limit/c/limit/set.h @@ -239,7 +239,7 @@ extern "C" { /** * Resize the sets array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -417,7 +417,7 @@ extern "C" { /** * Resize the setss array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_limit/c/limit/value.h b/level_0/f_limit/c/limit/value.h index 5298809..98add99 100644 --- a/level_0/f_limit/c/limit/value.h +++ b/level_0/f_limit/c/limit/value.h @@ -236,7 +236,7 @@ extern "C" { /** * Resize the values array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -414,7 +414,7 @@ extern "C" { /** * Resize the valuess array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_string/c/string/dynamic.h b/level_0/f_string/c/string/dynamic.h index ae7a832..6310c8a 100644 --- a/level_0/f_string/c/string/dynamic.h +++ b/level_0/f_string/c/string/dynamic.h @@ -211,7 +211,7 @@ extern "C" { /** * Resize the dynamic string to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -237,7 +237,7 @@ extern "C" { /** * Resize the dynamic string to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_string/c/string/map_multis.h b/level_0/f_string/c/string/map_multis.h index 9270605..9f47027 100644 --- a/level_0/f_string/c/string/map_multis.h +++ b/level_0/f_string/c/string/map_multis.h @@ -185,7 +185,7 @@ extern "C" { /** * Resize the map_multis array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_string/c/string/map_multiss.h b/level_0/f_string/c/string/map_multiss.h index c6d4ca6..e391315 100644 --- a/level_0/f_string/c/string/map_multiss.h +++ b/level_0/f_string/c/string/map_multiss.h @@ -185,7 +185,7 @@ extern "C" { /** * Resize the map_multiss array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_string/c/string/maps.h b/level_0/f_string/c/string/maps.h index 261b256..cd8de63 100644 --- a/level_0/f_string/c/string/maps.h +++ b/level_0/f_string/c/string/maps.h @@ -185,7 +185,7 @@ extern "C" { /** * Resize the string maps array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_string/c/string/mapss.h b/level_0/f_string/c/string/mapss.h index 4361bb1..ec36545 100644 --- a/level_0/f_string/c/string/mapss.h +++ b/level_0/f_string/c/string/mapss.h @@ -186,7 +186,7 @@ extern "C" { /** * Resize the string mapss array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_string/c/string/quantitys.h b/level_0/f_string/c/string/quantitys.h index d6ade2f..89f805e 100644 --- a/level_0/f_string/c/string/quantitys.h +++ b/level_0/f_string/c/string/quantitys.h @@ -183,7 +183,7 @@ extern "C" { /** * Resize the string quantitys array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_string/c/string/quantityss.h b/level_0/f_string/c/string/quantityss.h index 025880f..31f4653 100644 --- a/level_0/f_string/c/string/quantityss.h +++ b/level_0/f_string/c/string/quantityss.h @@ -184,7 +184,7 @@ extern "C" { /** * Resize the string quantityss array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_string/c/string/ranges.h b/level_0/f_string/c/string/ranges.h index d195d1b..69a5bef 100644 --- a/level_0/f_string/c/string/ranges.h +++ b/level_0/f_string/c/string/ranges.h @@ -184,7 +184,7 @@ extern "C" { /** * Resize the string ranges array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_string/c/string/rangess.h b/level_0/f_string/c/string/rangess.h index ee86eca..c454a1d 100644 --- a/level_0/f_string/c/string/rangess.h +++ b/level_0/f_string/c/string/rangess.h @@ -185,7 +185,7 @@ extern "C" { /** * Resize the string rangess array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_string/c/string/triples.h b/level_0/f_string/c/string/triples.h index deca5d5..bc9fe30 100644 --- a/level_0/f_string/c/string/triples.h +++ b/level_0/f_string/c/string/triples.h @@ -186,7 +186,7 @@ extern "C" { /** * Resize the string triples array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_string/c/string/tripless.h b/level_0/f_string/c/string/tripless.h index 28167fd..a69523e 100644 --- a/level_0/f_string/c/string/tripless.h +++ b/level_0/f_string/c/string/tripless.h @@ -186,7 +186,7 @@ extern "C" { /** * Resize the string tripless array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_thread/c/thread.c b/level_0/f_thread/c/thread.c index ce37ffd..f0f9733 100644 --- a/level_0/f_thread/c/thread.c +++ b/level_0/f_thread/c/thread.c @@ -1747,12 +1747,13 @@ extern "C" { #endif // _di_f_thread_semaphore_file_delete_ #ifndef _di_f_thread_semaphore_file_open_ - f_status_t f_thread_semaphore_file_open(const f_string_static_t name, const int flag, const mode_t mode, unsigned int value, f_thread_semaphore_t **semaphore) { + f_status_t f_thread_semaphore_file_open(const f_string_static_t name, const int flag, mode_t * const mode, unsigned int value, f_thread_semaphore_t **semaphore) { #ifndef _di_level_0_parameter_checking_ if (!semaphore) return F_status_set_error(F_parameter); + if ((flag & O_CREAT) && !mode) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (flag & O_CREAT) { + if ((flag & O_CREAT) || mode) { *semaphore = sem_open(name.string, flag, mode, value); } else { diff --git a/level_0/f_thread/c/thread.h b/level_0/f_thread/c/thread.h index f5b3104..b95c2c5 100644 --- a/level_0/f_thread/c/thread.h +++ b/level_0/f_thread/c/thread.h @@ -2296,10 +2296,14 @@ extern "C" { * (optional) The file permissions to assign the semaphore. * Ignored if O_CREAT is not used in flag. * Ignored if the named semaphore already exists. + * Not optional when O_CREAT flag is set. + * Set to NULL to not use. * @param value * (optional) The value to initially assign the semaphore on creation. * Ignored if O_CREAT is not used in flag. * Ignored if the named semaphore already exists. + * Not optional when O_CREAT flag is set. + * Ignored when mode is NULL. * @param semaphore * The thread semaphore. * @@ -2321,7 +2325,7 @@ extern "C" { * @see sem_open() */ #ifndef _di_f_thread_semaphore_file_open_ - extern f_status_t f_thread_semaphore_file_open(const f_string_static_t name, const int flag, const mode_t mode, unsigned int value, f_thread_semaphore_t **semaphore); + extern f_status_t f_thread_semaphore_file_open(const f_string_static_t name, const int flag, mode_t * const mode, unsigned int value, f_thread_semaphore_t **semaphore); #endif // _di_f_thread_semaphore_file_open_ /** diff --git a/level_0/f_type/c/type.h b/level_0/f_type/c/type.h index ceeabde..5c61c5a 100644 --- a/level_0/f_type/c/type.h +++ b/level_0/f_type/c/type.h @@ -70,7 +70,7 @@ extern "C" { * * All state values may be NULL, in which case they are to be ignored. * - * The general interpretation of the return results of interrupt() or any of the functions should have an error bit to designate an error and not an error bit to designate no error. + * The general interpretation of the state.status results of interrupt() or any of the functions should have an error bit to designate an error and not an error bit to designate not an error. * In the case of interrupt(), the F_interrupt and F_interrupt_not must be returned as appropriate and if not an error (the F_interrupt and F_interrupt_not may have an error bit). * To keep the logic simple, it is recommended that F_interrupt always be returned with the error bit set. * @@ -78,7 +78,6 @@ extern "C" { * This allows for the error to be processed with all relevant data before the function returns. * * These two callbacks (handle() and interrupt()) accept the following parameters: - * - error: The current status code (with error bit as appropriate) (only passed to handle()). * - state: The state data. Must be of type f_state_t. Must not be NULL. * - internal: Additional data passed by the function being called, often containing internal data to the called function. May be NULL. * @@ -89,16 +88,17 @@ extern "C" { * The function "bob_does()" maintains a state (f_state_t) called "bob_state". * The function "bob_does()" will call "f_talk()" that accepts a state (f_state_t) and defines the data structure type "f_interject_t" to be called interject. * While "f_talk()" executes, "bob_interrupts()" is periodically with the state (f_state_t) "bob_state" as the first parameter and the data structure (f_interject_t) "interject" as the second parameter. - * If Bob interjects the talk, then bob_interrupts() would return F_interrupt. - * If Bob does not interject the talk, then bob_interrupts() would return F_interrupt_not. + * If Bob interjects the talk, then bob_interrupts() would set state.status to F_interrupt. + * If Bob does not interject the talk, then bob_interrupts() would set state.status to F_interrupt_not. * This response is handled within f_talk(). - * The f_talk() function will then return status when done and might immediately return with F_interrupt (with error bit) if bob_interrupts() returns F_interrupt (with/without error bit). + * The f_talk() function will then set the state.status when done and might immediately set state.status to F_interrupt (with error bit) if bob_interrupts() returns F_interrupt (with/without error bit). * * step_large: The allocation step to use for large buffers. * step_small: The allocation step to use for small buffers. * flag: A 32-bit digit intended for provided flags that are defined by the function. + * status: The status used while processing (This should hold the error passed to the handle callback and should be updated as necessary). * handle: A function to call on a specific error (allowing for the error to be handled before function returns). May be NULL. - * interrupt: A function to call for checking to see if an interrupt is to be called (return result is passed to and handled by caller). May be NULL. + * interrupt: A function to call for checking to see if an interrupt is to be called. May be NULL. * callbacks: A structure (defined by function/project using this) of additional functions to call. May be NULL. * custom: A structure (defined by caller/parent) for holding custom data to be passed along to the interrupt() or one of the functions. May be NULL. * data: A structure (defined by function) for holding data relevant to the function. May be NULL. May be required. @@ -107,10 +107,11 @@ extern "C" { typedef struct { uint16_t step_large; uint16_t step_small; - uint32_t flag; + f_status_t status; + uint64_t flag; - f_status_t (*handle)(const f_status_t error, void * const state, void * const internal); - f_status_t (*interrupt)(void * const state, void * const internal); + void (*handle)(void * const state, void * const internal); + void (*interrupt)(void * const state, void * const internal); void *callbacks; void *custom; @@ -120,6 +121,7 @@ extern "C" { #define f_state_t_initialize { \ F_memory_default_allocation_large_d, \ F_memory_default_allocation_small_d, \ + F_none, \ 0, \ 0, \ 0, \ @@ -128,9 +130,10 @@ extern "C" { 0, \ } - #define macro_f_state_t_initialize(step_large, step_small, flag, handle, interrupt, callbacks, custom, data) { \ + #define macro_f_state_t_initialize_1(step_large, step_small, status, flag, handle, interrupt, callbacks, custom, data) { \ step_large, \ step_small, \ + status, \ flag, \ handle, \ interrupt, \ @@ -142,6 +145,7 @@ extern "C" { #define macro_f_state_t_clear(state) \ state.step_large = 0; \ state.step_small = 0; \ + state.status = F_none; \ state.flag = 0; \ state.handle = 0; \ state.interrupt = 0; \ diff --git a/level_0/f_type_array/c/type_array/array_length.h b/level_0/f_type_array/c/type_array/array_length.h index e850bbe..e0bb674 100644 --- a/level_0/f_type_array/c/type_array/array_length.h +++ b/level_0/f_type_array/c/type_array/array_length.h @@ -149,7 +149,7 @@ extern "C" { /** * Resize the string lengths array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -328,7 +328,7 @@ extern "C" { /** * Resize the string lengthss array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_type_array/c/type_array/cell.h b/level_0/f_type_array/c/type_array/cell.h index 447ee4a..1ead915 100644 --- a/level_0/f_type_array/c/type_array/cell.h +++ b/level_0/f_type_array/c/type_array/cell.h @@ -151,7 +151,7 @@ extern "C" { /** * Resize the string cells array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -328,7 +328,7 @@ extern "C" { /** * Resize the string cellss array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_type_array/c/type_array/fll_id.h b/level_0/f_type_array/c/type_array/fll_id.h index dbde84d..c6cb75a 100644 --- a/level_0/f_type_array/c/type_array/fll_id.h +++ b/level_0/f_type_array/c/type_array/fll_id.h @@ -151,7 +151,7 @@ extern "C" { /** * Resize the string ids array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -328,7 +328,7 @@ extern "C" { /** * Resize the string idss array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_type_array/c/type_array/int128.h b/level_0/f_type_array/c/type_array/int128.h index 0326b7c..3110dfb 100644 --- a/level_0/f_type_array/c/type_array/int128.h +++ b/level_0/f_type_array/c/type_array/int128.h @@ -151,7 +151,7 @@ extern "C" { /** * Resize the int128s array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -328,7 +328,7 @@ extern "C" { /** * Resize the int128ss array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_type_array/c/type_array/int16.h b/level_0/f_type_array/c/type_array/int16.h index b06bfbf..2d33eed 100644 --- a/level_0/f_type_array/c/type_array/int16.h +++ b/level_0/f_type_array/c/type_array/int16.h @@ -151,7 +151,7 @@ extern "C" { /** * Resize the int16s array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -330,7 +330,7 @@ extern "C" { /** * Resize the int16ss array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_type_array/c/type_array/int32.h b/level_0/f_type_array/c/type_array/int32.h index ccc3f8d..8e8ee35 100644 --- a/level_0/f_type_array/c/type_array/int32.h +++ b/level_0/f_type_array/c/type_array/int32.h @@ -150,7 +150,7 @@ extern "C" { /** * Resize the int32s array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -328,7 +328,7 @@ extern "C" { /** * Resize the int32ss array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_type_array/c/type_array/int64.h b/level_0/f_type_array/c/type_array/int64.h index c428dde..31ba1b8 100644 --- a/level_0/f_type_array/c/type_array/int64.h +++ b/level_0/f_type_array/c/type_array/int64.h @@ -151,7 +151,7 @@ extern "C" { /** * Resize the int64s array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -330,7 +330,7 @@ extern "C" { /** * Resize the int64ss array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_type_array/c/type_array/int8.h b/level_0/f_type_array/c/type_array/int8.h index 03d21ad..83db61c 100644 --- a/level_0/f_type_array/c/type_array/int8.h +++ b/level_0/f_type_array/c/type_array/int8.h @@ -151,7 +151,7 @@ extern "C" { /** * Resize the int8s array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -330,7 +330,7 @@ extern "C" { /** * Resize the int8ss array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_type_array/c/type_array/state.h b/level_0/f_type_array/c/type_array/state.h index af71eae..0a39664 100644 --- a/level_0/f_type_array/c/type_array/state.h +++ b/level_0/f_type_array/c/type_array/state.h @@ -151,7 +151,7 @@ extern "C" { /** * Resize the string states array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -330,7 +330,7 @@ extern "C" { /** * Resize the string statess array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_type_array/c/type_array/status.h b/level_0/f_type_array/c/type_array/status.h index 58b2ec2..e9224d2 100644 --- a/level_0/f_type_array/c/type_array/status.h +++ b/level_0/f_type_array/c/type_array/status.h @@ -151,7 +151,7 @@ extern "C" { /** * Resize the string statuss array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -330,7 +330,7 @@ extern "C" { /** * Resize the string statusss array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_type_array/c/type_array/uint128.h b/level_0/f_type_array/c/type_array/uint128.h index f5b9543..9634605 100644 --- a/level_0/f_type_array/c/type_array/uint128.h +++ b/level_0/f_type_array/c/type_array/uint128.h @@ -151,7 +151,7 @@ extern "C" { /** * Resize the string uint128s array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -328,7 +328,7 @@ extern "C" { /** * Resize the string uint128ss array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_type_array/c/type_array/uint16.h b/level_0/f_type_array/c/type_array/uint16.h index b649074..5d94b79 100644 --- a/level_0/f_type_array/c/type_array/uint16.h +++ b/level_0/f_type_array/c/type_array/uint16.h @@ -150,7 +150,7 @@ extern "C" { /** * Resize the string uint16s array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -328,7 +328,7 @@ extern "C" { /** * Resize the string uint16ss array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_type_array/c/type_array/uint32.h b/level_0/f_type_array/c/type_array/uint32.h index eb2b0d0..c6d9c79 100644 --- a/level_0/f_type_array/c/type_array/uint32.h +++ b/level_0/f_type_array/c/type_array/uint32.h @@ -150,7 +150,7 @@ extern "C" { /** * Resize the string uint32s array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -328,7 +328,7 @@ extern "C" { /** * Resize the string uint32ss array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_type_array/c/type_array/uint64.h b/level_0/f_type_array/c/type_array/uint64.h index 7324974..a1fe5c4 100644 --- a/level_0/f_type_array/c/type_array/uint64.h +++ b/level_0/f_type_array/c/type_array/uint64.h @@ -151,7 +151,7 @@ extern "C" { /** * Resize the string uint64s array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -330,7 +330,7 @@ extern "C" { /** * Resize the string uint64ss array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_type_array/c/type_array/uint8.h b/level_0/f_type_array/c/type_array/uint8.h index ce4aabc..b181d31 100644 --- a/level_0/f_type_array/c/type_array/uint8.h +++ b/level_0/f_type_array/c/type_array/uint8.h @@ -151,7 +151,7 @@ extern "C" { /** * Resize the string uint8s array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -330,7 +330,7 @@ extern "C" { /** * Resize the string uint8ss array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_utf/c/utf/dynamic.h b/level_0/f_utf/c/utf/dynamic.h index 0423879..9890857 100644 --- a/level_0/f_utf/c/utf/dynamic.h +++ b/level_0/f_utf/c/utf/dynamic.h @@ -209,7 +209,7 @@ extern "C" { /** * Resize the dynamic string to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * @@ -235,7 +235,7 @@ extern "C" { /** * Resize the dynamic string to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_utf/c/utf/map_multis.h b/level_0/f_utf/c/utf/map_multis.h index 2835c9b..2e655be 100644 --- a/level_0/f_utf/c/utf/map_multis.h +++ b/level_0/f_utf/c/utf/map_multis.h @@ -185,7 +185,7 @@ extern "C" { /** * Resize the map_multis array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_utf/c/utf/map_multiss.h b/level_0/f_utf/c/utf/map_multiss.h index 0b1b211..f1c82cf 100644 --- a/level_0/f_utf/c/utf/map_multiss.h +++ b/level_0/f_utf/c/utf/map_multiss.h @@ -185,7 +185,7 @@ extern "C" { /** * Resize the map_multiss array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_utf/c/utf/maps.h b/level_0/f_utf/c/utf/maps.h index ebe3de7..2d9069d 100644 --- a/level_0/f_utf/c/utf/maps.h +++ b/level_0/f_utf/c/utf/maps.h @@ -185,7 +185,7 @@ extern "C" { /** * Resize the string maps array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_utf/c/utf/mapss.h b/level_0/f_utf/c/utf/mapss.h index 275a4c4..01ac0aa 100644 --- a/level_0/f_utf/c/utf/mapss.h +++ b/level_0/f_utf/c/utf/mapss.h @@ -186,7 +186,7 @@ extern "C" { /** * Resize the string mapss array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_utf/c/utf/triples.h b/level_0/f_utf/c/utf/triples.h index ad116a1..f3df6df 100644 --- a/level_0/f_utf/c/utf/triples.h +++ b/level_0/f_utf/c/utf/triples.h @@ -186,7 +186,7 @@ extern "C" { /** * Resize the string triples array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_0/f_utf/c/utf/tripless.h b/level_0/f_utf/c/utf/tripless.h index 45cf155..677326f 100644 --- a/level_0/f_utf/c/utf/tripless.h +++ b/level_0/f_utf/c/utf/tripless.h @@ -186,7 +186,7 @@ extern "C" { /** * Resize the string tripless array to a larger size. * - * This will resize making the string larger based on the given length. + * This will resize making the array larger based on the given length. * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d). * If already set to the maximum buffer size, then the resize will fail. * diff --git a/level_1/fl_directory/c/directory.c b/level_1/fl_directory/c/directory.c index f1646a2..743e897 100644 --- a/level_1/fl_directory/c/directory.c +++ b/level_1/fl_directory/c/directory.c @@ -8,16 +8,11 @@ extern "C" { #ifndef _di_fl_directory_create_ f_status_t fl_directory_create(const f_string_static_t path, const mode_t mode) { - if (!path.used) { - return F_data_not; - } + if (!path.used) return F_data_not; f_status_t status = f_directory_exists(path); if (F_status_is_error(status)) return status; - - if (status == F_true) { - return F_directory_found; - } + if (status == F_true) return F_directory_found; { f_array_length_t at_tree = 0; @@ -52,258 +47,153 @@ extern "C" { } #endif // _di_fl_directory_create_ -#ifndef _di_fl_directory_clone_ - f_status_t fl_directory_clone(const f_string_static_t source, const f_string_static_t destination, const fl_directory_recurse_t recurse) { - - if (!source.used || !destination.used) { - return F_data_not; - } - - f_status_t status = f_directory_exists(source); - - if (F_status_is_error(status)) return status; - if (status == F_false) return F_status_set_error(F_directory_not); - - struct stat source_stat; - - memset(&source_stat, 0, sizeof(struct stat)); +#ifndef _di_fl_directory_copy_ + void fl_directory_copy(const f_string_static_t source, const f_string_static_t destination, f_directory_recurse_t * const recurse) { + #ifndef _di_level_1_parameter_checking_ + if (!recurse) return; + #endif // _di_level_1_parameter_checking_ - status = f_file_stat(source, !(recurse.flag & f_file_stat_flag_reference_e), &source_stat); - if (F_status_is_error(status)) return status; + recurse->source = recurse->source_top; + recurse->source_top = &source; + recurse->destination = recurse->destination_top; + recurse->destination_top = &destination; + recurse->depth = 0; + recurse->mode = recurse->mode; + recurse->state.status = F_none; + recurse->state.data = (void *) recurse; - status = f_directory_exists(destination); - if (F_status_is_error(status)) return status; + if (!recurse->source_top->used || !recurse->destination_top->used) { + recurse->state.status = F_data_not; - if (status == F_true) { - if (recurse.flag & f_file_stat_flag_exclusive_e) { - return F_status_set_error(F_directory_found); + if (recurse->state.handle) { + recurse->state.handle(&recurse->state, (void *) recurse); } - status = f_file_mode_set(destination, source_stat.st_mode); - if (F_status_is_error(status)) return status; + return; } - else { - status = f_directory_create(destination, source_stat.st_mode); - if (F_status_is_error(status)) return status; - } - - if (recurse.flag & (f_file_stat_flag_group_e | f_file_stat_flag_owner_e)) { - status = f_file_role_change(destination, source_stat.st_uid, source_stat.st_gid, F_true); - if (F_status_is_error(status)) return status; - } - - { - f_string_static_t static_source = source; - f_string_static_t static_destination = destination; - f_array_length_t i = 0; - - // Do not allow null termination or trailing path separators in the string's length calculation. - for (; i > 0; --i, --static_source.used) { - - if (!source.string[i - 1]) continue; - if (source.string[i - 1] == f_path_separator_s.string[0]) continue; - - break; - } // for - - i = destination.used; - - for (; i > 0; --i, --static_destination.used) { - - if (!destination.string[i - 1]) continue; - if (destination.string[i - 1] == f_path_separator_s.string[0]) continue; - break; - } // for - - if (recurse.depth_max) { - status = private_fl_directory_clone(static_source, static_destination, recurse, 1); - } - } + recurse->state.status = f_directory_exists(*recurse->source_top); - if (status == F_none && (!recurse.output.stream || recurse.output.id != -1) && recurse.verbose) { - recurse.verbose(recurse.output, source, destination); + if (recurse->state.status == F_false) { + recurse->state.status = F_status_set_error(F_directory_not); } - return status; - } -#endif // _di_fl_directory_clone_ - -#ifndef _di_fl_directory_clone_content_ - f_status_t fl_directory_clone_content(const f_string_static_t source, const f_string_static_t destination, const fl_directory_recurse_t recurse) { + if (F_status_is_error(recurse->state.status)) { + if (recurse->state.handle) { + recurse->state.handle(&recurse->state, (void *) recurse); + } - if (!source.used || !destination.used) { - return F_data_not; + return; } - f_status_t status = f_directory_exists(source); - - if (F_status_is_error(status)) return status; - if (status == F_false) return F_status_set_error(F_directory_not); - - status = f_directory_exists(destination); - if (F_status_is_error(status)) return status; - if (status == F_false) return F_status_set_error(F_directory_not); - - f_string_static_t static_source = macro_f_string_static_t_initialize(source.string, 0, source.used); - f_string_static_t static_destination = macro_f_string_static_t_initialize(destination.string, 0, destination.used); - - // Do not allow null termination or trailing path separators in the string's length calculation. - { - f_array_length_t i = source.used; - - for (; i > 0; --i, --static_source.used) { - - if (!source.string[i - 1]) continue; - if (source.string[i - 1] == f_path_separator_s.string[0]) continue; - - break; - } // for - - i = destination.used; + if (recurse->flag & f_directory_recurse_flag_top_e) { + if (recurse->flag & f_directory_recurse_flag_clone_e) { + struct stat source_stat; - for (; i > 0; --i, --static_destination.used) { + memset(&source_stat, 0, sizeof(struct stat)); - if (!destination.string[i - 1]) continue; - if (destination.string[i - 1] == f_path_separator_s.string[0]) continue; + recurse->state.status = f_file_stat(*recurse->source_top, recurse->flag & f_directory_recurse_flag_dereference_e, &source_stat); - break; - } // for - } - - if (!recurse.depth_max) { - return status; - } + if (F_status_is_error_not(recurse->state.status)) { + recurse->state.status = f_directory_exists(*recurse->destination_top); + } - status = private_fl_directory_clone(static_source, static_destination, recurse, 1); + if (F_status_is_error_not(recurse->state.status)) { + if (recurse->state.status == F_true) { + if (recurse->flag & f_directory_recurse_flag_exclusive_e) { + recurse->state.status = F_status_set_error(F_directory_found); + } + else { + recurse->state.status = f_file_mode_set(*recurse->destination_top, source_stat.st_mode); + } + } + else { + recurse->state.status = f_directory_create(*recurse->destination_top, source_stat.st_mode); + } + } - if (status == F_none && (!recurse.output.stream || recurse.output.id != -1) && recurse.verbose) { - recurse.verbose(recurse.output, source, destination); + if (F_status_is_error_not(recurse->state.status) && (recurse->flag & (f_directory_recurse_flag_group_e | f_directory_recurse_flag_owner_e))) { + recurse->state.status = f_file_role_change(*recurse->destination_top, (recurse->flag & f_directory_recurse_flag_owner_e) ? source_stat.st_uid : -1, (recurse->flag & f_directory_recurse_flag_group_e) ? source_stat.st_gid : -1, recurse->flag & f_directory_recurse_flag_dereference_e); + } + } + else { + if (recurse->state.status == F_true) { + if (recurse->flag & f_directory_recurse_flag_exclusive_e) { + recurse->state.status = F_status_set_error(F_directory_found); + } + else { + recurse->state.status = f_file_mode_set(*recurse->destination_top, recurse->mode.directory); + } + } + else { + recurse->state.status = f_directory_create(*recurse->destination_top, recurse->mode.directory); + } + } } + else { + recurse->state.status = f_directory_exists(*recurse->destination_top); - return status; - } -#endif // _di_fl_directory_clone_content_ - -#ifndef _di_fl_directory_copy_ - f_status_t fl_directory_copy(const f_string_static_t source, const f_string_static_t destination, const f_mode_t mode, const fl_directory_recurse_t recurse) { - - if (!source.used || !destination.used) { - return F_data_not; + if (recurse->state.status == F_false) { + recurse->state.status = F_status_set_error(F_directory_not); + } } - f_status_t status = f_directory_exists(source); - - if (F_status_is_error(status)) return status; - if (status == F_false) return F_status_set_error(F_directory_not); - - status = f_directory_exists(destination); - if (F_status_is_error(status)) return status; - - if (status == F_true) { - if (recurse.flag & f_file_stat_flag_exclusive_e) { - return F_status_set_error(F_directory_found); + if (F_status_is_error(recurse->state.status)) { + if (recurse->state.handle) { + recurse->state.handle(&recurse->state, (void *) &recurse); } - status = f_file_mode_set(destination, mode.directory); - if (F_status_is_error(status)) return status; - } - else { - status = f_directory_create(destination, mode.directory); - if (F_status_is_error(status)) return status; + return; } - f_string_static_t static_source = macro_f_string_static_t_initialize(source.string, 0, source.used); - f_string_static_t static_destination = macro_f_string_static_t_initialize(destination.string, 0, destination.used); + if (recurse->max_depth) { + f_array_length_t i = recurse->source_top->used; - // Do not allow null termination or trailing path separators in the string's length calculation. - { - f_array_length_t i = source.used; - - for (; i > 0; --i, --static_source.used) { + // Do not allow null termination or trailing path separators in the string's length calculation. + for (; i > 0; --i) { - if (!source.string[i - 1]) continue; - if (source.string[i - 1] == f_path_separator_s.string[0]) continue; + if (!recurse->source_top->string[i - 1]) continue; + if (recurse->source_top->string[i - 1] == f_path_separator_s.string[0]) continue; break; } // for - i = destination.used; + const f_string_static_t static_source = macro_f_string_static_t_initialize(recurse->source_top->string, recurse->source_top->size, i); - for (; i > 0; --i, --static_destination.used) { + for (i = recurse->destination_top->used; i > 0; --i) { - if (!destination.string[i - 1]) continue; - if (destination.string[i - 1] == f_path_separator_s.string[0]) continue; + if (!recurse->destination_top->string[i - 1]) continue; + if (recurse->destination_top->string[i - 1] == f_path_separator_s.string[0]) continue; break; } // for - } - if (recurse.depth_max) { - status = private_fl_directory_copy(static_source, static_destination, mode, recurse, 1); - } + const f_string_static_t static_destination = macro_f_string_static_t_initialize(recurse->destination_top->string, recurse->destination_top->size, i); - if (status == F_none && (!recurse.output.stream || recurse.output.id != -1) && recurse.verbose) { - recurse.verbose(recurse.output, source, destination); - } + recurse->source = &static_source; + recurse->destination = &static_destination; + recurse->depth = 1; - return status; - } -#endif // _di_fl_directory_copy_ - -#ifndef _di_fl_directory_copy_content_ - f_status_t fl_directory_copy_content(const f_string_static_t source, const f_string_static_t destination, const f_mode_t mode, const fl_directory_recurse_t recurse) { + private_fl_directory_copy_recurse(recurse); - if (!source.used || !destination.used) { - return F_data_not; + recurse->source = recurse->source_top; + recurse->destination = recurse->destination_top; + recurse->depth = 0; } - - f_status_t status = f_directory_exists(source); - - if (F_status_is_error(status)) return status; - if (status == F_false) return F_status_set_error(F_directory_not); - - status = f_directory_exists(destination); - if (F_status_is_error(status)) return status; - if (status == F_false) return F_status_set_error(F_directory_not); - - f_string_static_t static_source = macro_f_string_static_t_initialize(source.string, 0, source.used); - f_string_static_t static_destination = macro_f_string_static_t_initialize(destination.string, 0, destination.used); - - // Do not allow null termination or trailing path separators in the string's length calculation. - { - f_array_length_t i = source.used; - - for (; i > 0; --i, --static_source.used) { - - if (!source.string[i - 1]) continue; - if (source.string[i - 1] == f_path_separator_s.string[0]) continue; - - break; - } // for - - i = destination.used; - - for (; i > 0; --i, --static_destination.used) { - - if (!destination.string[i - 1]) continue; - if (destination.string[i - 1] == f_path_separator_s.string[0]) continue; - - break; - } // for + else { + recurse->state.status = F_none; } - if (recurse.depth_max) { - status = private_fl_directory_copy(static_source, static_destination, mode, recurse, 1); + if (recurse->state.status == F_none && recurse->verbose) { + recurse->verbose(*recurse->source, *recurse->destination, (void *) recurse); } - - if (status == F_none && (!recurse.output.stream || recurse.output.id != -1) && recurse.verbose) { - recurse.verbose(recurse.output, source, destination); + else if (F_status_is_error(recurse->state.status)) { + if (recurse->state.handle) { + recurse->state.handle(&recurse->state, (void *) &recurse); + } } - - return status; } -#endif // _di_fl_directory_copy_content_ +#endif // _di_fl_directory_copy_ #ifndef _di_fl_directory_list_ f_status_t fl_directory_list(const f_string_static_t path, int (*filter)(const struct dirent *), int (*sort)(const struct dirent **, const struct dirent **), const bool dereference, f_directory_listing_t * const listing) { @@ -311,9 +201,7 @@ extern "C" { if (!listing) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ - if (!path.used) { - return F_data_not; - } + if (!path.used) return F_data_not; return private_fl_directory_list(path, filter, sort, dereference, listing); } @@ -325,9 +213,7 @@ extern "C" { if (!path) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ - if (!path->used) { - return F_data_not; - } + if (!path->used) return F_data_not; const bool null_terminated = path->string[path->used] == 0; bool first_nulless = F_false; @@ -399,9 +285,7 @@ extern "C" { if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ - if (!source.used) { - return F_data_not; - } + if (!source.used) return F_data_not; return private_fl_directory_path_push(source, destination); } diff --git a/level_1/fl_directory/c/directory.h b/level_1/fl_directory/c/directory.h index 49a9810..7d6c3a0 100644 --- a/level_1/fl_directory/c/directory.h +++ b/level_1/fl_directory/c/directory.h @@ -86,92 +86,35 @@ extern "C" { #endif // _di_fl_directory_create_ /** - * Copy a directory and its contents, as well as its file mode and possibly the owner and group. + * Copy (or clone) a directories contents (and possibly the directory itself). * - * The paths must not contain NULL except for the terminating NULL. - * The paths must be NULL terminated. - * - * Symbolic links are not followed, they are copied as the symbolic link itself. - * - * This does not copy unknown file types. - * - * @param source - * The source file path. - * Must be NULL terminated. - * @param destination - * The destination file path. - * Must be NULL terminated. - * @param recurse - * The directory recurse data. - * - * @return - * F_none on success. - * F_data_not if source.used or destination.used is 0. - * - * F_directory_not (with error bit) if the source directory does not exist. - * F_failure (with error bit) for any other failure, failures might be populated with individual status codes. - * - * Errors (with error bit) from: f_directory_create(). - * Errors (with error bit) from: f_directory_exists(). - * Errors (with error bit) from: f_file_mode_set(). - * Errors (with error bit) from: f_file_role_change(). - * Errors (with error bit) from: f_file_stat(). - * - * @see f_directory_create() - * @see f_directory_exists() - * @see f_file_mode_set() - * @see f_file_role_change() - * @see f_file_stat() - */ -#ifndef _di_fl_directory_clone_ - extern f_status_t fl_directory_clone(const f_string_static_t source, const f_string_static_t destination, const fl_directory_recurse_t recurse); -#endif // _di_fl_directory_clone_ - -/** - * Copy a directory contents, as well as its file mode and possibly the owner and group. + * The file mode, owner, and group may conditionally be preserved when not cloning (when copying). * - * When cloning the contents of a directory, both the source and the destination paths must already exist and be directories, regardless of exclusive boolean. + * The source and destination must not contain NULL except for the terminating NULL. + * The source and destination must be NULL terminated. * - * The paths must not contain NULL except for the terminating NULL. - * The paths must be NULL terminated. - * - * Symbolic links are not followed, they are copied as the symbolic link itself. + * Symbolic links are by default not followed, they are copied as the symbolic link itself. + * Set the f_directory_recurse_flag_dereference_e to follow the symbolic links rather than copying the link itself. * * This does not copy unknown file types. * - * @param source - * The source file path. - * Must be NULL terminated. - * @param destination - * The destination file path. - * Must be NULL terminated. - * @param recurse - * The directory recurse data. + * If recurse.flag has f_directory_recurse_flag_top_e set, then this operates on the top directory otherwise only the content within the directory is operated on. * - * @return - * F_none on success. - * F_data_not if source.used or destination.used is 0. + * If recurse.flag has f_directory_recurse_flag_clone_e set, then this operates a clone operation rather than a copy operation. * - * F_directory_not (with error bit) if either the source or destination directory does not exist. - * F_failure (with error bit) for any other failure, failures might be populated with individual status codes. + * When using f_directory_recurse_flag_clone_e, the recurse.mode is not used. + * When not using f_directory_recurse_flag_clone_e, the recurse.mode is used and should be set accordingly. + * To not used recurse.mode, set the point to NULL. * - * Errors (with error bit) from: f_directory_exists(). + * The recurse.state.handle() callback is used for processing and reporting errors. + * This is not intended to replace the error state with a non error. + * To do so will likely cause problems and undefined behavior. * - * @see f_directory_exists() - */ -#ifndef _di_fl_directory_clone_content_ - extern f_status_t fl_directory_clone_content(const f_string_static_t source, const f_string_static_t destination, const fl_directory_recurse_t recurse); -#endif // _di_fl_directory_clone_content_ - -/** - * Copy a directory and its contents. + * The recurse.state.verbose() callback is used for printing success messages (generally when in verbose mode). * - * The paths must not contain NULL except for the terminating NULL. - * The paths must be NULL terminated. + * The recurse.state.interrupt() callback is used during some loops. * - * Symbolic links are not followed, they are copied as the symbolic link itself. - * - * This does not copy unknown file types. + * The recurse.state.custom is available to be defined by the caller for all recurse.state callbacks. * * @param source * The source file path. @@ -179,70 +122,38 @@ extern "C" { * @param destination * The destination file path. * Must be NULL terminated. - * @param mode - * The directory modes. * @param recurse * The directory recurse data. + * This must not be NULL. * - * @return - * F_none on success. - * F_data_not if source.used or destination.used is 0. + * This alters recurse.state.status: + * F_none on success. + * F_data_not if source.used or destination.used is 0. * - * F_directory_found (with error bit) if the destination directory is found and recurse.flag has f_file_stat_flag_exclusive_e. - * F_directory_not (with error bit) if the source directory does not exist. - * F_failure (with error bit) for any other failure, failures might be populated with individual status codes. + * F_directory_not (with error bit) if the source directory does not exist. + * F_failure (with error bit) for any other failure, failures might be populated with individual status codes. * - * Errors (with error bit) from: f_directory_create(). - * Errors (with error bit) from: f_directory_exists(). - * Errors (with error bit) from: f_file_mode_set(). - * Errors (with error bit) from: f_file_role_change(). - * Errors (with error bit) from: f_file_stat(). + * Errors (with error bit) from: f_directory_create(). + * Errors (with error bit) from: f_directory_exists(). + * Errors (with error bit) from: f_string_dynamic_resize(). + * Errors (with error bit) from: f_string_dynamics_resize(). + * Errors (with error bit) from: f_file_mode_set(). + * Errors (with error bit) from: f_file_role_change(). + * Errors (with error bit) from: f_file_stat(). * - * @see f_file_copy() + * @see f_directory_create() + * @see f_directory_exists() + * @see f_string_dynamic_resize() + * @see f_string_dynamics_resize() + * @see f_file_mode_set() + * @see f_file_role_change() + * @see f_file_stat() */ #ifndef _di_fl_directory_copy_ - extern f_status_t fl_directory_copy(const f_string_static_t source, const f_string_static_t destination, const f_mode_t mode, const fl_directory_recurse_t recurse); + extern void fl_directory_copy(const f_string_static_t source, const f_string_static_t destination, f_directory_recurse_t * const recurse); #endif // _di_fl_directory_copy_ /** - * Copy a directory contents. - * - * When copying the contents of a directory, both the source and the destination paths must already exist and be directories, regardless of exclusive boolean. - * - * The paths must not contain NULL except for the terminating NULL. - * The paths must be NULL terminated. - * - * Symbolic links are not followed, they are copied as the symbolic link itself. - * - * This does not copy unknown file types. - * - * @param source - * The source file path. - * Must be NULL terminated. - * @param destination - * The destination file path. - * Must be NULL terminated. - * @param mode - * The directory modes. - * @param recurse - * The directory recurse data. - * - * @return - * F_none on success. - * F_data_not if source.used or destination.used is 0. - * - * F_directory_not (with error bit) if either the source or the destination directory does not exist. - * F_failure (with error bit) for any other failure, failures might be populated with individual status codes. - * - * Errors (with error bit) from: f_directory_exists(). - * - * @see f_file_copy() - */ -#ifndef _di_fl_directory_copy_content_ - extern f_status_t fl_directory_copy_content(const f_string_static_t source, const f_string_static_t destination, const f_mode_t mode, const fl_directory_recurse_t recurse); -#endif // _di_fl_directory_copy_content_ - -/** * For some given path, print the names of each file and/or directory inside the directory, stored as a directory listing. * * Allows specifying a custom filter and custom sort. diff --git a/level_1/fl_directory/c/directory/common.h b/level_1/fl_directory/c/directory/common.h index 3cd7648..c1277d3 100644 --- a/level_1/fl_directory/c/directory/common.h +++ b/level_1/fl_directory/c/directory/common.h @@ -16,72 +16,6 @@ extern "C" { #endif - -/** - * An association of a path and a status code. - */ -#ifndef _di_fl_directory_recurse_d_ - #define FL_directory_recurse_depth_max_d 65535 -#endif // _di_fl_directory_recurse_d_ - -/** - * An association of a path and a status code. - * - * The allocation macros apply to the path. - * - * size_block: - * The default number of chunks to read at a time with each chunk being 1-byte. - * Must be greater than 0. - * flag: - * If f_file_stat_flag_exclusive_e, will fail when file already exists. - * If not f_file_stat_flag_exclusive_e, will not fail if file already exists (existing file will be replaced). - * - * If f_file_stat_flag_reference_e, will operate directly on a link rather than what it references. - * If not f_file_stat_flag_reference_e, will dereference any links. - * - * For clone operations: - * - If f_file_stat_flag_group_e or f_file_stat_flag_owner_e, will copy the owner and group ids. - * - If neither f_file_stat_flag_group_e nor f_file_stat_flag_owner_e, will not copy the owner and group ids. - * (In both cases for a clone operation, the file mode is copied.) - * output: - * Set to -1 to not print on successful operation. - * Set to a valid file descriptor to print to on successful operation. - * This is passed to the verbose function if that function pointer is not -1. - * verbose: - * Set output.id to -1 and output.stream to 0 to not print on successful operation. - * Set to address of a function to be called for printing such that: - * - The first parameter represents the output file type. - * - The second parameter represents the source string. - * - The third parameter represents the destination string. - * failures: - * A list of paths and their respective status codes for clone failures. - * If 0, then this and statuses are ignored. - */ -#ifndef _di_fl_directory_recurse_t_ - typedef struct { - f_number_unsigned_t depth_max; - f_number_unsigned_t size_block; - - uint8_t flag; - f_file_t output; - - void (*verbose)(const f_file_t, const f_string_static_t, const f_string_static_t); - - f_directory_statuss_t *failures; - } fl_directory_recurse_t; - - #define fl_directory_recurse_t_initialize { FL_directory_recurse_depth_max_d, F_file_default_read_size_d, 0, macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d), 0, 0 } - - #define macro_fl_directory_recurse_t_initialize(depth_max, size_block, flag, output, verbose, failures) { \ - depth_max, \ - size_block, \ - flag, \ - output, \ - verbose, \ - failures \ - } -#endif // _di_fl_directory_recurse_t_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_1/fl_directory/c/private-directory.c b/level_1/fl_directory/c/private-directory.c index 5fcf433..8d9b195 100644 --- a/level_1/fl_directory/c/private-directory.c +++ b/level_1/fl_directory/c/private-directory.c @@ -5,358 +5,221 @@ extern "C" { #endif -#if !defined(_di_fl_directory_clone_) || !defined(_di_fl_directory_clone_content_) - f_status_t private_fl_directory_clone(const f_string_static_t source, const f_string_static_t destination, const fl_directory_recurse_t recurse, const f_number_unsigned_t depth) { +#if !defined(_di_fl_directory_copy_) + void private_fl_directory_copy_recurse(f_directory_recurse_t * const recurse) { - f_status_t status = F_none; - f_directory_listing_t listing = f_directory_listing_t_initialize; + f_string_dynamics_t directories = f_string_dynamics_t_initialize; + f_string_dynamics_t directories_original = f_string_dynamics_t_initialize; - status = private_fl_directory_list(source, 0, 0, F_false, &listing); + directories_original.array = recurse->listing.directory.array; + directories_original.used = recurse->listing.directory.used; + directories_original.size = recurse->listing.directory.size; - if (F_status_is_error(status)) { - macro_f_directory_listing_t_delete_simple(listing); + recurse->listing.directory.array = directories.array; + recurse->listing.directory.used = directories.used; + recurse->listing.directory.size = directories.size; - return status; - } + recurse->state.status = private_fl_directory_list(*recurse->source, 0, 0, recurse->flag & f_directory_recurse_flag_dereference_e, &recurse->listing); + + if (F_status_is_error(recurse->state.status)) { - status = F_none; + // Only the directory is to be freed because all others are preserved between recursions. + f_string_dynamics_resize(0, &directories); - f_array_length_t failures_used = recurse.failures ? recurse.failures->used : 0; + return; + } + + recurse->state.status = F_none; { f_string_dynamics_t * const list[] = { - &listing.block, - &listing.character, - &listing.regular, - &listing.link, - &listing.fifo, - &listing.socket, - &listing.unknown, + &recurse->listing.block, + &recurse->listing.character, + &recurse->listing.regular, + &recurse->listing.link, + &recurse->listing.fifo, + &recurse->listing.socket, + &recurse->listing.unknown, }; - uint8_t i = 0; f_array_length_t j = 0; - for (; i < 7; ++i) { + for (uint8_t i = 0; i < 7; ++i) { - for (j = 0; F_status_is_fine(status) && j < list[i]->used; ++j) { - status = private_fl_directory_clone_file(list[i]->array[j], source, destination, recurse); + for (j = 0; F_status_is_fine(recurse->state.status) && j < list[i]->used; ++j) { + private_fl_directory_copy_recurse_file(list[i]->array[j], recurse); } // for - f_string_dynamics_resize(0, list[i]); - } // for - } - - for (f_array_length_t i = 0; F_status_is_fine(status) && i < listing.directory.used; ++i) { - - f_string_static_t source_sub = f_string_static_t_initialize; - f_string_static_t destination_sub = f_string_static_t_initialize; - - source_sub.used = source.used + listing.directory.array[i].used + 1; - source_sub.size = source_sub.used; - - destination_sub.used = destination.used + listing.directory.array[i].used + 1; - destination_sub.size = destination_sub.used; + list[i]->used = 0; - f_char_t path_source_sub[source_sub.used + 1]; - f_char_t path_destination_sub[destination_sub.used + 1]; - - memcpy(path_source_sub, source.string, sizeof(f_char_t) * source.used); - memcpy(path_source_sub + source.used + 1, listing.directory.array[i].string, sizeof(f_char_t) * listing.directory.array[i].used); - - memcpy(path_destination_sub, destination.string, sizeof(f_char_t) * destination.used); - memcpy(path_destination_sub + destination.used + 1, listing.directory.array[i].string, sizeof(f_char_t) * listing.directory.array[i].used); - - path_source_sub[source.used] = f_path_separator_s.string[0]; - path_source_sub[source_sub.used] = 0; - - path_destination_sub[destination.used] = f_path_separator_s.string[0]; - path_destination_sub[destination_sub.used] = 0; - - source_sub.string = path_source_sub; - destination_sub.string = path_destination_sub; - - status = f_directory_exists(source_sub); - if (F_status_is_error(status)) break; - - if (status == F_false) { - status = F_status_set_error(F_directory); - - break; - } - - { - struct stat source_stat; - - memset(&source_stat, 0, sizeof(struct stat)); - - status = f_file_stat(source_sub, F_false, &source_stat); - if (F_status_is_error(status)) break; + // Use an upper limit when retaining memory between recursion calls. + if (list[i]->size > F_directory_max_list_d) { + recurse->state.status = f_string_dynamics_resize(F_directory_max_list_d, list[i]); + if (F_status_is_error(recurse->state.status)) break; + } - status = f_directory_exists(destination_sub); - if (F_status_is_error(status)) break; + for (j = 0; j < list[i]->used; ++j) { - if (status == F_true) { - if (recurse.flag & f_file_stat_flag_exclusive_e) { - status = F_status_set_error(F_directory_found); + list[i]->array[j].used = 0; - break; + if (list[i]->array[j].size > F_directory_max_string_d) { + recurse->state.status = f_string_dynamic_resize(F_directory_max_string_d, &list[i]->array[j]); + if (F_status_is_error(recurse->state.status)) break; } + } // for + } // for + } - status = f_file_mode_set(destination_sub, source_stat.st_mode); - if (F_status_is_error(status)) break; - } - else { - status = f_directory_create(destination_sub, source_stat.st_mode); - if (F_status_is_error(status)) break; - } + if (F_status_is_error_not(recurse->state.status)) { + for (f_array_length_t i = 0; i < recurse->listing.directory.used; ++i) { - if (recurse.flag & (f_file_stat_flag_group_e | f_file_stat_flag_owner_e)) { - status = f_file_role_change(destination_sub, source_stat.st_uid, source_stat.st_gid, F_true); - if (F_status_is_error(status)) break; + if (recurse->state.interrupt) { + recurse->state.interrupt((void *) &recurse->state, (void *) recurse); + if (F_status_set_fine(recurse->state.status) == F_interrupt) break; } - } - if (depth < recurse.depth_max) { - status = private_fl_directory_clone(source_sub, destination_sub, recurse, depth + 1); + f_string_static_t source_sub = f_string_static_t_initialize; + f_string_static_t destination_sub = f_string_static_t_initialize; - if (status == F_none && (!recurse.output.stream || recurse.output.id != -1) && recurse.verbose) { - recurse.verbose(recurse.output, source_sub, destination_sub); - } - } - } // for + source_sub.used = recurse->source->used + recurse->listing.directory.array[i].used + 1; + source_sub.size = source_sub.used; - f_string_dynamics_resize(0, &listing.directory); - if (F_status_is_error(status)) return status; + destination_sub.used = recurse->destination->used + recurse->listing.directory.array[i].used + 1; + destination_sub.size = destination_sub.used; - if (recurse.failures && failures_used < recurse.failures->used) { - return F_failure; - } + f_char_t path_source_sub[source_sub.used + 1]; + f_char_t path_destination_sub[destination_sub.used + 1]; - return F_none; - } -#endif // !defined(_di_fl_directory_clone_) || !defined(_di_fl_directory_clone_content_) - -#if !defined(_di_fl_directory_clone_file_) - f_status_t private_fl_directory_clone_file(const f_string_static_t file, const f_string_static_t source, const f_string_static_t destination, const fl_directory_recurse_t recurse) { + memcpy(path_source_sub, recurse->source->string, sizeof(f_char_t) * recurse->source->used); + memcpy(path_source_sub + recurse->source->used + 1, recurse->listing.directory.array[i].string, sizeof(f_char_t) * recurse->listing.directory.array[i].used); - f_string_static_t path_source = f_string_static_t_initialize; - f_string_static_t path_destination = f_string_static_t_initialize; + memcpy(path_destination_sub, recurse->destination->string, sizeof(f_char_t) * recurse->destination->used); + memcpy(path_destination_sub + recurse->destination->used + 1, recurse->listing.directory.array[i].string, sizeof(f_char_t) * recurse->listing.directory.array[i].used); - path_source.used = source.used + file.used + 2; - path_destination.used = destination.used + file.used + 2; + path_source_sub[recurse->source->used] = f_path_separator_s.string[0]; + path_source_sub[source_sub.used] = 0; - f_char_t path_source_string[path_source.used]; - f_char_t path_destination_string[path_destination.used]; + path_destination_sub[recurse->destination->used] = f_path_separator_s.string[0]; + path_destination_sub[destination_sub.used] = 0; - path_source.string = path_source_string; - path_destination.string = path_destination_string; + source_sub.string = path_source_sub; + destination_sub.string = path_destination_sub; - memcpy(path_source_string, source.string, sizeof(f_char_t) * source.used); - memcpy(path_source_string + source.used + 1, file.string, sizeof(f_char_t) * file.used); - path_source_string[source.used] = f_path_separator_s.string[0]; - path_source_string[source.used + file.used + 1] = 0; + recurse->state.status = f_directory_exists(source_sub); + if (F_status_is_error(recurse->state.status)) break; - memcpy(path_destination_string, destination.string, sizeof(f_char_t) * destination.used); - memcpy(path_destination_string + destination.used + 1, file.string, sizeof(f_char_t) * file.used); - path_destination_string[destination.used] = f_path_separator_s.string[0]; - path_destination_string[destination.used + file.used + 1] = 0; + if (recurse->state.status == F_false) { + recurse->state.status = F_status_set_error(F_directory); - f_status_t status = f_file_clone(path_source, path_destination, recurse.size_block, recurse.flag); + break; + } - if (F_status_is_error(status) || status == F_support_not) { - if (status == F_status_set_error(F_memory_not)) { - return F_status_set_error(status); - } + if (recurse->flag & f_directory_recurse_flag_clone_e) { + struct stat source_stat; - if (!recurse.failures) return F_failure; + memset(&source_stat, 0, sizeof(struct stat)); - const f_status_t status_failure = status; + recurse->state.status = f_file_stat(source_sub, recurse->flag & f_directory_recurse_flag_dereference_e, &source_stat); + if (F_status_is_error(recurse->state.status)) break; - macro_f_memory_structure_increment(status, (*recurse.failures), 1, F_memory_default_allocation_small_d, macro_f_directory_statuss_t_resize, F_array_too_large); - if (F_status_is_error(status)) return status; + recurse->state.status = f_directory_exists(destination_sub); + if (F_status_is_error(recurse->state.status)) break; - f_directory_status_t failure = f_directory_status_t_initialize; - f_array_length_t size = 0; + if (recurse->state.status == F_true) { + if (recurse->flag & f_directory_recurse_flag_exclusive_e) { + recurse->state.status = F_status_set_error(F_directory_found); - // identify if failure was because of source or destination. - struct stat source_stat; + break; + } - memset(&source_stat, 0, sizeof(struct stat)); + recurse->state.status = f_file_mode_set(destination_sub, source_stat.st_mode); + if (F_status_is_error(recurse->state.status)) break; + } + else { + recurse->state.status = f_directory_create(destination_sub, source_stat.st_mode); + if (F_status_is_error(recurse->state.status)) break; + } - status = f_file_stat(source, F_false, &source_stat); - if (F_status_is_error(status)) { - if (status == F_status_set_error(F_string_too_large)) { - size = F_string_t_size_d - 1; + if (recurse->flag & (f_directory_recurse_flag_group_e | f_directory_recurse_flag_owner_e)) { + recurse->state.status = f_file_role_change(destination_sub, (recurse->flag & f_directory_recurse_flag_owner_e) ? source_stat.st_uid : -1, (recurse->flag & f_directory_recurse_flag_group_e) ? source_stat.st_gid : -1, recurse->flag & f_directory_recurse_flag_dereference_e); + if (F_status_is_error(recurse->state.status)) break; + } } else { - size = source.used + file.used + 1; - } + if (recurse->state.status == F_true) { + if (recurse->flag & f_directory_recurse_flag_exclusive_e) { + recurse->state.status = F_status_set_error(F_directory_found); - macro_f_directory_status_t_resize(status, failure, size + 1); - if (F_status_is_error(status)) return status; + break; + } - memcpy(failure.path.string, path_source.string, sizeof(f_char_t) * size); - failure.path.string[size] = 0; - } - else { - if (status == F_status_set_error(F_string_too_large)) { - size = F_string_t_size_d - 1; - } - else { - size = destination.used + file.used + 1; + recurse->state.status = f_file_mode_set(destination_sub, recurse->mode.directory); + if (F_status_is_error(recurse->state.status)) break; + } + else { + recurse->state.status = f_directory_create(destination_sub, recurse->mode.directory); + if (F_status_is_error(recurse->state.status)) break; + } } - macro_f_directory_status_t_resize(status, failure, size + 1); - if (F_status_is_error(status)) return status; - - memcpy(failure.path.string, path_destination.string, sizeof(f_char_t) * size); - failure.path.string[size] = 0; - } - - recurse.failures->array[recurse.failures->used].path.string = failure.path.string; - recurse.failures->array[recurse.failures->used].path.used = size; - recurse.failures->array[recurse.failures->used].path.size = size + 1; - recurse.failures->array[recurse.failures->used++].status = status_failure; - - return F_failure; - } - - if ((!recurse.output.stream || recurse.output.id != -1) && recurse.verbose) { - recurse.verbose(recurse.output, path_source, path_destination); - } - - return F_none; - } -#endif // !defined(_di_fl_directory_clone_file_) - -#if !defined(_di_fl_directory_copy_) || !defined(_di_fl_directory_copy_content_) - f_status_t private_fl_directory_copy(const f_string_static_t source, const f_string_static_t destination, const f_mode_t mode, const fl_directory_recurse_t recurse, const f_number_unsigned_t depth) { + if (recurse->depth < recurse->max_depth) { + recurse->source = (f_string_static_t * const) & source_sub; + recurse->destination = (f_string_static_t * const) & destination_sub; - f_status_t status = F_none; - f_directory_listing_t listing = f_directory_listing_t_initialize; - - status = private_fl_directory_list(source, 0, 0, F_false, &listing); + ++recurse->depth; - if (F_status_is_error(status)) { - macro_f_directory_listing_t_delete_simple(listing); + private_fl_directory_copy_recurse(recurse); - return status; - } + // Data must be restored after recursion. + recurse->source = (f_string_static_t * const) & source_sub; + recurse->destination = (f_string_static_t * const) & destination_sub; - status = F_none; + // Success inside the recursed function is handled inside the recursed function, so handle at the current depth. + if (recurse->state.status == F_none) { + --recurse->depth; - f_array_length_t failures_used = recurse.failures ? recurse.failures->used : 0; + if (recurse->verbose) { + recurse->verbose(source_sub, destination_sub, recurse); + } + } - { - f_string_dynamics_t * const list[] = { - &listing.block, - &listing.character, - &listing.regular, - &listing.link, - &listing.fifo, - &listing.socket, - &listing.unknown, - }; + // Errors in the recursed function are handled outside the recursed function here. + if (F_status_is_error(recurse->state.status)) { + if (recurse->state.handle) { + recurse->state.handle(&recurse->state, (void *) &recurse); + } - uint8_t i = 0; - f_array_length_t j = 0; + recurse->state.status = F_failure; + } - for (; i < 7; ++i) { + // Error is now handled, so update the depth and exit. + if (recurse->state.status == F_failure) { + --recurse->depth; - for (j = 0; F_status_is_fine(status) && j < list[i]->used; ++j) { - status = private_fl_directory_copy_file(list[i]->array[j], source, destination, mode, recurse); - } // for + break; + } + } - f_string_dynamics_resize(0, list[i]); + recurse->state.status = F_none; } // for } - for (f_array_length_t i = 0; F_status_is_fine(status) && i < listing.directory.used; ++i) { - - f_string_static_t source_sub = f_string_static_t_initialize; - f_string_static_t destination_sub = f_string_static_t_initialize; - - source_sub.used = source.used + listing.directory.array[i].used + 1; - source_sub.size = source_sub.used; - - destination_sub.used = destination.used + listing.directory.array[i].used + 1; - destination_sub.size = destination_sub.used; - - f_char_t path_source_sub[source_sub.used + 1]; - f_char_t path_destination_sub[destination_sub.used + 1]; - - memcpy(path_source_sub, source.string, sizeof(f_char_t) * source.used); - memcpy(path_source_sub + source.used + 1, listing.directory.array[i].string, sizeof(f_char_t) * listing.directory.array[i].used); - - memcpy(path_destination_sub, destination.string, destination.used); - memcpy(path_destination_sub + destination.used + 1, listing.directory.array[i].string, sizeof(f_char_t) * listing.directory.array[i].used); + recurse->listing.directory.array = directories_original.array; + recurse->listing.directory.used = directories_original.used; + recurse->listing.directory.size = directories_original.size; - path_source_sub[source.used] = f_path_separator_s.string[0]; - path_source_sub[source_sub.used] = 0; - - path_destination_sub[destination.used] = f_path_separator_s.string[0]; - path_destination_sub[destination_sub.used] = 0; - - source_sub.string = path_source_sub; - destination_sub.string = path_destination_sub; - - status = f_directory_exists(source_sub); - if (F_status_is_error(status)) break; - - if (status == F_false) { - status = F_status_set_error(F_directory); - - break; - } - - status = f_directory_exists(destination_sub); - if (F_status_is_error(status)) break; - - if (status == F_true) { - if (recurse.flag & f_file_stat_flag_exclusive_e) { - status = F_status_set_error(F_directory_found); - - break; - } - - status = f_file_mode_set(destination_sub, mode.directory); - if (F_status_is_error(status)) break; - } - else { - status = f_directory_create(destination_sub, mode.directory); - if (F_status_is_error(status)) break; - } - - if (depth < recurse.depth_max) { - status = private_fl_directory_copy(source_sub, destination_sub, mode, recurse, depth + 1); - - if (status == F_none && (!recurse.output.stream || recurse.output.id != -1) && recurse.verbose) { - recurse.verbose(recurse.output, source_sub, destination_sub); - } - } - } // for - - f_string_dynamics_resize(0, &listing.directory); - - if (F_status_is_error(status)) return status; - - if (recurse.failures && failures_used < recurse.failures->used) { - return F_failure; - } - - return F_none; + f_string_dynamics_resize(0, &directories); } -#endif // !defined(_di_fl_directory_copy_) || !defined(_di_fl_directory_copy_content_) +#endif // !defined(_di_fl_directory_copy_) -#if !defined(_di_fl_directory_copy_) || !defined(_di_fl_directory_copy_content_) - f_status_t private_fl_directory_copy_file(const f_string_static_t file, const f_string_static_t source, const f_string_static_t destination, const f_mode_t mode, const fl_directory_recurse_t recurse) { +#if !defined(_di_fl_directory_copy_) + void private_fl_directory_copy_recurse_file(const f_string_static_t file, f_directory_recurse_t * const recurse) { f_string_static_t path_source = f_string_static_t_initialize; f_string_static_t path_destination = f_string_static_t_initialize; - path_source.used = source.used + file.used + 2; - path_destination.used = destination.used + file.used + 2; + path_source.used = recurse->source->used + file.used + 2; + path_destination.used = recurse->destination->used + file.used + 2; f_char_t path_source_string[path_source.used]; f_char_t path_destination_string[path_destination.used]; @@ -364,88 +227,59 @@ extern "C" { path_source.string = path_source_string; path_destination.string = path_destination_string; - memcpy(path_source_string, source.string, sizeof(f_char_t) * source.used); - memcpy(path_source_string + source.used + 1, file.string, sizeof(f_char_t) * file.used); - path_source_string[source.used] = f_path_separator_s.string[0]; - path_source_string[source.used + file.used + 1] = 0; - - memcpy(path_destination_string, destination.string, sizeof(f_char_t) * destination.used); - memcpy(path_destination_string + destination.used + 1, file.string, sizeof(f_char_t) * file.used); - path_destination_string[destination.used] = f_path_separator_s.string[0]; - path_destination_string[destination.used + file.used + 1] = 0; - - f_status_t status = f_file_copy(path_source, path_destination, mode, recurse.size_block, recurse.flag); - - if (F_status_is_error(status) || status == F_support_not) { - if (status == F_status_set_error(F_memory_not)) { - return F_status_set_error(status); - } - - if (!recurse.failures) { - return F_failure; - } - - const f_status_t status_failure = status; + memcpy(path_source_string, recurse->source->string, sizeof(f_char_t) * recurse->source->used); + memcpy(path_source_string + recurse->source->used + 1, file.string, sizeof(f_char_t) * file.used); + path_source_string[recurse->source->used] = f_path_separator_s.string[0]; + path_source_string[recurse->source->used + file.used + 1] = 0; - macro_f_memory_structure_increment(status, (*recurse.failures), 1, F_memory_default_allocation_small_d, macro_f_directory_statuss_t_resize, F_array_too_large); - if (F_status_is_error(status)) return status; + memcpy(path_destination_string, recurse->destination->string, sizeof(f_char_t) * recurse->destination->used); + memcpy(path_destination_string + recurse->destination->used + 1, file.string, sizeof(f_char_t) * file.used); + path_destination_string[recurse->destination->used] = f_path_separator_s.string[0]; + path_destination_string[recurse->destination->used + file.used + 1] = 0; - f_directory_status_t failure = f_directory_status_t_initialize; - f_array_length_t size = 0; - - // identify if failure was because of source or destination. - struct stat source_stat; + f_status_t status = F_none; + int flag = (recurse->flag & f_directory_recurse_flag_dereference_e) ? 0 : f_file_stat_flag_reference_e; - memset(&source_stat, 0, sizeof(struct stat)); + if (recurse->flag & f_directory_recurse_flag_exclusive_e) { + flag |= f_file_stat_flag_exclusive_e; + } - status = f_file_stat(source, F_false, &source_stat); + if (recurse->flag & f_directory_recurse_flag_group_e) { + flag |= f_file_stat_flag_group_e; + } - if (F_status_is_error(status)) { - if (status == F_status_set_error(F_string_too_large)) { - size = F_string_t_size_d - 1; - } - else { - size = source.used + file.used + 1; - } + if (recurse->flag & f_directory_recurse_flag_owner_e) { + flag |= f_file_stat_flag_owner_e; + } - macro_f_directory_status_t_resize(status, failure, size + 1); - if (F_status_is_error(status)) return status; + if (recurse->flag & f_directory_recurse_flag_clone_e) { + recurse->state.status = f_file_clone(path_source, path_destination, recurse->size_block, flag); + } + else { + recurse->state.status = f_file_copy(path_source, path_destination, recurse->mode, recurse->size_block, flag); + } - memcpy(failure.path.string, path_source.string, sizeof(f_char_t) * size); - failure.path.string[size] = 0; + if (F_status_is_error(status) || status == F_support_not) { + if (recurse->state.handle) { + recurse->state.handle(&recurse->state, (void *) &recurse); } - else { - if (status == F_status_set_error(F_string_too_large)) { - size = F_string_t_size_d - 1; - } - else { - size = destination.used + file.used + 1; - } - macro_f_directory_status_t_resize(status, failure, size + 1); - if (F_status_is_error(status)) return status; + if (status == F_status_set_error(F_memory_not)) return; - memcpy(failure.path.string, path_destination.string, sizeof(f_char_t) * size); - failure.path.string[size] = 0; - } + recurse->state.status = F_failure; - recurse.failures->array[recurse.failures->used].path.string = failure.path.string; - recurse.failures->array[recurse.failures->used].path.used = size; - recurse.failures->array[recurse.failures->used].path.size = size + 1; - recurse.failures->array[recurse.failures->used++].status = status_failure; - - return F_failure; + return; } - if ((!recurse.output.stream || recurse.output.id != -1) && recurse.verbose) { - recurse.verbose(recurse.output, path_source, path_destination); + if (recurse->verbose) { + recurse->verbose(path_source, path_destination, (void *) recurse); } - return F_none; + recurse->state.status = F_none; } -#endif // !defined(_di_fl_directory_copy_) || !defined(_di_fl_directory_copy_content_) +#endif // !defined(_di_fl_directory_copy_) -#if !defined(_di_fl_directory_clone_) || !defined(_di_fl_directory_copy_) || !defined(_di_fl_directory_copy_content_) || !defined(_di_fl_directory_list_) +#if !defined(_di_fl_directory_copy_) || !defined(_di_fl_directory_list_) f_status_t private_fl_directory_list(const f_string_static_t path, int (*filter)(const struct dirent *), int (*sort)(const struct dirent **, const struct dirent **), const bool dereference, f_directory_listing_t * const listing) { struct dirent **entity = 0; @@ -495,7 +329,7 @@ extern "C" { for (; i < length; ++i) { name_directory.string = (f_string_t) entity[i]->d_name; - name_directory.used = strnlen(name_directory.string, F_directory_name_max_d); + name_directory.used = strnlen(name_directory.string, F_directory_max_name_d); // There is no reason to include "." and ".." in the directory listing. if (!strncmp(name_directory.string, "..", 3) || !strncmp(name_directory.string, ".", 2)) { @@ -537,7 +371,7 @@ extern "C" { } if (names->used == names->size) { - status = f_string_dynamics_increase_by(F_directory_default_allocation_step_d, names); + status = f_string_dynamics_increase_by(F_memory_default_allocation_small_d, names); if (F_status_is_error(status)) break; } @@ -565,7 +399,7 @@ extern "C" { return F_none; } -#endif // !defined(_di_fl_directory_clone_) || !defined(_di_fl_directory_copy_) || !defined(_di_fl_directory_copy_content_) || !defined(_di_fl_directory_list_) +#endif // !defined(_di_fl_directory_copy_) || !defined(_di_fl_directory_list_) #if !defined(_di_fl_directory_path_push_) || !defined(_di_fl_directory_path_push_dynamic_) f_status_t private_fl_directory_path_push(const f_string_static_t source, f_string_dynamic_t * const destination) { diff --git a/level_1/fl_directory/c/private-directory.h b/level_1/fl_directory/c/private-directory.h index b262cbb..fe846eb 100644 --- a/level_1/fl_directory/c/private-directory.h +++ b/level_1/fl_directory/c/private-directory.h @@ -15,62 +15,6 @@ extern "C" { #endif /** - * Private implementation of fl_directory_clone(). - * - * Intended to be shared to each of the different implementation variations. - * - * @param source - * The source file path. - * Must be NULL terminated. - * @param destination - * The destination file path. - * Must be NULL terminated. - * @param recurse - * The directory recurse data. - * @param depth - * The current depth. - * - * @return - * F_none on success. - * - * F_failure (with error bit) for any other failure, failures might be populated with individual status codes. - * - * @see fl_directory_clone() - */ -#if !defined(_di_fl_directory_clone_) || !defined(_di_fl_directory_clone_content_) - extern f_status_t private_fl_directory_clone(const f_string_static_t source, const f_string_static_t destination, const fl_directory_recurse_t recurse, const f_number_unsigned_t depth) F_attribute_visibility_internal_d; -#endif // !defined(_di_fl_directory_clone_) || !defined(_di_fl_directory_clone_content_) - -/** - * A special function intended to be used directly by private_fl_directory_clone(). - * - * Will only clone a single file and record any detected errors. - * - * @param file - * The name of the file within source to clone into destination. - * Must be NULL terminated. - * @param source - * The source file path. - * Must be NULL terminated. - * @param destination - * The destination file path. - * Must be NULL terminated. - * @param recurse - * The directory recurse data. - * - * @return - * F_none on success. - * - * F_array_too_large (with error bit) if a buffer would exceed max length. - * F_failure (with error bit) for any other failure, failures might be populated with individual status codes. - * - * @see fl_directory_clone() - */ -#if !defined(_di_fl_directory_clone_file_) - extern f_status_t private_fl_directory_clone_file(const f_string_static_t file, const f_string_static_t source, const f_string_static_t destination, const fl_directory_recurse_t recurse) F_attribute_visibility_internal_d; -#endif // !defined(_di_fl_directory_clone_file_) - -/** * Private implementation of fl_directory_copy(). * * Intended to be shared to each of the different implementation variations. @@ -81,8 +25,6 @@ extern "C" { * @param destination * The destination file path. * Must be NULL terminated. - * @param mode - * The mode for each file type. * @param recurse * The directory recurse data. * @param depth @@ -94,14 +36,13 @@ extern "C" { * F_failure (with error bit) for any other failure, failures might be populated with individual status codes. * * @see fl_directory_copy() - * @see fl_directory_copy_content() */ -#if !defined(_di_fl_directory_copy_) || !defined(_di_fl_directory_copy_content_) - extern f_status_t private_fl_directory_copy(const f_string_static_t source, const f_string_static_t destination, const f_mode_t mode, const fl_directory_recurse_t recurse, const f_number_unsigned_t depth) F_attribute_visibility_internal_d; -#endif // !defined(_di_fl_directory_copy_) || !defined(_di_fl_directory_copy_content_) +#if !defined(_di_fl_directory_copy_) + extern void private_fl_directory_copy_recurse(f_directory_recurse_t * const recurse) F_attribute_visibility_internal_d; +#endif // !defined(_di_fl_directory_copy_) /** - * A special function intended to be used directly by private_fl_directory_copy(). + * A special function intended to be used directly by private_fl_directory_copy_recurse(). * * Will only copy a single file and record any detected errors. * @@ -125,12 +66,11 @@ extern "C" { * F_array_too_large (with error bit) if a buffer would exceed max length. * F_failure (with error bit) for any other failure, failures might be populated with individual status codes. * - * @see fl_directory_copy() - * @see fl_directory_copy_content() + * @see fl_directory_clone() */ -#if !defined(_di_fl_directory_copy_) || !defined(_di_fl_directory_copy_content_) - extern f_status_t private_fl_directory_copy_file(const f_string_static_t file, const f_string_static_t source, const f_string_static_t destination, const f_mode_t mode, const fl_directory_recurse_t recurse) F_attribute_visibility_internal_d; -#endif // !defined(_di_fl_directory_copy_) || !defined(_di_fl_directory_copy_content_) +#if !defined(_di_fl_directory_copy_) + extern void private_fl_directory_copy_recurse_file(const f_string_static_t file, f_directory_recurse_t * const recurse) F_attribute_visibility_internal_d; +#endif // !defined(_di_fl_directory_copy_) /** * A special function intended to be used directly by fl_directory_list(). @@ -171,15 +111,12 @@ extern "C" { * @see f_file_stat_at() * @see f_string_dynamics_increase_by() * - * @see fl_directory_clone() - * @see fl_directory_clone_content() * @see fl_directory_copy() - * @see fl_directory_copy_content() * @see fl_directory_list() */ -#if !defined(_di_fl_directory_clone_) || !defined(_di_fl_directory_clone_content_) || !defined(_di_fl_directory_copy_) || !defined(_di_fl_directory_copy_content_) || !defined(_di_fl_directory_list_) +#if !defined(_di_fl_directory_copy_) || !defined(_di_fl_directory_list_) extern f_status_t private_fl_directory_list(const f_string_static_t path, int (*filter)(const struct dirent *), int (*sort)(const struct dirent **, const struct dirent **), const bool dereference, f_directory_listing_t * const listing) F_attribute_visibility_internal_d; -#endif // !defined(_di_fl_directory_clone_) || !defined(_di_fl_directory_clone_content_) || !defined(_di_fl_directory_copy_) || !defined(_di_fl_directory_copy_content_) || !defined(_di_fl_directory_list_) +#endif // !defined(_di_fl_directory_copy_) || !defined(_di_fl_directory_list_) /** * Private implementation of fl_directory_path_push(). diff --git a/level_1/fl_fss/c/fss/basic.c b/level_1/fl_fss/c/fss/basic.c index 527e404..b5821f9 100644 --- a/level_1/fl_fss/c/fss/basic.c +++ b/level_1/fl_fss/c/fss/basic.c @@ -1,187 +1,207 @@ #include "basic.h" #include "../private-fss.h" -#include "macro.h" #ifdef __cplusplus extern "C" { #endif #ifndef _di_fl_fss_basic_content_read_ - f_status_t fl_fss_basic_content_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_content_t * const found, f_fss_delimits_t * const delimits) { + void fl_fss_basic_content_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_content_t * const found, f_fss_delimits_t * const delimits, f_state_t * const state) { #ifndef _di_level_1_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!found) return F_status_set_error(F_parameter); - if (!delimits) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !found || !delimits) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_1_parameter_checking_ - f_status_t status = f_fss_skip_past_space(state, buffer, range); - if (F_status_is_error(status)) return status; + f_fss_skip_past_space(buffer, range, state); + if (F_status_is_error(state->status)) return; - if (status == F_none_eol) { + if (state->status == F_none_eol) { ++range->start; + state->status = F_fss_found_content_not; - return F_fss_found_content_not; + return; } - if (status == F_none_eos) return F_data_not_eos; - if (status == F_none_stop) return F_data_not_stop; + if (state->status == F_none_eos) { + state->status = F_data_not_eos; - status = f_string_ranges_increase(state.step_small, found); - if (F_status_is_error(status)) return status; + return; + } - found->array[found->used].start = range->start; + if (state->status == F_none_stop) { + state->status = F_data_not_stop; - for (;; ++range->start) { + return; + } - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); + state->status = f_string_ranges_increase(state->step_small, found); + if (F_status_is_error(state->status)) return; - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); + found->array[found->used].start = range->start; - break; - } + for (;; ++range->start) { + + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } - status = f_fss_skip_past_delimit(state, buffer, range); - if (F_status_is_error(status)) break; + f_fss_skip_past_delimit(buffer, range, state); + if (F_status_is_error(state->status)) break; - if (status == F_none_eos || status == F_none_stop) return status; + if (state->status == F_none_eos || state->status == F_none_stop) return; if (buffer.string[range->start] == f_fss_basic_close_s.string[0]) break; } // for - if (F_status_is_error(status)) return status; + if (F_status_is_error(state->status)) return; found->array[found->used++].stop = range->start - 1; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) return status; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) return; - return F_fss_found_content; + state->status = F_fss_found_content; } #endif // _di_fl_fss_basic_content_read_ #ifndef _di_fl_fss_basic_content_write_ - f_status_t fl_fss_basic_content_write(const f_string_static_t content, const uint8_t complete, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination) { + void fl_fss_basic_content_write(const f_string_static_t content, const uint8_t complete, f_string_range_t * const range, f_string_dynamic_t * const destination, f_state_t * const state) { #ifndef _di_level_1_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!destination) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !destination) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_1_parameter_checking_ - f_status_t status = F_none; + state->status = F_none; - status = f_fss_skip_past_delimit(state, content, range); - if (F_status_is_error(status)) return status; + f_fss_skip_past_delimit(content, range, state); + if (F_status_is_error(state->status)) return; if (range->start > range->stop || range->start >= content.used) { // Content should be terminated, even if empty. if (complete == f_fss_complete_full_e || complete == f_fss_complete_full_trim_e || complete == f_fss_complete_end_e) { - status = f_string_dynamic_increase(state.step_large, destination); - if (F_status_is_error(status)) return status; + state->status = f_string_dynamic_increase(state->step_large, destination); + if (F_status_is_error(state->status)) return; destination->string[destination->used++] = f_fss_basic_close_s.string[0]; } - if (range->start > range->stop) return F_data_not_stop; + state->status = range->start > range->stop ? F_data_not_stop : F_data_not_eos; - return F_data_not_eos; + return; } const f_array_length_t destination_used = destination->used; for (; range->start <= range->stop && range->start < content.used; ++range->start) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) return F_status_set_error(F_interrupt); + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) return; } if (content.string[range->start] == f_fss_eol_s.string[0]) { destination->used = destination_used; + state->status = F_status_set_error(F_none_eol); - return F_status_set_error(F_none_eol); + return; } if (content.string[range->start] == f_fss_placeholder_s.string[0]) continue; - status = f_string_dynamic_increase(state.step_large, destination); + state->status = f_string_dynamic_increase(state->step_large, destination); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } destination->string[destination->used++] = content.string[range->start]; } // for if (complete == f_fss_complete_full_e || complete == f_fss_complete_full_trim_e || complete == f_fss_complete_end_e) { - status = f_string_dynamic_increase(state.step_large, destination); + state->status = f_string_dynamic_increase(state->step_large, destination); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } destination->string[destination->used++] = f_fss_basic_close_s.string[0]; } - if (range->start > range->stop) return F_none_stop; - - return F_none_eos; + if (range->start > range->stop) state->status = F_none_stop; + else state->status = F_none_eos; } #endif // _di_fl_fss_basic_content_write_ #ifndef _di_fl_fss_basic_object_read_ - f_status_t fl_fss_basic_object_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_object_t * const found, uint8_t * const quote, f_fss_delimits_t * const delimits) { + void fl_fss_basic_object_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_object_t * const found, uint8_t * const quote, f_fss_delimits_t * const delimits, f_state_t * const state) { #ifndef _di_level_1_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!found) return F_status_set_error(F_parameter); - if (!delimits) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !found || !delimits) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_1_parameter_checking_ const f_array_length_t delimits_used = delimits->used; - const f_status_t status = private_fl_fss_basic_read(buffer, F_true, state, range, found, quote, delimits); + private_fl_fss_basic_read(buffer, F_true, range, found, quote, delimits, state); - if (F_status_is_error(status) || status == F_fss_found_object_not || status == F_data_not || status == F_data_not_eos || status == F_data_not_stop) { + if (F_status_is_error(state->status) || state->status == F_fss_found_object_not || state->status == F_data_not || state->status == F_data_not_eos || state->status == F_data_not_stop) { delimits->used = delimits_used; } - - return status; } #endif // _di_fl_fss_basic_object_read_ #ifndef _di_fl_fss_basic_object_write_ - f_status_t fl_fss_basic_object_write(const f_string_static_t object, const uint8_t quote, const uint8_t complete, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination) { + void fl_fss_basic_object_write(const f_string_static_t object, const uint8_t quote, const uint8_t complete, f_string_range_t * const range, f_string_dynamic_t * const destination, f_state_t * const state) { #ifndef _di_level_1_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!destination) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !destination) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_1_parameter_checking_ const f_array_length_t destination_used = destination->used; - f_status_t status = private_fl_fss_basic_write(F_true, object, quote ? quote : f_fss_quote_double_s.string[0], state, range, destination); + private_fl_fss_basic_write(F_true, object, quote ? quote : f_fss_quote_double_s.string[0], range, destination, state); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } - if (status == F_data_not_stop || status == F_data_not_eos) { + if (state->status == F_data_not_stop || state->status == F_data_not_eos) { // Objects cannot be empty, so write a quote empty string. { - const f_status_t status_allocation = f_string_dynamic_increase_by(state.step_small + 2, destination); + const f_status_t status = f_string_dynamic_increase_by(state->step_small + 2, destination); - if (F_status_is_error(status_allocation)) { + if (F_status_is_error(status)) { destination->used = destination_used; + state->status = status; - return status_allocation; + return; } } @@ -190,38 +210,38 @@ extern "C" { } if (complete == f_fss_complete_partial_e || complete == f_fss_complete_partial_trim_e || complete == f_fss_complete_full_e || complete == f_fss_complete_full_trim_e || complete == f_fss_complete_trim_e) { - if (status == F_none_stop || status == F_none_eos || status == F_data_not_stop || status == F_data_not_eos) { - f_status_t status2 = F_none; + if (state->status == F_none_stop || state->status == F_none_eos || state->status == F_data_not_stop || state->status == F_data_not_eos) { + const f_status_t status_original = state->status; if (complete == f_fss_complete_full_trim_e || complete == f_fss_complete_trim_e) { - status2 = private_fl_fss_basic_write_object_trim(quote ? quote : f_fss_quote_double_s.string[0], destination_used, state, destination); + private_fl_fss_basic_write_object_trim(quote ? quote : f_fss_quote_double_s.string[0], destination_used, destination, state); - if (F_status_is_error(status2)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status2; + return; } } if (complete != f_fss_complete_trim_e) { - status2 = f_string_dynamic_increase(state.step_large, destination); + state->status = f_string_dynamic_increase(state->step_large, destination); - if (F_status_is_error(status2)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status2; + return; } destination->string[destination->used++] = f_fss_basic_open_s.string[0]; } + + state->status = status_original; } } - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; } - - return status; } #endif // _di_fl_fss_basic_object_write_ diff --git a/level_1/fl_fss/c/fss/basic.h b/level_1/fl_fss/c/fss/basic.h index 4c72f8c..5993898 100644 --- a/level_1/fl_fss/c/fss/basic.h +++ b/level_1/fl_fss/c/fss/basic.h @@ -36,15 +36,6 @@ extern "C" { * * @param buffer * The buffer to read from. - * @param state - * A state for providing flags and handling interrupts during long running operations. - * There is no print_error(). - * There is no functions structure. - * There is no data structure passed to these functions. - * - * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. - * Error bit designates an error but must be passed along with F_interrupt. - * All other statuses are ignored. * @param range * The start/stop location within the buffer to be processed. * The start location will be updated as the buffer is being processed. @@ -54,6 +45,15 @@ extern "C" { * A set of all locations where a valid content was found. * @param delimits * A delimits array representing where delimits exist within the buffer. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * There is no print_error(). + * There is no functions structure. + * There is no data structure passed to these functions. + * + * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. + * Error bit designates an error but must be passed along with F_interrupt. + * All other statuses are ignored. * * @return * F_fss_found_content on success and content was found (start location is at end of content). @@ -79,7 +79,7 @@ extern "C" { * @see f_utf_buffer_increment() */ #ifndef _di_fl_fss_basic_content_read_ - extern f_status_t fl_fss_basic_content_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_content_t * const found, f_fss_delimits_t * const delimits); + extern void fl_fss_basic_content_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_content_t * const found, f_fss_delimits_t * const delimits, f_state_t * const state); #endif // _di_fl_fss_basic_content_read_ /** @@ -98,6 +98,10 @@ extern "C" { * If f_fss_complete_end_e, then the content followed by any appropriate "end" character designating the last content for some object, printing final newline, if applicable. * If f_fss_complete_partial_e, this will write any appropriate open and close aspects of this content, except for the final newline. * If f_fss_complete_full_e, this will write any appropriate open and close aspects of this content, including the final newline. + * @param range + * The start/stop location within the content string to write as an content. + * @param destination + * The buffer where the content is written to. * @param state * A state for providing flags and handling interrupts during long running operations. * There is no print_error(). @@ -106,11 +110,7 @@ extern "C" { * * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. * Error bit designates an error but must be passed along with F_interrupt. - * All other statuses are ignored. - * @param range - * The start/stop location within the content string to write as an content. - * @param destination - * The buffer where the content is written to. + * * @return * F_none on success. * F_none_eos on success after reaching the end of the buffer. @@ -131,7 +131,7 @@ extern "C" { * @see f_string_dynamic_increase_by() */ #ifndef _di_fl_fss_basic_content_write_ - extern f_status_t fl_fss_basic_content_write(const f_string_static_t content, const uint8_t complete, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination); + extern void fl_fss_basic_content_write(const f_string_static_t content, const uint8_t complete, f_string_range_t * const range, f_string_dynamic_t * const destination, f_state_t * const state); #endif // _di_fl_fss_basic_content_write_ /** @@ -141,15 +141,6 @@ extern "C" { * * @param buffer * The buffer to read from. - * @param state - * A state for providing flags and handling interrupts during long running operations. - * There is no print_error(). - * There is no functions structure. - * There is no data structure passed to these functions. - * - * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. - * Error bit designates an error but must be passed along with F_interrupt. - * All other statuses are ignored. * @param range * The start/stop location within the buffer to be processed. * The start location will be updated as the buffer is being processed. @@ -162,6 +153,15 @@ extern "C" { * Set pointer address to 0 to not use. * @param delimits * A delimits array representing where delimits exist within the buffer. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * There is no print_error(). + * There is no functions structure. + * There is no data structure passed to these functions. + * + * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. + * Error bit designates an error but must be passed along with F_interrupt. + * All other statuses are ignored. * * @return * F_fss_found_object on success and object was found (start location is at end of object). @@ -198,7 +198,7 @@ extern "C" { * @see f_utf_buffer_increment() */ #ifndef _di_fl_fss_basic_object_read_ - extern f_status_t fl_fss_basic_object_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_object_t * const found, uint8_t * const quote, f_fss_delimits_t * const delimits); + extern void fl_fss_basic_object_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_object_t * const found, uint8_t * const quote, f_fss_delimits_t * const delimits, f_state_t * const state); #endif // _di_fl_fss_basic_object_read_ /** @@ -221,6 +221,10 @@ extern "C" { * If f_fss_complete_full_trim_e, this will write any appropriate open and close aspects of this object, but will omit whitespace before and after the object (inside the quotes). * If f_fss_complete_partial_e, this will write any appropriate open and close aspects of this object. * If f_fss_complete_partial_trim, this will write any appropriate open and close aspects of this object, but will omit whitespace before and after the object (inside the quotes). + * @param range + * The start/stop location within the object string to write as an object. + * @param destination + * The buffer where the object is written to. * @param state * A state for providing flags and handling interrupts during long running operations. * There is no print_error(). @@ -230,10 +234,6 @@ extern "C" { * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. * Error bit designates an error but must be passed along with F_interrupt. * All other statuses are ignored. - * @param range - * The start/stop location within the object string to write as an object. - * @param destination - * The buffer where the object is written to. * * @return * F_none on success. @@ -259,7 +259,7 @@ extern "C" { * @see f_string_dynamic_increase_by() */ #ifndef _di_fl_fss_basic_object_write_ - extern f_status_t fl_fss_basic_object_write(const f_string_static_t object, const uint8_t quote, const uint8_t complete, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination); + extern void fl_fss_basic_object_write(const f_string_static_t object, const uint8_t quote, const uint8_t complete, f_string_range_t * const range, f_string_dynamic_t * const destination, f_state_t * const state); #endif // _di_fl_fss_basic_object_write_ #ifdef __cplusplus diff --git a/level_1/fl_fss/c/fss/basic_list.c b/level_1/fl_fss/c/fss/basic_list.c index a1f40b1..8246829 100644 --- a/level_1/fl_fss/c/fss/basic_list.c +++ b/level_1/fl_fss/c/fss/basic_list.c @@ -1,30 +1,46 @@ #include "basic_list.h" #include "../private-fss.h" -#include "macro.h" #ifdef __cplusplus extern "C" { #endif #ifndef _di_fl_fss_basic_list_content_read_ - f_status_t fl_fss_basic_list_content_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_content_t * const found, f_fss_delimits_t * const delimits, f_fss_comments_t * const comments) { + void fl_fss_basic_list_content_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_content_t * const found, f_fss_delimits_t * const delimits, f_fss_comments_t * const comments, f_state_t * const state) { #ifndef _di_level_1_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!found) return F_status_set_error(F_parameter); - if (!delimits) return F_status_set_error(F_parameter); - if (!comments) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !found || !delimits || !comments) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_1_parameter_checking_ const f_array_length_t delimits_used = delimits->used; const f_array_length_t comments_used = comments->used; - f_status_t status = f_fss_skip_past_delimit(state, buffer, range); - if (F_status_is_error(status)) return status; + f_fss_skip_past_delimit(buffer, range, state); + if (F_status_is_error(state->status)) return; + + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; + comments->used = comments_used; + + if (range->start >= buffer.used) { + found->array[found->used].stop = buffer.used - 1; + state->status = F_none_eos; + } + else { + found->array[found->used].stop = range->stop; + state->status = F_none_stop; + } - private_macro_fl_fss_content_with_comments_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, (*comments), comments_used, F_none_eos, F_none_stop); + return; + } - status = f_string_ranges_increase(state.step_small, found); - if (F_status_is_error(status)) return status; + state->status = f_string_ranges_increase(state->step_small, found); + if (F_status_is_error(state->status)) return; found->array[found->used].start = range->start; @@ -39,20 +55,15 @@ extern "C" { // Identify where the content ends. while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_eol_s.string[0]) { if (graph_first == 0x2) { - status = f_array_lengths_increase(state.step_small, delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase(state->step_small, delimits); + if (F_status_is_error(state->status)) break; delimits->array[delimits->used++] = comment_delimit; } @@ -70,14 +81,9 @@ extern "C" { for (++range->start; range->start <= range->stop && range->start < buffer.used; ++range->start) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_placeholder_s.string[0]) continue; @@ -94,25 +100,21 @@ extern "C" { while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_eol_s.string[0]) break; - status = f_fss_is_space(state, buffer, *range); - if (F_status_is_error(status)) break; + if (f_fss_is_space(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; - if (status == F_false) break; + break; + } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while if (range->start > range->stop || range->start >= buffer.used) break; @@ -124,12 +126,13 @@ extern "C" { if (slash_count % 2 == 0) { found->array[found->used++].stop = newline_last; range->start = newline_last + 1; + state->status = F_fss_found_content; - return F_fss_found_content; + return; } - status = f_array_lengths_increase_by((slash_count / 2) + 1, delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase_by((slash_count / 2) + 1, delimits); + if (F_status_is_error(state->status)) break; while (slash_count > 0) { @@ -141,15 +144,15 @@ extern "C" { --slash_count; } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) break; + if (F_status_is_error(state->status)) break; if (graph_first == 0x2) { - status = f_array_lengths_increase(state.step_small, delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase(state->step_small, delimits); + if (F_status_is_error(state->status)) break; delimits->array[delimits->used++] = comment_delimit; } @@ -173,51 +176,48 @@ extern "C" { while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_eol_s.string[0]) break; - status = f_fss_is_space(state, buffer, *range); - if (F_status_is_error(status)) break; + if (f_fss_is_space(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; - if (status == F_false) break; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; - } // while + break; + } - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; + } // while + if (F_status_is_error(state->status)) break; if (range->start > range->stop || range->start >= buffer.used) break; // Found a valid object, set stop point to last newline. if (buffer.string[range->start] == f_fss_eol_s.string[0]) { - if (newline_last == found->array[found->used].start && buffer.string[found->array[found->used].start] != f_fss_eol_s.string[0]) { range->start = newline_last; - return F_fss_found_content_not; - } - else { - range->start = newline_last + 1; - found->array[found->used++].stop = newline_last; + state->status = F_fss_found_content_not; + + return; } - return F_fss_found_content; + range->start = newline_last + 1; + found->array[found->used++].stop = newline_last; + state->status = F_fss_found_content; + + return; } if (buffer.string[range->start] == f_fss_eol_s.string[0]) { if (graph_first == 0x2) { - status = f_array_lengths_increase(state.step_small, delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase(state->step_small, delimits); + if (F_status_is_error(state->status)) break; delimits->array[delimits->used++] = comment_delimit; } @@ -232,11 +232,11 @@ extern "C" { if (graph_first == 0x1 && buffer.string[range->start] == f_fss_comment_s.string[0]) { start = newline_last + 1; - status = f_fss_seek_to_eol(state, buffer, range); - if (F_status_is_error(status)) break; + f_fss_seek_to_eol(buffer, range, state); + if (F_status_is_error(state->status)) break; - status = f_string_ranges_increase(state.step_small, comments); - if (F_status_is_error(status)) break; + state->status = f_string_ranges_increase(state->step_small, comments); + if (F_status_is_error(state->status)) break; if (range->start > range->stop || range->start >= buffer.used) { --range->start; @@ -252,69 +252,79 @@ extern "C" { } if (graph_first == 0x1) { - status = f_fss_is_space(state, buffer, *range); - if (F_status_is_error(status)) break; + if (f_fss_is_space(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; - if (status == F_false) { graph_first = 0x0; } } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { delimits->used = delimits_used; comments->used = comments_used; - return status; + return; } if (range->start >= buffer.used) { found->array[found->used].stop = buffer.used - 1; + state->status = F_none_eos; - return F_none_eos; + return; } if (range->start > range->stop) { found->array[found->used].stop = range->stop; + state->status = F_none_stop; - return F_none_stop; + return; } found->array[found->used++].stop = range->start - 1; - - return F_fss_found_content; + state->status = F_fss_found_content; } #endif // _di_fl_fss_basic_list_content_read_ #ifndef _di_fl_fss_basic_list_content_write_ - f_status_t fl_fss_basic_list_content_write(const f_string_static_t content, const uint8_t complete, const f_string_static_t * const prepend, f_state_t state, f_string_range_t *range, f_string_dynamic_t *destination) { + void fl_fss_basic_list_content_write(const f_string_static_t content, const uint8_t complete, const f_string_static_t * const prepend, f_string_range_t *range, f_string_dynamic_t *destination, f_state_t * const state) { #ifndef _di_level_1_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!destination) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !destination) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_1_parameter_checking_ - f_status_t status = f_fss_skip_past_delimit(state, content, range); - if (F_status_is_error(status)) return status; + f_fss_skip_past_delimit(content, range, state); + if (F_status_is_error(state->status)) return; - if (status == F_none_stop || status == F_none_eos) { + if (state->status == F_none_stop || state->status == F_none_eos) { if (complete == f_fss_complete_full_e || complete == f_fss_complete_full_trim_e || complete == f_fss_complete_end_e) { - const f_status_t status_allocation = f_string_dynamic_increase(state.step_large, destination); - if (F_status_is_error(status_allocation)) return status_allocation; + const f_status_t status = f_string_dynamic_increase(state->step_large, destination); + + if (F_status_is_error(status)) { + state->status = status; + + return; + } destination->string[destination->used++] = f_fss_basic_list_close_s.string[0]; } - if (status == F_none_stop) return F_data_not_stop; + state->status = state->status == F_none_stop ? F_data_not_stop : F_data_not_eos; - return F_data_not_eos; + return; } // Ensure that there is room for a slash delimit and possibly the end of content character. - status = f_string_dynamic_increase_by(state.step_small + 3, destination); - if (F_status_is_error(status)) return status; + state->status = f_string_dynamic_increase_by(state->step_small + 3, destination); + if (F_status_is_error(state->status)) return; const f_array_length_t destination_used = destination->used; @@ -330,22 +340,17 @@ extern "C" { while (range->start <= range->stop && range->start < content.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (content.string[range->start] == f_fss_slash_s.string[0] && !is_comment) { slash_count = 1; if (do_prepend) { - status = f_string_dynamic_append(*prepend, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_append(*prepend, destination); + if (F_status_is_error(state->status)) break; do_prepend = F_false; } @@ -355,25 +360,20 @@ extern "C" { for (++range->start; range->start <= range->stop && range->start < content.used; ++range->start) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - destination->used = destination_used; - - return F_status_set_error(F_interrupt); - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (content.string[range->start] == f_fss_placeholder_s.string[0]) continue; if (content.string[range->start] != f_fss_slash_s.string[0]) break; - status = f_string_dynamic_increase(state.step_large, destination); + state->status = f_string_dynamic_increase(state->step_large, destination); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } destination->string[destination->used++] = f_fss_slash_s.string[0]; @@ -383,14 +383,14 @@ extern "C" { if (content.string[range->start] == f_fss_basic_list_open_s.string[0]) { start = range->start++; - status = f_fss_skip_past_space(state, content, range); - if (F_status_is_error(status)) break; + f_fss_skip_past_space(content, range, state); + if (F_status_is_error(state->status)) break; if (content.string[range->start] == f_fss_eol_s.string[0] || range->start >= content.used || range->start > range->stop) { // Increase by total slashes + 1, along with the basic list open and possible newline. - status = f_string_dynamic_increase_by(slash_count + 3, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(slash_count + 3, destination); + if (F_status_is_error(state->status)) break; while (--slash_count) { destination->string[destination->used++] = f_fss_slash_s.string[0]; @@ -401,14 +401,14 @@ extern "C" { range->start = start + 1; - status = private_fl_fss_basic_list_write_add_until_end(content, state, range, destination); - if (F_status_is_error(status)) break; + private_fl_fss_basic_list_write_add_until_end(content, range, destination, state); + if (F_status_is_error(state->status)) break; continue; } - status = f_string_dynamic_increase(state.step_large, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase(state->step_large, destination); + if (F_status_is_error(state->status)) break; destination->string[destination->used++] = f_fss_basic_list_open_s.string[0]; range->start = start + 1; @@ -420,36 +420,36 @@ extern "C" { start = range->start++; if (do_prepend) { - status = f_string_dynamic_append(*prepend, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_append(*prepend, destination); + if (F_status_is_error(state->status)) break; do_prepend = F_false; } has_graph = F_true; - status = f_fss_skip_past_space(state, content, range); - if (F_status_is_error(status)) break; + f_fss_skip_past_space(content, range, state); + if (F_status_is_error(state->status)) break; if (content.string[range->start] == f_fss_eol_s.string[0] || range->start >= content.used || range->start > range->stop) { // Increase by slash and basic list open and possible newline. - status = f_string_dynamic_increase_by(state.step_small + 3, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(state->step_small + 3, destination); + if (F_status_is_error(state->status)) break; destination->string[destination->used++] = f_fss_slash_s.string[0]; destination->string[destination->used++] = f_fss_basic_list_open_s.string[0]; range->start = start + 1; - status = private_fl_fss_basic_list_write_add_until_end(content, state, range, destination); - if (F_status_is_error(status)) break; + private_fl_fss_basic_list_write_add_until_end(content, range, destination, state); + if (F_status_is_error(state->status)) break; continue; } - status = f_string_dynamic_increase(state.step_large, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase(state->step_large, destination); + if (F_status_is_error(state->status)) break; destination->string[destination->used++] = f_fss_basic_list_open_s.string[0]; range->start = start + 1; @@ -464,20 +464,18 @@ extern "C" { is_comment = F_false; } else { - status = f_fss_is_graph(state, content, *range); - - if (status == F_true) { - has_graph = F_true; + if (f_fss_is_graph(content, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; } - else if (F_status_is_error(status)) { - break; + else { + has_graph = F_true; } } if (content.string[range->start] != f_fss_placeholder_s.string[0]) { if (do_prepend) { - status = f_string_dynamic_append(*prepend, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_append(*prepend, destination); + if (F_status_is_error(state->status)) break; do_prepend = F_false; } @@ -488,31 +486,31 @@ extern "C" { width = macro_f_utf_byte_width(content.string[range->start]); - status = f_string_dynamic_increase_by(width, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(width, destination); + if (F_status_is_error(state->status)) break; for (i = 0; i < width; ++i) { destination->string[destination->used++] = content.string[range->start + i]; } // for } - status = f_utf_buffer_increment(content, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(content, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } if (complete == f_fss_complete_full_e || complete == f_fss_complete_full_trim_e || complete == f_fss_complete_end_e) { - status = f_string_dynamic_increase(state.step_large, destination); + state->status = f_string_dynamic_increase(state->step_large, destination); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } // Check to see if a newline exists, at the end. @@ -527,36 +525,55 @@ extern "C" { } } - if (range->start > range->stop) return F_none_stop; - if (range->start >= content.used) return F_none_eos; - - return F_none; + if (range->start > range->stop) { + state->status = F_none_stop; + } + else if (range->start >= content.used) { + state->status = F_none_eos; + } + else { + state->status = F_none; + } } #endif // _di_fl_fss_basic_list_content_write_ #ifndef _di_fl_fss_basic_list_object_read_ - f_status_t fl_fss_basic_list_object_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_object_t * const found, f_fss_delimits_t * const delimits) { + void fl_fss_basic_list_object_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_object_t * const found, f_fss_delimits_t * const delimits, f_state_t * const state) { #ifndef _di_level_1_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!found) return F_status_set_error(F_parameter); - if (!delimits) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !found || !delimits) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_1_parameter_checking_ const f_array_length_t delimits_used = delimits->used; - f_status_t status = f_fss_skip_past_space(state, buffer, range); - if (F_status_is_error(status)) return status; + f_fss_skip_past_space(buffer, range, state); + if (F_status_is_error(state->status)) return; - if (status == F_none_eol) { + if (state->status == F_none_eol) { // Move the start position to after the EOL. ++range->start; + state->status = F_fss_found_object_not; + + return; + } + + if (state->status == F_none_eos) { + state->status = F_data_not_eos; - return F_fss_found_object_not; + return; } - if (status == F_none_eos) return F_data_not_eos; - if (status == F_none_stop) return F_data_not_stop; + if (state->status == F_none_stop) { + state->status = F_data_not_stop; + + return; + } // Begin the search. found->start = range->start; @@ -564,16 +581,26 @@ extern "C" { // Ignore all comment lines. if (buffer.string[range->start] == f_fss_comment_s.string[0]) { - status = f_fss_seek_to_eol(state, buffer, range); - if (F_status_is_error(status)) return status; + f_fss_seek_to_eol(buffer, range, state); + if (F_status_is_error(state->status)) return; + + if (state->status == F_none_eos) { + state->status = F_data_not_eos; + + return; + } - if (status == F_none_eos) return F_data_not_eos; - if (status == F_none_stop) return F_data_not_stop; + if (state->status == F_none_stop) { + state->status = F_data_not_stop; + + return; + } // Move the start position to after the EOL. ++range->start; + state->status = F_fss_found_object_not; - return F_fss_found_object_not; + return; } f_array_length_t slash_first = 0; @@ -586,14 +613,9 @@ extern "C" { // Identify where the object ends. while (range->start <= range->stop && range->start < buffer.used && buffer.string[range->start] != f_fss_eol_s.string[0]) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_slash_s.string[0]) { @@ -602,66 +624,80 @@ extern "C" { for (++range->start; range->start <= range->stop && range->start < buffer.used; ++range->start) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } - if (buffer.string[range->start] == f_fss_placeholder_s.string[0]) { - continue; - } else if (buffer.string[range->start] != f_fss_slash_s.string[0]) { - break; - } + if (buffer.string[range->start] == f_fss_placeholder_s.string[0]) continue; + else if (buffer.string[range->start] != f_fss_slash_s.string[0]) break; ++slash_count; } // for - private_macro_fl_fss_object_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, F_data_not_eos, F_data_not_stop); + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; + + if (range->start >= buffer.used) { + found->stop = buffer.used - 1; + state->status = F_data_not_eos; + } + else { + found->stop = range->stop; + state->status = F_data_not_stop; + } + + return; + } if (buffer.string[range->start] == f_fss_basic_list_open_s.string[0]) { graph_first = F_false; stop = range->start - 1; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) return status; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) return; while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_eol_s.string[0]) break; - status = f_fss_is_space(state, buffer, *range); - if (F_status_is_error(status)) break; + if (f_fss_is_space(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; - if (status == F_false) break; + break; + } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - private_macro_fl_fss_object_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, F_data_not_eos, F_data_not_stop); + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; + + if (range->start >= buffer.used) { + found->stop = buffer.used - 1; + state->status = F_data_not_eos; + } + else { + found->stop = range->stop; + state->status = F_data_not_stop; + } + + return; + } if (buffer.string[range->start] == f_fss_eol_s.string[0]) { start = range->start; range->start = slash_first; - status = f_array_lengths_increase_by((slash_count / 2) + 1, delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase_by((slash_count / 2) + 1, delimits); + if (F_status_is_error(state->status)) break; if (slash_count % 2 == 0) { while (slash_count > 0) { @@ -675,32 +711,34 @@ extern "C" { --slash_count; } - status = f_utf_buffer_increment(buffer, range, 1); + state->status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { delimits->used = delimits_used; - return status; + return; } } // while found->stop = stop; range->start = start + 1; + state->status = F_fss_found_object; - return F_fss_found_object; + return; } range->start = start + 1; + state->status = F_fss_found_object_not; - return F_fss_found_object_not; + return; } } else if (graph_first && buffer.string[range->start] == f_fss_comment_s.string[0]) { graph_first = F_false; // Comments may only have white space before the '#', therefore only the first slash needs to be delimited. - status = f_array_lengths_increase(state.step_small, delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase(state->step_small, delimits); + if (F_status_is_error(state->status)) break; delimits->array[delimits->used++] = slash_first; ++range->start; @@ -716,91 +754,119 @@ extern "C" { graph_first = F_false; stop = range->start - 1; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_eol_s.string[0]) break; - status = f_fss_is_space(state, buffer, *range); - if (F_status_is_error(status)) break; + if (f_fss_is_space(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; - if (status == F_false) break; + break; + } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - private_macro_fl_fss_object_return_on_overflow_delimited((buffer), (*range), (*found), F_none_eos, F_none_stop); + if (range->start >= buffer.used) { + found->stop = buffer.used - 1; + state->status = F_none_eos; + + return; + } + + if (range->start > range->stop) { + found->stop = range->stop; + state->status = F_none_stop; + + return; + } if (buffer.string[range->start] == f_fss_eol_s.string[0]) { found->stop = stop; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; - return F_fss_found_object; + state->status = F_fss_found_object; + + return; } continue; } else if (graph_first) { - status = f_fss_is_space(state, buffer, *range); - if (F_status_is_error(status)) break; + if (f_fss_is_space(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; - if (status == F_false) { graph_first = F_false; } } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { delimits->used = delimits_used; - return status; + return; + } + + if (state->status == F_none_eos) { + state->status = F_data_not_eos; + + return; } - if (status == F_none_eos) return F_data_not_eos; - if (status == F_none_stop) return F_data_not_stop; + if (state->status == F_none_stop) { + state->status = F_data_not_stop; - // seek to the end of the line when no valid object is found. - status = f_fss_seek_to_eol(state, buffer, range); + return; + } - // move the start position to after the EOL. - ++range->start; + // Seek to the end of the line when no valid object is found. + f_fss_seek_to_eol(buffer, range, state); - return F_fss_found_object_not; + // Move the start position to after the EOL. + ++range->start; + state->status = F_fss_found_object_not; } #endif // _di_fl_fss_basic_list_object_read_ #ifndef _di_fl_fss_basic_list_object_write_ - f_status_t fl_fss_basic_list_object_write(const f_string_static_t object, const uint8_t complete, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination) { + void fl_fss_basic_list_object_write(const f_string_static_t object, const uint8_t complete, f_string_range_t * const range, f_string_dynamic_t * const destination, f_state_t * const state) { #ifndef _di_level_1_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !destination) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_1_parameter_checking_ - f_status_t status = f_fss_skip_past_delimit(state, object, range); - if (F_status_is_error(status)) return status; + f_fss_skip_past_delimit(object, range, state); + if (F_status_is_error(state->status)) return; - if (status == F_none_stop || status == F_none_eos) { + if (state->status == F_none_stop || state->status == F_none_eos) { if (complete == f_fss_complete_partial_e || complete == f_fss_complete_partial_trim_e || complete == f_fss_complete_full_e || complete == f_fss_complete_full_trim_e) { { - const f_status_t status_allocation = f_string_dynamic_increase_by(state.step_small + 2, destination); - if (F_status_is_error(status_allocation)) return status_allocation; + const f_status_t status = f_string_dynamic_increase_by(state->step_small + 2, destination); + + if (F_status_is_error(status)) { + state->status = status; + + return; + } } destination->string[destination->used++] = f_fss_basic_list_open_s.string[0]; @@ -810,9 +876,9 @@ extern "C" { } } - if (status == F_none_stop) return F_data_not_stop; + state->status = state->status == F_none_stop ? F_data_not_stop : F_data_not_eos; - return F_data_not_eos; + return; } const f_array_length_t destination_used = destination->used; @@ -825,54 +891,51 @@ extern "C" { // Find the first graph character. while (range->start <= range->stop && range->start < object.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (object.string[range->start] == f_fss_comment_s.string[0]) { // When a comment is found, escape it. - status = f_string_dynamic_increase(state.step_large, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase(state->step_large, destination); + if (F_status_is_error(state->status)) break; destination->string[destination->used++] = f_fss_slash_s.string[0]; break; } - status = f_fss_is_graph(state, object, *range); - if (F_status_is_error(status)) break; - - if (status == F_true) break; + if (f_fss_is_graph(object, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; + } + else { + break; + } // Objects will not have leading white spaces, but having this does not result in an invalid object, so just write the provided spaces. if (object.string[range->start] != f_fss_placeholder_s.string[0]) { if (object.string[range->start] == f_fss_eol_s.string[0]) { - status = F_status_set_error(F_none_eol); + state->status = F_status_set_error(F_none_eol); break; } - status = f_fss_is_space(state, object, *range); - if (F_status_is_error(status)) break; - - if (status == F_true) { + if (f_fss_is_space(object, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; + } + else { if (object.string[range->start] == f_fss_eol_s.string[0]) { - status = F_status_set_error(F_none_eol); + state->status = F_status_set_error(F_none_eol); break; } width = macro_f_utf_byte_width(object.string[range->start]); - status = f_string_dynamic_increase_by(width, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(width, destination); + if (F_status_is_error(state->status)) break; for (i = 0; i < width; ++i) { destination->string[destination->used++] = object.string[range->start + i]; @@ -880,26 +943,21 @@ extern "C" { } } - status = f_utf_buffer_increment(object, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(object, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } while (range->start <= range->stop && range->start < object.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (object.string[range->start] == f_fss_slash_s.string[0]) { @@ -907,14 +965,9 @@ extern "C" { for (++range->start; range->start <= range->stop && range->start < object.used; ++range->start) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (object.string[range->start] == f_fss_placeholder_s.string[0]) continue; @@ -923,7 +976,7 @@ extern "C" { ++slash_count; } // for - if (F_status_is_error(status)) break; + if (F_status_is_error(state->status)) break; if (range->start > range->stop || range->start >= object.used) { @@ -931,8 +984,8 @@ extern "C" { slash_count *= 2; } - status = f_string_dynamic_increase_by(slash_count, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(slash_count, destination); + if (F_status_is_error(state->status)) break; while (--slash_count) { destination->string[destination->used++] = f_fss_slash_s.string[0]; @@ -943,49 +996,49 @@ extern "C" { if (object.string[range->start] != f_fss_placeholder_s.string[0]) { if (object.string[range->start] == f_fss_eol_s.string[0]) { - status = F_status_set_error(F_none_eol); + state->status = F_status_set_error(F_none_eol); break; } width = macro_f_utf_byte_width(object.string[range->start]); - status = f_string_dynamic_increase_by(width, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(width, destination); + if (F_status_is_error(state->status)) break; for (i = 0; i < width; ++i) { destination->string[destination->used++] = object.string[range->start + i]; } // for } - status = f_utf_buffer_increment(object, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(object, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } if (complete == f_fss_complete_partial_e || complete == f_fss_complete_partial_trim_e || complete == f_fss_complete_full_e || complete == f_fss_complete_full_trim_e || complete == f_fss_complete_trim_e) { if (complete == f_fss_complete_full_trim_e || complete == f_fss_complete_trim_e) { - status = private_fl_fss_basic_list_write_object_trim(destination_used, state, destination); + private_fl_fss_basic_list_write_object_trim(destination_used, destination, state); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } } if (complete != f_fss_complete_trim_e) { - status = f_string_dynamic_increase(state.step_small + 2, destination); + state->status = f_string_dynamic_increase(state->step_small + 2, destination); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } destination->string[destination->used++] = f_fss_basic_list_open_s.string[0]; @@ -996,10 +1049,15 @@ extern "C" { } } - if (range->start > range->stop) return F_none_stop; - if (range->start >= object.used) return F_none_eos; - - return F_none; + if (range->start > range->stop) { + state->status = F_none_stop; + } + else if (range->start >= object.used) { + state->status = F_none_eos; + } + else { + state->status = F_none; + } } #endif // _di_fl_fss_basic_list_object_write_ diff --git a/level_1/fl_fss/c/fss/basic_list.h b/level_1/fl_fss/c/fss/basic_list.h index 2b98541..0b62d4d 100644 --- a/level_1/fl_fss/c/fss/basic_list.h +++ b/level_1/fl_fss/c/fss/basic_list.h @@ -37,15 +37,6 @@ extern "C" { * * @param buffer * The buffer to read from. - * @param state - * A state for providing flags and handling interrupts during long running operations. - * There is no print_error(). - * There is no functions structure. - * There is no data structure passed to these functions. - * - * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. - * Error bit designates an error but must be passed along with F_interrupt. - * All other statuses are ignored. * @param range * The start/stop location within the buffer to be processed. * The start location will be updated as the buffer is being processed. @@ -59,6 +50,15 @@ extern "C" { * An array of ranges representing where comments are found within any valid content. * This only stores comments found within valid content only. * The comment range will include the trailing newline. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * There is no print_error(). + * There is no functions structure. + * There is no data structure passed to these functions. + * + * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. + * Error bit designates an error but must be passed along with F_interrupt. + * All other statuses are ignored. * * @return * F_fss_found_content on success and content was found (start location is at end of content). @@ -90,7 +90,7 @@ extern "C" { * @see f_utf_buffer_increment() */ #ifndef _di_fl_fss_basic_list_content_read_ - extern f_status_t fl_fss_basic_list_content_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_content_t * const found, f_fss_delimits_t * const delimits, f_fss_comments_t * const comments); + extern void fl_fss_basic_list_content_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_content_t * const found, f_fss_delimits_t * const delimits, f_fss_comments_t * const comments, f_state_t * const state); #endif // _di_fl_fss_basic_list_content_read_ /** @@ -113,6 +113,10 @@ extern "C" { * A string of whitespace to prepend at the start of each line. * This should only be whitespace, anything else could produce invalid content. * Set the pointer address to 0 to disable. + * @param range + * The start/stop location within the content string to write as an content. + * @param destination + * The buffer where the content is written to. * @param state * A state for providing flags and handling interrupts during long running operations. * There is no print_error(). @@ -122,10 +126,6 @@ extern "C" { * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. * Error bit designates an error but must be passed along with F_interrupt. * All other statuses are ignored. - * @param range - * The start/stop location within the content string to write as an content. - * @param destination - * The buffer where the content is written to. * * @return * F_none on success. @@ -155,7 +155,7 @@ extern "C" { * @see f_utf_buffer_increment() */ #ifndef _di_fl_fss_basic_list_content_write_ - extern f_status_t fl_fss_basic_list_content_write(const f_string_static_t content, const uint8_t complete, const f_string_static_t * const prepend, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination); + extern void fl_fss_basic_list_content_write(const f_string_static_t content, const uint8_t complete, const f_string_static_t * const prepend, f_string_range_t * const range, f_string_dynamic_t * const destination, f_state_t * const state); #endif // _di_fl_fss_basic_list_content_write_ /** @@ -165,15 +165,6 @@ extern "C" { * * @param buffer * The buffer to read from. - * @param state - * A state for providing flags and handling interrupts during long running operations. - * There is no print_error(). - * There is no functions structure. - * There is no data structure passed to these functions. - * - * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. - * Error bit designates an error but must be passed along with F_interrupt. - * All other statuses are ignored. * @param range * The start/stop location within the buffer to be processed. * The start location will be updated as the buffer is being processed. @@ -183,6 +174,15 @@ extern "C" { * A location where a valid object was found. * @param delimits * A delimits array representing where delimits exist within the buffer. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * There is no print_error(). + * There is no functions structure. + * There is no data structure passed to these functions. + * + * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. + * Error bit designates an error but must be passed along with F_interrupt. + * All other statuses are ignored. * * @return * F_fss_found_object on success and object was found (start location is at end of object). @@ -216,7 +216,7 @@ extern "C" { * @see f_utf_buffer_increment() */ #ifndef _di_fl_fss_basic_list_object_read_ - extern f_status_t fl_fss_basic_list_object_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_object_t * const found, f_fss_delimits_t * const delimits); + extern void fl_fss_basic_list_object_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_object_t * const found, f_fss_delimits_t * const delimits, f_state_t * const state); #endif // _di_fl_fss_basic_list_object_read_ /** @@ -236,6 +236,10 @@ extern "C" { * If f_fss_complete_full_trim_e, this will write any appropriate open and close aspects of this object, but will omit whitespace before and after the object. * If f_fss_complete_partial_e, this will write any appropriate open and close aspects of this object. * If f_fss_complete_partial_tim, this will write any appropriate open and close aspects of this object, but will omit whitespace before and after the object. + * @param range + * The start/stop location within the object string to write as an object. + * @param destination + * The buffer where the object is written to. * @param state * A state for providing flags and handling interrupts during long running operations. * There is no print_error(). @@ -245,10 +249,6 @@ extern "C" { * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. * Error bit designates an error but must be passed along with F_interrupt. * All other statuses are ignored. - * @param range - * The start/stop location within the object string to write as an object. - * @param destination - * The buffer where the object is written to. * * @return * F_none on success. @@ -276,7 +276,7 @@ extern "C" { * @see f_utf_buffer_increment() */ #ifndef _di_fl_fss_basic_list_object_write_ - extern f_status_t fl_fss_basic_list_object_write(const f_string_static_t object, const uint8_t complete, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination); + extern void fl_fss_basic_list_object_write(const f_string_static_t object, const uint8_t complete, f_string_range_t * const range, f_string_dynamic_t * const destination, f_state_t * const state); #endif // _di_fl_fss_basic_list_object_write_ #ifdef __cplusplus diff --git a/level_1/fl_fss/c/fss/embedded_list.c b/level_1/fl_fss/c/fss/embedded_list.c index eb69e16..5705908 100644 --- a/level_1/fl_fss/c/fss/embedded_list.c +++ b/level_1/fl_fss/c/fss/embedded_list.c @@ -1,54 +1,53 @@ #include "embedded_list.h" #include "../private-fss.h" -#include "macro.h" #ifdef __cplusplus extern "C" { #endif #ifndef _di_fl_fss_embedded_list_content_read_ - f_status_t fl_fss_embedded_list_content_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_nest_t * const found, f_fss_delimits_t * const delimits, f_fss_comments_t * const comments) { + void fl_fss_embedded_list_content_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_nest_t * const found, f_fss_delimits_t * const delimits, f_fss_comments_t * const comments, f_state_t * const state) { #ifndef _di_level_1_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!found) return F_status_set_error(F_parameter); - if (!delimits) return F_status_set_error(F_parameter); - if (!comments) return F_status_set_error(F_parameter); - #endif // _di_level_1_parameter_checking_ + if (!state) return; - f_status_t status = f_fss_skip_past_delimit(state, buffer, range); - if (F_status_is_error(status)) return status; + if (!range || !found || !delimits || !comments) { + state->status = F_status_set_error(F_parameter); - if (status == F_none_eos || status == F_none_stop) { - return status; - } + return; + } + #endif // _di_level_1_parameter_checking_ - status = f_fss_nest_increase(state.step_small, found); - if (F_status_is_error(status)) return status; + f_fss_skip_past_delimit(buffer, range, state); + if (F_status_is_error(state->status)) return; + if (state->status == F_none_eos || state->status == F_none_stop) return; + + state->status = f_fss_nest_increase(state->step_small, found); + if (F_status_is_error(state->status)) return; f_array_lengths_t positions_start = f_array_lengths_t_initialize; - status = f_array_lengths_increase(state.step_small, &positions_start); - if (F_status_is_error(status)) return status; + state->status = f_array_lengths_increase(state->step_small, &positions_start); + if (F_status_is_error(state->status)) return; f_fss_objects_t objects = f_fss_objects_t_initialize; - status = f_string_ranges_increase(state.step_small, &objects); + state->status = f_string_ranges_increase(state->step_small, &objects); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { f_array_lengths_resize(0, &positions_start); - return status; + return; } f_array_lengths_t slashes = f_array_lengths_t_initialize; - status = f_array_lengths_increase(state.step_small, &slashes); + state->status = f_array_lengths_increase(state->step_small, &slashes); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { f_array_lengths_resize(0, &positions_start); f_string_ranges_resize(0, &objects); - return status; + return; } const f_array_length_t delimits_used = delimits->used; @@ -82,20 +81,15 @@ extern "C" { while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_eol_s.string[0]) { if (graph_first == 0x2) { - status = f_array_lengths_increase(state.step_small, delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase(state->step_small, delimits); + if (F_status_is_error(state->status)) break; delimits->array[delimits->used++] = comment_delimit; } @@ -105,10 +99,29 @@ extern "C" { graph_first = 0x1; if (depth) { - private_macro_fl_fss_nest_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, (*comments), comments_used, positions_start, objects, slashes, F_end_not_nest_eos, F_end_not_nest_stop); + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; + comments->used = comments_used; + + f_array_lengths_resize(0, &positions_start); + f_string_ranges_resize(0, &objects); + f_array_lengths_resize(0, &slashes); + + state->status = (range->start >= buffer.used) ? F_end_not_nest_eos : F_end_not_nest_stop; + + return; + } } else { - private_macro_fl_fss_nest_return_on_overflow_delimited((buffer), (*range), (*found), positions_start, objects, slashes, F_none_eos, F_none_stop); + if (range->start >= buffer.used || range->start > range->stop) { + f_array_lengths_resize(0, &positions_start); + f_string_ranges_resize(0, &objects); + f_array_lengths_resize(0, &slashes); + + state->status = (range->start >= buffer.used) ? F_none_eos : F_none_stop; + + return; + } } line_start = range->start; @@ -125,14 +138,9 @@ extern "C" { while (range->start <= range->stop && range->start < buffer.used && (buffer.string[range->start] == f_fss_placeholder_s.string[0] || buffer.string[range->start] == f_fss_slash_s.string[0])) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } position_previous = range->start; @@ -142,18 +150,40 @@ extern "C" { ++slashes.array[depth]; } else { - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } } // while - if (F_status_is_error(status)) break; + if (F_status_is_error(state->status)) break; if (depth) { - private_macro_fl_fss_nest_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, (*comments), comments_used, positions_start, objects, slashes, F_end_not_nest_eos, F_end_not_nest_stop); + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; + comments->used = comments_used; + + f_array_lengths_resize(0, &positions_start); + f_string_ranges_resize(0, &objects); + f_array_lengths_resize(0, &slashes); + + state->status = (range->start >= buffer.used) ? F_end_not_nest_eos : F_end_not_nest_stop; + + return; + } } else { - private_macro_fl_fss_nest_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, (*comments), comments_used, positions_start, objects, slashes, F_data_not_eos, F_data_not_stop); + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; + comments->used = comments_used; + + f_array_lengths_resize(0, &positions_start); + f_string_ranges_resize(0, &objects); + f_array_lengths_resize(0, &slashes); + + state->status = (range->start >= buffer.used) ? F_data_not_eos : F_data_not_stop; + + return; + } } // All slashes for an open are delimited (because it could represent a slash in the object name). @@ -163,8 +193,8 @@ extern "C" { // When slash is odd and a (delimited) valid open/close is found, then save delimited positions and continue. if (buffer.string[range->start] == f_fss_eol_s.string[0]) { if (graph_first == 0x2) { - status = f_array_lengths_increase(state.step_small, delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase(state->step_small, delimits); + if (F_status_is_error(state->status)) break; delimits->array[delimits->used++] = comment_delimit; } @@ -187,20 +217,15 @@ extern "C" { while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_eol_s.string[0]) { if (graph_first == 0x2) { - status = f_array_lengths_increase(state.step_small, delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase(state->step_small, delimits); + if (F_status_is_error(state->status)) break; delimits->array[delimits->used++] = comment_delimit; } @@ -213,25 +238,48 @@ extern "C" { } if (buffer.string[range->start] != f_fss_placeholder_s.string[0]) { - status = f_fss_is_space(state, buffer, *range); - if (F_status_is_error(status)) break; + if (f_fss_is_space(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; - if (status == F_false) break; + break; + } } position_previous = range->start; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) break; + if (F_status_is_error(state->status)) break; if (depth) { - private_macro_fl_fss_nest_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, (*comments), comments_used, positions_start, objects, slashes, F_end_not_nest_eos, F_end_not_nest_stop); + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; + comments->used = comments_used; + + f_array_lengths_resize(0, &positions_start); + f_string_ranges_resize(0, &objects); + f_array_lengths_resize(0, &slashes); + + state->status = (range->start >= buffer.used) ? F_end_not_nest_eos : F_end_not_nest_stop; + + return; + } } else { - private_macro_fl_fss_nest_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, (*comments), comments_used, positions_start, objects, slashes, F_data_not_eos, F_data_not_stop); + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; + comments->used = comments_used; + + f_array_lengths_resize(0, &positions_start); + f_string_ranges_resize(0, &objects); + f_array_lengths_resize(0, &slashes); + + state->status = (range->start >= buffer.used) ? F_data_not_eos : F_data_not_stop; + + return; + } } // This is a valid object open/close that has been delimited, save the slash delimit positions. @@ -249,8 +297,8 @@ extern "C" { range->start = slash_first; - status = f_array_lengths_increase_by((slashes.array[depth] / 2) + 1, delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase_by((slashes.array[depth] / 2) + 1, delimits); + if (F_status_is_error(state->status)) break; // Apply slash delimits, only slashes and placeholders should be present. while (slashes.array[depth]) { @@ -267,19 +315,19 @@ extern "C" { position_previous = range->start++; } // while - if (F_status_is_error(status)) break; + if (F_status_is_error(state->status)) break; // When slashes are even, the object is valid and needs to be processed. if (is_object) { if (++depth > positions_start.size) { - status = f_array_lengths_increase(state.step_small, &positions_start); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase(state->step_small, &positions_start); + if (F_status_is_error(state->status)) break; - status = f_string_ranges_increase(state.step_small, &objects); - if (F_status_is_error(status)) break; + state->status = f_string_ranges_increase(state->step_small, &objects); + if (F_status_is_error(state->status)) break; - status = f_array_lengths_increase(state.step_small, &slashes); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase(state->step_small, &slashes); + if (F_status_is_error(state->status)) break; } if (positions_start.used < depth) { @@ -296,8 +344,8 @@ extern "C" { } } else { - status = f_array_lengths_increase(state.step_small, delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase(state->step_small, delimits); + if (F_status_is_error(state->status)) break; delimits->array[delimits->used++] = slash_last; } @@ -318,57 +366,75 @@ extern "C" { before_list_open = position_previous; position_previous = range->start; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_eol_s.string[0]) break; if (buffer.string[range->start] != f_fss_placeholder_s.string[0]) { - status = f_fss_is_space(state, buffer, *range); - if (F_status_is_error(status)) break; + if (f_fss_is_space(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; - if (status == F_false) break; + break; + } } position_previous = range->start; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) break; + if (F_status_is_error(state->status)) break; if (depth) { - private_macro_fl_fss_nest_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, (*comments), comments_used, positions_start, objects, slashes, F_end_not_nest_eos, F_end_not_nest_stop); + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; + comments->used = comments_used; + + f_array_lengths_resize(0, &positions_start); + f_string_ranges_resize(0, &objects); + f_array_lengths_resize(0, &slashes); + + state->status = (range->start >= buffer.used) ? F_end_not_nest_eos : F_end_not_nest_stop; + + return; + } } else { - private_macro_fl_fss_nest_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, (*comments), comments_used, positions_start, objects, slashes, F_data_not_eos, F_data_not_stop); + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; + comments->used = comments_used; + + f_array_lengths_resize(0, &positions_start); + f_string_ranges_resize(0, &objects); + f_array_lengths_resize(0, &slashes); + + state->status = (range->start >= buffer.used) ? F_data_not_eos : F_data_not_stop; + + return; + } } if (buffer.string[range->start] == f_fss_eol_s.string[0]) { ++depth; if (depth >= positions_start.size) { - status = f_array_lengths_increase(state.step_small, &positions_start); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase(state->step_small, &positions_start); + if (F_status_is_error(state->status)) break; - status = f_string_ranges_increase(state.step_small, &objects); - if (F_status_is_error(status)) break; + state->status = f_string_ranges_increase(state->step_small, &objects); + if (F_status_is_error(state->status)) break; - status = f_array_lengths_increase(state.step_small, &slashes); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase(state->step_small, &slashes); + if (F_status_is_error(state->status)) break; } if (positions_start.used <= depth) { @@ -384,8 +450,8 @@ extern "C" { slashes.array[depth] = 0; if (graph_first == 0x2) { - status = f_array_lengths_increase(state.step_small, delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase(state->step_small, delimits); + if (F_status_is_error(state->status)) break; delimits->array[delimits->used++] = comment_delimit; } @@ -397,12 +463,12 @@ extern "C" { else { // No valid object close found, seek until EOL. - status = f_fss_seek_to_eol(state, buffer, range); - if (F_status_is_error(status)) break; + f_fss_seek_to_eol(buffer, range, state); + if (F_status_is_error(state->status)) break; if (graph_first == 0x2) { - status = f_array_lengths_increase(state.step_small, delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase(state->step_small, delimits); + if (F_status_is_error(state->status)) break; delimits->array[delimits->used++] = comment_delimit; } @@ -413,14 +479,9 @@ extern "C" { while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_eol_s.string[0]) { @@ -432,17 +493,39 @@ extern "C" { position_previous = range->start; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) break; + if (F_status_is_error(state->status)) break; if (depth) { - private_macro_fl_fss_nest_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, (*comments), comments_used, positions_start, objects, slashes, F_end_not_nest_eos, F_end_not_nest_stop); + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; + comments->used = comments_used; + + f_array_lengths_resize(0, &positions_start); + f_string_ranges_resize(0, &objects); + f_array_lengths_resize(0, &slashes); + + state->status = (range->start >= buffer.used) ? F_end_not_nest_eos : F_end_not_nest_stop; + + return; + } } else { - private_macro_fl_fss_nest_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, (*comments), comments_used, positions_start, objects, slashes, F_data_not_eos, F_data_not_stop); + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; + comments->used = comments_used; + + f_array_lengths_resize(0, &positions_start); + f_string_ranges_resize(0, &objects); + f_array_lengths_resize(0, &slashes); + + state->status = (range->start >= buffer.used) ? F_data_not_eos : F_data_not_stop; + + return; + } } } } @@ -451,54 +534,72 @@ extern "C" { while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } position_previous = range->start; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; if (buffer.string[range->start] == f_fss_eol_s.string[0]) break; if (buffer.string[range->start] != f_fss_placeholder_s.string[0]) { - status = f_fss_is_space(state, buffer, *range); - if (F_status_is_error(status)) break; + if (f_fss_is_space(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; - if (status == F_false) break; + break; + } } } // while - if (F_status_is_error(status)) break; + if (F_status_is_error(state->status)) break; if (depth) { - private_macro_fl_fss_nest_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, (*comments), comments_used, positions_start, objects, slashes, F_end_not_nest_eos, F_end_not_nest_stop); + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; + comments->used = comments_used; + + f_array_lengths_resize(0, &positions_start); + f_string_ranges_resize(0, &objects); + f_array_lengths_resize(0, &slashes); + + state->status = (range->start >= buffer.used) ? F_end_not_nest_eos : F_end_not_nest_stop; + + return; + } } else { - private_macro_fl_fss_nest_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, (*comments), comments_used, positions_start, objects, slashes, F_data_not_eos, F_data_not_stop); + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; + comments->used = comments_used; + + f_array_lengths_resize(0, &positions_start); + f_string_ranges_resize(0, &objects); + f_array_lengths_resize(0, &slashes); + + state->status = (range->start >= buffer.used) ? F_data_not_eos : F_data_not_stop; + + return; + } } if (buffer.string[range->start] == f_fss_eol_s.string[0]) { - status = f_fss_nest_increase(state.step_small, found); - if (F_status_is_error(status)) break; + state->status = f_fss_nest_increase(state->step_small, found); + if (F_status_is_error(state->status)) break; if (found->depth[depth].used == found->depth[depth].size) { - status = f_fss_items_increase(state.step_small, &found->depth[depth]); - if (F_status_is_error(status)) break; + state->status = f_fss_items_increase(state->step_small, &found->depth[depth]); + if (F_status_is_error(state->status)) break; } position = found->depth[depth].used; if (found->depth[depth].array[position].content.size != 1) { - status = f_string_ranges_resize(1, &found->depth[depth].array[position].content); - if (F_status_is_error(status)) break; + state->status = f_string_ranges_resize(1, &found->depth[depth].array[position].content); + if (F_status_is_error(state->status)) break; } if (depth) { @@ -522,8 +623,8 @@ extern "C" { } if (graph_first == 0x2) { - status = f_array_lengths_increase(state.step_small, delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase(state->step_small, delimits); + if (F_status_is_error(state->status)) break; delimits->array[delimits->used++] = comment_delimit; } @@ -533,16 +634,23 @@ extern "C" { graph_first = 0x1; if (!depth) { - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; - - private_macro_fl_fss_nest_return_on_overflow_delimited((buffer), (*range), (*found), positions_start, objects, slashes, F_none_eos, F_none_stop) + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; f_array_lengths_resize(0, &positions_start); f_string_ranges_resize(0, &objects); f_array_lengths_resize(0, &slashes); - return F_fss_found_content; + if (range->start >= buffer.used) { + state->status = F_none_eos; + } else if (range->start > range->stop) { + state->status = F_none_stop; + } + else { + state->status = F_fss_found_content; + } + + return; } --depth; @@ -552,20 +660,15 @@ extern "C" { // No valid object close found, seek until EOL. while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_eol_s.string[0]) { if (graph_first == 0x2) { - status = f_array_lengths_increase(state.step_small, delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase(state->step_small, delimits); + if (F_status_is_error(state->status)) break; delimits->array[delimits->used++] = comment_delimit; } @@ -579,36 +682,58 @@ extern "C" { position_previous = range->start; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) break; + if (F_status_is_error(state->status)) break; if (depth) { - private_macro_fl_fss_nest_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, (*comments), comments_used, positions_start, objects, slashes, F_end_not_nest_eos, F_end_not_nest_stop) + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; + comments->used = comments_used; + + f_array_lengths_resize(0, &positions_start); + f_string_ranges_resize(0, &objects); + f_array_lengths_resize(0, &slashes); + + state->status = (range->start >= buffer.used) ? F_end_not_nest_eos : F_end_not_nest_stop; + + return; + } } else { - private_macro_fl_fss_nest_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, (*comments), comments_used, positions_start, objects, slashes, F_data_not_eos, F_data_not_stop) + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; + comments->used = comments_used; + + f_array_lengths_resize(0, &positions_start); + f_string_ranges_resize(0, &objects); + f_array_lengths_resize(0, &slashes); + + state->status = (range->start >= buffer.used) ? F_data_not_eos : F_data_not_stop; + + return; + } } } } else if (graph_first == 0x1 && buffer.string[range->start] == f_fss_comment_s.string[0]) { position = newline_last + 1; - status = f_fss_seek_to_eol(state, buffer, range); - if (F_status_is_error(status)) break; + f_fss_seek_to_eol(buffer, range, state); + if (F_status_is_error(state->status)) break; - status = f_string_ranges_increase(state.step_small, comments); - if (F_status_is_error(status)) break; + state->status = f_string_ranges_increase(state->step_small, comments); + if (F_status_is_error(state->status)) break; if (range->start > range->stop || range->start >= buffer.used) { --range->start; } else { if (graph_first == 0x2) { - status = f_array_lengths_increase(state.step_small, delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase(state->step_small, delimits); + if (F_status_is_error(state->status)) break; delimits->array[delimits->used++] = comment_delimit; } @@ -626,16 +751,15 @@ extern "C" { position_previous = range->start; if (graph_first == 0x1) { - status = f_fss_is_space(state, buffer, *range); - if (F_status_is_error(status)) break; + if (f_fss_is_space(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; - if (status == F_false) { graph_first = 0x0; } } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; if (range->start >= buffer.used || range->start > range->stop) break; @@ -644,8 +768,8 @@ extern "C" { position_previous = range->start; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while f_array_lengths_resize(0, &positions_start); @@ -655,47 +779,55 @@ extern "C" { delimits->used = delimits_used; comments->used = comments_used; - if (F_status_is_error(status)) return status; + if (F_status_is_error(state->status)) return; if (range->start > range->stop) { - if (!depth) return F_status_set_error(F_end_not_stop); + state->status = F_status_set_error(depth ? F_end_not_nest_stop : F_end_not_stop); - return F_status_set_error(F_end_not_nest_stop); + return; } - if (!depth) return F_status_set_error(F_end_not_eos); - - return F_status_set_error(F_end_not_nest_eos); + state->status = F_status_set_error(depth ? F_end_not_nest_eos : F_end_not_eos); } #endif // _di_fl_fss_embedded_list_content_read_ #ifndef _di_fl_fss_embedded_list_content_write_ - f_status_t fl_fss_embedded_list_content_write(const f_string_static_t content, const uint8_t complete, const f_string_static_t * const prepend, const f_string_ranges_t * const ignore, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination) { + void fl_fss_embedded_list_content_write(const f_string_static_t content, const uint8_t complete, const f_string_static_t * const prepend, const f_string_ranges_t * const ignore, f_string_range_t * const range, f_string_dynamic_t * const destination, f_state_t * const state) { #ifndef _di_level_1_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!destination) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !destination) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_1_parameter_checking_ - f_status_t status = f_fss_skip_past_delimit(state, content, range); - if (F_status_is_error(status)) return status; + f_fss_skip_past_delimit(content, range, state); + if (F_status_is_error(state->status)) return; - if (status == F_none_eos) { - status = F_data_not_eos; + if (state->status == F_none_eos) { + state->status = F_data_not_eos; } - else if (status == F_none_stop) { - status = F_data_not_stop; + else if (state->status == F_none_stop) { + state->status = F_data_not_stop; } if (range->start > range->stop || range->start >= content.used) { if (complete == f_fss_complete_full_e || complete == f_fss_complete_full_trim_e || complete == f_fss_complete_end_e) { - const f_status_t status_allocation = f_string_dynamic_increase_by(state.step_small + 2, destination); - if (F_status_is_error(status_allocation)) return status_allocation; + const f_status_t status = f_string_dynamic_increase_by(state->step_small + 2, destination); + + if (F_status_is_error(status)) { + state->status = status; + + return; + } destination->string[destination->used++] = f_fss_embedded_list_close_s.string[0]; destination->string[destination->used++] = f_fss_embedded_list_close_end_s.string[0]; } - return status; + return; } const f_array_length_t destination_used = destination->used; @@ -715,52 +847,46 @@ extern "C" { while (range->start <= range->stop && range->start < content.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (content.string[range->start] == f_fss_slash_s.string[0] && !is_comment) { slash_count = 1; if (do_prepend) { - status = f_string_dynamic_append(*prepend, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_append(*prepend, destination); + if (F_status_is_error(state->status)) break; do_prepend = F_false; } - status = f_string_dynamic_increase(state.step_large, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase(state->step_large, destination); + if (F_status_is_error(state->status)) break; destination->string[destination->used++] = content.string[range->start]; for (++range->start; range->start <= range->stop && range->start < content.used; ++range->start) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) { destination->used = destination_used; - return F_status_set_error(F_interrupt); + return; } } if (content.string[range->start] == f_fss_placeholder_s.string[0]) continue; if (content.string[range->start] != f_fss_slash_s.string[0]) break; - status = f_string_dynamic_increase(state.step_large, destination); + state->status = f_string_dynamic_increase(state->step_large, destination); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } destination->string[destination->used++] = f_fss_slash_s.string[0]; @@ -770,14 +896,14 @@ extern "C" { if (content.string[range->start] == f_fss_embedded_list_open_s.string[0] || content.string[range->start] == f_fss_embedded_list_close_s.string[0]) { start = range->start++; - status = f_fss_skip_past_space(state, content, range); - if (F_status_is_error(status)) break; + f_fss_skip_past_space(content, range, state); + if (F_status_is_error(state->status)) break; if (range->start >= content.used || range->start > range->stop || content.string[range->start] == f_fss_eol_s.string[0]) { // Increase by total slashes + 1 embedded list open/close. - status = f_string_dynamic_increase_by(slash_count + 2, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(slash_count + 2, destination); + if (F_status_is_error(state->status)) break; if (content.string[range->start] == f_fss_embedded_list_open_s.string[0]) { while (--slash_count) { @@ -790,8 +916,8 @@ extern "C" { range->start = start + 1; - status = private_fl_fss_basic_list_write_add_until_end(content, state, range, destination); - if (F_status_is_error(status)) break; + private_fl_fss_basic_list_write_add_until_end(content, range, destination, state); + if (F_status_is_error(state->status)) break; if (content.string[range->start] != f_fss_eol_s.string[0]) { has_graph = F_true; @@ -801,8 +927,8 @@ extern "C" { } // Increase by character at "start" and possible newline. - status = f_string_dynamic_increase_by(state.step_small + 2, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(state->step_small + 2, destination); + if (F_status_is_error(state->status)) break; destination->string[destination->used++] = content.string[start]; @@ -823,16 +949,16 @@ extern "C" { start = range->start++; if (do_prepend) { - status = f_string_dynamic_append(*prepend, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_append(*prepend, destination); + if (F_status_is_error(state->status)) break; do_prepend = F_false; } has_graph = F_true; - status = f_fss_skip_past_space(state, content, range); - if (F_status_is_error(status)) break; + f_fss_skip_past_space(content, range, state); + if (F_status_is_error(state->status)) break; if (range->start >= content.used || range->start > range->stop || content.string[range->start] == f_fss_eol_s.string[0]) { @@ -851,8 +977,8 @@ extern "C" { } // for if (r < ignore->used) { - status = f_string_dynamic_increase(state.step_large, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase(state->step_large, destination); + if (F_status_is_error(state->status)) break; destination->string[destination->used++] = content.string[start]; range->start = start + 1; @@ -862,22 +988,22 @@ extern "C" { } // Increase by slash and extended list open and possible newline. - status = f_string_dynamic_increase_by(state.step_small + 3, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(state->step_small + 3, destination); + if (F_status_is_error(state->status)) break; destination->string[destination->used++] = f_fss_slash_s.string[0]; destination->string[destination->used++] = content.string[start]; range->start = start + 1; - status = private_fl_fss_basic_list_write_add_until_end(content, state, range, destination); - if (F_status_is_error(status)) break; + private_fl_fss_basic_list_write_add_until_end(content, range, destination, state); + if (F_status_is_error(state->status)) break; continue; } - status = f_string_dynamic_increase(state.step_large, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase(state->step_large, destination); + if (F_status_is_error(state->status)) break; destination->string[destination->used++] = content.string[start]; range->start = start + 1; @@ -891,17 +1017,17 @@ extern "C" { has_graph = F_false; is_comment = F_false; } - else if ((status = f_fss_is_graph(state, content, *range)) == F_true) { - has_graph = F_true; + else if (f_fss_is_graph(content, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; } - else if (F_status_is_error(status)) { - break; + else { + has_graph = F_true; } if (content.string[range->start] != f_fss_placeholder_s.string[0]) { if (do_prepend) { - status = f_string_dynamic_append(*prepend, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_append(*prepend, destination); + if (F_status_is_error(state->status)) break; do_prepend = F_false; } @@ -916,27 +1042,27 @@ extern "C" { width = macro_f_utf_byte_width(content.string[range->start]); - status = f_string_dynamic_increase_by(width, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(width, destination); + if (F_status_is_error(state->status)) break; for (i = 0; i < width; ++i) { destination->string[destination->used++] = content.string[range->start + i]; } // for } - status = f_utf_buffer_increment(content, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(content, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } if (complete == f_fss_complete_full_e || complete == f_fss_complete_full_trim_e || complete == f_fss_complete_end_e) { - status = f_string_dynamic_increase_by(state.step_small + 3, destination); - if (F_status_is_error(status)) return status; + state->status = f_string_dynamic_increase_by(state->step_small + 3, destination); + if (F_status_is_error(state->status)) return; if (!ends_on_eol) { destination->string[destination->used++] = f_fss_eol_s.string[0]; @@ -946,44 +1072,64 @@ extern "C" { destination->string[destination->used++] = f_fss_embedded_list_close_end_s.string[0]; } - if (range->start > range->stop) return F_none_stop; - if (range->start >= content.used) return F_none_eos; - - return F_none; + if (range->start > range->stop) { + state->status = F_none_stop; + } + else if (range->start >= content.used) { + state->status = F_none_eos; + } + else { + state->status = F_none; + } } #endif // _di_fl_fss_embedded_list_content_write_ #ifndef _di_fl_fss_embedded_list_object_read_ - f_status_t fl_fss_embedded_list_object_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_object_t * const found, f_fss_delimits_t * const delimits) { + void fl_fss_embedded_list_object_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_object_t * const found, f_fss_delimits_t * const delimits, f_state_t * const state) { #ifndef _di_level_1_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!found) return F_status_set_error(F_parameter); - if (!delimits) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !found || !delimits) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_1_parameter_checking_ const f_array_length_t delimits_used = delimits->used; - f_status_t status = f_fss_skip_past_space(state, buffer, range); - if (F_status_is_error(status)) return status; + f_fss_skip_past_space(buffer, range, state); + if (F_status_is_error(state->status)) return; - if (status == F_none_eol) { + if (state->status == F_none_eol) { // Move the start position to after the EOL. ++range->start; + state->status = F_fss_found_object_not; + + return; + } - return F_fss_found_object_not; + if (state->status == F_none_eos) { + state->status = F_data_not_eos; + + return; } - if (status == F_none_eos) return F_data_not_eos; - if (status == F_none_stop) return F_data_not_stop; + if (state->status == F_none_stop) { + state->status = F_data_not_stop; + + return; + } // Return found nothing if this line only contains white space and delimit placeholders. if (buffer.string[range->start] == f_fss_eol_s.string[0]) { // Move the start position to after the EOL. ++range->start; + state->status = F_fss_found_object_not; - return F_fss_found_object_not; + return; } // Begin the search. @@ -991,21 +1137,31 @@ extern "C" { // Ignore all comment lines. if (buffer.string[range->start] == f_fss_comment_s.string[0]) { - status = f_fss_seek_to_eol(state, buffer, range); + f_fss_seek_to_eol(buffer, range, state); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { delimits->used = delimits_used; - return status; + return; + } + + if (state->status == F_none_eos) { + state->status = F_data_not_eos; + + return; } - if (status == F_none_eos) return F_data_not_eos; - if (status == F_none_stop) return F_data_not_stop; + if (state->status == F_none_stop) { + state->status = F_data_not_stop; + + return; + } // Move the start position to after the EOL. ++range->start; + state->status = F_fss_found_object_not; - return F_fss_found_object_not; + return; } f_array_length_t start = 0; @@ -1018,44 +1174,47 @@ extern "C" { // Identify where the object ends. while (range->start <= range->stop && range->start < buffer.used && buffer.string[range->start] != f_fss_eol_s.string[0]) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_slash_s.string[0]) { slash_first = range->start; slash_count = 1; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; while (range->start <= range->stop && range->start < buffer.used && (buffer.string[range->start] == f_fss_placeholder_s.string[0] || buffer.string[range->start] == f_fss_slash_s.string[0])) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_slash_s.string[0]) slash_count++; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) break; + if (F_status_is_error(state->status)) break; + + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; + + if (range->start >= buffer.used) { + found->stop = buffer.used - 1; + state->status = F_data_not_eos; + } + else { + found->stop = range->stop; + state->status = F_data_not_stop; + } - private_macro_fl_fss_object_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, F_data_not_eos, F_data_not_stop); + return; + } if (buffer.string[range->start] == f_fss_embedded_list_open_s.string[0]) { graph_first = F_false; @@ -1063,36 +1222,46 @@ extern "C" { while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_eol_s.string[0]) break; - status = f_fss_is_graph(state, buffer, *range); - if (F_status_is_error(status)) break; - - if (status == F_true) break; + if (f_fss_is_graph(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; + } + else { + break; + } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - private_macro_fl_fss_object_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, F_data_not_eos, F_data_not_stop); + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; + + if (range->start >= buffer.used) { + found->stop = buffer.used - 1; + state->status = F_data_not_eos; + } + else { + found->stop = range->stop; + state->status = F_data_not_stop; + } + + return; + } if (buffer.string[range->start] == f_fss_eol_s.string[0]) { start = range->start; range->start = slash_first; - status = f_array_lengths_increase_by((slash_count / 2) + 1, delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase_by((slash_count / 2) + 1, delimits); + if (F_status_is_error(state->status)) break; if (slash_count % 2 == 0) { while (slash_count > 0) { @@ -1105,28 +1274,31 @@ extern "C" { --slash_count; } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) break; + if (F_status_is_error(state->status)) break; found->stop = stop; range->start = start + 1; + state->status = F_fss_found_object; - return F_fss_found_object; + return; } range->start = start + 1; - return F_fss_found_object_not; + state->status = F_fss_found_object_not; + + return; } } else if (graph_first && buffer.string[range->start] == f_fss_comment_s.string[0]) { graph_first = F_false; // Comments may only have white space before the '#', therefore only the first slash needs to be delimited. - status = f_array_lengths_increase(state.step_small, delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase(state->step_small, delimits); + if (F_status_is_error(state->status)) break; delimits->array[delimits->used++] = slash_first; ++range->start; @@ -1141,123 +1313,149 @@ extern "C" { graph_first = F_false; stop = range->start - 1; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_eol_s.string[0]) break; - status = f_fss_is_space(state, buffer, *range); - if (F_status_is_error(status)) break; + if (f_fss_is_space(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; - if (status == F_false) break; + break; + } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) break; + if (F_status_is_error(state->status)) break; + + if (range->start >= buffer.used) { + found->stop = buffer.used - 1; + state->status = F_none_eos; - private_macro_fl_fss_object_return_on_overflow_delimited((buffer), (*range), (*found), F_none_eos, F_none_stop); + return; + } + + if (range->start > range->stop) { + found->stop = range->stop; + state->status = F_none_stop; + + return; + } if (buffer.string[range->start] == f_fss_eol_s.string[0]) { found->stop = stop; // Move the start position to after the EOL. ++range->start; + state->status = F_fss_found_object; - return F_fss_found_object; + return; } continue; } else if (graph_first) { - status = f_fss_is_space(state, buffer, *range); - if (F_status_is_error(status)) break; + if (f_fss_is_space(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; - if (status == F_false) { graph_first = F_false; } } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { delimits->used = delimits_used; - return status; + return; } // Seek to the end of the line when no valid object is found. while (range->start <= range->stop && range->start < buffer.used && buffer.string[range->start] != f_fss_eol_s.string[0]) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } - status = f_utf_buffer_increment(buffer, range, 1); + state->status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { delimits->used = delimits_used; - return status; + return; } } // while - private_macro_fl_fss_object_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, F_data_not_eos, F_data_not_stop); + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; - status = f_utf_buffer_increment(buffer, range, 1); + if (range->start >= buffer.used) { + found->stop = buffer.used - 1; + state->status = F_data_not_eos; + } + else { + found->stop = range->stop; + state->status = F_data_not_stop; + } - if (F_status_is_error(status)) { + return; + } + + state->status = f_utf_buffer_increment(buffer, range, 1); + + if (F_status_is_error(state->status)) { delimits->used = delimits_used; - return status; + return; } - return F_fss_found_object_not; + state->status = F_fss_found_object_not; } #endif // _di_fl_fss_embedded_list_object_read_ #ifndef _di_fl_fss_embedded_list_object_write_ - f_status_t fl_fss_embedded_list_object_write(const f_string_static_t object, const uint8_t complete, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination) { + void fl_fss_embedded_list_object_write(const f_string_static_t object, const uint8_t complete, f_string_range_t * const range, f_string_dynamic_t * const destination, f_state_t * const state) { #ifndef _di_level_1_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !destination) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_1_parameter_checking_ - f_status_t status = f_fss_skip_past_delimit(state, object, range); - if (F_status_is_error(status)) return status; + f_fss_skip_past_delimit(object, range, state); + if (F_status_is_error(state->status)) return; - if (status == F_none_eos) { - status = F_data_not_eos; + if (state->status == F_none_eos) { + state->status = F_data_not_eos; } - else if (status == F_none_stop) { - status = F_data_not_stop; + else if (state->status == F_none_stop) { + state->status = F_data_not_stop; } - if (status == F_data_not_stop || status == F_data_not_eos) { + if (state->status == F_data_not_stop || state->status == F_data_not_eos) { if (complete == f_fss_complete_partial_e || complete == f_fss_complete_partial_trim_e || complete == f_fss_complete_full_e || complete == f_fss_complete_full_trim_e) { { - const f_status_t status_allocation = f_string_dynamic_increase_by(state.step_small + 2, destination); - if (F_status_is_error(status_allocation)) return status_allocation; + const f_status_t status = f_string_dynamic_increase_by(state->step_small + 2, destination); + if (F_status_is_error(status)) { + state->status = status; + + return; + } } destination->string[destination->used++] = f_fss_embedded_list_open_s.string[0]; @@ -1267,12 +1465,12 @@ extern "C" { } } - return status; + return; } // Ensure that there is room for a slash delimit, the object open character, and the end of line character. - status = f_string_dynamic_increase_by(state.step_small + 4, destination); - if (F_status_is_error(status)) return status; + state->status = f_string_dynamic_increase_by(state->step_small + 4, destination); + if (F_status_is_error(state->status)) return; const f_array_length_t destination_used = destination->used; @@ -1286,54 +1484,51 @@ extern "C" { // Find the first graph character. while (range->start <= range->stop && range->start < object.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (object.string[range->start] == f_fss_comment_s.string[0]) { // When a comment is found, escape it. - status = f_string_dynamic_increase(state.step_large, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase(state->step_large, destination); + if (F_status_is_error(state->status)) break; destination->string[destination->used++] = f_fss_slash_s.string[0]; break; } - status = f_fss_is_graph(state, object, *range); - if (F_status_is_error(status)) break; - - if (status == F_true) break; + if (f_fss_is_graph(object, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; + } + else { + break; + } // Objects will not have leading white spaces, but having this does not result in an invalid object, so just write the provided spaces. if (object.string[range->start] != f_fss_placeholder_s.string[0]) { if (object.string[range->start] == f_fss_eol_s.string[0]) { - status = F_status_set_error(F_none_eol); + state->status = F_status_set_error(F_none_eol); break; } - status = f_fss_is_space(state, object, *range); - if (F_status_is_error(status)) break; - - if (status == F_true) { + if (f_fss_is_space(object, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; + } + else { if (object.string[range->start] == f_fss_eol_s.string[0]) { - status = F_status_set_error(F_none_eol); + state->status = F_status_set_error(F_none_eol); break; } width = macro_f_utf_byte_width(object.string[range->start]); - status = f_string_dynamic_increase_by(width, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(width, destination); + if (F_status_is_error(state->status)) break; for (i = 0; i < width; ++i) { destination->string[destination->used++] = object.string[range->start + i]; @@ -1341,26 +1536,21 @@ extern "C" { } } - status = f_utf_buffer_increment(object, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(object, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } while (range->start <= range->stop && range->start < object.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (object.string[range->start] == f_fss_slash_s.string[0]) { @@ -1368,13 +1558,13 @@ extern "C" { for (++range->start; range->start <= range->stop && range->start < object.used; ++range->start) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); + if (state->interrupt) { + state->interrupt((void *) &state, 0); - if (F_status_set_fine(status) == F_interrupt) { + if (F_status_set_fine(state->status) == F_interrupt) { destination->used = destination_used; - return F_status_set_error(F_interrupt); + return; } } @@ -1390,8 +1580,8 @@ extern "C" { slash_count *= 2; } - status = f_string_dynamic_increase_by(slash_count, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(slash_count, destination); + if (F_status_is_error(state->status)) break; while (--slash_count) { destination->string[destination->used++] = f_fss_slash_s.string[0]; @@ -1406,17 +1596,19 @@ extern "C" { if (object.string[range->start] != f_fss_placeholder_s.string[0]) { if (object.string[range->start] == f_fss_eol_s.string[0]) { - status = F_status_set_error(F_none_eol); + state->status = F_status_set_error(F_none_eol); break; } - status = f_fss_is_space(state, object, *range); - if (F_status_is_error(status)) break; + if (f_fss_is_space(object, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; + } + else { + ends_on_space = F_true; - if (ends_on_space = (status == F_true)) { if (object.string[range->start] == f_fss_eol_s.string[0]) { - status = F_status_set_error(F_none_eol); + state->status = F_status_set_error(F_none_eol); break; } @@ -1424,32 +1616,32 @@ extern "C" { width = macro_f_utf_byte_width(object.string[range->start]); - status = f_string_dynamic_increase_by(width, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(width, destination); + if (F_status_is_error(state->status)) break; for (i = 0; i < width; ++i) { destination->string[destination->used++] = object.string[range->start + i]; } // for } - status = f_utf_buffer_increment(object, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(object, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } if (complete == f_fss_complete_partial_e || complete == f_fss_complete_partial_trim_e || complete == f_fss_complete_full_e || complete == f_fss_complete_full_trim_e || complete == f_fss_complete_trim_e) { if (complete == f_fss_complete_full_trim_e || complete == f_fss_complete_trim_e) { - status = private_fl_fss_basic_list_write_object_trim(destination_used, state, destination); + private_fl_fss_basic_list_write_object_trim(destination_used, destination, state); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } // Prevent a space from being added post-trimming. @@ -1457,12 +1649,12 @@ extern "C" { } if (complete != f_fss_complete_trim_e) { - status = f_string_dynamic_increase_by(state.step_small + 3, destination); + state->status = f_string_dynamic_increase_by(state->step_small + 3, destination); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } if (!ends_on_space) { @@ -1477,10 +1669,15 @@ extern "C" { } } - if (range->start > range->stop) return F_none_stop; - if (range->start >= object.used) return F_none_eos; - - return F_none; + if (range->start > range->stop) { + state->status = F_none_stop; + } + else if (range->start >= object.used) { + state->status = F_none_eos; + } + else { + state->status = F_none; + } } #endif // _di_fl_fss_embedded_list_object_write_ diff --git a/level_1/fl_fss/c/fss/embedded_list.h b/level_1/fl_fss/c/fss/embedded_list.h index 183349c..d717c95 100644 --- a/level_1/fl_fss/c/fss/embedded_list.h +++ b/level_1/fl_fss/c/fss/embedded_list.h @@ -41,15 +41,6 @@ extern "C" { * * @param buffer * The buffer to read from. - * @param state - * A state for providing flags and handling interrupts during long running operations. - * There is no print_error(). - * There is no functions structure. - * There is no data structure passed to these functions. - * - * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. - * Error bit designates an error but must be passed along with F_interrupt. - * All other statuses are ignored. * @param range * The start/stop location within the buffer to be processed. * The start location will be updated as the buffer is being processed. @@ -63,6 +54,15 @@ extern "C" { * An array of ranges representing where comments are found within any valid content. * This only stores comments found within valid content only. * The comment range will include the trailing newline. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * There is no print_error(). + * There is no functions structure. + * There is no data structure passed to these functions. + * + * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. + * Error bit designates an error but must be passed along with F_interrupt. + * All other statuses are ignored. * * @return * F_fss_found_content on success and content was found (start location is at end of content). @@ -96,7 +96,7 @@ extern "C" { * @see f_utf_buffer_increment() */ #ifndef _di_fl_fss_embedded_list_content_read_ - extern f_status_t fl_fss_embedded_list_content_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_nest_t * const found, f_fss_delimits_t * const delimits, f_fss_comments_t * const comments); + extern void fl_fss_embedded_list_content_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_nest_t * const found, f_fss_delimits_t * const delimits, f_fss_comments_t * const comments, f_state_t * const state); #endif // _di_fl_fss_embedded_list_content_read_ /** @@ -124,6 +124,10 @@ extern "C" { * These ranges are only checked/ignored if there is a valid nested object open or a valid nested object close. * Any valid nested object open or valid nested object close inside an ingore range will not be escaped. * Set the pointer address to 0 to disable. + * @param range + * The start/stop location within the content string to write as an content. + * @param destination + * The buffer where the content is written to. * @param state * A state for providing flags and handling interrupts during long running operations. * There is no print_error(). @@ -133,10 +137,6 @@ extern "C" { * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. * Error bit designates an error but must be passed along with F_interrupt. * All other statuses are ignored. - * @param range - * The start/stop location within the content string to write as an content. - * @param destination - * The buffer where the content is written to. * * @return * F_none on success. @@ -165,7 +165,7 @@ extern "C" { * @see f_utf_buffer_increment() */ #ifndef _di_fl_fss_embedded_list_content_write_ - extern f_status_t fl_fss_embedded_list_content_write(const f_string_static_t content, const uint8_t complete, const f_string_static_t * const prepend, const f_string_ranges_t * const ignore, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination); + extern void fl_fss_embedded_list_content_write(const f_string_static_t content, const uint8_t complete, const f_string_static_t * const prepend, const f_string_ranges_t * const ignore, f_string_range_t * const range, f_string_dynamic_t * const destination, f_state_t * const state); #endif // _di_fl_fss_embedded_list_content_write_ /** @@ -175,15 +175,6 @@ extern "C" { * * @param buffer * The buffer to read from. - * @param state - * A state for providing flags and handling interrupts during long running operations. - * There is no print_error(). - * There is no functions structure. - * There is no data structure passed to these functions. - * - * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. - * Error bit designates an error but must be passed along with F_interrupt. - * All other statuses are ignored. * @param range * The start/stop location within the buffer to be processed. * The start location will be updated as the buffer is being processed. @@ -193,6 +184,15 @@ extern "C" { * A location where a valid object was found. * @param delimits * A delimits array representing where delimits exist within the buffer. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * There is no print_error(). + * There is no functions structure. + * There is no data structure passed to these functions. + * + * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. + * Error bit designates an error but must be passed along with F_interrupt. + * All other statuses are ignored. * * @return * F_fss_found_object on success and object was found (start location is at end of object). @@ -226,7 +226,7 @@ extern "C" { * @see f_utf_buffer_increment() */ #ifndef _di_fl_fss_embedded_list_object_read_ - extern f_status_t fl_fss_embedded_list_object_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_object_t * const found, f_fss_delimits_t * const delimits); + extern void fl_fss_embedded_list_object_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_object_t * const found, f_fss_delimits_t * const delimits, f_state_t * const state); #endif // _di_fl_fss_embedded_list_object_read_ /** @@ -246,6 +246,10 @@ extern "C" { * If f_fss_complete_full_trim_e, this will write any appropriate open and close aspects of this object, but will omit whitespace before and after the object. * If f_fss_complete_partial_e, this will write any appropriate open and close aspects of this object. * If f_fss_complete_partial_tim, this will write any appropriate open and close aspects of this object, but will omit whitespace before and after the object. + * @param range + * The start/stop location within the object string to write as an object. + * @param destination + * The buffer where the object is written to. * @param state * A state for providing flags and handling interrupts during long running operations. * There is no print_error(). @@ -255,10 +259,6 @@ extern "C" { * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. * Error bit designates an error but must be passed along with F_interrupt. * All other statuses are ignored. - * @param range - * The start/stop location within the object string to write as an object. - * @param destination - * The buffer where the object is written to. * * @return * F_none on success. @@ -286,7 +286,7 @@ extern "C" { * @see f_utf_buffer_increment() */ #ifndef _di_fl_fss_embedded_list_object_write_ - extern f_status_t fl_fss_embedded_list_object_write(const f_string_static_t object, const uint8_t complete, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination); + extern void fl_fss_embedded_list_object_write(const f_string_static_t object, const uint8_t complete, f_string_range_t * const range, f_string_dynamic_t * const destination, f_state_t * const state); #endif // _di_fl_fss_embedded_list_object_write_ #ifdef __cplusplus diff --git a/level_1/fl_fss/c/fss/extended.c b/level_1/fl_fss/c/fss/extended.c index 77dc91f..f19fc6a 100644 --- a/level_1/fl_fss/c/fss/extended.c +++ b/level_1/fl_fss/c/fss/extended.c @@ -1,33 +1,43 @@ #include "extended.h" #include "../private-fss.h" -#include "macro.h" #ifdef __cplusplus extern "C" { #endif #ifndef _di_fl_fss_extended_content_read_ - f_status_t fl_fss_extended_content_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_content_t * const found, f_uint8s_t * const quotes, f_fss_delimits_t * const delimits) { + void fl_fss_extended_content_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_content_t * const found, f_uint8s_t * const quotes, f_fss_delimits_t * const delimits, f_state_t * const state) { #ifndef _di_level_1_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!found) return F_status_set_error(F_parameter); - if (!delimits) return F_status_set_error(F_parameter); - #endif // _di_level_1_parameter_checking_ + if (!state) return; - f_status_t status = F_none; - f_status_t status_allocate = F_none; + if (!range || !found || !delimits) { + state->status = F_status_set_error(F_parameter); + + return; + } + #endif // _di_level_1_parameter_checking_ - status = f_fss_skip_past_space(state, buffer, range); - if (F_status_is_error(status)) return status; + f_fss_skip_past_space(buffer, range, state); + if (F_status_is_error(state->status)) return; - if (status == F_none_eol) { + if (state->status == F_none_eol) { ++range->start; + state->status = F_fss_found_content_not; - return F_fss_found_content_not; + return; } - if (status == F_none_eos) return F_data_not_eos; - if (status == F_none_stop) return F_data_not_stop; + if (state->status == F_none_eos) { + state->status = F_data_not_eos; + + return; + } + + if (state->status == F_none_stop) { + state->status = F_data_not_stop; + + return; + } const f_array_length_t delimits_used = delimits->used; const f_array_length_t quotes_used = quotes ? quotes->used : 0; @@ -35,29 +45,32 @@ extern "C" { uint8_t content_found = 0; uint8_t quote = 0; + f_status_t status = F_none; + while (range->start <= range->stop && range->start < buffer.used) { f_string_range_t content_partial = f_string_range_t_initialize; quote = 0; - status = private_fl_fss_basic_read(buffer, F_false, state, range, &content_partial, "e, delimits); + private_fl_fss_basic_read(buffer, F_false, range, &content_partial, "e, delimits, state); - if (status == F_fss_found_object || status == F_fss_found_object_content_not) { - status_allocate = f_string_ranges_increase(state.step_small, found); + if (state->status == F_fss_found_object || state->status == F_fss_found_object_content_not) { + state->status = f_string_ranges_increase(state->step_small, found); - if (F_status_is_error_not(status_allocate) && quotes) { - status_allocate = f_uint8s_increase(state.step_small, quotes); + if (F_status_is_error_not(state->status) && quotes) { + state->status = f_uint8s_increase(state->step_small, quotes); } - if (F_status_is_error(status_allocate)) { + if (F_status_is_error(status)) { delimits->used = delimits_used; + state->status = status; if (quotes) { quotes->used = quotes_used; } - return status_allocate; + return; } found->array[found->used++] = content_partial; @@ -81,78 +94,87 @@ extern "C" { content_found = 1; - if (status == F_fss_found_object_content_not) break; + if (state->status == F_fss_found_object_content_not) break; } - else if (status == F_fss_found_object_not) { + else if (state->status == F_fss_found_object_not) { break; } - else if (status == F_data_not_eos) { + else if (state->status == F_data_not_eos) { if (content_found) { - status = F_none_eos; + state->status = F_none_eos; } content_found = 2; break; } - else if (status == F_data_not_stop) { + else if (state->status == F_data_not_stop) { if (content_found) { - status = F_none_stop; + state->status = F_none_stop; } content_found = 2; break; } - else if (status == F_end_not_group_eos || status == F_end_not_group_eos) { + else if (state->status == F_end_not_group_eos || state->status == F_end_not_group_eos) { if (content_found) { content_found = 2; } break; } - else if (F_status_is_error(status)) { + else if (F_status_is_error(state->status)) { delimits->used = delimits_used; - return status; + return; } } // while if (content_found) { - if (content_found == 2) return status; + if (content_found == 2) return; - return F_fss_found_content; + state->status = F_fss_found_content; + } + else { + state->status = F_fss_found_content_not; } - - return F_fss_found_content_not; } #endif // _di_fl_fss_extended_content_read_ #ifndef _di_fl_fss_extended_content_write_ - f_status_t fl_fss_extended_content_write(const f_string_static_t content, const uint8_t quote, const uint8_t complete, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination) { + void fl_fss_extended_content_write(const f_string_static_t content, const uint8_t quote, const uint8_t complete, f_string_range_t * const range, f_string_dynamic_t * const destination, f_state_t * const state) { #ifndef _di_level_1_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!destination) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !destination) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_1_parameter_checking_ const f_array_length_t destination_used = destination->used; // This operates exactly like an object, syntax-wise. - const f_status_t status = private_fl_fss_basic_write(F_false, content, quote ? quote : f_fss_quote_double_s.string[0], state, range, destination); + private_fl_fss_basic_write(F_false, content, quote ? quote : f_fss_quote_double_s.string[0], range, destination, state); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } - if (status == F_data_not_stop || status == F_data_not_eos) { + f_status_t status = F_none; + + if (state->status == F_data_not_stop || state->status == F_data_not_eos) { // Content that is empty must be represented by a quote empty string. - { - const f_status_t status_allocation = f_string_dynamic_increase_by(state.step_small + 4, destination); - if (F_status_is_error(status_allocation)) return status_allocation; - } + status = f_string_dynamic_increase_by(state->step_small + 4, destination); + + if (F_status_is_error(status)) { + state->status = status; + }; destination->string[destination->used++] = quote ? quote : f_fss_quote_double_s.string[0]; destination->string[destination->used++] = quote ? quote : f_fss_quote_double_s.string[0]; @@ -166,15 +188,18 @@ extern "C" { destination->string[destination->used++] = f_fss_extended_close_s.string[0]; } - if (status == F_data_not_stop) return F_none_stop; + state->status = (state->status == F_data_not_stop) ? F_none_stop : F_none_eos; - return F_none_eos; + return; } // Ensure that there is room, including the slash delimit and possibly the end of content characters. - { - const f_status_t status_allocation = f_string_dynamic_increase_by(state.step_small + 2, destination); - if (F_status_is_error(status_allocation)) return status_allocation; + status = f_string_dynamic_increase_by(state->step_small + 2, destination); + + if (F_status_is_error(status)) { + state->status = status; + + return; } if (complete == f_fss_complete_partial_e || complete == f_fss_complete_partial_trim_e || complete == f_fss_complete_full_e || complete == f_fss_complete_full_trim_e || complete == f_fss_complete_next_e) { @@ -184,59 +209,67 @@ extern "C" { if (complete == f_fss_complete_full_e || complete == f_fss_complete_full_trim_e || complete == f_fss_complete_end_e) { destination->string[destination->used++] = f_fss_extended_close_s.string[0]; } - - return status; } #endif // _di_fl_fss_extended_content_write_ #ifndef _di_fl_fss_extended_object_read_ - f_status_t fl_fss_extended_object_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_object_t * const found, uint8_t * const quote, f_fss_delimits_t * const delimits) { + void fl_fss_extended_object_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_object_t * const found, uint8_t * const quote, f_fss_delimits_t * const delimits, f_state_t * const state) { #ifndef _di_level_1_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!found) return F_status_set_error(F_parameter); - if (!delimits) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !found || !delimits) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_1_parameter_checking_ const f_array_length_t delimits_used = delimits->used; - const f_status_t status = private_fl_fss_basic_read(buffer, F_true, state, range, found, quote, delimits); + private_fl_fss_basic_read(buffer, F_true, range, found, quote, delimits, state); - if (F_status_is_error(status) || status == F_fss_found_object_not || status == F_data_not || status == F_data_not_eos || status == F_data_not_stop) { + if (F_status_is_error(state->status) || state->status == F_fss_found_object_not || state->status == F_data_not || state->status == F_data_not_eos || state->status == F_data_not_stop) { delimits->used = delimits_used; } - return status; + return; } #endif // _di_fl_fss_extended_object_read_ #ifndef _di_fl_fss_extended_object_write_ -f_status_t fl_fss_extended_object_write(const f_string_static_t object, const uint8_t quote, const uint8_t complete, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination) { +void fl_fss_extended_object_write(const f_string_static_t object, const uint8_t quote, const uint8_t complete, f_string_range_t * const range, f_string_dynamic_t * const destination, f_state_t * const state) { #ifndef _di_level_1_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!destination) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !destination) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_1_parameter_checking_ const f_array_length_t destination_used = destination->used; - f_status_t status = private_fl_fss_basic_write(F_true, object, quote ? quote : f_fss_quote_double_s.string[0], state, range, destination); + private_fl_fss_basic_write(F_true, object, quote ? quote : f_fss_quote_double_s.string[0], range, destination, state); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } - if (status == F_data_not_stop || status == F_data_not_eos) { + f_status_t status = F_none; + + if (state->status == F_data_not_stop || state->status == F_data_not_eos) { // Objects cannot be empty, so write a quote empty string. - { - const f_status_t status_allocation = f_string_dynamic_increase_by(state.step_small + 2, destination); + status = f_string_dynamic_increase_by(state->step_small + 2, destination); - if (F_status_is_error(status_allocation)) { - destination->used = destination_used; + if (F_status_is_error(status)) { + destination->used = destination_used; + state->status = status; - return status_allocation; - } + return; } destination->string[destination->used++] = quote ? quote : f_fss_quote_double_s.string[0]; @@ -244,34 +277,34 @@ f_status_t fl_fss_extended_object_write(const f_string_static_t object, const ui } if (complete == f_fss_complete_partial_e || complete == f_fss_complete_partial_trim_e || complete == f_fss_complete_full_e || complete == f_fss_complete_full_trim_e || complete == f_fss_complete_trim_e) { - if (status == F_none_stop || status == F_none_eos || status == F_data_not_stop || status == F_data_not_eos) { - f_status_t status2 = F_none; + if (state->status == F_none_stop || state->status == F_none_eos || state->status == F_data_not_stop || state->status == F_data_not_eos) { + status = F_none; if (complete == f_fss_complete_full_trim_e || complete == f_fss_complete_trim_e) { - status2 = private_fl_fss_basic_write_object_trim(quote ? quote : f_fss_quote_double_s.string[0], destination_used, state, destination); + private_fl_fss_basic_write_object_trim(quote ? quote : f_fss_quote_double_s.string[0], destination_used, destination, state); - if (F_status_is_error(status2)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; + state->status = status; - return status2; + return; } } if (complete != f_fss_complete_trim_e) { - status2 = f_string_dynamic_increase(state.step_large, destination); + status = f_string_dynamic_increase(state->step_large, destination); - if (F_status_is_error(status2)) { + if (F_status_is_error(status)) { destination->used = destination_used; + state->status = status; - return status2; + return; } destination->string[destination->used++] = f_fss_extended_open_s.string[0]; } } } - - return status; } #endif // _di_fl_fss_extended_object_write_ diff --git a/level_1/fl_fss/c/fss/extended.h b/level_1/fl_fss/c/fss/extended.h index b7cc23c..bca23bc 100644 --- a/level_1/fl_fss/c/fss/extended.h +++ b/level_1/fl_fss/c/fss/extended.h @@ -36,15 +36,6 @@ extern "C" { * * @param buffer * The buffer to read from. - * @param state - * A state for providing flags and handling interrupts during long running operations. - * There is no print_error(). - * There is no functions structure. - * There is no data structure passed to these functions. - * - * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. - * Error bit designates an error but must be passed along with F_interrupt. - * All other statuses are ignored. * @param range * The start/stop location within the buffer to be processed. * The start location will be updated as the buffer is being processed. @@ -57,6 +48,15 @@ extern "C" { * Set pointer address to 0 to not use. * @param delimits * A delimits array representing where delimits exist within the buffer. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * There is no print_error(). + * There is no functions structure. + * There is no data structure passed to these functions. + * + * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. + * Error bit designates an error but must be passed along with F_interrupt. + * All other statuses are ignored. * * @return * F_fss_found_content on success and content was found (start location is at end of content). @@ -93,7 +93,7 @@ extern "C" { * @see fl_fss_extended_content_read() */ #ifndef _di_fl_fss_extended_content_read_ - extern f_status_t fl_fss_extended_content_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_content_t * const found, f_uint8s_t * const quotes, f_fss_delimits_t * const delimits); + extern void fl_fss_extended_content_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_content_t * const found, f_uint8s_t * const quotes, f_fss_delimits_t * const delimits, f_state_t * const state); #endif // _di_fl_fss_extended_content_read_ /** @@ -115,6 +115,10 @@ extern "C" { * If f_fss_complete_end_e, then the content followed by any appropriate "end" character designating the last content for some object, printing final newline, if applicable. * If f_fss_complete_partial_e, this will write any appropriate open and close aspects of this content, except for the final newline. * If f_fss_complete_full_e, this will write any appropriate open and close aspects of this content, including the final newline. + * @param range + * The start/stop location within the content string to write as an content. + * @param destination + * The buffer where the content is written to. * @param state * A state for providing flags and handling interrupts during long running operations. * There is no print_error(). @@ -124,10 +128,6 @@ extern "C" { * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. * Error bit designates an error but must be passed along with F_interrupt. * All other statuses are ignored. - * @param range - * The start/stop location within the content string to write as an content. - * @param destination - * The buffer where the content is written to. * * @return * F_none on success. @@ -158,7 +158,7 @@ extern "C" { * @see fl_fss_extended_content_write() */ #ifndef _di_fl_fss_extended_content_write_ - extern f_status_t fl_fss_extended_content_write(const f_string_static_t content, const uint8_t quote, const uint8_t complete, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination); + extern void fl_fss_extended_content_write(const f_string_static_t content, const uint8_t quote, const uint8_t complete, f_string_range_t * const range, f_string_dynamic_t * const destination, f_state_t * const state); #endif // _di_fl_fss_extended_content_write_ /** @@ -168,15 +168,6 @@ extern "C" { * * @param buffer * The buffer to read from. - * @param state - * A state for providing flags and handling interrupts during long running operations. - * There is no print_error(). - * There is no functions structure. - * There is no data structure passed to these functions. - * - * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. - * Error bit designates an error but must be passed along with F_interrupt. - * All other statuses are ignored. * @param range * The start/stop location within the buffer to be processed. * The start location will be updated as the buffer is being processed. @@ -189,6 +180,15 @@ extern "C" { * Set pointer address to 0 to not use. * @param delimits * A delimits array representing where delimits exist within the buffer. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * There is no print_error(). + * There is no functions structure. + * There is no data structure passed to these functions. + * + * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. + * Error bit designates an error but must be passed along with F_interrupt. + * All other statuses are ignored. * * @return * F_fss_found_object on success and object was found (start location is at end of object). @@ -230,7 +230,7 @@ extern "C" { * @see fl_fss_extended_content_read() */ #ifndef _di_fl_fss_extended_object_read_ - extern f_status_t fl_fss_extended_object_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_object_t * const found, uint8_t * const quote, f_fss_delimits_t * const delimits); + extern void fl_fss_extended_object_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_object_t * const found, uint8_t * const quote, f_fss_delimits_t * const delimits, f_state_t * const state); #endif // _di_fl_fss_extended_object_read_ /** @@ -251,6 +251,10 @@ extern "C" { * If f_fss_complete_none_e, then only the object name is written. * If f_fss_complete_full_e, this will write any appropriate open and close aspects of this object. * If f_fss_complete_partial_e, this will write any appropriate open and close aspects of this object. + * @param range + * The start/stop location within the object string to write as an object. + * @param destination + * The buffer where the object is written to. * @param state * A state for providing flags and handling interrupts during long running operations. * There is no print_error(). @@ -260,10 +264,6 @@ extern "C" { * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. * Error bit designates an error but must be passed along with F_interrupt. * All other statuses are ignored. - * @param range - * The start/stop location within the object string to write as an object. - * @param destination - * The buffer where the object is written to. * * @return * F_none on success. @@ -289,7 +289,7 @@ extern "C" { * @see f_string_dynamic_increase_by() */ #ifndef _di_fl_fss_extended_object_write_ - extern f_status_t fl_fss_extended_object_write(const f_string_static_t object, const uint8_t quote, const uint8_t complete, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination); + extern void fl_fss_extended_object_write(const f_string_static_t object, const uint8_t quote, const uint8_t complete, f_string_range_t * const range, f_string_dynamic_t * const destination, f_state_t * const state); #endif // _di_fl_fss_extended_object_write_ #ifdef __cplusplus diff --git a/level_1/fl_fss/c/fss/extended_list.c b/level_1/fl_fss/c/fss/extended_list.c index 32eead3..77302ea 100644 --- a/level_1/fl_fss/c/fss/extended_list.c +++ b/level_1/fl_fss/c/fss/extended_list.c @@ -1,30 +1,46 @@ #include "extended_list.h" #include "../private-fss.h" -#include "macro.h" #ifdef __cplusplus extern "C" { #endif #ifndef _di_fl_fss_extended_list_content_read_ - f_status_t fl_fss_extended_list_content_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_content_t * const found, f_fss_delimits_t * const delimits, f_fss_comments_t * const comments) { + void fl_fss_extended_list_content_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_content_t * const found, f_fss_delimits_t * const delimits, f_fss_comments_t * const comments, f_state_t * const state) { #ifndef _di_level_1_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!found) return F_status_set_error(F_parameter); - if (!delimits) return F_status_set_error(F_parameter); - if (!comments) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !found || !delimits || !comments) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_1_parameter_checking_ const f_array_length_t delimits_used = delimits->used; const f_array_length_t comments_used = comments->used; - f_status_t status = f_fss_skip_past_delimit(state, buffer, range); - if (F_status_is_error(status)) return status; + f_fss_skip_past_delimit(buffer, range, state); + if (F_status_is_error(state->status)) return; - private_macro_fl_fss_content_with_comments_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, (*comments), comments_used, F_none_eos, F_none_stop); + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; + comments->used = comments_used; - status = f_string_ranges_increase(state.step_small, found); - if (F_status_is_error(status)) return status; + if (range->start >= buffer.used) { + found->array[found->used].stop = buffer.used - 1; + state->status = F_none_eos; + } + else { + found->array[found->used].stop = range->stop; + state->status = F_none_stop; + } + + return; + } + + state->status = f_string_ranges_increase(state->step_small, found); + if (F_status_is_error(state->status)) return; found->array[found->used].start = range->start; @@ -36,26 +52,21 @@ extern "C" { // Identify where the content ends. while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } - status = f_fss_skip_past_space(state, buffer, range); - if (F_status_is_error(status)) break; + f_fss_skip_past_space(buffer, range, state); + if (F_status_is_error(state->status)) break; - if (status == F_none_eol) { + if (state->status == F_none_eol) { newline_last = range->start++; continue; } - if (status == F_none_eos || status == F_none_stop) break; + if (state->status == F_none_eos || state->status == F_none_stop) break; if (buffer.string[range->start] == f_fss_slash_s.string[0]) { slash_first = range->start; @@ -63,14 +74,9 @@ extern "C" { for (++range->start; range->start <= range->stop && range->start < buffer.used; ++range->start) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_placeholder_s.string[0]) continue; @@ -89,32 +95,28 @@ extern "C" { while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_eol_s.string[0]) break; - status = f_fss_is_space(state, buffer, *range); - if (F_status_is_error(status)) break; + if (f_fss_is_space(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; - if (status == F_false) break; + break; + } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while if (range->start > range->stop || range->start >= buffer.used) break; if (buffer.string[range->start] == f_fss_eol_s.string[0]) { - status = f_array_lengths_increase(state.step_small, delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase(state->step_small, delimits); + if (F_status_is_error(state->status)) break; delimits->array[delimits->used++] = slash_first; @@ -122,14 +124,14 @@ extern "C" { } } else if (buffer.string[range->start] == f_fss_comment_s.string[0]) { - status = f_array_lengths_increase(state.step_small, delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase(state->step_small, delimits); + if (F_status_is_error(state->status)) break; delimits->array[delimits->used++] = slash_first; } - status = f_fss_seek_to_eol(state, buffer, range); - if (F_status_is_error(status)) break; + f_fss_seek_to_eol(buffer, range, state); + if (F_status_is_error(state->status)) break; continue; } @@ -139,28 +141,24 @@ extern "C" { while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_eol_s.string[0]) break; - status = f_fss_is_space(state, buffer, *range); - if (F_status_is_error(status)) break; + if (f_fss_is_space(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; - if (status == F_false) break; + break; + } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) break; + if (F_status_is_error(state->status)) break; if (range->start > range->stop || range->start >= buffer.used) break; @@ -173,12 +171,15 @@ extern "C" { found->array[found->used].start = 1; found->array[found->used++].stop = 0; - return F_fss_found_content_not; + state->status = F_fss_found_content_not; + + return; } found->array[found->used++].stop = newline_last; + state->status = F_fss_found_content; - return F_fss_found_content; + return; } continue; @@ -187,11 +188,11 @@ extern "C" { if (buffer.string[range->start] == f_fss_comment_s.string[0]) { start = newline_last + 1; - status = f_fss_seek_to_eol(state, buffer, range); - if (F_status_is_error(status)) break; + f_fss_seek_to_eol(buffer, range, state); + if (F_status_is_error(state->status)) break; - status = f_string_ranges_increase(state.step_small, comments); - if (F_status_is_error(status)) break; + state->status = f_string_ranges_increase(state->step_small, comments); + if (F_status_is_error(state->status)) break; if (range->start > range->stop || range->start >= buffer.used) { --range->start; @@ -207,55 +208,65 @@ extern "C" { } // There is no possibility of a valid content close, so seek until newline. - status = f_fss_seek_to_eol(state, buffer, range); - if (F_status_is_error(status)) break; + f_fss_seek_to_eol(buffer, range, state); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { delimits->used = delimits_used; comments->used = comments_used; - return status; + return; } - return F_fss_found_content_not; + state->status = F_fss_found_content_not; } #endif // _di_fl_fss_extended_list_content_read_ #ifndef _di_fl_fss_extended_list_content_write_ - f_status_t fl_fss_extended_list_content_write(const f_string_static_t content, const uint8_t complete, const f_string_static_t * const prepend, const f_string_ranges_t * const ignore, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination) { + void fl_fss_extended_list_content_write(const f_string_static_t content, const uint8_t complete, const f_string_static_t * const prepend, const f_string_ranges_t * const ignore, f_string_range_t * const range, f_string_dynamic_t * const destination, f_state_t * const state) { #ifndef _di_level_1_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!destination) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !destination) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_1_parameter_checking_ - f_status_t status = f_fss_skip_past_delimit(state, content, range); - if (F_status_is_error(status)) return status; + f_fss_skip_past_delimit(content, range, state); + if (F_status_is_error(state->status)) return; - if (status == F_none_eos) { - status = F_data_not_eos; + if (state->status == F_none_eos) { + state->status = F_data_not_eos; } - else if (status == F_none_stop) { - status = F_data_not_stop; + else if (state->status == F_none_stop) { + state->status = F_data_not_stop; } if (range->start > range->stop || range->start >= content.used) { if (complete == f_fss_complete_full_e || complete == f_fss_complete_full_trim_e || complete == f_fss_complete_end_e) { { - const f_status_t status_allocation = f_string_dynamic_increase_by(state.step_small + 2, destination); - if (F_status_is_error(status_allocation)) return status_allocation; + const f_status_t status = f_string_dynamic_increase_by(state->step_small + 2, destination); + + if (F_status_is_error(status)) { + state->status = status; + + return; + } } destination->string[destination->used++] = f_fss_extended_list_close_s.string[0]; destination->string[destination->used++] = f_fss_extended_list_close_end_s.string[0]; } - return status; + return; } // Ensure that there is room for a slash delimit and possibly the end of content characters. - status = f_string_dynamic_increase_by(state.step_small + 4, destination); - if (F_status_is_error(status)) return status; + state->status = f_string_dynamic_increase_by(state->step_small + 4, destination); + if (F_status_is_error(state->status)) return; const f_array_length_t destination_used = destination->used; @@ -273,56 +284,50 @@ extern "C" { while (range->start <= range->stop && range->start < content.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (content.string[range->start] == f_fss_slash_s.string[0] && !is_comment) { slash_count = 1; if (do_prepend) { - status = f_string_dynamic_increase_by(state.step_small + prepend->used, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(state->step_small + prepend->used, destination); + if (F_status_is_error(state->status)) break; - status = f_string_dynamic_append(*prepend, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_append(*prepend, destination); + if (F_status_is_error(state->status)) break; do_prepend = F_false; } else { - status = f_string_dynamic_increase(state.step_large, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase(state->step_large, destination); + if (F_status_is_error(state->status)) break; } destination->string[destination->used++] = content.string[range->start]; for (++range->start; range->start <= range->stop && range->start < content.used; ++range->start) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) { destination->used = destination_used; - return F_status_set_error(F_interrupt); + return; } } if (content.string[range->start] == f_fss_placeholder_s.string[0]) continue; if (content.string[range->start] != f_fss_slash_s.string[0]) break; - status = f_string_dynamic_increase(state.step_large, destination); + state->status = f_string_dynamic_increase(state->step_large, destination); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } destination->string[destination->used++] = f_fss_slash_s.string[0]; @@ -332,23 +337,23 @@ extern "C" { if (content.string[range->start] == f_fss_extended_list_close_s.string[0]) { start = range->start++; - status = f_fss_skip_past_space(state, content, range); - if (F_status_is_error(status)) break; + f_fss_skip_past_space(content, range, state); + if (F_status_is_error(state->status)) break; if (has_graph) { // Do nothing. } else if (content.string[range->start] == f_fss_eol_s.string[0] || range->start >= content.used || range->start > range->stop) { - status = f_string_dynamic_increase_by(state.step_small + 2, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(state->step_small + 2, destination); + if (F_status_is_error(state->status)) break; destination->string[destination->used++] = f_fss_slash_s.string[0]; destination->string[destination->used++] = f_fss_extended_list_close_s.string[0]; range->start = start + 1; - status = private_fl_fss_basic_list_write_add_until_end(content, state, range, destination); - if (F_status_is_error(status)) break; + private_fl_fss_basic_list_write_add_until_end(content, range, destination, state); + if (F_status_is_error(state->status)) break; if (content.string[range->start] != f_fss_eol_s.string[0]) { has_graph = F_true; @@ -358,8 +363,8 @@ extern "C" { } // Increase by character at "start" and possible newline. - status = f_string_dynamic_increase_by(state.step_small + 2, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(state->step_small + 2, destination); + if (F_status_is_error(state->status)) break; destination->string[destination->used++] = content.string[start]; @@ -380,16 +385,16 @@ extern "C" { start = range->start++; if (do_prepend) { - status = f_string_dynamic_append(*prepend, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_append(*prepend, destination); + if (F_status_is_error(state->status)) break; do_prepend = F_false; } has_graph = F_true; - status = f_fss_skip_past_space(state, content, range); - if (F_status_is_error(status)) break; + f_fss_skip_past_space(content, range, state); + if (F_status_is_error(state->status)) break; if (content.string[range->start] == f_fss_eol_s.string[0] || range->start >= content.used || range->start > range->stop) { @@ -408,8 +413,8 @@ extern "C" { } // for if (r < ignore->used) { - status = f_string_dynamic_increase(state.step_large, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase(state->step_large, destination); + if (F_status_is_error(state->status)) break; destination->string[destination->used++] = content.string[start]; range->start = start + 1; @@ -419,22 +424,22 @@ extern "C" { } // Increase by slash and extended list close. - status = f_string_dynamic_increase_by(state.step_small + 2, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(state->step_small + 2, destination); + if (F_status_is_error(state->status)) break; destination->string[destination->used++] = f_fss_slash_s.string[0]; destination->string[destination->used++] = content.string[start]; range->start = start + 1; - status = private_fl_fss_basic_list_write_add_until_end(content, state, range, destination); - if (F_status_is_error(status)) break; + private_fl_fss_basic_list_write_add_until_end(content, range, destination, state); + if (F_status_is_error(state->status)) break; continue; } - status = f_string_dynamic_increase(state.step_large, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase(state->step_large, destination); + if (F_status_is_error(state->status)) break; destination->string[destination->used++] = content.string[start]; range->start = start + 1; @@ -448,17 +453,17 @@ extern "C" { has_graph = F_false; is_comment = F_false; } - else if ((status = f_fss_is_graph(state, content, *range)) == F_true) { - has_graph = F_true; + else if (f_fss_is_graph(content, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; } - else if (F_status_is_error(status)) { - break; + else { + has_graph = F_true; } if (content.string[range->start] != f_fss_placeholder_s.string[0]) { if (do_prepend) { - status = f_string_dynamic_append(*prepend, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_append(*prepend, destination); + if (F_status_is_error(state->status)) break; do_prepend = F_false; } @@ -473,30 +478,30 @@ extern "C" { width = macro_f_utf_byte_width(content.string[range->start]); - status = f_string_dynamic_increase_by(width, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(width, destination); + if (F_status_is_error(state->status)) break; for (i = 0; i < width; ++i) { destination->string[destination->used++] = content.string[range->start + i]; } // for } - status = f_utf_buffer_increment(content, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(content, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } if (complete == f_fss_complete_full_e || complete == f_fss_complete_full_trim_e || complete == f_fss_complete_end_e) { - status = f_string_dynamic_increase_by(state.step_small + 3, destination); - if (F_status_is_error(status)) { + state->status = f_string_dynamic_increase_by(state->step_small + 3, destination); + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } if (!ends_on_eol) { @@ -507,44 +512,64 @@ extern "C" { destination->string[destination->used++] = f_fss_extended_list_close_end_s.string[0]; } - if (range->start > range->stop) return F_none_stop; - if (range->start >= content.used) return F_none_eos; - - return F_none; + if (range->start > range->stop) { + state->status = F_none_stop; + } + else if (range->start >= content.used) { + state->status = F_none_eos; + } + else { + state->status = F_none; + } } #endif // _di_fl_fss_extended_list_content_write_ #ifndef _di_fl_fss_extended_list_object_read_ - f_status_t fl_fss_extended_list_object_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_object_t * const found, f_fss_delimits_t * const delimits) { + void fl_fss_extended_list_object_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_object_t * const found, f_fss_delimits_t * const delimits, f_state_t * const state) { #ifndef _di_level_1_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!found) return F_status_set_error(F_parameter); - if (!delimits) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !found || !delimits) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_1_parameter_checking_ const f_array_length_t delimits_used = delimits->used; - f_status_t status = f_fss_skip_past_space(state, buffer, range); - if (F_status_is_error(status)) return status; + f_fss_skip_past_space(buffer, range, state); + if (F_status_is_error(state->status)) return; - if (status == F_none_eol) { + if (state->status == F_none_eol) { // Move the start position to after the EOL. ++range->start; + state->status = F_fss_found_object_not; - return F_fss_found_object_not; + return; } - if (status == F_none_eos) return F_data_not_eos; - if (status == F_none_stop) return F_data_not_stop; + if (state->status == F_none_eos) { + state->status = F_data_not_eos; + + return; + } + + if (state->status == F_none_stop) { + state->status = F_data_not_stop; + + return; + } // Return found nothing if this line only contains white space and delimit placeholders. if (buffer.string[range->start] == f_fss_eol_s.string[0]) { // Move the start position to after the EOL. ++range->start; + state->status = F_fss_found_object_not; - return F_fss_found_object_not; + return; } // Begin the search. @@ -552,21 +577,31 @@ extern "C" { // Ignore all comment lines. if (buffer.string[range->start] == f_fss_comment_s.string[0]) { - status = f_fss_seek_to_eol(state, buffer, range); + f_fss_seek_to_eol(buffer, range, state); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { delimits->used = delimits_used; - return status; + return; + } + + if (state->status == F_none_eos) { + state->status = F_data_not_eos; + + return; } - if (status == F_none_eos) return F_data_not_eos; - if (status == F_none_stop) return F_data_not_stop; + if (state->status == F_none_stop) { + state->status = F_data_not_stop; + + return; + } // Move the start position to after the EOL. ++range->start; + state->status = F_fss_found_object_not; - return F_fss_found_object_not; + return; } f_array_length_t start = 0; @@ -579,44 +614,47 @@ extern "C" { // Identify where the object ends. while (range->start <= range->stop && range->start < buffer.used && buffer.string[range->start] != f_fss_eol_s.string[0]) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_slash_s.string[0]) { slash_first = range->start; slash_count = 1; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; while (range->start <= range->stop && range->start < buffer.used && (buffer.string[range->start] == f_fss_placeholder_s.string[0] || buffer.string[range->start] == f_fss_slash_s.string[0])) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_slash_s.string[0]) ++slash_count; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) break; + if (F_status_is_error(state->status)) break; - private_macro_fl_fss_object_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, F_data_not_eos, F_data_not_stop); + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; + + if (range->start >= buffer.used) { + found->stop = buffer.used - 1; + state->status = F_data_not_eos; + } + else { + found->stop = range->stop; + state->status = F_data_not_stop; + } + + return; + } if (buffer.string[range->start] == f_fss_extended_list_open_s.string[0]) { graph_first = F_false; @@ -624,35 +662,45 @@ extern "C" { while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_eol_s.string[0]) break; - status = f_fss_is_graph(state, buffer, *range); - if (F_status_is_error(status)) break; - - if (status == F_true) break; + if (f_fss_is_graph(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; + } + else { + break; + } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - private_macro_fl_fss_object_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, F_data_not_eos, F_data_not_stop); + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; + + if (range->start >= buffer.used) { + found->stop = buffer.used - 1; + state->status = F_data_not_eos; + } + else { + found->stop = range->stop; + state->status = F_data_not_stop; + } + + return; + } if (buffer.string[range->start] == f_fss_eol_s.string[0]) { start = range->start; range->start = slash_first; - status = f_array_lengths_increase_by((slash_count / 2) + 1, delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase_by((slash_count / 2) + 1, delimits); + if (F_status_is_error(state->status)) break; if (slash_count % 2 == 0) { while (slash_count > 0) { @@ -665,29 +713,31 @@ extern "C" { --slash_count; } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) break; + if (F_status_is_error(state->status)) break; found->stop = stop; range->start = start + 1; + state->status = F_fss_found_object; - return F_fss_found_object; + return; } range->start = start + 1; + state->status = F_fss_found_object_not; - return F_fss_found_object_not; + return; } } else if (graph_first && buffer.string[range->start] == f_fss_comment_s.string[0]) { graph_first = F_false; // Comments may only have white space before the '#', therefore only the first slash needs to be delimited. - status = f_array_lengths_increase(state.step_small, delimits); - if (F_status_is_error(status)) break; + state->status = f_array_lengths_increase(state->step_small, delimits); + if (F_status_is_error(state->status)) break; delimits->array[delimits->used++] = slash_first; ++range->start; @@ -702,123 +752,150 @@ extern "C" { graph_first = F_false; stop = range->start - 1; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (buffer.string[range->start] == f_fss_eol_s.string[0]) break; - status = f_fss_is_space(state, buffer, *range); - if (F_status_is_error(status)) break; + if (f_fss_is_space(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; - if (status == F_false) break; + break; + } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) break; + if (F_status_is_error(state->status)) break; - private_macro_fl_fss_object_return_on_overflow_delimited((buffer), (*range), (*found), F_none_eos, F_none_stop); + if (range->start >= buffer.used) { + found->stop = buffer.used - 1; + state->status = F_none_eos; + + return; + } + + if (range->start > range->stop) { + found->stop = range->stop; + state->status = F_none_stop; + + return; + } if (buffer.string[range->start] == f_fss_eol_s.string[0]) { found->stop = stop; // Move the start position to after the EOL. ++range->start; + state->status = F_fss_found_object; - return F_fss_found_object; + return; } continue; } else if (graph_first) { - status = f_fss_is_space(state, buffer, *range); - if (F_status_is_error(status)) break; + if (f_fss_is_space(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; - if (status == F_false) { graph_first = F_false; } } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { delimits->used = delimits_used; - return status; + return; } // Seek to the end of the line when no valid object is found. while (range->start <= range->stop && range->start < buffer.used && buffer.string[range->start] != f_fss_eol_s.string[0]) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } - status = f_utf_buffer_increment(buffer, range, 1); + state->status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { delimits->used = delimits_used; - return status; + return; } } // while - private_macro_fl_fss_object_return_on_overflow((buffer), (*range), (*found), (*delimits), delimits_used, F_data_not_eos, F_data_not_stop); + if (range->start >= buffer.used || range->start > range->stop) { + delimits->used = delimits_used; - status = f_utf_buffer_increment(buffer, range, 1); + if (range->start >= buffer.used) { + found->stop = buffer.used - 1; + state->status = F_data_not_eos; + } + else { + found->stop = range->stop; + state->status = F_data_not_stop; + } + + return; + } - if (F_status_is_error(status)) { + state->status = f_utf_buffer_increment(buffer, range, 1); + + if (F_status_is_error(state->status)) { delimits->used = delimits_used; - return status; + return; } - return F_fss_found_object_not; + state->status = F_fss_found_object_not; } #endif // _di_fl_fss_extended_list_object_read_ #ifndef _di_fl_fss_extended_list_object_write_ - f_status_t fl_fss_extended_list_object_write(const f_string_static_t object, const uint8_t complete, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination) { + void fl_fss_extended_list_object_write(const f_string_static_t object, const uint8_t complete, f_string_range_t * const range, f_string_dynamic_t * const destination, f_state_t * const state) { #ifndef _di_level_1_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !destination) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_1_parameter_checking_ - f_status_t status = f_fss_skip_past_delimit(state, object, range); - if (F_status_is_error(status)) return status; + f_fss_skip_past_delimit(object, range, state); + if (F_status_is_error(state->status)) return; - if (status == F_none_eos) { - status = F_data_not_eos; + if (state->status == F_none_eos) { + state->status = F_data_not_eos; } - else if (status == F_none_stop) { - status = F_data_not_stop; + else if (state->status == F_none_stop) { + state->status = F_data_not_stop; } - if (status == F_data_not_stop || status == F_data_not_eos) { + if (state->status == F_data_not_stop || state->status == F_data_not_eos) { if (complete == f_fss_complete_partial_e || complete == f_fss_complete_partial_trim_e || complete == f_fss_complete_full_e || complete == f_fss_complete_full_trim_e) { { - const f_status_t status_allocation = f_string_dynamic_increase_by(state.step_small + 2, destination); - if (F_status_is_error(status_allocation)) return status_allocation; + const f_status_t status = f_string_dynamic_increase_by(state->step_small + 2, destination); + + if (F_status_is_error(status)) { + state->status = status; + + return; + } } destination->string[destination->used++] = f_fss_extended_list_open_s.string[0]; @@ -828,12 +905,12 @@ extern "C" { } } - return status; + return; } // Ensure that there is room for a slash delimit, the object open character, and the end of line character. - status = f_string_dynamic_increase_by(state.step_small + 4, destination); - if (F_status_is_error(status)) return status; + state->status = f_string_dynamic_increase_by(state->step_small + 4, destination); + if (F_status_is_error(state->status)) return; const f_array_length_t destination_used = destination->used; @@ -847,54 +924,51 @@ extern "C" { // Find the first graph character. while (range->start <= range->stop && range->start < object.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (object.string[range->start] == f_fss_comment_s.string[0]) { // When a comment is found, escape it. - status = f_string_dynamic_increase(state.step_large, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase(state->step_large, destination); + if (F_status_is_error(state->status)) break; destination->string[destination->used++] = f_fss_slash_s.string[0]; break; } - status = f_fss_is_graph(state, object, *range); - if (F_status_is_error(status)) break; - - if (status == F_true) break; + if (f_fss_is_graph(object, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; + } + else { + break; + } // Objects will not have leading white spaces, but having this does not result in an invalid object, so just write the provided spaces. if (object.string[range->start] != f_fss_placeholder_s.string[0]) { if (object.string[range->start] == f_fss_eol_s.string[0]) { - status = F_status_set_error(F_none_eol); + state->status = F_status_set_error(F_none_eol); break; } - status = f_fss_is_space(state, object, *range); - if (F_status_is_error(status)) break; - - if (status == F_true) { + if (f_fss_is_space(object, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; + } + else { if (object.string[range->start] == f_fss_eol_s.string[0]) { - status = F_status_set_error(F_none_eol); + state->status = F_status_set_error(F_none_eol); break; } width = macro_f_utf_byte_width(object.string[range->start]); - status = f_string_dynamic_increase_by(width, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(width, destination); + if (F_status_is_error(state->status)) break; for (i = 0; i < width; ++i) { destination->string[destination->used++] = object.string[range->start + i]; @@ -902,26 +976,21 @@ extern "C" { } } - status = f_utf_buffer_increment(object, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(object, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } while (range->start <= range->stop && range->start < object.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (object.string[range->start] == f_fss_slash_s.string[0]) { @@ -929,13 +998,13 @@ extern "C" { for (++range->start; range->start <= range->stop && range->start < object.used; ++range->start) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); + if (state->interrupt) { + state->interrupt((void *) &state, 0); - if (F_status_set_fine(status) == F_interrupt) { + if (F_status_set_fine(state->status) == F_interrupt) { destination->used = destination_used; - return F_status_set_error(F_interrupt); + return; } } @@ -951,8 +1020,8 @@ extern "C" { slash_count *= 2; } - status = f_string_dynamic_increase_by(slash_count, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(slash_count, destination); + if (F_status_is_error(state->status)) break; while (--slash_count) { destination->string[destination->used++] = f_fss_slash_s.string[0]; @@ -967,17 +1036,19 @@ extern "C" { if (object.string[range->start] != f_fss_placeholder_s.string[0]) { if (object.string[range->start] == f_fss_eol_s.string[0]) { - status = F_status_set_error(F_none_eol); + state->status = F_status_set_error(F_none_eol); break; } - status = f_fss_is_space(state, object, *range); - if (F_status_is_error(status)) break; + if (f_fss_is_space(object, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; + } + else { + ends_on_space = F_true; - if (ends_on_space = (status == F_true)) { if (object.string[range->start] == f_fss_eol_s.string[0]) { - status = F_status_set_error(F_none_eol); + state->status = F_status_set_error(F_none_eol); break; } @@ -985,32 +1056,32 @@ extern "C" { width = macro_f_utf_byte_width(object.string[range->start]); - status = f_string_dynamic_increase_by(width, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(width, destination); + if (F_status_is_error(state->status)) break; for (i = 0; i < width; ++i) { destination->string[destination->used++] = object.string[range->start + i]; } // for } - status = f_utf_buffer_increment(object, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(object, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } if (complete == f_fss_complete_partial_e || complete == f_fss_complete_partial_trim_e || complete == f_fss_complete_full_e || complete == f_fss_complete_full_trim_e || complete == f_fss_complete_trim_e) { if (complete == f_fss_complete_full_trim_e || complete == f_fss_complete_trim_e) { - status = private_fl_fss_basic_list_write_object_trim(destination_used, state, destination); + private_fl_fss_basic_list_write_object_trim(destination_used, destination, state); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } // Prevent a space from being added post-trimming. @@ -1018,12 +1089,12 @@ extern "C" { } if (complete != f_fss_complete_trim_e) { - status = f_string_dynamic_increase_by(state.step_small + 3, destination); + state->status = f_string_dynamic_increase_by(state->step_small + 3, destination); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = destination_used; - return status; + return; } if (!ends_on_space) { @@ -1038,10 +1109,15 @@ extern "C" { } } - if (range->start > range->stop) return F_none_stop; - if (range->start >= object.used) return F_none_eos; - - return F_none; + if (range->start > range->stop) { + state->status = F_none_stop; + } + else if (range->start >= object.used) { + state->status = F_none_eos; + } + else { + state->status = F_none; + } } #endif // _di_fl_fss_extended_list_object_write_ diff --git a/level_1/fl_fss/c/fss/extended_list.h b/level_1/fl_fss/c/fss/extended_list.h index fa92e3e..aa3f1ee 100644 --- a/level_1/fl_fss/c/fss/extended_list.h +++ b/level_1/fl_fss/c/fss/extended_list.h @@ -39,15 +39,6 @@ extern "C" { * * @param buffer * The buffer to read from. - * @param state - * A state for providing flags and handling interrupts during long running operations. - * There is no print_error(). - * There is no functions structure. - * There is no data structure passed to these functions. - * - * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. - * Error bit designates an error but must be passed along with F_interrupt. - * All other statuses are ignored. * @param range * The start/stop location within the buffer to be processed. * The start location will be updated as the buffer is being processed. @@ -61,6 +52,15 @@ extern "C" { * An array of ranges representing where comments are found within any valid content. * This only stores comments found within valid content only. * The comment range will include the trailing newline. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * There is no print_error(). + * There is no functions structure. + * There is no data structure passed to these functions. + * + * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. + * Error bit designates an error but must be passed along with F_interrupt. + * All other statuses are ignored. * * @return * F_fss_found_content on success and content was found (start location is at end of content). @@ -92,7 +92,7 @@ extern "C" { * @see f_utf_buffer_increment() */ #ifndef _di_fl_fss_extended_list_content_read_ - extern f_status_t fl_fss_extended_list_content_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_content_t * const found, f_fss_delimits_t * const delimits, f_fss_comments_t * const comments); + extern void fl_fss_extended_list_content_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_content_t * const found, f_fss_delimits_t * const delimits, f_fss_comments_t * const comments, f_state_t * const state); #endif // _di_fl_fss_extended_list_content_read_ /** @@ -120,6 +120,10 @@ extern "C" { * These ranges are only checked/ignored if there is a valid nested object open or a valid nested object close. * Any valid nested object open or valid nested object close inside an ingore range will not be escaped. * Set the pointer address to 0 to disable. + * @param range + * The start/stop location within the content string to write as an content. + * @param destination + * The buffer where the content is written to. * @param state * A state for providing flags and handling interrupts during long running operations. * There is no print_error(). @@ -129,10 +133,6 @@ extern "C" { * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. * Error bit designates an error but must be passed along with F_interrupt. * All other statuses are ignored. - * @param range - * The start/stop location within the content string to write as an content. - * @param destination - * The buffer where the content is written to. * * @return * F_none on success. @@ -161,7 +161,7 @@ extern "C" { * @see f_utf_buffer_increment() */ #ifndef _di_fl_fss_extended_list_content_write_ - extern f_status_t fl_fss_extended_list_content_write(const f_string_static_t content, const uint8_t complete, const f_string_static_t * const prepend, const f_string_ranges_t * const ignore, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination); + extern void fl_fss_extended_list_content_write(const f_string_static_t content, const uint8_t complete, const f_string_static_t * const prepend, const f_string_ranges_t * const ignore, f_string_range_t * const range, f_string_dynamic_t * const destination, f_state_t * const state); #endif // _di_fl_fss_extended_list_content_write_ /** @@ -171,15 +171,6 @@ extern "C" { * * @param buffer * The buffer to read from. - * @param state - * A state for providing flags and handling interrupts during long running operations. - * There is no print_error(). - * There is no functions structure. - * There is no data structure passed to these functions. - * - * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. - * Error bit designates an error but must be passed along with F_interrupt. - * All other statuses are ignored. * @param range * The start/stop location within the buffer to be processed. * The start location will be updated as the buffer is being processed. @@ -189,6 +180,15 @@ extern "C" { * A location where a valid object was found. * @param delimits * A delimits array representing where delimits exist within the buffer. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * There is no print_error(). + * There is no functions structure. + * There is no data structure passed to these functions. + * + * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. + * Error bit designates an error but must be passed along with F_interrupt. + * All other statuses are ignored. * * @return * F_fss_found_object on success and object was found (start location is at end of object). @@ -222,7 +222,7 @@ extern "C" { * @see f_utf_buffer_increment() */ #ifndef _di_fl_fss_extended_list_object_read_ - extern f_status_t fl_fss_extended_list_object_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_object_t * const found, f_fss_delimits_t * const delimits); + extern void fl_fss_extended_list_object_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_object_t * const found, f_fss_delimits_t * const delimits, f_state_t * const state); #endif // _di_fl_fss_extended_list_object_read_ /** @@ -242,6 +242,10 @@ extern "C" { * If f_fss_complete_full_trim_e, this will write any appropriate open and close aspects of this object, but will omit whitespace before and after the object. * If f_fss_complete_partial_e, this will write any appropriate open and close aspects of this object. * If f_fss_complete_partial_tim, this will write any appropriate open and close aspects of this object, but will omit whitespace before and after the object. + * @param range + * The start/stop location within the object string to write as an object. + * @param destination + * The buffer where the object is written to. * @param state * A state for providing flags and handling interrupts during long running operations. * There is no print_error(). @@ -251,10 +255,6 @@ extern "C" { * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. * Error bit designates an error but must be passed along with F_interrupt. * All other statuses are ignored. - * @param range - * The start/stop location within the object string to write as an object. - * @param destination - * The buffer where the object is written to. * * @return * F_none on success. @@ -282,7 +282,7 @@ extern "C" { * @see f_utf_buffer_increment() */ #ifndef _di_fl_fss_extended_list_object_write_ - extern f_status_t fl_fss_extended_list_object_write(const f_string_static_t object, const uint8_t complete, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination); + extern void fl_fss_extended_list_object_write(const f_string_static_t object, const uint8_t complete, f_string_range_t * const range, f_string_dynamic_t * const destination, f_state_t * const state); #endif // _di_fl_fss_extended_list_object_write_ #ifdef __cplusplus diff --git a/level_1/fl_fss/c/fss/macro.h b/level_1/fl_fss/c/fss/macro.h deleted file mode 100644 index ca4a6f6..0000000 --- a/level_1/fl_fss/c/fss/macro.h +++ /dev/null @@ -1,99 +0,0 @@ -/** - * FLL - Level 1 - * - * Project: FSS - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Provides generic functionality shared between and used by different fss processing functions. - */ -#ifndef _PRIVATE_FL_fss_macro_h -#define _PRIVATE_FL_fss_macro_h - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _di_private_macro_fl_fss_object_return_on_overflow_ - #define private_macro_fl_fss_object_return_on_overflow(buffer, range, found, delimits, delimits_used, eos_status, stop_status) \ - if (range.start >= buffer.used) { \ - delimits.used = delimits_used; \ - found.stop = buffer.used - 1; \ - return eos_status; \ - } \ - else if (range.start > range.stop) { \ - delimits.used = delimits_used; \ - found.stop = range.stop; \ - return stop_status; \ - } -#endif // _di_private_macro_fl_fss_object_return_on_overflow_ - -#ifndef _di_private_macro_fl_fss_object_return_on_overflow_delimited_ - #define private_macro_fl_fss_object_return_on_overflow_delimited(buffer, range, found, eos_status, stop_status) \ - if (range.start >= buffer.used) { \ - found.stop = buffer.used - 1; \ - return eos_status; \ - } \ - else if (range.start > range.stop) { \ - found.stop = range.stop; \ - return stop_status; \ - } -#endif // _di_private_macro_fl_fss_object_return_on_overflow_delimited_ - -#ifndef _di_private_macro_fl_fss_content_with_comments_return_on_overflow_ - #define private_macro_fl_fss_content_with_comments_return_on_overflow(buffer, range, found, delimits, delimits_used, comments, comments_used, eos_status, stop_status) \ - if (range.start >= buffer.used) { \ - delimits.used = delimits_used; \ - comments.used = comments_used; \ - found.array[found.used].stop = buffer.used - 1; \ - return eos_status; \ - } \ - else if (range.start > range.stop) { \ - delimits.used = delimits_used; \ - comments.used = comments_used; \ - found.array[found.used].stop = range.stop; \ - return stop_status; \ - } -#endif // _di_private_macro_fl_fss_content_with_comments_return_on_overflow_ - -#ifndef _di_private_macro_fl_fss_nest_return_on_overflow_ - #define private_macro_fl_fss_nest_return_on_overflow(buffer, range, found, delimits, delimits_used, comments, comments_used, positions, objects, slashes, eos_status, stop_status) \ - if (range.start >= buffer.used) { \ - delimits.used = delimits_used; \ - comments.used = comments_used; \ - macro_f_array_lengths_t_delete_simple(positions); \ - macro_f_fss_objects_t_delete_simple(objects); \ - macro_f_array_lengths_t_delete_simple(slashes); \ - return eos_status; \ - } \ - else if (range.start > range.stop) { \ - delimits.used = delimits_used; \ - comments.used = comments_used; \ - macro_f_array_lengths_t_delete_simple(positions); \ - macro_f_fss_objects_t_delete_simple(objects); \ - macro_f_array_lengths_t_delete_simple(slashes); \ - return stop_status; \ - } -#endif // _di_private_macro_fl_fss_nest_return_on_overflow_ - -#ifndef _di_private_macro_fl_fss_nest_return_on_overflow_delimited_ - #define private_macro_fl_fss_nest_return_on_overflow_delimited(buffer, range, found, positions, objects, slashes, eos_status, stop_status) \ - if (range.start >= buffer.used) { \ - macro_f_array_lengths_t_delete_simple(positions); \ - macro_f_fss_objects_t_delete_simple(objects); \ - macro_f_array_lengths_t_delete_simple(slashes); \ - return eos_status; \ - } \ - else if (range.start > range.stop) { \ - macro_f_array_lengths_t_delete_simple(positions); \ - macro_f_fss_objects_t_delete_simple(objects); \ - macro_f_array_lengths_t_delete_simple(slashes); \ - return stop_status; \ - } -#endif // _di_private_macro_fl_fss_nest_return_on_overflow_delimited_ - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // _PRIVATE_FL_fss_macro_h diff --git a/level_1/fl_fss/c/private-fss.c b/level_1/fl_fss/c/private-fss.c index 0b0c4a2..5061d4c 100644 --- a/level_1/fl_fss/c/private-fss.c +++ b/level_1/fl_fss/c/private-fss.c @@ -1,70 +1,61 @@ #include "fss.h" #include "private-fss.h" -#include "fss/macro.h" #ifdef __cplusplus extern "C" { #endif #if !defined(_di_fl_fss_basic_list_content_write_) || !defined(_di_fl_fss_extended_list_content_write_) || !defined(_di_fl_fss_embedded_list_content_write_) - f_status_t private_fl_fss_basic_list_write_add_until_end(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination) { + void private_fl_fss_basic_list_write_add_until_end(const f_string_static_t buffer, f_string_range_t * const range, f_string_dynamic_t * const destination, f_state_t * const state) { - f_status_t status = F_none; + state->status = F_none; for (; range->start <= range->stop && range->start < buffer.used; ++range->start) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - return F_status_set_error(F_interrupt); - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) return; } if (buffer.string[range->start] == f_fss_placeholder_s.string[0]) continue; if (buffer.string[range->start] == f_fss_eol_s.string[0]) break; - status = f_string_dynamic_increase(state.step_large, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase(state->step_large, destination); + if (F_status_is_error(state->status)) break; destination->string[destination->used++] = buffer.string[range->start]; } // for - - return status; } #endif // !defined(_di_fl_fss_basic_list_content_write_) || !defined(_di_fl_fss_extended_list_content_write_) || !defined(_di_fl_fss_embedded_list_content_write_) #if !defined(_di_fl_fss_basic_list_object_write_) || !defined(_di_fl_fss_extended_list_object_write_) - f_status_t private_fl_fss_basic_list_write_object_trim(const f_array_length_t used_start, f_state_t state, f_string_dynamic_t * const destination) { + void private_fl_fss_basic_list_write_object_trim(const f_array_length_t used_start, f_string_dynamic_t * const destination, f_state_t * const state) { - f_status_t status = F_none; f_string_range_t destination_range = macro_f_string_range_t_initialize2(destination->used); f_array_length_t i = 0; - uint8_t width = 0; - for (; destination_range.start < destination->used; ++destination_range.start) { + state->status = F_none; - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); + for (; destination_range.start < destination->used; ++destination_range.start) { - if (F_status_set_fine(status) == F_interrupt) { - return F_status_set_error(F_interrupt); - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) return; } if (destination->string[destination_range.start] == f_fss_placeholder_s.string[0]) continue; - status = f_fss_is_space(state, *destination, destination_range); + if (f_fss_is_space(*destination, destination_range, state) == F_false) { + if (F_status_is_error(state->status)) { + destination->used = used_start; - if (F_status_is_error(status)) { - destination->used = used_start; + return; + } - return status; + break; } - if (status == F_false) break; - width = macro_f_utf_byte_width(destination->string[destination_range.start]); for (i = 0; i < width; ++i) { @@ -74,12 +65,9 @@ extern "C" { for (destination_range.start = destination->used - 1; destination_range.start > 0; --destination_range.start) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - return F_status_set_error(F_interrupt); - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) return; } if (destination->string[destination_range.start] == f_fss_placeholder_s.string[0]) { @@ -88,57 +76,67 @@ extern "C" { continue; } - status = f_fss_is_space(state, *destination, destination_range); + if (f_fss_is_space(*destination, destination_range, state) == F_false) { - // When going backwards, getting incomplete UTF-8 sequences is not an error. - if (F_status_set_fine(status) == F_complete_not_utf) continue; + // When going backwards, getting incomplete UTF-8 sequences is not an error. + if (F_status_set_fine(state->status) == F_complete_not_utf) continue; - if (F_status_is_error(status)) { - destination->used = used_start; + if (F_status_is_error(state->status)) { + destination->used = used_start; - return status; - } + return; + } - if (status == F_false) break; + break; + } destination->used -= macro_f_utf_byte_width(destination->string[destination_range.start]); } // for if (destination_range.start == 0) { - status = f_fss_is_space(state, *destination, destination_range); - - if (F_status_is_error(status)) { - destination->used = used_start; + if (f_fss_is_space(*destination, destination_range, state) == F_false) { + if (F_status_is_error(state->status)) { + destination->used = used_start; - return status; + return; + } } - - if (status == F_true) { + else { destination->used = 0; } } - return F_none; + state->status = F_none; } #endif // !defined(_di_fl_fss_basic_list_object_write_) || !defined(_di_fl_fss_extended_list_object_write_) #if !defined(_di_fl_fss_basic_object_read_) || !defined(_di_fl_fss_extended_object_read_) || !defined(_di_fl_fss_extended_content_read_) - f_status_t private_fl_fss_basic_read(const f_string_static_t buffer, const bool object_as, f_state_t state, f_string_range_t * const range, f_fss_object_t * const found, uint8_t * const quote, f_fss_delimits_t * const delimits) { + void private_fl_fss_basic_read(const f_string_static_t buffer, const bool object_as, f_string_range_t * const range, f_fss_object_t * const found, uint8_t * const quote, f_fss_delimits_t * const delimits, f_state_t * const state) { - f_status_t status = f_fss_skip_past_space(state, buffer, range); - if (F_status_is_error(status)) return status; + f_fss_skip_past_space(buffer, range, state); + if (F_status_is_error(state->status)) return; + if (state->status == F_data_not) return; - if (status == F_none_eol) { + if (state->status == F_none_eol) { // Move the start position to after the EOL. ++range->start; + state->status = F_fss_found_object_not; - return F_fss_found_object_not; + return; } - if (status == F_none_eos) return F_data_not_eos; - if (status == F_none_stop) return F_data_not_stop; - if (status == F_data_not) return status; + if (state->status == F_none_eos) { + state->status = F_data_not_eos; + + return; + } + + if (state->status == F_none_stop) { + state->status = F_data_not_stop; + + return; + } // Begin the search. found->start = range->start; @@ -148,29 +146,31 @@ extern "C" { while (buffer.string[range->start] != f_fss_eol_s.string[0]) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - return F_status_set_error(F_interrupt); - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) return; } ++range->start; if (range->start >= buffer.used) { - return F_data_not_eos; + state->status = F_data_not_eos; + + return; } if (range->start > range->stop) { - return F_data_not_stop; + state->status = F_data_not_stop; + + return; } } // while // Move the start position to after the EOL. ++range->start; + state->status = F_fss_found_object_not; - return F_fss_found_object_not; + return; } // Handle quote support. @@ -186,88 +186,90 @@ extern "C" { found->start = range->start; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) return status; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) return; while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) return; } - status = f_fss_is_zero_width(state, buffer, *range); - if (F_status_is_error(status)) return status; - - if (status == F_true) { - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + if (f_fss_is_zero_width(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) return; + } + else { + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; continue; } if (buffer.string[range->start] != f_fss_slash_s.string[0]) { - status = f_fss_is_space(state, buffer, *range); - if (F_status_is_error(status)) return status; + if (f_fss_is_space(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) return; + } // Found the end of the object while processing the slash for potential delimits. - if (status == F_true) { + if (state->status == F_true) { found->stop = range->start - 1; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; if (buffer.string[range->start] == f_fss_eol_s.string[0]) { - return F_fss_found_object_content_not; + state->status = F_fss_found_object_content_not; + + return; } - return F_fss_found_object; + state->status = F_fss_found_object; + + return; } break; } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) return status; + if (F_status_is_error(state->status)) return; if (range->start >= buffer.used) { found->stop = buffer.used - 1; + state->status = F_none_eos; - return F_none_eos; + return; } if (range->start > range->stop) { found->stop = range->stop; + state->status = F_none_stop; - return F_none_stop; + return; } if (buffer.string[range->start] == f_fss_quote_single_s.string[0] || buffer.string[range->start] == f_fss_quote_double_s.string[0] || buffer.string[range->start] == f_fss_quote_backtick_s.string[0] || (object_as && buffer.string[range->start] == f_fss_comment_s.string[0])) { // Only the first slash before a quote needs to be escaped (or not) as once there is a slash before a quote, this cannot ever be a quote object. // This simplifies the number of slashes needed. - status = f_array_lengths_increase(state.step_small, delimits); - if (F_status_is_error(status)) return status; + state->status = f_array_lengths_increase(state->step_small, delimits); + if (F_status_is_error(state->status)) return; delimits->array[delimits->used++] = first_slash; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) return status; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) return; } } else if (buffer.string[range->start] == f_fss_quote_single_s.string[0] || buffer.string[range->start] == f_fss_quote_double_s.string[0] || buffer.string[range->start] == f_fss_quote_backtick_s.string[0]) { quote_found = buffer.string[range->start]; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) return status; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) return; found->start = range->start; } @@ -280,34 +282,28 @@ extern "C" { while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - return F_status_set_error(F_interrupt); - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) return; } if (buffer.string[range->start] == f_fss_slash_s.string[0]) { first_slash = range->start; slash_count = 1; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) return status; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) return; while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - return F_status_set_error(F_interrupt); - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) return; } if (buffer.string[range->start] == f_fss_placeholder_s.string[0]) { - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) return status; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) return; continue; } @@ -317,20 +313,22 @@ extern "C" { ++slash_count; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) return status; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) return; } // while if (range->start >= buffer.used) { found->stop = buffer.used - 1; + state->status = F_end_not_group_eos; - return F_end_not_group_eos; + return; } if (range->start > range->stop) { found->stop = range->stop; + state->status = F_end_not_group_stop; - return F_end_not_group_stop; + return; } if (buffer.string[range->start] == quote_found) { @@ -340,28 +338,29 @@ extern "C" { if (range->start + 1 <= range->stop && range->start + 1 < buffer.used) { ++range->start; - status = f_fss_skip_past_delimit(state, buffer, range); - if (F_status_is_error(status)) return status; + f_fss_skip_past_delimit(buffer, range, state); + if (F_status_is_error(state->status)) return; if (range->start > range->stop || range->start >= buffer.used) { // EOS or EOL was reached, so it is a valid closing quote. // (for EOL, this is always TRUE, for EOS this could be false but there is no way to know this, so assume TRUE.) - status = F_true; + state->status = F_true; } else { - status = f_fss_is_space(state, buffer, *range); - if (F_status_is_error(status)) return status; + if (f_fss_is_space(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) return; + } } } else { // EOS or EOL was reached, so it is a valid closing quote. // (for EOL, this is always TRUE, for EOS this could be false but there is no way to know this, so assume TRUE.) - status = F_true; + state->status = F_true; } - if (status == F_true) { + if (state->status == F_true) { if (quote) { if (quote_found == f_fss_quote_single_s.string[0] || quote_found == f_fss_quote_double_s.string[0] || quote_found == f_fss_quote_backtick_s.string[0]) { *quote = quote_found; @@ -374,8 +373,8 @@ extern "C" { range->start = first_slash; if (slash_count % 2 == 0) { - status = f_array_lengths_increase_by(slash_count / 2, delimits); - if (F_status_is_error(status)) return status; + state->status = f_array_lengths_increase_by(slash_count / 2, delimits); + if (F_status_is_error(state->status)) return; while (slash_count > 0) { @@ -388,61 +387,68 @@ extern "C" { --slash_count; } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) return status; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) return; } // while range->start = location + 1; while (buffer.string[range->start] == f_fss_placeholder_s.string[0]) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) return; + } - if (F_status_set_fine(status) == F_interrupt) { - return F_status_set_error(F_interrupt); - } + if (++range->start >= buffer.used) { + state->status = F_none_eos; + + return; } - if (++range->start >= buffer.used) return F_none_eos; - if (range->start > range->stop) return F_none_stop; - } // while + if (range->start > range->stop) { + state->status = F_none_stop; - status = f_fss_is_graph(state, buffer, *range); - if (F_status_is_error(status)) return status; + return; + } + } // while - if (status == F_true) { + if (f_fss_is_graph(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) return; + } + else { while (range->start <= range->stop && range->start < buffer.used && buffer.string[range->start] != f_fss_eol_s.string[0]) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - return F_status_set_error(F_interrupt); - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) return; } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) return status; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) return; } // while if (range->start >= buffer.used) { found->stop = buffer.used - 1; + state->status = F_data_not_eos; - return F_data_not_eos; + return; } if (range->start > range->stop) { found->stop = range->stop; + state->status = F_data_not_stop; - return F_data_not_stop; + return; } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) return status; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) return; + + state->status = F_fss_found_object_not; - return F_fss_found_object_not; + return; } if (buffer.string[range->start] == f_fss_eol_s.string[0]) { @@ -450,37 +456,39 @@ extern "C" { // Move the start position to after the EOL. ++range->start; + state->status = F_fss_found_object_content_not; - return F_fss_found_object_content_not; + return; } found->stop = location - 1; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) return status; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) return; - return F_fss_found_object; + state->status = F_fss_found_object; + + return; } - else { - status = f_array_lengths_increase_by((slash_count / 2) + 1, delimits); - if (F_status_is_error(status)) return status; - while (slash_count > 0) { + state->status = f_array_lengths_increase_by((slash_count / 2) + 1, delimits); + if (F_status_is_error(state->status)) return; - if (buffer.string[range->start] == f_fss_slash_s.string[0]) { - if (slash_count % 2 == 1) { - delimits->array[delimits->used++] = range->start; - } + while (slash_count > 0) { - --slash_count; + if (buffer.string[range->start] == f_fss_slash_s.string[0]) { + if (slash_count % 2 == 1) { + delimits->array[delimits->used++] = range->start; } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) return status; - } // while + --slash_count; + } - range->start = location; - } + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) return; + } // while + + range->start = location; } else { range->start = location; @@ -495,30 +503,31 @@ extern "C" { if (range->start + 1 <= range->stop && range->start + 1 < buffer.used) { ++range->start; - status = f_fss_skip_past_delimit(state, buffer, range); - if (F_status_is_error(status)) return status; + f_fss_skip_past_delimit(buffer, range, state); + if (F_status_is_error(state->status)) return; if (range->start > range->stop || range->start >= buffer.used) { // EOS or EOL was reached, so it is a valid closing quote. // (for EOL, this is always TRUE, for EOS this could be false but there is no way to know this, so assume TRUE.) - status = F_true; + state->status = F_true; } else { - status = f_fss_is_space(state, buffer, *range); - if (F_status_is_error(status)) return status; + if (f_fss_is_space(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) return; + } } } else { // EOS or EOL was reached, so it is a valid closing quote. // (for EOL, this is always TRUE, for EOS this could be false but there is no way to know this, so assume TRUE.) - status = F_true; + state->status = F_true; } range->start = location; - if (status == F_true) { + if (state->status == F_true) { if (quote) { if (quote_found == f_fss_quote_single_s.string[0] || quote_found == f_fss_quote_double_s.string[0] || quote_found == f_fss_quote_backtick_s.string[0]) { *quote = quote_found; @@ -530,84 +539,87 @@ extern "C" { found->stop = range->start - 1; - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) return status; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) return; while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - return F_status_set_error(F_interrupt); - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) return; } if (buffer.string[range->start] == f_fss_eol_s.string[0]) { // Move the start position to after the EOL. ++range->start; + state->status = F_fss_found_object_content_not; - return F_fss_found_object_content_not; + return; } - status = f_fss_is_space(state, buffer, *range); - if (F_status_is_error(status)) return status; + if (f_fss_is_space(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) return; + } + else { + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) return; - if (status == F_true) { - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) return status; + state->status = F_fss_found_object; - return F_fss_found_object; + return; } if (buffer.string[range->start] != f_fss_placeholder_s.string[0]) { while (range->start <= range->stop && range->start < buffer.used && buffer.string[range->start] != f_fss_eol_s.string[0]) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - return F_status_set_error(F_interrupt); - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) return; } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) return status; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) return; } // while if (range->start >= buffer.used) { found->stop = buffer.used - 1; + state->status = F_data_not_eos; - return F_data_not_eos; + return; } if (range->start > range->stop) { found->stop = range->stop; + state->status = F_data_not_stop; - return F_data_not_stop; + return; } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) return status; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) return; - return F_fss_found_object_not; + state->status = F_fss_found_object_not; + + return; } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) return status; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) return; } // while if (range->start >= buffer.used) { found->stop = buffer.used - 1; + state->status = F_none_eos; - return F_none_eos; + return; } if (range->start > range->stop) { found->stop = range->stop; + state->status = F_none_stop; - return F_none_stop; + return; } } } @@ -615,51 +627,51 @@ extern "C" { // Move the start position to after the EOL. ++range->start; + state->status = F_fss_found_object_not; - return F_fss_found_object_not; + return; } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) return status; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) return; } // while if (range->start >= buffer.used) { found->stop = buffer.used - 1; + state->status = F_end_not_group_eos; - return F_end_not_group_eos; + return; } if (range->start > range->stop) { found->stop = range->stop; + state->status = F_end_not_group_stop; - return F_end_not_group_stop; + return; } } else { - status = F_none; + state->status = F_none; while (range->start <= range->stop && range->start < buffer.used) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } - status = f_fss_is_space(state, buffer, *range); - if (F_status_is_error(status)) return status; - - if (status == F_true) break; + if (f_fss_is_space(buffer, *range, state) == F_false) { + if (F_status_is_error(state->status)) return; + } + else { + break; + } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) break; } // while - if (F_status_is_error(status)) return status; + if (F_status_is_error(state->status)) return; found->stop = range->start - 1; @@ -668,40 +680,58 @@ extern "C" { // Move the start position to after the EOL. ++range->start; - return F_fss_found_object_content_not; + state->status = F_fss_found_object_content_not; + + return; } - status = f_utf_buffer_increment(buffer, range, 1); - if (F_status_is_error(status)) return status; + state->status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(state->status)) return; + + state->status = F_fss_found_object; - return F_fss_found_object; + return; } // Seek to the EOL when no valid object is found. - status = f_fss_seek_to_eol(state, buffer, range); - if (F_status_is_error(status)) return status; + f_fss_seek_to_eol(buffer, range, state); + if (F_status_is_error(state->status)) return; // Move the start position to after the EOL. ++range->start; - return F_fss_found_object_not; + state->status = F_fss_found_object_not; } #endif // !defined(_di_fl_fss_basic_object_read_) || !defined(_di_fl_fss_extended_object_read_) #if !defined(_di_fl_fss_basic_object_write_) || !defined(_di_fl_fss_extended_object_write_) || !defined(_di_fl_fss_extended_content_write_) - f_status_t private_fl_fss_basic_write(const bool object_as, const f_string_static_t object, const uint8_t quote, f_state_t state, f_string_range_t *range, f_string_dynamic_t *destination) { + void private_fl_fss_basic_write(const bool object_as, const f_string_static_t object, const uint8_t quote, f_string_range_t *range, f_string_dynamic_t *destination, f_state_t * const state) { - f_status_t status = f_fss_skip_past_space(state, object, range); - if (F_status_is_error(status)) return status; + f_fss_skip_past_space(object, range, state); + if (F_status_is_error(state->status)) return; + if (state->status == F_data_not) return; - if (status == F_none_eos) return F_data_not_eos; - if (status == F_none_stop) return F_data_not_stop; - if (status == F_none_eol) return F_status_set_error(F_none_eol); - if (status == F_data_not) return status; + if (state->status == F_none_eos) { + state->status = F_data_not_eos; + + return; + } + + if (state->status == F_none_stop) { + state->status = F_data_not_stop; + + return; + } + + if (state->status == F_none_eol) { + state->status = F_status_set_error(F_none_eol); + + return; + } // Ensure that there is room for the potential start and stop quotes, a potential delimit at start, and the potential object open character. - status = f_string_dynamic_increase_by(state.step_small + 5, destination); - if (F_status_is_error(status)) return status; + state->status = f_string_dynamic_increase_by(state->step_small + 5, destination); + if (F_status_is_error(state->status)) return; const f_array_length_t input_start = range->start; const f_array_length_t used_start = destination->used; @@ -713,6 +743,8 @@ extern "C" { f_array_length_t item_total = 0; f_array_length_t i = 0; + uint8_t width = 0; + const f_char_t quote_char = quote ? quote : f_string_ascii_quote_double_s.string[0]; // Use placeholders for potential quote and potential delimited quote to avoid doing things such as memmove(). @@ -727,18 +759,11 @@ extern "C" { commented = F_true; } - uint8_t width = 0; - for (; range->start <= range->stop && range->start < object.used; ) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (object.string[range->start] == f_fss_slash_s.string[0]) { @@ -747,14 +772,9 @@ extern "C" { for (; range->start <= range->stop && range->start < object.used; ++range->start) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) { - status = F_status_set_error(F_interrupt); - - break; - } + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) break; } if (object.string[range->start] == f_fss_slash_s.string[0]) { @@ -772,14 +792,14 @@ extern "C" { // If this is the first quote, then only a single delimit slash is needed. if (item_first == input_start) { - status = f_string_dynamic_increase(state.step_large, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase(state->step_large, destination); + if (F_status_is_error(state->status)) break; destination->string[destination->used++] = f_fss_slash_s.string[0]; } else { - status = f_string_dynamic_increase_by(item_total, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(item_total, destination); + if (F_status_is_error(state->status)) break; for (i = 0; i < item_total; ++i) { destination->string[destination->used++] = f_fss_slash_s.string[0]; @@ -787,8 +807,8 @@ extern "C" { } } - status = f_string_dynamic_increase_by(item_total, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(item_total, destination); + if (F_status_is_error(state->status)) break; for (i = 0; i < item_total; ++i) { destination->string[destination->used++] = f_fss_slash_s.string[0]; @@ -798,7 +818,7 @@ extern "C" { } if (object.string[range->start] == f_fss_eol_s.string[0]) { - status = F_status_set_error(F_none_eol); + state->status = F_status_set_error(F_none_eol); break; } @@ -806,13 +826,13 @@ extern "C" { if (object.string[range->start] == quote_char) { item_first = range->start++; - status = f_fss_skip_past_delimit(state, object, range); - if (F_status_is_error(status)) break; + f_fss_skip_past_delimit(object, range, state); + if (F_status_is_error(state->status)) break; if (range->start > range->stop || range->start >= object.used) { - status = f_string_dynamic_increase_by(item_total + 1, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(item_total + 1, destination); + if (F_status_is_error(state->status)) break; for (i = 0; i < item_total; ++i) { destination->string[destination->used++] = f_fss_slash_s.string[0]; @@ -823,21 +843,21 @@ extern "C" { break; } - // if any space is found after a quote after a slash, then this must be delimited and quote. - status = f_fss_is_space(state, object, *range); - if (F_status_is_error(status)) break; - - if (status == F_true) { + // If any space is found after a quote after a slash, then this must be delimited and quote. + if (f_fss_is_space(object, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; + } + else { if (object.string[range->start] == f_fss_eol_s.string[0]) { - status = F_status_set_error(F_none_eol); + state->status = F_status_set_error(F_none_eol); break; } quoted_is = F_true; - status = f_string_dynamic_increase_by(item_total + 1, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(item_total + 1, destination); + if (F_status_is_error(state->status)) break; // Add the slashes that delimit the slashes. if (item_first == input_start) { @@ -852,8 +872,8 @@ extern "C" { width = macro_f_utf_byte_width(object.string[range->start]); - status = f_string_dynamic_increase_by(item_total + width + 1, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(item_total + width + 1, destination); + if (F_status_is_error(state->status)) break; for (i = 0; i < item_total; ++i) { destination->string[destination->used++] = f_fss_slash_s.string[0]; @@ -872,8 +892,8 @@ extern "C" { commented = F_true; } - status = f_string_dynamic_increase_by(item_total + 1, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(item_total + 1, destination); + if (F_status_is_error(state->status)) break; for (i = 0; i < item_total; ++i) { destination->string[destination->used++] = f_fss_slash_s.string[0]; @@ -886,12 +906,12 @@ extern "C" { else { // If any space is found, then this must be quote. - status = f_fss_is_space(state, object, *range); - if (F_status_is_error(status)) break; - - if (status == F_true) { + if (f_fss_is_space(object, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; + } + else { if (object.string[range->start] == f_fss_eol_s.string[0]) { - status = F_status_set_error(F_none_eol); + state->status = F_status_set_error(F_none_eol); break; } @@ -901,8 +921,8 @@ extern "C" { width = macro_f_utf_byte_width(object.string[range->start]); - status = f_string_dynamic_increase_by(item_total + width, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(item_total + width, destination); + if (F_status_is_error(state->status)) break; // There is nothing to delimit, so all slashes should be printed as is. for (i = 0; i < item_total; ++i) { @@ -919,19 +939,19 @@ extern "C" { // The very first quote, must be escaped, when quoting is disabled. if (item_first == input_start) { - status = f_string_dynamic_increase(state.step_large, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase(state->step_large, destination); + if (F_status_is_error(state->status)) break; destination->string[used_start + 1] = f_fss_slash_s.string[0]; } - status = f_fss_skip_past_delimit(state, object, range); - if (F_status_is_error(status)) return status; + f_fss_skip_past_delimit(object, range, state); + if (F_status_is_error(state->status)) return; if (range->start > range->stop || range->start >= object.used) { - status = f_string_dynamic_increase(state.step_large, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase(state->step_large, destination); + if (F_status_is_error(state->status)) break; destination->string[destination->used++] = quote_char; @@ -939,8 +959,8 @@ extern "C" { } if (object.string[range->start] == quote_char) { - status = f_string_dynamic_increase(state.step_large, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase(state->step_large, destination); + if (F_status_is_error(state->status)) break; destination->string[destination->used++] = quote_char; @@ -949,19 +969,19 @@ extern "C" { } // If any space is found, then this must be quote. - status = f_fss_is_space(state, object, *range); - if (F_status_is_error(status)) break; - - if (status == F_true) { + if (f_fss_is_space(object, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; + } + else { if (object.string[range->start] == f_fss_eol_s.string[0]) { - status = F_status_set_error(F_none_eol); + state->status = F_status_set_error(F_none_eol); break; } if (item_first != input_start) { - status = f_string_dynamic_increase(state.step_large, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase(state->step_large, destination); + if (F_status_is_error(state->status)) break; destination->string[destination->used++] = f_fss_slash_s.string[0]; } @@ -971,8 +991,8 @@ extern "C" { width = macro_f_utf_byte_width(object.string[range->start]); - status = f_string_dynamic_increase_by(width + 1, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(width + 1, destination); + if (F_status_is_error(state->status)) break; destination->string[destination->used++] = quote_char; @@ -981,47 +1001,47 @@ extern "C" { } // for } else if (object.string[range->start] == f_fss_eol_s.string[0]) { - status = F_status_set_error(F_none_eol); + state->status = F_status_set_error(F_none_eol); break; } else if (object.string[range->start] != f_fss_placeholder_s.string[0]) { if (!quoted_is) { - status = f_fss_is_space(state, object, *range); - if (F_status_is_error(status)) break; - - if (status == F_true) { + if (f_fss_is_space(object, *range, state) == F_false) { + if (F_status_is_error(state->status)) break; + } + else { quoted_is = F_true; } } width = macro_f_utf_byte_width(object.string[range->start]); - status = f_string_dynamic_increase_by(width, destination); - if (F_status_is_error(status)) break; + state->status = f_string_dynamic_increase_by(width, destination); + if (F_status_is_error(state->status)) break; for (i = 0; i < width; ++i) { destination->string[destination->used++] = object.string[range->start + i]; } // for } - status = f_utf_buffer_increment(object, range, 1); - if (F_status_is_error(status)) break; + state->status = f_utf_buffer_increment(object, range, 1); + if (F_status_is_error(state->status)) break; } // for - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = used_start; - return status; + return; } if (quoted_is) { - status = f_string_dynamic_increase_by(state.step_small + 2, destination); + f_string_dynamic_increase_by(state->step_small + 2, destination); - if (F_status_is_error(status)) { + if (F_status_is_error(state->status)) { destination->used = used_start; - return status; + return; } destination->string[used_start] = quote_char; @@ -1032,13 +1052,13 @@ extern "C" { for (i = input_start + 1; i <= range->stop && i < object.used; ++i) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); + if (state->interrupt) { + state->interrupt((void *) &state, 0); - if (F_status_set_fine(status) == F_interrupt) { + if (F_status_set_fine(state->status) == F_interrupt) { destination->used = used_start; - return F_status_set_error(F_interrupt); + return; } } @@ -1051,24 +1071,24 @@ extern "C" { range_i.start = i; - status = f_fss_is_space(state, object, range_i); + if (f_fss_is_space(object, range_i, state) == F_false) { + if (F_status_is_error(state->status)) { + destination->used = used_start; - if (F_status_is_error(status)) { - destination->used = used_start; + return; + } - return status; + destination->string[used_start + 1] = f_fss_placeholder_s.string[0]; } - - if (status == F_true) { + else { if (object.string[i] == f_fss_eol_s.string[0]) { destination->used = used_start; - return F_status_set_error(F_none_eol); + state->status = F_status_set_error(F_none_eol); + + return; } } - else { - destination->string[used_start + 1] = f_fss_placeholder_s.string[0]; - } } } } @@ -1076,16 +1096,14 @@ extern "C" { destination->string[used_start] = f_fss_slash_s.string[0]; } - if (range->start > range->stop) return F_none_stop; - - return F_none_eos; + if (range->start > range->stop) state->status = F_none_stop; + else state->status = F_none_eos; } #endif // !defined(_di_fl_fss_basic_object_write_) || !defined(_di_fl_fss_extended_object_write_) || !defined(_di_fl_fss_extended_content_write_) #if !defined(_di_fl_fss_basic_object_write_) || !defined(_di_fl_fss_extended_object_write_) - f_status_t private_fl_fss_basic_write_object_trim(const uint8_t quote, const f_array_length_t used_start, f_state_t state, f_string_dynamic_t * const destination) { + void private_fl_fss_basic_write_object_trim(const uint8_t quote, const f_array_length_t used_start, f_string_dynamic_t * const destination, f_state_t * const state) { - f_status_t status = F_none; f_string_range_t destination_range = macro_f_string_range_t_initialize2(destination->used); f_array_length_t i = 0; @@ -1095,13 +1113,13 @@ extern "C" { // If there are any spaces, then this will be quote so find the first non-placeholder character. for (; destination_range.start < destination->used; ++destination_range.start) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); + if (state->interrupt) { + state->interrupt((void *) &state, 0); - if (F_status_set_fine(status) == F_interrupt) { + if (F_status_set_fine(state->status) == F_interrupt) { destination->used = used_start; - return F_status_set_error(F_interrupt); + return; } } @@ -1113,28 +1131,28 @@ extern "C" { for (++destination_range.start; destination_range.start < destination->used; ++destination_range.start) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); + if (state->interrupt) { + state->interrupt((void *) &state, 0); - if (F_status_set_fine(status) == F_interrupt) { + if (F_status_set_fine(state->status) == F_interrupt) { destination->used = used_start; - return F_status_set_error(F_interrupt); + return; } } if (destination->string[destination_range.start] == f_fss_placeholder_s.string[0]) continue; - status = f_fss_is_space(state, *destination, destination_range); + if (f_fss_is_space(*destination, destination_range, state) == F_false) { + if (F_status_is_error(state->status)) { + destination->used = used_start; - if (F_status_is_error(status)) { - destination->used = used_start; + return; + } - return status; + break; } - if (status == F_false) break; - width = macro_f_utf_byte_width(destination->string[destination_range.start]); for (i = 0; i < width; ++i) { @@ -1145,13 +1163,13 @@ extern "C" { // Find the last quote. for (destination_range.start = destination->used - 1; destination_range.start > front; --destination_range.start) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); + if (state->interrupt) { + state->interrupt((void *) &state, 0); - if (F_status_set_fine(status) == F_interrupt) { + if (F_status_set_fine(state->status) == F_interrupt) { destination->used = used_start; - return F_status_set_error(F_interrupt); + return; } } @@ -1166,30 +1184,31 @@ extern "C" { for (; destination_range.start > front; --destination_range.start) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); + if (state->interrupt) { + state->interrupt((void *) &state, 0); - if (F_status_set_fine(status) == F_interrupt) { + if (F_status_set_fine(state->status) == F_interrupt) { destination->used = used_start; - return F_status_set_error(F_interrupt); + return; } } if (destination->string[destination_range.start] == f_fss_placeholder_s.string[0]) continue; - status = f_fss_is_space(state, *destination, destination_range); + if (f_fss_is_space(*destination, destination_range, state) == F_false) { - // When going backwards, getting incomplete UTF-8 sequences is not an error. - if (F_status_set_fine(status) == F_complete_not_utf) continue; + // When going backwards, getting incomplete UTF-8 sequences is not an error. + if (F_status_set_fine(state->status) == F_complete_not_utf) continue; - if (F_status_is_error(status)) { - destination->used = used_start; + if (F_status_is_error(state->status)) { + destination->used = used_start; - return status; - } + return; + } - if (status == F_false) break; + break; + } width = macro_f_utf_byte_width(destination->string[destination_range.start]); @@ -1201,25 +1220,27 @@ extern "C" { // If there is no whitespace between the quotes, post-trimming, then remove the quotes. for (destination_range.start = front; destination_range.start < rear; ++destination_range.start) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); + if (state->interrupt) { + state->interrupt((void *) &state, 0); - if (F_status_set_fine(status) == F_interrupt) { + if (F_status_set_fine(state->status) == F_interrupt) { destination->used = used_start; - return F_status_set_error(F_interrupt); + return; } } - status = f_fss_is_space(state, *destination, destination_range); - - if (F_status_is_error(status)) { - destination->used = used_start; + if (f_fss_is_space(*destination, destination_range, state) == F_false) { + if (F_status_is_error(state->status)) { + destination->used = used_start; - return status; + return; + } + } + else { + break; } - if (status == F_true) break; } // for if (destination_range.start == rear) { @@ -1228,7 +1249,7 @@ extern "C" { } } - return F_none; + state->status = F_none; } #endif // !defined(_di_fl_fss_basic_object_write_) || !defined(_di_fl_fss_extended_object_write_) diff --git a/level_1/fl_fss/c/private-fss.h b/level_1/fl_fss/c/private-fss.h index 8e743e6..30e51f5 100644 --- a/level_1/fl_fss/c/private-fss.h +++ b/level_1/fl_fss/c/private-fss.h @@ -20,6 +20,10 @@ extern "C" { * * @param buffer * The buffer to seek through. + * @param range + * The start/stop location within the buffer string to process. + * @param destination + * The buffer where the bytes are written to. * @param state * A state for providing flags and handling interrupts during long running operations. * There is no print_error(). @@ -29,17 +33,13 @@ extern "C" { * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. * Error bit designates an error but must be passed along with F_interrupt. * All other statuses are ignored. - * @param range - * The start/stop location within the buffer string to process. - * @param destination - * The buffer where the bytes are written to. * - * @return - * F_none on success. + * This alters state.status: + * F_none on success. * - * F_interrupt (with error bit) if stopping due to an interrupt. + * F_interrupt (with error bit) if stopping due to an interrupt. * - * Errors (with error bit) from: f_string_dynamic_increase(). + * Errors (with error bit) from: f_string_dynamic_increase(). * * @see f_string_dynamic_increase() * @see fl_fss_basic_list_content_write() @@ -47,7 +47,7 @@ extern "C" { * @see fl_fss_extended_list_content_write() */ #if !defined(_di_fl_fss_basic_list_content_write_) || !defined(_di_fl_fss_extended_list_content_write_) || !defined(_di_fl_fss_embedded_list_content_write_) - extern f_status_t private_fl_fss_basic_list_write_add_until_end(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination) F_attribute_visibility_internal_d; + extern void private_fl_fss_basic_list_write_add_until_end(const f_string_static_t buffer, f_string_range_t * const range, f_string_dynamic_t * const destination, f_state_t * const state) F_attribute_visibility_internal_d; #endif // !defined(_di_fl_fss_basic_list_content_write_) || !defined(_di_fl_fss_extended_list_content_write_) || !defined(_di_fl_fss_embedded_list_content_write_) /** @@ -55,6 +55,8 @@ extern "C" { * * @param used_start * The destination.used value before any operations were performed. + * @param destination + * The buffer where the object is written to. * @param state * A state for providing flags and handling interrupts during long running operations. * There is no print_error(). @@ -64,22 +66,20 @@ extern "C" { * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. * Error bit designates an error but must be passed along with F_interrupt. * All other statuses are ignored. - * @param destination - * The buffer where the object is written to. * - * @return - * F_none on success. + * This alters state.status: + * F_none on success. * - * F_interrupt (with error bit) if stopping due to an interrupt. + * F_interrupt (with error bit) if stopping due to an interrupt. * - * Errors (with error bit) from: f_fss_is_space(). + * Errors (with error bit) from: f_fss_is_space(). * * @see f_fss_is_space() * @see fl_fss_basic_list_object_write() * @see fl_fss_extended_list_object_write() */ #if !defined(_di_fl_fss_basic_list_object_write_) || !defined(_di_fl_fss_extended_list_object_write_) - extern f_status_t private_fl_fss_basic_list_write_object_trim(const f_array_length_t used_start, f_state_t state, f_string_dynamic_t * const destination) F_attribute_visibility_internal_d; + extern void private_fl_fss_basic_list_write_object_trim(const f_array_length_t used_start, f_string_dynamic_t * const destination, f_state_t * const state) F_attribute_visibility_internal_d; #endif // !defined(_di_fl_fss_basic_list_object_write_) || !defined(_di_fl_fss_extended_list_object_write_) /** @@ -95,15 +95,6 @@ extern "C" { * * As Object, this checks if the first graph character is a comment character '#', or an escaped comment character '#'. * As Content, this does nothing special in regards to a leading '#'. - * @param state - * A state for providing flags and handling interrupts during long running operations. - * There is no print_error(). - * There is no functions structure. - * There is no data structure passed to these functions. - * - * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. - * Error bit designates an error but must be passed along with F_interrupt. - * All other statuses are ignored. * @param range * The start/stop location within the buffer to be processed. * The start location will be updated as the buffer is being processed. @@ -117,29 +108,38 @@ extern "C" { * @param delimits * An array of delimits detected during processing. * The caller is expected to decide if and when to process them. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * There is no print_error(). + * There is no functions structure. + * There is no data structure passed to these functions. * - * @return - * F_fss_found_object on success and object was found (start location is at end of object). - * F_fss_found_object_not on success and no object was found (start location is after character designating this is not an object). - * F_none_eos on success after reaching the end of the buffer (a valid object is not yet confirmed). - * F_none_stop on success after reaching stopping point (a valid object is not yet confirmed). - * F_data_not_eos no objects found after reaching the end of the buffer (essentially only comments are found). - * F_data_not_stop no data found after reaching stopping point (essentially only comments are found). - * F_end_not_group_eos if EOS was reached before the a group termination was reached. - * F_end_not_group_stop if stop point was reached before the a group termination was reached. - * - * F_interrupt (with error bit) if stopping due to an interrupt. - * F_none_eol (with error bit) after reaching an EOL, which is not supported by the standard. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_array_lengths_increase(). - * Errors (with error bit) from: f_array_lengths_increase_by(). - * Errors (with error bit) from: f_fss_is_graph(). - * Errors (with error bit) from: f_fss_is_space(). - * Errors (with error bit) from: f_fss_is_zero_width(). - * Errors (with error bit) from: f_fss_skip_past_delimit(). - * Errors (with error bit) from: f_fss_skip_past_space(). - * Errors (with error bit) from: f_utf_buffer_increment(). + * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. + * Error bit designates an error but must be passed along with F_interrupt. + * All other statuses are ignored. + * + * This alters state.status: + * F_fss_found_object on success and object was found (start location is at end of object). + * F_fss_found_object_not on success and no object was found (start location is after character designating this is not an object). + * F_none_eos on success after reaching the end of the buffer (a valid object is not yet confirmed). + * F_none_stop on success after reaching stopping point (a valid object is not yet confirmed). + * F_data_not_eos no objects found after reaching the end of the buffer (essentially only comments are found). + * F_data_not_stop no data found after reaching stopping point (essentially only comments are found). + * F_end_not_group_eos if EOS was reached before the a group termination was reached. + * F_end_not_group_stop if stop point was reached before the a group termination was reached. + * + * F_interrupt (with error bit) if stopping due to an interrupt. + * F_none_eol (with error bit) after reaching an EOL, which is not supported by the standard. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_array_lengths_increase(). + * Errors (with error bit) from: f_array_lengths_increase_by(). + * Errors (with error bit) from: f_fss_is_graph(). + * Errors (with error bit) from: f_fss_is_space(). + * Errors (with error bit) from: f_fss_is_zero_width(). + * Errors (with error bit) from: f_fss_skip_past_delimit(). + * Errors (with error bit) from: f_fss_skip_past_space(). + * Errors (with error bit) from: f_utf_buffer_increment(). * * @see f_array_lengths_increase() * @see f_array_lengths_increase_by() @@ -154,7 +154,7 @@ extern "C" { * @see fl_fss_extended_content_read() */ #if !defined(_di_fl_fss_basic_object_read_) || !defined(_di_fl_fss_extended_object_read_) || !defined(_di_fl_fss_extended_content_read_) - extern f_status_t private_fl_fss_basic_read(const f_string_static_t buffer, const bool object_as, f_state_t state, f_string_range_t * const range, f_fss_object_t * const found, uint8_t * const quote, f_fss_delimits_t * const delimits) F_attribute_visibility_internal_d; + extern void private_fl_fss_basic_read(const f_string_static_t buffer, const bool object_as, f_string_range_t * const range, f_fss_object_t * const found, uint8_t * const quote, f_fss_delimits_t * const delimits, f_state_t * const state) F_attribute_visibility_internal_d; #endif // !defined(_di_fl_fss_basic_object_read_) || !defined(_di_fl_fss_extended_object_read_) || !defined(_di_fl_fss_extended_content_read_) /** @@ -175,6 +175,10 @@ extern "C" { * @param quote * If 0, then double quotes are auto-inserted, when required. * Otherwise, this is quote character to wrap the object in when writing. + * @param range + * The start/stop location within the object string to write as an object. + * @param destination + * The buffer where the object is written to. * @param state * A state for providing flags and handling interrupts during long running operations. * There is no print_error(). @@ -184,28 +188,24 @@ extern "C" { * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. * Error bit designates an error but must be passed along with F_interrupt. * All other statuses are ignored. - * @param range - * The start/stop location within the object string to write as an object. - * @param destination - * The buffer where the object is written to. * - * @return - * F_none on success. - * F_none_eos on success after reaching the end of the buffer. - * F_none_stop on success after reaching the range stop. - * F_data_not_stop no data to write due start location being greater than stop location. - * F_data_not_eos no data to write due start location being greater than or equal to buffer size. + * This alters state.status: + * F_none on success. + * F_none_eos on success after reaching the end of the buffer. + * F_none_stop on success after reaching the range stop. + * F_data_not_stop no data to write due start location being greater than stop location. + * F_data_not_eos no data to write due start location being greater than or equal to buffer size. * - * F_interrupt (with error bit) if stopping due to an interrupt. - * F_none_eol (with error bit) after reaching an EOL, which is not supported by the standard. - * F_parameter (with error bit) if a parameter is invalid. + * F_interrupt (with error bit) if stopping due to an interrupt. + * F_none_eol (with error bit) after reaching an EOL, which is not supported by the standard. + * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_fss_is_space(). - * Errors (with error bit) from: f_fss_skip_past_delimit(). - * Errors (with error bit) from: f_fss_skip_past_space(). - * Errors (with error bit) from: f_string_dynamic_increase(). - * Errors (with error bit) from: f_string_dynamic_increase_by(). - * Errors (with error bit) from: f_utf_buffer_increment(). + * Errors (with error bit) from: f_fss_is_space(). + * Errors (with error bit) from: f_fss_skip_past_delimit(). + * Errors (with error bit) from: f_fss_skip_past_space(). + * Errors (with error bit) from: f_string_dynamic_increase(). + * Errors (with error bit) from: f_string_dynamic_increase_by(). + * Errors (with error bit) from: f_utf_buffer_increment(). * * @see f_fss_is_space() * @see f_fss_skip_past_delimit() @@ -218,7 +218,7 @@ extern "C" { * @see fl_fss_extended_content_write() */ #if !defined(fl_fss_basic_object_write) || !defined(fl_fss_extended_object_write) || !defined(_di_fl_fss_extended_content_write_) - extern f_status_t private_fl_fss_basic_write(const bool object_as, const f_string_static_t object, const uint8_t quote, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination) F_attribute_visibility_internal_d; + extern void private_fl_fss_basic_write(const bool object_as, const f_string_static_t object, const uint8_t quote, f_string_range_t * const range, f_string_dynamic_t * const destination, f_state_t * const state) F_attribute_visibility_internal_d; #endif // !defined(fl_fss_basic_object_write) || !defined(fl_fss_extended_object_write) || !defined(_di_fl_fss_extended_content_write_) /** @@ -229,6 +229,8 @@ extern "C" { * Otherwise, this is quote character to wrap the object in when writing. * @param used_start * The destination.used value before any operations were perfomed. + * @param destination + * The buffer where the object is written to. * @param state * A state for providing flags and handling interrupts during long running operations. * There is no print_error(). @@ -238,22 +240,20 @@ extern "C" { * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. * Error bit designates an error but must be passed along with F_interrupt. * All other statuses are ignored. - * @param destination - * The buffer where the object is written to. * - * @return - * F_none on success. + * This alters state.status: + * F_none on success. * - * F_interrupt (with error bit) if stopping due to an interrupt. + * F_interrupt (with error bit) if stopping due to an interrupt. * - * Errors (with error bit) from: f_fss_is_space(). + * Errors (with error bit) from: f_fss_is_space(). * * @see f_fss_is_space() * @see fl_fss_basic_object_write() * @see fl_fss_extended_object_write() */ #if !defined(_di_fl_fss_basic_object_write_) || !defined(_di_fl_fss_extended_object_write_) - extern f_status_t private_fl_fss_basic_write_object_trim(const uint8_t quote, const f_array_length_t used_start, f_state_t state, f_string_dynamic_t * const destination) F_attribute_visibility_internal_d; + extern void private_fl_fss_basic_write_object_trim(const uint8_t quote, const f_array_length_t used_start, f_string_dynamic_t * const destination, f_state_t * const state) F_attribute_visibility_internal_d; #endif // !defined(_di_fl_fss_basic_object_write_) || !defined(_di_fl_fss_extended_object_write_) #ifdef __cplusplus diff --git a/level_1/fl_iki/c/iki.c b/level_1/fl_iki/c/iki.c index 37fef36..3b55482 100644 --- a/level_1/fl_iki/c/iki.c +++ b/level_1/fl_iki/c/iki.c @@ -5,21 +5,22 @@ extern "C" { #endif #ifndef _di_fl_iki_read_ - f_status_t fl_iki_read(const f_state_t state, f_string_static_t * const buffer, f_string_range_t * const range, f_iki_data_t * const data) { + void fl_iki_read(f_string_static_t * const buffer, f_string_range_t * const range, f_iki_data_t * const data, f_state_t * const state) { #ifndef _di_level_1_parameter_checking_ - if (!buffer) return F_status_set_error(F_parameter); - if (!range) return F_status_set_error(F_parameter); - #endif // _di_level_1_parameter_checking_ + if (!state) return; + + if (!buffer || !range) { + state->status = F_status_set_error(F_parameter); - f_status_t status = F_none; + return; + } + #endif // _di_level_1_parameter_checking_ do { - status = f_iki_read(state, buffer, range, data); - if (F_status_is_error(status)) return status; + f_iki_read(buffer, range, data, state); + if (F_status_is_error(state->status)) return; } while (range->start <= range->stop && range->start < buffer->used); - - return status; } #endif // _di_fl_iki_read_ diff --git a/level_1/fl_iki/c/iki.h b/level_1/fl_iki/c/iki.h index cfae53b..14495a2 100644 --- a/level_1/fl_iki/c/iki.h +++ b/level_1/fl_iki/c/iki.h @@ -35,8 +35,6 @@ extern "C" { * This does not verify if any vocabulary name is known. * This only finds complete vocabulary names and their respective content. * - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param buffer * The string to process. * @param range @@ -46,25 +44,28 @@ extern "C" { * A start location past the stop location or buffer used means that the entire range was processed. * @param data * The IKI data. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * This must not be NULL. * - * @return - * F_none on success and an IKI vocabulary name was found. - * F_none_stop on success and an IKI vocabulary name was found and stop point was reached. - * F_none_eos on success and an IKI vocabulary name was found and end of string was reached. - * F_complete_not_utf_eos on success and EOS was reached, but at an incomplete UTF-8 sequence. - * F_complete_not_utf_stop on success and stop point was reached, but at an incomplete UTF-8 sequence. - * F_data_not_eos on success and EOS was reached, but there were no IKI vocabularie names found. - * F_data_not_stop on success and stop point was reached, but there were no IKI vocabularie names found. + * This alters state.status: + * F_none on success and an IKI vocabulary name was found. + * F_none_stop on success and an IKI vocabulary name was found and stop point was reached. + * F_none_eos on success and an IKI vocabulary name was found and end of string was reached. + * F_complete_not_utf_eos on success and EOS was reached, but at an incomplete UTF-8 sequence. + * F_complete_not_utf_stop on success and stop point was reached, but at an incomplete UTF-8 sequence. + * F_data_not_eos on success and EOS was reached, but there were no IKI vocabularie names found. + * F_data_not_stop on success and stop point was reached, but there were no IKI vocabularie names found. * - * F_parameter (with error bit) if a parameter is invalid. + * F_parameter (with error bit) if a parameter is invalid. * - * Success from: f_iki_read(). - * Errors (with error bit) from: f_iki_read(). + * Success from: f_iki_read(). + * Errors (with error bit) from: f_iki_read(). * * @see f_iki_read() */ #ifndef _di_fl_iki_read_ - extern f_status_t fl_iki_read(const f_state_t state, f_string_static_t * const buffer, f_string_range_t * const range, f_iki_data_t * const data); + extern void fl_iki_read(f_string_static_t * const buffer, f_string_range_t * const range, f_iki_data_t * const data, f_state_t * const state); #endif // _di_fl_iki_read_ #ifdef __cplusplus diff --git a/level_2/fll_error/c/error.c b/level_2/fll_error/c/error.c index 7c15fd4..4e06e90 100644 --- a/level_2/fll_error/c/error.c +++ b/level_2/fll_error/c/error.c @@ -106,7 +106,7 @@ extern "C" { fl_print_format("%[%QFailed to %Q %Q '%]", print.to, print.context, print.prefix, operation, type_name, print.context); fl_print_format("%[%Q%]", print.to, print.notable, name, print.notable); - fl_print_format("%[', already in an error state.%]%r", print.to, print.context, print.context, f_string_eol_s); + fl_print_format("%[', already in an error state->%]%r", print.to, print.context, print.context, f_string_eol_s); funlockfile(print.to.stream); } diff --git a/level_2/fll_file/c/file.c b/level_2/fll_file/c/file.c index 3a72ffc..aa8c189 100644 --- a/level_2/fll_file/c/file.c +++ b/level_2/fll_file/c/file.c @@ -15,47 +15,62 @@ extern "C" { #endif // _di_fll_file_mode_set_all_ #ifndef _di_fll_file_move_ - f_status_t fll_file_move(const f_string_static_t source, const f_string_static_t destination, const fl_directory_recurse_t recurse) { + void fll_file_move(const f_string_static_t source, const f_string_static_t destination, f_directory_recurse_t * const recurse) { + #ifndef _di_level_2_parameter_checking_ + if (!recurse) return; + #endif // _di_level_2_parameter_checking_ + + if (!source.used || !destination.used) { + recurse->state.status = F_data_not; - if (!source.used || !destination.used) return F_data_not; + return; + } - f_status_t status = f_file_rename(source, destination); + recurse->state.status = f_file_rename(source, destination); - if (F_status_set_fine(status) != F_mount) { - if (status == F_none && (!recurse.output.stream || recurse.output.id != -1) && recurse.verbose) { - recurse.verbose(recurse.output, source, destination); + if (F_status_set_fine(recurse->state.status) != F_mount) { + if (recurse->state.status == F_none && recurse->verbose) { + recurse->verbose(source, destination, recurse); } - return status; + return; } - status = f_file_is(source, F_file_type_directory_d, !(recurse.flag & f_file_stat_flag_reference_e)); + recurse->state.status = f_file_is(source, F_file_type_directory_d, !(recurse->flag & f_file_stat_flag_reference_e)); + + if (recurse->state.status == F_file_found_not) { + recurse->state.status = F_status_set_error(recurse->state.status); + } - if (status == F_file_found_not) return F_status_set_error(status); - if (F_status_is_error(status)) return status; + if (F_status_is_error(recurse->state.status)) return; - if (status == F_true) { - status = fl_directory_clone(source, destination, recurse); - if (F_status_is_error(status)) return status; + if (recurse->state.status == F_true) { + const uint8_t flag_original = recurse->flag; - status = f_directory_remove(source, recurse.depth_max, F_false); + recurse->flag = f_directory_recurse_flag_clone_e; - if (status == F_none && (!recurse.output.stream || recurse.output.id != -1) && recurse.verbose) { - recurse.verbose(recurse.output, source, destination); + fl_directory_copy(source, destination, recurse); + + recurse->flag = flag_original; + + if (F_status_is_error(recurse->state.status)) return; + + recurse->state.status = f_directory_remove(source, recurse->max_depth, F_false); + + if (recurse->state.status == F_none && recurse->verbose) { + recurse->verbose(source, destination, recurse); } } else { - status = f_file_clone(source, destination, recurse.size_block, recurse.flag); - if (F_status_is_error(status)) return status; + recurse->state.status = f_file_clone(source, destination, recurse->size_block, recurse->flag); + if (F_status_is_error(recurse->state.status)) return; - status = f_file_remove(source); + recurse->state.status = f_file_remove(source); - if (status == F_none && (!recurse.output.stream || recurse.output.id != -1) && recurse.verbose) { - recurse.verbose(recurse.output, source, destination); + if (recurse->state.status == F_none && recurse->verbose) { + recurse->verbose(source, destination, recurse); } } - - return status; } #endif // _di_fll_file_move_ diff --git a/level_2/fll_file/c/file.h b/level_2/fll_file/c/file.h index da7f723..ea66076 100644 --- a/level_2/fll_file/c/file.h +++ b/level_2/fll_file/c/file.h @@ -90,43 +90,44 @@ extern "C" { * The path to copy to. * @param recurse * The directory recurse data. - * - * @return - * F_none on success. - * - * F_access_denied (with error bit) on access denied. - * F_buffer (with error bit) if the buffer is invalid. - * F_busy (with error bit) if file system is too busy to perform write. - * F_directory (with error bit) if a supposed directory in path is not actually a directory. - * F_directory_empty_not (with error bit) if the destination is a non-empty directory. - * F_file_found_not (with error bit) if file at path was not found. - * F_file_type_directory (with error bit) if destination is a directory but source is not. - * F_filesystem_quota_block (with error bit) if file system's disk blocks or inodes are exhausted. - * F_link (with error bit) if source or destination has the maxiumum associated links. - * F_loop (with error bit) on loop error. - * F_memory_not (with error bit) if out of memory. - * F_name (with error bit) on path name error. - * F_parameter (with error bit) if a parameter is invalid. - * F_prohibited (with error bit) if file system does not allow for making changes. - * F_read_only (with error bit) if file is read-only. - * F_space_not (with error bit) if file system is out of space (or file system quota is reached). - * F_failure (with error bit) for any other error, failures might be populated with individual status codes. - * - * Errors (with error bit) from: f_directory_remove_custom(). - * Errors (with error bit) from: f_file_is(). - * Errors (with error bit) from: f_file_remove(). - * Errors (with error bit) from: f_file_rename(). - * Errors (with error bit) from: fl_directory_clone(). + * This must not be NULL. + * + * This alters recurse.state.status: + * F_none on success. + * + * F_access_denied (with error bit) on access denied. + * F_buffer (with error bit) if the buffer is invalid. + * F_busy (with error bit) if file system is too busy to perform write. + * F_directory (with error bit) if a supposed directory in path is not actually a directory. + * F_directory_empty_not (with error bit) if the destination is a non-empty directory. + * F_file_found_not (with error bit) if file at path was not found. + * F_file_type_directory (with error bit) if destination is a directory but source is not. + * F_filesystem_quota_block (with error bit) if file system's disk blocks or inodes are exhausted. + * F_link (with error bit) if source or destination has the maxiumum associated links. + * F_loop (with error bit) on loop error. + * F_memory_not (with error bit) if out of memory. + * F_name (with error bit) on path name error. + * F_parameter (with error bit) if a parameter is invalid. + * F_prohibited (with error bit) if file system does not allow for making changes. + * F_read_only (with error bit) if file is read-only. + * F_space_not (with error bit) if file system is out of space (or file system quota is reached). + * F_failure (with error bit) for any other error, failures might be populated with individual status codes. + * + * Errors (with error bit) from: f_directory_remove_custom(). + * Errors (with error bit) from: f_file_is(). + * Errors (with error bit) from: f_file_remove(). + * Errors (with error bit) from: f_file_rename(). + * Errors (with error bit) from: fl_directory_copy(). * * @see f_directory_remove() * @see f_directory_remove_custom() * @see f_file_is() * @see f_file_remove() * @see f_file_rename() - * @see fl_directory_clone() + * @see fl_directory_copy() */ #ifndef _di_fll_file_move_ - extern f_status_t fll_file_move(const f_string_static_t source, const f_string_static_t destination, const fl_directory_recurse_t recurse); + extern void fll_file_move(const f_string_static_t source, const f_string_static_t destination, f_directory_recurse_t * const recurse); #endif // _di_fll_file_move_ /** diff --git a/level_2/fll_file/c/private-file.c b/level_2/fll_file/c/private-file.c index 2b627af..f459d4f 100644 --- a/level_2/fll_file/c/private-file.c +++ b/level_2/fll_file/c/private-file.c @@ -22,7 +22,7 @@ extern "C" { status = fl_directory_list(path, 0, 0, dereference, &listing); if (F_status_is_error(status)) { - macro_f_directory_listing_t_delete_simple(listing); + f_directory_listing_delete(&listing); return status; } @@ -98,7 +98,7 @@ extern "C" { } } // for - f_string_dynamics_resize(0, &listing.directory); + f_directory_listing_delete(&listing); if (F_status_is_error(status)) return status; @@ -123,7 +123,7 @@ extern "C" { status = fl_directory_list(path, 0, 0, dereference, &listing); if (F_status_is_error(status)) { - macro_f_directory_listing_t_delete_simple(listing); + f_directory_listing_delete(&listing); return status; } @@ -199,7 +199,7 @@ extern "C" { } // for } - f_string_dynamics_resize(0, &listing.directory); + f_directory_listing_delete(&listing); if (F_status_is_error(status)) return status; diff --git a/level_2/fll_fss/c/fss/basic.c b/level_2/fll_fss/c/fss/basic.c index b88ab12..94acf4b 100644 --- a/level_2/fll_fss/c/fss/basic.c +++ b/level_2/fll_fss/c/fss/basic.c @@ -5,16 +5,18 @@ extern "C" { #endif #ifndef _di_fll_fss_basic_read_ - f_status_t fll_fss_basic_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_objects_t * const objects, f_fss_contents_t * const contents, f_uint8s_t * const objects_quoted, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits) { + void fll_fss_basic_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_objects_t * const objects, f_fss_contents_t * const contents, f_uint8s_t * const objects_quoted, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits, f_state_t * const state) { #ifndef _di_level_2_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!objects) return F_status_set_error(F_parameter); - if (!contents) return F_status_set_error(F_parameter); - if (!objects_delimits) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !objects || !contents) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_2_parameter_checking_ f_status_t status = F_none; - f_status_t status2 = F_none; f_array_length_t initial_used = objects->used; bool found_data = F_false; @@ -22,17 +24,17 @@ extern "C" { uint8_t *quoted_object = 0; do { - status = f_string_ranges_increase(state.step_small, objects); - if (F_status_is_error(status)) return status; + state->status = f_string_ranges_increase(state->step_small, objects); + if (F_status_is_error(state->status)) return; - status = f_string_rangess_increase(state.step_small, contents); - if (F_status_is_error(status)) return status; + state->status = f_string_rangess_increase(state->step_small, contents); + if (F_status_is_error(state->status)) return; contents->array[contents->used].used = 0; if (objects_quoted) { - status = f_uint8s_increase(state.step_small, objects_quoted); - if (F_status_is_error(status)) return status; + state->status = f_uint8s_increase(state->step_small, objects_quoted); + if (F_status_is_error(state->status)) return; } do { @@ -40,58 +42,68 @@ extern "C" { quoted_object = &objects_quoted->array[objects_quoted->used]; } - status = fl_fss_basic_object_read(buffer, state, range, &objects->array[objects->used], quoted_object, objects_delimits); - if (F_status_is_error(status)) return status; + fl_fss_basic_object_read(buffer, range, &objects->array[objects->used], quoted_object, objects_delimits, state); + if (F_status_is_error(state->status)) return; if (range->start >= range->stop || range->start >= buffer.used) { - if (status == F_fss_found_object || status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object || state->status == F_fss_found_object_content_not) { ++objects->used; if (objects_quoted) { ++objects_quoted->used; } - status2 = f_string_ranges_increase(state.step_small, &contents->array[contents->used]); - if (F_status_is_error(status2)) return status2; + status = f_string_ranges_increase(state->step_small, &contents->array[contents->used]); + if (F_status_is_error(status)) { + state->status = status; + + return; + } contents->array[contents->used++].used = 0; + state->status = F_fss_found_object_content_not; - return F_fss_found_object_content_not; + return; } if (found_data) { - if (range->start >= buffer.used) return F_none_eos; + state->status = (range->start >= buffer.used) ? F_none_eos : F_none_stop; - return F_none_stop; + return; } - if (range->start >= buffer.used) return F_data_not_eos; + state->status = (range->start >= buffer.used) ? F_data_not_eos : F_data_not_stop; - return F_data_not_stop; + return; } - if (status == F_fss_found_object) { + if (state->status == F_fss_found_object) { found_data = F_true; - contents->array[contents->used].used = 0; - status = fl_fss_basic_content_read(buffer, state, range, &contents->array[contents->used], contents_delimits ? contents_delimits : objects_delimits); - if (F_status_is_error(status)) return status; + fl_fss_basic_content_read(buffer, range, &contents->array[contents->used], contents_delimits ? contents_delimits : objects_delimits, state); + if (F_status_is_error(state->status)) return; break; } - else if (status == F_fss_found_object_content_not) { + + if (state->status == F_fss_found_object_content_not) { found_data = F_true; - status2 = f_string_ranges_increase(state.step_small, &contents->array[contents->used]); - if (F_status_is_error(status2)) return status2; + status = f_string_ranges_increase(state->step_small, &contents->array[contents->used]); + + if (F_status_is_error(status)) { + state->status = status; + + return; + } break; } - } while (status == F_fss_found_object_not); + } while (state->status == F_fss_found_object_not); - if (status == F_none_eos || status == F_none_stop) { + if (state->status == F_none_eos || state->status == F_none_stop) { ++contents->array[contents->used++].used; ++objects->used; @@ -99,29 +111,33 @@ extern "C" { ++objects_quoted->used; } - return status; + return; } - if (status == F_data_not_eos || status == F_data_not_stop) { + if (state->status == F_data_not_eos || state->status == F_data_not_stop) { // If at least some valid object was found, then return F_none equivelents. if (objects->used > initial_used) { - if (status == F_data_not_eos) return F_none_eos; - if (status == F_data_not_stop) return F_none_stop; + if (state->status == F_data_not_eos) { + state->status = F_none_eos; + } + else if (state->status == F_data_not_stop) { + state->status = F_none_stop; + } } - return status; + return; } - if (status != F_fss_found_object && status != F_fss_found_content && status != F_fss_found_content_not && status != F_fss_found_object_content_not) { - return status; + if (state->status != F_fss_found_object && state->status != F_fss_found_content && state->status != F_fss_found_content_not && state->status != F_fss_found_object_content_not) { + return; } // When content is found, the range->start is incremented, if content is found at range->stop, then range->start will be > range.stop. if (range->start >= range->stop || range->start >= buffer.used) { - if (status == F_fss_found_object || status == F_fss_found_content || status == F_fss_found_content_not || status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object || state->status == F_fss_found_content || state->status == F_fss_found_content_not || state->status == F_fss_found_object_content_not) { - if (status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object_content_not) { contents->array[contents->used].used = 0; } @@ -133,12 +149,12 @@ extern "C" { } } - if (range->start >= buffer.used) return F_none_eos; + state->status = (range->start >= buffer.used) ? F_none_eos : F_none_stop; - return F_none_stop; + return; } - if (status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object_content_not) { contents->array[contents->used].used = 0; } @@ -151,42 +167,45 @@ extern "C" { } while (range->start < F_string_t_size_d); - return F_status_is_error(F_number_overflow); + state->status = F_status_is_error(F_number_overflow); } #endif // _di_fll_fss_basic_read_ #ifndef _di_fll_fss_basic_write_ - f_status_t fll_fss_basic_write(const f_string_static_t object, const f_string_static_t content, const uint8_t quote, f_state_t state, f_string_dynamic_t * const destination) { + void fll_fss_basic_write(const f_string_static_t object, const f_string_static_t content, const uint8_t quote, f_string_dynamic_t * const destination, f_state_t * const state) { #ifndef _di_level_2_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); + if (!state) return; + + if (!destination) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_2_parameter_checking_ - f_status_t status = 0; f_string_range_t range = macro_f_string_range_t_initialize2(object.used); - status = fl_fss_basic_object_write(object, quote, f_fss_complete_full_e, state, &range, destination); + fl_fss_basic_object_write(object, quote, f_fss_complete_full_e, &range, destination, state); - if (F_status_is_error(status) || status == F_data_not_stop || status == F_data_not_eos) { - return status; + if (F_status_is_error(state->status) || state->status == F_data_not_stop || state->status == F_data_not_eos) { + return; } - if (status == F_none || status == F_none_stop || status == F_none_eos || status == F_none_eol) { + if (state->status == F_none || state->status == F_none_stop || state->status == F_none_eos || state->status == F_none_eol) { if (content.used) { range.start = 0; range.stop = content.used - 1; - status = fl_fss_basic_content_write(content, f_fss_complete_full_e, state, &range, destination); - if (F_status_is_error(status)) return status; + fl_fss_basic_content_write(content, f_fss_complete_full_e, &range, destination, state); + if (F_status_is_error(state->status)) return; } else { - status = f_string_dynamic_increase(state.step_small, destination); - if (F_status_is_error(status)) return status; + state->status = f_string_dynamic_increase(state->step_small, destination); + if (F_status_is_error(state->status)) return; destination->string[destination->used++] = f_string_eol_s.string[0]; } } - - return status; } #endif // _di_fll_fss_basic_write_ diff --git a/level_2/fll_fss/c/fss/basic.h b/level_2/fll_fss/c/fss/basic.h index 6940b43..0c0ec24 100644 --- a/level_2/fll_fss/c/fss/basic.h +++ b/level_2/fll_fss/c/fss/basic.h @@ -32,15 +32,6 @@ extern "C" { * * @param buffer * The buffer to read from. - * @param state - A state for providing flags and handling interrupts during long running operations. - * There is no print_error(). - * There is no functions structure. - * There is no data structure passed to these functions. - * - * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. - * Error bit designates an error but must be passed along with F_interrupt. - * All other statuses are ignored. * @param range * The range within the buffer that is currently being read. * @param objects @@ -57,23 +48,32 @@ extern "C" { * (optional) An array of delimits for contents detected during processing. * The caller is expected to decide if and when to process them. * Set pointer address to 0 and all delimits will instead utilize objects_delimits. + * @param state + A state for providing flags and handling interrupts during long running operations. + * There is no print_error(). + * There is no functions structure. + * There is no data structure passed to these functions. + * + * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. + * Error bit designates an error but must be passed along with F_interrupt. + * All other statuses are ignored. * - * @return - * F_none on success. - * F_none_eos on success after reaching the end of the buffer. - * F_none_stop on success after reaching stopping point. - * F_data_not_eol if there is no data to write and EOL was reached. - * F_data_not_eos no data to write due start location being greater than or equal to buffer size. - * F_data_not_stop no data to write due start location being greater than stop location. + * This alters state.status: + * F_none on success. + * F_none_eos on success after reaching the end of the buffer. + * F_none_stop on success after reaching stopping point. + * F_data_not_eol if there is no data to write and EOL was reached. + * F_data_not_eos no data to write due start location being greater than or equal to buffer size. + * F_data_not_stop no data to write due start location being greater than stop location. * - * F_number_overflow (with error bit) if the maximum buffer size is reached. - * F_parameter (with error bit) if a parameter is invalid. + * F_number_overflow (with error bit) if the maximum buffer size is reached. + * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_string_ranges_increase(). - * Errors (with error bit) from: f_string_rangess_increase(). - * Errors (with error bit) from: f_uint8s_increase(). - * Errors (with error bit) from: fl_fss_basic_content_read(). - * Errors (with error bit) from: fl_fss_basic_object_read(). + * Errors (with error bit) from: f_string_ranges_increase(). + * Errors (with error bit) from: f_string_rangess_increase(). + * Errors (with error bit) from: f_uint8s_increase(). + * Errors (with error bit) from: fl_fss_basic_content_read(). + * Errors (with error bit) from: fl_fss_basic_object_read(). * * @see f_string_ranges_increase() * @see f_string_rangess_increase() @@ -82,7 +82,7 @@ extern "C" { * @see fl_fss_basic_object_read() */ #ifndef _di_fll_fss_basic_read_ - extern f_status_t fll_fss_basic_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_objects_t * const objects, f_fss_contents_t * const contents, f_uint8s_t * const objects_quoted, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits); + extern void fll_fss_basic_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_objects_t * const objects, f_fss_contents_t * const contents, f_uint8s_t * const objects_quoted, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits, f_state_t * const state); #endif // _di_fll_fss_basic_read_ /** @@ -95,8 +95,10 @@ extern "C" { * @param quote * If 0, then double quotes are auto-inserted, when required. * Otherwise, this is quote character to wrap the object in when writing. + * @param destination + * The buffer where the content is written to. * @param state - A state for providing flags and handling interrupts during long running operations. + * A state for providing flags and handling interrupts during long running operations. * There is no print_error(). * There is no functions structure. * There is no data structure passed to these functions. @@ -104,28 +106,26 @@ extern "C" { * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. * Error bit designates an error but must be passed along with F_interrupt. * All other statuses are ignored. - * @param destination - * The buffer where the content is written to. * - * @return - * F_none on success. - * F_none_eos on success after reaching the end of the buffer. - * F_none_stop on success after reaching stopping point. - * F_data_not_eos no data to write due start location being greater than or equal to buffer size. - * F_data_not_stop no data to write due start location being greater than stop location. + * This alters state.status: + * F_none on success. + * F_none_eos on success after reaching the end of the buffer. + * F_none_stop on success after reaching stopping point. + * F_data_not_eos no data to write due start location being greater than or equal to buffer size. + * F_data_not_stop no data to write due start location being greater than stop location. * - * F_parameter (with error bit) if a parameter is invalid. + * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_string_dynamic_increase(). - * Errors (with error bit) from: fl_fss_basic_content_write(). - * Errors (with error bit) from: fl_fss_basic_object_write(). + * Errors (with error bit) from: f_string_dynamic_increase(). + * Errors (with error bit) from: fl_fss_basic_content_write(). + * Errors (with error bit) from: fl_fss_basic_object_write(). * * @see f_string_dynamic_increase() * @see fl_fss_basic_content_write() * @see fl_fss_basic_object_write() */ #ifndef _di_fll_fss_basic_write_ - extern f_status_t fll_fss_basic_write(const f_string_static_t object, const f_string_static_t content, const uint8_t quote, f_state_t state, f_string_dynamic_t * const destination); + extern void fll_fss_basic_write(const f_string_static_t object, const f_string_static_t content, const uint8_t quote, f_string_dynamic_t * const destination, f_state_t * const state); #endif // _di_fll_fss_basic_write_ #ifdef __cplusplus diff --git a/level_2/fll_fss/c/fss/basic_list.c b/level_2/fll_fss/c/fss/basic_list.c index 75ca4ea..7ebc3a3 100644 --- a/level_2/fll_fss/c/fss/basic_list.c +++ b/level_2/fll_fss/c/fss/basic_list.c @@ -5,106 +5,122 @@ extern "C" { #endif #ifndef _di_fll_fss_basic_list_read_ - f_status_t fll_fss_basic_list_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_objects_t * const objects, f_fss_contents_t * const contents, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits, f_fss_comments_t * const comments) { + void fll_fss_basic_list_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_objects_t * const objects, f_fss_contents_t * const contents, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits, f_fss_comments_t * const comments, f_state_t * const state) { #ifndef _di_level_2_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!objects) return F_status_set_error(F_parameter); - if (!contents) return F_status_set_error(F_parameter); - if (!objects_delimits) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !objects || !contents) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_2_parameter_checking_ f_status_t status = F_none; - f_status_t status2 = F_none; f_array_length_t initial_used = objects->used; bool found_data = F_false; do { - status = f_string_ranges_increase(state.step_small, objects); - if (F_status_is_error(status)) return status; + state->status = f_string_ranges_increase(state->step_small, objects); + if (F_status_is_error(state->status)) return; - status = f_string_rangess_increase(state.step_small, contents); - if (F_status_is_error(status)) return status; + state->status = f_string_rangess_increase(state->step_small, contents); + if (F_status_is_error(state->status)) return; contents->array[contents->used].used = 0; do { - status = fl_fss_basic_list_object_read(buffer, state, range, &objects->array[objects->used], objects_delimits); - if (F_status_is_error(status)) return status; + fl_fss_basic_list_object_read(buffer, range, &objects->array[objects->used], objects_delimits, state); + if (F_status_is_error(state->status)) return; if (range->start >= range->stop || range->start >= buffer.used) { - if (status == F_fss_found_object || status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object || state->status == F_fss_found_object_content_not) { ++objects->used; - status2 = f_string_ranges_increase(state.step_small, &contents->array[contents->used]); - if (F_status_is_error(status2)) return status2; + status = f_string_ranges_increase(state->step_small, &contents->array[contents->used]); + + if (F_status_is_error(status)) { + state->status = status; + + return; + } contents->array[contents->used++].used = 0; + state->status = F_fss_found_object_content_not; - return F_fss_found_object_content_not; + return; } if (found_data) { - if (range->start >= buffer.used) return F_none_eos; - - return F_none_stop; + state->status = (range->start >= buffer.used) ? F_none_eos : F_none_stop; + } + else { + state->status = (range->start >= buffer.used) ? F_data_not_eos : F_data_not_stop; } - if (range->start >= buffer.used) return F_data_not_eos; - - return F_data_not_stop; + return; } - if (status == F_fss_found_object) { + if (state->status == F_fss_found_object) { found_data = F_true; contents->array[contents->used].used = 0; - status = fl_fss_basic_list_content_read(buffer, state, range, &contents->array[contents->used], contents_delimits ? contents_delimits : objects_delimits, comments); - if (F_status_is_error(status)) return status; + fl_fss_basic_list_content_read(buffer, range, &contents->array[contents->used], contents_delimits ? contents_delimits : objects_delimits, comments, state); + if (F_status_is_error(state->status)) return; break; } - if (status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object_content_not) { found_data = F_true; - status2 = f_string_ranges_increase(state.step_small, &contents->array[contents->used]); - if (F_status_is_error(status2)) return status2; + status = f_string_ranges_increase(state->step_small, &contents->array[contents->used]); + + if (F_status_is_error(status)) { + state->status = status; + + return; + } break; } - } while (status == F_fss_found_object_not); + } while (state->status == F_fss_found_object_not); - if (status == F_none_eos || status == F_none_stop) { + if (state->status == F_none_eos || state->status == F_none_stop) { ++contents->array[contents->used++].used; ++objects->used; - return status; + return; } - if (status == F_data_not_eos || status == F_data_not_stop) { + if (state->status == F_data_not_eos || state->status == F_data_not_stop) { // If at least some valid object was found, then return F_none equivalents. if (objects->used > initial_used) { - if (status == F_data_not_eos) return F_none_eos; - if (status == F_data_not_stop) return F_none_stop; + if (state->status == F_data_not_eos) { + state->status = F_none_eos; + } + else if (state->status == F_data_not_stop) { + state->status = F_none_stop; + } } - return status; + return; } - if (status != F_fss_found_object && status != F_fss_found_content && status != F_fss_found_content_not && status != F_fss_found_object_content_not) { - return status; + if (state->status != F_fss_found_object && state->status != F_fss_found_content && state->status != F_fss_found_content_not && state->status != F_fss_found_object_content_not) { + return; } if (range->start >= range->stop || range->start >= buffer.used) { // When content is found, the range->start is incremented, if content is found at range->stop, then range->start will be > range.stop. - if (status == F_fss_found_object || status == F_fss_found_content || status == F_fss_found_content_not || status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object || state->status == F_fss_found_content || state->status == F_fss_found_content_not || state->status == F_fss_found_object_content_not) { - if (status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object_content_not) { contents->array[contents->used].used = 0; } @@ -112,12 +128,12 @@ extern "C" { ++contents->used; } - if (range->start >= buffer.used) return F_none_eos; + state->status = (range->start >= buffer.used) ? F_none_eos : F_none_stop; - return F_none_stop; + return; } - if (status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object_content_not) { contents->array[contents->used].used = 0; } @@ -126,26 +142,25 @@ extern "C" { } while (range->start < F_string_t_size_d); - return F_status_is_error(F_number_overflow); + state->status = F_status_is_error(F_number_overflow); } #endif // _di_fll_fss_basic_list_read_ #ifndef _di_fll_fss_basic_list_write_ - f_status_t fll_fss_basic_list_write(const f_string_static_t object, const f_string_static_t content, const f_string_static_t * const content_prepend, f_state_t state, f_string_dynamic_t * const destination) { + void fll_fss_basic_list_write(const f_string_static_t object, const f_string_static_t content, const f_string_static_t * const content_prepend, f_string_dynamic_t * const destination, f_state_t * const state) { #ifndef _di_level_2_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); + if (!state) return; #endif // _di_level_2_parameter_checking_ - f_status_t status = 0; f_string_range_t range = macro_f_string_range_t_initialize2(object.used); - status = fl_fss_basic_list_object_write(object, f_fss_complete_full_e, state, &range, destination); + fl_fss_basic_list_object_write(object, f_fss_complete_full_e, &range, destination, state); - if (F_status_is_error(status) || status == F_data_not_stop || status == F_data_not_eos) { - return status; + if (F_status_is_error(state->status) || state->status == F_data_not_stop || state->status == F_data_not_eos) { + return; } - if (status == F_none || status == F_none_stop || status == F_none_eos || status == F_none_eol) { + if (state->status == F_none || state->status == F_none_stop || state->status == F_none_eos || state->status == F_none_eol) { if (content.used) { range.start = 0; range.stop = content.used - 1; @@ -155,10 +170,8 @@ extern "C" { range.stop = 0; } - status = fl_fss_basic_list_content_write(content, f_fss_complete_full_e, content_prepend, state, &range, destination); + fl_fss_basic_list_content_write(content, f_fss_complete_full_e, content_prepend, &range, destination, state); } - - return status; } #endif // _di_fll_fss_basic_list_write_ diff --git a/level_2/fll_fss/c/fss/basic_list.h b/level_2/fll_fss/c/fss/basic_list.h index cc19b09..7bb2f0c 100644 --- a/level_2/fll_fss/c/fss/basic_list.h +++ b/level_2/fll_fss/c/fss/basic_list.h @@ -32,15 +32,6 @@ extern "C" { * * @param buffer * The buffer to read from. - * @param state - A state for providing flags and handling interrupts during long running operations. - * There is no print_error(). - * There is no functions structure. - * There is no data structure passed to these functions. - * - * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. - * Error bit designates an error but must be passed along with F_interrupt. - * All other statuses are ignored. * @param range * The range within the buffer that is currently being read. * @param objects @@ -57,22 +48,31 @@ extern "C" { * @param comments * An array of ranges representing where comments are found within any valid content. * This only stores comments found within valid content only. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * There is no print_error(). + * There is no functions structure. + * There is no data structure passed to these functions. * - * @return - * F_none on success. - * F_none_eos on success after reaching the end of the buffer. - * F_none_stop on success after reaching stopping point. - * F_data_not_eos no data to write due start location being greater than or equal to buffer size. - * F_data_not_stop no data to write due start location being greater than stop location. + * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. + * Error bit designates an error but must be passed along with F_interrupt. + * All other statuses are ignored. * - * F_number_overflow (with error bit) if the maximum buffer size is reached. - * F_parameter (with error bit) if a parameter is invalid. + * This alters state.status: + * F_none on success. + * F_none_eos on success after reaching the end of the buffer. + * F_none_stop on success after reaching stopping point. + * F_data_not_eos no data to write due start location being greater than or equal to buffer size. + * F_data_not_stop no data to write due start location being greater than stop location. + * + * F_number_overflow (with error bit) if the maximum buffer size is reached. + * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_string_ranges_increase(). - * Errors (with error bit) from: f_string_rangess_increase(). - * Errors (with error bit) from: f_uint8s_increase(). - * Errors (with error bit) from: fl_fss_basic_list_content_read(). - * Errors (with error bit) from: fl_fss_basic_list_object_read(). + * Errors (with error bit) from: f_string_ranges_increase(). + * Errors (with error bit) from: f_string_rangess_increase(). + * Errors (with error bit) from: f_uint8s_increase(). + * Errors (with error bit) from: fl_fss_basic_list_content_read(). + * Errors (with error bit) from: fl_fss_basic_list_object_read(). * * @see f_string_ranges_increase() * @see f_string_rangess_increase() @@ -81,7 +81,7 @@ extern "C" { * @see fl_fss_basic_list_object_read() */ #ifndef _di_fll_fss_basic_list_read_ - extern f_status_t fll_fss_basic_list_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_objects_t * const objects, f_fss_contents_t * const contents, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits, f_fss_comments_t * const comments); + extern void fll_fss_basic_list_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_objects_t * const objects, f_fss_contents_t * const contents, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits, f_fss_comments_t * const comments, f_state_t * const state); #endif // _di_fll_fss_basic_list_read_ /** @@ -94,6 +94,8 @@ extern "C" { * @param content_prepend * A string to prepend at the start of each line in content, such as spaces. * Set the pointer address to 0 to disable. + * @param destination + * The buffer to write to. * @param state A state for providing flags and handling interrupts during long running operations. * There is no print_error(). @@ -103,8 +105,6 @@ extern "C" { * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. * Error bit designates an error but must be passed along with F_interrupt. * All other statuses are ignored. - * @param destination - * The buffer to write to. * * @return * F_none on success. @@ -124,7 +124,7 @@ extern "C" { * @see fl_fss_basic_list_object_write() */ #ifndef _di_fll_fss_basic_list_write_ - extern f_status_t fll_fss_basic_list_write(const f_string_static_t object, const f_string_static_t content, const f_string_static_t *content_prepend, f_state_t state, f_string_dynamic_t * const destination); + extern void fll_fss_basic_list_write(const f_string_static_t object, const f_string_static_t content, const f_string_static_t *content_prepend, f_string_dynamic_t * const destination, f_state_t * const state); #endif // _di_fll_fss_basic_list_write_ #ifdef __cplusplus diff --git a/level_2/fll_fss/c/fss/embedded_list.c b/level_2/fll_fss/c/fss/embedded_list.c index 3b9e70b..e0a8d2b 100644 --- a/level_2/fll_fss/c/fss/embedded_list.c +++ b/level_2/fll_fss/c/fss/embedded_list.c @@ -5,22 +5,24 @@ extern "C" { #endif #ifndef _di_fll_fss_embedded_list_read_ - f_status_t fll_fss_embedded_list_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_nest_t * const nest, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits, f_fss_comments_t * const comments) { + void fll_fss_embedded_list_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_nest_t * const nest, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits, f_fss_comments_t * const comments, f_state_t * const state) { #ifndef _di_level_2_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!nest) return F_status_set_error(F_parameter); - if (!objects_delimits) return F_status_set_error(F_parameter); - if (!comments) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !nest) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_2_parameter_checking_ - f_status_t status = F_none; f_array_length_t initial_used = 0; bool found_data = F_false; if (!nest->used) { - status = f_fss_nest_resize(state.step_small, nest); - if (F_status_is_error(status)) return status; + state->status = f_fss_nest_resize(state->step_small, nest); + if (F_status_is_error(state->status)) return; } else { initial_used = nest->depth[0].used; @@ -28,108 +30,115 @@ extern "C" { do { do { - status = f_fss_items_resize(state.step_small, &nest->depth[0]); - if (F_status_is_error(status)) return status; + state->status = f_fss_items_resize(state->step_small, &nest->depth[0]); + if (F_status_is_error(state->status)) return; nest->depth[nest->used].used = 0; - status = fl_fss_embedded_list_object_read(buffer, state, range, &nest->depth[0].array[nest->depth[0].used].object, objects_delimits); - if (F_status_is_error(status)) return status; + fl_fss_embedded_list_object_read(buffer, range, &nest->depth[0].array[nest->depth[0].used].object, objects_delimits, state); + if (F_status_is_error(state->status)) return; if (range->start >= range->stop || range->start >= buffer.used) { - if (status == F_fss_found_object || status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object || state->status == F_fss_found_object_content_not) { // Extended list requires content closure, so this could be an error. - return F_fss_found_object_content_not; + state->status = F_fss_found_object_content_not; + + return; } if (found_data) { - if (range->start >= buffer.used) return F_none_eos; + state->status = (range->start >= buffer.used) ? F_none_eos : F_none_stop; - return F_none_stop; + return; } - if (range->start >= buffer.used) return F_data_not_eos; + state->status = (range->start >= buffer.used) ? F_data_not_eos : F_data_not_stop; - return F_data_not_stop; + return; } - if (status == F_fss_found_object) { + if (state->status == F_fss_found_object) { found_data = F_true; - status = fl_fss_embedded_list_content_read(buffer, state, range, nest, contents_delimits ? contents_delimits : objects_delimits, comments); + fl_fss_embedded_list_content_read(buffer, range, nest, contents_delimits ? contents_delimits : objects_delimits, comments, state); break; } - if (status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object_content_not) { found_data = F_true; break; } - } while (status == F_fss_found_object_not); + } while (state->status == F_fss_found_object_not); - if (status == F_none_eos || status == F_none_stop) { - return status; - } + if (state->status == F_none_eos || state->status == F_none_stop) return; - if (status == F_data_not_eos || status == F_data_not_stop) { + if (state->status == F_data_not_eos || state->status == F_data_not_stop) { // If at least some valid object was found, then return F_none equivalents. if (nest->depth[0].used > initial_used) { - if (status == F_data_not_eos) return F_none_eos; - if (status == F_data_not_stop) return F_none_stop; + if (state->status == F_data_not_eos) { + state->status = F_none_eos; + } + else if (state->status == F_data_not_stop) { + state->status = F_none_stop; + } } - return status; + return; } - if (status == F_end_not_eos || status == F_end_not_stop || status == F_end_not_nest_eos || status == F_end_not_nest_stop) { + if (state->status == F_end_not_eos || state->status == F_end_not_stop || state->status == F_end_not_nest_eos || state->status == F_end_not_nest_stop) { // If at least some valid object was found, then return F_none equivalents. if (nest->depth[0].used > initial_used) { - if (status == F_data_not_eos) return F_none_eos; - if (status == F_data_not_stop) return F_none_stop; + if (state->status == F_data_not_eos) { + state->status = F_none_eos; + } + else if (state->status == F_data_not_stop) { + state->status = F_none_stop; + } } - return status; + return; } - if (status != F_fss_found_object && status != F_fss_found_content && status != F_fss_found_content_not && status != F_fss_found_object_content_not) { - return status; + if (state->status != F_fss_found_object && state->status != F_fss_found_content && state->status != F_fss_found_content_not && state->status != F_fss_found_object_content_not) { + return; } if (range->start >= range->stop || range->start >= buffer.used) { // When content is found, the range->start is incremented, if content is found at range->stop, then range->start will be > range.stop. - if (range->start >= buffer.used) return F_none_eos; + state->status = (range->start >= buffer.used) ? F_none_eos : F_none_stop; - return F_none_stop; + return; } } while (range->start < F_string_t_size_d); - return F_status_is_error(F_number_overflow); + state->status = F_status_is_error(F_number_overflow); } #endif // _di_fll_fss_embedded_list_read_ #ifndef _di_fll_fss_embedded_list_write_ - f_status_t fll_fss_embedded_list_write(const f_string_static_t object, const f_string_static_t content, const f_string_static_t *content_prepend, const f_string_ranges_t *ignore, f_state_t state, f_string_dynamic_t * const destination) { + void fll_fss_embedded_list_write(const f_string_static_t object, const f_string_static_t content, const f_string_static_t *content_prepend, const f_string_ranges_t *ignore, f_string_dynamic_t * const destination, f_state_t * const state) { #ifndef _di_level_2_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); + if (!state) return; #endif // _di_level_2_parameter_checking_ - f_status_t status = 0; f_string_range_t range = macro_f_string_range_t_initialize2(object.used); - status = fl_fss_embedded_list_object_write(object, f_fss_complete_full_e, state, &range, destination); + fl_fss_embedded_list_object_write(object, f_fss_complete_full_e, &range, destination, state); - if (F_status_is_error(status) || status == F_data_not_stop || status == F_data_not_eos) { - return status; + if (F_status_is_error(state->status) || state->status == F_data_not_stop || state->status == F_data_not_eos) { + return; } - if (status == F_none || status == F_none_stop || status == F_none_eos || status == F_none_eol) { + if (state->status == F_none || state->status == F_none_stop || state->status == F_none_eos || state->status == F_none_eol) { if (content.used) { range.start = 0; range.stop = content.used - 1; @@ -139,10 +148,8 @@ extern "C" { range.stop = 0; } - status = fl_fss_embedded_list_content_write(content, f_fss_complete_full_e, content_prepend, ignore, state, &range, destination); + fl_fss_embedded_list_content_write(content, f_fss_complete_full_e, content_prepend, ignore, &range, destination, state); } - - return status; } #endif // _di_fll_fss_embedded_list_write_ diff --git a/level_2/fll_fss/c/fss/embedded_list.h b/level_2/fll_fss/c/fss/embedded_list.h index eeebd50..2c67423 100644 --- a/level_2/fll_fss/c/fss/embedded_list.h +++ b/level_2/fll_fss/c/fss/embedded_list.h @@ -31,15 +31,6 @@ extern "C" { * * @param buffer * The buffer to read from. - * @param state - A state for providing flags and handling interrupts during long running operations. - * There is no print_error(). - * There is no functions structure. - * There is no data structure passed to these functions. - * - * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. - * Error bit designates an error but must be passed along with F_interrupt. - * All other statuses are ignored. * @param range * The range within the buffer that is currently being read. * @param nest @@ -54,24 +45,33 @@ extern "C" { * @param comments * An array of ranges representing where comments are found within any valid content. * This only stores comments found within valid content only. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * There is no print_error(). + * There is no functions structure. + * There is no data structure passed to these functions. + * + * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. + * Error bit designates an error but must be passed along with F_interrupt. + * All other statuses are ignored. * - * @return - * F_none on success (both valid object and valid content found with start location is at end of content). - * F_none_eos on success after reaching the end of the buffer (both valid object and valid content found with start location is at end of buffer). - * F_none_stop on success after reaching stopping point (both valid object and valid content found with start location is at stop point). - * F_data_not_eol if there is no data to write and EOL was reached. - * F_data_not_eos no data to write due start location being greater than or equal to buffer size. - * F_data_not_stop no data to write due start location being greater than stop location. - * F_fss_found_object_content_not on success and object was found but no content was found (start location is at end of object). + * This alters state.status: + * F_none on success (both valid object and valid content found with start location is at end of content). + * F_none_eos on success after reaching the end of the buffer (both valid object and valid content found with start location is at end of buffer). + * F_none_stop on success after reaching stopping point (both valid object and valid content found with start location is at stop point). + * F_data_not_eol if there is no data to write and EOL was reached. + * F_data_not_eos no data to write due start location being greater than or equal to buffer size. + * F_data_not_stop no data to write due start location being greater than stop location. + * F_fss_found_object_content_not on success and object was found but no content was found (start location is at end of object). * - * F_number_overflow (with error bit) if the maximum buffer size is reached. - * F_parameter (with error bit) if a parameter is invalid. + * F_number_overflow (with error bit) if the maximum buffer size is reached. + * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_string_ranges_increase(). - * Errors (with error bit) from: f_string_rangess_increase(). - * Errors (with error bit) from: f_uint8s_increase(). - * Errors (with error bit) from: fl_fss_embedded_list_content_read(). - * Errors (with error bit) from: fl_fss_embedded_list_object_read(). + * Errors (with error bit) from: f_string_ranges_increase(). + * Errors (with error bit) from: f_string_rangess_increase(). + * Errors (with error bit) from: f_uint8s_increase(). + * Errors (with error bit) from: fl_fss_embedded_list_content_read(). + * Errors (with error bit) from: fl_fss_embedded_list_object_read(). * * @see f_string_ranges_increase() * @see f_string_rangess_increase() @@ -80,7 +80,7 @@ extern "C" { * @see fl_fss_embedded_list_object_read() */ #ifndef _di_fll_fss_embedded_list_read_ - extern f_status_t fll_fss_embedded_list_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_nest_t * const nest, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits, f_fss_comments_t * const comments); + extern void fll_fss_embedded_list_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_nest_t * const nest, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits, f_fss_comments_t * const comments, f_state_t * const state); #endif // _di_fll_fss_embedded_list_read_ /** @@ -98,8 +98,10 @@ extern "C" { * These ranges are only checked/ignored if there is a valid nested object open or a valid nested object close. * Any valid nested object open or valid nested object close inside an ingore range will not be escaped. * Set the pointer address to 0 to disable. + * @param destination + * The buffer where the content is written to. * @param state - A state for providing flags and handling interrupts during long running operations. + * A state for providing flags and handling interrupts during long running operations. * There is no print_error(). * There is no functions structure. * There is no data structure passed to these functions. @@ -107,28 +109,26 @@ extern "C" { * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. * Error bit designates an error but must be passed along with F_interrupt. * All other statuses are ignored. - * @param destination - * The buffer where the content is written to. * - * @return - * F_none on success. - * F_none_eos on success after reaching the end of the buffer. - * F_none_stop on success after reaching stopping point. - * F_data_not_eos no data to write due start location being greater than or equal to buffer size. - * F_data_not_stop no data to write due start location being greater than stop location. + * This alters state.status: + * F_none on success. + * F_none_eos on success after reaching the end of the buffer. + * F_none_stop on success after reaching stopping point. + * F_data_not_eos no data to write due start location being greater than or equal to buffer size. + * F_data_not_stop no data to write due start location being greater than stop location. * - * F_parameter (with error bit) if a parameter is invalid. + * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_string_dynamic_increase(). - * Errors (with error bit) from: fl_fss_embedded_list_content_write(). - * Errors (with error bit) from: fl_fss_embedded_list_object_write(). + * Errors (with error bit) from: f_string_dynamic_increase(). + * Errors (with error bit) from: fl_fss_embedded_list_content_write(). + * Errors (with error bit) from: fl_fss_embedded_list_object_write(). * * @see f_string_dynamic_increase() * @see fl_fss_embedded_list_content_write() * @see fl_fss_embedded_list_object_write() */ #ifndef _di_fll_fss_embedded_list_write_ - extern f_status_t fll_fss_embedded_list_write(const f_string_static_t object, const f_string_static_t content, const f_string_static_t *content_prepend, const f_string_ranges_t *ignore, f_state_t state, f_string_dynamic_t * const destination); + extern void fll_fss_embedded_list_write(const f_string_static_t object, const f_string_static_t content, const f_string_static_t *content_prepend, const f_string_ranges_t *ignore, f_string_dynamic_t * const destination, f_state_t * const state); #endif // _di_fll_fss_embedded_list_write_ #ifdef __cplusplus diff --git a/level_2/fll_fss/c/fss/extended.c b/level_2/fll_fss/c/fss/extended.c index 2fa3828..15d9044 100644 --- a/level_2/fll_fss/c/fss/extended.c +++ b/level_2/fll_fss/c/fss/extended.c @@ -5,16 +5,18 @@ extern "C" { #endif #ifndef _di_fll_fss_extended_read_ - f_status_t fll_fss_extended_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_objects_t * const objects, f_fss_contents_t * const contents, f_uint8s_t * const objects_quoted, f_uint8ss_t * const contents_quoted, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits) { + void fll_fss_extended_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_objects_t * const objects, f_fss_contents_t * const contents, f_uint8s_t * const objects_quoted, f_uint8ss_t * const contents_quoted, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits, f_state_t * const state) { #ifndef _di_level_2_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!objects) return F_status_set_error(F_parameter); - if (!contents) return F_status_set_error(F_parameter); - if (!objects_delimits) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !objects || !contents) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_2_parameter_checking_ f_status_t status = F_none; - f_status_t status2 = F_none; f_array_length_t initial_used = objects->used; bool found_data = F_false; @@ -23,22 +25,22 @@ extern "C" { f_uint8s_t *quoted_content = 0; do { - status = f_string_ranges_increase(state.step_small, objects); - if (F_status_is_error(status)) return status; + state->status = f_string_ranges_increase(state->step_small, objects); + if (F_status_is_error(state->status)) return; - status = f_string_rangess_increase(state.step_small, contents); - if (F_status_is_error(status)) return status; + state->status = f_string_rangess_increase(state->step_small, contents); + if (F_status_is_error(state->status)) return; contents->array[contents->used].used = 0; if (objects_quoted) { - status = f_uint8s_increase(state.step_small, objects_quoted); - if (F_status_is_error(status)) return status; + state->status = f_uint8s_increase(state->step_small, objects_quoted); + if (F_status_is_error(state->status)) return; } if (contents_quoted) { - status = f_uint8ss_increase(state.step_small, contents_quoted); - if (F_status_is_error(status)) return status; + state->status = f_uint8ss_increase(state->step_small, contents_quoted); + if (F_status_is_error(state->status)) return; contents_quoted->array[contents_quoted->used].used = 0; } @@ -48,71 +50,72 @@ extern "C" { quoted_object = &objects_quoted->array[objects_quoted->used]; } - status = fl_fss_extended_object_read(buffer, state, range, &objects->array[objects->used], quoted_object, objects_delimits); - if (F_status_is_error(status)) return status; + fl_fss_extended_object_read(buffer, range, &objects->array[objects->used], quoted_object, objects_delimits, state); + if (F_status_is_error(state->status)) return; if (range->start >= range->stop || range->start >= buffer.used) { - if (status == F_fss_found_object || status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object || state->status == F_fss_found_object_content_not) { ++objects->used; if (objects_quoted) { ++objects_quoted->used; } - status2 = f_string_ranges_increase(state.step_small, &contents->array[contents->used]); - if (F_status_is_error(status2)) return status2; + status = f_string_ranges_increase(state->step_small, &contents->array[contents->used]); + if (F_status_is_error(status)) return; contents->array[contents->used++].used = 0; if (contents_quoted) { - status2 = f_uint8s_increase(state.step_small, &contents_quoted->array[contents_quoted->used]); - if (F_status_is_error(status2)) return status2; + status = f_uint8s_increase(state->step_small, &contents_quoted->array[contents_quoted->used]); + if (F_status_is_error(status)) return; contents_quoted->array[contents_quoted->used++].used = 0; } - return F_fss_found_object_content_not; + state->status = F_fss_found_object_content_not; + + return; } if (found_data) { - if (range->start >= buffer.used) return F_none_eos; - - return F_none_stop; + state->status = (range->start >= buffer.used) ? F_none_eos : F_none_stop; + } + else { + state->status = (range->start >= buffer.used) ? F_data_not_eos : F_data_not_stop; } - if (range->start >= buffer.used) return F_data_not_eos; - - return F_data_not_stop; + return; } - if (status == F_fss_found_object) { + if (state->status == F_fss_found_object) { found_data = F_true; contents->array[contents->used].used = 0; if (contents_quoted) { - status2 = f_uint8s_increase(state.step_small, &contents_quoted->array[contents_quoted->used]); - if (F_status_is_error(status2)) return status2; + state->status = f_uint8s_increase(state->step_small, &contents_quoted->array[contents_quoted->used]); + if (F_status_is_error(state->status)) return; quoted_content = &contents_quoted->array[contents_quoted->used]; quoted_content->used = 0; } - status = fl_fss_extended_content_read(buffer, state, range, &contents->array[contents->used], quoted_content, contents_delimits ? contents_delimits : objects_delimits); - if (F_status_is_error(status)) return status; + fl_fss_extended_content_read(buffer, range, &contents->array[contents->used], quoted_content, contents_delimits ? contents_delimits : objects_delimits, state); + if (F_status_is_error(state->status)) return; break; } - if (status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object_content_not) { found_data = F_true; break; } - } while (status == F_fss_found_object_not); + } while (state->status == F_fss_found_object_not); - if (status == F_none_eos || status == F_none_stop) { + if (state->status == F_none_eos || state->status == F_none_stop) { ++contents->array[contents->used++].used; ++objects->used; @@ -125,30 +128,34 @@ extern "C" { ++contents_quoted->used; } - return status; + return; } - if (status == F_data_not_eos || status == F_data_not_stop || status == F_end_not_group_eos || status == F_end_not_group_stop) { + if (state->status == F_data_not_eos || state->status == F_data_not_stop || state->status == F_end_not_group_eos || state->status == F_end_not_group_stop) { // If at least some valid object was found, then return F_none equivelents. if (objects->used > initial_used) { - if (status == F_data_not_eos) return F_none_eos; - if (status == F_data_not_stop) return F_none_stop; + if (state->status == F_data_not_eos) { + state->status = F_none_eos; + } + else if (state->status == F_data_not_stop) { + state->status = F_none_stop; + } } - return status; + return; } - if (status != F_fss_found_object && status != F_fss_found_content && status != F_fss_found_content_not && status != F_fss_found_object_content_not && status != F_end_not_group) { - return status; + if (state->status != F_fss_found_object && state->status != F_fss_found_content && state->status != F_fss_found_content_not && state->status != F_fss_found_object_content_not && state->status != F_end_not_group) { + return; } if (range->start >= range->stop || range->start >= buffer.used) { // When content is found, the range->start is incremented, if content is found at range->stop, then range->start will be > range.stop. - if (status == F_fss_found_object || status == F_fss_found_content || status == F_fss_found_content_not || status == F_fss_found_object_content_not || status == F_end_not_group) { + if (state->status == F_fss_found_object || state->status == F_fss_found_content || state->status == F_fss_found_content_not || state->status == F_fss_found_object_content_not || state->status == F_end_not_group) { - if (status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object_content_not) { contents->array[contents->used].used = 0; } @@ -165,17 +172,17 @@ extern "C" { } if (range->start >= buffer.used) { - if (status == F_end_not_group) return F_end_not_group_eos; + state->status = (state->status == F_end_not_group) ? F_end_not_group_eos : F_none_eos; - return F_none_eos; + return; } - if (status == F_end_not_group) return F_end_not_group_stop; + state->status = (state->status == F_end_not_group) ? F_end_not_group_stop : F_none_stop; - return F_none_stop; + return; } - if (status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object_content_not) { contents->array[contents->used].used = 0; } @@ -192,26 +199,25 @@ extern "C" { } while (range->start < F_string_t_size_d); - return F_status_is_error(F_number_overflow); + state->status = F_status_is_error(F_number_overflow); } #endif // _di_fll_fss_extended_read_ #ifndef _di_fll_fss_extended_write_ - f_status_t fll_fss_extended_write(const f_string_static_t object, const f_string_statics_t contents, const uint8_t quote, f_state_t state, f_string_dynamic_t * const destination) { + void fll_fss_extended_write(const f_string_static_t object, const f_string_statics_t contents, const uint8_t quote, f_string_dynamic_t * const destination, f_state_t * const state) { #ifndef _di_level_2_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); + if (!state) return; #endif // _di_level_2_parameter_checking_ - f_status_t status = 0; f_string_range_t range = macro_f_string_range_t_initialize2(object.used); - status = fl_fss_extended_object_write(object, quote, f_fss_complete_full_e, state, &range, destination); + fl_fss_extended_object_write(object, quote, f_fss_complete_full_e, &range, destination, state); - if (F_status_is_error(status) || status == F_data_not_stop || status == F_data_not_eos) { - return status; + if (F_status_is_error(state->status) || state->status == F_data_not_stop || state->status == F_data_not_eos) { + return; } - if (status == F_none || status == F_none_stop || status == F_none_eos || status == F_none_eol) { + if (state->status == F_none || state->status == F_none_stop || state->status == F_none_eos || state->status == F_none_eol) { uint8_t complete = f_fss_complete_next_e; for (f_array_length_t i = 0; i < contents.used; ++i) { @@ -229,12 +235,10 @@ extern "C" { range.stop = 0; } - status = fl_fss_extended_content_write(contents.array[i], quote, complete, state, &range, destination); - if (F_status_is_error(status)) return status; + fl_fss_extended_content_write(contents.array[i], quote, complete, &range, destination, state); + if (F_status_is_error(state->status)) return; } // for } - - return status; } #endif // _di_fll_fss_extended_write_ diff --git a/level_2/fll_fss/c/fss/extended.h b/level_2/fll_fss/c/fss/extended.h index e03224e..9dbb5d9 100644 --- a/level_2/fll_fss/c/fss/extended.h +++ b/level_2/fll_fss/c/fss/extended.h @@ -31,15 +31,6 @@ extern "C" { * * @param buffer * The buffer to read from. - * @param state - A state for providing flags and handling interrupts during long running operations. - * There is no print_error(). - * There is no functions structure. - * There is no data structure passed to these functions. - * - * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. - * Error bit designates an error but must be passed along with F_interrupt. - * All other statuses are ignored. * @param range * The range within the buffer that is currently being read. * @param objects @@ -59,23 +50,32 @@ extern "C" { * (optional) An array of delimits for contents detected during processing. * The caller is expected to decide if and when to process them. * Set pointer address to 0 and all delimits will instead utilize objects_delimits. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * There is no print_error(). + * There is no functions structure. + * There is no data structure passed to these functions. + * + * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. + * Error bit designates an error but must be passed along with F_interrupt. + * All other statuses are ignored. * - * @return - * F_none on success. - * F_none_stop on success after reaching stopping point. - * F_none_eos on success after reaching the end of the buffer. - * F_data_not_stop no data to write due start location being greater than stop location. - * F_data_not_eos no data to write due start location being greater than or equal to buffer size. - * F_data_not_eol if there is no data to write and EOL was reached. + * This alters state.status: + * F_none on success. + * F_none_stop on success after reaching stopping point. + * F_none_eos on success after reaching the end of the buffer. + * F_data_not_stop no data to write due start location being greater than stop location. + * F_data_not_eos no data to write due start location being greater than or equal to buffer size. + * F_data_not_eol if there is no data to write and EOL was reached. * - * F_number_overflow (with error bit) if the maximum buffer size is reached. - * F_parameter (with error bit) if a parameter is invalid. + * F_number_overflow (with error bit) if the maximum buffer size is reached. + * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_string_ranges_increase(). - * Errors (with error bit) from: f_string_rangess_increase(). - * Errors (with error bit) from: f_uint8s_increase(). - * Errors (with error bit) from: fl_fss_extended_content_read(). - * Errors (with error bit) from: fl_fss_extended_object_read(). + * Errors (with error bit) from: f_string_ranges_increase(). + * Errors (with error bit) from: f_string_rangess_increase(). + * Errors (with error bit) from: f_uint8s_increase(). + * Errors (with error bit) from: fl_fss_extended_content_read(). + * Errors (with error bit) from: fl_fss_extended_object_read(). * * @see f_string_ranges_increase() * @see f_string_rangess_increase() @@ -84,7 +84,7 @@ extern "C" { * @see fl_fss_extended_object_read() */ #ifndef _di_fll_fss_extended_read_ - extern f_status_t fll_fss_extended_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_objects_t * const objects, f_fss_contents_t * const contents, f_uint8s_t * const objects_quoted, f_uint8ss_t * const contents_quoted, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits); + extern void fll_fss_extended_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_objects_t * const objects, f_fss_contents_t * const contents, f_uint8s_t * const objects_quoted, f_uint8ss_t * const contents_quoted, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits, f_state_t * const state); #endif // _di_fll_fss_extended_read_ /** @@ -97,8 +97,10 @@ extern "C" { * @param quote * If 0, then double quotes are auto-inserted, when required. * Otherwise, this is quote character to wrap the object in when writing. + * @param destination + * The buffer where the content is written to. * @param state - A state for providing flags and handling interrupts during long running operations. + * A state for providing flags and handling interrupts during long running operations. * There is no print_error(). * There is no functions structure. * There is no data structure passed to these functions. @@ -106,28 +108,26 @@ extern "C" { * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. * Error bit designates an error but must be passed along with F_interrupt. * All other statuses are ignored. - * @param destination - * The buffer where the content is written to. * - * @return - * F_none on success. - * F_none_eos on success after reaching the end of the buffer. - * F_none_stop on success after reaching stopping point. - * F_data_not_eos no data to write due start location being greater than or equal to buffer size. - * F_data_not_stop no data to write due start location being greater than stop location. + * This alters state.status: + * F_none on success. + * F_none_eos on success after reaching the end of the buffer. + * F_none_stop on success after reaching stopping point. + * F_data_not_eos no data to write due start location being greater than or equal to buffer size. + * F_data_not_stop no data to write due start location being greater than stop location. * - * F_parameter (with error bit) if a parameter is invalid. + * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_string_dynamic_increase(). - * Errors (with error bit) from: fl_fss_extended_content_write(). - * Errors (with error bit) from: fl_fss_extended_object_write(). + * Errors (with error bit) from: f_string_dynamic_increase(). + * Errors (with error bit) from: fl_fss_extended_content_write(). + * Errors (with error bit) from: fl_fss_extended_object_write(). * * @see f_string_dynamic_increase() * @see fl_fss_extended_content_write() * @see fl_fss_extended_object_write() */ #ifndef _di_fll_fss_extended_write_ - extern f_status_t fll_fss_extended_write(const f_string_static_t object, const f_string_statics_t contents, const uint8_t quote, f_state_t state, f_string_dynamic_t * const destination); + extern void fll_fss_extended_write(const f_string_static_t object, const f_string_statics_t contents, const uint8_t quote, f_string_dynamic_t * const destination, f_state_t * const state); #endif // _di_fll_fss_extended_write_ #ifdef __cplusplus diff --git a/level_2/fll_fss/c/fss/extended_list.c b/level_2/fll_fss/c/fss/extended_list.c index af34289..89e8fb7 100644 --- a/level_2/fll_fss/c/fss/extended_list.c +++ b/level_2/fll_fss/c/fss/extended_list.c @@ -5,105 +5,120 @@ extern "C" { #endif #ifndef _di_fll_fss_extended_list_read_ - f_status_t fll_fss_extended_list_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_objects_t * const objects, f_fss_contents_t * const contents, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits, f_fss_comments_t * const comments) { + void fll_fss_extended_list_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_objects_t * const objects, f_fss_contents_t * const contents, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits, f_fss_comments_t * const comments, f_state_t * const state) { #ifndef _di_level_2_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!objects) return F_status_set_error(F_parameter); - if (!contents) return F_status_set_error(F_parameter); - if (!objects_delimits) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !objects || !contents) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_2_parameter_checking_ f_status_t status = F_none; - f_status_t status2 = F_none; f_array_length_t initial_used = objects->used; bool found_data = F_false; do { - status = f_string_ranges_increase(state.step_small, objects); - if (F_status_is_error(status)) return status; + state->status = f_string_ranges_increase(state->step_small, objects); + if (F_status_is_error(state->status)) return; - status = f_string_rangess_increase(state.step_small, contents); - if (F_status_is_error(status)) return status; + state->status = f_string_rangess_increase(state->step_small, contents); + if (F_status_is_error(state->status)) return; contents->array[contents->used].used = 0; do { - status = fl_fss_extended_list_object_read(buffer, state, range, &objects->array[objects->used], objects_delimits); - if (F_status_is_error(status)) return status; + fl_fss_extended_list_object_read(buffer, range, &objects->array[objects->used], objects_delimits, state); + if (F_status_is_error(state->status)) return; if (range->start >= range->stop || range->start >= buffer.used) { - if (status == F_fss_found_object || status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object || state->status == F_fss_found_object_content_not) { ++objects->used; - status2 = f_string_ranges_increase(state.step_small, &contents->array[contents->used]); - if (F_status_is_error(status2)) return status2; + status = f_string_ranges_increase(state->step_small, &contents->array[contents->used]); + if (F_status_is_error(state->status)) { + state->status = status; + + return; + } contents->array[contents->used++].used = 0; + state->status = F_fss_found_object_content_not; - return F_fss_found_object_content_not; + return; } if (found_data) { - if (range->start >= buffer.used) return F_none_eos; - - return F_none_stop; + state->status = (range->start >= buffer.used) ? F_none_eos : F_none_stop; + } + else { + state->status = (range->start >= buffer.used) ? F_data_not_eos : F_data_not_stop; } - if (range->start >= buffer.used) return F_data_not_eos; - - return F_data_not_stop; + return; } - if (status == F_fss_found_object) { + if (state->status == F_fss_found_object) { found_data = F_true; - contents->array[contents->used].used = 0; - status = fl_fss_extended_list_content_read(buffer, state, range, &contents->array[contents->used], contents_delimits ? contents_delimits : objects_delimits, comments); - if (F_status_is_error(status)) return status; + fl_fss_extended_list_content_read(buffer, range, &contents->array[contents->used], contents_delimits ? contents_delimits : objects_delimits, comments, state); + if (F_status_is_error(state->status)) return; break; } - else if (status == F_fss_found_object_content_not) { + + if (state->status == F_fss_found_object_content_not) { found_data = F_true; - status2 = f_string_ranges_increase(state.step_small, &contents->array[contents->used]); - if (F_status_is_error(status2)) return status2; + status = f_string_ranges_increase(state->step_small, &contents->array[contents->used]); + + if (F_status_is_error(status)) { + state->status = status; + + return; + } break; } - } while (status == F_fss_found_object_not); + } while (state->status == F_fss_found_object_not); - if (status == F_none_eos || status == F_none_stop) { + if (state->status == F_none_eos || state->status == F_none_stop) { ++contents->array[contents->used++].used; ++objects->used; - return status; + return; } - if (status == F_data_not_eos || status == F_data_not_stop) { + if (state->status == F_data_not_eos || state->status == F_data_not_stop) { // If at least some valid object was found, then return F_none equivalents. if (objects->used > initial_used) { - if (status == F_data_not_eos) return F_none_eos; - if (status == F_data_not_stop) return F_none_stop; + if (state->status == F_data_not_eos) { + state->status = F_none_eos; + } + else if (state->status == F_data_not_stop) { + state->status = F_none_stop; + } } - return status; + return; } - if (status != F_fss_found_object && status != F_fss_found_content && status != F_fss_found_content_not && status != F_fss_found_object_content_not) { - return status; + if (state->status != F_fss_found_object && state->status != F_fss_found_content && state->status != F_fss_found_content_not && state->status != F_fss_found_object_content_not) { + return; } if (range->start >= range->stop || range->start >= buffer.used) { // When content is found, the range->start is incremented, if content is found at range->stop, then range->start will be > range.stop. - if (status == F_fss_found_object || status == F_fss_found_content || status == F_fss_found_content_not || status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object || state->status == F_fss_found_content || state->status == F_fss_found_content_not || state->status == F_fss_found_object_content_not) { - if (status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object_content_not) { contents->array[contents->used].used = 0; } @@ -111,12 +126,12 @@ extern "C" { ++contents->used; } - if (range->start >= buffer.used) return F_none_eos; + state->status = (range->start >= buffer.used) ? F_none_eos : F_none_stop; - return F_none_stop; + return; } - if (status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object_content_not) { contents->array[contents->used].used = 0; } @@ -125,26 +140,25 @@ extern "C" { } while (range->start < F_string_t_size_d); - return F_status_is_error(F_number_overflow); + state->status = F_status_is_error(F_number_overflow); } #endif // _di_fll_fss_extended_list_read_ #ifndef _di_fll_fss_extended_list_write_ - f_status_t fll_fss_extended_list_write(const f_string_static_t object, const f_string_static_t content, const f_string_static_t *content_prepend, const f_string_ranges_t *ignore, f_state_t state, f_string_dynamic_t * const destination) { + void fll_fss_extended_list_write(const f_string_static_t object, const f_string_static_t content, const f_string_static_t *content_prepend, const f_string_ranges_t *ignore, f_string_dynamic_t * const destination, f_state_t * const state) { #ifndef _di_level_2_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); + if (!state) return; #endif // _di_level_2_parameter_checking_ - f_status_t status = 0; f_string_range_t range = macro_f_string_range_t_initialize2(object.used); - status = fl_fss_extended_list_object_write(object, f_fss_complete_full_e, state, &range, destination); + fl_fss_extended_list_object_write(object, f_fss_complete_full_e, &range, destination, state); - if (F_status_is_error(status) || status == F_data_not_stop || status == F_data_not_eos) { - return status; + if (F_status_is_error(state->status) || state->status == F_data_not_stop || state->status == F_data_not_eos) { + return; } - if (status == F_none || status == F_none_stop || status == F_none_eos || status == F_none_eol) { + if (state->status == F_none || state->status == F_none_stop || state->status == F_none_eos || state->status == F_none_eol) { if (content.used) { range.start = 0; range.stop = content.used - 1; @@ -154,10 +168,8 @@ extern "C" { range.stop = 0; } - status = fl_fss_extended_list_content_write(content, f_fss_complete_full_e, content_prepend, ignore, state, &range, destination); + fl_fss_extended_list_content_write(content, f_fss_complete_full_e, content_prepend, ignore, &range, destination, state); } - - return status; } #endif // _di_fll_fss_extended_list_write_ diff --git a/level_2/fll_fss/c/fss/extended_list.h b/level_2/fll_fss/c/fss/extended_list.h index 0974b90..15bce8c 100644 --- a/level_2/fll_fss/c/fss/extended_list.h +++ b/level_2/fll_fss/c/fss/extended_list.h @@ -33,15 +33,6 @@ extern "C" { * * @param buffer * The buffer to read from. - * @param state - A state for providing flags and handling interrupts during long running operations. - * There is no print_error(). - * There is no functions structure. - * There is no data structure passed to these functions. - * - * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. - * Error bit designates an error but must be passed along with F_interrupt. - * All other statuses are ignored. * @param range * The range within the buffer that is currently being read. * @param objects @@ -58,24 +49,33 @@ extern "C" { * @param comments * An array of ranges representing where comments are found within any valid content. * This only stores comments found within valid content only. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * There is no print_error(). + * There is no functions structure. + * There is no data structure passed to these functions. + * + * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. + * Error bit designates an error but must be passed along with F_interrupt. + * All other statuses are ignored. * - * @return - * F_none on success (both valid object and valid content found with start location is at end of content). - * F_none_eos on success after reaching the end of the buffer (both valid object and valid content found with start location is at end of buffer). - * F_none_stop on success after reaching stopping point (both valid object and valid content found with start location is at stop point). - * F_data_not_eol if there is no data to write and EOL was reached. - * F_data_not_eos no data to write due start location being greater than or equal to buffer size. - * F_data_not_stop no data to write due start location being greater than stop location. - * F_fss_found_object_content_not on success and object was found but no content was found (start location is at end of object). + * This alters state.status: + * F_none on success (both valid object and valid content found with start location is at end of content). + * F_none_eos on success after reaching the end of the buffer (both valid object and valid content found with start location is at end of buffer). + * F_none_stop on success after reaching stopping point (both valid object and valid content found with start location is at stop point). + * F_data_not_eol if there is no data to write and EOL was reached. + * F_data_not_eos no data to write due start location being greater than or equal to buffer size. + * F_data_not_stop no data to write due start location being greater than stop location. + * F_fss_found_object_content_not on success and object was found but no content was found (start location is at end of object). * - * F_number_overflow (with error bit) if the maximum buffer size is reached. - * F_parameter (with error bit) if a parameter is invalid. + * F_number_overflow (with error bit) if the maximum buffer size is reached. + * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_string_ranges_increase(). - * Errors (with error bit) from: f_string_rangess_increase(). - * Errors (with error bit) from: f_uint8s_increase(). - * Errors (with error bit) from: fl_fss_extended_list_content_read(). - * Errors (with error bit) from: fl_fss_extended_list_object_read(). + * Errors (with error bit) from: f_string_ranges_increase(). + * Errors (with error bit) from: f_string_rangess_increase(). + * Errors (with error bit) from: f_uint8s_increase(). + * Errors (with error bit) from: fl_fss_extended_list_content_read(). + * Errors (with error bit) from: fl_fss_extended_list_object_read(). * * @see f_string_ranges_increase() * @see f_string_rangess_increase() @@ -84,7 +84,7 @@ extern "C" { * @see fl_fss_extended_list_object_read() */ #ifndef _di_fll_fss_extended_list_read_ - extern f_status_t fll_fss_extended_list_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_objects_t * const objects, f_fss_contents_t * const contents, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits, f_fss_comments_t * const comments); + extern void fll_fss_extended_list_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_objects_t * const objects, f_fss_contents_t * const contents, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits, f_fss_comments_t * const comments, f_state_t * const state); #endif // _di_fll_fss_extended_list_read_ /** @@ -102,8 +102,10 @@ extern "C" { * These ranges are only checked/ignored if there is a valid nested object open or a valid nested object close. * Any valid nested object open or valid nested object close inside an ingore range will not be escaped. * Set the pointer address to 0 to disable. + * @param destination + * The buffer where the content is written to. * @param state - A state for providing flags and handling interrupts during long running operations. + * A state for providing flags and handling interrupts during long running operations. * There is no print_error(). * There is no functions structure. * There is no data structure passed to these functions. @@ -111,28 +113,26 @@ extern "C" { * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. * Error bit designates an error but must be passed along with F_interrupt. * All other statuses are ignored. - * @param destination - * The buffer where the content is written to. * - * @return - * F_none on success. - * F_none_eos on success after reaching the end of the buffer. - * F_none_stop on success after reaching stopping point. - * F_data_not_eos no data to write due start location being greater than or equal to buffer size. - * F_data_not_stop no data to write due start location being greater than stop location. + * This alters state.status: + * F_none on success. + * F_none_eos on success after reaching the end of the buffer. + * F_none_stop on success after reaching stopping point. + * F_data_not_eos no data to write due start location being greater than or equal to buffer size. + * F_data_not_stop no data to write due start location being greater than stop location. * - * F_parameter (with error bit) if a parameter is invalid. + * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_string_dynamic_increase(). - * Errors (with error bit) from: fl_fss_extended_list_content_write(). - * Errors (with error bit) from: fl_fss_extended_list_object_write(). + * Errors (with error bit) from: f_string_dynamic_increase(). + * Errors (with error bit) from: fl_fss_extended_list_content_write(). + * Errors (with error bit) from: fl_fss_extended_list_object_write(). * * @see f_string_dynamic_increase() * @see fl_fss_extended_list_content_write() * @see fl_fss_extended_list_object_write() */ #ifndef _di_fll_fss_extended_list_write_ - extern f_status_t fll_fss_extended_list_write(const f_string_static_t object, const f_string_static_t content, const f_string_static_t *content_prepend, const f_string_ranges_t *ignore, f_state_t state, f_string_dynamic_t * const destination); + extern void fll_fss_extended_list_write(const f_string_static_t object, const f_string_static_t content, const f_string_static_t *content_prepend, const f_string_ranges_t *ignore, f_string_dynamic_t * const destination, f_state_t * const state); #endif // _di_fll_fss_extended_list_write_ #ifdef __cplusplus diff --git a/level_2/fll_fss/c/fss/payload.c b/level_2/fll_fss/c/fss/payload.c index 7d4e959..c74738a 100644 --- a/level_2/fll_fss/c/fss/payload.c +++ b/level_2/fll_fss/c/fss/payload.c @@ -5,74 +5,84 @@ extern "C" { #endif #ifndef _di_fll_fss_payload_read_ - f_status_t fll_fss_payload_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_objects_t * const objects, f_fss_contents_t * const contents, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits, f_fss_comments_t * const comments) { + void fll_fss_payload_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_objects_t * const objects, f_fss_contents_t * const contents, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits, f_fss_comments_t * const comments, f_state_t * const state) { #ifndef _di_level_2_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); - if (!objects) return F_status_set_error(F_parameter); - if (!contents) return F_status_set_error(F_parameter); - if (!objects_delimits) return F_status_set_error(F_parameter); + if (!state) return; + + if (!range || !objects || !contents) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_2_parameter_checking_ f_status_t status = F_none; - f_status_t status2 = F_none; f_array_length_t initial_used = objects->used; bool found_data = F_false; do { - status = f_string_ranges_increase(state.step_small, objects); - if (F_status_is_error(status)) return status; + state->status = f_string_ranges_increase(state->step_small, objects); + if (F_status_is_error(state->status)) return; - status = f_string_rangess_increase(state.step_small, contents); - if (F_status_is_error(status)) return status; + state->status = f_string_rangess_increase(state->step_small, contents); + if (F_status_is_error(state->status)) return; contents->array[contents->used].used = 0; do { - status = fl_fss_basic_list_object_read(buffer, state, range, &objects->array[objects->used], objects_delimits); - if (F_status_is_error(status)) return status; + fl_fss_basic_list_object_read(buffer, range, &objects->array[objects->used], objects_delimits, state); + if (F_status_is_error(state->status)) return; if (range->start >= range->stop || range->start >= buffer.used) { - if (status == F_fss_found_object || status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object || state->status == F_fss_found_object_content_not) { if (fl_string_dynamic_partial_compare_string(f_fss_payload_s.string, buffer, f_fss_payload_s.used, objects->array[objects->used]) == F_equal_to) { - status = F_fss_found_object_content_not; + state->status = F_fss_found_object_content_not; } // Returning without a "payload" is an error. else { - status = F_status_set_error(F_fss_found_object_content_not); + state->status = F_status_set_error(F_fss_found_object_content_not); } ++objects->used; - status2 = f_string_ranges_increase(state.step_small, &contents->array[contents->used]); - if (F_status_is_error(status2)) return status2; + status = f_string_ranges_increase(state->step_small, &contents->array[contents->used]); + if (F_status_is_error(status)) { + state->status = status; + + return; + } contents->array[contents->used++].used = 0; - return status; + return; } // Returning without a "payload" is an error. if (found_data) { - if (range->start >= buffer.used) return F_status_set_error(F_none_eos); - - return F_status_set_error(F_none_stop); + state->status = F_status_set_error((range->start >= buffer.used) ? F_none_eos : F_none_stop); + } + else { + state->status = F_status_set_error((range->start >= buffer.used) ? F_data_not_eos : F_data_not_stop); } - if (range->start >= buffer.used) return F_status_set_error(F_data_not_eos); - - return F_status_set_error(F_data_not_stop); + return; } - if (status == F_fss_found_object) { + if (state->status == F_fss_found_object) { found_data = F_true; contents->array[contents->used].used = 0; if (fl_string_dynamic_partial_compare_string(f_fss_payload_s.string, buffer, f_fss_payload_s.used, objects->array[objects->used]) == F_equal_to) { - status2 = f_string_ranges_increase(state.step_small, &contents->array[contents->used]); - if (F_status_is_error(status)) return status; + status = f_string_ranges_increase(state->step_small, &contents->array[contents->used]); + + if (F_status_is_error(status)) { + state->status = status; + + return; + } contents->array[contents->used].used = 1; contents->array[contents->used].array[0].start = range->start; @@ -80,80 +90,101 @@ extern "C" { if (buffer.used > range->stop) { contents->array[contents->used].array[0].stop = range->stop; range->start = range->stop + 1; - status = F_none_stop; + state->status = F_none_stop; } else { contents->array[contents->used].array[0].stop = buffer.used - 1; range->start = buffer.used; - status = F_none_eos; + state->status = F_none_eos; } ++objects->used; ++contents->used; - return status; + return; } - status = fl_fss_basic_list_content_read(buffer, state, range, &contents->array[contents->used], contents_delimits ? contents_delimits : objects_delimits, comments); - if (F_status_is_error(status)) return status; + fl_fss_basic_list_content_read(buffer, range, &contents->array[contents->used], contents_delimits ? contents_delimits : objects_delimits, comments, state); + if (F_status_is_error(state->status)) return; break; } - else if (status == F_fss_found_object_content_not) { + + if (state->status == F_fss_found_object_content_not) { found_data = F_true; - status2 = f_string_ranges_increase(state.step_small, &contents->array[contents->used]); - if (F_status_is_error(status2)) return status2; + status = f_string_ranges_increase(state->step_small, &contents->array[contents->used]); + + if (F_status_is_error(status)) { + state->status = status; + + return; + } contents->array[contents->used].used = 0; if (fl_string_dynamic_partial_compare_string(f_fss_payload_s.string, buffer, f_fss_payload_s.used, objects->array[objects->used]) == F_equal_to) { ++objects->used; - status2 = f_string_ranges_increase(state.step_small, &contents->array[contents->used]); - if (F_status_is_error(status2)) return status2; + status = f_string_ranges_increase(state->step_small, &contents->array[contents->used]); + + if (F_status_is_error(status)) { + state->status = status; + + return; + } contents->array[contents->used++].used = 0; + state->status = F_none; - return F_none; + return; } break; } - } while (status == F_fss_found_object_not); + } while (state->status == F_fss_found_object_not); - if (status == F_none_eos || status == F_none_stop) { + if (state->status == F_none_eos || state->status == F_none_stop) { ++contents->array[contents->used].used; ++objects->used; ++contents->used; // Returning without a "payload" is an error. - return F_status_set_error(status); + state->status = F_status_set_error(state->status); + + return; } - if (status == F_data_not_eos || status == F_data_not_stop) { + if (state->status == F_data_not_eos || state->status == F_data_not_stop) { // If at least some valid object was found, then return F_none equivalents. if (objects->used > initial_used) { // Returning without a "payload" is an error. - if (status == F_data_not_eos) return F_status_set_error(F_none_eos); - if (status == F_data_not_stop) return F_status_set_error(F_none_stop); + if (state->status == F_data_not_eos) { + state->status = F_status_set_error(F_none_eos); + } + else if (state->status == F_data_not_stop) { + state->status = F_status_set_error(F_none_stop); + } + } + else { + state->status = F_status_set_error(state->status); } - return F_status_set_error(status); + return; } - if (status != F_fss_found_object && status != F_fss_found_content && status != F_fss_found_content_not && status != F_fss_found_object_content_not) { - return status; + if (state->status != F_fss_found_object && state->status != F_fss_found_content && state->status != F_fss_found_content_not && state->status != F_fss_found_object_content_not) { + return; } if (range->start >= range->stop || range->start >= buffer.used) { // When content is found, the range->start is incremented, if content is found at range->stop, then range->start will be > range.stop. - if (status == F_fss_found_object || status == F_fss_found_content || status == F_fss_found_content_not || status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object || state->status == F_fss_found_content || state->status == F_fss_found_content_not || state->status == F_fss_found_object_content_not) { - if (status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object_content_not) { contents->array[contents->used].used = 0; } @@ -162,12 +193,12 @@ extern "C" { } // Returning without a "payload" is an error. - if (range->start >= buffer.used) return F_status_set_error(F_none_eos); + state->status = F_status_set_error((range->start >= buffer.used) ? F_none_eos : F_none_stop); - return F_status_set_error(F_none_stop); + return; } - if (status == F_fss_found_object_content_not) { + if (state->status == F_fss_found_object_content_not) { contents->array[contents->used].used = 0; } @@ -176,39 +207,43 @@ extern "C" { } while (range->start < F_string_t_size_d); - return F_status_is_error(F_number_overflow); + state->status = F_status_is_error(F_number_overflow); } #endif // _di_fll_fss_payload_read_ #ifndef _di_fll_fss_payload_write_ - f_status_t fll_fss_payload_write(const f_string_static_t object, const f_string_static_t content, const bool trim, const f_string_static_t * const content_prepend, f_state_t state, f_string_dynamic_t * const destination) { + void fll_fss_payload_write(const f_string_static_t object, const f_string_static_t content, const bool trim, const f_string_static_t * const content_prepend, f_string_dynamic_t * const destination, f_state_t * const state) { #ifndef _di_level_2_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); + if (!state) return; + + if (!destination) { + state->status = F_status_set_error(F_parameter); + + return; + } #endif // _di_level_2_parameter_checking_ - f_status_t status = 0; f_string_range_t range = macro_f_string_range_t_initialize2(object.used); - status = fl_fss_basic_list_object_write(object, trim ? f_fss_complete_full_trim_e : f_fss_complete_full_e, state, &range, destination); + fl_fss_basic_list_object_write(object, trim ? f_fss_complete_full_trim_e : f_fss_complete_full_e, &range, destination, state); - if (F_status_is_error(status) || status == F_data_not_stop || status == F_data_not_eos) { - return status; + if (F_status_is_error(state->status) || state->status == F_data_not_stop || state->status == F_data_not_eos) { + return; } - if (status == F_none || status == F_none_stop || status == F_none_eos || status == F_none_eol) { + if (state->status == F_none || state->status == F_none_stop || state->status == F_none_eos || state->status == F_none_eol) { if (fl_string_dynamic_compare(f_fss_payload_s, object) == F_equal_to) { - status = f_string_dynamic_increase_by(content.used, destination); - if (F_status_is_error(status)) return status; + state->status = f_string_dynamic_increase_by(content.used, destination); + if (F_status_is_error(state->status)) return; f_array_length_t i = 0; // Copy in blocks to allow for interruptability of potentially large data sets. for (; i < content.used && i + F_fss_default_block_size_normal_d < content.used; i += F_fss_default_block_size_normal_d) { - if (state.interrupt) { - status = state.interrupt((void *) &state, 0); - - if (F_status_set_fine(status) == F_interrupt) return F_status_set_error(F_interrupt); + if (state->interrupt) { + state->interrupt((void *) &state, 0); + if (F_status_set_fine(state->status) == F_interrupt) return; } memcpy(destination->string + destination->used + i, content.string + i, sizeof(f_char_t) * F_fss_default_block_size_normal_d); @@ -230,11 +265,9 @@ extern "C" { range.stop = 0; } - status = fl_fss_basic_list_content_write(content, f_fss_complete_full_e, content_prepend, state, &range, destination); + fl_fss_basic_list_content_write(content, f_fss_complete_full_e, content_prepend, &range, destination, state); } } - - return status; } #endif // _di_fll_fss_payload_write_ diff --git a/level_2/fll_fss/c/fss/payload.h b/level_2/fll_fss/c/fss/payload.h index 4c9f7eb..87acdfc 100644 --- a/level_2/fll_fss/c/fss/payload.h +++ b/level_2/fll_fss/c/fss/payload.h @@ -37,15 +37,6 @@ extern "C" { * * @param buffer * The buffer to read from. - * @param state - A state for providing flags and handling interrupts during long running operations. - * There is no print_error(). - * There is no functions structure. - * There is no data structure passed to these functions. - * - * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. - * Error bit designates an error but must be passed along with F_interrupt. - * All other statuses are ignored. * @param range * The range within the buffer that is currently being read. * @param objects @@ -62,33 +53,42 @@ extern "C" { * @param comments * An array of ranges representing where comments are found within any valid content. * This only stores comments found within valid content only. + * @param state + * A state for providing flags and handling interrupts during long running operations. + * There is no print_error(). + * There is no functions structure. + * There is no data structure passed to these functions. + * + * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. + * Error bit designates an error but must be passed along with F_interrupt. + * All other statuses are ignored. * - * @return - * F_none on success. - * F_none_eos on success after reaching the end of the buffer. - * F_none_stop on success after reaching stopping point. - * F_data_not_eos no data to write due start location being greater than or equal to buffer size. - * F_data_not_stop no data to write due start location being greater than stop location. - * - * F_fss_found_object_content_not (with error bit) When payload Content is missing. - * F_data_not_eos (with error bit) no data to write due start location being greater than or equal to buffer size, except that no "payload" is found. - * F_data_not_stop (with error bit) no data to write due start location being greater than stop location, except that no "payload" is found. - * F_none (with error bit) on success, except that no "payload" is found. - * F_none_eos (with error bit) on success after reaching the end of the buffer, except that no "payload" is found. - * F_none_stop (with error bit) on success after reaching stopping point, except that no "payload" is found. - * F_number_overflow (with error bit) if the maximum buffer size is reached. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: fl_fss_basic_list_content_read(). - * Errors (with error bit) from: fl_fss_basic_list_object_read(). - * - * F_number_overflow (with error bit) if the maximum buffer size is reached. - * - * Errors (with error bit) from: f_string_ranges_increase(). - * Errors (with error bit) from: f_string_rangess_increase(). - * Errors (with error bit) from: f_uint8s_increase(). - * Errors (with error bit) from: fl_fss_basic_list_content_read(). - * Errors (with error bit) from: fl_fss_basic_list_object_read(). + * This alters state.status: + * F_none on success. + * F_none_eos on success after reaching the end of the buffer. + * F_none_stop on success after reaching stopping point. + * F_data_not_eos no data to write due start location being greater than or equal to buffer size. + * F_data_not_stop no data to write due start location being greater than stop location. + * + * F_fss_found_object_content_not (with error bit) When payload Content is missing. + * F_data_not_eos (with error bit) no data to write due start location being greater than or equal to buffer size, except that no "payload" is found. + * F_data_not_stop (with error bit) no data to write due start location being greater than stop location, except that no "payload" is found. + * F_none (with error bit) on success, except that no "payload" is found. + * F_none_eos (with error bit) on success after reaching the end of the buffer, except that no "payload" is found. + * F_none_stop (with error bit) on success after reaching stopping point, except that no "payload" is found. + * F_number_overflow (with error bit) if the maximum buffer size is reached. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: fl_fss_basic_list_content_read(). + * Errors (with error bit) from: fl_fss_basic_list_object_read(). + * + * F_number_overflow (with error bit) if the maximum buffer size is reached. + * + * Errors (with error bit) from: f_string_ranges_increase(). + * Errors (with error bit) from: f_string_rangess_increase(). + * Errors (with error bit) from: f_uint8s_increase(). + * Errors (with error bit) from: fl_fss_basic_list_content_read(). + * Errors (with error bit) from: fl_fss_basic_list_object_read(). * * @see f_string_ranges_increase() * @see f_string_rangess_increase() @@ -97,7 +97,7 @@ extern "C" { * @see fl_fss_basic_list_object_read() */ #ifndef _di_fll_fss_payload_read_ - extern f_status_t fll_fss_payload_read(const f_string_static_t buffer, f_state_t state, f_string_range_t * const range, f_fss_objects_t * const objects, f_fss_contents_t * const contents, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits, f_fss_comments_t * const comments); + extern void fll_fss_payload_read(const f_string_static_t buffer, f_string_range_t * const range, f_fss_objects_t * const objects, f_fss_contents_t * const contents, f_fss_delimits_t * const objects_delimits, f_fss_delimits_t * const contents_delimits, f_fss_comments_t * const comments, f_state_t * const state); #endif // _di_fll_fss_payload_read_ /** @@ -120,8 +120,10 @@ extern "C" { * A string to prepend at the start of each line in content, such as spaces. * This will not be prepended for the Object "payload". * Set the pointer address to 0 to disable. + * @param destination + * The buffer to append to. * @param state - A state for providing flags and handling interrupts during long running operations. + * A state for providing flags and handling interrupts during long running operations. * There is no print_error(). * There is no functions structure. * There is no data structure passed to these functions. @@ -129,28 +131,26 @@ extern "C" { * When interrupt() returns, only F_interrupt and F_interrupt_not are processed. * Error bit designates an error but must be passed along with F_interrupt. * All other statuses are ignored. - * @param destination - * The buffer to append to. * - * @return - * F_none on success. - * F_none_eos on success after reaching the end of the buffer. - * F_none_stop on success after reaching stopping point. - * F_data_not_eos no data to write due start location being greater than or equal to buffer size. - * F_data_not_stop no data to write due start location being greater than stop location. + * This alters state.status: + * F_none on success. + * F_none_eos on success after reaching the end of the buffer. + * F_none_stop on success after reaching stopping point. + * F_data_not_eos no data to write due start location being greater than or equal to buffer size. + * F_data_not_stop no data to write due start location being greater than stop location. * - * F_parameter (with error bit) if a parameter is invalid. + * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_string_dynamic_increase(). - * Errors (with error bit) from: fl_fss_basic_list_content_write(). - * Errors (with error bit) from: fl_fss_basic_list_object_write(). + * Errors (with error bit) from: f_string_dynamic_increase(). + * Errors (with error bit) from: fl_fss_basic_list_content_write(). + * Errors (with error bit) from: fl_fss_basic_list_object_write(). * * @see f_string_dynamic_increase() * @see fl_fss_basic_list_content_write() * @see fl_fss_basic_list_object_write() */ #ifndef _di_fll_fss_payload_write_ - extern f_status_t fll_fss_payload_write(const f_string_static_t object, const f_string_static_t content, const bool trim, const f_string_static_t * const content_prepend, f_state_t state, f_string_dynamic_t * const destination); + extern void fll_fss_payload_write(const f_string_static_t object, const f_string_static_t content, const bool trim, const f_string_static_t * const content_prepend, f_string_dynamic_t * const destination, f_state_t * const state); #endif // _di_fll_fss_payload_write_ #ifdef __cplusplus diff --git a/level_3/byte_dump/c/byte_dump.h b/level_3/byte_dump/c/byte_dump.h index 08a862f..336abe7 100644 --- a/level_3/byte_dump/c/byte_dump.h +++ b/level_3/byte_dump/c/byte_dump.h @@ -108,8 +108,6 @@ extern "C" { * * @param arguments * The parameters passed to the process (often referred to as command line arguments). - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param main * The main program data. * @param setting @@ -120,12 +118,14 @@ extern "C" { * * Errors (with error bit) from: f_console_parameter_process(). * Errors (with error bit) from: fll_program_parameter_process_context(). + * @param state + * A state for providing flags and handling interrupts during long running operations. * * @see f_console_parameter_process() * @see fll_program_parameter_process_context() */ #ifndef _di_byte_dump_setting_load_ - extern void byte_dump_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, byte_dump_setting_t * const setting); + extern void byte_dump_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, byte_dump_setting_t * const setting, f_state_t * const state); #endif // _di_byte_dump_setting_load_ /** diff --git a/level_3/byte_dump/c/common.c b/level_3/byte_dump/c/common.c index 3745e86..3cdc827 100644 --- a/level_3/byte_dump/c/common.c +++ b/level_3/byte_dump/c/common.c @@ -77,14 +77,14 @@ extern "C" { #endif // _di_byte_dump_setting_delete_ #ifndef _di_byte_dump_setting_load_ - void byte_dump_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, byte_dump_setting_t * const setting) { + void byte_dump_setting_load(const f_console_arguments_t arguments, f_state_t * const state, fll_program_data_t * const main, byte_dump_setting_t * const setting) { if (!main || !setting) return; setting->flag = 0; // Load parameters. - setting->status = f_console_parameter_process(state, arguments, &main->parameters, 0); + setting->status = f_console_parameter_process(arguments, state, &main->parameters, 0); if (F_status_is_error(setting->status)) { byte_dump_print_line_first_locked(setting, main->error); diff --git a/level_3/byte_dump/c/common.h b/level_3/byte_dump/c/common.h index 39933ee..1bdc0a8 100644 --- a/level_3/byte_dump/c/common.h +++ b/level_3/byte_dump/c/common.h @@ -392,7 +392,7 @@ extern "C" { * * flag: Flags passed to the main function. * - * status: The main status code, generally used by the load settings and main functions. + * state: The state information. * * line_first: A string expected to represent either "\n" or NULL to allow for easy handling of when to print first new line or not. * line_last: A string expected to represent either "\n" or NULL to allow for easy handling of when to print last new line or not. @@ -401,7 +401,7 @@ extern "C" { typedef struct { uint16_t flag; - f_status_t status; + f_state_t state; f_string_static_t line_first; f_string_static_t line_last; @@ -410,7 +410,7 @@ extern "C" { #define byte_dump_setting_t_initialize \ { \ byte_dump_main_flag_none_e, \ - F_none, \ + f_state_initialize_t, \ f_string_static_t_initialize, \ f_string_static_t_initialize, \ } diff --git a/level_3/control/c/common.c b/level_3/control/c/common.c index 508174b..0b50b01 100644 --- a/level_3/control/c/common.c +++ b/level_3/control/c/common.c @@ -180,14 +180,14 @@ extern "C" { #endif // _di_control_setting_delete_ #ifndef _di_control_setting_load_ - void control_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, control_setting_t * const setting) { + void control_setting_load(const f_console_arguments_t arguments, f_state_t * const state, fll_program_data_t * const main, control_setting_t * const setting) { if (!main || !setting) return; setting->flag = 0; // Load parameters. - setting->status = f_console_parameter_process(state, arguments, &main->parameters, 0); + setting->status = f_console_parameter_process(arguments, state, &main->parameters, 0); if (F_status_is_error(setting->status)) { control_print_line_first_locked(setting, main->error); diff --git a/level_3/control/c/common.h b/level_3/control/c/common.h index bf877c8..cc3fa40 100644 --- a/level_3/control/c/common.h +++ b/level_3/control/c/common.h @@ -227,7 +227,7 @@ extern "C" { * * flag: Flags passed to the main function. * - * status: The main status code, generally used by the load settings and main functions. + * state: The state information. * * line_first: A string expected to represent either "\n" or NULL to allow for easy handling of when to print first new line or not. * line_last: A string expected to represent either "\n" or NULL to allow for easy handling of when to print last new line or not. @@ -236,7 +236,7 @@ extern "C" { typedef struct { uint16_t flag; - f_status_t status; + f_state_t state; f_string_static_t line_first; f_string_static_t line_last; @@ -245,7 +245,7 @@ extern "C" { #define control_setting_t_initialize \ { \ control_main_flag_none_e, \ - F_none, \ + f_state_t_initialize, \ f_string_static_t_initialize, \ f_string_static_t_initialize, \ } @@ -333,8 +333,6 @@ extern "C" { * * @param arguments * The parameters passed to the process (often referred to as command line arguments). - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param main * The main program data. * @param setting @@ -345,12 +343,14 @@ extern "C" { * * Errors (with error bit) from: f_console_parameter_process(). * Errors (with error bit) from: fll_program_parameter_process_context(). + * @param state + * A state for providing flags and handling interrupts during long running operations. * * @see f_console_parameter_process() * @see fll_program_parameter_process_context() */ #ifndef _di_control_setting_load_ - extern void control_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, control_setting_t * const setting); + extern void control_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, control_setting_t * const setting, f_state_t * const state); #endif // _di_control_setting_load_ /** diff --git a/level_3/controller/c/common.c b/level_3/controller/c/common.c index b5f38c5..a73cf7b 100644 --- a/level_3/controller/c/common.c +++ b/level_3/controller/c/common.c @@ -612,14 +612,14 @@ extern "C" { #endif // _di_controller_setting_delete_ #ifndef _di_controller_setting_load_ - void controller_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, controller_setting_t * const setting) { + void controller_setting_load(const f_console_arguments_t arguments, f_state_t * const state, fll_program_data_t * const main, controller_setting_t * const setting) { if (!main || !setting) return; setting->flag = 0; // Load parameters. - setting->status = f_console_parameter_process(state, arguments, &main->parameters, 0); + setting->status = f_console_parameter_process(arguments, state, &main->parameters, 0); if (F_status_is_error(setting->status)) { controller_print_line_first_locked(setting, main->error); diff --git a/level_3/controller/c/common.h b/level_3/controller/c/common.h index 9504f82..a194952 100644 --- a/level_3/controller/c/common.h +++ b/level_3/controller/c/common.h @@ -485,7 +485,7 @@ extern "C" { * * flag: Flags passed to the main function. * - * status: The main status code, generally used by the load settings and main functions. + * state: The state information. * * line_first: A string expected to represent either "\n" or NULL to allow for easy handling of when to print first new line or not. * line_last: A string expected to represent either "\n" or NULL to allow for easy handling of when to print last new line or not. @@ -494,7 +494,7 @@ extern "C" { typedef struct { uint16_t flag; - f_status_t status; + f_state_t state; f_string_static_t line_first; f_string_static_t line_last; @@ -503,7 +503,7 @@ extern "C" { #define controller_setting_t_initialize \ { \ controller_main_flag_none_e, \ - F_none, \ + f_state_t_initialize, \ f_string_static_t_initialize, \ f_string_static_t_initialize, \ } @@ -726,8 +726,6 @@ extern "C" { * * @param arguments * The parameters passed to the process (often referred to as command line arguments). - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param main * The main program data. * @param setting @@ -738,12 +736,14 @@ extern "C" { * * Errors (with error bit) from: f_console_parameter_process(). * Errors (with error bit) from: fll_program_parameter_process_context(). + * @param state + * A state for providing flags and handling interrupts during long running operations. * * @see f_console_parameter_process() * @see fll_program_parameter_process_context() */ #ifndef _di_controller_setting_load_ - extern void controller_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, controller_setting_t * const setting); + extern void controller_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, controller_setting_t * const setting, f_state_t * const state); #endif // _di_controller_setting_load_ /** diff --git a/level_3/controller/c/rule/private-rule.c b/level_3/controller/c/rule/private-rule.c index ba3d9f4..0194fd3 100644 --- a/level_3/controller/c/rule/private-rule.c +++ b/level_3/controller/c/rule/private-rule.c @@ -60,7 +60,7 @@ extern "C" { #endif // _di_controller_rule_find_ #ifndef _di_controller_rule_parameters_read_ - f_status_t controller_rule_parameters_read(const controller_global_t global, const f_string_static_t buffer, const f_state_t state, f_fss_object_t * const object, f_fss_content_t * const content, controller_rule_action_t * const action) { + f_status_t controller_rule_parameters_read(const controller_global_t global, const f_string_static_t buffer, f_fss_object_t * const object, f_fss_content_t * const content, controller_rule_action_t * const action, f_state_t * const state) { f_status_t status = F_none; @@ -153,7 +153,7 @@ extern "C" { range.start = 0; range.stop = action->parameters.array[action->parameters.used].used - 1; - status = fl_iki_read(state, &action->parameters.array[action->parameters.used], &range, &action->ikis.array[action->ikis.used]); + status = fl_iki_read(&action->parameters.array[action->parameters.used], &range, &action->ikis.array[action->ikis.used], state); if (F_status_is_error(status)) { controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "fl_iki_read", F_true); @@ -305,7 +305,7 @@ extern "C" { f_string_range_t range_iki = macro_f_string_range_t_initialize2(actions->array[actions->used].parameters.array[0].used); - status = fl_iki_read(state, &actions->array[actions->used].parameters.array[0], &range_iki, &actions->array[actions->used].ikis.array[0]); + status = fl_iki_read(&actions->array[actions->used].parameters.array[0], &range_iki, &actions->array[actions->used].ikis.array[0], state); if (F_status_is_error(status)) { controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "fl_iki_read", F_true); @@ -610,7 +610,7 @@ extern "C" { f_string_range_t range_iki = macro_f_string_range_t_initialize2(actions->array[actions->used].parameters.array[0].used); - status = fl_iki_read(state, &actions->array[actions->used].parameters.array[0], &range_iki, &actions->array[actions->used].ikis.array[0]); + status = fl_iki_read(&actions->array[actions->used].parameters.array[0], &range_iki, &actions->array[actions->used].ikis.array[0], state); if (F_status_is_error(status)) { controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "fl_iki_read", F_true); @@ -2389,7 +2389,7 @@ extern "C" { cache->delimits.used = 0; // The current line is not an Extended List object, so the next possibility is a Basic List (and Extended List, both use the same Object structure). - status = fl_fss_extended_object_read(cache->buffer_item, state, &range, &cache->range_action, 0, &cache->delimits); + fl_fss_extended_object_read(cache->buffer_item, &range, &cache->range_action, 0, &cache->delimits, state); if (F_status_is_error(status)) { controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "fl_fss_extended_object_read", F_true); diff --git a/level_3/controller/c/rule/private-rule.h b/level_3/controller/c/rule/private-rule.h index 6f3deb7..83c6191 100644 --- a/level_3/controller/c/rule/private-rule.h +++ b/level_3/controller/c/rule/private-rule.h @@ -72,8 +72,6 @@ extern "C" { * The global data. * @param buffer * The buffer containing the content. - * @param state - * The state data for passing to fl_iki_read(). * @param object * (optional) The range representing where the object is found within the buffer. * Set pointer address to 0 to disable. @@ -82,6 +80,8 @@ extern "C" { * Set pointer address to 0 to disable. * @param action * The rule action. + * @param state + * The state data for passing to fl_iki_read(). * * @return * F_none on success. @@ -101,7 +101,7 @@ extern "C" { * @see fl_iki_read() */ #ifndef _di_controller_rule_parameters_read_ - extern f_status_t controller_rule_parameters_read(const controller_global_t global, const f_string_static_t buffer, const f_state_t state, f_fss_object_t * const object, f_fss_content_t * const content, controller_rule_action_t * const action) F_attribute_visibility_internal_d; + extern f_status_t controller_rule_parameters_read(const controller_global_t global, const f_string_static_t buffer, f_fss_object_t * const object, f_fss_content_t * const content, controller_rule_action_t * const action, f_state_t * const state) F_attribute_visibility_internal_d; #endif // _di_controller_rule_parameters_read_ /** diff --git a/level_3/fake/c/main/build.c b/level_3/fake/c/main/build.c index f161ccc..cd542f9 100644 --- a/level_3/fake/c/main/build.c +++ b/level_3/fake/c/main/build.c @@ -377,11 +377,11 @@ const f_string_static_t fake_build_documentation_files_s = macro_f_string_static memcpy(path_source.string, source.string, sizeof(f_char_t) * source.used); - fl_directory_recurse_t recurse = fl_directory_recurse_t_initialize; + f_directory_recurse_t recurse = f_directory_recurse_t_initialize; if (data->main->error.verbosity >= f_console_verbosity_verbose_e) { recurse.output = data->main->message.to; - recurse.verbose = fake_verbose_print_copy; + recurse.verbose = fake_print_verbose_copy; } recurse.failures = &failures; @@ -533,6 +533,8 @@ const f_string_static_t fake_build_documentation_files_s = macro_f_string_static macro_f_directory_statuss_t_delete_simple(failures); + f_directory_recurse_delete(&recurse); + f_string_dynamic_resize(0, &path_source); f_string_dynamic_resize(0, &destination_file); f_string_dynamic_resize(0, &destination_directory); diff --git a/level_3/fake/c/main/build/print-verbose.h b/level_3/fake/c/main/build/print-verbose.h index cafaeeb..377d947 100644 --- a/level_3/fake/c/main/build/print-verbose.h +++ b/level_3/fake/c/main/build/print-verbose.h @@ -32,7 +32,7 @@ extern "C" { * F_none on success. * F_output_not on success, but no printing is performed. * - * @see fake_print_simple() + * @see fake_print_simple_variable() */ #ifndef _di_fake_build_print_verbose_create_directory_ extern f_status_t fake_build_print_verbose_create_directory(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t directory); diff --git a/level_3/fake/c/main/clean.c b/level_3/fake/c/main/clean.c index 7ffed96..61ee581 100644 --- a/level_3/fake/c/main/clean.c +++ b/level_3/fake/c/main/clean.c @@ -23,10 +23,10 @@ extern "C" { f_status_t status = F_none; if (data->main->error.verbosity >= f_console_verbosity_verbose_e) { - status = f_directory_remove_custom(data->setting->build, F_directory_descriptors_max_d, F_true, fake_clean_remove_recursively_verbosely); + status = f_directory_remove_custom(data->setting->build, F_directory_max_descriptors_d, F_true, fake_clean_remove_recursively_verbosely); } else { - status = f_directory_remove(data->setting->build, F_directory_descriptors_max_d, F_true); + status = f_directory_remove(data->setting->build, F_directory_max_descriptors_d, F_true); } if (F_status_set_fine(status) == F_file_found_not || F_status_set_fine(status) == F_directory) { diff --git a/level_3/fake/c/main/clean/print.c b/level_3/fake/c/main/clean/print.c deleted file mode 100644 index 9dcac6e..0000000 --- a/level_3/fake/c/main/clean/print.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "../fake.h" -#include "print.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_3/fake/c/main/clean/print.h b/level_3/fake/c/main/clean/print.h deleted file mode 100644 index f8c77fa..0000000 --- a/level_3/fake/c/main/clean/print.h +++ /dev/null @@ -1,23 +0,0 @@ -/** - * FLL - Level 3 - * - * Project: Featureless Make - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Provides clean print functionality. - * - * This is auto-included and should not need to be explicitly included. - */ -#ifndef _PRIVATE_clean_print_h -#define _PRIVATE_clean_print_h - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // _PRIVATE_clean_print_h diff --git a/level_3/fake/c/main/common.c b/level_3/fake/c/main/common.c index a6adff9..f6aa6d5 100644 --- a/level_3/fake/c/main/common.c +++ b/level_3/fake/c/main/common.c @@ -29,7 +29,7 @@ extern "C" { #endif // _di_fake_setting_delete_ #ifndef _di_fake_setting_load_ - void fake_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fake_setting_t * const setting) { + void fake_setting_load(const f_console_arguments_t arguments, f_state_t * const state, fll_program_data_t * const main, fake_setting_t * const setting) { if (!main || !setting) return; @@ -43,7 +43,7 @@ extern "C" { data.setting = setting; // Load parameters. - setting->status = f_console_parameter_process(state, arguments, &main->parameters, (void *) &data); + setting->status = f_console_parameter_process(arguments, &main->parameters, state, (void *) &data); } if (F_status_is_error(setting->status)) { @@ -451,7 +451,7 @@ extern "C" { if (!state) return; if (!void_parameters || !void_data || (state->type != f_console_parameter_state_type_simple_e && state->type != f_console_parameter_state_type_miss_e)) { - state->status = F_process; + state->state->status = F_process; return; } @@ -459,10 +459,10 @@ extern "C" { f_console_parameters_t * const parameters = (f_console_parameters_t * const) void_parameters; fake_data_t * const data = (fake_data_t * const) void_data; - state->status = f_uint8s_increase(fake_default_allocation_small_d, &data->setting->operations); + state->state->status = f_uint8s_increase(fake_default_allocation_small_d, &data->setting->operations); - if (F_status_is_error(state->status)) { - fake_print_error(data->setting, data->main->error, state->status, macro_fake_f(f_uint8s_increase)); + if (F_status_is_error(state->state->status)) { + fake_print_error(data->setting, data->main->error, state->state->status, macro_fake_f(f_uint8s_increase)); return; } @@ -493,12 +493,12 @@ extern "C" { break; default: - state->status = F_process; + state->state->status = F_process; return; } - state->status = F_none; + state->state->status = F_none; } #endif // _di_fake_setting_load_parameter_callback_ diff --git a/level_3/fake/c/main/common.h b/level_3/fake/c/main/common.h index f6199e1..20470d7 100644 --- a/level_3/fake/c/main/common.h +++ b/level_3/fake/c/main/common.h @@ -42,8 +42,6 @@ extern "C" { * * @param arguments * The parameters passed to the process (often referred to as command line arguments). - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param main * The main program data. * @param setting @@ -54,12 +52,14 @@ extern "C" { * * Errors (with error bit) from: f_console_parameter_process(). * Errors (with error bit) from: fll_program_parameter_process_context(). + * @param state + * A state for providing flags and handling interrupts during long running operations. * * @see f_console_parameter_process() * @see fll_program_parameter_process_context() */ #ifndef _di_fake_setting_load_ - extern void fake_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fake_setting_t * const setting); + extern void fake_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, fake_setting_t * const setting, f_state_t * const state); #endif // _di_fake_setting_load_ /** diff --git a/level_3/fake/c/main/common/type.h b/level_3/fake/c/main/common/type.h index 166b894..1c33e55 100644 --- a/level_3/fake/c/main/common/type.h +++ b/level_3/fake/c/main/common/type.h @@ -61,7 +61,6 @@ extern "C" { * flag: Flags passed to the main function. * * state: The state data used when processing the FSS data. - * status: The main status code, generally used by the load settings and main functions. * * line_first: A string expected to represent either "\n" or NULL to allow for easy handling of when to print first new line or not. * line_last: A string expected to represent either "\n" or NULL to allow for easy handling of when to print last new line or not. @@ -84,7 +83,6 @@ extern "C" { uint32_t flag; f_state_t state; - f_status_t status; f_string_static_t line_first; f_string_static_t line_last; @@ -109,7 +107,6 @@ extern "C" { { \ fake_main_flag_print_first_e, \ f_state_t_initialize, \ - F_none, \ f_string_static_t_initialize, \ f_string_static_t_initialize, \ f_string_dynamic_t_initialize, \ diff --git a/level_3/fake/c/main/fake.c b/level_3/fake/c/main/fake.c index 24491ff..8bc3e66 100644 --- a/level_3/fake/c/main/fake.c +++ b/level_3/fake/c/main/fake.c @@ -213,7 +213,9 @@ extern "C" { fake_print_line_last_locked(setting, main->error); } else if (setting->status != F_child) { - fake_print_operation_all_complete(setting, main->message); + if (F_status_is_error_not(setting->status)) { + fake_print_operation_all_complete(setting, main->message); + } if (setting->status != F_interrupt) { fake_print_line_last_locked(setting, main->message); @@ -531,24 +533,6 @@ extern "C" { } #endif // _di_fake_validate_parameter_paths_ -#ifndef _di_fake_verbose_print_clone_ - void fake_verbose_print_clone(const f_file_t output, const f_string_static_t source, const f_string_static_t destination) { - fll_print_format("Cloned '%Q' to '%Q'.%r", output, source, destination, f_string_eol_s); - } -#endif // _di_fake_verbose_print_clone_ - -#ifndef _di_fake_verbose_print_copy_ - void fake_verbose_print_copy(const f_file_t output, const f_string_static_t source, const f_string_static_t destination) { - fll_print_format("Copied '%Q' to '%Q'.%r", output, source, destination, f_string_eol_s); - } -#endif // _di_fake_verbose_print_copy_ - -#ifndef _di_fake_verbose_print_move_ - void fake_verbose_print_move(const f_file_t output, const f_string_static_t source, const f_string_static_t destination) { - fll_print_format("Moved '%Q' to '%Q'.%r", output, source, destination, f_string_eol_s); - } -#endif // _di_fake_verbose_print_move_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/fake/c/main/fake.h b/level_3/fake/c/main/fake.h index 7479367..a14503e 100644 --- a/level_3/fake/c/main/fake.h +++ b/level_3/fake/c/main/fake.h @@ -104,6 +104,7 @@ #include #include #include +#include #include #ifdef __cplusplus @@ -233,48 +234,6 @@ extern "C" { extern f_status_t fake_validate_parameter_paths(fake_data_t * const data); #endif // _di_fake_validate_parameter_paths_ -/** - * Helper function for performing a verbose print for a file clone operation. - * - * @param output - * A file to print to. - * @param source - * The source string. - * @param destination - * The destination string. - */ -#ifndef _di_fake_verbose_print_clone_ - extern void fake_verbose_print_clone(const f_file_t output, const f_string_static_t source, const f_string_static_t destination); -#endif // _di_fake_verbose_print_clone_ - -/** - * Helper function for performing a verbose print for a file copy operation. - * - * @param output - * A file to print to. - * @param source - * The source string. - * @param destination - * The destination string. - */ -#ifndef _di_fake_verbose_print_copy_ - extern void fake_verbose_print_copy(const f_file_t output, const f_string_static_t source, const f_string_static_t destination); -#endif // _di_fake_verbose_print_copy_ - -/** - * Helper function for performing a verbose print for a file move operation. - * - * @param output - * A file to print to. - * @param source - * The source string. - * @param destination - * The destination string. - */ -#ifndef _di_fake_verbose_print_move_ - extern void fake_verbose_print_move(const f_file_t output, const f_string_static_t source, const f_string_static_t destination); -#endif // _di_fake_verbose_print_move_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/fake/c/main/make.c b/level_3/fake/c/main/make.c index 7df1c31..702000a 100644 --- a/level_3/fake/c/main/make.c +++ b/level_3/fake/c/main/make.c @@ -58,15 +58,7 @@ extern "C" { } if (status == F_exist_not) { - if (data->main->error.verbosity > f_console_verbosity_quiet_e) { - f_file_stream_lock(data->main->error.to); - - fl_print_format("%r%[%QThe group name '%]", data->main->error.to, f_string_eol_s, data->main->error.context, data->main->error.prefix, data->main->error.context); - fl_print_format("%[%Q%]", data->main->error.to, data->main->error.notable, buffer, data->main->error.notable); - fl_print_format("%[' is not found.%]%r", data->main->error.to, data->main->error.context, data->main->error.context, f_string_eol_s); - - f_file_stream_unlock(data->main->error.to); - } + fake_print_error_group_not_found(data->setting, data->main->error, buffer); return F_status_set_error(F_failure); } @@ -80,15 +72,7 @@ extern "C" { } if (number > F_type_size_32_unsigned_d) { - if (data->main->error.verbosity > f_console_verbosity_quiet_e) { - f_file_stream_lock(data->main->error.to); - - fl_print_format("%r%[%QThe number '%]", data->main->error.to, f_string_eol_s, data->main->error.context, data->main->error.prefix, data->main->error.context); - fl_print_format("%[%un%]", data->main->error.to, data->main->error.notable, number, data->main->error.notable); - fl_print_format("%[' is too large.%]%r", data->main->error.to, data->main->error.context, data->main->error.context, f_string_eol_s); - - f_file_stream_unlock(data->main->error.to); - } + fake_print_error_number_too_large(data->setting, data->main->error, buffer); } *id = (gid_t) number; @@ -109,19 +93,11 @@ extern "C" { const f_status_t status = f_file_mode_from_string(buffer, data->main->umask, mode, replace); if (F_status_is_error(status)) { - if (data->main->error.verbosity > f_console_verbosity_quiet_e) { - if (F_status_set_fine(status) == F_syntax) { - f_file_stream_lock(data->main->error.to); - - fl_print_format("%r%[%QThe mode '%]", data->main->error.to, f_string_eol_s, data->main->error.context, data->main->error.prefix, data->main->error.context); - fl_print_format("%[%Q%]", data->main->error.to, data->main->error.notable, buffer, data->main->error.notable); - fl_print_format("%[' is invalid.%]%r", data->main->error.to, data->main->error.context, data->main->error.context, f_string_eol_s); - - f_file_stream_unlock(data->main->error.to); - } - else { - fake_print_error(data->setting, print, status, macro_fake_f(fll_execute_arguments_add)); - } + if (F_status_set_fine(status) == F_syntax) { + fake_print_error_mode_invalid(data->setting, data->main->error, buffer); + } + else { + fake_print_error(data->setting, print, status, macro_fake_f(fll_execute_arguments_add)); } return status; @@ -151,15 +127,7 @@ extern "C" { } if (status == F_exist_not) { - if (data->main->error.verbosity > f_console_verbosity_quiet_e) { - f_file_stream_lock(data->main->error.to); - - fl_print_format("%r%[%QThe user '%]", data->main->error.to, f_string_eol_s, data->main->error.context, data->main->error.prefix, data->main->error.context); - fl_print_format("%[%Q%]", data->main->error.to, data->main->error.notable, buffer, data->main->error.notable); - fl_print_format("%[' is not found.%]%r", data->main->error.to, data->main->error.context, data->main->error.context, f_string_eol_s); - - f_file_stream_unlock(data->main->error.to); - } + fake_print_error_user_not_found(data->setting, data->main->error, buffer); return F_status_set_error(F_failure); } @@ -173,15 +141,7 @@ extern "C" { } if (number > F_type_size_32_unsigned_d) { - if (data->main->error.verbosity > f_console_verbosity_quiet_e) { - f_file_stream_lock(data->main->error.to); - - fl_print_format("%r%[%QThe number '%]", data->main->error.to, f_string_eol_s, data->main->error.context, data->main->error.prefix, data->main->error.context); - fl_print_format("%[%un%]", data->main->error.to, data->main->error.notable, number, data->main->error.notable); - fl_print_format("%[' is too large.%]%r", data->main->error.to, data->main->error.context, data->main->error.context, f_string_eol_s); - - f_file_stream_unlock(data->main->error.to); - } + fake_print_error_number_too_large(data->setting, data->main->error, buffer); } *id = (uid_t) number; diff --git a/level_3/fake/c/main/make/operate.c b/level_3/fake/c/main/make/operate.c index b9b2444..b310f11 100644 --- a/level_3/fake/c/main/make/operate.c +++ b/level_3/fake/c/main/make/operate.c @@ -374,7 +374,7 @@ extern "C" { range = content.array[i]; - *status = fl_iki_read(state, &data_make->buffer, &range, iki_data); + *status = fl_iki_read(&data_make->buffer, &range, iki_data, state); if (F_status_is_error(*status)) { if (F_status_set_fine(*status) != F_interrupt) { diff --git a/level_3/fake/c/main/make/operate_block.c b/level_3/fake/c/main/make/operate_block.c index 90c0300..f0034e5 100644 --- a/level_3/fake/c/main/make/operate_block.c +++ b/level_3/fake/c/main/make/operate_block.c @@ -60,7 +60,7 @@ extern "C" { return; } - // When done processing an operation within an if/else condition, update the process state. + // When done processing an operation within an if/else condition, update the process state-> if (state_process->block == fake_state_process_block_done_e) { // Nothing to do. } diff --git a/level_3/fake/c/main/make/operate_process_type.c b/level_3/fake/c/main/make/operate_process_type.c index 2ae1f15..f69f078 100644 --- a/level_3/fake/c/main/make/operate_process_type.c +++ b/level_3/fake/c/main/make/operate_process_type.c @@ -205,13 +205,13 @@ extern "C" { const f_array_length_t total = data_make->cache_arguments.used - 1; f_string_static_t destination = f_string_static_t_initialize; - fl_directory_recurse_t recurse = fl_directory_recurse_t_initialize; + f_directory_recurse_t recurse = f_directory_recurse_t_initialize; f_mode_t mode = f_mode_t_initialize; if (clone) { if (data_make->main->error.verbosity >= f_console_verbosity_verbose_e) { recurse.output = data_make->main->message.to; - recurse.verbose = fake_verbose_print_clone; + recurse.verbose = fake_print_verbose_clone; } recurse.flag = f_file_stat_flag_group_e | f_file_stat_flag_owner_e; @@ -221,7 +221,7 @@ extern "C" { if (data_make->main->error.verbosity >= f_console_verbosity_verbose_e) { recurse.output = data_make->main->message.to; - recurse.verbose = fake_verbose_print_copy; + recurse.verbose = fake_print_verbose_copy; } } @@ -317,6 +317,8 @@ extern "C" { if (F_status_is_error(status_file)) { fake_print_error_file(data_make->setting, data_make->main->error, status_file, clone ? macro_fake_f(f_file_clone) : macro_fake_f(f_file_copy), data_make->cache_arguments.array[i], clone ? f_file_operation_clone_s : f_file_operation_copy_s, fll_error_file_type_file_e); + f_directory_recurse_delete(&recurse); + return F_status_set_error(F_failure); } @@ -325,10 +327,14 @@ extern "C" { else if (F_status_is_error(status_file)) { fake_print_error_file(data_make->setting, data_make->main->error, status_file, macro_fake_f(f_directory_is), data_make->cache_arguments.array[i], f_file_operation_identify_s, fll_error_file_type_directory_e); + f_directory_recurse_delete(&recurse); + return F_status_set_error(F_failure); } } // for + f_directory_recurse_delete(&recurse); + return F_none; } #endif // _di_fake_make_operate_process_type_copy_ @@ -361,7 +367,7 @@ extern "C" { f_status_t status = F_none; - const int recursion_max = all ? F_directory_descriptors_max_d : 0; + const int recursion_max = all ? F_directory_max_descriptors_d : 0; struct stat file_stat; for (f_array_length_t i = 0; i < data_make->cache_arguments.used; ++i) { @@ -1269,7 +1275,7 @@ extern "C" { if ((flag & 0x1) && f_file_exists(data_make->cache_arguments.array[data_make->cache_arguments.used - 1], F_false) == F_true) { if (f_directory_is(data_make->cache_arguments.array[data_make->cache_arguments.used - 1]) == F_true) { - status = f_directory_remove(data_make->cache_arguments.array[data_make->cache_arguments.used - 1], F_directory_descriptors_max_d, F_false); + status = f_directory_remove(data_make->cache_arguments.array[data_make->cache_arguments.used - 1], F_directory_max_descriptors_d, F_false); if (F_status_is_error(status)) { fake_print_error_file(data_make->setting, data_make->main->error, status, macro_fake_f(f_directory_remove), data_make->cache_arguments.array[data_make->cache_arguments.used - 1], f_file_operation_delete_s, fll_error_file_type_directory_e); @@ -1366,13 +1372,13 @@ extern "C" { const f_array_length_t total = data_make->cache_arguments.used -1; - fl_directory_recurse_t recurse = fl_directory_recurse_t_initialize; + f_directory_recurse_t recurse = f_directory_recurse_t_initialize; f_string_static_t destination = f_string_static_t_initialize; if (data_make->main->error.verbosity >= f_console_verbosity_verbose_e) { recurse.output = data_make->main->message.to; - recurse.verbose = fake_verbose_print_move; + recurse.verbose = fake_print_verbose_move; } bool existing = F_true; diff --git a/level_3/fake/c/main/print-error.c b/level_3/fake/c/main/print-error.c index 764d836..5628ce0 100644 --- a/level_3/fake/c/main/print-error.c +++ b/level_3/fake/c/main/print-error.c @@ -21,17 +21,8 @@ extern "C" { f_status_t fake_print_error_argument_empty(fake_setting_t * const setting, const fl_print_t print, const f_array_length_t index) { if (print.verbosity == f_console_verbosity_quiet_e) return F_output_not; - if (!print.to.stream) return F_output_not; - f_file_stream_lock(print.to); - - fake_print_line_first_unlocked(setting, print); - - fl_print_format("%[%QThe %]", print.to, f_string_eol_s, print.context, print.prefix, print.context); - fl_print_format("%[%un%]", print.to, print.notable, index, print.notable); - fl_print_format("%[ argument must not be an empty string.%]%r", print.to, print.context, print.context, f_string_eol_s); - - f_file_stream_unlock(print.to); + fake_print_context_wrapped_number(setting, print, "The ", (f_number_unsigned_t) index, " argument must not be an empty string"); return F_none; } @@ -188,9 +179,9 @@ extern "C" { #endif // _di_fake_print_error_build_operation_file_ #ifndef _di_fake_print_error_build_operation_file_full_ - void fake_print_error_build_operation_file_full(fake_setting_t * const setting, const fl_print_t print, const f_string_t before, const f_string_static_t operation, const f_string_static_t source, const f_string_static_t destination, const f_string_static_t how, const f_string_t after) { + f_status_t fake_print_error_build_operation_file_full(fake_setting_t * const setting, const fl_print_t print, const f_string_t before, const f_string_static_t operation, const f_string_static_t source, const f_string_static_t destination, const f_string_static_t how, const f_string_t after) { - if (!setting) return; + if (!setting || print.verbosity < f_console_verbosity_error_e) return F_output_not; f_file_stream_lock(print.to); @@ -208,6 +199,8 @@ extern "C" { fl_print_format("%S.%]%r", print.to, print.context, after, print.context, f_string_eol_s); f_file_stream_unlock(print.to); + + return F_none; } #endif // _di_fake_print_error_build_operation_file_full_ @@ -228,6 +221,17 @@ extern "C" { } #endif // _di_fake_print_error_build_operation_file_partial_ +#ifndef _di_fake_print_error_directory_create_parent_missing_ + f_status_t fake_print_error_directory_create_parent_missing(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t path) { + + if (!setting || print.verbosity < f_console_verbosity_error_e) return F_output_not; + + fake_print_context_wrapped_variable(setting, print, "The directory ", path, " could not be created, a parent directory is missing or invalid"); + + return F_none; + } +#endif // _di_fake_print_error_directory_create_parent_missing_ + #ifndef _di_fake_print_error_failure_operation_ f_status_t fake_print_error_failure_operation(fake_setting_t * const setting, const fl_print_t print, const uint8_t operation) { @@ -297,6 +301,17 @@ extern "C" { } #endif // _di_fake_print_error_file_ +#ifndef _di_fake_print_error_file_create_parent_missing_ + f_status_t fake_print_error_file_create_parent_missing(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t path) { + + if (!setting || print.verbosity < f_console_verbosity_error_e) return F_output_not; + + fake_print_context_wrapped_variable(setting, print, "The file ", path, " could not be created, a parent directory is missing or invalid"); + + return F_none; + } +#endif // _di_fake_print_error_file_create_parent_missing_ + #ifndef _di_fake_print_error_file_fallback_ f_status_t fake_print_error_file_fallback(fake_setting_t * const setting, const fl_print_t print, const f_status_t status, const f_string_t function, const f_string_static_t name, const f_string_static_t operation, const uint8_t type) { @@ -398,6 +413,39 @@ extern "C" { } #endif // _di_fake_print_error_fss_message_ +#ifndef _di_fake_print_error_group_not_found_ + f_status_t fake_print_error_group_not_found(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t group) { + + if (!setting || print.verbosity < f_console_verbosity_error_e) return F_output_not; + + fake_print_context_wrapped_variable(setting, print, "The group ", group, " is not found"); + + return F_none; + } +#endif // _di_fake_print_error_group_not_found_ + +#ifndef _di_fake_print_error_mode_invalid_ + f_status_t fake_print_error_mode_invalid(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t mode) { + + if (!setting || print.verbosity < f_console_verbosity_error_e) return F_output_not; + + fake_print_context_wrapped_variable(setting, print, "The mode ", mode, " is invalid"); + + return F_none; + } +#endif // _di_fake_print_error_mode_invalid_ + +#ifndef _di_fake_print_error_number_too_large_ + f_status_t fake_print_error_number_too_large(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t number) { + + if (!setting || print.verbosity < f_console_verbosity_error_e) return F_output_not; + + fake_print_context_wrapped_variable(setting, print, "The number ", number, " is too large"); + + return F_none; + } +#endif // _di_fake_print_error_number_too_large_ + #ifndef _di_fake_print_error_operation_failed_ f_status_t fake_print_error_operation_failed(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t buffer, const f_string_range_t section_name, const f_string_range_t operation_name) { @@ -652,6 +700,17 @@ extern "C" { } #endif // _di_fake_print_error_too_many_arguments_ +#ifndef _di_fake_print_error_user_not_found_ + f_status_t fake_print_error_user_not_found(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t user) { + + if (!setting || print.verbosity < f_console_verbosity_error_e) return F_output_not; + + fake_print_context_wrapped_variable(setting, print, "The user ", user, " is not found"); + + return F_none; + } +#endif // _di_fake_print_error_user_not_found_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/fake/c/main/print-error.h b/level_3/fake/c/main/print-error.h index b1c3228..9de04aa 100644 --- a/level_3/fake/c/main/print-error.h +++ b/level_3/fake/c/main/print-error.h @@ -35,7 +35,11 @@ extern "C" { * F_none on success. * F_output_not on success, but no printing is performed. * - * @see fll_error_print() + * @see f_file_stream_lock() + * @see f_file_stream_unlock() + * @see fl_print_format() + * + * @see fake_print_line_first_unlocked() */ #ifndef _di_fake_print_error_ extern f_status_t fake_print_error(fake_setting_t * const setting, const fl_print_t print, const f_status_t status, const f_string_t function); @@ -44,8 +48,12 @@ extern "C" { /** * Print an error message for when an argument is an empty string. * - * @param data_make - * All make related setting data, including data from the fakefile and the build settings file. + * @param setting + * The main program settings. + * + * This does not alter setting.status. + * @param print + * Designates the how and where to print. * @param index * The index of the argument that is an empty string. * @@ -53,7 +61,7 @@ extern "C" { * F_none on success. * F_output_not on success, but no printing is performed. * - * @see fll_print_format() + * @see fake_print_context_wrapped_number() */ #ifndef _di_fake_print_error_argument_empty_ extern f_status_t fake_print_error_argument_empty(fake_setting_t * const setting, const fl_print_t print, const f_array_length_t index); @@ -93,14 +101,14 @@ extern "C" { * @see f_file_stream_unlock() * @see fl_print_format() * - * @see fake_print_error_build_operation_file_partial(); + * @see fake_print_line_first_unlocked() */ #ifndef _di_fake_print_error_build_operation_file_ extern f_status_t fake_print_error_build_operation_file(fake_setting_t * const setting, const fl_print_t print, const f_status_t status, const f_string_t function, const f_string_static_t operation, const f_string_static_t source, const f_string_static_t destination, const f_string_static_t how, const bool fallback); #endif // _di_fake_print_error_build_operation_file_ /** - * Helper function for printing build operation file error messages. + * Print build operation file error messages. * * This prints the "copy source to destination" part of the message. * @@ -134,7 +142,7 @@ extern "C" { * @see fake_print_line_first_unlocked() */ #ifndef _di_fake_print_error_build_operation_file_full_ - extern void fake_print_error_build_operation_file_full(fake_setting_t * const setting, const fl_print_t print, const f_string_t before, const f_string_static_t operation, const f_string_static_t source, const f_string_static_t destination, const f_string_static_t how, const f_string_t after); + extern f_status_t fake_print_error_build_operation_file_full(fake_setting_t * const setting, const fl_print_t print, const f_string_t before, const f_string_static_t operation, const f_string_static_t source, const f_string_static_t destination, const f_string_static_t how, const f_string_t after); #endif // _di_fake_print_error_build_operation_file_full_ /** @@ -167,6 +175,28 @@ extern "C" { #endif // _di_fake_print_error_build_operation_file_partial_ /** + * Print error message regarding file create directory failure due to a missing or invalid parent directory. + * + * @param setting + * The main program settings. + * + * This does not alter setting.status. + * @param print + * Designates the how and where to print. + * @param path + * The name of the file or directory. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * @see fake_print_context_wrapped_variable() + */ +#ifndef _di_fake_print_error_file_create_parent_missing_ + extern f_status_t fake_print_error_file_create_parent_missing(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t path); +#endif // _di_fake_print_error_file_create_parent_missing_ + +/** * Print error message for when an operation fails. * * @param setting @@ -274,6 +304,28 @@ extern "C" { #endif // _di_fake_print_error_file_ /** + * Print error message regarding file create failure due to a missing or invalid parent directory. + * + * @param setting + * The main program settings. + * + * This does not alter setting.status. + * @param print + * Designates the how and where to print. + * @param path + * The name of the file or directory. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * @see fake_print_context_wrapped_variable() + */ +#ifndef _di_fake_print_error_directory_create_parent_missing_ + extern f_status_t fake_print_error_directory_create_parent_missing(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t path); +#endif // _di_fake_print_error_directory_create_parent_missing_ + +/** * Print file related error message regarding a function failing in some way, setting fallback to F_false and returning result.. * * @param setting @@ -411,6 +463,72 @@ extern "C" { #endif // _di_fake_print_error_fss_message_ /** + * Print error message regarding the group not being found. + * + * @param setting + * The main program settings. + * + * This does not alter setting.status. + * @param print + * Designates the how and where to print. + * @param group + * A string representing the group (either as a name or as a group ID). + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * @see fake_print_context_wrapped_variable() + */ +#ifndef _di_fake_print_error_group_not_found_ + extern f_status_t fake_print_error_group_not_found(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t group); +#endif // _di_fake_print_error_group_not_found_ + +/** + * Print error message regarding the mode being invalid. + * + * @param setting + * The main program settings. + * + * This does not alter setting.status. + * @param print + * Designates the how and where to print. + * @param mode + * A string representing the invalid mode. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * @see fake_print_context_wrapped_variable() + */ +#ifndef _di_fake_print_error_mode_invalid_ + extern f_status_t fake_print_error_mode_invalid(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t mode); +#endif // _di_fake_print_error_mode_invalid_ + +/** + * Print error message regarding the number being too large. + * + * @param setting + * The main program settings. + * + * This does not alter setting.status. + * @param print + * Designates the how and where to print. + * @param number + * A string representing the number that is too large. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * @see fake_print_context_wrapped_variable() + */ +#ifndef _di_fake_print_error_number_too_large_ + extern f_status_t fake_print_error_number_too_large(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t number); +#endif // _di_fake_print_error_number_too_large_ + +/** * Print error messages when processing some fakefile section, for a specific line and operation, and that operation failed. * * @param data @@ -743,6 +861,28 @@ extern "C" { extern f_status_t fake_print_error_too_many_arguments(fake_setting_t * const setting, const fl_print_t print); #endif // _di_fake_print_error_too_many_arguments_ +/** + * Print error message regarding the user not being found. + * + * @param setting + * The main program settings. + * + * This does not alter setting.status. + * @param print + * Designates the how and where to print. + * @param user + * A string representing the user (either as a name or as a user ID). + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * @see fake_print_context_wrapped_variable() + */ +#ifndef _di_fake_print_error_user_not_found_ + extern f_status_t fake_print_error_user_not_found(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t user); +#endif // _di_fake_print_error_user_not_found_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/fake/c/main/print-verbose.c b/level_3/fake/c/main/print-verbose.c new file mode 100644 index 0000000..ed26852 --- /dev/null +++ b/level_3/fake/c/main/print-verbose.c @@ -0,0 +1,107 @@ +#include "fake.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_fake_print_verbose_clone_ + f_status_t fake_print_verbose_clone(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t source, const f_string_static_t destination) { + + if (!setting || print.verbosity < f_console_verbosity_verbose_e) return F_output_not; + + fake_print_wrapped_variables(setting, print, "Cloned ", source, " to ", destination, 0); + + return F_none; + } +#endif // _di_fake_print_verbose_clone_ + +#ifndef _di_fake_print_verbose_copy_ + f_status_t fake_print_verbose_copy(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t source, const f_string_static_t destination) { + + if (!setting || print.verbosity < f_console_verbosity_verbose_e) return F_output_not; + + fll_print_format("Copied '%Q' to '%Q'.%r", output, source, destination, f_string_eol_s); + } +#endif // _di_fake_print_verbose_copy_ + +#ifndef _di_fake_print_verbose_create_directory_ + f_status_t fake_print_verbose_create_directory(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t path) { + + if (!setting || print.verbosity < f_console_verbosity_verbose_e) return F_output_not; + + fake_print_simple_variable(setting, print, "Created directory ", path); + + return F_none; + } +#endif // _di_fake_print_verbose_create_directory_ + +#ifndef _di_fake_print_verbose_create_file_ + f_status_t fake_print_verbose_create_file(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t path) { + + if (!setting || print.verbosity < f_console_verbosity_verbose_e) return F_output_not; + + fake_print_simple_variable(setting, print, "Created file ", path); + + return F_none; + } +#endif // _di_fake_print_verbose_create_file_ + +#ifndef _di_fake_print_verbose_directory_exists_ + f_status_t fake_print_verbose_directory_exists(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t path) { + + if (!setting || print.verbosity < f_console_verbosity_verbose_e) return F_output_not; + + fake_print_wrapped_variable(setting, print, "Directory ", path, " already exists"); + + return F_none; + } +#endif // _di_fake_print_verbose_directory_exists_ + +#ifndef _di_fake_print_verbose_file_exists_ + f_status_t fake_print_verbose_file_exists(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t path) { + + if (!setting || print.verbosity < f_console_verbosity_verbose_e) return F_output_not; + + fake_print_wrapped_variable(setting, print, "File ", path, " already exists"); + } +#endif // _di_fake_print_verbose_file_exists_ + +#ifndef _di_fake_print_verbose_file_exists_as_link_ + f_status_t fake_print_verbose_file_exists_as_link(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t path) { + + if (!setting || print.verbosity < f_console_verbosity_verbose_e) return F_output_not; + + fake_print_wrapped_variable(setting, print, "File ", path, " already exists (as a symbolic link)"); + } +#endif // _di_fake_print_verbose_file_exists_as_link_ + +#ifndef _di_fake_print_verbose_file_exists_not_regular_or_link_ + f_status_t fake_print_verbose_file_exists_not_regular_or_link(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t path) { + + if (!setting || print.verbosity < f_console_verbosity_verbose_e) return F_output_not; + + fake_print_wrapped_variable(setting, print, "File ", path, " already exists but is not a regular file (or a symbolic link)"); + } +#endif // _di_fake_print_verbose_file_exists_not_regular_or_link_ + +#ifndef _di_fake_print_verbose_file_pre_populated_ + f_status_t fake_print_verbose_file_pre_populated(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t path) { + + if (!setting || print.verbosity < f_console_verbosity_verbose_e) return F_output_not; + + fake_print_simple_variable(setting, print, "Pre-populated file ", path); + } +#endif // _di_fake_print_verbose_file_pre_populated_ + +#ifndef _di_fake_print_verbose_move_ + f_status_t fake_print_verbose_move(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t source, const f_string_static_t destination) { + + if (!setting || print.verbosity < f_console_verbosity_verbose_e) return F_output_not; + + fll_print_format("Moved '%Q' to '%Q'.%r", output, source, destination, f_string_eol_s); + } +#endif // _di_fake_print_verbose_move_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/fake/c/main/print-verbose.h b/level_3/fake/c/main/print-verbose.h new file mode 100644 index 0000000..e838d70 --- /dev/null +++ b/level_3/fake/c/main/print-verbose.h @@ -0,0 +1,249 @@ +/** + * FLL - Level 3 + * + * Project: Featureless Make + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides the verbose print functionality. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _fake_print_verbose_h +#define _fake_print_verbose_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Helper function for performing a verbose print for a file clone operation. + * + * @param setting + * The main program settings. + * + * This does not alter setting.status. + * @param print + * Designates the how and where to print. + * @param source + * The source string. + * @param destination + * The destination string. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * @see fake_print_wrapped_variables() + */ +#ifndef _di_fake_print_verbose_clone_ + extern f_status_t fake_print_verbose_clone(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t source, const f_string_static_t destination); +#endif // _di_fake_print_verbose_clone_ + +/** + * Helper function for performing a verbose print for a file copy operation. + * + * @param setting + * The main program settings. + * + * This does not alter setting.status. + * @param print + * Designates the how and where to print. + * @param source + * The source string. + * @param destination + * The destination string. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * @see fake_print_wrapped_variables() + */ +#ifndef _di_fake_print_verbose_copy_ + extern f_status_t fake_print_verbose_copy(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t source, const f_string_static_t destination); +#endif // _di_fake_print_verbose_copy_ + +/** + * Print verbose message about creating a directory. + * + * @param setting + * The main program settings. + * + * This does not alter setting.status. + * @param print + * Designates the how and where to print. + * @param path + * The name of the file. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * @see fake_print_simple_variable() + */ +#ifndef _di_fake_print_verbose_create_directory_ + extern f_status_t fake_print_verbose_create_directory(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t path); +#endif // _di_fake_print_verbose_create_directory_ + +/** + * Print verbose message about creating a file. + * + * @param setting + * The main program settings. + * + * This does not alter setting.status. + * @param print + * Designates the how and where to print. + * @param path + * The name of the file. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * @see fake_print_simple_variable() + */ +#ifndef _di_fake_print_verbose_create_file_ + extern f_status_t fake_print_verbose_create_file(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t path); +#endif // _di_fake_print_verbose_create_file_ + +/** + * Print a verbose message for when a directory already exists. + * + * @param setting + * The main program settings. + * + * This does not alter setting.status. + * @param print + * Designates the how and where to print. + * @param path + * The name of the directory. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * @see fake_print_wrapped_variable() + */ +#ifndef _di_fake_print_verbose_directory_exists_ + extern f_status_t fake_print_verbose_directory_exists(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t path); +#endif // _di_fake_print_verbose_directory_exists_ + +/** + * Print a verbose message for when a file already exists. + * + * @param setting + * The main program settings. + * + * This does not alter setting.status. + * @param print + * Designates the how and where to print. + * @param path + * The name of the file or directory. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * @see fake_print_wrapped_variable() + */ +#ifndef _di_fake_print_verbose_file_exists_ + extern f_status_t fake_print_verbose_file_exists(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t path); +#endif // _di_fake_print_verbose_file_exists_ + +/** + * Print a verbose message for when a file already exists as a symbolic link. + * + * @param setting + * The main program settings. + * + * This does not alter setting.status. + * @param print + * Designates the how and where to print. + * @param path + * The name of the file or directory. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * @see fake_print_wrapped_variable() + */ +#ifndef _di_fake_print_verbose_file_exists_as_link_ + extern f_status_t fake_print_verbose_file_exists_as_link(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t path); +#endif // _di_fake_print_verbose_file_exists_as_link_ + +/** + * Print a verbose message for when a file already exists but is not a regular file or a symbolic link. + * + * @param setting + * The main program settings. + * + * This does not alter setting.status. + * @param print + * Designates the how and where to print. + * @param path + * The name of the file or directory. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * @see fake_print_wrapped_variable() + */ +#ifndef _di_fake_print_verbose_file_exists_not_regular_or_link_ + extern f_status_t fake_print_verbose_file_exists_not_regular_or_link(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t path); +#endif // _di_fake_print_verbose_file_exists_not_regular_or_link_ + +/** + * Print a verbose message for when a file is pre-populated. + * + * @param setting + * The main program settings. + * + * This does not alter setting.status. + * @param print + * Designates the how and where to print. + * @param path + * The name of the file or directory. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * @see fake_print_simple_variable() + */ +#ifndef _di_fake_print_verbose_file_pre_populated_ + extern f_status_t fake_print_verbose_file_pre_populated(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t path); +#endif // _di_fake_print_verbose_file_pre_populated_ + +/** +* Print a verbose message for when a file is moved. + * + * @param setting + * The main program settings. + * + * This does not alter setting.status. + * @param print + * Designates the how and where to print. + * @param source + * The source string. + * @param destination + * The destination string. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * @see fake_print_wrapped_variables() + */ +#ifndef _di_fake_print_verbose_move_ + extern f_status_t fake_print_verbose_move(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t source, const f_string_static_t destination); +#endif // _di_fake_print_verbose_move_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _fake_print_verbose_h diff --git a/level_3/fake/c/main/print-warning.c b/level_3/fake/c/main/print-warning.c index 11b1a4c..8a2aa48 100644 --- a/level_3/fake/c/main/print-warning.c +++ b/level_3/fake/c/main/print-warning.c @@ -4,6 +4,17 @@ extern "C" { #endif +#ifndef _di_fake_print_warning_path_exists_not_directory_ + f_status_t fake_print_warning_path_exists_not_directory(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t path) { + + if (!setting || print.verbosity < f_console_verbosity_verbose_e) return F_output_not; + + fake_print_context_wrapped_variable(setting, print, "The path ", path, " exists but is not a directory"); + + return F_none; + } +#endif // _di_fake_print_warning_path_exists_not_directory_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/fake/c/main/print-warning.h b/level_3/fake/c/main/print-warning.h index bc8f51b..b2d6a9f 100644 --- a/level_3/fake/c/main/print-warning.h +++ b/level_3/fake/c/main/print-warning.h @@ -16,6 +16,28 @@ extern "C" { #endif +/** + * Print warning message about path existing but is not a directory. + * + * @param setting + * The main program settings. + * + * This does not alter setting.status. + * @param print + * Designates the how and where to print. + * @param path + * The name of the file or directory. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * @see fake_print_context_wrapped_variable() + */ +#ifndef _di_fake_print_warning_path_exists_not_directory_ + extern f_status_t fake_print_warning_path_exists_not_directory(fake_setting_t * const setting, const fl_print_t print, const f_string_static_t path); +#endif // _di_fake_print_warning_path_exists_not_directory_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/fake/c/main/print.c b/level_3/fake/c/main/print.c index c141ea7..f0d10b1 100644 --- a/level_3/fake/c/main/print.c +++ b/level_3/fake/c/main/print.c @@ -36,6 +36,23 @@ extern "C" { } #endif // _di_fake_print_context_simple_variable_ +#ifndef _di_fake_print_context_wrapped_number_ + void fake_print_context_wrapped_number(fake_setting_t * const setting, const fl_print_t print, const f_string_t before, const f_number_unsigned_t number, const f_string_t after) { + + if (!setting) return; + + f_file_stream_lock(print.to); + + fake_print_line_first_unlocked(setting, print); + + fl_print_format("%[%Q%S'%]", print.to, print.context, print.prefix, before, print.context); + fl_print_format("%[%un%]", print.to, print.notable, number, print.notable); + fl_print_format("%['%S.%]%r", print.to, print.context, after, print.context, f_string_eol_s); + + f_file_stream_unlock(print.to); + } +#endif // _di_fake_print_context_wrapped_number_ + #ifndef _di_fake_print_context_wrapped_parameter_ void fake_print_context_wrapped_parameter(fake_setting_t * const setting, const fl_print_t print, const f_string_t before, const f_string_static_t symbol, const f_string_static_t name, const f_string_t after) { @@ -110,6 +127,17 @@ extern "C" { } #endif // _di_fake_print_context_wrapped_variables_ +#ifndef _di_fake_print_generating_skeleton_ + f_status_t fake_print_generating_skeleton(fake_setting_t * const setting, const fl_print_t print) { + + if (!setting || print.verbosity < f_console_verbosity_normal_e) return F_output_not; + + fake_print_simple(setting, print, "Generating skeleton structure"); + + return F_none; + } +#endif // _di_fake_print_generating_skeleton_ + #ifndef _di_fake_print_help_ f_status_t fake_print_help(fake_setting_t * const setting, const fl_print_t print) { @@ -261,7 +289,6 @@ extern "C" { f_status_t fake_print_operation_all_complete(fake_setting_t * const setting, const fl_print_t print) { if (!setting || print.verbosity < f_console_verbosity_normal_e) return F_output_not; - if (F_status_is_error(setting->status)) return F_output_not; f_file_stream_lock(print.to); diff --git a/level_3/fake/c/main/print.h b/level_3/fake/c/main/print.h index 3c42e29..25f452a 100644 --- a/level_3/fake/c/main/print.h +++ b/level_3/fake/c/main/print.h @@ -77,6 +77,40 @@ extern "C" { #endif // _di_fake_print_context_simple_variable_ /** + * Print a variable context message with a before string, an after string, and an unsigned number variable. + * + * This is primarily used by numerous print functions to reduce code. + * This is not used for any print functions that has complex format structures. + * + * @param setting + * The main program settings. + * (Must be of type fake_setting_t.) + * + * This does not alter setting.status. + * @param print + * The output structure to print to. + * @param before + * The string being printed before the variable. + * Likely should have a space added at the end of the string. + * Set to NULL to disable. + * @param number + * The number representing the variable. + * @param after + * The string being printed after the variable. + * Likely should have a space added at the start of the string. + * Set to NULL to disable. + * + * @see f_file_stream_lock() + * @see f_file_stream_unlock() + * @see fl_print_format() + * + * @see fake_print_line_first_unlocked() + */ +#ifndef _di_fake_print_context_wrapped_number_ + extern void fake_print_context_wrapped_number(fake_setting_t * const setting, const fl_print_t print, const f_string_t before, const f_number_unsigned_t number, const f_string_t after); +#endif // _di_fake_print_context_wrapped_number_ + +/** * Print a parameter context message with a before string, an after string, a string symbol, and a parameter name. * * This is primarily used by numerous print functions to reduce code. @@ -240,6 +274,27 @@ extern "C" { #endif // _di_fake_print_context_wrapped_variables_ /** + * Print a message about generating skeleton. + * + * @param setting + * The main program settings. + * (Must be of type fake_setting_t.) + * + * This does not alter setting.status. + * @param print + * The output structure to print to. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * @see fake_print_line_first_unlocked() + */ +#ifndef _di_fake_print_generating_skeleton_ + extern f_status_t fake_print_generating_skeleton(fake_setting_t * const setting, const fl_print_t print); +#endif // _di_fake_print_generating_skeleton_ + +/** * Print help. * * @param setting diff --git a/level_3/fake/c/main/skeleton.c b/level_3/fake/c/main/skeleton.c index fc96093..b351366 100644 --- a/level_3/fake/c/main/skeleton.c +++ b/level_3/fake/c/main/skeleton.c @@ -11,7 +11,7 @@ extern "C" { f_status_t status = F_none; if (data->main->message.verbosity != f_console_verbosity_quiet_e && data->main->message.verbosity != f_console_verbosity_error_e) { - fll_print_format("%rGenerating skeleton structure.%r", data->main->message.to, f_string_eol_s, f_string_eol_s); + fake_print_generating_skeleton(data->setting, data->main->message); if (data->main->message.verbosity >= f_console_verbosity_verbose_e) { fll_print_dynamic(f_string_eol_s, data->main->message.to); @@ -134,23 +134,13 @@ extern "C" { f_status_t status = f_directory_exists(path); if (status == F_true) { - if (data->main->error.verbosity >= f_console_verbosity_verbose_e) { - fll_print_format("Directory '%Q' already exists.%r", data->main->message.to, path, f_string_eol_s); - } + fake_print_verbose_directory_exists(data->setting, data->main->message, path); return F_none; } if (status == F_false) { - if (data->main->error.verbosity > f_console_verbosity_quiet_e) { - f_file_stream_lock(data->main->error.to); - - fl_print_format("%r%[%QThe path '%]", data->main->error.to, f_string_eol_s, data->main->error.context, data->main->error.prefix, data->main->error.context); - fl_print_format("%[%Q%]", data->main->error.to, data->main->error.notable, path, data->main->error.notable); - fl_print_format("%[' exists but is not a directory.%]%r", data->main->error.to, data->main->error.context, data->main->error.context, f_string_eol_s); - - f_file_stream_unlock(data->main->error.to); - } + fake_print_warning_path_exists_not_directory(data->setting, data->main->warning, path); return F_status_set_warning(F_failure); } @@ -159,13 +149,7 @@ extern "C" { if (F_status_is_error(status)) { if (F_status_set_fine(status) == F_file_found_not) { - f_file_stream_lock(data->main->error.to); - - fl_print_format("%r%[%QThe path '%]", data->main->error.to, f_string_eol_s, data->main->error.context, data->main->error.prefix, data->main->error.context); - fl_print_format("%[%Q%]", data->main->error.to, data->main->error.notable, path, data->main->error.notable); - fl_print_format("%[' could not be created, a parent directory does not exist.%]%r", data->main->error.to, data->main->error.context, data->main->error.context, f_string_eol_s); - - f_file_stream_unlock(data->main->error.to); + fake_print_error_directory_create_parent_missing(data->setting, data->main->error, path); } else { fake_print_error_file(data->setting, data->main->error, status, macro_fake_f(f_directory_create), path, f_file_operation_create_s, fll_error_file_type_directory_e); @@ -174,9 +158,7 @@ extern "C" { return status; } - if (data->main->error.verbosity >= f_console_verbosity_verbose_e) { - fll_print_format("Directory '%Q' created.%r", data->main->message.to, path, f_string_eol_s); - } + fake_print_verbose_create_directory(data->setting, data->main->message, path); } else if (F_status_is_error(status)) { fake_print_error_file(data->setting, data->main->error, status, macro_fake_f(f_directory_exists), path, f_file_operation_create_s, fll_error_file_type_directory_e); @@ -198,9 +180,7 @@ extern "C" { status = f_file_is(path, F_file_type_regular_d, F_false); if (status == F_true) { - if (data->main->error.verbosity >= f_console_verbosity_verbose_e) { - fll_print_format("File '%Q' already exists.%r", data->main->message.to, path, f_string_eol_s); - } + fake_print_verbose_file_exists(data->setting, data->main->message, path); return F_none; } @@ -210,18 +190,14 @@ extern "C" { status = f_file_is(path, F_file_type_link_d, F_false); if (status == F_true) { - if (data->main->error.verbosity >= f_console_verbosity_verbose_e) { - fll_print_format("File '%Q' already exists (as a symbolic link).%r", data->main->message.to, path, f_string_eol_s); - } + fake_print_verbose_file_exists_as_link(data->setting, data->main->message, path); return F_none; } } if (status == F_false) { - if (data->main->error.verbosity >= f_console_verbosity_verbose_e) { - fll_print_format("File '%Q' already exists but is not a regular file (or symbolic link).%r", data->main->message.to, path, f_string_eol_s); - } + fake_print_verbose_file_exists_not_regular_or_link(data->setting, data->main->message, path); return F_status_set_warning(F_none); } @@ -236,13 +212,7 @@ extern "C" { if (F_status_is_error(status)) { if (F_status_set_fine(status) == F_file_found_not) { - f_file_stream_lock(data->main->error.to); - - fl_print_format("%r%[%QThe file '%]", data->main->error.to, f_string_eol_s, data->main->error.context, data->main->error.prefix, data->main->error.context); - fl_print_format("%[%Q%]", data->main->error.to, data->main->error.notable, path, data->main->error.notable); - fl_print_format("%[' could not be created, a parent directory does not exist.%]%r", data->main->error.to, data->main->error.context, data->main->error.context, f_string_eol_s); - - f_file_stream_unlock(data->main->error.to); + fake_print_error_file_create_parent_missing(data->setting, data->main->error, path); } else { fake_print_error_file(data->setting, data->main->error, status, macro_fake_f(f_file_create), path, f_file_operation_create_s, fll_error_file_type_file_e); @@ -251,9 +221,7 @@ extern "C" { return status; } - if (data->main->error.verbosity >= f_console_verbosity_verbose_e) { - fll_print_format("File '%Q' created.%r", data->main->message.to, path, f_string_eol_s); - } + fake_print_verbose_create_file(data->setting, data->main->message, path); if (content.used) { f_file_t file = f_file_t_initialize; @@ -280,9 +248,7 @@ extern "C" { return status; } - if (data->main->error.verbosity >= f_console_verbosity_verbose_e) { - fll_print_format("File '%Q' pre-populated.%r", data->main->message.to, path, f_string_eol_s); - } + fake_print_verbose_file_pre_populated(data->setting, data->main->message, path); f_file_stream_flush(file); f_file_stream_close(&file); diff --git a/level_3/fake/data/build/settings b/level_3/fake/data/build/settings index 0366e1e..1262f85 100644 --- a/level_3/fake/data/build/settings +++ b/level_3/fake/data/build/settings @@ -27,18 +27,16 @@ build_libraries-individual -lf_account -lf_capability -lf_color -lf_console -lf_ build_libraries-level -lfll_2 -lfll_1 -lfll_0 build_libraries-monolithic -lfll -build_sources_library main/build.c main/clean.c main/common.c main/fake.c main/make.c main/print.c main/print-error.c main/print-warning.c main/skeleton.c +build_sources_library main/build.c main/clean.c main/common.c main/fake.c main/make.c main/print.c main/print-error.c main/print-warning.c main/print-verbose.c main/skeleton.c build_sources_library main/build/library.c main/build/load.c main/build/object.c main/build/objects.c main/build/print.c main/build/print-error.c main/build/print-verbose.c main/build/print-warning.c main/build/program.c main/build/skeleton.c -build_sources_library main/clean/print.c build_sources_library main/common/define.c main/common/enumeration.c main/common/print.c main/common/string.c main/common/type.c build_sources_library main/fake/path_generate.c build_sources_library main/make/load_fakefile.c main/make/load_parameters.c main/make/operate_block.c main/make/operate.c main/make/operate_process.c main/make/operate_process_type.c main/make/operate_validate.c main/make/operate_validate_type.c main/make/print.c main/make/print-error.c main/make/print-verbose.c main/make/print-warning.c build_sources_program main/main.c -build_sources_headers main/build.h main/clean.h main/common.h main/fake.h main/make.h main/print.h main/print-error.h main/print-warning.h main/skeleton.h +build_sources_headers main/build.h main/clean.h main/common.h main/fake.h main/make.h main/print.h main/print-error.h main/print-warning.h main/print-verbose.h main/skeleton.h build_sources_headers main/build/library.h main/build/load.h main/build/object.h main/build/objects.h main/build/print.h main/build/print-error.h main/build/print-verbose.h main/build/print-warning.h main/build/program.h main/build/skeleton.h -build_sources_headers main/clean/print.h build_sources_headers main/common/define.h main/common/enumeration.h main/common/print.h main/common/string.h main/common/type.h build_sources_headers main/fake/path_generate.h build_sources_headers main/make/load_fakefile.h main/make/load_parameters.h main/make/operate_block.h main/make/operate.h main/make/operate_process.h main/make/operate_process_type.h main/make/operate_validate.h main/make/operate_validate_type.h main/make/print.h main/make/print-error.h main/make/print-verbose.h main/make/print-warning.h main/make/print-warning.h diff --git a/level_3/firewall/c/common.c b/level_3/firewall/c/common.c index 424c025..aff8ddb 100644 --- a/level_3/firewall/c/common.c +++ b/level_3/firewall/c/common.c @@ -113,7 +113,7 @@ extern "C" { #endif // _di_firewall_setting_delete_ #ifndef _di_firewall_setting_load_ - void firewall_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, firewall_setting_t * const setting) { + void firewall_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, firewall_setting_t * const setting, f_state_t * const state) { if (!main || !setting) return; diff --git a/level_3/firewall/c/common.h b/level_3/firewall/c/common.h index a3e4592..cc7dfdd 100644 --- a/level_3/firewall/c/common.h +++ b/level_3/firewall/c/common.h @@ -445,7 +445,7 @@ extern "C" { * * flag: Flags passed to the main function. * - * status: The main status code, generally used by the load settings and main functions. + * state: The state information. * * line_first: A string expected to represent either "\n" or NULL to allow for easy handling of when to print first new line or not. * line_last: A string expected to represent either "\n" or NULL to allow for easy handling of when to print last new line or not. @@ -454,7 +454,7 @@ extern "C" { typedef struct { uint16_t flag; - f_status_t status; + f_state_t state; f_string_static_t line_first; f_string_static_t line_last; @@ -463,7 +463,7 @@ extern "C" { #define firewall_setting_t_initialize \ { \ firewall_main_flag_none_e, \ - F_none, \ + f_state_t_initialize, \ f_string_static_t_initialize, \ f_string_static_t_initialize, \ } @@ -495,8 +495,6 @@ extern "C" { * * @param arguments * The parameters passed to the process (often referred to as command line arguments). - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param main * The main program data. * @param setting @@ -507,12 +505,14 @@ extern "C" { * * Errors (with error bit) from: f_console_parameter_process(). * Errors (with error bit) from: fll_program_parameter_process_context(). + * @param state + * A state for providing flags and handling interrupts during long running operations. * * @see f_console_parameter_process() * @see fll_program_parameter_process_context() */ #ifndef _di_firewall_setting_load_ - extern void firewall_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, firewall_setting_t * const setting); + extern void firewall_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, firewall_setting_t * const setting, f_state_t * const state); #endif // _di_firewall_setting_load_ /** diff --git a/level_3/fss_basic_list_read/c/common.c b/level_3/fss_basic_list_read/c/common.c index a21f5c3..b5fa042 100644 --- a/level_3/fss_basic_list_read/c/common.c +++ b/level_3/fss_basic_list_read/c/common.c @@ -71,14 +71,14 @@ extern "C" { #endif // _di_fss_basic_list_read_setting_delete_ #ifndef _di_fss_basic_list_read_setting_load_ - void fss_basic_list_read_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fss_basic_list_read_setting_t * const setting) { + void fss_basic_list_read_setting_load(const f_console_arguments_t arguments, f_state_t * const state, fll_program_data_t * const main, fss_basic_list_read_setting_t * const setting) { if (!main || !setting) return; setting->flag = 0; // Load parameters. - setting->status = f_console_parameter_process(state, arguments, &main->parameters, 0); + setting->status = f_console_parameter_process(arguments, state, &main->parameters, 0); if (F_status_is_error(setting->status)) { fss_basic_list_read_print_line_first_locked(setting, main->error); diff --git a/level_3/fss_basic_list_read/c/common.h b/level_3/fss_basic_list_read/c/common.h index 656a811..11761f3 100644 --- a/level_3/fss_basic_list_read/c/common.h +++ b/level_3/fss_basic_list_read/c/common.h @@ -345,7 +345,7 @@ extern "C" { * * flag: Flags passed to the main function. * - * status: The main status code, generally used by the load settings and main functions. + * state: The state information. * * line_first: A string expected to represent either "\n" or NULL to allow for easy handling of when to print first new line or not. * line_last: A string expected to represent either "\n" or NULL to allow for easy handling of when to print last new line or not. @@ -354,7 +354,7 @@ extern "C" { typedef struct { uint16_t flag; - f_status_t status; + f_state_t state; f_string_static_t line_first; f_string_static_t line_last; @@ -363,7 +363,7 @@ extern "C" { #define fss_basic_list_read_setting_t_initialize \ { \ fss_basic_list_read_main_flag_none_e, \ - F_none, \ + f_state_t_initialize, \ f_string_static_t_initialize, \ f_string_static_t_initialize, \ } @@ -395,8 +395,6 @@ extern "C" { * * @param arguments * The parameters passed to the process (often referred to as command line arguments). - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param main * The main program data. * @param setting @@ -407,12 +405,14 @@ extern "C" { * * Errors (with error bit) from: f_console_parameter_process(). * Errors (with error bit) from: fll_program_parameter_process_context(). + * @param state + * A state for providing flags and handling interrupts during long running operations. * * @see f_console_parameter_process() * @see fll_program_parameter_process_context() */ #ifndef _di_fss_basic_list_read_setting_load_ - extern void fss_basic_list_read_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fss_basic_list_read_setting_t * const setting); + extern void fss_basic_list_read_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, fss_basic_list_read_setting_t * const setting, f_state_t * const state); #endif // _di_fss_basic_list_read_setting_load_ /** diff --git a/level_3/fss_basic_read/c/common.c b/level_3/fss_basic_read/c/common.c index 15a6ec0..b48b7c6 100644 --- a/level_3/fss_basic_read/c/common.c +++ b/level_3/fss_basic_read/c/common.c @@ -70,14 +70,14 @@ extern "C" { #endif // _di_fss_basic_read_setting_delete_ #ifndef _di_fss_basic_read_setting_load_ - void fss_basic_read_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fss_basic_read_setting_t * const setting) { + void fss_basic_read_setting_load(const f_console_arguments_t arguments, f_state_t * const state, fll_program_data_t * const main, fss_basic_read_setting_t * const setting) { if (!main || !setting) return; setting->flag = 0; // Load parameters. - setting->status = f_console_parameter_process(state, arguments, &main->parameters, 0); + setting->status = f_console_parameter_process(arguments, state, &main->parameters, 0); if (F_status_is_error(setting->status)) { fss_basic_read_print_line_first_locked(setting, main->error); diff --git a/level_3/fss_basic_read/c/common.h b/level_3/fss_basic_read/c/common.h index 76e3317..7002d4f 100644 --- a/level_3/fss_basic_read/c/common.h +++ b/level_3/fss_basic_read/c/common.h @@ -343,7 +343,7 @@ extern "C" { * * flag: Flags passed to the main function. * - * status: The main status code, generally used by the load settings and main functions. + * state: The state information. * * line_first: A string expected to represent either "\n" or NULL to allow for easy handling of when to print first new line or not. * line_last: A string expected to represent either "\n" or NULL to allow for easy handling of when to print last new line or not. @@ -352,7 +352,7 @@ extern "C" { typedef struct { uint16_t flag; - f_status_t status; + f_state_t state; f_string_static_t line_first; f_string_static_t line_last; @@ -361,7 +361,7 @@ extern "C" { #define fss_basic_read_setting_t_initialize \ { \ fss_basic_read_main_flag_none_e, \ - F_none, \ + f_state_t_initialize, \ f_string_static_t_initialize, \ f_string_static_t_initialize, \ } @@ -393,8 +393,6 @@ extern "C" { * * @param arguments * The parameters passed to the process (often referred to as command line arguments). - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param main * The main program data. * @param setting @@ -405,12 +403,14 @@ extern "C" { * * Errors (with error bit) from: f_console_parameter_process(). * Errors (with error bit) from: fll_program_parameter_process_context(). + * @param state + * A state for providing flags and handling interrupts during long running operations. * * @see f_console_parameter_process() * @see fll_program_parameter_process_context() */ #ifndef _di_fss_basic_read_setting_load_ - extern void fss_basic_read_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fss_basic_read_setting_t * const setting); + extern void fss_basic_read_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, fss_basic_read_setting_t * const setting, f_state_t * const state); #endif // _di_fss_basic_read_setting_load_ /** diff --git a/level_3/fss_embedded_list_read/c/common.c b/level_3/fss_embedded_list_read/c/common.c index a0355f0..0e254f6 100644 --- a/level_3/fss_embedded_list_read/c/common.c +++ b/level_3/fss_embedded_list_read/c/common.c @@ -69,14 +69,14 @@ extern "C" { #endif // _di_fss_embedded_list_read_setting_delete_ #ifndef _di_fss_embedded_list_read_setting_load_ - void fss_embedded_list_read_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fss_embedded_list_read_setting_t * const setting) { + void fss_embedded_list_read_setting_load(const f_console_arguments_t arguments, f_state_t * const state, fll_program_data_t * const main, fss_embedded_list_read_setting_t * const setting) { if (!main || !setting) return; setting->flag = 0; // Load parameters. - setting->status = f_console_parameter_process(state, arguments, &main->parameters, 0); + setting->status = f_console_parameter_process(arguments, state, &main->parameters, 0); if (F_status_is_error(setting->status)) { fss_embedded_list_read_print_line_first_locked(setting, main->error); diff --git a/level_3/fss_embedded_list_read/c/common.h b/level_3/fss_embedded_list_read/c/common.h index 049987c..2b767ee 100644 --- a/level_3/fss_embedded_list_read/c/common.h +++ b/level_3/fss_embedded_list_read/c/common.h @@ -326,7 +326,7 @@ extern "C" { * * flag: Flags passed to the main function. * - * status: The main status code, generally used by the load settings and main functions. + * state: The state information. * * line_first: A string expected to represent either "\n" or NULL to allow for easy handling of when to print first new line or not. * line_last: A string expected to represent either "\n" or NULL to allow for easy handling of when to print last new line or not. @@ -335,7 +335,7 @@ extern "C" { typedef struct { uint16_t flag; - f_status_t status; + f_state_t state; f_string_static_t line_first; f_string_static_t line_last; @@ -344,7 +344,7 @@ extern "C" { #define fss_embedded_list_read_setting_t_initialize \ { \ fss_embedded_list_read_main_flag_none_e, \ - F_none, \ + f_state_t_initialize, \ f_string_static_t_initialize, \ f_string_static_t_initialize, \ } @@ -376,8 +376,6 @@ extern "C" { * * @param arguments * The parameters passed to the process (often referred to as command line arguments). - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param main * The main program data. * @param setting @@ -388,12 +386,14 @@ extern "C" { * * Errors (with error bit) from: f_console_parameter_process(). * Errors (with error bit) from: fll_program_parameter_process_context(). + * @param state + * A state for providing flags and handling interrupts during long running operations. * * @see f_console_parameter_process() * @see fll_program_parameter_process_context() */ #ifndef _di_fss_embedded_list_read_setting_load_ - extern void fss_embedded_list_read_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fss_embedded_list_read_setting_t * const setting); + extern void fss_embedded_list_read_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, fss_embedded_list_read_setting_t * const setting, f_state_t * const state); #endif // _di_fss_embedded_list_read_setting_load_ /** diff --git a/level_3/fss_extended_list_read/c/common.c b/level_3/fss_extended_list_read/c/common.c index 71c9811..a024598 100644 --- a/level_3/fss_extended_list_read/c/common.c +++ b/level_3/fss_extended_list_read/c/common.c @@ -77,14 +77,14 @@ extern "C" { #endif // _di_fss_extended_list_read_setting_delete_ #ifndef _di_fss_extended_list_read_setting_load_ - void fss_extended_list_read_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fss_extended_list_read_setting_t * const setting) { + void fss_extended_list_read_setting_load(const f_console_arguments_t arguments, f_state_t * const state, fll_program_data_t * const main, fss_extended_list_read_setting_t * const setting) { if (!main || !setting) return; setting->flag = 0; // Load parameters. - setting->status = f_console_parameter_process(state, arguments, &main->parameters, 0); + setting->status = f_console_parameter_process(arguments, state, &main->parameters, 0); if (F_status_is_error(setting->status)) { fss_extended_list_read_print_line_first_locked(setting, main->error); diff --git a/level_3/fss_extended_list_read/c/common.h b/level_3/fss_extended_list_read/c/common.h index 46fe131..4cf95d3 100644 --- a/level_3/fss_extended_list_read/c/common.h +++ b/level_3/fss_extended_list_read/c/common.h @@ -343,7 +343,7 @@ extern "C" { * * flag: Flags passed to the main function. * - * status: The main status code, generally used by the load settings and main functions. + * state: The state information. * * line_first: A string expected to represent either "\n" or NULL to allow for easy handling of when to print first new line or not. * line_last: A string expected to represent either "\n" or NULL to allow for easy handling of when to print last new line or not. @@ -352,7 +352,7 @@ extern "C" { typedef struct { uint16_t flag; - f_status_t status; + f_state_t state; f_string_static_t line_first; f_string_static_t line_last; @@ -361,7 +361,7 @@ extern "C" { #define fss_extended_list_read_setting_t_initialize \ { \ fss_extended_list_read_main_flag_none_e, \ - F_none, \ + f_state_t_initialize, \ f_string_static_t_initialize, \ f_string_static_t_initialize, \ } @@ -427,7 +427,7 @@ extern "C" { * @see fll_program_parameter_process_context() */ #ifndef _di_fss_extended_list_read_setting_load_ - extern void fss_extended_list_read_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fss_extended_list_read_setting_t * const setting); + extern void fss_extended_list_read_setting_load(const f_console_arguments_t arguments, f_state_t * const state, fll_program_data_t * const main, fss_extended_list_read_setting_t * const setting); #endif // _di_fss_extended_list_read_setting_load_ /** diff --git a/level_3/fss_extended_read/c/common.c b/level_3/fss_extended_read/c/common.c index fc1cd30..e8ad344 100644 --- a/level_3/fss_extended_read/c/common.c +++ b/level_3/fss_extended_read/c/common.c @@ -70,14 +70,14 @@ extern "C" { #endif // _di_fss_extended_read_setting_delete_ #ifndef _di_fss_extended_read_setting_load_ - void fss_extended_read_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fss_extended_read_setting_t * const setting) { + void fss_extended_read_setting_load(const f_console_arguments_t arguments, f_state_t * const state, fll_program_data_t * const main, fss_extended_read_setting_t * const setting) { if (!main || !setting) return; setting->flag = 0; // Load parameters. - setting->status = f_console_parameter_process(state, arguments, &main->parameters, 0); + setting->status = f_console_parameter_process(arguments, state, &main->parameters, 0); if (F_status_is_error(setting->status)) { fss_extended_read_print_line_first_locked(setting, main->error); diff --git a/level_3/fss_extended_read/c/common.h b/level_3/fss_extended_read/c/common.h index 49f5d5b..633d64d 100644 --- a/level_3/fss_extended_read/c/common.h +++ b/level_3/fss_extended_read/c/common.h @@ -342,7 +342,7 @@ extern "C" { * * flag: Flags passed to the main function. * - * status: The main status code, generally used by the load settings and main functions. + * state: The state information. * * line_first: A string expected to represent either "\n" or NULL to allow for easy handling of when to print first new line or not. * line_last: A string expected to represent either "\n" or NULL to allow for easy handling of when to print last new line or not. @@ -351,7 +351,7 @@ extern "C" { typedef struct { uint16_t flag; - f_status_t status; + f_state_t state; f_string_static_t line_first; f_string_static_t line_last; @@ -360,7 +360,7 @@ extern "C" { #define fss_extended_read_setting_t_initialize \ { \ fss_extended_read_main_flag_none_e, \ - F_none, \ + f_state_t_initialize, \ f_string_static_t_initialize, \ f_string_static_t_initialize, \ } @@ -409,7 +409,7 @@ extern "C" { * @see fll_program_parameter_process_context() */ #ifndef _di_fss_extended_read_setting_load_ - extern void fss_extended_read_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fss_extended_read_setting_t * const setting); + extern void fss_extended_read_setting_load(const f_console_arguments_t arguments, f_state_t * const state, fll_program_data_t * const main, fss_extended_read_setting_t * const setting); #endif // _di_fss_extended_read_setting_load_ /** diff --git a/level_3/fss_identify/c/common.c b/level_3/fss_identify/c/common.c index cc4866a..f133f1b 100644 --- a/level_3/fss_identify/c/common.c +++ b/level_3/fss_identify/c/common.c @@ -37,14 +37,14 @@ extern "C" { #endif // _di_fss_identify_setting_delete_ #ifndef _di_fss_identify_setting_load_ - void fss_identify_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fss_identify_setting_t * const setting) { + void fss_identify_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, fss_identify_setting_t * const setting, f_state_t * const state) { if (!main || !setting) return; setting->flag = 0; // Load parameters. - setting->status = f_console_parameter_process(state, arguments, &main->parameters, 0); + setting->status = f_console_parameter_process(arguments, state, &main->parameters, 0); if (F_status_is_error(setting->status)) { fss_identify_print_line_first_locked(setting, main->error); diff --git a/level_3/fss_identify/c/common.h b/level_3/fss_identify/c/common.h index be5b9b3..3badc66 100644 --- a/level_3/fss_identify/c/common.h +++ b/level_3/fss_identify/c/common.h @@ -192,7 +192,7 @@ extern "C" { * * flag: Flags passed to the main function. * - * status: The main status code, generally used by the load settings and main functions. + * state: The state information. * * line_first: A string expected to represent either "\n" or NULL to allow for easy handling of when to print first new line or not. * line_last: A string expected to represent either "\n" or NULL to allow for easy handling of when to print last new line or not. @@ -201,7 +201,7 @@ extern "C" { typedef struct { uint16_t flag; - f_status_t status; + f_state_t state; f_string_static_t line_first; f_string_static_t line_last; @@ -210,7 +210,7 @@ extern "C" { #define fss_identify_setting_t_initialize \ { \ fss_identify_main_flag_none_e, \ - F_none, \ + f_state_t_initialize, \ f_string_static_t_initialize, \ f_string_static_t_initialize, \ } @@ -259,7 +259,7 @@ extern "C" { * @see fll_program_parameter_process_context() */ #ifndef _di_fss_identify_setting_load_ - extern void fss_identify_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fss_identify_setting_t * const setting); + extern void fss_identify_setting_load(const f_console_arguments_t arguments, f_state_t * const state, fll_program_data_t * const main, fss_identify_setting_t * const setting); #endif // _di_fss_identify_setting_load_ /** diff --git a/level_3/fss_payload_read/c/common.c b/level_3/fss_payload_read/c/common.c index c9b75ab..a94cb20 100644 --- a/level_3/fss_payload_read/c/common.c +++ b/level_3/fss_payload_read/c/common.c @@ -71,7 +71,7 @@ extern "C" { #endif // _di_fss_payload_read_setting_delete_ #ifndef _di_fss_payload_read_setting_load_ - void fss_payload_read_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fss_payload_read_setting_t * const setting) { + void fss_payload_read_setting_load(const f_console_arguments_t arguments, f_state_t * const state, fll_program_data_t * const main, fss_payload_read_setting_t * const setting) { if (!main || !setting) return; diff --git a/level_3/fss_payload_read/c/common.h b/level_3/fss_payload_read/c/common.h index 61b2072..8aefedb 100644 --- a/level_3/fss_payload_read/c/common.h +++ b/level_3/fss_payload_read/c/common.h @@ -349,7 +349,7 @@ extern "C" { * * flag: Flags passed to the main function. * - * status: The main status code, generally used by the load settings and main functions. + * state: The state information. * * line_first: A string expected to represent either "\n" or NULL to allow for easy handling of when to print first new line or not. * line_last: A string expected to represent either "\n" or NULL to allow for easy handling of when to print last new line or not. @@ -358,7 +358,7 @@ extern "C" { typedef struct { uint16_t flag; - f_status_t status; + f_state_t state; f_string_static_t line_first; f_string_static_t line_last; @@ -367,7 +367,7 @@ extern "C" { #define fss_payload_read_setting_t_initialize \ { \ fss_payload_read_main_flag_none_e, \ - F_none, \ + f_state_t_initialize, \ f_string_static_t_initialize, \ f_string_static_t_initialize, \ } @@ -399,8 +399,6 @@ extern "C" { * * @param arguments * The parameters passed to the process (often referred to as command line arguments). - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param main * The main program data. * @param setting @@ -411,12 +409,14 @@ extern "C" { * * Errors (with error bit) from: f_console_parameter_process(). * Errors (with error bit) from: fll_program_parameter_process_context(). + * @param state + * A state for providing flags and handling interrupts during long running operations. * * @see f_console_parameter_process() * @see fll_program_parameter_process_context() */ #ifndef _di_fss_payload_read_setting_load_ - extern void fss_payload_read_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fss_payload_read_setting_t * const setting); + extern void fss_payload_read_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, fss_payload_read_setting_t * const setting, f_state_t * const state); #endif // _di_fss_payload_read_setting_load_ /** diff --git a/level_3/fss_write/c/basic/fss_write.c b/level_3/fss_write/c/basic/fss_write.c index 46308a4..270e2e0 100644 --- a/level_3/fss_write/c/basic/fss_write.c +++ b/level_3/fss_write/c/basic/fss_write.c @@ -18,9 +18,9 @@ extern "C" { (setting->flag & fss_write_flag_partial_e) ? f_fss_complete_partial_e : f_fss_complete_full_e, - setting->state, &setting->range, - &setting->buffer + &setting->buffer, + setting->state ); if (F_status_set_fine(setting->status) == F_none_eol) { diff --git a/level_3/fss_write/c/basic/main.c b/level_3/fss_write/c/basic/main.c index a0ed10c..362b7d5 100644 --- a/level_3/fss_write/c/basic/main.c +++ b/level_3/fss_write/c/basic/main.c @@ -28,9 +28,8 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { { const f_console_arguments_t arguments = macro_f_console_arguments_t_initialize(argc, argv, envp); - f_state_t state = f_state_t_initialize; - fss_write_setting_load(arguments, state, &data, &setting, 0); + fss_write_setting_load(arguments, &data, &setting, 0); } fss_write_main(&data, &setting); diff --git a/level_3/fss_write/c/main/common-type.h b/level_3/fss_write/c/main/common-type.h index 8b01df3..64f6cc5 100644 --- a/level_3/fss_write/c/main/common-type.h +++ b/level_3/fss_write/c/main/common-type.h @@ -160,8 +160,6 @@ extern "C" { * * flag: Flags passed to the main function. * - * status: The main status code, generally used by the load settings and main functions. - * * state: The state data used when processing the FSS data. * range: A range used as a buffer during processing. * @@ -195,8 +193,6 @@ extern "C" { typedef struct { uint16_t flag; - f_status_t status; - f_state_t state; f_string_range_t range; @@ -231,7 +227,6 @@ extern "C" { #define fss_write_setting_t_initialize \ { \ fss_write_flag_none_e, \ - F_none, \ macro_f_state_t_initialize(fss_write_default_allocation_large_d, fss_write_default_allocation_small_d, 0, 0, &fll_program_standard_signal_state, 0, 0, 0), \ f_string_range_t_initialize, \ f_string_static_t_initialize, \ diff --git a/level_3/fss_write/c/main/common.c b/level_3/fss_write/c/main/common.c index 9da9cb8..607a4ad 100644 --- a/level_3/fss_write/c/main/common.c +++ b/level_3/fss_write/c/main/common.c @@ -23,7 +23,7 @@ extern "C" { #endif // _di_fss_write_setting_delete_ #ifndef _di_fss_write_setting_load_ - void fss_write_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fss_write_setting_t * const setting, void (*callback)(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fss_write_setting_t * const setting)) { + void fss_write_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, fss_write_setting_t * const setting, void (*callback)(const f_console_arguments_t arguments, fll_program_data_t * const main, fss_write_setting_t * const setting)) { if (!main || !setting) return; @@ -105,7 +105,7 @@ extern "C" { } if (callback) { - callback(arguments, state, main, setting); + callback(arguments, main, setting); if (F_status_is_error(setting->status)) return; if (setting->status == F_done) { @@ -293,7 +293,7 @@ extern "C" { for (; range.start < main->parameters.arguments.array[index].used; range.start++) { - setting->status = f_fss_is_space(state, main->parameters.arguments.array[index], range); + setting->status = f_fss_is_space(main->parameters.arguments.array[index], range, state); if (F_status_is_error(setting->status)) { fss_write_print_error(setting, main->error, macro_fss_write_f(f_fss_is_space)); diff --git a/level_3/fss_write/c/main/common.h b/level_3/fss_write/c/main/common.h index 3fa3ce1..dd0990d 100644 --- a/level_3/fss_write/c/main/common.h +++ b/level_3/fss_write/c/main/common.h @@ -42,8 +42,6 @@ extern "C" { * * @param arguments * The parameters passed to the process (often referred to as command line arguments). - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param main * The main program data. * @param setting @@ -72,7 +70,7 @@ extern "C" { * @see fll_program_parameter_process_verbosity() */ #ifndef _di_fss_write_setting_load_ - extern void fss_write_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fss_write_setting_t * const setting, void (*callback)(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fss_write_setting_t * const setting)); + extern void fss_write_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, fss_write_setting_t * const setting, void (*callback)(const f_console_arguments_t arguments, fll_program_data_t * const main, fss_write_setting_t * const setting)); #endif // _di_fss_write_setting_load_ /** diff --git a/level_3/fss_write/c/main/main.c b/level_3/fss_write/c/main/main.c index 7264ce6..1f281e4 100644 --- a/level_3/fss_write/c/main/main.c +++ b/level_3/fss_write/c/main/main.c @@ -53,7 +53,7 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { #endif // _di_fss_write_main_process_help_ #ifndef _di_fss_write_main_setting_load_as_ - void fss_write_main_setting_load_as(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fss_write_setting_t * const setting) { + void fss_write_main_setting_load_as(const f_console_arguments_t arguments, fll_program_data_t * const main, fss_write_setting_t * const setting, f_state_t * const state) { if (!main || !setting || F_status_is_error(setting->status) || (setting->flag & fss_write_flag_version_e)) return; diff --git a/level_3/fss_write/c/main/main.h b/level_3/fss_write/c/main/main.h index c44a75f..b291120 100644 --- a/level_3/fss_write/c/main/main.h +++ b/level_3/fss_write/c/main/main.h @@ -59,8 +59,6 @@ extern int main(const int argc, const f_string_t *argv, const f_string_t *envp); * * @param arguments * The parameters passed to the process (often referred to as command line arguments). - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param main * The main program data. * @param setting @@ -83,6 +81,8 @@ extern int main(const int argc, const f_string_t *argv, const f_string_t *envp); * Errors (with error bit) from: f_string_dynamics_resize(). * Errors (with error bit) from: fll_program_parameter_process_context(). * Errors (with error bit) from: fll_program_parameter_process_verbosity(). + * @param state + * A state for providing flags and handling interrupts during long running operations. * * @see f_console_parameter_process() * @see f_file_stream_open() @@ -93,7 +93,7 @@ extern int main(const int argc, const f_string_t *argv, const f_string_t *envp); * @see fss_write_setting_load() */ #ifndef _di_fss_write_main_setting_load_as_ - extern void fss_write_main_setting_load_as(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fss_write_setting_t * const setting); + extern void fss_write_main_setting_load_as(const f_console_arguments_t arguments, fll_program_data_t * const main, fss_write_setting_t * const setting, f_state_t * const state); #endif // _di_fss_write_main_setting_load_as_ #ifdef __cplusplus diff --git a/level_3/fss_write/c/payload/fss_write.c b/level_3/fss_write/c/payload/fss_write.c index ab3a051..ca5b3f9 100644 --- a/level_3/fss_write/c/payload/fss_write.c +++ b/level_3/fss_write/c/payload/fss_write.c @@ -542,7 +542,7 @@ extern "C" { #endif // _di_fss_write_payload_process_set_ #ifndef _di_fss_write_payload_setting_load_ - void fss_write_payload_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fss_write_setting_t * const setting) { + void fss_write_payload_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, fss_write_setting_t * const setting, f_state_t * const state) { if (!main || !setting) return; diff --git a/level_3/fss_write/c/payload/fss_write.h b/level_3/fss_write/c/payload/fss_write.h index e1ffdf3..3367711 100644 --- a/level_3/fss_write/c/payload/fss_write.h +++ b/level_3/fss_write/c/payload/fss_write.h @@ -124,8 +124,6 @@ extern "C" { * * @param arguments * The parameters passed to the process (often referred to as command line arguments). - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param main * The main program data. * @param setting @@ -143,11 +141,13 @@ extern "C" { * This alters setting.status: * F_none on success. * F_data_not on success but nothing was provided to operate with. + * @param state + * A state for providing flags and handling interrupts during long running operations. * * @see fss_write_setting_load() */ #ifndef _di_fss_write_payload_setting_load_ - extern void fss_write_payload_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, fss_write_setting_t * const setting); + extern void fss_write_payload_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, fss_write_setting_t * const setting, f_state_t * const state); #endif // _di_fss_write_payload_setting_load_ #ifdef __cplusplus diff --git a/level_3/iki_read/c/main/common-type.h b/level_3/iki_read/c/main/common-type.h index fd4a6fb..419b107 100644 --- a/level_3/iki_read/c/main/common-type.h +++ b/level_3/iki_read/c/main/common-type.h @@ -139,7 +139,7 @@ extern "C" { * * flag: Flags passed to the main function. * - * status: The main status code, generally used by the load settings and main functions. + * state: The state information. * * at: The position representing the "at" index. * line: The position representing the "line" index. @@ -165,7 +165,7 @@ extern "C" { typedef struct { uint16_t flag; - f_status_t status; + f_state_t state; f_array_length_t at; f_array_length_t line; @@ -191,7 +191,7 @@ extern "C" { #define iki_read_setting_t_initialize \ { \ iki_read_main_flag_none_e, \ - F_none, \ + f_state_t_initialize, \ 0, \ 0, \ f_string_static_t_initialize, \ diff --git a/level_3/iki_read/c/main/common.c b/level_3/iki_read/c/main/common.c index e41f8a3..603da31 100644 --- a/level_3/iki_read/c/main/common.c +++ b/level_3/iki_read/c/main/common.c @@ -25,14 +25,14 @@ extern "C" { #endif // _di_iki_read_setting_delete_ #ifndef _di_iki_read_setting_load_ - void iki_read_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, iki_read_setting_t * const setting) { + void iki_read_setting_load(const f_console_arguments_t arguments, f_state_t * const state, fll_program_data_t * const main, iki_read_setting_t * const setting) { if (!main || !setting) return; setting->flag = 0; // Load parameters. - setting->status = f_console_parameter_process(state, arguments, &main->parameters, 0); + setting->status = f_console_parameter_process(arguments, state, &main->parameters, 0); if (F_status_is_error(setting->status)) { iki_read_print_error(setting, main->error, macro_iki_read_f(f_console_parameter_process)); diff --git a/level_3/iki_read/c/main/common.h b/level_3/iki_read/c/main/common.h index 2230031..a42d0b6 100644 --- a/level_3/iki_read/c/main/common.h +++ b/level_3/iki_read/c/main/common.h @@ -71,7 +71,7 @@ extern "C" { * @see fll_program_parameter_process_verbosity() */ #ifndef _di_iki_read_setting_load_ - extern void iki_read_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, iki_read_setting_t * const setting); + extern void iki_read_setting_load(const f_console_arguments_t arguments, f_state_t * const state, fll_program_data_t * const main, iki_read_setting_t * const setting); #endif // _di_iki_read_setting_load_ /** diff --git a/level_3/iki_read/c/main/private-read.c b/level_3/iki_read/c/main/private-read.c index 48d20de..3d501c8 100644 --- a/level_3/iki_read/c/main/private-read.c +++ b/level_3/iki_read/c/main/private-read.c @@ -165,7 +165,7 @@ extern "C" { { const f_state_t state = macro_f_state_t_initialize(iki_read_common_allocation_large_d, iki_read_common_allocation_small_d, 0, 0, &fll_program_standard_signal_state, 0, (void *) main, 0); - setting->status = fl_iki_read(state, &setting->buffer, buffer_range, &setting->data); + setting->status = fl_iki_read(&setting->buffer, buffer_range, &setting->data, state); } if (F_status_is_error(setting->status)) { @@ -278,7 +278,7 @@ extern "C" { { const f_state_t state = macro_f_state_t_initialize(iki_read_common_allocation_large_d, iki_read_common_allocation_small_d, 0, 0, &fll_program_standard_signal_state, 0, (void *) main, 0); - setting->status = fl_iki_read(state, &setting->buffer, &range, &setting->data); + setting->status = fl_iki_read(&setting->buffer, &range, &setting->data, state); } if (F_status_is_error(setting->status)) { @@ -392,7 +392,7 @@ extern "C" { { f_state_t state = macro_f_state_t_initialize(iki_read_common_allocation_large_d, iki_read_common_allocation_small_d, 0, 0, &fll_program_standard_signal_state, 0, (void *) main, 0); - setting->status = fl_iki_read(state, &setting->buffer, &range, &setting->data); + setting->status = fl_iki_read(&setting->buffer, &range, &setting->data, state); } if (F_status_is_error(setting->status)) { diff --git a/level_3/iki_write/c/main/common-type.h b/level_3/iki_write/c/main/common-type.h index 31242b3..7bcac47 100644 --- a/level_3/iki_write/c/main/common-type.h +++ b/level_3/iki_write/c/main/common-type.h @@ -109,7 +109,7 @@ extern "C" { * * flag: Flags passed to the main function. * - * status: The main status code, generally used by the load settings and main functions. + * state: The state information. * * line_first: A string expected to represent either "\n" or NULL to allow for easy handling of when to print first new line or not. * line_last: A string expected to represent either "\n" or NULL to allow for easy handling of when to print last new line or not. @@ -128,7 +128,7 @@ extern "C" { typedef struct { uint16_t flag; - f_status_t status; + f_state_t state; f_string_static_t line_first; f_string_static_t line_last; @@ -147,7 +147,7 @@ extern "C" { #define iki_write_setting_t_initialize \ { \ iki_write_main_flag_none_e, \ - F_none, \ + f_state_t_initialize, \ f_string_static_t_initialize, \ f_string_static_t_initialize, \ f_string_dynamic_t_initialize, \ diff --git a/level_3/iki_write/c/main/common.c b/level_3/iki_write/c/main/common.c index a49b70c..4e7cbed 100644 --- a/level_3/iki_write/c/main/common.c +++ b/level_3/iki_write/c/main/common.c @@ -22,14 +22,14 @@ extern "C" { #endif // _di_iki_write_setting_delete_ #ifndef _di_iki_write_setting_load_ - void iki_write_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, iki_write_setting_t * const setting) { + void iki_write_setting_load(const f_console_arguments_t arguments, f_state_t * const state, fll_program_data_t * const main, iki_write_setting_t * const setting) { if (!main || !setting) return; setting->flag = 0; // Load parameters. - setting->status = f_console_parameter_process(state, arguments, &main->parameters, 0); + setting->status = f_console_parameter_process(arguments, state, &main->parameters, 0); if (F_status_is_error(setting->status)) { iki_write_print_error(setting, main->error, macro_iki_write_f(f_console_parameter_process)); diff --git a/level_3/iki_write/c/main/common.h b/level_3/iki_write/c/main/common.h index 2098346..4378c8c 100644 --- a/level_3/iki_write/c/main/common.h +++ b/level_3/iki_write/c/main/common.h @@ -42,8 +42,6 @@ extern "C" { * * @param arguments * The parameters passed to the process (often referred to as command line arguments). - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param main * The main program data. * @param setting @@ -57,6 +55,8 @@ extern "C" { * Errors (with error bit) from: f_string_dynamics_resize(). * Errors (with error bit) from: fll_program_parameter_process_context(). * Errors (with error bit) from: fll_program_parameter_process_verbosity(). + * @param state + * A state for providing flags and handling interrupts during long running operations. * * @see f_console_parameter_process() * @see f_file_stream_open() @@ -65,7 +65,7 @@ extern "C" { * @see fll_program_parameter_process_verbosity() */ #ifndef _di_iki_write_setting_load_ - extern void iki_write_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, iki_write_setting_t * const setting); + extern void iki_write_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, iki_write_setting_t * const setting, f_state_t * const state); #endif // _di_iki_write_setting_load_ /** diff --git a/level_3/status_code/c/main/common-type.h b/level_3/status_code/c/main/common-type.h index 34febeb..61c4aa9 100644 --- a/level_3/status_code/c/main/common-type.h +++ b/level_3/status_code/c/main/common-type.h @@ -116,7 +116,7 @@ extern "C" { * * flag: Flags passed to the main function. * - * status: The main status code, generally used by the load settings and main functions. + * state: The state information. * * line_first: A string expected to represent either "\n" or NULL to allow for easy handling of when to print first new line or not. * line_last: A string expected to represent either "\n" or NULL to allow for easy handling of when to print last new line or not. @@ -129,7 +129,7 @@ extern "C" { typedef struct { uint16_t flag; - f_status_t status; + f_state_t state; f_string_static_t line_first; f_string_static_t line_last; @@ -145,7 +145,7 @@ extern "C" { #define status_code_setting_t_initialize \ { \ status_code_main_flag_none_e, \ - F_none, \ + f_state_initialize_t, \ f_string_static_t_initialize, \ f_string_static_t_initialize, \ 0, \ diff --git a/level_3/status_code/c/main/common.c b/level_3/status_code/c/main/common.c index fea0f7f..9eb9ad3 100644 --- a/level_3/status_code/c/main/common.c +++ b/level_3/status_code/c/main/common.c @@ -14,12 +14,12 @@ extern "C" { #endif // _di_status_code_setting_delete_ #ifndef _di_status_code_setting_load_ - void status_code_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, status_code_setting_t * const setting) { + void status_code_setting_load(const f_console_arguments_t arguments, f_state_t * const state, fll_program_data_t * const main, status_code_setting_t * const setting) { if (!main || !setting) return; // Load parameters. - setting->status = f_console_parameter_process(state, arguments, &main->parameters, 0); + setting->status = f_console_parameter_process(arguments, state, &main->parameters, 0); if (F_status_is_error(setting->status)) { status_code_print_error(setting, main->error, macro_status_code_f(f_console_parameter_process)); diff --git a/level_3/status_code/c/main/common.h b/level_3/status_code/c/main/common.h index 3ffcaad..faf1365 100644 --- a/level_3/status_code/c/main/common.h +++ b/level_3/status_code/c/main/common.h @@ -42,8 +42,6 @@ extern "C" { * * @param arguments * The parameters passed to the process (often referred to as command line arguments). - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param main * The main program data. * @param setting @@ -54,12 +52,14 @@ extern "C" { * * Errors (with error bit) from: f_console_parameter_process(). * Errors (with error bit) from: fll_program_parameter_process_context(). + * @param state + * A state for providing flags and handling interrupts during long running operations. * * @see f_console_parameter_process() * @see fll_program_parameter_process_context() */ #ifndef _di_status_code_setting_load_ - extern void status_code_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, status_code_setting_t * const setting); + extern void status_code_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, status_code_setting_t * const setting, f_state_t * const state); #endif // _di_status_code_setting_load_ /** diff --git a/level_3/utf8/c/main/common-type.h b/level_3/utf8/c/main/common-type.h index 190eb5b..f7e582c 100644 --- a/level_3/utf8/c/main/common-type.h +++ b/level_3/utf8/c/main/common-type.h @@ -168,7 +168,7 @@ extern "C" { * mode: The input/output mode (see utf8_modes_e). * flag: Flags passed to the main function. * - * status: The main status code, generally used by the load settings and main functions. + * state: The state information. * * valid: Designate the output context set for valid characters. * valid_not: Designate the output context set for invalid characters. @@ -191,7 +191,7 @@ extern "C" { uint8_t mode; uint16_t flag; - f_status_t status; + f_state_t state; f_color_set_t valid; f_color_set_t valid_not; @@ -214,7 +214,7 @@ extern "C" { { \ utf8_mode_from_bytesequence_e | utf8_mode_to_codepoint_e, \ utf8_main_flag_none_e, \ - F_none, \ + f_state_initialize_t, \ f_color_set_t_initialize, \ f_color_set_t_initialize, \ f_string_static_t_initialize, \ diff --git a/level_3/utf8/c/main/common.c b/level_3/utf8/c/main/common.c index d93a009..4b8a431 100644 --- a/level_3/utf8/c/main/common.c +++ b/level_3/utf8/c/main/common.c @@ -21,14 +21,14 @@ extern "C" { #endif // _di_utf8_setting_delete_ #ifndef _di_utf8_setting_load_ - void utf8_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, utf8_setting_t * const setting) { + void utf8_setting_load(const f_console_arguments_t arguments, f_state_t * const state, fll_program_data_t * const main, utf8_setting_t * const setting) { if (!main || !setting) return; setting->flag = 0; // Load parameters. - setting->status = f_console_parameter_process(state, arguments, &main->parameters, 0); + setting->status = f_console_parameter_process(arguments, state, &main->parameters, 0); if (F_status_is_error(setting->status)) { utf8_print_error(setting, main->error, macro_utf8_f(f_console_parameter_process)); diff --git a/level_3/utf8/c/main/common.h b/level_3/utf8/c/main/common.h index f3e49bc..2a3f294 100644 --- a/level_3/utf8/c/main/common.h +++ b/level_3/utf8/c/main/common.h @@ -42,8 +42,6 @@ extern "C" { * * @param arguments * The parameters passed to the process (often referred to as command line arguments). - * @param state - * A state for providing flags and handling interrupts during long running operations. * @param main * The main program data. * @param setting @@ -54,12 +52,14 @@ extern "C" { * * Errors (with error bit) from: f_console_parameter_process(). * Errors (with error bit) from: fll_program_parameter_process_context(). + * @param state + * A state for providing flags and handling interrupts during long running operations. * * @see f_console_parameter_process() * @see fll_program_parameter_process_context() */ #ifndef _di_utf8_setting_load_ - extern void utf8_setting_load(const f_console_arguments_t arguments, f_state_t state, fll_program_data_t * const main, utf8_setting_t * const setting); + extern void utf8_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, utf8_setting_t * const setting, f_state_t * const state); #endif // _di_utf8_setting_load_ /**