From: Kevin Day Date: Sun, 21 Jun 2020 01:03:42 +0000 (-0500) Subject: Progress: organize headers, simplify fss structures, initial IKI support X-Git-Tag: 0.5.0~145 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=6b530cab38da1aac458f5496d9b377df2f036e03;p=fll Progress: organize headers, simplify fss structures, initial IKI support Move more headers into the secondary structures to simplify the main header, which will now more often be just for function definitions. The FSS structures can use a more common base to better allow integration with separate projects that utilize the same basic design. This is important for IKI project. Casting to/from fss objects and contents to their respective ranges should now be possible. Begin adding the IKI support, which is a new FSS standard focused on a simpler/smaller Wiki design. The goal is not to handle presentation but instead to provide very simple context on certain text blocks based on some vocabulary. A very common example would be sending a plain text e-mail with a URL in it, the URL could be encapsulated in an IKI vocabulary object to tell both the human and the computer that this is a URL. For a URL, this is very useful in that no part of the URL need be escaped, except for the closing quote and its respective delimiter. Example iki URL: url:"http://www.example.com/this does not exist/". As opposed to http://www.example.com/this%20does%20not%20exist/. The first case is easier for a human while still remaining simple enough for a machine. The IKI syntax, at least in its most basic form, is not meant to be a full WIKI formatter. While this may be accomplished with a sufficiently large enough vocabulary, this seems unnecessary at this time. The IKI syntax standard itself is yet to be ironed out and ill be updated overtime until I am satisfied. --- diff --git a/build/level_0/settings b/build/level_0/settings index 37fa8e7..0016f9e 100644 --- a/build/level_0/settings +++ b/build/level_0/settings @@ -20,9 +20,9 @@ build_language c build_linker ar build_libraries -lc build_libraries-level -build_sources_library console.c conversion.c directory.c private-directory.c environment.c private-environment.c file.c private-file.c fss.c memory.c path.c pipe.c print.c serialize.c private-serialize.c socket.c utf.c private-utf.c +build_sources_library console.c conversion.c directory.c private-directory.c environment.c private-environment.c file.c private-file.c fss.c iki.c memory.c path.c pipe.c print.c serialize.c private-serialize.c socket.c utf.c private-utf.c build_sources_program -build_sources_headers color.h console.h conversion.h directory.h directory_type.h environment.h file.h fss.h fss-common.h fss-named.h fss-nest.h fss-set.h memory.h path.h pipe.h print.h serialize.h socket.h status.h status_array.h string.h type.h type_array.h utf.h utf-common.h +build_sources_headers color.h console.h conversion.h directory.h directory_type.h environment.h file.h fss.h fss-common.h fss-named.h fss-nest.h fss-set.h iki.h iki-common.h iki-common.h memory.h memory-structure.h path.h pipe.h print.h serialize.h socket.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_script build_sources_setting build_script yes diff --git a/build/monolithic/settings b/build/monolithic/settings index f119b30..341ff3c 100644 --- a/build/monolithic/settings +++ b/build/monolithic/settings @@ -20,9 +20,9 @@ build_language c build_linker ar build_libraries -lc build_libraries-monolithic -build_sources_library 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/memory.c level_0/path.c level_0/pipe.c level_0/print.c level_0/serialize.c level_0/private-serialize.c level_0/socket.c level_0/utf.c level_0/private-utf.c level_1/color.c level_1/console.c level_1/directory.c level_1/private-directory.c level_1/fss.c level_1/private-fss.c level_1/fss_basic.c level_1/fss_basic_list.c level_1/fss_extended.c level_1/fss_extended_list.c level_1/print.c level_1/status.c level_1/string.c level_1/private-string.c level_1/utf.c level_1/private-utf.c level_1/utf_file.c level_1/private-utf_file.c level_2/execute.c level_2/private-execute.c level_2/file.c level_2/fss.c level_2/fss_basic.c level_2/fss_basic_list.c level_2/fss_extended.c level_2/fss_extended_list.c level_2/fss_status.c level_2/program.c level_2/status.c +build_sources_library 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/memory.c level_0/path.c level_0/pipe.c level_0/print.c level_0/serialize.c level_0/private-serialize.c level_0/socket.c level_0/utf.c level_0/private-utf.c level_1/color.c level_1/console.c level_1/directory.c level_1/private-directory.c level_1/fss.c level_1/private-fss.c level_1/fss_basic.c level_1/fss_basic_list.c level_1/fss_extended.c level_1/fss_extended_list.c level_1/print.c level_1/status.c level_1/string.c level_1/private-string.c level_1/utf.c level_1/private-utf.c level_1/utf_file.c level_1/private-utf_file.c level_2/execute.c level_2/private-execute.c level_2/file.c level_2/fss.c level_2/fss_basic.c level_2/fss_basic_list.c level_2/fss_extended.c level_2/fss_extended_list.c level_2/fss_status.c level_2/program.c level_2/status.c build_sources_program -build_sources_headers level_0/color.h level_0/console.h level_0/conversion.h level_0/directory.h level_0/directory_type.h level_0/environment.h level_0/file.h level_0/fss.h level_0/fss-common.h level_0/fss-named.h level_0/fss-nest.h level_0/fss-set.h level_0/memory.h level_0/path.h level_0/pipe.h level_0/print.h level_0/serialize.h level_0/socket.h level_0/status.h level_0/status_array.h level_0/string.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/directory.h level_1/fss.h level_1/fss_basic.h level_1/fss_basic_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/print.h level_1/status.h level_1/string.h level_1/utf.h level_1/utf_file.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_extended.h level_2/fss_extended_list.h level_2/fss_status.h level_2/program.h level_2/status.h +build_sources_headers level_0/color.h level_0/console.h level_0/conversion.h level_0/directory.h level_0/directory_type.h level_0/environment.h level_0/file.h level_0/fss.h level_0/fss-common.h level_0/fss-named.h level_0/fss-nest.h level_0/fss-set.h level_0/iki.h level_0/iki-common.h level_0/iki-common.h level_0/memory.h level_0/memory-structure.h level_0/path.h level_0/pipe.h level_0/print.h level_0/serialize.h level_0/socket.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/directory.h level_1/fss.h level_1/fss_basic.h level_1/fss_basic_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/print.h level_1/status.h level_1/string.h level_1/utf.h level_1/utf_file.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_extended.h level_2/fss_extended_list.h level_2/fss_status.h level_2/program.h level_2/status.h build_sources_script build_sources_setting build_script yes diff --git a/documents/todo.txt b/documents/todo.txt index 22b0322..e1f86f6 100644 --- a/documents/todo.txt +++ b/documents/todo.txt @@ -79,25 +79,6 @@ This file contains FLL-wide todo notes. Variable name will be made uppercase and will be only alphabetic or underscore. -A new wiki-like syntax meant to be simpler: - - url:"http:// a b c/" - - code:" code goes here" - - quote:"This is a quote" - - var:"some_variable_name" - - emphasis:"This text is important" - - Escaping only neds to be done like these two cases: - 1) escaping main syntax: - - url\:"http:// a b c/" - - after the first '\:', every '\' is a literal '\'. - - url\\\\\:"http:// a b c/" would be read as: 'url\\\\:"http:// a b c/"'. - 2) escaping the quoted part - - quote:"This is a \"quote\"" - - There is no way to know the terminating '"' so all quotes inside must be escaped. - - after the first '\"', every '\' is a literal '\'. - - quote:"" would be read as: 'url\\\\:"http:// a b c/"'. - - Create this as a new FSS format, FSS-Text (FSS-000D). - Go though all source code and ensure that, for all non-exceptional cases, any dynamic strings appends to existing buffers instead of overwriting them (based on buffer->used). Then document this behavior. diff --git a/level_0/f_fss/c/fss-common.h b/level_0/f_fss/c/fss-common.h index 3a14f1c..1589329 100644 --- a/level_0/f_fss/c/fss-common.h +++ b/level_0/f_fss/c/fss-common.h @@ -122,6 +122,8 @@ extern "C" { /** * Stores information about a particular fss file, otherwise known as its header. * + * @todo change this to use a range instead if a length to support multiple sub-headers. + * * type: the kind of fss file is this. * length: Total length of the header. */ @@ -166,9 +168,8 @@ extern "C" { #define f_macro_fss_headers_adjust(status, headers, new_length) f_macro_memory_structure_adjust(status, headers, f_fss_header, new_length) #endif // _di_f_fss_headers_ - /** - * This is a location that represents an object. + * This is a range that represents an object. */ #ifndef _di_fss_object_ typedef f_string_range f_fss_object; @@ -186,62 +187,50 @@ extern "C" { * used: Total number of allocated spaces used. */ #ifndef _di_fss_objects_ - typedef struct { - f_fss_object *array; - - f_string_length size; - f_string_length used; - } f_fss_objects; + typedef f_string_ranges f_fss_objects; - #define f_fss_objects_initialize { 0, 0, 0 } + #define f_fss_objects_initialize f_string_ranges_initialize - #define f_macro_fss_objects_clear(objects) f_macro_memory_structure_clear(objects) + #define f_macro_fss_objects_clear(objects) f_macro_string_ranges_clear(objects) - #define f_macro_fss_objects_new(status, objects, length) f_macro_memory_structure_new(status, objects, f_fss_object, length) + #define f_macro_fss_objects_new(status, objects, length) f_macro_string_ranges_new(status, objects, length) - #define f_macro_fss_objects_delete(status, objects) f_macro_memory_structure_delete(status, objects, f_fss_object) - #define f_macro_fss_objects_destroy(status, objects) f_macro_memory_structure_destroy(status, objects, f_fss_object) + #define f_macro_fss_objects_delete(status, objects) f_macro_string_ranges_delete(status, objects) + #define f_macro_fss_objects_destroy(status, objects) f_macro_string_ranges_destroy(status, objects) - #define f_macro_fss_objects_delete_simple(objects) f_macro_memory_structure_delete_simple(objects, f_fss_object) - #define f_macro_fss_objects_destroy_simple(objects) f_macro_memory_structure_destroy_simple(objects, f_fss_object) + #define f_macro_fss_objects_delete_simple(objects) f_macro_string_ranges_delete_simple(objects) + #define f_macro_fss_objects_destroy_simple(objects) f_macro_string_ranges_destroy_simple(objects) - #define f_macro_fss_objects_resize(status, objects, new_length) f_macro_memory_structure_resize(status, objects, f_fss_object, new_length) - #define f_macro_fss_objects_adjust(status, objects, new_length) f_macro_memory_structure_destroy(status, objects, f_fss_object, new_length) + #define f_macro_fss_objects_resize(status, objects, new_length) f_macro_string_ranges_resize(status, objects, new_length) + #define f_macro_fss_objects_adjust(status, objects, new_length) f_macro_string_ranges_destroy(status, objects, new_length) #endif // _di_fss_objects_ /** - * This holds an array of string locations that represent the content. + * This holds an array of string ranges that represent the content. * - * The very first string location will represent the outermost content. - * All of the following string locations will represent the first level of nesting of all sub-content. - * There will be no nesting beyond the first level recorded in this structure. + * The very first string range will represent the first content found. * * array: The array of content. * size: Total amount of allocated space. * used: Total number of allocated spaces used. */ #ifndef _di_fss_content_ - typedef struct { - f_string_range *array; - - f_array_length size; - f_array_length used; - } f_fss_content; + typedef f_string_ranges f_fss_content; - #define f_fss_content_initialize { 0, 0, 0 } + #define f_fss_content_initialize f_string_ranges_initialize - #define f_macro_fss_content_clear(content) f_macro_memory_structure_new(content) + #define f_macro_fss_content_clear(content) f_macro_string_ranges_clear(content) - #define f_macro_fss_content_new(status, content, length) f_macro_memory_structure_new(status, content, f_string_range, length) + #define f_macro_fss_content_new(status, content, length) f_macro_string_ranges_new(status, content, length) - #define f_macro_fss_content_delete(status, content) f_macro_memory_structure_delete(status, content, f_string_range) - #define f_macro_fss_content_destroy(status, content) f_macro_memory_structure_destroy(status, content, f_string_range) + #define f_macro_fss_content_delete(status, content) f_macro_string_ranges_delete(status, content) + #define f_macro_fss_content_destroy(status, content) f_macro_string_ranges_destroy(status, content) - #define f_macro_fss_content_delete_simple(content) f_macro_memory_structure_delete_simple(content, f_string_range) - #define f_macro_fss_content_destroy_simple(content) f_macro_memory_structure_destroy_simple(content, f_string_range) + #define f_macro_fss_content_delete_simple(content) f_macro_string_ranges_delete_simple(content) + #define f_macro_fss_content_destroy_simple(content) f_macro_string_ranges_destroy_simple(content) - #define f_macro_fss_content_resize(status, content, new_length) f_macro_memory_structure_resize(status, content, f_string_range, new_length) - #define f_macro_fss_content_adjust(status, content, new_length) f_macro_memory_structure_adjust(status, content, f_string_range, new_length) + #define f_macro_fss_content_resize(status, content, new_length) f_macro_string_ranges_resize(status, content, new_length) + #define f_macro_fss_content_adjust(status, content, new_length) f_macro_string_ranges_adjust(status, content, new_length) #endif // _di_fss_content_ /** @@ -252,27 +241,22 @@ extern "C" { * used: Total number of allocated spaces used. */ #ifndef _di_f_fss_contents_ - typedef struct { - f_fss_content *array; - - f_array_length size; - f_array_length used; - } f_fss_contents; + typedef f_string_rangess f_fss_contents; - #define f_fss_contents_initialize { 0, 0, 0 } + #define f_fss_contents_initialize f_string_rangess_initialize - #define f_macro_fss_contents_clear(contents) f_macro_memory_structures_clear(contents) + #define f_macro_fss_contents_clear(contents) f_macro_string_rangess_clear(contents) - #define f_macro_fss_contents_new(status, contents, length) f_macro_memory_structures_delete(status, contents, f_fss_content, length) + #define f_macro_fss_contents_new(status, contents, length) f_macro_string_rangess_new(status, contents, length) - #define f_macro_fss_contents_delete(status, contents) f_macro_memory_structures_delete(status, contents, f_fss_content) - #define f_macro_fss_contents_destroy(status, contents) f_macro_memory_structures_destroy(status, contents, f_fss_content) + #define f_macro_fss_contents_delete(status, contents) f_macro_string_rangess_delete(status, contents) + #define f_macro_fss_contents_destroy(status, contents) f_macro_string_rangess_destroy(status, contents) - #define f_macro_fss_contents_delete_simple(contents) f_macro_memory_structures_delete_simple(contents, f_fss_content) - #define f_macro_fss_contents_destroy_simple(contents) f_macro_memory_structures_destroy_simple(contents, f_fss_content) + #define f_macro_fss_contents_delete_simple(contents) f_macro_string_rangess_delete_simple(contents) + #define f_macro_fss_contents_destroy_simple(contents) f_macro_string_rangess_destroy_simple(contents) - #define f_macro_fss_contents_resize(status, contents, new_length) f_macro_memory_structures_resize(status, contents, f_fss_content, new_length, f_array_length) - #define f_macro_fss_contents_adjust(status, contents, new_length) f_macro_memory_structures_resize(status, contents, f_fss_content, new_length, f_array_length) + #define f_macro_fss_contents_resize(status, contents, new_length) f_macro_string_rangess_resize(status, contents, new_length) + #define f_macro_fss_contents_adjust(status, contents, new_length) f_macro_string_rangess_adjust(status, contents, new_length) #endif // _di_f_fss_contents_ #ifdef __cplusplus diff --git a/level_0/f_fss/c/fss-named.h b/level_0/f_fss/c/fss-named.h index aa9c142..ee97308 100644 --- a/level_0/f_fss/c/fss-named.h +++ b/level_0/f_fss/c/fss-named.h @@ -74,9 +74,9 @@ extern "C" { } #define f_macro_fss_named_adjust(status, set, new_length) \ - f_macro_fss_objects_resize(status, set.objects, new_length) \ + f_macro_fss_objects_adjust(status, set.objects, new_length) \ if (F_status_is_fine(status)) { \ - f_macro_fss_contents_resize(status, set.contents, new_length) \ + f_macro_fss_contents_adjust(status, set.contents, new_length) \ } #endif // _di_f_fss_named_ diff --git a/level_0/f_iki/c/iki-common.h b/level_0/f_iki/c/iki-common.h new file mode 100644 index 0000000..e3ab6ef --- /dev/null +++ b/level_0/f_iki/c/iki-common.h @@ -0,0 +1,162 @@ +/** + * FLL - Level 0 + * + * Project: Iki + * API Version: 0.5 + * Licenses: lgplv2.1 + * + * Defines iki common data. + * + * This is auto-included by iki.h and should not need to be explicitly included. + */ +#ifndef _F_iki_h +#define _F_iki_h + +// libc includes +#include +#include + +// fll-0 includes +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_iki_vocabulary_0000_ + #define iki_vocabulary_0000_emphasis "emphasis" + #define iki_vocabulary_0000_code "code" + #define iki_vocabulary_0000_quote "quote" + #define iki_vocabulary_0000_uri "uri" + #define iki_vocabulary_0000_url "url" + #define iki_vocabulary_0000_urn "urn" + #define iki_vocabulary_0000_variable "var" + + #define iki_vocabulary_0000_emphasis_length 8 + #define iki_vocabulary_0000_code_length 4 + #define iki_vocabulary_0000_quote_length 5 + #define iki_vocabulary_0000_uri_length 3 + #define iki_vocabulary_0000_url_length 3 + #define iki_vocabulary_0000_urn_length 3 + #define iki_vocabulary_0000_variable_length 3 +#endif // _di_iki_vocabulary_0000_ + +#ifndef _di_iki_vocabulary_0001_ + #define iki_vocabulary_0001_variable "var" + + #define iki_vocabulary_0001_variable_length 3 +#endif // _di_iki_vocabulary_0001_ + +/** + * This holds an array of string ranges that represent the vocabulary names. + * + * array: The array of vocabulary names. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_iki_vocabulary_ + typedef f_string_ranges f_iki_vocabulary; + + #define f_iki_vocabulary_initialize f_string_ranges_initialize + + #define f_macro_iki_vocabulary_clear(vocabulary) f_macro_string_ranges_clear(vocabulary) + + #define f_macro_iki_vocabulary_new(status, vocabulary, length) f_macro_string_ranges_new(status, vocabulary, length) + + #define f_macro_iki_vocabulary_delete(status, vocabulary) f_macro_string_ranges_delete(status, vocabulary) + #define f_macro_iki_vocabulary_destroy(status, vocabulary) f_macro_string_ranges_destroy(status, vocabulary) + + #define f_macro_iki_vocabulary_delete_simple(vocabulary) f_macro_string_ranges_delete_simple(vocabulary) + #define f_macro_iki_vocabulary_destroy_simple(vocabulary) f_macro_string_ranges_destroy_simple(vocabulary) + + #define f_macro_iki_vocabulary_resize(status, vocabulary, new_length) f_macro_string_ranges_resize(status, vocabulary, new_length) + #define f_macro_iki_vocabulary_adjust(status, vocabulary, new_length) f_macro_string_ranges_destroy(status, vocabulary, new_length) +#endif // _di_iki_vocabulary_ + +/** + * This holds an array of f_iki_vocabulary. + * + * array: The array of content. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_iki_vocabularys_ + typedef f_string_rangess f_iki_vocabularys; + + #define f_iki_vocabularys_initialize f_string_rangess_initialize + + #define f_macro_iki_vocabularys_clear(content) f_macro_string_rangess_clear(content) + + #define f_macro_iki_vocabularys_new(status, content, length) f_macro_string_rangess_new(status, content, length) + + #define f_macro_iki_vocabularys_delete(status, content) f_macro_string_rangess_delete(status, content) + #define f_macro_iki_vocabularys_destroy(status, content) f_macro_string_rangess_destroy(status, content) + + #define f_macro_iki_vocabularys_delete_simple(content) f_macro_string_rangess_delete_simple(content) + #define f_macro_iki_vocabularys_destroy_simple(content) f_macro_string_rangess_destroy_simple(content) + + #define f_macro_iki_vocabularys_resize(status, content, new_length) f_macro_string_rangess_resize(status, content, new_length) + #define f_macro_iki_vocabularys_adjust(status, content, new_length) f_macro_string_rangess_adjust(status, content, new_length) +#endif // _di_iki_vocabularys_ + +/** + * This holds an array of string ranges that represent the content. + * + * The very first string range will represent the first content found. + * + * array: The array of content. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_iki_content_ + typedef f_string_ranges f_iki_content; + + #define f_iki_content_initialize f_string_ranges_initialize + + #define f_macro_iki_content_clear(content) f_macro_string_ranges_clear(content) + + #define f_macro_iki_content_new(status, content, length) f_macro_string_ranges_new(status, content, length) + + #define f_macro_iki_content_delete(status, content) f_macro_string_ranges_delete(status, content) + #define f_macro_iki_content_destroy(status, content) f_macro_string_ranges_destroy(status, content) + + #define f_macro_iki_content_delete_simple(content) f_macro_string_ranges_delete_simple(content) + #define f_macro_iki_content_destroy_simple(content) f_macro_string_ranges_destroy_simple(content) + + #define f_macro_iki_content_resize(status, content, new_length) f_macro_string_ranges_resize(status, content, new_length) + #define f_macro_iki_content_adjust(status, content, new_length) f_macro_string_ranges_adjust(status, content, new_length) +#endif // _di_iki_content_ + +/** + * This holds an array of f_iki_content. + * + * array: The array of content. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_iki_contents_ + typedef f_string_rangess f_iki_contents; + + #define f_iki_contents_initialize f_string_rangess_initialize + + #define f_macro_iki_contents_clear(content) f_macro_string_rangess_clear(content) + + #define f_macro_iki_contents_new(status, content, length) f_macro_string_rangess_new(status, content, length) + + #define f_macro_iki_contents_delete(status, content) f_macro_string_rangess_delete(status, content) + #define f_macro_iki_contents_destroy(status, content) f_macro_string_rangess_destroy(status, content) + + #define f_macro_iki_contents_delete_simple(content) f_macro_string_rangess_delete_simple(content) + #define f_macro_iki_contents_destroy_simple(content) f_macro_string_rangess_destroy_simple(content) + + #define f_macro_iki_contents_resize(status, content, new_length) f_macro_string_rangess_resize(status, content, new_length) + #define f_macro_iki_contents_adjust(status, content, new_length) f_macro_string_rangess_adjust(status, content, new_length) +#endif // _di_iki_contents_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_iki_h diff --git a/level_0/f_iki/c/iki.c b/level_0/f_iki/c/iki.c new file mode 100644 index 0000000..cbd140c --- /dev/null +++ b/level_0/f_iki/c/iki.c @@ -0,0 +1,10 @@ +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_iki/c/iki.h b/level_0/f_iki/c/iki.h new file mode 100644 index 0000000..5d3629f --- /dev/null +++ b/level_0/f_iki/c/iki.h @@ -0,0 +1,71 @@ +/** + * FLL - Level 0 + * + * Project: Iki + * API Version: 0.5 + * Licenses: lgplv2.1 + * + * Provides a Wiki-Like syntax meant to be much simpler. + * + * This simpler Wiki-Like syntax, called Iki, focuses just on simply adding context. + * The context itself is not explicitly define but a few common standards are provided. + * + * The example syntax: + * - url:"http:// a b c/" + * - code:" code goes here" + * - quote:"This is a quote" + * - var:"some_variable_name" + * - emphasis:"This text is important" + * + * Which is: (word character, no whitespace, '-', '_', and '+')(colon ':')(quote, either single (') or double ("))(anything goes and closing quotes must be escaped)(closing quote, must match openening quote) + * + * Escaping only needs to be done like these three cases: + * 1) escaping main syntax: + * - url\:"http:// a b c/" + * - after the first '\:', every '\' is a literal '\'. + * - url\\\\\:"http:// a b c/" would be read as: 'url\\\\:"http:// a b c/"'. + * 2) escaping the quoted part, but only for the closing quote that matches the opening quote: + * - quote:"This is a \"quote\"" + * - There is no way to know the terminating quote so all quotes matching the opening quote inside must be escaped. + * - emphasis:"\"This is some Text with a slash before quote: \\\"" would be read as: emphasis, with value: "This is some Text with a slash before quote: \". + * - Create this as a new FSS format, FSS-Text (FSS-000D). + * + * IKI-0000 (Basic) provides the following vocabulary: + * - emphasis: Providing emphasis on text, such as bold. + * - code: Representing code (formatting preserved or otherwise presented literally). + * - quote: Representing quoted text. + * - uri: Representing a URI (This is a superset of URL and URN). + * - url: Representing a URL. + * - urn: Representing a URN. + * - var: Representing a variable name. + * + * IKI-0001 (Variable) provides the following vocabulary: + * - var: Representing a variable name. + * + * This is intended to also be used by FSS-Iki_Text (FSS-000D), which focuses on the format and not the context. + * Wherease, IKI-0000 (Basic) represents the vocabulary and its respective context. + * Therefore an FSS-000D may have any IKI-???? format within it. + * + * A format header such as "# fss-000d iki-0001\n" would represent an IKI format of IKI-0001 (Variable). + */ +#ifndef _F_iki_h +#define _F_iki_h + +// libc includes +#include +#include + +// fll-0 includes +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_iki_h diff --git a/level_0/f_iki/data/build/defines b/level_0/f_iki/data/build/defines new file mode 100644 index 0000000..c665317 --- /dev/null +++ b/level_0/f_iki/data/build/defines @@ -0,0 +1,2 @@ +# fss-0000 + diff --git a/level_0/f_iki/data/build/dependencies b/level_0/f_iki/data/build/dependencies new file mode 100644 index 0000000..13b45c7 --- /dev/null +++ b/level_0/f_iki/data/build/dependencies @@ -0,0 +1,5 @@ +f_type +f_status +f_memory +f_string +f_utf diff --git a/level_0/f_iki/data/build/settings b/level_0/f_iki/data/build/settings new file mode 100644 index 0000000..570317e --- /dev/null +++ b/level_0/f_iki/data/build/settings @@ -0,0 +1,52 @@ +# fss-0001 + +project_name f_iki + +version_major 0 +version_minor 5 +version_micro 0 +version_target major + +environment + +process_pre +process_post + +modes individual +modes_default individual + +build_compiler gcc +build_language c +build_linker ar +build_libraries -lc +build_libraries-individual -lf_utf -lf_memory +build_sources_library iki.c +build_sources_program +build_sources_headers iki.h iki-common.h +build_sources_script +build_sources_setting +build_script yes +build_shared yes +build_static yes + +path_headers level_0 +path_library_script script +path_library_shared shared +path_library_static static +path_program_script script +path_program_shared shared +path_program_static static + +search_exclusive yes +search_shared yes +search_static yes + +defines_all +defines_static +defines_shared + +flags_all -z now -g +flags_shared +flags_static +flags_library -fPIC +flags_program -fPIE diff --git a/level_0/f_memory/c/memory-structure.h b/level_0/f_memory/c/memory-structure.h new file mode 100644 index 0000000..d8a583f --- /dev/null +++ b/level_0/f_memory/c/memory-structure.h @@ -0,0 +1,335 @@ +/** + * FLL - Level 0 + * + * Project: Memory + * API Version: 0.5 + * Licenses: lgplv2.1 + * + * Defines memory structure data. + * + * This is auto-included by memory.h and should not need to be explicitly included. + */ +#ifndef _F_memory_structure_h +#define _F_memory_structure_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Reset a generic memory stucture to 0 (clear all values). + * + * This does not deallocate memory, be certain that memory is not allocated before calling this to avoid potential memory leaks. + * + * structure: the structure to operate on. + */ +#ifndef _di_f_macro_memory_structure_clear_ + #define f_macro_memory_structure_clear(structure) \ + structure.array = 0; \ + structure.size = 0; \ + structure.used = 0; +#endif // _di_f_macro_memory_structure_clear_ + +/** + * Create a new generic memory structure. + * + * This does not deallocate memory, be certain that memory is not allocated before calling this to avoid potential memory leaks. + * + * status: the status to return. + * structure: the structure to operate on. + * type: the structure type. + * length: the new size of the array. + */ +#ifndef _di_f_macro_memory_structure_new_ + #define f_macro_memory_structure_new(status, structure, type, length) \ + f_macro_memory_structure_clear(structure) \ + status = f_memory_new((void **) & structure.array, sizeof(type), length); \ + if (status == F_none) { \ + structure.size = length; \ + structure.used = 0; \ + } +#endif // _di_f_macro_memory_structure_new_ + +/** + * Delete a generic memory structure. + * + * status: the status to return. + * structure: the structure to operate on. + * type: the structure type. + */ +#ifndef _di_f_macro_memory_structure_delete_ + #define f_macro_memory_structure_delete(status, structure, type) \ + status = f_memory_delete((void **) & structure.array, sizeof(type), structure.size); \ + if (status == F_none) { \ + structure.size = 0; \ + structure.used = 0; \ + } +#endif // _di_f_macro_memory_structure_delete_ + +/** + * Destroy a generic memory structure. + * + * status: the status to return. + * structure: the structure to operate on. + * type: the structure type. + */ +#ifndef _di_f_macro_memory_structure_destroy_ + #define f_macro_memory_structure_destroy(status, structure, type) \ + status = f_memory_destroy((void **) & structure.array, sizeof(type), structure.size); \ + if (status == F_none) { \ + structure.size = 0; \ + structure.used = 0; \ + } +#endif // _di_f_macro_memory_structure_destroy_ + +/** + * Delete a generic memory structure. + * + * structure: the structure to operate on. + * type: the structure type. + */ +#ifndef _di_f_macro_memory_structure_delete_simple_ + #define f_macro_memory_structure_delete_simple(structure, type) \ + if (f_memory_delete((void **) & structure.array, sizeof(type), structure.size) == F_none) { \ + structure.size = 0; \ + structure.used = 0; \ + } +#endif // _di_f_macro_memory_structure_delete_simple_ + +/** + * Destroy a generic memory structure. + * + * structure: the structure to operate on. + * type: the structure type. + */ +#ifndef _di_f_macro_memory_structure_destroy_simple_ + #define f_macro_memory_structure_destroy_simple(structure, type) \ + if (f_memory_destroy((void **) & structure.array, sizeof(type), structure.size) == F_none) { \ + structure.size = 0; \ + structure.used = 0; \ + } +#endif // _di_f_macro_memory_structure_destroy_simple_ + +/** + * Resize a generic memory structure. + * + * status: the status to return. + * structure: the structure to operate on. + * type: the structure type. + * new_length: the new size of the array. + */ +#ifndef _di_f_macro_memory_structure_resize_ + #define f_macro_memory_structure_resize(status, structure, type, new_length) \ + status = f_memory_resize((void **) & structure.array, sizeof(type), structure.size, new_length); \ + if (status == F_none) { \ + structure.size = new_length; \ + if (structure.used > structure.size) structure.used = new_length; \ + } +#endif // _di_f_macro_memory_structure_resize_ + +/** + * Adjust a generic memory structure. + * + * status: the status to return. + * structure: the structure to operate on. + * type: the structure type. + * new_length: the new size of the array. + */ +#ifndef _di_f_macro_memory_structure_adjust_ + #define f_macro_memory_structure_adjust(status, structure, type, new_length) \ + status = f_memory_adjust((void **) & structure.array, sizeof(type), structure.size, new_length); \ + if (status == F_none) { \ + structure.size = new_length; \ + if (structure.used > structure.size) structure.used = new_length; \ + } +#endif // _di_f_macro_memory_structure_adjust_ + +/** + * Reset a generic memory stuctures to 0 (clear all values). + * + * This does not deallocate memory, be certain that memory is not allocated before calling this to avoid potential memory leaks. + * + * structures: the structures to operate on. + */ +#ifndef _di_f_macro_memory_structures_clear_ + #define f_macro_memory_structures_clear(structures) \ + structures.array = 0; \ + structures.size = 0; \ + structures.used = 0; +#endif // _di_f_macro_memory_structures_clear_ + +/** + * Create a new generic memory structures. + * + * This does not deallocate memory, be certain that memory is not allocated before calling this to avoid potential memory leaks. + * + * status: the status to return. + * structures: the structures to operate on. + * type_stuctures: the structure type. + * new_length: the new size of the array. + */ +#ifndef _di_f_macro_memory_structures_new_ + #define f_macro_memory_structures_new(status, structures, type_structures, new_length) \ + f_macro_memory_structures_clear(structures) \ + status = f_memory_new((void **) & structures.array, sizeof(type_structures), new_length); \ + if (status == F_none) { \ + structures.size = new_length; \ + structures.used = 0; \ + } +#endif // _di_f_macro_memory_structures_new_ + +/** + * Delete a generic memory structures. + * + * status: the status to return. + * structures: the structures to operate on. + * type_stucture: the structure type. + * type_stuctures: the structure type. + */ +#ifndef _di_f_macro_memory_structures_delete_ + #define f_macro_memory_structures_delete(status, structures, type_structure, type_structures) \ + status = F_none; \ + structures.used = structures.size; \ + while (structures.used > 0) { \ + structures.used--; \ + f_macro_memory_structure_delete(status, structures.array[structures.used], type_structure); \ + if (status != F_none) break; \ + } \ + if (status == F_none) status = f_memory_delete((void **) & structures.array, sizeof(type_structures), structures.size); \ + if (status == F_none) structures.size = 0; +#endif // _di_f_macro_memory_structures_delete_ + +/** + * Destroy a generic memory structures. + * + * status: the status to return. + * structures: the structures to operate on. + * type_stucture: the structure type. + * type_stuctures: the structure type. + */ +#ifndef _di_f_macro_memory_structures_destroy_ + #define f_macro_memory_structures_destroy(status, structures, type_structure, type_structures) \ + status = F_none; \ + structures.used = structures.size; \ + while (structures.used > 0) { \ + structures.used--; \ + f_macro_memory_structure_destroy(status, structures.array[structures.used], type_structure); \ + if (status != F_none) break; \ + } \ + if (status == F_none) status = f_memory_destroy((void **) & structures.array, sizeof(type_structures), structures.size); \ + if (status == F_none) structures.size = 0; +#endif // _di_f_macro_memory_structures_destroy_ + +/** + * Delete a generic memory structures. + * + * structures: the structures to operate on. + * type_stucture: the structure type. + * type_stuctures: the structure type. + */ +#ifndef _di_f_macro_memory_structures_delete_simple_ + #define f_macro_memory_structures_delete_simple(structures, type_structure, type_structures) \ + structures.used = structures.size; \ + while (structures.used > 0) { \ + structures.used--; \ + f_macro_memory_structure_delete_simple(structures.array[structures.used], type_structure); \ + } \ + if (structures.used == 0) { \ + if (f_memory_delete((void **) & structures.array, sizeof(type_structures), structures.size)) { \ + structures.size = 0; \ + } \ + } +#endif // _di_f_macro_memory_structures_delete_simple_ + +/** + * Destroy a generic memory structures. + * + * structures: the structures to operate on. + * type_stucture: the structure type. + * type_stuctures: the structure type. + */ +#ifndef _di_f_macro_memory_structures_destroy_simple_ + #define f_macro_memory_structures_destroy_simple(structures, type_structure, type_structures) \ + structures.used = structures.size; \ + while (structures.used > 0) { \ + structures.used--; \ + f_macro_memory_structure_destroy_simple(structures.array[structures.used], type_structure); \ + } \ + if (structures.used == 0) { \ + if (f_memory_destroy((void **) & structures.array, sizeof(type_structures), structures.size)) { \ + structures.size = 0; \ + } \ + } +#endif // _di_f_macro_memory_structures_destroy_simple_ + +/** + * Resize a generic memory structures. + * + * status: the status to return. + * structures: the structures to operate on. + * type_stucture: the structure type. + * type_stuctures: the structure type. + * new_length: the new size of the array. + * length_variable: the data type of the length variable. + */ +#ifndef _di_f_macro_memory_structures_resize_ + #define f_macro_memory_structures_resize(status, structures, type_structure, type_structures, new_length, length_variable) \ + status = F_none; \ + if (new_length < structures.size) { \ + length_variable i = structures.size - new_length; \ + for (; i < structures.size; i++) { \ + f_macro_memory_structure_delete(status, structures.array[i], type_structure); \ + if (status != F_none) break; \ + } \ + } \ + if (status == F_none) status = f_memory_resize((void **) & structures.array, sizeof(type_structures), structures.size, new_length); \ + if (status == F_none) { \ + if (new_length > structures.size) { \ + length_variable i = structures.size; \ + for (; i < new_length; i++) { \ + memset(&structures.array[i], 0, sizeof(type_structures)); \ + } \ + } \ + structures.size = new_length; \ + if (structures.used > structures.size) structures.used = new_length; \ + } +#endif // _di_f_macro_memory_structures_resize_ + +/** + * Adjust a generic memory structures. + * + * status: the status to return. + * structures: the structures to operate on. + * type_stucture: the structure type. + * type_stuctures: the structure type. + * new_length: the new size of the array. + * length_variable: the data type of the length variable. + */ +#ifndef _di_f_macro_memory_structures_adjust_ + #define f_macro_memory_structures_adjust(status, structures, type_structure, type_structures, new_length, length_variable) \ + status = F_none; \ + if (new_length < structures.size) { \ + length_variable i = structures.size - new_length; \ + for (; i < structures.size; i++) { \ + f_macro_memory_structure_destroy(status, structures.array[i], type_structure); \ + if (status != F_none) break; \ + } \ + } \ + if (status == F_none) status = f_memory_adjust((void **) & structures.array, sizeof(type_structures), structures.size, new_length); \ + if (status == F_none) { \ + if (new_length > structures.size) { \ + length_variable i = structures.size; \ + for (; i < new_length; i++) { \ + memset(&structures.array[i], 0, sizeof(type_structures)); \ + } \ + } \ + structures.size = new_length; \ + if (structures.used > structures.size) structures.used = new_length; \ + } +#endif // _di_f_macro_memory_structures_adjust_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_memory_structure_h diff --git a/level_0/f_memory/c/memory.h b/level_0/f_memory/c/memory.h index e43af4a..df8f4d7 100644 --- a/level_0/f_memory/c/memory.h +++ b/level_0/f_memory/c/memory.h @@ -23,6 +23,9 @@ #include #include +// fll-0 memory includes +#include + #ifdef __cplusplus extern "C" { #endif @@ -179,312 +182,6 @@ extern "C" { extern f_return_status f_memory_adjust(void **pointer, const f_memory_size_t type, const f_memory_length old_length, const f_memory_length new_length); #endif // _di_f_memory_adjust_ -/** - * Reset a generic memory stucture to 0 (clear all values). - * - * This does not deallocate memory, be certain that memory is not allocated before calling this to avoid potential memory leaks. - * - * structure: the structure to operate on. - */ -#ifndef _di_f_macro_memory_structure_clear_ - #define f_macro_memory_structure_clear(structure) \ - structure.array = 0; \ - structure.size = 0; \ - structure.used = 0; -#endif // _di_f_macro_memory_structure_clear_ - -/** - * Create a new generic memory structure. - * - * This does not deallocate memory, be certain that memory is not allocated before calling this to avoid potential memory leaks. - * - * status: the status to return. - * structure: the structure to operate on. - * type: the structure type. - * length: the new size of the array. - */ -#ifndef _di_f_macro_memory_structure_new_ - #define f_macro_memory_structure_new(status, structure, type, length) \ - f_macro_memory_structure_clear(structure) \ - status = f_memory_new((void **) & structure.array, sizeof(type), length); \ - if (status == F_none) { \ - structure.size = length; \ - structure.used = 0; \ - } -#endif // _di_f_macro_memory_structure_new_ - -/** - * Delete a generic memory structure. - * - * status: the status to return. - * structure: the structure to operate on. - * type: the structure type. - */ -#ifndef _di_f_macro_memory_structure_delete_ - #define f_macro_memory_structure_delete(status, structure, type) \ - status = f_memory_delete((void **) & structure.array, sizeof(type), structure.size); \ - if (status == F_none) { \ - structure.size = 0; \ - structure.used = 0; \ - } -#endif // _di_f_macro_memory_structure_delete_ - -/** - * Destroy a generic memory structure. - * - * status: the status to return. - * structure: the structure to operate on. - * type: the structure type. - */ -#ifndef _di_f_macro_memory_structure_destroy_ - #define f_macro_memory_structure_destroy(status, structure, type) \ - status = f_memory_destroy((void **) & structure.array, sizeof(type), structure.size); \ - if (status == F_none) { \ - structure.size = 0; \ - structure.used = 0; \ - } -#endif // _di_f_macro_memory_structure_destroy_ - -/** - * Delete a generic memory structure. - * - * structure: the structure to operate on. - * type: the structure type. - */ -#ifndef _di_f_macro_memory_structure_delete_simple_ - #define f_macro_memory_structure_delete_simple(structure, type) \ - if (f_memory_delete((void **) & structure.array, sizeof(type), structure.size) == F_none) { \ - structure.size = 0; \ - structure.used = 0; \ - } -#endif // _di_f_macro_memory_structure_delete_simple_ - -/** - * Destroy a generic memory structure. - * - * structure: the structure to operate on. - * type: the structure type. - */ -#ifndef _di_f_macro_memory_structure_destroy_simple_ - #define f_macro_memory_structure_destroy_simple(structure, type) \ - if (f_memory_destroy((void **) & structure.array, sizeof(type), structure.size) == F_none) { \ - structure.size = 0; \ - structure.used = 0; \ - } -#endif // _di_f_macro_memory_structure_destroy_simple_ - -/** - * Resize a generic memory structure. - * - * status: the status to return. - * structure: the structure to operate on. - * type: the structure type. - * new_length: the new size of the array. - */ -#ifndef _di_f_macro_memory_structure_resize_ - #define f_macro_memory_structure_resize(status, structure, type, new_length) \ - status = f_memory_resize((void **) & structure.array, sizeof(type), structure.size, new_length); \ - if (status == F_none) { \ - structure.size = new_length; \ - if (structure.used > structure.size) structure.used = new_length; \ - } -#endif // _di_f_macro_memory_structure_resize_ - -/** - * Adjust a generic memory structure. - * - * status: the status to return. - * structure: the structure to operate on. - * type: the structure type. - * new_length: the new size of the array. - */ -#ifndef _di_f_macro_memory_structure_adjust_ - #define f_macro_memory_structure_adjust(status, structure, type, new_length) \ - status = f_memory_adjust((void **) & structure.array, sizeof(type), structure.size, new_length); \ - if (status == F_none) { \ - structure.size = new_length; \ - if (structure.used > structure.size) structure.used = new_length; \ - } -#endif // _di_f_macro_memory_structure_adjust_ - -/** - * Reset a generic memory stuctures to 0 (clear all values). - * - * This does not deallocate memory, be certain that memory is not allocated before calling this to avoid potential memory leaks. - * - * structures: the structures to operate on. - */ -#ifndef _di_f_macro_memory_structures_clear_ - #define f_macro_memory_structures_clear(structures) \ - structures.array = 0; \ - structures.size = 0; \ - structures.used = 0; -#endif // _di_f_macro_memory_structures_clear_ - -/** - * Create a new generic memory structures. - * - * This does not deallocate memory, be certain that memory is not allocated before calling this to avoid potential memory leaks. - * - * status: the status to return. - * structures: the structures to operate on. - * type: the structure type. - * new_length: the new size of the array. - */ -#ifndef _di_f_macro_memory_structures_new_ - #define f_macro_memory_structures_new(status, structures, type, new_length) \ - f_macro_memory_structures_clear(structures) \ - status = f_memory_new((void **) & structures.array, sizeof(type), new_length); \ - if (status == F_none) { \ - structures.size = new_length; \ - structures.used = 0; \ - } -#endif // _di_f_macro_memory_structures_new_ - -/** - * Delete a generic memory structures. - * - * status: the status to return. - * structures: the structures to operate on. - * type: the structure type.. - */ -#ifndef _di_f_macro_memory_structures_delete_ - #define f_macro_memory_structures_delete(status, structures, type) \ - status = F_none; \ - structures.used = structures.size; \ - while (structures.used > 0) { \ - structures.used--; \ - f_macro_memory_structure_delete(status, structures.array[structures.used], type); \ - if (status != F_none) break; \ - } \ - if (status == F_none) status = f_memory_delete((void **) & structures.array, sizeof(type), structures.size); \ - if (status == F_none) structures.size = 0; -#endif // _di_f_macro_memory_structures_delete_ - -/** - * Destroy a generic memory structures. - * - * status: the status to return. - * structures: the structures to operate on. - * type: the structure type. - */ -#ifndef _di_f_macro_memory_structures_destroy_ - #define f_macro_memory_structures_destroy(status, structures, type) \ - status = F_none; \ - structures.used = structures.size; \ - while (structures.used > 0) { \ - structures.used--; \ - f_macro_memory_structure_destroy(status, structures.array[structures.used], type); \ - if (status != F_none) break; \ - } \ - if (status == F_none) status = f_memory_destroy((void **) & structures.array, sizeof(type), structures.size); \ - if (status == F_none) structures.size = 0; -#endif // _di_f_macro_memory_structures_destroy_ - -/** - * Delete a generic memory structures. - * - * structures: the structures to operate on. - * type: the structure type.. - */ -#ifndef _di_f_macro_memory_structures_delete_simple_ - #define f_macro_memory_structures_delete_simple(structures, type) \ - structures.used = structures.size; \ - while (structures.used > 0) { \ - structures.used--; \ - f_macro_memory_structure_delete_simple(structures.array[structures.used], type); \ - } \ - if (structures.used == 0) { \ - if (f_memory_delete((void **) & structures.array, sizeof(type), structures.size)) { \ - structures.size = 0; \ - } \ - } -#endif // _di_f_macro_memory_structures_delete_simple_ - -/** - * Destroy a generic memory structures. - * - * structures: the structures to operate on. - * type: the structure type. - */ -#ifndef _di_f_macro_memory_structures_destroy_simple_ - #define f_macro_memory_structures_destroy_simple(structures, type) \ - structures.used = structures.size; \ - while (structures.used > 0) { \ - structures.used--; \ - f_macro_memory_structure_destroy_simple(structures.array[structures.used], type); \ - } \ - if (structures.used == 0) { \ - if (f_memory_destroy((void **) & structures.array, sizeof(type), structures.size)) { \ - structures.size = 0; \ - } \ - } -#endif // _di_f_macro_memory_structures_destroy_simple_ - -/** - * Resize a generic memory structures. - * - * status: the status to return. - * structures: the structures to operate on. - * type: the structure type. - * new_length: the new size of the array. - * length_variable: the data type of the length variable. - */ -#ifndef _di_f_macro_memory_structures_resize_ - #define f_macro_memory_structures_resize(status, structures, type, new_length, length_variable) \ - status = F_none; \ - if (new_length < structures.size) { \ - length_variable i = structures.size - new_length; \ - for (; i < structures.size; i++) { \ - f_macro_memory_structure_delete(status, structures.array[i], type); \ - if (status != F_none) break; \ - } \ - } \ - if (status == F_none) status = f_memory_resize((void **) & structures.array, sizeof(type), structures.size, new_length); \ - if (status == F_none) { \ - if (new_length > structures.size) { \ - length_variable i = structures.size; \ - for (; i < new_length; i++) { \ - memset(&structures.array[i], 0, sizeof(type)); \ - } \ - } \ - structures.size = new_length; \ - if (structures.used > structures.size) structures.used = new_length; \ - } -#endif // _di_f_macro_memory_structures_resize_ - -/** - * Adjust a generic memory structures. - * - * status: the status to return. - * structures: the structures to operate on. - * type: the structure type. - * new_length: the new size of the array. - * length_variable: the data type of the length variable. - */ -#ifndef _di_f_macro_memory_structures_adjust_ - #define f_macro_memory_structures_adjust(status, structures, type, new_length, length_variable) \ - status = F_none; \ - if (new_length < structures.size) { \ - length_variable i = structures.size - new_length; \ - for (; i < structures.size; i++) { \ - f_macro_memory_structure_destroy(status, structures.array[i], type); \ - if (status != F_none) break; \ - } \ - } \ - if (status == F_none) status = f_memory_adjust((void **) & structures.array, sizeof(type), structures.size, new_length); \ - if (status == F_none) { \ - if (new_length > structures.size) { \ - length_variable i = structures.size; \ - for (; i < new_length; i++) { \ - memset(&structures.array[i], 0, sizeof(type)); \ - } \ - } \ - structures.size = new_length; \ - if (structures.used > structures.size) structures.used = new_length; \ - } -#endif // _di_f_macro_memory_structures_adjust_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_memory/data/build/settings b/level_0/f_memory/data/build/settings index 484743a..d55eb1f 100644 --- a/level_0/f_memory/data/build/settings +++ b/level_0/f_memory/data/build/settings @@ -22,7 +22,7 @@ build_libraries -lc build_libraries-individual build_sources_library memory.c build_sources_program -build_sources_headers memory.h +build_sources_headers memory.h memory-structure.h build_sources_script build_sources_setting build_script yes diff --git a/level_0/f_status/c/status_array.h b/level_0/f_status/c/status_array.h index 46ab661..5cb939b 100644 --- a/level_0/f_status/c/status_array.h +++ b/level_0/f_status/c/status_array.h @@ -33,18 +33,18 @@ extern "C" { #define f_statuss_initialize { 0, 0, 0 } - #define f_macro_statuss_clear(status) f_macro_memory_structure_clear(statuses) + #define f_macro_statuss_clear(statuss) f_macro_memory_structure_clear(statuss) - #define f_macro_statuss_new(status, statuses, length) f_macro_memory_structure_new(status, statuses, f_status, length) + #define f_macro_statuss_new(status, statuss, length) f_macro_memory_structure_new(status, statuss, f_status, length) - #define f_macro_statuss_delete(status, statuses) f_macro_memory_structure_delete(status, statuses, f_status) - #define f_macro_statuss_destroy(status, statuses) f_macro_memory_structure_destroy(status, statuses, f_status) + #define f_macro_statuss_delete(status, statuss) f_macro_memory_structure_delete(status, statuss, f_status) + #define f_macro_statuss_destroy(status, statuss) f_macro_memory_structure_destroy(status, statuss, f_status) - #define f_macro_statuss_delete_simple(statuses) f_macro_memory_structure_delete_simple(statuses, f_status) - #define f_macro_statuss_destroy_simple(statuses) f_macro_memory_structure_destroy_simple(statuses, f_status) + #define f_macro_statuss_delete_simple(statuss) f_macro_memory_structure_delete_simple(statuss, f_status) + #define f_macro_statuss_destroy_simple(statuss) f_macro_memory_structure_destroy_simple(statuss, f_status) - #define f_macro_statuss_resize(status, statuses, new_length) f_macro_memory_structure_resize(status, statuses, f_status, new_length) - #define f_macro_statuss_adjust(status, statuses, new_length) f_macro_memory_structure_adjust(status, statuses, f_status, new_length) + #define f_macro_statuss_resize(status, statuss, new_length) f_macro_memory_structure_resize(status, statuss, f_status, new_length) + #define f_macro_statuss_adjust(status, statuss, new_length) f_macro_memory_structure_adjust(status, statuss, f_status, new_length) #endif // _di_f_statuss_ /** @@ -64,18 +64,18 @@ extern "C" { #define f_statusss_initialize { 0, 0, 0 } - #define f_macro_statusss_clear(statuses) f_macro_memory_structures_clear(statuses) + #define f_macro_statusss_clear(statusss) f_macro_memory_structures_clear(statusss) - #define f_macro_statusss_new(status, statuses, length) f_macro_memory_structures_new(status, statuses, f_status, length) + #define f_macro_statusss_new(status, statusss, length) f_macro_memory_structures_new(status, statusss, f_status, f_statuss, length) - #define f_macro_statusss_delete(status, statuses) f_macro_memory_structures_delete(status, statuses, f_status) - #define f_macro_statusss_destroy(status, statuses) f_macro_memory_structures_destroy(status, statuses, f_status) + #define f_macro_statusss_delete(status, statusss) f_macro_memory_structures_delete(status, statusss, f_status, f_statuss) + #define f_macro_statusss_destroy(status, statusss) f_macro_memory_structures_destroy(status, statusss, f_status, f_statuss) - #define f_macro_statusss_delete_simple(statuses) f_macro_memory_structures_delete_simple(statuses, f_status) - #define f_macro_statusss_destroy_simple(statuses) f_macro_memory_structures_destroy_simple(statuses, f_status) + #define f_macro_statusss_delete_simple(statusss) f_macro_memory_structures_delete_simple(statusss, f_status, f_statuss) + #define f_macro_statusss_destroy_simple(statusss) f_macro_memory_structures_destroy_simple(statusss, f_status, f_statuss) - #define f_macro_statusss_resize(status, statuses, new_length) f_macro_memory_structures_resize(status, statuses, f_status, new_length) - #define f_macro_statusss_adjust(status, statuses, new_length) f_macro_memory_structures_adjust(status, statuses, f_status, new_length) + #define f_macro_statusss_resize(status, statusss, new_length) f_macro_memory_structures_resize(status, statusss, f_status, f_statuss, new_length) + #define f_macro_statusss_adjust(status, statusss, new_length) f_macro_memory_structures_adjust(status, statusss, f_status, f_statuss, new_length) #endif // _di_f_statuss_ #ifdef __cplusplus diff --git a/level_0/f_string/c/string-common.h b/level_0/f_string/c/string-common.h new file mode 100644 index 0000000..0fc3553 --- /dev/null +++ b/level_0/f_string/c/string-common.h @@ -0,0 +1,130 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.5 + * Licenses: lgplv2.1 + * + * Defines common string data. + * + * This is auto-included by string.h and should not need to be explicitly included. + */ +#ifndef _F_string_common_h +#define _F_string_common_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * BUG: for whatever reason strnlen is considered not included with -Wall, even with __USE_GNU defined. + * therefore this gets defined here. + */ +#ifdef _en_BUG_strnlen_ + extern size_t strnlen (const char *string, size_t max_length); +#endif // _en_BUG_strnlen_ + +/** + * Define the end of line character. + * FLL forbids '\r' and '\r\n' as end of line characters, \r will be silently ignored. + */ +#ifndef _di_f_string_has_eol_ + #define f_string_eol "\n" +#endif // _di_f_string_has_eol_ + +#ifndef _di_f_string_has_placeholder_ + #define f_string_placeholder "\0" +#endif // _di_f_string_has_placeholder_ + +#ifndef _di_string_format_pointers_ + #define string_format_string "%s" + #define string_format_character "%c" + #define string_format_wide_string "%ls" + #define string_format_wide_character "%lc" + #define string_format_integer "%i" + #define string_format_unsigned "%u" + #define string_format_double "%d" + #define string_format_float "%f" + #define string_format_short_integer "%hi" + #define string_format_short_unsigned "%hu" + #define string_format_long_integer "%li" + #define string_format_long_unsigned "%lu" + #define string_format_long_double "%ld" + #define string_format_long_long_integer "%lli" + #define string_format_long_long_unsigned "%llu" +#endif // _di_string_format_pointers_ + +#ifndef _di_f_array_length_printf_ + #define f_array_length_printf string_format_integer + #define f_array_length_short_printf string_format_short_integer + #define f_array_length_long_printf string_format_long_integer +#endif // _di_f_array_length_printf_ + +/** + * define the basic string type. + */ +#ifndef _di_f_string_ + typedef char *f_string; + + #define f_string_initialize 0 + + #define f_macro_string_new(status, string, length) status = f_memory_new((void **) & string, sizeof(f_string), length) + #define f_macro_string_delete(status, string, length) status = f_memory_delete((void **) & string, sizeof(f_string), length) + #define f_macro_string_destroy(status, string, length) status = f_memory_destroy((void **) & string, sizeof(f_string), length) + + #define f_macro_string_delete_simple(string, length) f_memory_delete((void **) & string, sizeof(f_string), length) + #define f_macro_string_destroy_simple(string, length) f_memory_destroy((void **) & string, sizeof(f_string), length) + + #define f_macro_string_resize(status, string, old_length, new_length) \ + status = f_memory_resize((void **) & string, sizeof(f_string), old_length, new_length) + + #define f_macro_string_adjust(status, string, old_length, new_length) \ + status = f_memory_adjust((void **) & string, sizeof(f_string), old_length, new_length) +#endif // _di_f_string_ + +#ifndef _di_f_string_length_ + typedef f_number_unsigned f_string_length; + + // string size is set to (size - 4) to compensate for UTF-8 4-byte character such that it can easily act as a (size - 1) regardless of UTF-8. + #define f_string_length_size 0xfffffffffffffffb + #define f_string_length_size_max f_type_number_size_max_unsigned + + #define f_string_length_printf string_format_long_integer +#endif // _di_f_string_length_ + +/** + * A structure containing an array of string lengths. + * + * array: the array of string lengths. + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ +#ifndef _di_f_string_lengths_ + typedef struct { + f_string_length *array; + + f_array_length size; + f_array_length used; + } f_string_lengths; + + #define f_string_lengths_initialize { 0, 0, 0 } + + #define f_macro_string_lengths_clear(lengths) f_macro_memory_structure_clear(lengths) + + #define f_macro_string_lengths_new(status, lengths, length) f_macro_memory_structure_new(status, lengths, f_string_length, length) + + #define f_macro_string_lengths_delete(status, lengths) f_macro_memory_structure_delete(status, lengths, f_string_length) + #define f_macro_string_lengths_destroy(status, lengths) f_macro_memory_structure_destroy(status, lengths, f_string_length) + + #define f_macro_string_lengths_delete_simple(lengths) f_macro_memory_structure_delete_simple(lengths, f_string_length) + #define f_macro_string_lengths_destroy_simple(lengths) f_macro_memory_structure_destroy_simple(lengths, f_string_length) + + #define f_macro_string_lengths_resize(status, lengths, new_length) f_macro_memory_structure_resize(status, lengths, f_string_length, new_length) + #define f_macro_string_lengths_adjust(status, lengths, new_length) f_macro_memory_structure_adjust(status, lengths, f_string_length, new_length) +#endif // _di_f_string_lengths_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_string_common_h diff --git a/level_0/f_string/c/string-dynamic.h b/level_0/f_string/c/string-dynamic.h new file mode 100644 index 0000000..0bfc6bd --- /dev/null +++ b/level_0/f_string/c/string-dynamic.h @@ -0,0 +1,252 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.5 + * Licenses: lgplv2.1 + * + * Defines dynamic (and static) string data. + * + * This is auto-included by string.h and should not need to be explicitly included. + */ +#ifndef _F_string_dynamic_h +#define _F_string_dynamic_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A string that is analogous to f_string_dynamic but intended for static-only uses. + * + * The f_string_static type should never be directly allocated or deallocated. + * + * A special f_macro_string_static_initialize() is provided for the special purpose of easily initialize a static string. + * + * string: the string. + * size: total amount of space available. + * used: total number of space used. + */ +#ifndef _di_f_string_static_ + typedef struct { + f_string string; + + f_string_length size; + f_string_length used; + } f_string_static; + + #define f_string_static_initialize { 0, 0, 0 } + + #define f_macro_string_static_clear(string_static) \ + string_static.string = 0; \ + string_static.size = 0; \ + string_static.used = 0; + + #define f_macro_string_static_initialize(string, length) { string, length, length } +#endif // _di_f_string_static_ + +/** + * A string that supports contains a size attribute to handle dynamic allocations and deallocations. + * + * Save the string size along with the string, so that strlen(..) commands can be avoided as much as possible. + * + * This is a sub-type of f_string_static, allowing it to be passed into any f_string_static type. + * It is recommended that f_string_static are not otherwise casted into f_string_dynamic to avoid potential memory allocation issues. + * + * string: the string. + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ +#ifndef _di_f_string_dynamic_ + typedef f_string_static f_string_dynamic; + + #define f_string_dynamic_initialize f_string_static_initialize + + #define f_macro_string_dynamic_clear(dynamic) f_macro_string_static_clear(dynamic) + + #define f_macro_string_dynamic_new(status, dynamic, new_length) \ + f_macro_string_dynamic_clear(dynamic) \ + status = f_memory_new((void **) & dynamic.string, sizeof(f_string), new_length); \ + if (status == F_none) { \ + dynamic.size = new_length; \ + dynamic.used = 0; \ + } + + #define f_macro_string_dynamic_delete(status, dynamic) \ + status = f_memory_delete((void **) & dynamic.string, sizeof(f_string), dynamic.size); \ + if (status == F_none) { \ + dynamic.size = 0; \ + dynamic.used = 0; \ + } + + #define f_macro_string_dynamic_destroy(status, dynamic) \ + status = f_memory_destroy((void **) & dynamic.string, sizeof(f_string), dynamic.size); \ + if (status == F_none) { \ + dynamic.size = 0; \ + dynamic.used = 0; \ + } + + #define f_macro_string_dynamic_delete_simple(dynamic) \ + f_memory_delete((void **) & dynamic.string, sizeof(f_string), dynamic.size); \ + dynamic.size = 0; \ + dynamic.used = 0; + + #define f_macro_string_dynamic_destroy_simple(dynamic) \ + f_memory_destroy((void **) & dynamic.string, sizeof(f_string), dynamic.size); \ + dynamic.size = 0; \ + dynamic.used = 0; + + #define f_macro_string_dynamic_resize(status, dynamic, new_length) \ + status = f_memory_resize((void **) & dynamic.string, sizeof(f_string), dynamic.size, new_length); \ + if (status == F_none) { \ + dynamic.size = new_length; \ + if (dynamic.used > dynamic.size) dynamic.used = new_length; \ + } + + #define f_macro_string_dynamic_adjust(status, dynamic, new_length) \ + status = f_memory_adjust((void **) & dynamic.string, sizeof(f_string), dynamic.size, new_length); \ + if (status == F_none) { \ + dynamic.size = new_length; \ + if (dynamic.used > dynamic.size) dynamic.used = new_length; \ + } +#endif // _di_f_string_dynamic_ + +/** + * An array of static strings. + * + * array: the array of static strings. + * size: total amount of space available. + * used: total number of space used. + */ +#ifndef _di_f_string_statics_ + typedef struct { + f_string_static *array; + + f_array_length size; + f_array_length used; + } f_string_statics; + + #define f_string_statics_initialize { 0, 0, 0 } + + #define f_macro_string_statics_clear(statics) \ + statics.array = 0; \ + statics.size = 0; \ + statics.used = 0; +#endif // _di_f_string_statics_ + +/** + * An array of dynamic strings. + * + * array: the array of dynamic strings. + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ +#ifndef _di_f_string_dynamics_ + typedef f_string_statics f_string_dynamics; + + #define f_string_dynamics_initialize f_string_statics_initialize + + #define f_macro_string_dynamics_clear(dynamics) f_macro_string_statics_clear(dynamics) + + #define f_macro_string_dynamics_new(status, dynamics, length) \ + f_macro_string_dynamics_clear(dynamics) \ + status = f_memory_new((void **) & dynamics.array, sizeof(f_string_dynamic), length); \ + if (status == F_none) { \ + dynamics.size = length; \ + dynamics.used = 0; \ + } + + #define f_macro_string_dynamics_delete(status, dynamics) \ + status = F_none; \ + dynamics.used = dynamics.size; \ + while (dynamics.used > 0) { \ + dynamics.used--; \ + f_macro_string_dynamic_delete(status, dynamics.array[dynamics.used]); \ + if (status != F_none) break; \ + } \ + if (status == F_none) status = f_memory_delete((void **) & dynamics.array, sizeof(f_string_dynamic), dynamics.size); \ + if (status == F_none) dynamics.size = 0; + + #define f_macro_string_dynamics_destroy(status, dynamics) \ + status = F_none; \ + dynamics.used = dynamics.size; \ + while (dynamics.used > 0) { \ + dynamics.used--; \ + f_macro_string_dynamic_destroy(status, dynamics.array[dynamics.used]); \ + if (status != F_none) break; \ + } \ + if (status == F_none) status = f_memory_destroy((void **) & dynamics.array, sizeof(f_string_dynamic), dynamics.size); \ + if (status == F_none) dynamics.size = 0; + + #define f_macro_string_dynamics_delete_simple(dynamics) \ + dynamics.used = dynamics.size; \ + while (dynamics.used > 0) { \ + dynamics.used--; \ + f_macro_string_dynamic_delete_simple(dynamics.array[dynamics.used]); \ + if (dynamics.used == 0) { \ + if (f_memory_delete((void **) & dynamics.array, sizeof(f_string_dynamic), dynamics.size)) { \ + dynamics.size = 0; \ + } \ + } \ + } + + #define f_macro_string_dynamics_destroy_simple(dynamics) \ + dynamics.used = dynamics.size; \ + while (dynamics.used > 0) { \ + dynamics.used--; \ + f_macro_string_dynamic_destroy_simple(dynamics.array[dynamics.used]); \ + if (dynamics.used == 0) { \ + if (f_memory_destroy((void **) & dynamics.array, sizeof(f_string_dynamic), dynamics.size)) { \ + dynamics.size = 0; \ + } \ + } \ + } + + #define f_macro_string_dynamics_resize(status, dynamics, new_length) \ + status = F_none; \ + if (new_length < dynamics.size) { \ + f_array_length i = dynamics.size - new_length; \ + for (; i < dynamics.size; i++) { \ + f_macro_string_dynamic_delete(status, dynamics.array[i]); \ + if (status != F_none) break; \ + } \ + } \ + if (status == F_none) status = f_memory_resize((void **) & dynamics.array, sizeof(f_string_dynamic), dynamics.size, new_length); \ + if (status == F_none) { \ + if (new_length > dynamics.size) { \ + f_array_length i = dynamics.size; \ + for (; i < new_length; i++) { \ + memset(&dynamics.array[i], 0, sizeof(f_string_dynamic)); \ + } \ + } \ + dynamics.size = new_length; \ + if (dynamics.used > dynamics.size) dynamics.used = new_length; \ + } + + #define f_macro_string_dynamics_adjust(status, dynamics, new_length) \ + status = F_none; \ + if (new_length < dynamics.size) { \ + f_array_length i = dynamics.size - new_length; \ + for (; i < dynamics.size; i++) { \ + f_macro_string_dynamic_destroy(status, dynamics.array[i], f_string_dynamic); \ + if (status != F_none) break; \ + } \ + } \ + if (status == F_none) status = f_memory_adjust((void **) & dynamics.array, sizeof(f_string_dynamic), dynamics.size, new_length); \ + if (status == F_none) { \ + if (new_length > dynamics.size) { \ + f_array_length i = dynamics.size; \ + for (; i < new_length; i++) { \ + memset(&dynamics.array[i], 0, sizeof(f_string_dynamic)); \ + } \ + } \ + dynamics.size = new_length; \ + if (dynamics.used > dynamics.size) dynamics.used = new_length; \ + } +#endif // _di_f_string_dynamics_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_string_dynamic_h diff --git a/level_0/f_string/c/string-map.h b/level_0/f_string/c/string-map.h new file mode 100644 index 0000000..51c4dab --- /dev/null +++ b/level_0/f_string/c/string-map.h @@ -0,0 +1,337 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.5 + * Licenses: lgplv2.1 + * + * Defines map string data. + * + * This is auto-included by string.h and should not need to be explicitly included. + */ +#ifndef _F_string_map_h +#define _F_string_map_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A string map consisting of a name and value. + * + * name: A string representing the map name. + * value: A string representing the map value. + */ +#ifndef _di_f_string_map_ + typedef struct { + f_string_dynamic name; + f_string_dynamic value; + } f_string_map; + + #define f_string_map_initialize { f_string_dynamic_initialize, f_string_dynamic_initialize } + + #define f_macro_string_map_clear(map) \ + map.array = 0; \ + map.size = 0; \ + map.used = 0; + + #define f_macro_string_map_delete(status, map) \ + f_macro_string_dynamic_delete(status, map.name) \ + if (status == F_none) { \ + f_macro_string_dynamic_delete(status, map.value) \ + } + + #define f_macro_string_map_destroy(status, map) \ + f_macro_string_dynamic_destroy(status, map.name) \ + if (status == F_none) { \ + f_macro_string_dynamic_destroy(status, map.value) \ + } + + #define f_macro_string_map_delete_simple(map) \ + f_macro_string_dynamic_delete_simple(map.name) \ + f_macro_string_dynamic_delete_simple(map.value) + + #define f_macro_string_map_destroy_simple(map) \ + f_macro_string_dynamic_destroy_simple(map.name) \ + f_macro_string_dynamic_destroy_simple(map.value) +#endif // _di_f_string_map_ + +/** + * An array of string maps. + * + * array: the array of string maps. + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ +#ifndef _di_f_string_maps_ + typedef struct { + f_string_map *array; + + f_array_length size; + f_array_length used; + } f_string_maps; + + #define f_string_maps_initialize f_string_statics_initialize + + #define f_macro_string_maps_clear(maps) \ + maps.array = 0; \ + maps.size = 0; \ + maps.used = 0; + + #define f_macro_string_maps_new(status, maps, length) \ + f_macro_string_maps_clear(maps) \ + status = f_memory_new((void **) & maps.array, sizeof(f_string_map), length); \ + if (status == F_none) { \ + maps.size = length; \ + maps.used = 0; \ + } + + #define f_macro_string_maps_delete(status, maps) \ + status = F_none; \ + maps.used = maps.size; \ + while (maps.used > 0) { \ + maps.used--; \ + f_macro_string_map_delete(status, maps.array[maps.used]); \ + if (status != F_none) break; \ + } \ + if (status == F_none) status = f_memory_delete((void **) & maps.array, sizeof(f_string_map), maps.size); \ + if (status == F_none) maps.size = 0; + + #define f_macro_string_maps_destroy(status, maps) \ + status = F_none; \ + maps.used = maps.size; \ + while (maps.used > 0) { \ + maps.used--; \ + f_macro_string_map_destroy(status, maps.array[maps.used]); \ + if (status != F_none) break; \ + } \ + if (status == F_none) status = f_memory_destroy((void **) & maps.array, sizeof(f_string_map), maps.size); \ + if (status == F_none) maps.size = 0; + + #define f_macro_string_maps_delete_simple(maps) \ + maps.used = maps.size; \ + while (maps.used > 0) { \ + maps.used--; \ + f_macro_string_map_delete_simple(maps.array[maps.used]); \ + if (maps.used == 0) { \ + if (f_memory_delete((void **) & maps.array, sizeof(f_string_map), maps.size)) { \ + maps.size = 0; \ + } \ + } \ + } + + #define f_macro_string_maps_destroy_simple(maps) \ + maps.used = maps.size; \ + while (maps.used > 0) { \ + maps.used--; \ + f_macro_string_map_destroy_simple(maps.array[maps.used]); \ + if (maps.used == 0) { \ + if (f_memory_destroy((void **) & maps.array, sizeof(f_string_map), maps.size)) { \ + maps.size = 0; \ + } \ + } \ + } + + #define f_macro_string_maps_resize(status, maps, new_length) \ + status = F_none; \ + if (new_length < maps.size) { \ + f_array_length i = maps.size - new_length; \ + for (; i < maps.size; i++) { \ + f_macro_string_map_delete(status, maps.array[i]); \ + if (status != F_none) break; \ + } \ + } \ + if (status == F_none) status = f_memory_resize((void **) & maps.array, sizeof(f_string_map), maps.size, new_length); \ + if (status == F_none) { \ + if (new_length > maps.size) { \ + f_array_length i = maps.size; \ + for (; i < new_length; i++) { \ + memset(&maps.array[i], 0, sizeof(f_string_map)); \ + } \ + } \ + maps.size = new_length; \ + if (maps.used > maps.size) maps.used = new_length; \ + } + + #define f_macro_string_maps_adjust(status, maps, new_length) \ + status = F_none; \ + if (new_length < maps.size) { \ + f_array_length i = maps.size - new_length; \ + for (; i < maps.size; i++) { \ + f_macro_string_map_destroy(status, maps.array[i], f_string_map); \ + if (status != F_none) break; \ + } \ + } \ + if (status == F_none) status = f_memory_adjust((void **) & maps.array, sizeof(f_string_map), maps.size, new_length); \ + if (status == F_none) { \ + if (new_length > maps.size) { \ + f_array_length i = maps.size; \ + for (; i < new_length; i++) { \ + memset(&maps.array[i], 0, sizeof(f_string_map)); \ + } \ + } \ + maps.size = new_length; \ + if (maps.used > maps.size) maps.used = new_length; \ + } +#endif // _di_f_string_maps_ + +/** + * A string map consisting of a name and multiple values. + * + * name: A string representing the map name. + * value: An array of strings representing the map value. + */ +#ifndef _di_f_string_map_multi_ + typedef struct { + f_string_dynamic name; + f_string_dynamics value; + } f_string_map_multi; + + #define f_string_map_multi_initialize { f_string_dynamic_initialize, f_string_dynamics_initialize } + + #define f_macro_string_map_multi_clear(map) \ + f_macro_string_dynamic_clear(map.name) \ + f_macro_string_dynamics_clear(map.value) + + #define f_macro_string_map_multi_delete(status, map) \ + f_macro_string_dynamic_delete(status, map.name) \ + if (status == F_none) { \ + f_macro_string_dynamics_delete(status, map.value) \ + } + + #define f_macro_string_map_multi_destroy(status, map) \ + f_macro_string_dynamic_destroy(status, map.name) \ + if (status == F_none) { \ + f_macro_string_dynamics_destroy(status, map.value) \ + } + + #define f_macro_string_map_multi_delete_simple(map) \ + f_macro_string_dynamic_delete_simple(map.name) \ + f_macro_string_dynamics_delete_simple(map.value) + + #define f_macro_string_map_multi_destroy_simple(map) \ + f_macro_string_dynamic_destroy_simple(map.name) \ + f_macro_string_dynamics_destroy_simple(map.value) +#endif // _di_f_string_map_multi_ + +/** + * An array of string maps. + * + * array: the array of string maps. + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ +#ifndef _di_f_string_map_multis_ + typedef struct { + f_string_map_multi *array; + + f_array_length size; + f_array_length used; + } f_string_map_multis; + + #define f_string_map_multis_initialize f_string_statics_initialize + + #define f_macro_string_map_multis_clear(maps) f_macro_string_statics_clear(maps) + + #define f_macro_string_map_multis_new(status, maps, length) \ + f_macro_string_map_multis_clear(maps) \ + status = f_memory_new((void **) & maps.array, sizeof(f_string_map_multi), length); \ + if (status == F_none) { \ + maps.size = length; \ + maps.used = 0; \ + } + + #define f_macro_string_map_multis_delete(status, maps) \ + status = F_none; \ + maps.used = maps.size; \ + while (maps.used > 0) { \ + maps.used--; \ + f_macro_string_map_multi_delete(status, maps.array[maps.used]); \ + if (status != F_none) break; \ + } \ + if (status == F_none) status = f_memory_delete((void **) & maps.array, sizeof(f_string_map_multi), maps.size); \ + if (status == F_none) maps.size = 0; + + #define f_macro_string_map_multis_destroy(status, maps) \ + status = F_none; \ + maps.used = maps.size; \ + while (maps.used > 0) { \ + maps.used--; \ + f_macro_string_map_multi_destroy(status, maps.array[maps.used]); \ + if (status != F_none) break; \ + } \ + if (status == F_none) status = f_memory_destroy((void **) & maps.array, sizeof(f_string_map_multi), maps.size); \ + if (status == F_none) maps.size = 0; + + #define f_macro_string_map_multis_delete_simple(maps) \ + maps.used = maps.size; \ + while (maps.used > 0) { \ + maps.used--; \ + f_macro_string_map_multi_delete_simple(maps.array[maps.used]); \ + if (maps.used == 0) { \ + if (f_memory_delete((void **) & maps.array, sizeof(f_string_map_multi), maps.size)) { \ + maps.size = 0; \ + } \ + } \ + } + + #define f_macro_string_map_multis_destroy_simple(maps) \ + maps.used = maps.size; \ + while (maps.used > 0) { \ + maps.used--; \ + f_macro_string_map_multi_destroy_simple(maps.array[maps.used]); \ + if (maps.used == 0) { \ + if (f_memory_destroy((void **) & maps.array, sizeof(f_string_map_multi), maps.size)) { \ + maps.size = 0; \ + } \ + } \ + } + + #define f_macro_string_map_multis_resize(status, maps, new_length) \ + status = F_none; \ + if (new_length < maps.size) { \ + f_array_length i = maps.size - new_length; \ + for (; i < maps.size; i++) { \ + f_macro_string_map_multi_delete(status, maps.array[i]); \ + if (status != F_none) break; \ + } \ + } \ + if (status == F_none) status = f_memory_resize((void **) & maps.array, sizeof(f_string_map_multi), maps.size, new_length); \ + if (status == F_none) { \ + if (new_length > maps.size) { \ + f_array_length i = maps.size; \ + for (; i < new_length; i++) { \ + memset(&maps.array[i], 0, sizeof(f_string_map_multi)); \ + } \ + } \ + maps.size = new_length; \ + if (maps.used > maps.size) maps.used = new_length; \ + } + + #define f_macro_string_map_multis_adjust(status, maps, new_length) \ + status = F_none; \ + if (new_length < maps.size) { \ + f_array_length i = maps.size - new_length; \ + for (; i < maps.size; i++) { \ + f_macro_string_map_multi_destroy(status, maps.array[i], f_string_map_multi); \ + if (status != F_none) break; \ + } \ + } \ + if (status == F_none) status = f_memory_adjust((void **) & maps.array, sizeof(f_string_map_multi), maps.size, new_length); \ + if (status == F_none) { \ + if (new_length > maps.size) { \ + f_array_length i = maps.size; \ + for (; i < new_length; i++) { \ + memset(&maps.array[i], 0, sizeof(f_string_map_multi)); \ + } \ + } \ + maps.size = new_length; \ + if (maps.used > maps.size) maps.used = new_length; \ + } +#endif // _di_f_string_map_multis_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_string_map_h diff --git a/level_0/f_string/c/string-quantity.h b/level_0/f_string/c/string-quantity.h new file mode 100644 index 0000000..0e69504 --- /dev/null +++ b/level_0/f_string/c/string-quantity.h @@ -0,0 +1,75 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.5 + * Licenses: lgplv2.1 + * + * Defines quantity string data. + * + * This is auto-included by string.h and should not need to be explicitly included. + */ +#ifndef _F_string_quantity_h +#define _F_string_quantity_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Store string quantity. + * + * Similar to f_string_range, except total is relative to start and is not an absolute stop position. + * + * Two common uses for when total is 0 is: + * 1) Exactly that, process a total of 0 strings bytes. + * 2) Process with no limit, aka infinite. + * + * start: The position where the string starts (based on some string/buffer). + * total: The total number of elements within that string/buffer the quantity represents. + */ +#ifndef _di_f_string_quantity_ + typedef struct { + f_string_length start; + f_string_length total; + } f_string_quantity; + + #define f_string_quantity_initialize { 0, 0 } +#endif // _di_f_string_quantity_ + +/** + * An array of string quantities. + * + * array: the array of string quantities. + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ +#ifndef _di_f_string_quantitys_ + typedef struct { + f_string_quantity *array; + + f_array_length size; + f_array_length used; + } f_string_quantitys; + + #define f_string_quantitys_initialize {0, 0, 0} + + #define f_macro_string_quantitys_clear(quantitys) f_macro_memory_structure_clear(quantitys) + + #define f_macro_string_quantitys_new(status, quantitys, length) f_macro_memory_structure_new(status, quantitys, f_string_quantity, length) + + #define f_macro_string_quantitys_delete(status, quantitys) f_macro_memory_structure_delete(status, quantitys, f_string_quantity) + #define f_macro_string_quantitys_destroy(status, quantitys) f_macro_memory_structure_destroy(status, quantitys, f_string_quantity) + + #define f_macro_string_quantitys_delete_simple(quantitys) f_macro_memory_structure_delete_simple(quantitys, f_string_quantity) + #define f_macro_string_quantitys_destroy_simple(quantitys) f_macro_memory_structure_destroy_simple(quantitys, f_string_quantity) + + #define f_macro_string_quantitys_resize(status, quantitys, new_length) f_macro_memory_structure_resize(status, quantitys, f_string_quantity, new_length) + #define f_macro_string_quantitys_adjust(status, quantitys, new_length) f_macro_memory_structure_adjust(status, quantitys, f_string_quantity, new_length) +#endif // _di_f_string_quantitys_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_string_quantity_h diff --git a/level_0/f_string/c/string-range.h b/level_0/f_string/c/string-range.h new file mode 100644 index 0000000..1d503b3 --- /dev/null +++ b/level_0/f_string/c/string-range.h @@ -0,0 +1,112 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.5 + * Licenses: lgplv2.1 + * + * Defines range string data. + * + * This is auto-included by string.h and should not need to be explicitly included. + */ +#ifndef _F_string_range_h +#define _F_string_range_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A structure designating a start and stop range for some string. + * + * In general, this project uses the start and stop position inclusively, meaning that a range of 0 to 1 would include positions 0 and position 1. + * Therefore, a range from 0 to 0 would be include position 0. + * Set start to some value larger than stop to designate that there is no range (such as start = 1, stop = 0). + * + * A special f_macro_string_range_initialize() is provided for the special purpose of easily initialize a static string range. + * + * start: the start position. + * stop: the stop position. + */ +#ifndef _di_f_string_range_ + typedef struct { + f_string_length start; + f_string_length stop; + } f_string_range; + + #define f_string_range_initialize { 1, 0 } + + #define f_macro_string_range_initialize(length) { 0, length - 1 } + + #define f_macro_string_range_clear(range) \ + range.start = 1; \ + range.stop = 0; +#endif // _di_f_string_range_ + +/** + * An array of string ranges. + * + * array: the array of string ranges. + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ +#ifndef _di_f_string_ranges_ + typedef struct { + f_string_range *array; + + f_array_length size; + f_array_length used; + } f_string_ranges; + + #define f_string_ranges_initialize {0, 0, 0} + + #define f_macro_string_ranges_clear(ranges) f_macro_memory_structure_clear(ranges) + + #define f_macro_string_ranges_new(status, ranges, length) f_macro_memory_structure_new(status, ranges, f_string_range, length) + + #define f_macro_string_ranges_delete(status, ranges) f_macro_memory_structure_delete(status, ranges, f_string_range) + #define f_macro_string_ranges_destroy(status, ranges) f_macro_memory_structure_destroy(status, ranges, f_string_range) + + #define f_macro_string_ranges_delete_simple(ranges) f_macro_memory_structure_delete_simple(ranges, f_string_range) + #define f_macro_string_ranges_destroy_simple(ranges) f_macro_memory_structure_destroy_simple(ranges, f_string_range) + + #define f_macro_string_ranges_resize(status, ranges, new_length) f_macro_memory_structure_resize(status, ranges, f_string_range, new_length) + #define f_macro_string_ranges_adjust(status, ranges, new_length) f_macro_memory_structure_adjust(status, ranges, f_string_range, new_length) +#endif // _di_f_string_ranges_ + +/** + * This holds an array of f_string_ranges. + * + * array: The array of ranges arrays. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_string_rangess_ + typedef struct { + f_string_ranges *array; + + f_array_length size; + f_array_length used; + } f_string_rangess; + + #define f_string_rangess_initialize { 0, 0, 0 } + + #define f_macro_string_rangess_clear(rangess) f_macro_memory_structures_clear(rangess) + + #define f_macro_string_rangess_new(status, rangess, length) f_macro_memory_structures_new(status, rangess, f_string_ranges, length) + + #define f_macro_string_rangess_delete(status, rangess) f_macro_memory_structures_delete(status, rangess, f_string_range, f_string_ranges) + #define f_macro_string_rangess_destroy(status, rangess) f_macro_memory_structures_destroy(status, rangess, f_string_range, f_string_ranges) + + #define f_macro_string_rangess_delete_simple(rangess) f_macro_memory_structures_delete_simple(rangess, f_string_range, f_string_ranges) + #define f_macro_string_rangess_destroy_simple(rangess) f_macro_memory_structures_destroy_simple(rangess, f_string_range, f_string_ranges) + + #define f_macro_string_rangess_resize(status, rangess, new_length) f_macro_memory_structures_resize(status, rangess, f_string_range, f_string_ranges, new_length, f_array_length) + #define f_macro_string_rangess_adjust(status, rangess, new_length) f_macro_memory_structures_adjust(status, rangess, f_string_range, f_string_ranges, new_length, f_array_length) +#endif // _di_f_string_rangess_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_string_range_h diff --git a/level_0/f_string/c/string.h b/level_0/f_string/c/string.h index c7bfe44..0e1cb40 100644 --- a/level_0/f_string/c/string.h +++ b/level_0/f_string/c/string.h @@ -21,770 +21,17 @@ #include #include +// fll-0 string includes +#include +#include +#include +#include +#include + #ifdef __cplusplus extern "C" { #endif -/** - * BUG: for whatever reason strnlen is considered not included with -Wall, even with __USE_GNU defined. - * therefore this gets defined here. - */ -#ifdef _en_BUG_strnlen_ - extern size_t strnlen (const char *string, size_t max_length); -#endif // _en_BUG_strnlen_ - -/** - * Define the end of line character. - * FLL forbids '\r' and '\r\n' as end of line characters, \r will be silently ignored. - */ -#ifndef _di_f_string_has_eol_ - #define f_string_eol "\n" -#endif // _di_f_string_has_eol_ - -#ifndef _di_f_string_has_placeholder_ - #define f_string_placeholder "\0" -#endif // _di_f_string_has_placeholder_ - -#ifndef _di_string_format_pointers_ - #define string_format_string "%s" - #define string_format_character "%c" - #define string_format_wide_string "%ls" - #define string_format_wide_character "%lc" - #define string_format_integer "%i" - #define string_format_unsigned "%u" - #define string_format_double "%d" - #define string_format_float "%f" - #define string_format_short_integer "%hi" - #define string_format_short_unsigned "%hu" - #define string_format_long_integer "%li" - #define string_format_long_unsigned "%lu" - #define string_format_long_double "%ld" - #define string_format_long_long_integer "%lli" - #define string_format_long_long_unsigned "%llu" -#endif // _di_string_format_pointers_ - -#ifndef _di_f_array_length_printf_ - #define f_array_length_printf string_format_integer - #define f_array_length_short_printf string_format_short_integer - #define f_array_length_long_printf string_format_long_integer -#endif // _di_f_array_length_printf_ - -/** - * define the basic string type. - */ -#ifndef _di_f_string_ - typedef char *f_string; - - #define f_string_initialize 0 - - #define f_macro_string_new(status, string, length) status = f_memory_new((void **) & string, sizeof(f_string), length) - #define f_macro_string_delete(status, string, length) status = f_memory_delete((void **) & string, sizeof(f_string), length) - #define f_macro_string_destroy(status, string, length) status = f_memory_destroy((void **) & string, sizeof(f_string), length) - - #define f_macro_string_delete_simple(string, length) f_memory_delete((void **) & string, sizeof(f_string), length) - #define f_macro_string_destroy_simple(string, length) f_memory_destroy((void **) & string, sizeof(f_string), length) - - #define f_macro_string_resize(status, string, old_length, new_length) \ - status = f_memory_resize((void **) & string, sizeof(f_string), old_length, new_length) - - #define f_macro_string_adjust(status, string, old_length, new_length) \ - status = f_memory_adjust((void **) & string, sizeof(f_string), old_length, new_length) -#endif // _di_f_string_ - -#ifndef _di_f_string_length_ - typedef f_number_unsigned f_string_length; - - // string size is set to (size - 4) to compensate for UTF-8 4-byte character such that it can easily act as a (size - 1) regardless of UTF-8. - #define f_string_length_size 0xfffffffffffffffb - #define f_string_length_size_max f_type_number_size_max_unsigned - - #define f_string_length_printf string_format_long_integer -#endif // _di_f_string_length_ - -/** - * A structure containing an array of string lengths. - * - * array: the array of string lengths. - * size: total amount of allocated space. - * used: total number of allocated spaces used. - */ -#ifndef _di_f_string_lengths_ - typedef struct { - f_string_length *array; - - f_array_length size; - f_array_length used; - } f_string_lengths; - - #define f_string_lengths_initialize { 0, 0, 0 } - - #define f_macro_string_lengths_clear(lengths) f_macro_memory_structure_clear(lengths) - - #define f_macro_string_lengths_new(status, lengths, length) f_macro_memory_structure_new(status, lengths, f_string_length, length) - - #define f_macro_string_lengths_delete(status, lengths) f_macro_memory_structure_delete(status, lengths, f_string_length) - #define f_macro_string_lengths_destroy(status, lengths) f_macro_memory_structure_destroy(status, lengths, f_string_length) - - #define f_macro_string_lengths_delete_simple(lengths) f_macro_memory_structure_delete_simple(lengths, f_string_length) - #define f_macro_string_lengths_destroy_simple(lengths) f_macro_memory_structure_destroy_simple(lengths, f_string_length) - - #define f_macro_string_lengths_resize(status, lengths, new_length) f_macro_memory_structure_resize(status, lengths, f_string_length, new_length) - #define f_macro_string_lengths_adjust(status, lengths, new_length) f_macro_memory_structure_adjust(status, lengths, f_string_length, new_length) -#endif // _di_f_string_lengths_ - -/** - * A structure designating a start and stop range for some string. - * - * In general, this project uses the start and stop position inclusively, meaning that a range of 0 to 1 would include positions 0 and position 1. - * Therefore, a range from 0 to 0 would be include position 0. - * Set start to some value larger than stop to designate that there is no range (such as start = 1, stop = 0). - * - * A special f_macro_string_range_initialize() is provided for the special purpose of easily initialize a static string range. - * - * start: the start position. - * stop: the stop position. - */ -#ifndef _di_f_string_range_ - typedef struct { - f_string_length start; - f_string_length stop; - } f_string_range; - - #define f_string_range_initialize { 1, 0 } - - #define f_macro_string_range_initialize(length) { 0, length - 1 } - - #define f_macro_string_range_clear(range) \ - range.start = 1; \ - range.stop = 0; -#endif // _di_f_string_range_ - -/** - * An array of string ranges. - * - * array: the array of string ranges. - * size: total amount of allocated space. - * used: total number of allocated spaces used. - */ -#ifndef _di_f_string_ranges_ - typedef struct { - f_string_range *array; - - f_array_length size; - f_array_length used; - } f_string_ranges; - - #define f_string_ranges_initialize {0, 0, 0} - - #define f_macro_string_ranges_clear(ranges) f_macro_memory_structure_clear(ranges) - - #define f_macro_string_ranges_new(status, ranges, length) f_macro_memory_structure_new(status, ranges, f_string_range, length) - - #define f_macro_string_ranges_delete(status, ranges) f_macro_memory_structure_delete(status, ranges, f_string_range) - #define f_macro_string_ranges_destroy(status, ranges) f_macro_memory_structure_destroy(status, ranges, f_string_range) - - #define f_macro_string_ranges_delete_simple(ranges) f_macro_memory_structure_delete_simple(ranges, f_string_range) - #define f_macro_string_ranges_destroy_simple(ranges) f_macro_memory_structure_destroy_simple(ranges, f_string_range) - - #define f_macro_string_ranges_resize(status, ranges, new_length) f_macro_memory_structure_resize(status, ranges, f_string_range, new_length) - #define f_macro_string_ranges_adjust(status, ranges, new_length) f_macro_memory_structure_adjust(status, ranges, f_string_range, new_length) -#endif // _di_f_string_ranges_ - -/** - * Store string quantity. - * - * Similar to f_string_range, except total is relative to start and is not an absolute stop position. - * - * Two common uses for when total is 0 is: - * 1) Exactly that, process a total of 0 strings bytes. - * 2) Process with no limit, aka infinite. - * - * start: The position where the string starts (based on some string/buffer). - * total: The total number of elements within that string/buffer the quantity represents. - */ -#ifndef _di_f_string_quantity_ - typedef struct { - f_string_length start; - f_string_length total; - } f_string_quantity; - - #define f_string_quantity_initialize { 0, 0 } -#endif // _di_f_string_quantity_ - -/** - * An array of string quantities. - * - * array: the array of string quantities. - * size: total amount of allocated space. - * used: total number of allocated spaces used. - */ -#ifndef _di_f_string_quantitys_ - typedef struct { - f_string_quantity *array; - - f_array_length size; - f_array_length used; - } f_string_quantitys; - - #define f_string_quantitys_initialize {0, 0, 0} - - #define f_macro_string_quantitys_clear(quantitys) f_macro_memory_structure_clear(quantitys) - - #define f_macro_string_quantitys_new(status, quantitys, length) f_macro_memory_structure_new(status, quantitys, f_string_quantity, length) - - #define f_macro_string_quantitys_delete(status, quantitys) f_macro_memory_structure_delete(status, quantitys, f_string_quantity) - #define f_macro_string_quantitys_destroy(status, quantitys) f_macro_memory_structure_destroy(status, quantitys, f_string_quantity) - - #define f_macro_string_quantitys_delete_simple(quantitys) f_macro_memory_structure_delete_simple(quantitys, f_string_quantity) - #define f_macro_string_quantitys_destroy_simple(quantitys) f_macro_memory_structure_destroy_simple(quantitys, f_string_quantity) - - #define f_macro_string_quantitys_resize(status, quantitys, new_length) f_macro_memory_structure_resize(status, quantitys, f_string_quantity, new_length) - #define f_macro_string_quantitys_adjust(status, quantitys, new_length) f_macro_memory_structure_adjust(status, quantitys, f_string_quantity, new_length) -#endif // _di_f_string_quantitys_ - -/** - * A string that is analogous to f_string_dynamic but intended for static-only uses. - * - * The f_string_static type should never be directly allocated or deallocated. - * - * A special f_macro_string_static_initialize() is provided for the special purpose of easily initialize a static string. - * - * string: the string. - * size: total amount of space available. - * used: total number of space used. - */ -#ifndef _di_f_string_static_ - typedef struct { - f_string string; - - f_string_length size; - f_string_length used; - } f_string_static; - - #define f_string_static_initialize { 0, 0, 0 } - - #define f_macro_string_static_clear(string_static) \ - string_static.string = 0; \ - string_static.size = 0; \ - string_static.used = 0; - - #define f_macro_string_static_initialize(string, length) { string, length, length } -#endif // _di_f_string_static_ - -/** - * A string that supports contains a size attribute to handle dynamic allocations and deallocations. - * - * Save the string size along with the string, so that strlen(..) commands can be avoided as much as possible. - * - * This is a sub-type of f_string_static, allowing it to be passed into any f_string_static type. - * It is recommended that f_string_static are not otherwise casted into f_string_dynamic to avoid potential memory allocation issues. - * - * string: the string. - * size: total amount of allocated space. - * used: total number of allocated spaces used. - */ -#ifndef _di_f_string_dynamic_ - typedef f_string_static f_string_dynamic; - - #define f_string_dynamic_initialize f_string_static_initialize - - #define f_macro_string_dynamic_clear(dynamic) f_macro_string_static_clear(dynamic) - - #define f_macro_string_dynamic_new(status, dynamic, new_length) \ - f_macro_string_dynamic_clear(dynamic) \ - status = f_memory_new((void **) & dynamic.string, sizeof(f_string), new_length); \ - if (status == F_none) { \ - dynamic.size = new_length; \ - dynamic.used = 0; \ - } - - #define f_macro_string_dynamic_delete(status, dynamic) \ - status = f_memory_delete((void **) & dynamic.string, sizeof(f_string), dynamic.size); \ - if (status == F_none) { \ - dynamic.size = 0; \ - dynamic.used = 0; \ - } - - #define f_macro_string_dynamic_destroy(status, dynamic) \ - status = f_memory_destroy((void **) & dynamic.string, sizeof(f_string), dynamic.size); \ - if (status == F_none) { \ - dynamic.size = 0; \ - dynamic.used = 0; \ - } - - #define f_macro_string_dynamic_delete_simple(dynamic) \ - f_memory_delete((void **) & dynamic.string, sizeof(f_string), dynamic.size); \ - dynamic.size = 0; \ - dynamic.used = 0; - - #define f_macro_string_dynamic_destroy_simple(dynamic) \ - f_memory_destroy((void **) & dynamic.string, sizeof(f_string), dynamic.size); \ - dynamic.size = 0; \ - dynamic.used = 0; - - #define f_macro_string_dynamic_resize(status, dynamic, new_length) \ - status = f_memory_resize((void **) & dynamic.string, sizeof(f_string), dynamic.size, new_length); \ - if (status == F_none) { \ - dynamic.size = new_length; \ - if (dynamic.used > dynamic.size) dynamic.used = new_length; \ - } - - #define f_macro_string_dynamic_adjust(status, dynamic, new_length) \ - status = f_memory_adjust((void **) & dynamic.string, sizeof(f_string), dynamic.size, new_length); \ - if (status == F_none) { \ - dynamic.size = new_length; \ - if (dynamic.used > dynamic.size) dynamic.used = new_length; \ - } -#endif // _di_f_string_dynamic_ - -/** - * An array of static strings. - * - * array: the array of static strings. - * size: total amount of space available. - * used: total number of space used. - */ -#ifndef _di_f_string_statics_ - typedef struct { - f_string_static *array; - - f_array_length size; - f_array_length used; - } f_string_statics; - - #define f_string_statics_initialize { 0, 0, 0 } - - #define f_macro_string_statics_clear(statics) \ - statics.array = 0; \ - statics.size = 0; \ - statics.used = 0; -#endif // _di_f_string_statics_ - -/** - * An array of dynamic strings. - * - * array: the array of dynamic strings. - * size: total amount of allocated space. - * used: total number of allocated spaces used. - */ -#ifndef _di_f_string_dynamics_ - typedef f_string_statics f_string_dynamics; - - #define f_string_dynamics_initialize f_string_statics_initialize - - #define f_macro_string_dynamics_clear(dynamics) f_macro_string_statics_clear(dynamics) - - #define f_macro_string_dynamics_new(status, dynamics, length) \ - f_macro_string_dynamics_clear(dynamics) \ - status = f_memory_new((void **) & dynamics.array, sizeof(f_string_dynamic), length); \ - if (status == F_none) { \ - dynamics.size = length; \ - dynamics.used = 0; \ - } - - #define f_macro_string_dynamics_delete(status, dynamics) \ - status = F_none; \ - dynamics.used = dynamics.size; \ - while (dynamics.used > 0) { \ - dynamics.used--; \ - f_macro_string_dynamic_delete(status, dynamics.array[dynamics.used]); \ - if (status != F_none) break; \ - } \ - if (status == F_none) status = f_memory_delete((void **) & dynamics.array, sizeof(f_string_dynamic), dynamics.size); \ - if (status == F_none) dynamics.size = 0; - - #define f_macro_string_dynamics_destroy(status, dynamics) \ - status = F_none; \ - dynamics.used = dynamics.size; \ - while (dynamics.used > 0) { \ - dynamics.used--; \ - f_macro_string_dynamic_destroy(status, dynamics.array[dynamics.used]); \ - if (status != F_none) break; \ - } \ - if (status == F_none) status = f_memory_destroy((void **) & dynamics.array, sizeof(f_string_dynamic), dynamics.size); \ - if (status == F_none) dynamics.size = 0; - - #define f_macro_string_dynamics_delete_simple(dynamics) \ - dynamics.used = dynamics.size; \ - while (dynamics.used > 0) { \ - dynamics.used--; \ - f_macro_string_dynamic_delete_simple(dynamics.array[dynamics.used]); \ - if (dynamics.used == 0) { \ - if (f_memory_delete((void **) & dynamics.array, sizeof(f_string_dynamic), dynamics.size)) { \ - dynamics.size = 0; \ - } \ - } \ - } - - #define f_macro_string_dynamics_destroy_simple(dynamics) \ - dynamics.used = dynamics.size; \ - while (dynamics.used > 0) { \ - dynamics.used--; \ - f_macro_string_dynamic_destroy_simple(dynamics.array[dynamics.used]); \ - if (dynamics.used == 0) { \ - if (f_memory_destroy((void **) & dynamics.array, sizeof(f_string_dynamic), dynamics.size)) { \ - dynamics.size = 0; \ - } \ - } \ - } - - #define f_macro_string_dynamics_resize(status, dynamics, new_length) \ - status = F_none; \ - if (new_length < dynamics.size) { \ - f_array_length i = dynamics.size - new_length; \ - for (; i < dynamics.size; i++) { \ - f_macro_string_dynamic_delete(status, dynamics.array[i]); \ - if (status != F_none) break; \ - } \ - } \ - if (status == F_none) status = f_memory_resize((void **) & dynamics.array, sizeof(f_string_dynamic), dynamics.size, new_length); \ - if (status == F_none) { \ - if (new_length > dynamics.size) { \ - f_array_length i = dynamics.size; \ - for (; i < new_length; i++) { \ - memset(&dynamics.array[i], 0, sizeof(f_string_dynamic)); \ - } \ - } \ - dynamics.size = new_length; \ - if (dynamics.used > dynamics.size) dynamics.used = new_length; \ - } - - #define f_macro_string_dynamics_adjust(status, dynamics, new_length) \ - status = F_none; \ - if (new_length < dynamics.size) { \ - f_array_length i = dynamics.size - new_length; \ - for (; i < dynamics.size; i++) { \ - f_macro_string_dynamic_destroy(status, dynamics.array[i], f_string_dynamic); \ - if (status != F_none) break; \ - } \ - } \ - if (status == F_none) status = f_memory_adjust((void **) & dynamics.array, sizeof(f_string_dynamic), dynamics.size, new_length); \ - if (status == F_none) { \ - if (new_length > dynamics.size) { \ - f_array_length i = dynamics.size; \ - for (; i < new_length; i++) { \ - memset(&dynamics.array[i], 0, sizeof(f_string_dynamic)); \ - } \ - } \ - dynamics.size = new_length; \ - if (dynamics.used > dynamics.size) dynamics.used = new_length; \ - } -#endif // _di_f_string_dynamics_ - -/** - * A string map consisting of a name and value. - * - * name: A string representing the map name. - * value: A string representing the map value. - */ -#ifndef _di_f_string_map_ - typedef struct { - f_string_dynamic name; - f_string_dynamic value; - } f_string_map; - - #define f_string_map_initialize { f_string_dynamic_initialize, f_string_dynamic_initialize } - - #define f_macro_string_map_clear(map) \ - map.array = 0; \ - map.size = 0; \ - map.used = 0; - - #define f_macro_string_map_delete(status, map) \ - f_macro_string_dynamic_delete(status, map.name) \ - if (status == F_none) { \ - f_macro_string_dynamic_delete(status, map.value) \ - } - - #define f_macro_string_map_destroy(status, map) \ - f_macro_string_dynamic_destroy(status, map.name) \ - if (status == F_none) { \ - f_macro_string_dynamic_destroy(status, map.value) \ - } - - #define f_macro_string_map_delete_simple(map) \ - f_macro_string_dynamic_delete_simple(map.name) \ - f_macro_string_dynamic_delete_simple(map.value) - - #define f_macro_string_map_destroy_simple(map) \ - f_macro_string_dynamic_destroy_simple(map.name) \ - f_macro_string_dynamic_destroy_simple(map.value) -#endif // _di_f_string_map_ - -/** - * An array of string maps. - * - * array: the array of string maps. - * size: total amount of allocated space. - * used: total number of allocated spaces used. - */ -#ifndef _di_f_string_maps_ - typedef struct { - f_string_map *array; - - f_array_length size; - f_array_length used; - } f_string_maps; - - #define f_string_maps_initialize f_string_statics_initialize - - #define f_macro_string_maps_clear(maps) \ - maps.array = 0; \ - maps.size = 0; \ - maps.used = 0; - - #define f_macro_string_maps_new(status, maps, length) \ - f_macro_string_maps_clear(maps) \ - status = f_memory_new((void **) & maps.array, sizeof(f_string_map), length); \ - if (status == F_none) { \ - maps.size = length; \ - maps.used = 0; \ - } - - #define f_macro_string_maps_delete(status, maps) \ - status = F_none; \ - maps.used = maps.size; \ - while (maps.used > 0) { \ - maps.used--; \ - f_macro_string_map_delete(status, maps.array[maps.used]); \ - if (status != F_none) break; \ - } \ - if (status == F_none) status = f_memory_delete((void **) & maps.array, sizeof(f_string_map), maps.size); \ - if (status == F_none) maps.size = 0; - - #define f_macro_string_maps_destroy(status, maps) \ - status = F_none; \ - maps.used = maps.size; \ - while (maps.used > 0) { \ - maps.used--; \ - f_macro_string_map_destroy(status, maps.array[maps.used]); \ - if (status != F_none) break; \ - } \ - if (status == F_none) status = f_memory_destroy((void **) & maps.array, sizeof(f_string_map), maps.size); \ - if (status == F_none) maps.size = 0; - - #define f_macro_string_maps_delete_simple(maps) \ - maps.used = maps.size; \ - while (maps.used > 0) { \ - maps.used--; \ - f_macro_string_map_delete_simple(maps.array[maps.used]); \ - if (maps.used == 0) { \ - if (f_memory_delete((void **) & maps.array, sizeof(f_string_map), maps.size)) { \ - maps.size = 0; \ - } \ - } \ - } - - #define f_macro_string_maps_destroy_simple(maps) \ - maps.used = maps.size; \ - while (maps.used > 0) { \ - maps.used--; \ - f_macro_string_map_destroy_simple(maps.array[maps.used]); \ - if (maps.used == 0) { \ - if (f_memory_destroy((void **) & maps.array, sizeof(f_string_map), maps.size)) { \ - maps.size = 0; \ - } \ - } \ - } - - #define f_macro_string_maps_resize(status, maps, new_length) \ - status = F_none; \ - if (new_length < maps.size) { \ - f_array_length i = maps.size - new_length; \ - for (; i < maps.size; i++) { \ - f_macro_string_map_delete(status, maps.array[i]); \ - if (status != F_none) break; \ - } \ - } \ - if (status == F_none) status = f_memory_resize((void **) & maps.array, sizeof(f_string_map), maps.size, new_length); \ - if (status == F_none) { \ - if (new_length > maps.size) { \ - f_array_length i = maps.size; \ - for (; i < new_length; i++) { \ - memset(&maps.array[i], 0, sizeof(f_string_map)); \ - } \ - } \ - maps.size = new_length; \ - if (maps.used > maps.size) maps.used = new_length; \ - } - - #define f_macro_string_maps_adjust(status, maps, new_length) \ - status = F_none; \ - if (new_length < maps.size) { \ - f_array_length i = maps.size - new_length; \ - for (; i < maps.size; i++) { \ - f_macro_string_map_destroy(status, maps.array[i], f_string_map); \ - if (status != F_none) break; \ - } \ - } \ - if (status == F_none) status = f_memory_adjust((void **) & maps.array, sizeof(f_string_map), maps.size, new_length); \ - if (status == F_none) { \ - if (new_length > maps.size) { \ - f_array_length i = maps.size; \ - for (; i < new_length; i++) { \ - memset(&maps.array[i], 0, sizeof(f_string_map)); \ - } \ - } \ - maps.size = new_length; \ - if (maps.used > maps.size) maps.used = new_length; \ - } -#endif // _di_f_string_maps_ - -/** - * A string map consisting of a name and multiple values. - * - * name: A string representing the map name. - * value: An array of strings representing the map value. - */ -#ifndef _di_f_string_map_multi_ - typedef struct { - f_string_dynamic name; - f_string_dynamics value; - } f_string_map_multi; - - #define f_string_map_multi_initialize { f_string_dynamic_initialize, f_string_dynamics_initialize } - - #define f_macro_string_map_multi_clear(map) \ - f_macro_string_dynamic_clear(map.name) \ - f_macro_string_dynamics_clear(map.value) - - #define f_macro_string_map_multi_delete(status, map) \ - f_macro_string_dynamic_delete(status, map.name) \ - if (status == F_none) { \ - f_macro_string_dynamics_delete(status, map.value) \ - } - - #define f_macro_string_map_multi_destroy(status, map) \ - f_macro_string_dynamic_destroy(status, map.name) \ - if (status == F_none) { \ - f_macro_string_dynamics_destroy(status, map.value) \ - } - - #define f_macro_string_map_multi_delete_simple(map) \ - f_macro_string_dynamic_delete_simple(map.name) \ - f_macro_string_dynamics_delete_simple(map.value) - - #define f_macro_string_map_multi_destroy_simple(map) \ - f_macro_string_dynamic_destroy_simple(map.name) \ - f_macro_string_dynamics_destroy_simple(map.value) -#endif // _di_f_string_map_multi_ - -/** - * An array of string maps. - * - * array: the array of string maps. - * size: total amount of allocated space. - * used: total number of allocated spaces used. - */ -#ifndef _di_f_string_map_multis_ - typedef struct { - f_string_map_multi *array; - - f_array_length size; - f_array_length used; - } f_string_map_multis; - - #define f_string_map_multis_initialize f_string_statics_initialize - - #define f_macro_string_map_multis_clear(maps) f_macro_string_statics_clear(maps) - - #define f_macro_string_map_multis_new(status, maps, length) \ - f_macro_string_map_multis_clear(maps) \ - status = f_memory_new((void **) & maps.array, sizeof(f_string_map_multi), length); \ - if (status == F_none) { \ - maps.size = length; \ - maps.used = 0; \ - } - - #define f_macro_string_map_multis_delete(status, maps) \ - status = F_none; \ - maps.used = maps.size; \ - while (maps.used > 0) { \ - maps.used--; \ - f_macro_string_map_multi_delete(status, maps.array[maps.used]); \ - if (status != F_none) break; \ - } \ - if (status == F_none) status = f_memory_delete((void **) & maps.array, sizeof(f_string_map_multi), maps.size); \ - if (status == F_none) maps.size = 0; - - #define f_macro_string_map_multis_destroy(status, maps) \ - status = F_none; \ - maps.used = maps.size; \ - while (maps.used > 0) { \ - maps.used--; \ - f_macro_string_map_multi_destroy(status, maps.array[maps.used]); \ - if (status != F_none) break; \ - } \ - if (status == F_none) status = f_memory_destroy((void **) & maps.array, sizeof(f_string_map_multi), maps.size); \ - if (status == F_none) maps.size = 0; - - #define f_macro_string_map_multis_delete_simple(maps) \ - maps.used = maps.size; \ - while (maps.used > 0) { \ - maps.used--; \ - f_macro_string_map_multi_delete_simple(maps.array[maps.used]); \ - if (maps.used == 0) { \ - if (f_memory_delete((void **) & maps.array, sizeof(f_string_map_multi), maps.size)) { \ - maps.size = 0; \ - } \ - } \ - } - - #define f_macro_string_map_multis_destroy_simple(maps) \ - maps.used = maps.size; \ - while (maps.used > 0) { \ - maps.used--; \ - f_macro_string_map_multi_destroy_simple(maps.array[maps.used]); \ - if (maps.used == 0) { \ - if (f_memory_destroy((void **) & maps.array, sizeof(f_string_map_multi), maps.size)) { \ - maps.size = 0; \ - } \ - } \ - } - - #define f_macro_string_map_multis_resize(status, maps, new_length) \ - status = F_none; \ - if (new_length < maps.size) { \ - f_array_length i = maps.size - new_length; \ - for (; i < maps.size; i++) { \ - f_macro_string_map_multi_delete(status, maps.array[i]); \ - if (status != F_none) break; \ - } \ - } \ - if (status == F_none) status = f_memory_resize((void **) & maps.array, sizeof(f_string_map_multi), maps.size, new_length); \ - if (status == F_none) { \ - if (new_length > maps.size) { \ - f_array_length i = maps.size; \ - for (; i < new_length; i++) { \ - memset(&maps.array[i], 0, sizeof(f_string_map_multi)); \ - } \ - } \ - maps.size = new_length; \ - if (maps.used > maps.size) maps.used = new_length; \ - } - - #define f_macro_string_map_multis_adjust(status, maps, new_length) \ - status = F_none; \ - if (new_length < maps.size) { \ - f_array_length i = maps.size - new_length; \ - for (; i < maps.size; i++) { \ - f_macro_string_map_multi_destroy(status, maps.array[i], f_string_map_multi); \ - if (status != F_none) break; \ - } \ - } \ - if (status == F_none) status = f_memory_adjust((void **) & maps.array, sizeof(f_string_map_multi), maps.size, new_length); \ - if (status == F_none) { \ - if (new_length > maps.size) { \ - f_array_length i = maps.size; \ - for (; i < new_length; i++) { \ - memset(&maps.array[i], 0, sizeof(f_string_map_multi)); \ - } \ - } \ - maps.size = new_length; \ - if (maps.used > maps.size) maps.used = new_length; \ - } -#endif // _di_f_string_map_multis_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_string/data/build/settings b/level_0/f_string/data/build/settings index 2167fc8..21d990d 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 +build_sources_headers string.h string-common.h string-dynamic.h string-quantity.h string-range.h build_sources_script build_sources_setting build_script yes diff --git a/level_0/f_type/c/type_array.h b/level_0/f_type/c/type_array.h index d1167bc..55ea309 100644 --- a/level_0/f_type/c/type_array.h +++ b/level_0/f_type/c/type_array.h @@ -68,16 +68,16 @@ extern "C" { #define f_macro_array_lengthss_clear(lengths) f_macro_memory_structures_clear(lengths) - #define f_macro_array_lengthss_new(status, lengths, length) f_macro_memory_structures_new(status, lengths, f_array_lengths, length) + #define f_macro_array_lengthss_new(status, lengths, length) f_macro_memory_structures_new(status, lengths, f_array_length, f_array_lengths, length) - #define f_macro_array_lengthss_delete(status, lengths) f_macro_memory_structures_delete(status, lengths, f_array_lengths) - #define f_macro_array_lengthss_destroy(status, lengths) f_macro_memory_structures_destroy(status, lengths, f_array_lengths) + #define f_macro_array_lengthss_delete(status, lengths) f_macro_memory_structures_delete(status, lengths, f_array_length, f_array_lengths) + #define f_macro_array_lengthss_destroy(status, lengths) f_macro_memory_structures_destroy(status, lengths, f_array_length, f_array_lengths) - #define f_macro_array_lengthss_delete_simple(lengths) f_macro_memory_structures_delete_simple(lengths, f_array_lengths) - #define f_macro_array_lengthss_destroy_simple(lengths) f_macro_memory_structures_destroy_simple(lengths, f_array_lengths) + #define f_macro_array_lengthss_delete_simple(lengths) f_macro_memory_structures_delete_simple(lengths, f_array_length, f_array_lengths) + #define f_macro_array_lengthss_destroy_simple(lengths) f_macro_memory_structures_destroy_simple(lengths, f_array_length, f_array_lengths) - #define f_macro_array_lengthss_resize(status, lengths, new_length) f_macro_memory_structures_resize(status, lengths, f_array_lengths, new_length) - #define f_macro_array_lengthss_adjust(status, lengths, new_length) f_macro_memory_structures_adjust(status, lengths, f_array_lengths, new_length) + #define f_macro_array_lengthss_resize(status, lengths, new_length) f_macro_memory_structures_resize(status, lengths, f_array_length, f_array_lengths, new_length) + #define f_macro_array_lengthss_adjust(status, lengths, new_length) f_macro_memory_structures_adjust(status, lengths, f_array_length, f_array_lengths, new_length) #endif // _di_f_array_lengthss_ #ifdef __cplusplus diff --git a/specifications/fss-000D.txt b/specifications/fss-000D.txt new file mode 100644 index 0000000..da41436 --- /dev/null +++ b/specifications/fss-000D.txt @@ -0,0 +1,48 @@ +# fss-0002 + +Featureless Settings Specification: 000D - Iki Text: + Iki is an unstructured WIKI-like syntax meant to be simpler than WIKI syntax. + This fss specification represents a plain text file not following any special FSS structure but instead supports the IKI syntax. + The IKI syntax may be used in any FSS specification and the specific vocabulary is defined by appending + + There is no requirement for any specific IKI vocabulary by this standard only that the given syntax is supported. + To specify the IKI vocabulary being used append the IKI vocabulary header immediately after the fss header like such: "# fss-000d iki-0001". + + The IKI syntax provides a vocabulary name with specific context associated with it followed by quoted code that is represented by the given vocabulary name. + + When IKI is encapsulated inside any FSS format, the parent FSS format rules apply and must take precedence. + Therefore additional escaping may be required. + As for this FSS format (FSS-000D), there is no structure and therefore only the IKI syntax rules apply. + + For compatibility with the FSS terminology, the Vocabulary Name is to be considered the Object and the Vocabulary value is to be considered the Content. + + Key\: + \o = any printable word character, including "_", "-", "+". + \c = any printing character, including whitespace, and any delimited quote (used as the opening quote) or a any quote (undelimited) not used as the opening quote. + \q = either a single quote (') or a double quote ("). + \x = any character. + * = 0 or more occurrences. + + Structure\: + \x*\o:\q\c\q + + Example\: + # fss-000d iki-0000 + + This is my sentence, anything can go here but sometimes I want to emphasis:"emphasize some text". + + Other times I want to render a url such as this example url: url:'http://www.example.com/url with space/'. + + There are no comments, except for maybe the FSS header. + + Quotes may be included, such as: code:"const char *string = \"My \\\"quoted\\\" C string.\";". + + Objects would be\: + 1) emphasis + 2) url + 3) code + + Contents would be\: + 1.1) emphasize some text + 2.1) http://www.example.com/url with space/ + 3.1) const char *string = "My \"quoted\" C string."; diff --git a/specifications/fss.txt b/specifications/fss.txt index f65c562..6a0e02f 100644 --- a/specifications/fss.txt +++ b/specifications/fss.txt @@ -6,6 +6,7 @@ Featureless Settings Specifications: This specification defines the following\: - Will consist of numerous different kinds of specification files, depending on the type of information stored. - As with the practice of "#!/bin/bash", the setting files MUST have the following: "# fss-????" format, such as "# fss-0001". + - Multiple sub-standards may be appended to the FSS header, using the same format structure, such as supporting IKI: "# fss-???? iki-????" (or in theory, HTML5, such as: "# fss-???? html-0005"). - With the ? representing the (hexadecimal/base-16) number that represents the particular specification structure. - All settings specifications must avoid any form of noise, relative to the data being stored. - ie: XML would be considered anti-KISS due to the extreme level of noise generated by the XML language (not easy to read). @@ -86,3 +87,4 @@ Featureless Settings Specifications: - fss-000A: Extended Reverse Mapping - fss-000B: Simple Json - fss-000C: Simple List + - fss-000D: Iki Text