From fc1d33e993e99e8ff34d82be7fabadf7608d9c6d Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Mon, 26 Jun 2023 20:43:18 -0500 Subject: [PATCH] Feature: Add f_files_t and f_filess_t. Provide arrays of f_file_t. --- build/level_0/settings | 6 +- build/monolithic/settings | 6 +- level_0/f_type/c/type_file.h | 50 ++- level_0/f_type_array/c/type_array/file.c | 279 +++++++++++++++++ level_0/f_type_array/c/type_array/file.h | 379 +++++++++++++++++++++++ level_0/f_type_array/c/type_array/private-file.c | 127 ++++++++ level_0/f_type_array/c/type_array/private-file.h | 180 +++++++++++ level_0/f_type_array/c/type_array_file.h | 1 + level_0/f_type_array/data/build/settings | 6 +- 9 files changed, 1023 insertions(+), 11 deletions(-) create mode 100644 level_0/f_type_array/c/type_array/file.c create mode 100644 level_0/f_type_array/c/type_array/file.h create mode 100644 level_0/f_type_array/c/type_array/private-file.c create mode 100644 level_0/f_type_array/c/type_array/private-file.h diff --git a/build/level_0/settings b/build/level_0/settings index 98ab20c..da60113 100644 --- a/build/level_0/settings +++ b/build/level_0/settings @@ -73,8 +73,8 @@ build_sources_library string/quantity.c string/quantitys.c string/quantityss.c build_sources_library string/range.c string/ranges.c string/rangess.c build_sources_library string/static.c string/statics.c string/staticss.c build_sources_library string/triple.c string/triples.c string/tripless.c -build_sources_library type_array/cell.c type_array/fll_id.c type_array/int8.c type_array/int16.c type_array/int32.c type_array/int64.c type_array/int128.c type_array/number_unsigned.c type_array/poll.c type_array/state.c type_array/status.c type_array/uint8.c type_array/uint16.c type_array/uint32.c type_array/uint64.c type_array/uint128.c -build_sources_library type_array/private-cell.c type_array/private-fll_id.c type_array/private-int8.c type_array/private-int16.c type_array/private-int32.c type_array/private-int64.c type_array/private-int128.c type_array/private-number_unsigned.c type_array/private-poll.c type_array/private-state.c type_array/private-status.c type_array/private-uint8.c type_array/private-uint16.c type_array/private-uint32.c type_array/private-uint64.c type_array/private-uint128.c +build_sources_library type_array/cell.c type_array/file.c type_array/fll_id.c type_array/int8.c type_array/int16.c type_array/int32.c type_array/int64.c type_array/int128.c type_array/number_unsigned.c type_array/poll.c type_array/state.c type_array/status.c type_array/uint8.c type_array/uint16.c type_array/uint32.c type_array/uint64.c type_array/uint128.c +build_sources_library type_array/private-cell.c type_array/private-file.c type_array/private-fll_id.c type_array/private-int8.c type_array/private-int16.c type_array/private-int32.c type_array/private-int64.c type_array/private-int128.c type_array/private-number_unsigned.c type_array/private-poll.c type_array/private-state.c type_array/private-status.c type_array/private-uint8.c type_array/private-uint16.c type_array/private-uint32.c type_array/private-uint64.c type_array/private-uint128.c build_sources_library utf.c private-utf.c private-utf_alphabetic.c private-utf_combining.c private-utf_control.c private-utf_digit.c private-utf_emoji.c private-utf_numeric.c private-utf_phonetic.c private-utf_private.c private-utf_punctuation.c private-utf_subscript.c private-utf_superscript.c private-utf_symbol.c private-utf_unassigned.c private-utf_valid.c private-utf_whitespace.c private-utf_wide.c private-utf_word.c private-utf_zero_width.c build_sources_library utf/common.c utf/convert.c build_sources_library utf/dynamic.c utf/dynamics.c utf/dynamicss.c @@ -126,7 +126,7 @@ build_sources_headers string/range.h string/ranges.h string/rangess.h build_sources_headers string/static.h string/statics.h string/staticss.h build_sources_headers string/triple.h string/triples.h string/tripless.h build_sources_headers type.h type_file.h -build_sources_headers type_array.h type_array/common.h type_array/cell.h type_array/fll_id.h type_array/int8.h type_array/int16.h type_array/int32.h type_array/int64.h type_array/int128.h type_array/number_unsigned.h type_array/poll.h type_array/state.h type_array/status.h type_array/uint8.h type_array/uint16.h type_array/uint32.h type_array/uint64.h type_array/uint128.h +build_sources_headers type_array.h type_array/common.h type_array/cell.h type_array/file.h type_array/fll_id.h type_array/int8.h type_array/int16.h type_array/int32.h type_array/int64.h type_array/int128.h type_array/number_unsigned.h type_array/poll.h type_array/state.h type_array/status.h type_array/uint8.h type_array/uint16.h type_array/uint32.h type_array/uint64.h type_array/uint128.h build_sources_headers utf.h utf/common.h utf/convert.h utf/dynamic.h utf/dynamics.h utf/dynamicss.h utf/is.h utf/is_character.h utf/map.h utf/maps.h utf/mapss.h utf/map_multi.h utf/map_multis.h utf/map_multiss.h utf/static.h utf/statics.h utf/staticss.h utf/string.h utf/triple.h utf/triples.h utf/tripless.h build_sources_headers-thread thread.h thread/attribute.h thread/barrier.h thread/barrier_attribute.h thread/condition.h thread/condition_attribute.h thread/id.h thread/key.h thread/lock.h thread/lock_attribute.h thread/mutex.h thread/mutex_attribute.h thread/once.h thread/semaphore.h thread/set.h thread/spin.h diff --git a/build/monolithic/settings b/build/monolithic/settings index e7c7924..d172611 100644 --- a/build/monolithic/settings +++ b/build/monolithic/settings @@ -73,8 +73,8 @@ build_sources_library level_0/string/quantity.c level_0/string/quantitys.c level build_sources_library level_0/string/range.c level_0/string/ranges.c level_0/string/rangess.c build_sources_library level_0/string/static.c level_0/string/statics.c level_0/string/staticss.c build_sources_library level_0/string/triple.c level_0/string/triples.c level_0/string/tripless.c -build_sources_library level_0/type_array/cell.c level_0/type_array/fll_id.c level_0/type_array/int8.c level_0/type_array/int16.c level_0/type_array/int32.c level_0/type_array/int64.c level_0/type_array/int128.c level_0/type_array/number_unsigned.c level_0/type_array/poll.c level_0/type_array/state.c level_0/type_array/status.c level_0/type_array/uint8.c level_0/type_array/uint16.c level_0/type_array/uint32.c level_0/type_array/uint64.c level_0/type_array/uint128.c -build_sources_library level_0/type_array/private-cell.c level_0/type_array/private-fll_id.c level_0/type_array/private-int8.c level_0/type_array/private-int16.c level_0/type_array/private-int32.c level_0/type_array/private-int64.c level_0/type_array/private-int128.c level_0/type_array/private-number_unsigned.c level_0/type_array/private-poll.c level_0/type_array/private-state.c level_0/type_array/private-status.c level_0/type_array/private-uint8.c level_0/type_array/private-uint16.c level_0/type_array/private-uint32.c level_0/type_array/private-uint64.c level_0/type_array/private-uint128.c +build_sources_library level_0/type_array/cell.c level_0/type_array/file.c level_0/type_array/fll_id.c level_0/type_array/int8.c level_0/type_array/int16.c level_0/type_array/int32.c level_0/type_array/int64.c level_0/type_array/int128.c level_0/type_array/number_unsigned.c level_0/type_array/poll.c level_0/type_array/state.c level_0/type_array/status.c level_0/type_array/uint8.c level_0/type_array/uint16.c level_0/type_array/uint32.c level_0/type_array/uint64.c level_0/type_array/uint128.c +build_sources_library level_0/type_array/private-cell.c level_0/type_array/private-file.c level_0/type_array/private-fll_id.c level_0/type_array/private-int8.c level_0/type_array/private-int16.c level_0/type_array/private-int32.c level_0/type_array/private-int64.c level_0/type_array/private-int128.c level_0/type_array/private-number_unsigned.c level_0/type_array/private-poll.c level_0/type_array/private-state.c level_0/type_array/private-status.c level_0/type_array/private-uint8.c level_0/type_array/private-uint16.c level_0/type_array/private-uint32.c level_0/type_array/private-uint64.c level_0/type_array/private-uint128.c build_sources_library level_0/utf.c level_0/private-utf.c level_0/private-utf_alphabetic.c level_0/private-utf_combining.c level_0/private-utf_control.c level_0/private-utf_digit.c level_0/private-utf_emoji.c level_0/private-utf_numeric.c level_0/private-utf_phonetic.c level_0/private-utf_private.c level_0/private-utf_punctuation.c level_0/private-utf_subscript.c level_0/private-utf_superscript.c level_0/private-utf_symbol.c level_0/private-utf_unassigned.c level_0/private-utf_valid.c level_0/private-utf_whitespace.c level_0/private-utf_wide.c level_0/private-utf_word.c level_0/private-utf_zero_width.c build_sources_library level_0/utf/common.c level_0/utf/convert.c build_sources_library level_0/utf/dynamic.c level_0/utf/dynamics.c level_0/utf/dynamicss.c @@ -148,7 +148,7 @@ build_sources_headers level_0/string/range.h level_0/string/ranges.h level_0/str build_sources_headers level_0/string/static.h level_0/string/statics.h level_0/string/staticss.h build_sources_headers level_0/string/triple.h level_0/string/triples.h level_0/string/tripless.h build_sources_headers level_0/type.h level_0/type_file.h -build_sources_headers level_0/type_array.h level_0/type_array/common.h level_0/type_array/cell.h level_0/type_array/fll_id.h level_0/type_array/int8.h level_0/type_array/int16.h level_0/type_array/int32.h level_0/type_array/int64.h level_0/type_array/int128.h level_0/type_array/number_unsigned.h level_0/type_array/poll.h level_0/type_array/state.h level_0/type_array/status.h level_0/type_array/uint8.h level_0/type_array/uint16.h level_0/type_array/uint32.h level_0/type_array/uint64.h level_0/type_array/uint128.h +build_sources_headers level_0/type_array.h level_0/type_array/common.h level_0/type_array/cell.h level_0/type_array/file.h level_0/type_array/fll_id.h level_0/type_array/int8.h level_0/type_array/int16.h level_0/type_array/int32.h level_0/type_array/int64.h level_0/type_array/int128.h level_0/type_array/number_unsigned.h level_0/type_array/poll.h level_0/type_array/state.h level_0/type_array/status.h level_0/type_array/uint8.h level_0/type_array/uint16.h level_0/type_array/uint32.h level_0/type_array/uint64.h level_0/type_array/uint128.h build_sources_headers level_0/utf.h level_0/utf/common.h level_0/utf/convert.h level_0/utf/dynamic.h level_0/utf/dynamics.h level_0/utf/dynamicss.h level_0/utf/is.h level_0/utf/is_character.h level_0/utf/map.h level_0/utf/maps.h level_0/utf/mapss.h level_0/utf/map_multi.h level_0/utf/map_multis.h level_0/utf/map_multiss.h level_0/utf/static.h level_0/utf/statics.h level_0/utf/staticss.h level_0/utf/string.h level_0/utf/triple.h level_0/utf/triples.h level_0/utf/tripless.h build_sources_headers level_1/control_group.h diff --git a/level_0/f_type/c/type_file.h b/level_0/f_type/c/type_file.h index 2420401..6944b60 100644 --- a/level_0/f_type/c/type_file.h +++ b/level_0/f_type/c/type_file.h @@ -187,6 +187,52 @@ extern "C" { #endif // _di_f_file_t_ /** + * An array of f_file_t. + * + * The macros are defined in type_array.h or type_array_file.h. + * + * array: The array of f_file_t. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_files_t_ + typedef struct { + f_file_t *array; + + f_number_unsigned_t size; + f_number_unsigned_t used; + } f_files_t; + + #define f_files_t_initialize { 0, 0, 0 } + + #define macro_f_files_t_initialize_1(array, size, used) { array, size, used } + #define macro_f_files_t_initialize_2(array, length) { array, length, length } +#endif // _di_f_files_t_ + +/** + * This holds an array of f_files_t. + * + * The macros are defined in type_array.h or type_array_file.h. + * + * array: The array of f_file_t arrays. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_filess_t_ + typedef struct { + f_files_t *array; + + f_number_unsigned_t size; + f_number_unsigned_t used; + } f_filess_t; + + #define f_filess_t_initialize { 0, 0, 0 } + + #define macro_f_filess_t_initialize_1(array, size, used) { array, size, used } + #define macro_f_filess_t_initialize_2(array, length) { array, length, length } +#endif // _di_f_filess_t_ + +/** * A typdef for representing struct pollfd. */ #ifndef _di_f_poll_t_ @@ -203,7 +249,7 @@ extern "C" { /** * An array of pollfd structures. * - * The macros are defined in type_array.h or type_array-common.h. + * The macros are defined in type_array.h or type_array_file.h. * * If used for functions like poll() (a common use) then the max array length for used is limited to nfds_t which might be different from f_number_unsigned_t. * The nfds_t is often either uint32_t or an uint64_t. @@ -230,7 +276,7 @@ extern "C" { /** * An array of f_polls_t. * - * The macros are defined in type_array.h or type_array-common.h. + * The macros are defined in type_array.h or type_array_file.h. * * array: The array of f_polls_t. * size: Total amount of allocated space. diff --git a/level_0/f_type_array/c/type_array/file.c b/level_0/f_type_array/c/type_array/file.c new file mode 100644 index 0000000..eb82e4e --- /dev/null +++ b/level_0/f_type_array/c/type_array/file.c @@ -0,0 +1,279 @@ +#include "../type_array.h" +#include "../type_array_file.h" +#include "file.h" +#include "private-file.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_files_adjust_ + f_status_t f_files_adjust(const f_number_unsigned_t length, f_files_t *files) { + #ifndef _di_level_0_parameter_checking_ + if (!files) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_files_adjust(length, files); + } +#endif // _di_f_files_adjust_ + +#ifndef _di_f_files_append_ + f_status_t f_files_append(const f_file_t source, f_files_t *destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_files_append(source, destination); + } +#endif // _di_f_files_append_ + +#ifndef _di_f_files_append_all_ + f_status_t f_files_append_all(const f_files_t source, f_files_t *destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + return private_f_files_append_all(source, destination); + } +#endif // _di_f_files_append_all_ + +#ifndef _di_f_files_decimate_by_ + f_status_t f_files_decimate_by(const f_number_unsigned_t amount, f_files_t *files) { + #ifndef _di_level_0_parameter_checking_ + if (!files) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (files->size - amount > 0) { + return private_f_files_adjust(files->size - amount, files); + } + + return private_f_files_adjust(0, files); + } +#endif // _di_f_files_decimate_by_ + +#ifndef _di_f_files_decrease_by_ + f_status_t f_files_decrease_by(const f_number_unsigned_t amount, f_files_t *files) { + #ifndef _di_level_0_parameter_checking_ + if (!files) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (files->size - amount > 0) { + return private_f_files_resize(files->size - amount, files); + } + + return private_f_files_resize(0, files); + } +#endif // _di_f_files_decrease_by_ + +#ifndef _di_f_files_increase_ + f_status_t f_files_increase(const f_number_unsigned_t step, f_files_t *files) { + #ifndef _di_level_0_parameter_checking_ + if (!files) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && files->used + 1 > files->size) { + f_number_unsigned_t size = files->used + step; + + if (size > F_number_t_size_unsigned_d) { + if (files->used + 1 > F_number_t_size_unsigned_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_number_t_size_unsigned_d; + } + + return private_f_files_resize(size, files); + } + + return F_data_not; + } +#endif // _di_f_files_increase_ + +#ifndef _di_f_files_increase_by_ + f_status_t f_files_increase_by(const f_number_unsigned_t amount, f_files_t *files) { + #ifndef _di_level_0_parameter_checking_ + if (!files) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (files->used + amount > files->size) { + if (files->used + amount > F_number_t_size_unsigned_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_files_resize(files->used + amount, files); + } + + return F_data_not; + } +#endif // _di_f_files_increase_by_ + +#ifndef _di_f_files_resize_ + f_status_t f_files_resize(const f_number_unsigned_t length, f_files_t *files) { + #ifndef _di_level_0_parameter_checking_ + if (!files) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_files_resize(length, files); + } +#endif // _di_f_files_resize_ + +#ifndef _di_f_filess_adjust_ + f_status_t f_filess_adjust(const f_number_unsigned_t length, f_filess_t *filess) { + #ifndef _di_level_0_parameter_checking_ + if (!filess) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_filess_adjust(length, filess); + } +#endif // _di_f_filess_adjust_ + +#ifndef _di_f_filess_append_ + f_status_t f_filess_append(const f_files_t source, f_filess_t *destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + f_status_t status = F_none; + + if (destination->used + 1 > destination->size) { + status = private_f_filess_resize(destination->used + F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; + } + + status = private_f_files_append_all(source, &destination->array[destination->used]); + if (F_status_is_error(status)) return status; + + ++destination->used; + + return F_none; + } +#endif // _di_f_filess_append_ + +#ifndef _di_f_filess_append_all_ + f_status_t f_filess_append_all(const f_filess_t source, f_filess_t *destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + f_status_t status = F_none; + + if (destination->used + source.used > destination->size) { + status = private_f_filess_resize(destination->used + source.used, destination); + if (F_status_is_error(status)) return status; + } + + for (f_number_unsigned_t i = 0; i < source.used; ++i, ++destination->used) { + + destination->array[destination->used].used = 0; + + if (source.array[i].used) { + status = private_f_files_append_all(source.array[i], &destination->array[destination->used]); + if (F_status_is_error(status)) return status; + } + } // for + + return F_none; + } +#endif // _di_f_filess_append_all_ + +#ifndef _di_f_filess_decimate_by_ + f_status_t f_filess_decimate_by(const f_number_unsigned_t amount, f_filess_t *filess) { + #ifndef _di_level_0_parameter_checking_ + if (!filess) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (filess->size - amount > 0) { + return private_f_filess_adjust(filess->size - amount, filess); + } + + return private_f_filess_adjust(0, filess); + } +#endif // _di_f_filess_decimate_by_ + +#ifndef _di_f_filess_decrease_by_ + f_status_t f_filess_decrease_by(const f_number_unsigned_t amount, f_filess_t *filess) { + #ifndef _di_level_0_parameter_checking_ + if (!filess) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (filess->size - amount > 0) { + return private_f_filess_resize(filess->size - amount, filess); + } + + return private_f_filess_resize(0, filess); + } +#endif // _di_f_filess_decrease_by_ + +#ifndef _di_f_filess_increase_ + f_status_t f_filess_increase(const f_number_unsigned_t step, f_filess_t *filess) { + #ifndef _di_level_0_parameter_checking_ + if (!filess) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && filess->used + 1 > filess->size) { + f_number_unsigned_t size = filess->used + step; + + if (size > F_number_t_size_unsigned_d) { + if (filess->used + 1 > F_number_t_size_unsigned_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_number_t_size_unsigned_d; + } + + return private_f_filess_resize(size, filess); + } + + return F_data_not; + } +#endif // _di_f_filess_increase_ + +#ifndef _di_f_filess_increase_by_ + f_status_t f_filess_increase_by(const f_number_unsigned_t amount, f_filess_t *filess) { + #ifndef _di_level_0_parameter_checking_ + if (!filess) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (filess->used + amount > filess->size) { + if (filess->used + amount > F_number_t_size_unsigned_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_filess_resize(filess->used + amount, filess); + } + + return F_data_not; + } +#endif // _di_f_filess_increase_by_ + +#ifndef _di_f_filess_resize_ + f_status_t f_filess_resize(const f_number_unsigned_t length, f_filess_t *filess) { + #ifndef _di_level_0_parameter_checking_ + if (!filess) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_filess_resize(length, filess); + } +#endif // _di_f_filess_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_type_array/c/type_array/file.h b/level_0/f_type_array/c/type_array/file.h new file mode 100644 index 0000000..a829240 --- /dev/null +++ b/level_0/f_type_array/c/type_array/file.h @@ -0,0 +1,379 @@ +/** + * FLL - Level 0 + * + * Project: Type + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Defines data to be used for/by type (array) related functionality. + * + * This is auto-included by type_array.h and should not need to be explicitly included. + */ +#ifndef _F_type_array_file_h +#define _F_type_array_file_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Resize the files array. + * + * @param length + * The new size to use. + * @param files + * The files array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_adjust(). + */ +#ifndef _di_f_files_adjust_ + extern f_status_t f_files_adjust(const f_number_unsigned_t length, f_files_t *files); +#endif // _di_f_files_adjust_ + +/** + * Append the single source file onto the destination. + * + * @param source + * The source file to append. + * @param destination + * The destination files the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_files_append_ + extern f_status_t f_files_append(const f_file_t source, f_files_t *destination); +#endif // _di_f_files_append_ + +/** + * Append the source files onto the destination. + * + * @param source + * The source files to append. + * @param destination + * The destination files the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_files_append_all_ + extern f_status_t f_files_append_all(const f_files_t source, f_files_t *destination); +#endif // _di_f_files_append_all_ + +/** + * Resize the files array 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 les than 0. + * + * @param amount + * A positive number representing how much to decimate the size by. + * @param files + * The files array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_adjust(). + */ +#ifndef _di_f_files_decimate_by_ + extern f_status_t f_files_decimate_by(const f_number_unsigned_t amount, f_files_t *files); +#endif // _di_f_files_decimate_by_ + +/** + * Resize the files array 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 les than 0. + * + * @param amount + * A positive number representing how much to decrease the size by. + * @param files + * The files array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_files_decrease_by_ + extern f_status_t f_files_decrease_by(const f_number_unsigned_t amount, f_files_t *files); +#endif // _di_f_files_decrease_by_ + +/** + * Increase the size of the files array, but only if necesary. + * + * If the given length is too large for the buffer, then attempt to set max buffer size (F_number_t_size_unsigned_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 files + * The files 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_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_files_increase_ + extern f_status_t f_files_increase(const f_number_unsigned_t step, f_files_t *files); +#endif // _di_f_files_increase_ + +/** + * Resize the files array 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_number_t_size_unsigned_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 files + * The files 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_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_files_increase_by_ + extern f_status_t f_files_increase_by(const f_number_unsigned_t amount, f_files_t *files); +#endif // _di_f_files_increase_by_ + +/** + * Resize the files array. + * + * @param length + * The new size to use. + * @param files + * The files array to adjust. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_files_resize_ + extern f_status_t f_files_resize(const f_number_unsigned_t length, f_files_t *files); +#endif // _di_f_files_resize_ + +/** + * Resize the filess array. + * + * @param length + * The new size to use. + * @param filess + * The filess array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_adjust(). + * Errors (with error bit) from: f_memory_destroy(). + */ +#ifndef _di_f_filess_adjust_ + extern f_status_t f_filess_adjust(const f_number_unsigned_t length, f_filess_t *filess); +#endif // _di_f_filess_adjust_ + +/** + * Append the single source files onto the destination. + * + * @param source + * The source files to append. + * @param destination + * The destination ranges the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_filess_append_ + extern f_status_t f_filess_append(const f_files_t source, f_filess_t *destination); +#endif // _di_f_filess_append_ + +/** + * Append the source filess onto the destination. + * + * @param source + * The source filess to append. + * @param destination + * The destination ranges the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_filess_append_all_ + extern f_status_t f_filess_append_all(const f_filess_t source, f_filess_t *destination); +#endif // _di_f_filess_append_all_ + +/** + * Resize the filess array 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 filess + * The filess array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_adjust(). + * Errors (with error bit) from: f_memory_destroy(). + */ +#ifndef _di_f_filess_decimate_by_ + extern f_status_t f_filess_decimate_by(const f_number_unsigned_t amount, f_filess_t *filess); +#endif // _di_f_filess_decimate_by_ + +/** + * Resize the filess array 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 filess + * The filess array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_delete(). + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_filess_decrease_by_ + extern f_status_t f_filess_decrease_by(const f_number_unsigned_t amount, f_filess_t *filess); +#endif // _di_f_filess_decrease_by_ + +/** + * Increase the size of the filess array, but only if necessary. + * + * If the given length is too large for the buffer, then attempt to set max buffer size (F_number_t_size_unsigned_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 filess + * The filess 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_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_filess_increase_ + extern f_status_t f_filess_increase(const f_number_unsigned_t step, f_filess_t *filess); +#endif // _di_f_filess_increase_ + +/** + * Resize the filess array 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_number_t_size_unsigned_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 filess + * The filess 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_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_filess_increase_by_ + extern f_status_t f_filess_increase_by(const f_number_unsigned_t amount, f_filess_t *filess); +#endif // _di_f_filess_increase_by_ + +/** + * Resize the filess array. + * + * @param length + * The new size to use. + * @param filess + * The filess array to adjust. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_delete(). + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_filess_resize_ + extern f_status_t f_filess_resize(const f_number_unsigned_t length, f_filess_t *filess); +#endif // _di_f_filess_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_type_array_file_h diff --git a/level_0/f_type_array/c/type_array/private-file.c b/level_0/f_type_array/c/type_array/private-file.c new file mode 100644 index 0000000..6abb3c6 --- /dev/null +++ b/level_0/f_type_array/c/type_array/private-file.c @@ -0,0 +1,127 @@ +#include "../type_array.h" +#include "../type_array_file.h" +#include "private-file.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(_di_f_files_adjust_) || !defined(_di_f_files_decimate_by_) + f_status_t private_f_files_adjust(const f_number_unsigned_t length, f_files_t *files) { + + const f_status_t status = f_memory_adjust(files->size, length, sizeof(f_file_t), (void **) & files->array); + if (F_status_is_error(status)) return status; + + files->size = length; + + if (files->used > files->size) { + files->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_files_adjust_) || !defined(_di_f_files_decimate_by_) + +#if !defined(_di_f_files_append_) || !defined(_di_f_filess_append_) + extern f_status_t private_f_files_append(const f_file_t source, f_files_t *destination) { + + if (destination->used + 1 > destination->size) { + const f_status_t status = private_f_files_resize(destination->used + F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; + } + + destination->array[destination->used++] = source; + + return F_none; + } +#endif // !defined(_di_f_files_append_) || !defined(_di_f_filess_append_) + +#if !defined(_di_f_files_append_) || !defined(_di_f_files_append_all_) || !defined(_di_f_filess_append_all_) + extern f_status_t private_f_files_append_all(const f_files_t source, f_files_t *destination) { + + if (destination->used + source.used > destination->size) { + const f_status_t status = private_f_files_resize(destination->used + source.used, destination); + if (F_status_is_error(status)) return status; + } + + for (f_number_unsigned_t i = 0; i < source.used; ++i) { + destination->array[destination->used++] = source.array[i]; + } // for + + return F_none; + } +#endif // !defined(_di_f_files_append_) || !defined(_di_f_files_append_all_) || !defined(_di_f_filess_append_all_) + +#if !defined(_di_f_files_append_) || !defined(_di_f_files_append_all_) || !defined(_di_f_files_decrease_by_) || !defined(_di_f_files_increase_) || !defined(_di_f_files_increase_by_) || !defined(_di_f_files_resize_) || !defined(_di_f_filess_append_) || !defined(_di_f_filess_append_all_) + f_status_t private_f_files_resize(const f_number_unsigned_t length, f_files_t *files) { + + const f_status_t status = f_memory_resize(files->size, length, sizeof(f_file_t), (void **) & files->array); + if (F_status_is_error(status)) return status; + + files->size = length; + + if (files->used > files->size) { + files->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_files_append_) || !defined(_di_f_files_append_all_) || !defined(_di_f_files_decrease_by_) || !defined(_di_f_files_increase_) || !defined(_di_f_files_increase_by_) || !defined(_di_f_files_resize_) || !defined(_di_f_filess_append_) || !defined(_di_f_filess_append_all_) + +#if !defined(_di_f_filess_adjust_) || !defined(_di_f_filess_decimate_by_) + f_status_t private_f_filess_adjust(const f_number_unsigned_t length, f_filess_t *filess) { + + f_status_t status = F_none; + + for (f_number_unsigned_t i = length; i < filess->size; ++i) { + + status = f_memory_destroy(filess->array[i].size, sizeof(f_files_t), (void **) & filess->array[i].array); + if (F_status_is_error(status)) return status; + + filess->array[i].size = 0; + filess->array[i].used = 0; + } // for + + status = f_memory_adjust(filess->size, length, sizeof(f_files_t), (void **) & filess->array); + if (F_status_is_error(status)) return status; + + filess->size = length; + + if (filess->used > filess->size) { + filess->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_filess_adjust_) || !defined(_di_f_filess_decimate_by_) + +#if !defined(_di_f_filess_decrease_by_) || !defined(_di_f_filess_increase_) || !defined(_di_f_filess_increase_by_) || !defined(_di_f_filess_resize_) + f_status_t private_f_filess_resize(const f_number_unsigned_t length, f_filess_t *filess) { + + f_status_t status = F_none; + + for (f_number_unsigned_t i = length; i < filess->size; ++i) { + + status = f_memory_delete(filess->array[i].size, sizeof(f_files_t), (void **) & filess->array[i].array); + if (F_status_is_error(status)) return status; + + filess->array[i].size = 0; + filess->array[i].used = 0; + } // for + + status = f_memory_resize(filess->size, length, sizeof(f_files_t), (void **) & filess->array); + if (F_status_is_error(status)) return status; + + filess->size = length; + + if (filess->used > filess->size) { + filess->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_filess_decrease_by_) || !defined(_di_f_filess_increase_) || !defined(_di_f_filess_increase_by_) || !defined(_di_f_filess_resize_) + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_type_array/c/type_array/private-file.h b/level_0/f_type_array/c/type_array/private-file.h new file mode 100644 index 0000000..6c94fb5 --- /dev/null +++ b/level_0/f_type_array/c/type_array/private-file.h @@ -0,0 +1,180 @@ +/** + * FLL - Level 0 + * + * Project: Type + * 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_type_array_file_h +#define _PRIVATE_F_type_array_file_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Private implementation for resizing the files array. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The length to adjust to. + * @param files + * The files array to adjust. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * + * Errors (with error bit) from: f_memory_adjust(). + * + * @see f_files_adjust() + * @see f_files_decimate_by() + */ +#if !defined(_di_f_files_adjust_) || !defined(_di_f_files_decimate_by_) + extern f_status_t private_f_files_adjust(const f_number_unsigned_t length, f_files_t *files) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_files_adjust_) || !defined(_di_f_files_decimate_by_) + +/** + * Private implementation for appending the file array. + * + * Intended to be shared to each of the different implementation variations. + * + * @param source + * The source file to append. + * @param destination + * The destination lengths the source is appended onto. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: f_memory_resize(). + * + * @see f_memory_resize() + * @see f_files_append() + * @see f_filess_append() + */ +#if !defined(_di_f_files_append_) || !defined(_di_f_filess_append_) + extern f_status_t private_f_files_append(const f_file_t source, f_files_t *destination) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_files_append_) || !defined(_di_f_filess_append_) + +/** + * Private implementation for appending the file array. + * + * Intended to be shared to each of the different implementation variations. + * + * @param source + * The source files to append. + * @param destination + * The destination lengths the source is appended onto. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: f_memory_resize(). + * + * @see f_memory_resize() + * @see f_files_append_all() + * @see f_filess_append() + * @see f_filess_append_all() + */ +#if !defined(_di_f_files_append_) || !defined(_di_f_files_append_all_) || !defined(_di_f_filess_append_all_) + extern f_status_t private_f_files_append_all(const f_files_t source, f_files_t *destination) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_files_append_) || !defined(_di_f_files_append_all_) || !defined(_di_f_filess_append_all_) + +/** + * Private implementation for resizing the files array. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The length to adjust to. + * @param files + * The files array to adjust. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * + * Errors (with error bit) from: f_memory_resize(). + * + * @see f_files_append() + * @see f_files_append_all() + * @see f_files_decrease_by() + * @see f_files_increase() + * @see f_files_increase_by() + * @see f_files_resize() + * @see f_filess_append() + * @see f_filess_append_all() + * + */ +#if !defined(_di_f_files_append_) || !defined(_di_f_files_append_all_) || !defined(_di_f_files_decrease_by_) || !defined(_di_f_files_increase_) || !defined(_di_f_files_increase_by_) || !defined(_di_f_files_resize_) || !defined(_di_f_filess_append_) || !defined(_di_f_filess_append_all_) + extern f_status_t private_f_files_resize(const f_number_unsigned_t length, f_files_t *files) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_files_append_) || !defined(_di_f_files_append_all_) || !defined(_di_f_files_decrease_by_) || !defined(_di_f_files_increase_) || !defined(_di_f_files_increase_by_) || !defined(_di_f_files_resize_) || !defined(_di_f_filess_append_) || !defined(_di_f_filess_append_all_) + +/** + * Private implementation for resizing the filess array. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The length to adjust to. + * @param filess + * The filess array to adjust. + * + * @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 new length is larger than max array length. + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_adjust(). + * Errors (with error bit) from: f_memory_destroy(). + * + * @see f_filess_adjust() + * @see f_filess_decimate_by() + */ +#if !defined(_di_f_filess_adjust_) || !defined(_di_f_filess_decimate_by_) + extern f_status_t private_f_filess_adjust(const f_number_unsigned_t length, f_filess_t *filess) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_filess_adjust_) || !defined(_di_f_filess_decimate_by_) + +/** + * Private implementation for resizing the filess array. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The length to resize to. + * @param filess + * The filess 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 new length is larger than max array length. + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_delete(). + * Errors (with error bit) from: f_memory_resize(). + * + * @see f_filess_decrease_by() + * @see f_filess_increase() + * @see f_filess_increase_by() + * @see f_filess_resize() + */ +#if !defined(_di_f_filess_decrease_by_) || !defined(_di_f_filess_increase_) || !defined(_di_f_filess_increase_by_) || !defined(_di_f_filess_resize_) + extern f_status_t private_f_filess_resize(const f_number_unsigned_t length, f_filess_t *filess) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_filess_decrease_by_) || !defined(_di_f_filess_increase_) || !defined(_di_f_filess_increase_by_) || !defined(_di_f_filess_resize_) + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _PRIVATE_F_type_array_file_h diff --git a/level_0/f_type_array/c/type_array_file.h b/level_0/f_type_array/c/type_array_file.h index dddc0fb..c7829b8 100644 --- a/level_0/f_type_array/c/type_array_file.h +++ b/level_0/f_type_array/c/type_array_file.h @@ -19,6 +19,7 @@ #include // FLL-0 type_array includes. +#include #include #ifdef __cplusplus diff --git a/level_0/f_type_array/data/build/settings b/level_0/f_type_array/data/build/settings index 76dbae7..1ea161f 100644 --- a/level_0/f_type_array/data/build/settings +++ b/level_0/f_type_array/data/build/settings @@ -32,10 +32,10 @@ build_language c build_libraries -lc build_libraries-individual -lf_memory -build_sources_library type_array/cell.c type_array/fll_id.c type_array/int8.c type_array/int16.c type_array/int32.c type_array/int64.c type_array/int128.c type_array/number_unsigned.c type_array/poll.c type_array/state.c type_array/status.c type_array/uint8.c type_array/uint16.c type_array/uint32.c type_array/uint64.c type_array/uint128.c -build_sources_library type_array/private-cell.c type_array/private-fll_id.c type_array/private-int8.c type_array/private-int16.c type_array/private-int32.c type_array/private-int64.c type_array/private-int128.c type_array/private-number_unsigned.c type_array/private-poll.c type_array/private-state.c type_array/private-status.c type_array/private-uint8.c type_array/private-uint16.c type_array/private-uint32.c type_array/private-uint64.c type_array/private-uint128.c +build_sources_library type_array/cell.c type_array/file.c type_array/fll_id.c type_array/int8.c type_array/int16.c type_array/int32.c type_array/int64.c type_array/int128.c type_array/number_unsigned.c type_array/poll.c type_array/state.c type_array/status.c type_array/uint8.c type_array/uint16.c type_array/uint32.c type_array/uint64.c type_array/uint128.c +build_sources_library type_array/private-cell.c type_array/private-file.c type_array/private-fll_id.c type_array/private-int8.c type_array/private-int16.c type_array/private-int32.c type_array/private-int64.c type_array/private-int128.c type_array/private-number_unsigned.c type_array/private-poll.c type_array/private-state.c type_array/private-status.c type_array/private-uint8.c type_array/private-uint16.c type_array/private-uint32.c type_array/private-uint64.c type_array/private-uint128.c -build_sources_headers type_array.h type_array_file.h type_array/common.h type_array/cell.h type_array/fll_id.h type_array/int8.h type_array/int16.h type_array/int32.h type_array/int64.h type_array/int128.h type_array/number_unsigned.h type_array/poll.h type_array/state.h type_array/status.h type_array/uint8.h type_array/uint16.h type_array/uint32.h type_array/uint64.h type_array/uint128.h +build_sources_headers type_array.h type_array_file.h type_array/common.h type_array/cell.h type_array/file.h type_array/fll_id.h type_array/int8.h type_array/int16.h type_array/int32.h type_array/int64.h type_array/int128.h type_array/number_unsigned.h type_array/poll.h type_array/state.h type_array/status.h type_array/uint8.h type_array/uint16.h type_array/uint32.h type_array/uint64.h type_array/uint128.h build_script yes build_shared yes -- 1.8.3.1