From: Kevin Day Date: Thu, 30 Apr 2020 02:56:00 +0000 (-0500) Subject: Feature: add parameter rip functions for ripping console parameters into an array... X-Git-Tag: 0.5.0~310 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=43006fd41f5b3922bcde5a7c7bdd4455313ebff0;p=fll Feature: add parameter rip functions for ripping console parameters into an array of strings --- diff --git a/level_2/fll_program/c/program.c b/level_2/fll_program/c/program.c index 7be4ba9..3fb05b0 100644 --- a/level_2/fll_program/c/program.c +++ b/level_2/fll_program/c/program.c @@ -214,6 +214,76 @@ extern "C" { } #endif // _di_fll_program_parameter_additional_mash_trim_ +#ifndef _di_fll_program_parameter_additional_rip_ + f_return_status fll_program_parameter_additional_rip(const f_string *argv, const f_string_lengths additional, f_string_dynamics *result) { + #ifndef _di_level_2_parameter_checking_ + if (argv == 0) return f_status_set_error(f_invalid_parameter); + if (result == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_2_parameter_checking_ + + f_status status = f_none; + + for (f_string_length i = 0; i < additional.used; i++) { + f_string_dynamic ripped = f_string_dynamic_initialize; + + status = fl_string_rip(argv[additional.array[i]], 0, strnlen(argv[additional.array[i]], f_console_max_size), &ripped); + + if (f_status_is_error(status)) return status; + + if (status == f_no_data) { + status = f_none; + } + else { + if (result->used >= result->size) { + f_macro_string_dynamics_resize(status, (*result), result->size + f_console_default_allocation_step); + + if (f_status_is_error(status)) return status; + } + + result->array[result->used] = ripped; + result->used++; + } + } // for + + return status; + } +#endif // _di_fll_program_parameter_additional_rip_ + +#ifndef _di_fll_program_parameter_additional_rip_trim_ + f_return_status fll_program_parameter_additional_rip_trim(const f_string *argv, const f_string_lengths additional, f_string_dynamics *result) { + #ifndef _di_level_2_parameter_checking_ + if (argv == 0) return f_status_set_error(f_invalid_parameter); + if (result == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_2_parameter_checking_ + + f_status status = f_none; + + for (f_string_length i = 0; i < additional.used; i++) { + f_string_dynamic ripped = f_string_dynamic_initialize; + + status = fl_string_rip_trim(argv[additional.array[i]], 0, strnlen(argv[additional.array[i]], f_console_max_size), &ripped); + + if (f_status_is_error(status)) return status; + + if (status == f_no_data) { + status = f_none; + } + else { + if (result->used >= result->size) { + f_macro_string_dynamics_resize(status, (*result), result->size + f_console_default_allocation_step); + + if (f_status_is_error(status)) return status; + } + + result->array[result->used] = ripped; + result->used++; + } + } // for + + return status; + } +#endif // _di_fll_program_parameter_additional_rip_trim_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_2/fll_program/c/program.h b/level_2/fll_program/c/program.h index 52583e1..68c55b7 100644 --- a/level_2/fll_program/c/program.h +++ b/level_2/fll_program/c/program.h @@ -210,6 +210,58 @@ extern "C" { extern f_return_status fll_program_parameter_additional_mash_trim(const f_string glue, const f_string_length glue_length, const f_string *argv, const f_string_lengths additional, f_string_dynamic *destination); #endif // _di_fll_program_parameter_additional_mash_trim_ +/** + * Allocate new strings from all of the provided locations. + * + * Empty console parameters are ignored. + * + * @param argv + * The program argument array to parse. + * @param additional + * The string locations where the console parameters are found. + * @param result + * An array of dynamic strings each representing a console parameter. + * + * @return + * f_none on success. + * f_no_data if nothing to rip, no allocations or reallocations are performed. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_error_allocation (with error bit) on memory allocation error. + * f_error_reallocation (with error bit) on memory reallocation error. + * + * @see fl_string_rip() + * @see fll_program_parameter_additional_rip_trim() + */ +#ifndef _di_fll_program_parameter_additional_rip_ + extern f_return_status fll_program_parameter_additional_rip(const f_string *argv, const f_string_lengths additional, f_string_dynamics *result); +#endif // _di_fll_program_parameter_additional_rip_ + +/** + * Allocate new strings from all of the provided locations. + * + * The console parameters are trimmed. + * + * @param argv + * The program argument array to parse. + * @param additional + * The string locations where the console parameters are found. + * @param result + * An array of dynamic strings each representing a console parameter. + * + * @return + * f_none on success. + * f_no_data if nothing to rip, no allocations or reallocations are performed. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_error_allocation (with error bit) on memory allocation error. + * f_error_reallocation (with error bit) on memory reallocation error. + * + * @see fl_string_rip() + * @see fll_program_parameter_additional_rip() + */ +#ifndef _di_fll_program_parameter_additional_rip_trim_ + extern f_return_status fll_program_parameter_additional_rip_trim(const f_string *argv, const f_string_lengths additional, f_string_dynamics *result); +#endif // _di_fll_program_parameter_additional_rip_trim_ + #ifdef __cplusplus } // extern "C" #endif