From 7d32523fa7ea331e06360b0cefe20cda27d0a321 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Thu, 10 Dec 2020 23:49:29 -0600 Subject: [PATCH] Feature: Provide a tuple of string structure. --- build/level_0/settings | 2 +- build/monolithic/settings | 2 +- level_0/f_string/c/string.h | 1 + level_0/f_string/c/string_map.h | 9 +- level_0/f_string/c/string_tuple.h | 188 +++++++++++++++++++++++++++++++++++ level_0/f_string/data/build/settings | 2 +- 6 files changed, 198 insertions(+), 6 deletions(-) create mode 100644 level_0/f_string/c/string_tuple.h diff --git a/build/level_0/settings b/build/level_0/settings index d3abb0a..1882cdb 100644 --- a/build/level_0/settings +++ b/build/level_0/settings @@ -22,7 +22,7 @@ build_libraries -lc build_libraries-level build_sources_library account.c console.c conversion.c directory.c private-directory.c environment.c private-environment.c file.c private-file.c fss.c iki.c private-iki.c memory.c path.c private-path.c pipe.c print.c private-print.c process.c serialize.c private-serialize.c signal.c socket.c utf.c private-utf.c build_sources_program -build_sources_headers account.h account-common.h color.h console.h console-common.h conversion.h conversion-common.h directory.h directory_type.h directory-common.h environment.h environment-common.h file.h file-common.h fss.h fss-common.h fss_comment.h fss_delimit.h fss_named.h fss_nest.h fss_quote.h fss_set.h iki.h iki-common.h memory.h memory_structure.h path.h path-common.h pipe.h print.h process.h process-common.h serialize.h serialize-common.h signal.h signal-common.h socket.h socket-common.h status.h status_array.h string.h string-common.h string_dynamic.h string_map.h string_quantity.h string_range.h type.h type_array.h utf.h utf-common.h +build_sources_headers account.h account-common.h color.h console.h console-common.h conversion.h conversion-common.h directory.h directory_type.h directory-common.h environment.h environment-common.h file.h file-common.h fss.h fss-common.h fss_comment.h fss_delimit.h fss_named.h fss_nest.h fss_quote.h fss_set.h iki.h iki-common.h memory.h memory_structure.h path.h path-common.h pipe.h print.h process.h process-common.h serialize.h serialize-common.h signal.h signal-common.h socket.h socket-common.h status.h status_array.h string.h string-common.h string_dynamic.h string_map.h string_quantity.h string_range.h string_tuple.h type.h type_array.h utf.h utf-common.h build_sources_script build_sources_setting build_script yes diff --git a/build/monolithic/settings b/build/monolithic/settings index 60966d5..5709ada 100644 --- a/build/monolithic/settings +++ b/build/monolithic/settings @@ -22,7 +22,7 @@ build_libraries -lc build_libraries-monolithic build_sources_library level_0/account.c level_0/console.c level_0/conversion.c level_0/directory.c level_0/private-directory.c level_0/environment.c level_0/private-environment.c level_0/file.c level_0/private-file.c level_0/fss.c level_0/iki.c level_0/private-iki.c level_0/memory.c level_0/path.c level_0/private-path.c level_0/pipe.c level_0/print.c level_0/private-print.c level_0/process.c level_0/serialize.c level_0/private-serialize.c level_0/signal.c level_0/socket.c level_0/utf.c level_0/private-utf.c level_1/color.c level_1/console.c level_1/conversion.c level_1/directory.c level_1/private-directory.c level_1/environment.c level_1/private-fss.c level_1/fss_basic.c level_1/fss_basic_list.c level_1/fss_embedded_list.c level_1/fss_extended.c level_1/fss_extended_list.c level_1/iki.c level_1/print.c level_1/private-print.c level_1/status.c level_1/string.c level_1/private-string.c level_1/type.c level_1/utf.c level_1/private-utf.c level_1/utf_file.c level_1/private-utf_file.c level_2/error.c level_2/private-error.c level_2/execute.c level_2/private-execute.c level_2/file.c level_2/private-file.c level_2/fss.c level_2/private-fss.c level_2/fss_basic.c level_2/fss_basic_list.c level_2/fss_embedded_list.c level_2/fss_extended.c level_2/fss_extended_list.c level_2/fss_status.c level_2/iki.c level_2/private-iki.c level_2/path.c level_2/program.c level_2/status.c build_sources_program -build_sources_headers level_0/account.h level_0/account-common.h level_0/color.h level_0/console.h level_0/console-common.h level_0/conversion.h level_0/conversion-common.h level_0/directory.h level_0/directory_type.h level_0/directory-common.h level_0/environment.h level_0/environment-common.h level_0/file.h level_0/file-common.h level_0/fss.h level_0/fss-common.h level_0/fss_comment.h level_0/fss_delimit.h level_0/fss_named.h level_0/fss_nest.h level_0/fss_quote.h level_0/fss_set.h level_0/iki.h level_0/iki-common.h level_0/memory.h level_0/memory_structure.h level_0/path.h level_0/path-common.h level_0/pipe.h level_0/print.h level_0/process.h level_0/process-common.h level_0/serialize.h level_0/serialize-common.h level_0/signal.h level_0/signal-common.h level_0/socket.h level_0/socket-common.h level_0/status.h level_0/status_array.h level_0/string.h level_0/string-common.h level_0/string_dynamic.h level_0/string_map.h level_0/string_quantity.h level_0/string_range.h level_0/type.h level_0/type_array.h level_0/utf.h level_0/utf-common.h level_1/color.h level_1/console.h level_1/conversion.h level_1/directory.h level_1/environment.h level_1/fss.h level_1/fss_basic.h level_1/fss_basic_list.h level_1/fss_embedded_list.h level_1/fss_extended.h level_1/fss_extended_list.h level_1/fss_macro.h level_1/fss_status.h level_1/iki.h level_1/print.h level_1/status.h level_1/string.h level_1/type.h level_1/utf.h level_1/utf_file.h level_2/error.h level_2/error-common.h level_2/execute.h level_2/file.h level_2/fss.h level_2/fss_basic.h level_2/fss_basic_list.h level_2/fss_embedded_list.h level_2/fss_extended.h level_2/fss_extended_list.h level_2/fss_status.h level_2/iki.h level_2/path.h level_2/program.h level_2/status.h +build_sources_headers level_0/account.h level_0/account-common.h level_0/color.h level_0/console.h level_0/console-common.h level_0/conversion.h level_0/conversion-common.h level_0/directory.h level_0/directory_type.h level_0/directory-common.h level_0/environment.h level_0/environment-common.h level_0/file.h level_0/file-common.h level_0/fss.h level_0/fss-common.h level_0/fss_comment.h level_0/fss_delimit.h level_0/fss_named.h level_0/fss_nest.h level_0/fss_quote.h level_0/fss_set.h level_0/iki.h level_0/iki-common.h level_0/memory.h level_0/memory_structure.h level_0/path.h level_0/path-common.h level_0/pipe.h level_0/print.h level_0/process.h level_0/process-common.h level_0/serialize.h level_0/serialize-common.h level_0/signal.h level_0/signal-common.h level_0/socket.h level_0/socket-common.h level_0/status.h level_0/status_array.h level_0/string.h level_0/string-common.h level_0/string_dynamic.h level_0/string_map.h level_0/string_quantity.h level_0/string_range.h level_0/string_tuple.h level_0/type.h level_0/type_array.h level_0/utf.h level_0/utf-common.h level_1/color.h level_1/console.h level_1/conversion.h level_1/directory.h level_1/environment.h level_1/fss.h level_1/fss_basic.h level_1/fss_basic_list.h level_1/fss_embedded_list.h level_1/fss_extended.h level_1/fss_extended_list.h level_1/fss_macro.h level_1/fss_status.h level_1/iki.h level_1/print.h level_1/status.h level_1/string.h level_1/type.h level_1/utf.h level_1/utf_file.h level_2/error.h level_2/error-common.h level_2/execute.h level_2/file.h level_2/fss.h level_2/fss_basic.h level_2/fss_basic_list.h level_2/fss_embedded_list.h level_2/fss_extended.h level_2/fss_extended_list.h level_2/fss_status.h level_2/iki.h level_2/path.h level_2/program.h level_2/status.h build_sources_script build_sources_setting build_script yes diff --git a/level_0/f_string/c/string.h b/level_0/f_string/c/string.h index eb5a4a2..fd7481a 100644 --- a/level_0/f_string/c/string.h +++ b/level_0/f_string/c/string.h @@ -27,6 +27,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { diff --git a/level_0/f_string/c/string_map.h b/level_0/f_string/c/string_map.h index b568125..aee9fba 100644 --- a/level_0/f_string/c/string_map.h +++ b/level_0/f_string/c/string_map.h @@ -31,9 +31,12 @@ extern "C" { #define f_string_map_t_initialize { f_string_dynamic_t_initialize, f_string_dynamic_t_initialize } #define f_macro_string_map_t_clear(map) \ - map.array = 0; \ - map.size = 0; \ - map.used = 0; + map.name.array = 0; \ + map.name.size = 0; \ + map.name.used = 0; \ + map.value.array = 0; \ + map.value.size = 0; \ + map.value.used = 0; #define f_macro_string_map_t_delete(status, map) \ f_macro_string_dynamic_t_delete(status, map.name) \ diff --git a/level_0/f_string/c/string_tuple.h b/level_0/f_string/c/string_tuple.h new file mode 100644 index 0000000..3ab94ff --- /dev/null +++ b/level_0/f_string/c/string_tuple.h @@ -0,0 +1,188 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.5 + * Licenses: lgplv2.1 + * + * Defines tuple string data. + * + * This is auto-included by string.h and should not need to be explicitly included. + */ +#ifndef _F_string_tuple_h +#define _F_string_tuple_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A string tuple consisting of a set of three strings. + * + * one: A string representing the first string in the tuple. + * two: A string representing the second string in the tuple. + * three: A string representing the third string in the tuple. + */ +#ifndef _di_f_string_tuple_t_ + typedef struct { + f_string_dynamic_t one; + f_string_dynamic_t two; + f_string_dynamic_t three; + } f_string_tuple_t; + + #define f_string_tuple_t_initialize { f_string_dynamic_t_initialize, f_string_dynamic_t_initialize, f_string_dynamic_t_initialize } + + #define f_macro_string_tuple_t_clear(tuple) \ + tuple.one.array = 0; \ + tuple.one.size = 0; \ + tuple.one.used = 0; \ + tuple.two.array = 0; \ + tuple.two.size = 0; \ + tuple.two.used = 0; \ + tuple.three.array = 0; \ + tuple.three.size = 0; \ + tuple.three.used = 0; + + #define f_macro_string_tuple_t_delete(status, tuple) \ + f_macro_string_dynamic_t_delete(status, tuple.one) \ + if (status == F_none) { \ + f_macro_string_dynamic_t_delete(status, tuple.two) \ + } \ + if (status == F_none) { \ + f_macro_string_dynamic_t_delete(status, tuple.three) \ + } + + #define f_macro_string_tuple_t_destroy(status, tuple) \ + f_macro_string_dynamic_t_destroy(status, tuple.one) \ + if (status == F_none) { \ + f_macro_string_dynamic_t_destroy(status, tuple.two) \ + } \ + if (status == F_none) { \ + f_macro_string_dynamic_t_destroy(status, tuple.three) \ + } + + #define f_macro_string_tuple_t_delete_simple(tuple) \ + f_macro_string_dynamic_t_delete_simple(tuple.one) \ + f_macro_string_dynamic_t_delete_simple(tuple.two) \ + f_macro_string_dynamic_t_delete_simple(tuple.three) + + #define f_macro_string_tuple_t_destroy_simple(tuple) \ + f_macro_string_dynamic_t_destroy_simple(tuple.one) \ + f_macro_string_dynamic_t_destroy_simple(tuple.two) \ + f_macro_string_dynamic_t_destroy_simple(tuple.three) +#endif // _di_f_string_tuple_t_ + +/** + * An array of string tuples. + * + * array: the array of string tuples. + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ +#ifndef _di_f_string_tuples_t_ + typedef struct { + f_string_tuple_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_string_tuples_t; + + #define f_string_tuples_t_initialize f_string_statics_t_initialize + + #define f_macro_string_tuples_t_clear(tuples) \ + tuples.array = 0; \ + tuples.size = 0; \ + tuples.used = 0; + + #define f_macro_string_tuples_t_new(status, tuples, length) \ + f_macro_string_tuples_t_clear(tuples) \ + status = f_memory_new((void **) & tuples.array, sizeof(f_string_tuple_t), length); \ + if (status == F_none) { \ + tuples.size = length; \ + tuples.used = 0; \ + } + + #define f_macro_string_tuples_t_delete(status, tuples) \ + status = F_none; \ + tuples.used = tuples.size; \ + while (tuples.used) { \ + tuples.used--; \ + f_macro_string_tuple_t_delete(status, tuples.array[tuples.used]); \ + if (status != F_none) break; \ + } \ + if (status == F_none) status = f_memory_delete((void **) & tuples.array, sizeof(f_string_tuple_t), tuples.size); \ + if (status == F_none) tuples.size = 0; + + #define f_macro_string_tuples_t_destroy(status, tuples) \ + status = F_none; \ + tuples.used = tuples.size; \ + while (tuples.used) { \ + tuples.used--; \ + f_macro_string_tuple_t_destroy(status, tuples.array[tuples.used]); \ + if (status != F_none) break; \ + } \ + if (status == F_none) status = f_memory_destroy((void **) & tuples.array, sizeof(f_string_tuple_t), tuples.size); \ + if (status == F_none) tuples.size = 0; + + #define f_macro_string_tuples_t_delete_simple(tuples) \ + tuples.used = tuples.size; \ + while (tuples.used) { \ + tuples.used--; \ + f_macro_string_tuple_t_delete_simple(tuples.array[tuples.used]); \ + } \ + f_memory_delete((void **) & tuples.array, sizeof(f_string_tuple_t), tuples.size); \ + tuples.size = 0; + + #define f_macro_string_tuples_t_destroy_simple(tuples) \ + tuples.used = tuples.size; \ + while (tuples.used) { \ + tuples.used--; \ + f_macro_string_tuple_t_destroy_simple(tuples.array[tuples.used]); \ + } \ + f_memory_destroy((void **) & tuples.array, sizeof(f_string_tuple_t), tuples.size); \ + tuples.size = 0; + + #define f_macro_string_tuples_t_resize(status, tuples, new_length) \ + status = F_none; \ + if (new_length < tuples.size) { \ + for (f_array_length_t _macro__i = tuples.size - new_length; _macro__i < tuples.size; _macro__i++) { \ + f_macro_string_tuple_t_delete(status, tuples.array[_macro__i]); \ + if (status != F_none) break; \ + } \ + } \ + if (status == F_none) status = f_memory_resize((void **) & tuples.array, sizeof(f_string_tuple_t), tuples.size, new_length); \ + if (status == F_none) { \ + if (new_length > tuples.size) { \ + for (f_array_length_t _macro__i = tuples.size; _macro__i < new_length; _macro__i++) { \ + memset(&tuples.array[_macro__i], 0, sizeof(f_string_tuple_t)); \ + } \ + } \ + tuples.size = new_length; \ + if (tuples.used > tuples.size) tuples.used = new_length; \ + } + + #define f_macro_string_tuples_t_adjust(status, tuples, new_length) \ + status = F_none; \ + if (new_length < tuples.size) { \ + for (f_array_length_t _macro__i = tuples.size - new_length; _macro__i < tuples.size; _macro__i++) { \ + f_macro_string_tuple_t_destroy(status, tuples.array[_macro__i], f_string_tuple_t); \ + if (status != F_none) break; \ + } \ + } \ + if (status == F_none) status = f_memory_adjust((void **) & tuples.array, sizeof(f_string_tuple_t), tuples.size, new_length); \ + if (status == F_none) { \ + if (new_length > tuples.size) { \ + for (f_array_length_t _macro__i = tuples.size; _macro__i < new_length; _macro__i++) { \ + memset(&tuples.array[_macro__i], 0, sizeof(f_string_tuple_t)); \ + } \ + } \ + tuples.size = new_length; \ + if (tuples.used > tuples.size) tuples.used = new_length; \ + } +#endif // _di_f_string_tuples_t_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_string_tuple_h diff --git a/level_0/f_string/data/build/settings b/level_0/f_string/data/build/settings index 1e91f5d..550aa58 100644 --- a/level_0/f_string/data/build/settings +++ b/level_0/f_string/data/build/settings @@ -22,7 +22,7 @@ build_libraries -lc build_libraries-individual -lf_memory build_sources_library build_sources_program -build_sources_headers string.h string-common.h string_dynamic.h string_map.h string_quantity.h string_range.h +build_sources_headers string.h string-common.h string_dynamic.h string_map.h string_quantity.h string_range.h string_tuple.h build_sources_script build_sources_setting build_script yes -- 1.8.3.1