From 7332ba62f1337e728508fb5b4697926c8b94503b Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 18 Sep 2020 19:37:12 -0500 Subject: [PATCH] Update: f_file, f_fss, fl_fss, fl_utf, level_3. f_file: - Fix some function ordering. - Do not use "0" to represent closed files, instead use "-1". - "0" is used for standard input, which treating this as file closed prevents piped data from being read. f_fss: - The f_string_range_t should have _t in its macros. - Updating all related code. fl_string: - Fix some function ordering. - Add fl_string_dynamic_sink_line(). - Rewrite function parameter ordering to have constants on the left and editable pointers on the right. - While I also like the logical flow of the previous behavior, during my development the practice of separating first by constants and then editable pointers won out. - Updating all related code. fl_utf: - Rewrite function parameter ordering to have constants on the left and editable pointers on the right. - While I also like the logical flow of the previous behavior, during my development the practice of separating first by constants and then editable pointers won out. - Updating all related code. level_3: - Make f_console_parameter_ids_t and f_console_parameters_t constants, where possible. More of the project will need reviewing of function parameter ordering. --- level_0/f_file/c/file.c | 166 ++++++------- level_0/f_file/c/file.h | 213 ++++++++--------- level_0/f_file/c/private-file.c | 8 +- level_0/f_fss/c/fss-common.h | 4 +- level_0/f_serialize/c/serialize.c | 2 +- level_0/f_string/c/string_range.h | 8 +- level_1/fl_conversion/c/conversion.c | 4 +- level_1/fl_fss/c/fss_basic.c | 4 +- level_1/fl_fss/c/fss_basic_list.c | 4 +- level_1/fl_fss/c/fss_extended.c | 2 +- level_1/fl_fss/c/fss_extended_list.c | 4 +- level_1/fl_fss/c/private-fss.c | 2 +- level_1/fl_string/c/string.c | 256 +++++++++----------- level_1/fl_string/c/string.h | 263 +++++++++++---------- level_1/fl_utf/c/private-utf.c | 6 + level_1/fl_utf/c/utf.c | 2 + level_1/fl_utf_file/c/utf_file.c | 4 +- level_1/fl_utf_file/c/utf_file.h | 8 +- level_2/fll_fss/c/fss.c | 2 +- level_2/fll_fss/c/fss_basic.c | 2 +- level_2/fll_fss/c/fss_basic_list.c | 2 +- level_2/fll_fss/c/fss_extended.c | 2 +- level_2/fll_fss/c/fss_extended_list.c | 2 +- level_2/fll_fss/c/private-fss.c | 4 +- level_3/byte_dump/c/byte_dump.c | 8 +- level_3/fake/c/fake.c | 4 +- level_3/fake/c/private-build.c | 2 +- level_3/fake/c/private-make.c | 88 +++---- level_3/firewall/c/firewall.c | 6 +- level_3/firewall/c/private-firewall.c | 6 +- .../fss_basic_list_read/c/fss_basic_list_read.c | 6 +- .../c/private-fss_basic_list_read.c | 10 +- .../fss_basic_list_write/c/fss_basic_list_write.c | 6 +- level_3/fss_basic_read/c/fss_basic_read.c | 6 +- level_3/fss_basic_read/c/private-fss_basic_read.c | 10 +- level_3/fss_basic_write/c/fss_basic_write.c | 6 +- .../c/fss_extended_list_read.c | 6 +- .../c/private-fss_extended_list_read.c | 12 +- level_3/fss_extended_read/c/fss_extended_read.c | 6 +- .../c/private-fss_extended_read.c | 10 +- level_3/fss_extended_write/c/fss_extended_write.c | 6 +- level_3/fss_status_code/c/fss_status_code.c | 4 +- .../fss_status_code/c/private-fss_status_code.c | 4 +- level_3/iki_read/c/iki_read.c | 14 +- level_3/iki_read/c/iki_read.h | 5 +- level_3/iki_read/c/private-iki_read.c | 12 +- level_3/init/c/init.c | 4 +- level_3/init/c/private-init.c | 6 +- level_3/status_code/c/private-status_code.c | 4 +- level_3/status_code/c/status_code.c | 4 +- 50 files changed, 605 insertions(+), 624 deletions(-) diff --git a/level_0/f_file/c/file.c b/level_0/f_file/c/file.c index ddd834b..35a7c06 100644 --- a/level_0/f_file/c/file.c +++ b/level_0/f_file/c/file.c @@ -85,10 +85,6 @@ extern "C" { #ifndef _di_f_file_close_ f_return_status f_file_close(int *id) { - #ifndef _di_level_0_parameter_checking_ - if (id == 0) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - return private_f_file_close(id); } #endif // _di_f_file_close_ @@ -1318,75 +1314,6 @@ extern "C" { } #endif // _di_f_file_mode_to_mode_ -#ifndef _di_f_file_rename_ - f_return_status f_file_rename(const f_string_t source, const f_string_t destination) { - #ifndef _di_level_0_parameter_checking_ - if (source == 0) return F_status_set_error(F_parameter); - if (destination == 0) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (rename(source, destination) < 0) { - if (errno == EACCES) return F_status_set_error(F_access_denied); - if (errno == EBUSY) return F_status_set_error(F_busy); - if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block); - if (errno == EFAULT) return F_status_set_error(F_buffer); - if (errno == EINVAL) return F_status_set_error(F_parameter); - if (errno == EISDIR) return F_status_set_error(F_file_type_directory); - if (errno == ELOOP) return F_status_set_error(F_loop); - if (errno == EMLINK) return F_status_set_error(F_link); - if (errno == ENAMETOOLONG) return F_status_set_error(F_name); - if (errno == ENOENT) return F_status_set_error(F_file_found_not); - if (errno == ENOMEM) return F_status_set_error(F_memory_out); - if (errno == ENOSPC) return F_status_set_error(F_space_not); - if (errno == ENOTDIR) return F_status_set_error(F_directory); - if (errno == ENOTEMPTY) return F_status_set_error(F_directory_empty_not); - if (errno == EEXIST) return F_status_set_error(F_directory_empty_not); - if (errno == EPERM) return F_status_set_error(F_prohibited); - if (errno == EROFS) return F_status_set_error(F_read_only); - if (errno == EXDEV) return F_status_set_error(F_mount); - - return F_status_set_error(F_failure); - } - - return F_none; - } -#endif // _di_f_file_rename_ - -#ifndef _di_f_file_rename_at_ - f_return_status f_file_rename_at(const int at_id, const int to_id, const f_string_t source, const f_string_t destination) { - #ifndef _di_level_0_parameter_checking_ - if (source == 0) return F_status_set_error(F_parameter); - if (destination == 0) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (renameat(at_id, source, to_id, destination) < 0) { - if (errno == EACCES) return F_status_set_error(F_access_denied); - if (errno == EBUSY) return F_status_set_error(F_busy); - if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block); - if (errno == EFAULT) return F_status_set_error(F_buffer); - if (errno == EINVAL) return F_status_set_error(F_parameter); - if (errno == EISDIR) return F_status_set_error(F_file_type_directory); - if (errno == ELOOP) return F_status_set_error(F_loop); - if (errno == EMLINK) return F_status_set_error(F_link); - if (errno == ENAMETOOLONG) return F_status_set_error(F_name); - if (errno == ENOENT) return F_status_set_error(F_file_found_not); - if (errno == ENOMEM) return F_status_set_error(F_memory_out); - if (errno == ENOSPC) return F_status_set_error(F_space_not); - if (errno == ENOTDIR) return F_status_set_error(F_directory); - if (errno == ENOTEMPTY) return F_status_set_error(F_directory_empty_not); - if (errno == EEXIST) return F_status_set_error(F_directory_empty_not); - if (errno == EPERM) return F_status_set_error(F_prohibited); - if (errno == EROFS) return F_status_set_error(F_read_only); - if (errno == EXDEV) return F_status_set_error(F_mount); - if (errno == EBADF) return F_status_set_error(F_directory_descriptor); - - return F_status_set_error(F_failure); - } - - return F_none; - } -#endif // _di_f_file_rename_at_ - #ifndef _di_f_file_name_base_ f_return_status f_file_name_base(const f_string_t path, const f_string_length_t length, f_string_dynamic_t *name_base) { #ifndef _di_level_0_parameter_checking_ @@ -1509,8 +1436,7 @@ extern "C" { if (buffer->used > buffer->size) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (file.id < 0) return F_status_set_error(F_file); - if (file.id == 0) return F_status_set_error(F_file_closed); + if (file.id == -1) return F_status_set_error(F_file_closed); f_status_t status = F_none; ssize_t size_read = 0; @@ -1560,8 +1486,7 @@ extern "C" { if (buffer->used > buffer->size) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (file.id < 0) return F_status_set_error(F_file); - if (file.id == 0) return F_status_set_error(F_file_closed); + if (file.id == -1) return F_status_set_error(F_file_closed); f_status_t status = F_none; ssize_t size_read = 0; @@ -1605,14 +1530,13 @@ extern "C" { #endif // _di_f_file_read_block_ #ifndef _di_f_file_read_until_ - f_return_status f_file_read_until(const f_file_t file, f_string_dynamic_t *buffer, const f_string_length_t total) { + f_return_status f_file_read_until(const f_file_t file, const f_string_length_t total, f_string_dynamic_t *buffer) { #ifndef _di_level_0_parameter_checking_ if (file.size_read == 0) return F_status_set_error(F_parameter); if (buffer->used > buffer->size) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (file.id < 0) return F_status_set_error(F_file); - if (file.id == 0) return F_status_set_error(F_file_closed); + if (file.id == -1) return F_status_set_error(F_file_closed); f_status_t status = F_none; ssize_t size_read = 0; @@ -1629,6 +1553,7 @@ extern "C" { memset(&buffer_read, 0, sizeof(buffer_size)); while (buffer_count < total && (size_read = read(file.id, buffer_read, buffer_size)) > 0) { + if (buffer->used + size_read > buffer->size) { if (buffer->size + size_read > f_string_length_t_size) { return F_status_set_error(F_string_too_large); @@ -1718,6 +1643,75 @@ extern "C" { } #endif // _di_f_file_remove_at_ +#ifndef _di_f_file_rename_ + f_return_status f_file_rename(const f_string_t source, const f_string_t destination) { + #ifndef _di_level_0_parameter_checking_ + if (source == 0) return F_status_set_error(F_parameter); + if (destination == 0) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (rename(source, destination) < 0) { + if (errno == EACCES) return F_status_set_error(F_access_denied); + if (errno == EBUSY) return F_status_set_error(F_busy); + if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block); + if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == EINVAL) return F_status_set_error(F_parameter); + if (errno == EISDIR) return F_status_set_error(F_file_type_directory); + if (errno == ELOOP) return F_status_set_error(F_loop); + if (errno == EMLINK) return F_status_set_error(F_link); + if (errno == ENAMETOOLONG) return F_status_set_error(F_name); + if (errno == ENOENT) return F_status_set_error(F_file_found_not); + if (errno == ENOMEM) return F_status_set_error(F_memory_out); + if (errno == ENOSPC) return F_status_set_error(F_space_not); + if (errno == ENOTDIR) return F_status_set_error(F_directory); + if (errno == ENOTEMPTY) return F_status_set_error(F_directory_empty_not); + if (errno == EEXIST) return F_status_set_error(F_directory_empty_not); + if (errno == EPERM) return F_status_set_error(F_prohibited); + if (errno == EROFS) return F_status_set_error(F_read_only); + if (errno == EXDEV) return F_status_set_error(F_mount); + + return F_status_set_error(F_failure); + } + + return F_none; + } +#endif // _di_f_file_rename_ + +#ifndef _di_f_file_rename_at_ + f_return_status f_file_rename_at(const int at_id, const int to_id, const f_string_t source, const f_string_t destination) { + #ifndef _di_level_0_parameter_checking_ + if (source == 0) return F_status_set_error(F_parameter); + if (destination == 0) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (renameat(at_id, source, to_id, destination) < 0) { + if (errno == EACCES) return F_status_set_error(F_access_denied); + if (errno == EBUSY) return F_status_set_error(F_busy); + if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block); + if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == EINVAL) return F_status_set_error(F_parameter); + if (errno == EISDIR) return F_status_set_error(F_file_type_directory); + if (errno == ELOOP) return F_status_set_error(F_loop); + if (errno == EMLINK) return F_status_set_error(F_link); + if (errno == ENAMETOOLONG) return F_status_set_error(F_name); + if (errno == ENOENT) return F_status_set_error(F_file_found_not); + if (errno == ENOMEM) return F_status_set_error(F_memory_out); + if (errno == ENOSPC) return F_status_set_error(F_space_not); + if (errno == ENOTDIR) return F_status_set_error(F_directory); + if (errno == ENOTEMPTY) return F_status_set_error(F_directory_empty_not); + if (errno == EEXIST) return F_status_set_error(F_directory_empty_not); + if (errno == EPERM) return F_status_set_error(F_prohibited); + if (errno == EROFS) return F_status_set_error(F_read_only); + if (errno == EXDEV) return F_status_set_error(F_mount); + if (errno == EBADF) return F_status_set_error(F_directory_descriptor); + + return F_status_set_error(F_failure); + } + + return F_none; + } +#endif // _di_f_file_rename_at_ + #ifndef _di_f_file_role_change_ f_return_status f_file_role_change(const f_string_t path, const uid_t uid, const gid_t gid, const bool dereference) { #ifndef _di_level_0_parameter_checking_ @@ -2009,8 +2003,7 @@ extern "C" { if (buffer.used > buffer.size) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (file.id < 0) return F_status_set_error(F_file); - if (file.id == 0) return F_status_set_error(F_file_closed); + if (file.id == -1) return F_status_set_error(F_file_closed); if (buffer.used == 0) { if (written) *written = 0; @@ -2045,8 +2038,7 @@ extern "C" { if (buffer.used > buffer.size) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (file.id < 0) return F_status_set_error(F_file); - if (file.id == 0) return F_status_set_error(F_file_closed); + if (file.id == -1) return F_status_set_error(F_file_closed); if (buffer.used == 0) { if (written) *written = 0; @@ -2091,8 +2083,7 @@ extern "C" { if (buffer.used > buffer.size) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (file.id < 0) return F_status_set_error(F_file); - if (file.id == 0) return F_status_set_error(F_file_closed); + if (file.id == -1) return F_status_set_error(F_file_closed); if (buffer.used == 0 || total == 0) { if (written) *written = 0; @@ -2139,8 +2130,7 @@ extern "C" { if (range.start >= buffer.used) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (file.id < 0) return F_status_set_error(F_file); - if (file.id == 0) return F_status_set_error(F_file_closed); + if (file.id == -1) return F_status_set_error(F_file_closed); if (buffer.used == 0) { if (written) *written = 0; diff --git a/level_0/f_file/c/file.h b/level_0/f_file/c/file.h index 2ffe9ea..058b04f 100644 --- a/level_0/f_file/c/file.h +++ b/level_0/f_file/c/file.h @@ -114,7 +114,7 @@ extern "C" { /** * Commonly used file related properties. * - * id: File descriptor. + * id: File descriptor, with a value of -1 represents a closed file. * flag: Flags used for opening the file. * size_read: The default number of 1-byte characters to read at a time and is often used for the read buffer size. * size_write: The default number of 1-byte characters to read at a time and is often used for the write buffer size. @@ -127,16 +127,16 @@ extern "C" { size_t size_write; } f_file_t; - #define f_file_t_initialize { 0, f_file_flag_read_only, f_file_default_read_size, f_file_default_write_size } + #define f_file_t_initialize { -1, f_file_flag_read_only, f_file_default_read_size, f_file_default_write_size } #define f_macro_file_t_clear(file) \ - file.id = 0; \ + file.id = -1; \ file.flag = 0; \ file.size_read = 0; \ file.size_write = 0; #define f_macro_file_t_reset(file) \ - file.id = 0; \ + file.id = -1; \ file.flag = f_file_flag_read_only; \ file.size_read = f_file_default_read_size; \ file.size_write = f_file_default_write_size; @@ -456,7 +456,6 @@ extern "C" { * F_filesystem_quota_block (with error bit) if filesystem's disk blocks or inodes are exhausted. * F_input_output (with error bit) on I/O error. * F_interrupted (with error bit) when program received an interrupt signal, halting operation. - * F_parameter (with error bit) if a parameter is invalid. * F_space_not (with error bit) if filesystem is out of space (or filesystem quota is reached). * * @see fclose() @@ -1446,99 +1445,6 @@ extern "C" { #endif // _di_f_file_mode_to_mode_ /** - * Rename a file. - * - * The paths must not contain NULL except for the terminating NULL. - * The paths must be NULL terminated. - * - * This essentially renames a file but can also change the file's path, which is identical to a move. - * However, renames only work within a filesystem and cannot be moved to another filesystem. - * - * If destination already exists, then according to rename(), destination will be atomically replaced. - * Which, if destination is a directory, then that directory must either not exist or be empty. - * - * @param source - * The path to the file to copy from. - * @param destination - * The path to copy to. - * - * @return - * F_none on success. - * F_access_denied (with error bit) on access denied. - * F_buffer (with error bit) if the buffer is invalid. - * F_busy (with error bit) if filesystem is too busy to perform write. - * F_directory (with error bit) if a supposed directory in path is not actually a directory. - * F_directory_empty_not (with error bit) if the destination is a non-empty directory. - * F_file_found_not (with error bit) if file at path was not found. - * F_file_type_directory (with error bit) if destination is a directory but source is not. - * F_filesystem_quota_block (with error bit) if filesystem's disk blocks or inodes are exhausted. - * F_link (with error bit) if source or destination has the maxiumum associated links. - * F_loop (with error bit) on loop error. - * F_memory_out (with error bit) if out of memory. - * F_mount (with error bit) if source and destination are not within the same mounted filesystems. - * F_name (with error bit) on path name error. - * F_parameter (with error bit) if a parameter is invalid. - * F_prohibited (with error bit) if filesystem does not allow for making changes. - * F_read_only (with error bit) if file is read-only. - * F_space_not (with error bit) if filesystem is out of space (or filesystem quota is reached). - * F_failure (with error bit) for any other error. - * - * @see rename() - */ -#ifndef _di_f_file_rename_ - extern f_return_status f_file_rename(const f_string_t source, const f_string_t destination); -#endif // _di_f_file_rename_ - -/** - * Rename a file. - * - * The paths must not contain NULL except for the terminating NULL. - * The paths must be NULL terminated. - * - * This essentially renames a file but can also change the file's path, which is identical to a move. - * However, renames only work within a filesystem and cannot be moved to another filesystem. - * - * If destination already exists, then according to rename(), destination will be atomically replaced. - * Which, if destination is a directory, then that directory must either not exist or be empty. - * - * @param at_id - * The parent directory, as an open directory file descriptor, in which the source is relative to. - * @param to_id - * The parent directory, as an open directory file descriptor, in which the destination is relative to. - * @param source - * The path to the file to copy from. - * @param destination - * The path to copy to. - * - * @return - * F_none on success. - * F_access_denied (with error bit) on access denied. - * F_buffer (with error bit) if the buffer is invalid. - * F_busy (with error bit) if filesystem is too busy to perform write. - * F_directory (with error bit) if a supposed directory in path is not actually a directory. - * F_directory_descriptor (with error bit) for bad directory descriptor for at_id or to_id. - * F_directory_empty_not (with error bit) if the destination is a non-empty directory. - * F_file_found_not (with error bit) if file at path was not found. - * F_file_type_directory (with error bit) if destination is a directory but source is not. - * F_filesystem_quota_block (with error bit) if filesystem's disk blocks or inodes are exhausted. - * F_link (with error bit) if source or destination has the maxiumum associated links. - * F_loop (with error bit) on loop error. - * F_memory_out (with error bit) if out of memory. - * F_mount (with error bit) if source and destination are not within the same mounted filesystems. - * F_name (with error bit) on path name error. - * F_parameter (with error bit) if a parameter is invalid. - * F_prohibited (with error bit) if filesystem does not allow for making changes. - * F_read_only (with error bit) if file is read-only. - * F_space_not (with error bit) if filesystem is out of space (or filesystem quota is reached). - * F_failure (with error bit) for any other error. - * - * @see renameat() - */ -#ifndef _di_f_file_rename_at_ - extern f_return_status f_file_rename_at(const int at_id, const int to_id, const f_string_t source, const f_string_t destination); -#endif // _di_f_file_rename_at_ - -/** * Get the base name of a file path. * * @param path @@ -1684,7 +1590,6 @@ extern "C" { * F_none_eof on success and EOF was reached. * F_block (with error bit) if file descriptor is set to non-block and the read would result in a blocking operation. * F_buffer (with error bit) if the buffer is invalid. - * F_file (with error bit) if file descriptor is in an error state. * F_file_closed (with error bit) if file is not open. * F_file_descriptor (with error bit) if the file descriptor is invalid. * F_file_type_directory (with error bit) if file descriptor represents a directory. @@ -1715,7 +1620,6 @@ extern "C" { * F_none_eof on success and EOF was reached. * F_block (with error bit) if file descriptor is set to non-block and the read would result in a blocking operation. * F_buffer (with error bit) if the buffer is invalid. - * F_file (with error bit) if file descriptor is in an error state. * F_file_closed (with error bit) if file is not open. * F_file_descriptor (with error bit) if the file descriptor is invalid. * F_file_type_directory (with error bit) if file descriptor represents a directory. @@ -1725,9 +1629,9 @@ extern "C" { * * @see read() */ -#ifndef _di_f_file_read_ +#ifndef _di_f_file_read_block_ extern f_return_status f_file_read_block(const f_file_t file, f_string_dynamic_t *buffer); -#endif // _di_f_file_read_ +#endif // _di_f_file_read_block_ /** * Read until a given number or EOF is reached, storing it in the buffer. @@ -1737,17 +1641,16 @@ extern "C" { * @param file * The file to read. * The file must already be open. - * @param buffer - * The buffer the file is being read into. * @param total * The total bytes to read, unless EOF is reached first. + * @param buffer + * The buffer the file is being read into. * * @return * F_none on success. * F_none_eof on success and EOF was reached. * F_block (with error bit) if file descriptor is set to non-block and the read would result in a blocking operation. * F_buffer (with error bit) if the buffer is invalid. - * F_file (with error bit) if file descriptor is in an error state. * F_file_closed (with error bit) if file is not open. * F_file_descriptor (with error bit) if the file descriptor is invalid. * F_file_type_directory (with error bit) if file descriptor represents a directory. @@ -1758,7 +1661,7 @@ extern "C" { * @see read() */ #ifndef _di_f_file_read_until_ - extern f_return_status f_file_read_until(const f_file_t file, f_string_dynamic_t *buffer, const f_string_length_t total); + extern f_return_status f_file_read_until(const f_file_t file, const f_string_length_t total, f_string_dynamic_t *buffer); #endif // _di_f_file_read_until_ /** @@ -1822,6 +1725,99 @@ extern "C" { #endif // _di_f_file_remove_at_ /** + * Rename a file. + * + * The paths must not contain NULL except for the terminating NULL. + * The paths must be NULL terminated. + * + * This essentially renames a file but can also change the file's path, which is identical to a move. + * However, renames only work within a filesystem and cannot be moved to another filesystem. + * + * If destination already exists, then according to rename(), destination will be atomically replaced. + * Which, if destination is a directory, then that directory must either not exist or be empty. + * + * @param source + * The path to the file to copy from. + * @param destination + * The path to copy to. + * + * @return + * F_none on success. + * F_access_denied (with error bit) on access denied. + * F_buffer (with error bit) if the buffer is invalid. + * F_busy (with error bit) if filesystem is too busy to perform write. + * F_directory (with error bit) if a supposed directory in path is not actually a directory. + * F_directory_empty_not (with error bit) if the destination is a non-empty directory. + * F_file_found_not (with error bit) if file at path was not found. + * F_file_type_directory (with error bit) if destination is a directory but source is not. + * F_filesystem_quota_block (with error bit) if filesystem's disk blocks or inodes are exhausted. + * F_link (with error bit) if source or destination has the maxiumum associated links. + * F_loop (with error bit) on loop error. + * F_memory_out (with error bit) if out of memory. + * F_mount (with error bit) if source and destination are not within the same mounted filesystems. + * F_name (with error bit) on path name error. + * F_parameter (with error bit) if a parameter is invalid. + * F_prohibited (with error bit) if filesystem does not allow for making changes. + * F_read_only (with error bit) if file is read-only. + * F_space_not (with error bit) if filesystem is out of space (or filesystem quota is reached). + * F_failure (with error bit) for any other error. + * + * @see rename() + */ +#ifndef _di_f_file_rename_ + extern f_return_status f_file_rename(const f_string_t source, const f_string_t destination); +#endif // _di_f_file_rename_ + +/** + * Rename a file. + * + * The paths must not contain NULL except for the terminating NULL. + * The paths must be NULL terminated. + * + * This essentially renames a file but can also change the file's path, which is identical to a move. + * However, renames only work within a filesystem and cannot be moved to another filesystem. + * + * If destination already exists, then according to rename(), destination will be atomically replaced. + * Which, if destination is a directory, then that directory must either not exist or be empty. + * + * @param at_id + * The parent directory, as an open directory file descriptor, in which the source is relative to. + * @param to_id + * The parent directory, as an open directory file descriptor, in which the destination is relative to. + * @param source + * The path to the file to copy from. + * @param destination + * The path to copy to. + * + * @return + * F_none on success. + * F_access_denied (with error bit) on access denied. + * F_buffer (with error bit) if the buffer is invalid. + * F_busy (with error bit) if filesystem is too busy to perform write. + * F_directory (with error bit) if a supposed directory in path is not actually a directory. + * F_directory_descriptor (with error bit) for bad directory descriptor for at_id or to_id. + * F_directory_empty_not (with error bit) if the destination is a non-empty directory. + * F_file_found_not (with error bit) if file at path was not found. + * F_file_type_directory (with error bit) if destination is a directory but source is not. + * F_filesystem_quota_block (with error bit) if filesystem's disk blocks or inodes are exhausted. + * F_link (with error bit) if source or destination has the maxiumum associated links. + * F_loop (with error bit) on loop error. + * F_memory_out (with error bit) if out of memory. + * F_mount (with error bit) if source and destination are not within the same mounted filesystems. + * F_name (with error bit) on path name error. + * F_parameter (with error bit) if a parameter is invalid. + * F_prohibited (with error bit) if filesystem does not allow for making changes. + * F_read_only (with error bit) if file is read-only. + * F_space_not (with error bit) if filesystem is out of space (or filesystem quota is reached). + * F_failure (with error bit) for any other error. + * + * @see renameat() + */ +#ifndef _di_f_file_rename_at_ + extern f_return_status f_file_rename_at(const int at_id, const int to_id, const f_string_t source, const f_string_t destination); +#endif // _di_f_file_rename_at_ + +/** * Change owner and/or group of a given file at the specified path. * * At least one of uid or gid must not be -1. @@ -2252,7 +2248,6 @@ extern "C" { * F_none_stop on success but no data was written (written == 0) (not an error and often happens if file type is not a regular file). * F_block (with error bit) if file descriptor is set to non-block and the write would result in a blocking operation. * F_buffer (with error bit) if the buffer is invalid. - * F_file (with error bit) if file descriptor is in an error state. * F_file_closed (with error bit) if file is not open. * F_file_descriptor (with error bit) if the file descriptor is invalid. * F_file_type_directory (with error bit) if file descriptor represents a directory. @@ -2285,7 +2280,6 @@ extern "C" { * F_none_stop on success but no data was written (written == 0) (not an error and often happens if file type is not a regular file). * F_block (with error bit) if file descriptor is set to non-block and the write would result in a blocking operation. * F_buffer (with error bit) if the buffer is invalid. - * F_file (with error bit) if file descriptor is in an error state. * F_file_closed (with error bit) if file is not open. * F_file_descriptor (with error bit) if the file descriptor is invalid. * F_file_type_directory (with error bit) if file descriptor represents a directory. @@ -2319,7 +2313,6 @@ extern "C" { * F_none_eos on success but range.stop exceeded buffer.used (only wrote up to buffer.used). * F_block (with error bit) if file descriptor is set to non-block and the write would result in a blocking operation. * F_buffer (with error bit) if the buffer is invalid. - * F_file (with error bit) if file descriptor is in an error state. * F_file_closed (with error bit) if file is not open. * F_file_descriptor (with error bit) if the file descriptor is invalid. * F_file_type_directory (with error bit) if file descriptor represents a directory. @@ -2353,8 +2346,6 @@ extern "C" { * F_none_eos on success but range.stop exceeded buffer.used (only wrote up to buffer.used). * F_block (with error bit) if file descriptor is set to non-block and the write would result in a blocking operation. * F_buffer (with error bit) if the buffer is invalid. - * F_file (with error bit) if file descriptor is in an error state. - * F_file_closed (with error bit) if file is not open. * F_file_descriptor (with error bit) if the file descriptor is invalid. * F_file_type_directory (with error bit) if file descriptor represents a directory. * F_input_output (with error bit) on I/O error. diff --git a/level_0/f_file/c/private-file.c b/level_0/f_file/c/private-file.c index 5fa715e..508f513 100644 --- a/level_0/f_file/c/private-file.c +++ b/level_0/f_file/c/private-file.c @@ -7,6 +7,8 @@ extern "C" { #if !defined(_di_f_file_close_) || !defined(_di_f_file_copy_) f_return_status private_f_file_close(int *id) { + if (*id == -1) return F_none; + if (F_status_is_error(private_f_file_flush(*id))) return F_status_set_error(F_file_synchronize); if (close(*id) < 0) { @@ -19,7 +21,7 @@ extern "C" { return F_status_set_error(F_file_close); } - *id = 0; + *id = -1; return F_none; } #endif // !defined(_di_f_file_close_) || !defined(_di_f_file_copy_) @@ -500,7 +502,7 @@ extern "C" { file->id = open(path, file->flag, mode); } - if (file->id < 0) { + if (file->id == -1) { if (errno == EACCES) return F_status_set_error(F_access_denied); if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block); if (errno == EEXIST) return F_status_set_error(F_file_found); @@ -537,7 +539,7 @@ extern "C" { file->id = openat(at_id, path, file->flag, mode); } - if (file->id < 0) { + if (file->id == -1) { if (errno == EACCES) return F_status_set_error(F_access_denied); if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block); if (errno == EEXIST) return F_status_set_error(F_file_found); diff --git a/level_0/f_fss/c/fss-common.h b/level_0/f_fss/c/fss-common.h index 9ef4305..ad84a76 100644 --- a/level_0/f_fss/c/fss-common.h +++ b/level_0/f_fss/c/fss-common.h @@ -174,9 +174,9 @@ extern "C" { #ifndef _di_fss_object_t_ typedef f_string_range_t f_fss_object_t; - #define f_fss_object_t_initialize f_string_range_initialize + #define f_fss_object_t_initialize f_string_range_t_initialize - #define f_macro_fss_object_t_clear(object) f_macro_string_range_clear(object) + #define f_macro_fss_object_t_clear(object) f_macro_string_range_t_clear(object) #endif // _di_fss_object_t_ /** diff --git a/level_0/f_serialize/c/serialize.c b/level_0/f_serialize/c/serialize.c index a50acbe..468c0ce 100644 --- a/level_0/f_serialize/c/serialize.c +++ b/level_0/f_serialize/c/serialize.c @@ -169,7 +169,7 @@ extern "C" { if (dynamic == 0) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - f_string_range_t range = f_string_range_initialize; + f_string_range_t range = f_string_range_t_initialize; f_status_t status = private_f_serialize_un_simple_find(serialize, index, &range); if (F_status_is_error(status)) return status; diff --git a/level_0/f_string/c/string_range.h b/level_0/f_string/c/string_range.h index f9a2fc6..5881fbc 100644 --- a/level_0/f_string/c/string_range.h +++ b/level_0/f_string/c/string_range.h @@ -23,7 +23,7 @@ extern "C" { * 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. + * A special f_macro_string_range_t_initialize() is provided for the special purpose of easily initialize a static string range. * * start: the start position. * stop: the stop position. @@ -34,11 +34,11 @@ extern "C" { f_string_length_t stop; } f_string_range_t; - #define f_string_range_initialize { 1, 0 } + #define f_string_range_t_initialize { 1, 0 } - #define f_macro_string_range_initialize(length) { length ? 0 : 1, length ? length - 1 : 0 } + #define f_macro_string_range_t_initialize(length) { length ? 0 : 1, length ? length - 1 : 0 } - #define f_macro_string_range_clear(range) \ + #define f_macro_string_range_t_clear(range) \ range.start = 1; \ range.stop = 0; #endif // _di_f_string_range_t_ diff --git a/level_1/fl_conversion/c/conversion.c b/level_1/fl_conversion/c/conversion.c index b0df184..bb7f05c 100644 --- a/level_1/fl_conversion/c/conversion.c +++ b/level_1/fl_conversion/c/conversion.c @@ -670,7 +670,7 @@ extern "C" { return F_status_set_error(F_number); } - f_string_range_t location_offset = f_string_range_initialize; + f_string_range_t location_offset = f_string_range_t_initialize; location_offset.start = range.start + offset; location_offset.stop = range.stop; @@ -810,7 +810,7 @@ extern "C" { return F_status_set_error(F_number); } - f_string_range_t location_offset = f_string_range_initialize; + f_string_range_t location_offset = f_string_range_t_initialize; location_offset.start = range.start + offset; location_offset.stop = range.stop; diff --git a/level_1/fl_fss/c/fss_basic.c b/level_1/fl_fss/c/fss_basic.c index a080e20..c9a4d15 100644 --- a/level_1/fl_fss/c/fss_basic.c +++ b/level_1/fl_fss/c/fss_basic.c @@ -114,8 +114,8 @@ extern "C" { if (range->start > range->stop) return F_data_not_stop; else if (range->start >= content.used) return F_data_not_eos; - f_string_range_t input_position = f_string_range_initialize; - f_string_range_t buffer_position = f_string_range_initialize; + f_string_range_t input_position = f_string_range_t_initialize; + f_string_range_t buffer_position = f_string_range_t_initialize; // ensure that there is room for the terminating newline. f_string_length_t size_allocate = destination->used + content.used + 1 + f_fss_default_allocation_step_string; diff --git a/level_1/fl_fss/c/fss_basic_list.c b/level_1/fl_fss/c/fss_basic_list.c index df0589d..63ce16a 100644 --- a/level_1/fl_fss/c/fss_basic_list.c +++ b/level_1/fl_fss/c/fss_basic_list.c @@ -396,7 +396,7 @@ extern "C" { f_status_t status = F_none; - f_string_range_t buffer_position = f_string_range_initialize; + f_string_range_t buffer_position = f_string_range_t_initialize; f_string_length_t start_position = f_string_t_initialize; f_string_length_t size_allocate = 0; f_string_length_t start_buffer = 0; @@ -524,7 +524,7 @@ extern "C" { bool is_comment = F_false; bool has_graph = F_false; - f_string_range_t buffer_position = f_string_range_initialize; + f_string_range_t buffer_position = f_string_range_t_initialize; f_string_length_t start_position = f_string_t_initialize; f_string_length_t size_allocate = 0; diff --git a/level_1/fl_fss/c/fss_extended.c b/level_1/fl_fss/c/fss_extended.c index 8d16de4..afcc442 100644 --- a/level_1/fl_fss/c/fss_extended.c +++ b/level_1/fl_fss/c/fss_extended.c @@ -70,7 +70,7 @@ extern "C" { uint8_t content_found = 0; while (range->start <= range->stop && range->start < buffer->used) { - f_string_range_t content_partial = f_string_range_initialize; + f_string_range_t content_partial = f_string_range_t_initialize; f_fss_quoted_t quoted = 0; status = private_fl_fss_basic_object_read(buffer, range, &content_partial, "ed, &delimits); diff --git a/level_1/fl_fss/c/fss_extended_list.c b/level_1/fl_fss/c/fss_extended_list.c index a7d5510..396f13e 100644 --- a/level_1/fl_fss/c/fss_extended_list.c +++ b/level_1/fl_fss/c/fss_extended_list.c @@ -772,7 +772,7 @@ extern "C" { f_status_t status = F_none; - f_string_range_t buffer_position = f_string_range_initialize; + f_string_range_t buffer_position = f_string_range_t_initialize; f_string_length_t start_position = f_string_t_initialize; f_string_length_t size_allocate = 0; f_string_length_t start_buffer = 0; @@ -901,7 +901,7 @@ extern "C" { bool is_comment = F_false; bool has_graph = F_false; - f_string_range_t buffer_position = f_string_range_initialize; + f_string_range_t buffer_position = f_string_range_t_initialize; f_string_length_t start_position = f_string_t_initialize; f_string_length_t size_allocate = 0; diff --git a/level_1/fl_fss/c/private-fss.c b/level_1/fl_fss/c/private-fss.c index f6c5cf7..30b6533 100644 --- a/level_1/fl_fss/c/private-fss.c +++ b/level_1/fl_fss/c/private-fss.c @@ -506,7 +506,7 @@ extern "C" { const f_string_length_t position_start = range->start; - f_string_range_t destination_position = f_string_range_initialize; + f_string_range_t destination_position = f_string_range_t_initialize; destination_position.start = destination->used; destination_position.stop = destination->used; diff --git a/level_1/fl_string/c/string.c b/level_1/fl_string/c/string.c index 8ebb363..eb759cc 100644 --- a/level_1/fl_string/c/string.c +++ b/level_1/fl_string/c/string.c @@ -764,6 +764,36 @@ extern "C" { } #endif // _di_fl_string_dynamic_prepend_nulless_ +#ifndef _di_fl_string_dynamic_rip_ + f_return_status fl_string_dynamic_rip(const f_string_static_t source, const f_string_range_t range, f_string_dynamic_t *destination) { + #ifndef _di_level_1_parameter_checking_ + if (source.used <= range.start) return F_status_set_error(F_parameter); + if (source.used <= range.stop) return F_status_set_error(F_parameter); + if (destination == 0) return F_status_set_error(F_parameter); + #endif // _di_level_1_parameter_checking_ + + if (source.used == 0) return F_data_not_eos; + if (range.start > range.stop) return F_data_not_stop; + + return private_fl_string_append(source.string + range.start, (range.stop - range.start) + 1, destination); + } +#endif // _di_fl_string_dynamic_rip_ + +#ifndef _di_fl_string_dynamic_rip_nulless_ + f_return_status fl_string_dynamic_rip_nulless(const f_string_static_t source, const f_string_range_t range, f_string_dynamic_t *destination) { + #ifndef _di_level_1_parameter_checking_ + if (source.used <= range.start) return F_status_set_error(F_parameter); + if (source.used <= range.stop) return F_status_set_error(F_parameter); + if (destination == 0) return F_status_set_error(F_parameter); + #endif // _di_level_1_parameter_checking_ + + if (source.used == 0) return F_data_not_eos; + if (range.start > range.stop) return F_data_not_stop; + + return private_fl_string_append_nulless(source.string + range.start, (range.stop - range.start) + 1, destination); + } +#endif // _di_fl_string_dynamic_rip_nulless_ + #ifndef _di_fl_string_dynamic_size_decrease_ f_return_status fl_string_dynamic_size_decrease(const f_string_length_t length, f_string_dynamic_t *string) { #ifndef _di_level_1_parameter_checking_ @@ -795,96 +825,40 @@ extern "C" { } #endif // _di_fl_string_dynamic_size_increase_ -#ifndef _di_fl_string_dynamics_size_decrease_ - f_return_status fl_string_dynamics_size_decrease(const f_array_length_t length, f_string_dynamics_t *strings) { - #ifndef _di_level_1_parameter_checking_ - if (length == 0) return F_status_set_error(F_parameter); - if (strings == 0) return F_status_set_error(F_parameter); - #endif // _di_level_1_parameter_checking_ - - f_status_t status = F_none; - - if (strings->size - length > 0) { - f_macro_string_dynamics_resize(status, (*strings), strings->size - length); - } - else if (strings->size - length <= 0) { - f_macro_string_dynamics_t_delete(status, (*strings)); - } - - return status; - } -#endif // _di_fl_string_dynamics_size_decrease_ - -#ifndef _di_fl_string_dynamics_size_increase_ - f_return_status fl_string_dynamics_size_increase(const f_array_length_t length, f_string_dynamics_t *strings) { +#ifndef _di_fl_string_dynamic_seek_line_ + f_return_status fl_string_dynamic_seek_line(const f_string_t string, f_string_range_t *range) { #ifndef _di_level_1_parameter_checking_ - if (length == 0) return F_status_set_error(F_parameter); - if (strings == 0) return F_status_set_error(F_parameter); - #endif // _di_level_1_parameter_checking_ - - f_status_t status = F_none; - - if (strings->size + length > f_array_length_t_size) { - if (strings->size == f_array_length_t_size) { - return F_status_set_error(F_string_too_large); - } - - f_macro_string_dynamics_resize(status, (*strings), f_array_length_t_size); - return F_string_too_large; - } - - f_macro_string_dynamics_resize(status, (*strings), strings->size + length); - return status; - } -#endif // _di_fl_string_dynamics_size_increase_ - -#ifndef _di_fl_string_dynamic_rip_ - f_return_status fl_string_dynamic_rip(const f_string_static_t source, const f_string_range_t range, f_string_dynamic_t *destination) { - #ifndef _di_level_1_parameter_checking_ - if (source.used <= range.start) return F_status_set_error(F_parameter); - if (source.used <= range.stop) return F_status_set_error(F_parameter); - if (destination == 0) return F_status_set_error(F_parameter); + if (range == 0) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ - if (source.used == 0) return F_data_not_eos; - if (range.start > range.stop) return F_data_not_stop; - - return private_fl_string_append(source.string + range.start, (range.stop - range.start) + 1, destination); - } -#endif // _di_fl_string_dynamic_rip_ + if (!string) return F_data_not; + if (range->start > range->stop) return F_data_not_stop; -#ifndef _di_fl_string_dynamic_rip_nulless_ - f_return_status fl_string_dynamic_rip_nulless(const f_string_static_t source, const f_string_range_t range, f_string_dynamic_t *destination) { - #ifndef _di_level_1_parameter_checking_ - if (source.used <= range.start) return F_status_set_error(F_parameter); - if (source.used <= range.stop) return F_status_set_error(F_parameter); - if (destination == 0) return F_status_set_error(F_parameter); - #endif // _di_level_1_parameter_checking_ + while (string[range->start] != f_string_eol[0]) { + range->start++; - if (source.used == 0) return F_data_not_eos; - if (range.start > range.stop) return F_data_not_stop; + if (range->start > range->stop) return F_none_stop; + } // while - return private_fl_string_append_nulless(source.string + range.start, (range.stop - range.start) + 1, destination); + return F_none; } -#endif // _di_fl_string_dynamic_rip_nulless_ +#endif // _di_fl_string_dynamic_seek_line_ #ifndef _di_fl_string_dynamic_seek_line_to_ - f_return_status fl_string_dynamic_seek_line_to(const f_string_static_t buffer, f_string_range_t *range, const int8_t seek_to_this) { + f_return_status fl_string_dynamic_seek_line_to(const f_string_t string, f_string_range_t *range, const int8_t seek_to_this) { #ifndef _di_level_1_parameter_checking_ if (range == 0) return F_status_set_error(F_parameter); - if (buffer.used <= range->start) return F_status_set_error(F_parameter); - if (buffer.used <= range->stop) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ - if (buffer.used == 0) return F_data_not_eos; + if (!string) return F_data_not; if (range->start > range->stop) return F_data_not_stop; - while (buffer.string[range->start] != seek_to_this) { - if (buffer.string[range->start] == f_string_eol[0]) return F_none_eol; + while (string[range->start] != seek_to_this) { + + if (string[range->start] == f_string_eol[0]) return F_none_eol; range->start++; - if (range->start >= buffer.used) return F_none_eos; if (range->start > range->stop) return F_none_stop; } // while @@ -893,14 +867,12 @@ extern "C" { #endif // _di_fl_string_dynamic_seek_line_to_ #ifndef _di_fl_string_dynamic_seek_line_to_utf_character_ - f_return_status fl_string_dynamic_seek_line_to_utf_character(const f_string_static_t buffer, f_string_range_t *range, const f_utf_character_t seek_to_this) { + f_return_status fl_string_dynamic_seek_line_to_utf_character(const f_string_t string, f_string_range_t *range, const f_utf_character_t seek_to_this) { #ifndef _di_level_1_parameter_checking_ if (range == 0) return F_status_set_error(F_parameter); - if (buffer.used <= range->start) return F_status_set_error(F_parameter); - if (buffer.used <= range->stop) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ - if (buffer.used == 0) return F_data_not_eos; + if (!string) return F_data_not; if (range->start > range->stop) return F_data_not_stop; const unsigned short seek_width = f_macro_utf_character_t_width(seek_to_this); @@ -911,22 +883,17 @@ extern "C" { f_string_length_t width_max = 0; - while (range->start < buffer.used) { + while (range->start <= range->stop) { width_max = (range->stop - range->start) + 1; - - if (width_max > buffer.used - range->start) { - width_max = buffer.used - range->start; - } - - width = f_macro_utf_byte_width_is(buffer.string[range->start]); + width = f_macro_utf_byte_width_is(string[range->start]); if (width == 0) { width = 1; - if (buffer.string[range->start] == f_string_eol[0]) return F_none_eol; + if (string[range->start] == f_string_eol[0]) return F_none_eol; if (seek_width == width) { - if (buffer.string[range->start] == seek_to_this) return F_none; + if (string[range->start] == seek_to_this) return F_none; } } // Do not operate on UTF-8 fragments that are not the first byte of the character. @@ -934,12 +901,12 @@ extern "C" { return F_status_set_error(F_incomplete_utf); } else { - if (range->start + width >= buffer.used) return F_status_set_error(F_incomplete_utf_eos); if (range->start + width > range->stop) return F_status_set_error(F_incomplete_utf_stop); if (width == seek_width) { f_utf_character_t character = 0; - status = f_utf_char_to_character(buffer.string + range->start, width_max, &character); + + status = f_utf_char_to_character(string + range->start, width_max, &character); if (F_status_is_error(status)) return status; if (character == seek_to_this) return F_none; @@ -956,14 +923,12 @@ extern "C" { #endif // _di_fl_string_dynamic_seek_line_to_utf_character_ #ifndef _di_fl_string_dynamic_seek_line_until_graph_ - f_return_status fl_string_dynamic_seek_line_until_graph(const f_string_static_t buffer, f_string_range_t *range, const int8_t placeholder) { + f_return_status fl_string_dynamic_seek_line_until_graph(const f_string_t string, f_string_range_t *range, const int8_t placeholder) { #ifndef _di_level_1_parameter_checking_ if (range == 0) return F_status_set_error(F_parameter); - if (buffer.used <= range->start) return F_status_set_error(F_parameter); - if (buffer.used <= range->stop) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ - if (buffer.used == 0) return F_data_not_eos; + if (!string) return F_data_not; if (range->start > range->stop) return F_data_not_stop; f_status_t status = F_none; @@ -971,15 +936,12 @@ extern "C" { f_string_length_t width_max = (range->stop - range->start) + 1; - if (width_max > buffer.used - range->start) { - width_max = buffer.used - range->start; - } + while (string[range->start] == placeholder || (status = f_utf_is_graph(string + range->start, width_max)) == F_false) { - while (buffer.string[range->start] == placeholder || (status = f_utf_is_graph(buffer.string + range->start, width_max)) == F_false) { if (F_status_is_error(status)) return status; - if (buffer.string[range->start] == f_string_eol[0]) return F_none_eol; + if (string[range->start] == f_string_eol[0]) return F_none_eol; - width = f_macro_utf_byte_width_is(buffer.string[range->start]); + width = f_macro_utf_byte_width_is(string[range->start]); if (width == 0) { width = 1; @@ -989,20 +951,14 @@ extern "C" { return F_status_set_error(F_incomplete_utf); } else { - if (range->start + width >= buffer.used) return F_status_set_error(F_incomplete_utf_eos); if (range->start + width > range->stop) return F_status_set_error(F_incomplete_utf_stop); } range->start += width; - if (range->start >= buffer.used) return F_none_eos; if (range->start > range->stop) return F_none_stop; width_max = (range->stop - range->start) + 1; - - if (width_max > buffer.used - range->start) { - width_max = buffer.used - range->start; - } } // while if (F_status_is_error(status)) return status; @@ -1012,14 +968,12 @@ extern "C" { #endif // _di_fl_string_dynamic_seek_line_until_graph_ #ifndef _di_fl_string_dynamic_seek_line_until_non_graph_ - f_return_status fl_string_dynamic_seek_line_until_non_graph(const f_string_static_t buffer, f_string_range_t *range, const int8_t placeholder) { + f_return_status fl_string_dynamic_seek_line_until_non_graph(const f_string_t string, f_string_range_t *range, const int8_t placeholder) { #ifndef _di_level_1_parameter_checking_ if (range == 0) return F_status_set_error(F_parameter); - if (buffer.used <= range->start) return F_status_set_error(F_parameter); - if (buffer.used <= range->stop) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ - if (buffer.used == 0) return F_data_not_eos; + if (!string) return F_data_not; if (range->start > range->stop) return F_data_not_stop; f_status_t status = F_none; @@ -1027,15 +981,11 @@ extern "C" { f_string_length_t width_max = (range->stop - range->start) + 1; - if (width_max > buffer.used - range->start) { - width_max = buffer.used - range->start; - } - - while (buffer.string[range->start] == placeholder || (status = f_utf_is_whitespace(buffer.string + range->start, width_max)) == F_false) { + while (string[range->start] == placeholder || (status = f_utf_is_whitespace(string + range->start, width_max)) == F_false) { if (F_status_is_error(status)) return status; - if (buffer.string[range->start] == f_string_eol[0]) return F_none_eol; + if (string[range->start] == f_string_eol[0]) return F_none_eol; - width = f_macro_utf_byte_width_is(buffer.string[range->start]); + width = f_macro_utf_byte_width_is(string[range->start]); if (width == 0) { width = 1; @@ -1045,20 +995,14 @@ extern "C" { return F_status_set_error(F_incomplete_utf); } else { - if (range->start + width >= buffer.used) return F_status_set_error(F_incomplete_utf_eos); if (range->start + width > range->stop) return F_status_set_error(F_incomplete_utf_stop); } range->start += width; - if (range->start >= buffer.used) return F_none_eos; if (range->start > range->stop) return F_none_stop; width_max = (range->stop - range->start) + 1; - - if (width_max > buffer.used - range->start) { - width_max = buffer.used - range->start; - } } // while if (F_status_is_error(status)) return status; @@ -1068,20 +1012,17 @@ extern "C" { #endif // _di_fl_string_dynamic_seek_line_until_non_graph_ #ifndef _di_fl_string_dynamic_seek_to_ - f_return_status fl_string_dynamic_seek_to(const f_string_static_t buffer, f_string_range_t *range, const int8_t seek_to_this) { + f_return_status fl_string_dynamic_seek_to(const f_string_t string, f_string_range_t *range, const int8_t seek_to_this) { #ifndef _di_level_1_parameter_checking_ if (range == 0) return F_status_set_error(F_parameter); - if (buffer.used <= range->start) return F_status_set_error(F_parameter); - if (buffer.used <= range->stop) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ - if (buffer.used == 0) return F_data_not_eos; + if (!string) return F_data_not; if (range->start > range->stop) return F_data_not_stop; - while (buffer.string[range->start] != seek_to_this) { + while (string[range->start] != seek_to_this) { range->start++; - if (range->start >= buffer.used) return F_none_eos; if (range->start > range->stop) return F_none_stop; } // while @@ -1090,14 +1031,12 @@ extern "C" { #endif // _di_fl_string_dynamic_seek_to_ #ifndef _di_fl_string_dynamic_seek_to_utf_character_ - f_return_status fl_string_dynamic_seek_to_utf_character(const f_string_static_t buffer, f_string_range_t *range, const f_utf_character_t seek_to_this) { + f_return_status fl_string_dynamic_seek_to_utf_character(const f_string_t string, f_string_range_t *range, const f_utf_character_t seek_to_this) { #ifndef _di_level_1_parameter_checking_ if (range == 0) return F_status_set_error(F_parameter); - if (buffer.used <= range->start) return F_status_set_error(F_parameter); - if (buffer.used <= range->stop) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ - if (buffer.used == 0) return F_data_not_eos; + if (!string) return F_data_not; if (range->start > range->stop) return F_data_not_stop; const unsigned short seek_width = f_macro_utf_character_t_width(seek_to_this); @@ -1108,20 +1047,15 @@ extern "C" { f_string_length_t width_max = 0; - while (range->start < buffer.used) { + while (range->start <= range->stop) { width_max = (range->stop - range->start) + 1; - - if (width_max > buffer.used - range->start) { - width_max = buffer.used - range->start; - } - - width = f_macro_utf_byte_width_is(buffer.string[range->start]); + width = f_macro_utf_byte_width_is(string[range->start]); if (width == 0) { width = 1; if (seek_width == width) { - if (buffer.string[range->start] == seek_to_this) return F_none; + if (string[range->start] == seek_to_this) return F_none; } } // Do not operate on UTF-8 fragments that are not the first byte of the character. @@ -1129,12 +1063,11 @@ extern "C" { return F_status_set_error(F_incomplete_utf); } else { - if (range->start + width >= buffer.used) return F_status_set_error(F_incomplete_utf_eos); if (range->start + width > range->stop) return F_status_set_error(F_incomplete_utf_stop); if (width == seek_width) { f_utf_character_t character = 0; - status = f_utf_char_to_character(buffer.string + range->start, width_max, &character); + status = f_utf_char_to_character(string + range->start, width_max, &character); if (F_status_is_error(status)) return status; if (character == seek_to_this) return F_none; @@ -1209,6 +1142,49 @@ extern "C" { } #endif // _di_fl_string_dynamic_terminate_after_ +#ifndef _di_fl_string_dynamics_size_decrease_ + f_return_status fl_string_dynamics_size_decrease(const f_array_length_t length, f_string_dynamics_t *strings) { + #ifndef _di_level_1_parameter_checking_ + if (length == 0) return F_status_set_error(F_parameter); + if (strings == 0) return F_status_set_error(F_parameter); + #endif // _di_level_1_parameter_checking_ + + f_status_t status = F_none; + + if (strings->size - length > 0) { + f_macro_string_dynamics_resize(status, (*strings), strings->size - length); + } + else if (strings->size - length <= 0) { + f_macro_string_dynamics_t_delete(status, (*strings)); + } + + return status; + } +#endif // _di_fl_string_dynamics_size_decrease_ + +#ifndef _di_fl_string_dynamics_size_increase_ + f_return_status fl_string_dynamics_size_increase(const f_array_length_t length, f_string_dynamics_t *strings) { + #ifndef _di_level_1_parameter_checking_ + if (length == 0) return F_status_set_error(F_parameter); + if (strings == 0) return F_status_set_error(F_parameter); + #endif // _di_level_1_parameter_checking_ + + f_status_t status = F_none; + + if (strings->size + length > f_array_length_t_size) { + if (strings->size == f_array_length_t_size) { + return F_status_set_error(F_string_too_large); + } + + f_macro_string_dynamics_resize(status, (*strings), f_array_length_t_size); + return F_string_too_large; + } + + f_macro_string_dynamics_resize(status, (*strings), strings->size + length); + return status; + } +#endif // _di_fl_string_dynamics_size_increase_ + #ifndef _di_fl_string_lengths_size_decrease_ f_return_status fl_string_lengths_size_decrease(const f_array_length_t length, f_string_lengths_t *lengths) { #ifndef _di_level_1_parameter_checking_ diff --git a/level_1/fl_string/c/string.h b/level_1/fl_string/c/string.h index 066574a..757115b 100644 --- a/level_1/fl_string/c/string.h +++ b/level_1/fl_string/c/string.h @@ -1057,54 +1057,60 @@ extern "C" { #endif // _di_fl_string_dynamic_prepend_nulless_ /** - * Resize the dynamic string to a smaller size. + * Allocate a new string from the provided range in the buffer. * - * This will resize making the string smaller based on the given length. - * If the given length is too small, then the resize will fail. - * This will not shrink the size to less than 0. + * Ignores leading and trailing whitespace. + * As a result, resulting size may be smaller than requested range. * - * @param length - * A positive number greater than 0 representing how much to decrease the size by. - * @param string - * The string to resize. + * @param source + * The buffer to rip from. + * @param range + * A range within the buffer representing the string to rip. + * @param destination + * The new string, which will be allocated or reallocated as necessary. * * @return * F_none on success. + * F_data_not_eos if source length is 0. + * F_data_not_stop if range.start > range.stop. * F_memory_allocation (with error bit) on memory allocation error. * F_memory_reallocation (with error bit) on memory reallocation error. * F_parameter (with error bit) if a parameter is invalid. * F_string_too_large (with error bit) if the combined string is too large. */ -#ifndef _di_fl_string_dynamic_size_decrease_ - extern f_return_status fl_string_dynamic_size_decrease(const f_string_length_t length, f_string_dynamic_t *string); -#endif // _di_fl_string_dynamic_size_decrease_ +#ifndef _di_fl_string_dynamic_rip_ + extern f_return_status fl_string_dynamic_rip(const f_string_static_t source, const f_string_range_t range, f_string_dynamic_t *destination); +#endif // _di_fl_string_dynamic_rip_ /** - * Resize the dynamic string to a larger size. + * Allocate a new string from the provided range in the buffer. * - * This will resize making the string larger based on the given length. - * If the given length is too large for the buffer, then attempt to set max buffer size (f_string_length_t_size). - * If already set to the maximum buffer size, then the resize will fail. + * Ignores leading and trailing whitespace. + * As a result, resulting size may be smaller than requested range. * - * @param length - * A positive number greater than 0 representing how much to increase the size by. - * @param string - * The string to resize. + * Skips over NULL characters from source when appending. + * + * @param source + * The string to rip from. + * @param range + * A range within the buffer representing the string to rip. + * @param destination + * The new string, which will be allocated or reallocated as necessary. * * @return * F_none on success. - * F_string_too_large on success, but the requested length is too large for the buffer. + * F_data_not_eos if source length is 0. + * F_data_not_stop if range.start > range.stop. * F_memory_allocation (with error bit) on memory allocation error. * F_memory_reallocation (with error bit) on memory reallocation error. * F_parameter (with error bit) if a parameter is invalid. - * F_string_too_large (with error bit) if the combined string is too large. */ -#ifndef _di_fl_string_dynamic_size_increase_ - extern f_return_status fl_string_dynamic_size_increase(const f_string_length_t length, f_string_dynamic_t *string); -#endif // _di_fl_string_dynamic_size_increase_ +#ifndef _di_fl_string_dynamic_rip_nulless_ + extern f_return_status fl_string_dynamic_rip_nulless(const f_string_static_t source, const f_string_range_t range, f_string_dynamic_t *destination); +#endif // _di_fl_string_dynamic_rip_nulless_ /** - * Resize the array of dynamic strings to a smaller size. + * Resize the dynamic string to a smaller size. * * This will resize making the string smaller based on the given length. * If the given length is too small, then the resize will fail. @@ -1112,8 +1118,8 @@ extern "C" { * * @param length * A positive number greater than 0 representing how much to decrease the size by. - * @param strings - * The string array to resize. + * @param string + * The string to resize. * * @return * F_none on success. @@ -1122,21 +1128,21 @@ extern "C" { * F_parameter (with error bit) if a parameter is invalid. * F_string_too_large (with error bit) if the combined string is too large. */ -#ifndef _di_fl_string_dynamics_size_decrease_ - extern f_return_status fl_string_dynamics_size_decrease(const f_array_length_t length, f_string_dynamics_t *strings); -#endif // _di_fl_string_dynamics_size_decrease_ +#ifndef _di_fl_string_dynamic_size_decrease_ + extern f_return_status fl_string_dynamic_size_decrease(const f_string_length_t length, f_string_dynamic_t *string); +#endif // _di_fl_string_dynamic_size_decrease_ /** - * Resize the array of dynamic strings to a larger size. + * Resize the dynamic string to a larger size. * * This will resize making the string larger based on the given length. - * If the given length is too large for the buffer, then attempt to set max buffer size (f_array_length_t_size). + * If the given length is too large for the buffer, then attempt to set max buffer size (f_string_length_t_size). * If already set to the maximum buffer size, then the resize will fail. * * @param length * A positive number greater than 0 representing how much to increase the size by. - * @param strings - * The string array to resize. + * @param string + * The string to resize. * * @return * F_none on success. @@ -1146,68 +1152,35 @@ extern "C" { * F_parameter (with error bit) if a parameter is invalid. * F_string_too_large (with error bit) if the combined string is too large. */ -#ifndef _di_fl_string_dynamics_size_increase_ - extern f_return_status fl_string_dynamics_size_increase(const f_array_length_t length, f_string_dynamics_t *strings); -#endif // _di_fl_string_dynamics_size_increase_ - -/** - * Allocate a new string from the provided range in the buffer. - * - * Ignores leading and trailing whitespace. - * As a result, resulting size may be smaller than requested range. - * - * @param source - * The buffer to rip from. - * @param range - * A range within the buffer representing the string to rip. - * @param destination - * The new string, which will be allocated or reallocated as necessary. - * - * @return - * F_none on success. - * F_data_not_eos if source length is 0. - * F_data_not_stop if range.start > range.stop. - * F_memory_allocation (with error bit) on memory allocation error. - * F_memory_reallocation (with error bit) on memory reallocation error. - * F_parameter (with error bit) if a parameter is invalid. - * F_string_too_large (with error bit) if the combined string is too large. - */ -#ifndef _di_fl_string_dynamic_rip_ - extern f_return_status fl_string_dynamic_rip(const f_string_static_t source, const f_string_range_t range, f_string_dynamic_t *destination); -#endif // _di_fl_string_dynamic_rip_ +#ifndef _di_fl_string_dynamic_size_increase_ + extern f_return_status fl_string_dynamic_size_increase(const f_string_length_t length, f_string_dynamic_t *string); +#endif // _di_fl_string_dynamic_size_increase_ /** - * Allocate a new string from the provided range in the buffer. - * - * Ignores leading and trailing whitespace. - * As a result, resulting size may be smaller than requested range. - * - * Skips over NULL characters from source when appending. + * Seek the buffer location forward until EOL is reached. * - * @param source - * The string to rip from. + * @param string + * The string to traverse. * @param range - * A range within the buffer representing the string to rip. - * @param destination - * The new string, which will be allocated or reallocated as necessary. + * A range within the buffer representing the start and stop locations. + * The start location will be incremented by seek. * * @return * F_none on success. - * F_data_not_eos if source length is 0. - * F_data_not_stop if range.start > range.stop. - * F_memory_allocation (with error bit) on memory allocation error. - * F_memory_reallocation (with error bit) on memory reallocation error. + * F_none_stop on success, but stopped at end of range. + * F_data_not on success, but there was no string data to seek. + * F_data_not_stop on success, but the range.start > range.stop. * F_parameter (with error bit) if a parameter is invalid. */ -#ifndef _di_fl_string_dynamic_rip_nulless_ - extern f_return_status fl_string_dynamic_rip_nulless(const f_string_static_t source, const f_string_range_t range, f_string_dynamic_t *destination); -#endif // _di_fl_string_dynamic_rip_nulless_ +#ifndef _di_fl_string_dynamic_seek_line_ + extern f_return_status fl_string_dynamic_seek_line(const f_string_t string, f_string_range_t *range); +#endif // _di_fl_string_dynamic_seek_line_ /** * Seek the buffer location forward until the character (1-byte wide) or EOL is reached. * - * @param buffer - * The buffer to traverse. + * @param string + * The string to traverse. * @param range * A range within the buffer representing the start and stop locations. * The start location will be incremented by seek. @@ -1217,21 +1190,20 @@ extern "C" { * @return * F_none on success. * F_none_eol on success, but stopped at EOL. - * F_none_eos on success, but stopped at end of buffer. - * F_none_stop on success, but stopped stop location. - * F_data_not_eos if buffer length is 0. - * F_data_not_stop if range.start > range.stop. + * F_none_stop on success, but stopped at end of range. + * F_data_not on success, but there was no string data to seek. + * F_data_not_stop on success, but the range.start > range.stop. * F_parameter (with error bit) if a parameter is invalid. */ #ifndef _di_fl_string_dynamic_seek_line_to_ - extern f_return_status fl_string_dynamic_seek_line_to(const f_string_static_t buffer, f_string_range_t *range, const int8_t seek_to_this); + extern f_return_status fl_string_dynamic_seek_line_to(const f_string_t string, f_string_range_t *range, const int8_t seek_to_this); #endif // _di_fl_string_dynamic_seek_line_to_ /** * Seek the buffer location forward until the character (up to 4-byte wide) or EOL is reached. * - * @param buffer - * The buffer to traverse. + * @param string + * The string to traverse. * @param range * A range within the buffer representing the start and stop locations. * The start location will be incremented by seek. @@ -1241,11 +1213,10 @@ extern "C" { * @return * F_none on success. * F_none_eol on success, but stopped at EOL. - * F_none_eos on success, but stopped at end of buffer. - * F_data_not_eos if buffer length is 0. - * F_data_not_stop if range.start > range.stop. + * F_none_stop on success, but stopped at end of range. + * F_data_not on success, but there was no string data to seek. + * F_data_not_stop on success, but the range.start > range.stop. * F_incomplete_utf (with error bit) if character is an incomplete UTF-8 fragment. - * F_incomplete_utf_eos (with error bit) if end of string is reached before a complete UTF-8 character can be processed. * F_incomplete_utf_stop (with error bit) if the stop location is reached before the complete UTF-8 character can be processed. * F_parameter (with error bit) if a parameter is invalid. * F_utf (with error bit) if character is an invalid UTF-8 character. @@ -1255,14 +1226,14 @@ extern "C" { * @see f_utf_char_to_character() */ #ifndef _di_fl_string_dynamic_seek_line_to_utf_character_ - extern f_return_status fl_string_dynamic_seek_line_to_utf_character(const f_string_static_t buffer, f_string_range_t *range, const f_utf_character_t seek_to_this); + extern f_return_status fl_string_dynamic_seek_line_to_utf_character(const f_string_t string, f_string_range_t *range, const f_utf_character_t seek_to_this); #endif // _di_fl_string_dynamic_seek_line_to_utf_character_ /** * Increment buffer location until a graph character (including UTF-8) or an EOL is matched. * - * @param buffer - * The buffer to traverse. + * @param string + * The string to traverse. * @param range * A range within the buffer representing the start and stop locations. * @param placeholder @@ -1271,11 +1242,10 @@ extern "C" { * @return * F_none on success. * F_none_eol on success, but stopped at EOL. - * F_none_eos on success, but stopped at end of buffer. - * F_data_not_eos if buffer length is 0. - * F_data_not_stop if range.start > range.stop. + * F_none_stop on success, but stopped at end of range. + * F_data_not on success, but there was no string data to seek. + * F_data_not_stop on success, but the range.start > range.stop. * F_incomplete_utf (with error bit) if character is an incomplete UTF-8 fragment. - * F_incomplete_utf_eos (with error bit) if end of string is reached before a complete UTF-8 character can be processed. * F_incomplete_utf_stop (with error bit) if the stop location is reached before the complete UTF-8 character can be processed. * F_memory_allocation (with error bit) on memory allocation error. * F_memory_reallocation (with error bit) on memory reallocation error. @@ -1286,14 +1256,14 @@ extern "C" { * @see f_utf_is_graph() */ #ifndef _di_fl_string_dynamic_seek_line_until_graph_ - extern f_return_status fl_string_dynamic_seek_line_until_graph(const f_string_static_t buffer, f_string_range_t *range, const int8_t placeholder); + extern f_return_status fl_string_dynamic_seek_line_until_graph(const f_string_t string, f_string_range_t *range, const int8_t placeholder); #endif // _di_fl_string_dynamic_seek_line_until_graph_ /** * Increment buffer location until a non-graph character (including UTF-8) or an EOL is matched. * - * @param buffer - * The buffer to traverse. + * @param string + * The string to traverse. * @param range * A range within the buffer representing the start and stop locations. * @param placeholder @@ -1302,12 +1272,10 @@ extern "C" { * @return * F_none on success. * F_none_eol on success, but stopped at EOL. - * F_none_eos on success, but stopped at end of buffer. - * F_none_stop on success, but stopped stop location. - * F_data_not_eos if buffer length is 0. - * F_data_not_stop if range.start > range.stop. + * F_none_stop on success, but stopped at end of range. + * F_data_not on success, but there was no string data to seek. + * F_data_not_stop on success, but the range.start > range.stop. * F_incomplete_utf (with error bit) if character is an incomplete UTF-8 fragment. - * F_incomplete_utf_eos (with error bit) if end of string is reached before a complete UTF-8 character can be processed. * F_incomplete_utf_stop (with error bit) if the stop location is reached before the complete UTF-8 character can be processed. * F_memory_allocation (with error bit) on memory allocation error. * F_memory_reallocation (with error bit) on memory reallocation error. @@ -1318,14 +1286,14 @@ extern "C" { * @see f_utf_is_graph() */ #ifndef _di_fl_string_dynamic_seek_line_until_non_graph_ - extern f_return_status fl_string_dynamic_seek_line_until_non_graph(const f_string_static_t buffer, f_string_range_t *range, const int8_t placeholder); + extern f_return_status fl_string_dynamic_seek_line_until_non_graph(const f_string_t string, f_string_range_t *range, const int8_t placeholder); #endif // _di_fl_string_dynamic_seek_line_until_non_graph_ /** * Seek the buffer location forward until the character (1-byte wide) is reached. * - * @param buffer - * The buffer to traverse. + * @param string + * The string to traverse. * @param range * A range within the buffer representing the start and stop locations. * The start location will be incremented by seek. @@ -1334,24 +1302,22 @@ extern "C" { * * @return * F_none on success. - * F_none_eos on success, but stopped at end of buffer. - * F_none_stop on success, but stopped stop location. - * F_data_not_eos if buffer length is 0. - * F_data_not_stop if range.start > range.stop. + * F_none_stop on success, but stopped at end of range. + * F_data_not on success, but there was no string data to seek. + * F_data_not_stop on success, but the range.start > range.stop. * F_incomplete_utf (with error bit) if character is an incomplete UTF-8 fragment. - * F_incomplete_utf_eos (with error bit) if end of string is reached before a complete UTF-8 character can be processed. * F_incomplete_utf_stop (with error bit) if the stop location is reached before the complete UTF-8 character can be processed. * F_parameter (with error bit) if a parameter is invalid. */ #ifndef _di_fl_string_dynamic_seek_to_ - extern f_return_status fl_string_dynamic_seek_to(const f_string_static_t buffer, f_string_range_t *range, const int8_t seek_to_this); + extern f_return_status fl_string_dynamic_seek_to(const f_string_t string, f_string_range_t *range, const int8_t seek_to_this); #endif // _di_fl_string_dynamic_seek_to_ /** * Seek the buffer location forward until the UTF-8 character (up to 4-byte wide) is reached. * - * @param buffer - * The buffer to traverse. + * @param string + * The string to traverse. * @param range * A range within the buffer representing the start and stop locations. * The start location will be incremented by seek. @@ -1360,12 +1326,10 @@ extern "C" { * * @return * F_none on success. - * F_none_eos on success, but stopped at end of buffer. - * F_none_stop on success, but stopped stop location. - * F_data_not_eos if buffer length is 0. - * F_data_not_stop if range.start > range.stop. + * F_none_stop on success, but stopped at end of range. + * F_data_not on success, but there was no string data to seek. + * F_data_not_stop on success, but the range.start > range.stop. * F_incomplete_utf (with error bit) if character is an incomplete UTF-8 fragment. - * F_incomplete_utf_eos (with error bit) if end of string is reached before a complete UTF-8 character can be processed. * F_incomplete_utf_stop (with error bit) if the stop location is reached before the complete UTF-8 character can be processed. * F_parameter (with error bit) if a parameter is invalid. * F_utf (with error bit) if character is an invalid UTF-8 character. @@ -1375,7 +1339,7 @@ extern "C" { * @see f_utf_char_to_character() */ #ifndef _di_fl_string_dynamic_seek_to_utf_character_ - extern f_return_status fl_string_dynamic_seek_to_utf_character(const f_string_static_t buffer, f_string_range_t *range, const f_utf_character_t seek_to_this); + extern f_return_status fl_string_dynamic_seek_to_utf_character(const f_string_t string, f_string_range_t *range, const f_utf_character_t seek_to_this); #endif // _di_fl_string_dynamic_seek_to_utf_character_ /** @@ -1423,6 +1387,53 @@ extern "C" { #endif // _di_fl_string_dynamic_terminate_after_ /** + * Resize the array of dynamic strings to a smaller size. + * + * This will resize making the string smaller based on the given length. + * If the given length is too small, then the resize will fail. + * This will not shrink the size to less than 0. + * + * @param length + * A positive number greater than 0 representing how much to decrease the size by. + * @param strings + * The string array to resize. + * + * @return + * F_none on success. + * F_memory_allocation (with error bit) on memory allocation error. + * F_memory_reallocation (with error bit) on memory reallocation error. + * F_parameter (with error bit) if a parameter is invalid. + * F_string_too_large (with error bit) if the combined string is too large. + */ +#ifndef _di_fl_string_dynamics_size_decrease_ + extern f_return_status fl_string_dynamics_size_decrease(const f_array_length_t length, f_string_dynamics_t *strings); +#endif // _di_fl_string_dynamics_size_decrease_ + +/** + * Resize the array of dynamic strings to a larger size. + * + * This will resize making the string larger based on the given length. + * If the given length is too large for the buffer, then attempt to set max buffer size (f_array_length_t_size). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param length + * A positive number greater than 0 representing how much to increase the size by. + * @param strings + * The string array to resize. + * + * @return + * F_none on success. + * F_string_too_large on success, but the requested length is too large for the buffer. + * F_memory_allocation (with error bit) on memory allocation error. + * F_memory_reallocation (with error bit) on memory reallocation error. + * F_parameter (with error bit) if a parameter is invalid. + * F_string_too_large (with error bit) if the combined string is too large. + */ +#ifndef _di_fl_string_dynamics_size_increase_ + extern f_return_status fl_string_dynamics_size_increase(const f_array_length_t length, f_string_dynamics_t *strings); +#endif // _di_fl_string_dynamics_size_increase_ + +/** * Resize the array of string lengths to a smaller size. * * This will resize making the string smaller based on the given length. diff --git a/level_1/fl_utf/c/private-utf.c b/level_1/fl_utf/c/private-utf.c index 15f953a..8e7f70f 100644 --- a/level_1/fl_utf/c/private-utf.c +++ b/level_1/fl_utf/c/private-utf.c @@ -36,6 +36,7 @@ extern "C" { f_utf_string_length_t first = 0; for (f_utf_string_length_t i = 0; i <= length; i++) { + if (i == length) { if (i > first) { f_utf_string_length_t size = i - first; @@ -127,6 +128,7 @@ extern "C" { // skip past leading whitespace in string1. for (; i1 < stop1; i1++) { + // skip past NULL in string1. while (i1 < stop1 && string1[i1] == 0) i1++; if (i1 == stop1) break; @@ -189,6 +191,7 @@ extern "C" { // determine where the last non-whitespace is in string2. for (f_utf_string_length_t j = i2; j < stop2; j++) { + // skip past NULL in string2. while (j < stop2 && string2[j] == 0) j++; if (j == stop2) break; @@ -211,6 +214,7 @@ extern "C" { } for (; i1 < last1 && i2 < last2; i1++, i2++) { + // skip past NULL in string1. while (i1 < last1 && string1[i1] == 0) i1++; if (i1 == last1) break; @@ -277,6 +281,7 @@ extern "C" { f_utf_string_length_t offset = 0; for (f_utf_string_length_t i = 0; i <= length; i++) { + if (i == length) { if (i > first) { const f_utf_string_length_t size = i - first; @@ -347,6 +352,7 @@ extern "C" { // skip past leading whitespace. for (; *start <= *stop; (*start)++) { + // skip past NULL. while (*start < *stop && source[*start] == 0) (*start)++; if (*start > *stop) break; diff --git a/level_1/fl_utf/c/utf.c b/level_1/fl_utf/c/utf.c index c27d762..4b1f5c6 100644 --- a/level_1/fl_utf/c/utf.c +++ b/level_1/fl_utf/c/utf.c @@ -33,6 +33,7 @@ extern "C" { f_utf_string_length_t j = 1; while (i <= length && j <= destination->used) { + if (source[length - i] == f_utf_character_t_eos) { i++; continue; @@ -71,6 +72,7 @@ extern "C" { f_utf_string_length_t j = 1; while (i <= length && j <= destination->used) { + if (source[length - i] == f_utf_character_t_eos) { i++; continue; diff --git a/level_1/fl_utf_file/c/utf_file.c b/level_1/fl_utf_file/c/utf_file.c index 823c512..369d834 100644 --- a/level_1/fl_utf_file/c/utf_file.c +++ b/level_1/fl_utf_file/c/utf_file.c @@ -27,6 +27,7 @@ extern "C" { memset(&buffer_read, 0, sizeof(file.size_read)); while ((size_read = read(file.id, buffer_read, file.size_read)) > 0) { + if (buffer->used + size_read > buffer->size) { if (buffer->size + size_read > f_utf_string_length_t_size) { return F_status_set_error(F_string_too_large); @@ -126,7 +127,7 @@ extern "C" { #endif // _di_fl_utf_file_read_block_ #ifndef _di_fl_utf_file_read_until_ - f_return_status fl_utf_file_read_until(const f_file_t file, f_utf_string_dynamic_t *buffer, const f_utf_string_length_t total) { + f_return_status fl_utf_file_read_until(const f_file_t file, const f_utf_string_length_t total, f_utf_string_dynamic_t *buffer) { #ifndef _di_level_1_parameter_checking_ if (file.size_read == 0) return F_status_set_error(F_parameter); if (buffer->used > buffer->size) return F_status_set_error(F_parameter); @@ -154,6 +155,7 @@ extern "C" { memset(&buffer_read, 0, sizeof(buffer_size)); while (buffer_count < total && (size_read = read(file.id, buffer_read, buffer_size)) > 0) { + if (buffer->used + size_read > buffer->size) { if (buffer->size + size_read > f_string_length_t_size) { return F_status_set_error(F_string_too_large); diff --git a/level_1/fl_utf_file/c/utf_file.h b/level_1/fl_utf_file/c/utf_file.h index 912e01c..44f9380 100644 --- a/level_1/fl_utf_file/c/utf_file.h +++ b/level_1/fl_utf_file/c/utf_file.h @@ -99,10 +99,10 @@ extern "C" { * @param file * The file to read. * The file must already be open. - * @param buffer - * The buffer the file is being read into. * @param total * The total bytes to read, unless EOF is reached first. + * @param buffer + * The buffer the file is being read into. * * @return * F_none on success. @@ -119,10 +119,10 @@ extern "C" { * F_interrupted (with error bit) if interrupt was received. * F_parameter (with error bit) if a parameter is invalid. * - * @see read + * @see read() */ #ifndef _di_fl_utf_file_read_until_ - extern f_return_status fl_utf_file_read_until(const f_file_t file, f_utf_string_dynamic_t *buffer, const f_utf_string_length_t total); + extern f_return_status fl_utf_file_read_until(const f_file_t file, const f_utf_string_length_t total, f_utf_string_dynamic_t *buffer); #endif // _di_fl_utf_file_read_until_ /** diff --git a/level_2/fll_fss/c/fss.c b/level_2/fll_fss/c/fss.c index ceda1ce..3d753b6 100644 --- a/level_2/fll_fss/c/fss.c +++ b/level_2/fll_fss/c/fss.c @@ -38,7 +38,7 @@ extern "C" { f_macro_string_dynamic_t_resize(status, buffer, f_fss_max_header_length + 1); if (F_status_is_error(status)) return status; - status = f_file_read_until(*file, &buffer, f_fss_max_header_length + 1); + status = f_file_read_until(*file, f_fss_max_header_length + 1, &buffer); if (F_status_is_error(status)) return status; return private_fll_fss_identify(buffer, header); diff --git a/level_2/fll_fss/c/fss_basic.c b/level_2/fll_fss/c/fss_basic.c index 41842e2..0992c61 100644 --- a/level_2/fll_fss/c/fss_basic.c +++ b/level_2/fll_fss/c/fss_basic.c @@ -163,7 +163,7 @@ extern "C" { f_status_t status = 0; f_array_length_t current = 0; - f_string_range_t range = f_macro_string_range_initialize(object.used); + f_string_range_t range = f_macro_string_range_t_initialize(object.used); status = fl_fss_basic_object_write(object, 0, &range, destination); diff --git a/level_2/fll_fss/c/fss_basic_list.c b/level_2/fll_fss/c/fss_basic_list.c index 6c19c7d..59ab6b7 100644 --- a/level_2/fll_fss/c/fss_basic_list.c +++ b/level_2/fll_fss/c/fss_basic_list.c @@ -142,7 +142,7 @@ extern "C" { f_status_t status = 0; f_array_length_t current = 0; - f_string_range_t range = f_string_range_initialize; + f_string_range_t range = f_string_range_t_initialize; range.start = 0; range.stop = object.used - 1; diff --git a/level_2/fll_fss/c/fss_extended.c b/level_2/fll_fss/c/fss_extended.c index 7362b69..6c96bff 100644 --- a/level_2/fll_fss/c/fss_extended.c +++ b/level_2/fll_fss/c/fss_extended.c @@ -199,7 +199,7 @@ extern "C" { f_status_t status = 0; f_array_length_t current = 0; - f_string_range_t range = f_macro_string_range_initialize(object.used); + f_string_range_t range = f_macro_string_range_t_initialize(object.used); status = fl_fss_extended_object_write(object, 0, &range, buffer); diff --git a/level_2/fll_fss/c/fss_extended_list.c b/level_2/fll_fss/c/fss_extended_list.c index e5c9fdd..97499bd 100644 --- a/level_2/fll_fss/c/fss_extended_list.c +++ b/level_2/fll_fss/c/fss_extended_list.c @@ -117,7 +117,7 @@ extern "C" { f_status_t status = 0; f_array_length_t current = 0; - f_string_range_t range = f_string_range_initialize; + f_string_range_t range = f_string_range_t_initialize; range.start = 0; range.stop = object.used - 1; diff --git a/level_2/fll_fss/c/private-fss.c b/level_2/fll_fss/c/private-fss.c index d9d40f5..d43693b 100644 --- a/level_2/fll_fss/c/private-fss.c +++ b/level_2/fll_fss/c/private-fss.c @@ -46,7 +46,7 @@ extern "C" { if (f_conversion_character_is_hexidecimal(buffer.string[i]) == F_true) { i++; - f_string_range_t range = f_string_range_initialize; + f_string_range_t range = f_string_range_t_initialize; range.start = i - 4; range.stop = i; @@ -105,7 +105,7 @@ extern "C" { // @todo this needs to be changed to support sub-headers (maybe something like FL_fss_accepted_additional). i++; - f_string_range_t range = f_string_range_initialize; + f_string_range_t range = f_string_range_t_initialize; range.start = i - 4; range.stop = i; diff --git a/level_3/byte_dump/c/byte_dump.c b/level_3/byte_dump/c/byte_dump.c index 0cab62c..6b016f9 100644 --- a/level_3/byte_dump/c/byte_dump.c +++ b/level_3/byte_dump/c/byte_dump.c @@ -73,7 +73,7 @@ extern "C" { f_status_t status = F_none; { - f_console_parameters_t parameters = { data->parameters, byte_dump_total_parameters }; + const f_console_parameters_t parameters = { data->parameters, byte_dump_total_parameters }; f_console_parameter_ids_t choices = f_console_parameter_ids_t_initialize; // Identify priority of color parameters. @@ -171,7 +171,7 @@ extern "C" { } else if (data->parameters[byte_dump_parameter_width].result == f_console_result_additional) { const f_string_length_t index = data->parameters[byte_dump_parameter_width].additional.array[data->parameters[byte_dump_parameter_width].additional.used - 1]; - const f_string_range_t range = f_macro_string_range_initialize(strlen(arguments.argv[index])); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(arguments.argv[index])); f_number_unsigned_t number = 0; @@ -202,7 +202,7 @@ extern "C" { } else if (data->parameters[byte_dump_parameter_first].result == f_console_result_additional) { const f_string_length_t index = data->parameters[byte_dump_parameter_first].additional.array[data->parameters[byte_dump_parameter_first].additional.used - 1]; - const f_string_range_t range = f_macro_string_range_initialize(strlen(arguments.argv[index])); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(arguments.argv[index])); f_number_unsigned_t number = 0; @@ -233,7 +233,7 @@ extern "C" { } else if (data->parameters[byte_dump_parameter_last].result == f_console_result_additional) { const f_string_length_t index = data->parameters[byte_dump_parameter_last].additional.array[data->parameters[byte_dump_parameter_last].additional.used - 1]; - const f_string_range_t range = f_macro_string_range_initialize(strlen(arguments.argv[index])); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(arguments.argv[index])); f_number_unsigned_t number = 0; diff --git a/level_3/fake/c/fake.c b/level_3/fake/c/fake.c index 868144e..acadef5 100644 --- a/level_3/fake/c/fake.c +++ b/level_3/fake/c/fake.c @@ -100,7 +100,7 @@ extern "C" { f_status_t status = F_none; { - f_console_parameters_t parameters = { data->parameters, fake_total_parameters }; + const f_console_parameters_t parameters = { data->parameters, fake_total_parameters }; // Load all parameters and identify priority of color parameters. { @@ -312,7 +312,7 @@ extern "C" { } } // for - // ensure a newline is always put at the end of the program execution, unless in quite mode. + // ensure a newline is always put at the end of the program execution, unless in quiet mode. if (data->verbosity != fake_verbosity_quiet) { if (F_status_is_error(status) || status == F_signal) { fprintf(f_type_error, "%c", f_string_eol[0]); diff --git a/level_3/fake/c/private-build.c b/level_3/fake/c/private-build.c index fdbe304..0e94768 100644 --- a/level_3/fake/c/private-build.c +++ b/level_3/fake/c/private-build.c @@ -1285,7 +1285,7 @@ extern "C" { *status = F_status_set_error(F_signal); } else if (F_status_is_error_not(*status)) { - f_string_range_t range = f_macro_string_range_initialize(buffer.used); + f_string_range_t range = f_macro_string_range_t_initialize(buffer.used); *status = fll_fss_extended_read(&buffer, &range, &objects, &contents, 0, 0); diff --git a/level_3/fake/c/private-make.c b/level_3/fake/c/private-make.c index f72eac6..1993f17 100644 --- a/level_3/fake/c/private-make.c +++ b/level_3/fake/c/private-make.c @@ -22,7 +22,7 @@ extern "C" { return F_status_set_error(F_false); } - const f_string_range_t range = f_macro_string_range_initialize(data_make->path.stack.array[0].used); + const f_string_range_t range = f_macro_string_range_t_initialize(data_make->path.stack.array[0].used); if (range.start <= range.stop) { status = fl_string_dynamic_partial_compare(data_make->path.stack.array[0], data_make->path_cache, range, range); @@ -45,7 +45,7 @@ extern "C" { #ifndef _di_fake_make_get_id_group_ f_return_status fake_make_get_id_group(const fake_data_t data, const fake_make_print_t print, const f_string_static_t buffer, gid_t *id) { - const f_string_range_t range = f_macro_string_range_initialize(buffer.used); + const f_string_range_t range = f_macro_string_range_t_initialize(buffer.used); f_number_unsigned_t number = 0; @@ -123,7 +123,7 @@ extern "C" { #ifndef _di_fake_make_get_id_owner_ f_return_status fake_make_get_id_owner(const fake_data_t data, const fake_make_print_t print, const f_string_static_t buffer, uid_t *id) { - const f_string_range_t range = f_macro_string_range_initialize(buffer.used); + const f_string_range_t range = f_macro_string_range_t_initialize(buffer.used); f_number_unsigned_t number = 0; @@ -202,7 +202,7 @@ extern "C" { f_fss_contents_t list_contents = f_fss_contents_t_initialize; { - f_string_range_t range = f_macro_string_range_initialize(data_make->buffer.used); + f_string_range_t range = f_macro_string_range_t_initialize(data_make->buffer.used); *status = fll_fss_basic_list_read(&data_make->buffer, &range, &list_objects, &list_contents); @@ -224,8 +224,8 @@ extern "C" { const f_string_static_t name_settings = f_macro_string_static_t_initialize(fake_make_section_settings, fake_make_section_settings_length); const f_string_static_t name_main = f_macro_string_static_t_initialize(fake_make_section_main, fake_make_section_main_length); - const f_string_range_t name_settings_range = f_macro_string_range_initialize(fake_make_section_settings_length); - const f_string_range_t name_main_range = f_macro_string_range_initialize(fake_make_section_main_length); + const f_string_range_t name_settings_range = f_macro_string_range_t_initialize(fake_make_section_settings_length); + const f_string_range_t name_main_range = f_macro_string_range_t_initialize(fake_make_section_main_length); f_macro_fss_nameds_t_new((*status), data_make->fakefile, list_objects.used); @@ -239,7 +239,7 @@ extern "C" { } { - f_string_range_t content_range = f_string_range_initialize; + f_string_range_t content_range = f_string_range_t_initialize; for (f_array_length_t i = 0; i < list_objects.used; i++) { @@ -1142,14 +1142,14 @@ extern "C" { const f_string_static_t vocabulary_define = f_macro_string_static_t_initialize(iki_vocabulary_0002_define, iki_vocabulary_0002_define_length); const f_string_static_t vocabulary_parameter = f_macro_string_static_t_initialize(iki_vocabulary_0002_parameter, iki_vocabulary_0002_parameter_length); - const f_string_range_t range_define = f_macro_string_range_initialize(iki_vocabulary_0002_define_length); - const f_string_range_t range_parameter = f_macro_string_range_initialize(iki_vocabulary_0002_parameter_length); + const f_string_range_t range_define = f_macro_string_range_t_initialize(iki_vocabulary_0002_define_length); + const f_string_range_t range_parameter = f_macro_string_range_t_initialize(iki_vocabulary_0002_parameter_length); f_iki_variable_t iki_variable = f_iki_variable_t_initialize; f_iki_vocabulary_t iki_vocabulary = f_iki_vocabulary_t_initialize; f_iki_content_t iki_content = f_iki_content_t_initialize; - f_string_range_t range = f_string_range_initialize; + f_string_range_t range = f_string_range_t_initialize; f_string_map_multis_t *parameter = &data_make->setting_make.parameter; bool unmatched = F_true; @@ -1910,37 +1910,37 @@ extern "C" { }; const f_string_range_t operations_range[] = { - f_macro_string_range_initialize(fake_make_operation_break_length), - f_macro_string_range_initialize(fake_make_operation_build_length), - f_macro_string_range_initialize(fake_make_operation_clean_length), - f_macro_string_range_initialize(fake_make_operation_clone_length), - f_macro_string_range_initialize(fake_make_operation_compile_length), - f_macro_string_range_initialize(fake_make_operation_copy_length), - f_macro_string_range_initialize(fake_make_operation_define_length), - f_macro_string_range_initialize(fake_make_operation_delete_length), - f_macro_string_range_initialize(fake_make_operation_deletes_length), - f_macro_string_range_initialize(fake_make_operation_else_length), - f_macro_string_range_initialize(fake_make_operation_exit_length), - f_macro_string_range_initialize(fake_make_operation_fail_length), - f_macro_string_range_initialize(fake_make_operation_group_length), - f_macro_string_range_initialize(fake_make_operation_groups_length), - f_macro_string_range_initialize(fake_make_operation_if_length), - f_macro_string_range_initialize(fake_make_operation_index_length), - f_macro_string_range_initialize(fake_make_operation_link_length), - f_macro_string_range_initialize(fake_make_operation_mode_length), - f_macro_string_range_initialize(fake_make_operation_modes_length), - f_macro_string_range_initialize(fake_make_operation_move_length), - f_macro_string_range_initialize(fake_make_operation_operate_length), - f_macro_string_range_initialize(fake_make_operation_owner_length), - f_macro_string_range_initialize(fake_make_operation_owners_length), - f_macro_string_range_initialize(fake_make_operation_pop_length), - f_macro_string_range_initialize(fake_make_operation_print_length), - f_macro_string_range_initialize(fake_make_operation_run_length), - f_macro_string_range_initialize(fake_make_operation_shell_length), - f_macro_string_range_initialize(fake_make_operation_skeleton_length), - f_macro_string_range_initialize(fake_make_operation_to_length), - f_macro_string_range_initialize(fake_make_operation_top_length), - f_macro_string_range_initialize(fake_make_operation_touch_length), + f_macro_string_range_t_initialize(fake_make_operation_break_length), + f_macro_string_range_t_initialize(fake_make_operation_build_length), + f_macro_string_range_t_initialize(fake_make_operation_clean_length), + f_macro_string_range_t_initialize(fake_make_operation_clone_length), + f_macro_string_range_t_initialize(fake_make_operation_compile_length), + f_macro_string_range_t_initialize(fake_make_operation_copy_length), + f_macro_string_range_t_initialize(fake_make_operation_define_length), + f_macro_string_range_t_initialize(fake_make_operation_delete_length), + f_macro_string_range_t_initialize(fake_make_operation_deletes_length), + f_macro_string_range_t_initialize(fake_make_operation_else_length), + f_macro_string_range_t_initialize(fake_make_operation_exit_length), + f_macro_string_range_t_initialize(fake_make_operation_fail_length), + f_macro_string_range_t_initialize(fake_make_operation_group_length), + f_macro_string_range_t_initialize(fake_make_operation_groups_length), + f_macro_string_range_t_initialize(fake_make_operation_if_length), + f_macro_string_range_t_initialize(fake_make_operation_index_length), + f_macro_string_range_t_initialize(fake_make_operation_link_length), + f_macro_string_range_t_initialize(fake_make_operation_mode_length), + f_macro_string_range_t_initialize(fake_make_operation_modes_length), + f_macro_string_range_t_initialize(fake_make_operation_move_length), + f_macro_string_range_t_initialize(fake_make_operation_operate_length), + f_macro_string_range_t_initialize(fake_make_operation_owner_length), + f_macro_string_range_t_initialize(fake_make_operation_owners_length), + f_macro_string_range_t_initialize(fake_make_operation_pop_length), + f_macro_string_range_t_initialize(fake_make_operation_print_length), + f_macro_string_range_t_initialize(fake_make_operation_run_length), + f_macro_string_range_t_initialize(fake_make_operation_shell_length), + f_macro_string_range_t_initialize(fake_make_operation_skeleton_length), + f_macro_string_range_t_initialize(fake_make_operation_to_length), + f_macro_string_range_t_initialize(fake_make_operation_top_length), + f_macro_string_range_t_initialize(fake_make_operation_touch_length), }; const uint8_t operations_type[] = { @@ -3004,7 +3004,7 @@ extern "C" { if (*operation_if == fake_make_operation_if_type_if_greater || *operation_if == fake_make_operation_if_type_if_greater_equal || *operation_if == fake_make_operation_if_type_if_less || *operation_if == fake_make_operation_if_type_if_less_equal) { f_status_t status_number = F_none; - f_string_range_t range = f_string_range_initialize; + f_string_range_t range = f_string_range_t_initialize; f_number_unsigned_t number_left = 0; f_number_unsigned_t number_right = 0; @@ -4662,7 +4662,7 @@ extern "C" { } f_status_t status_number = F_none; - f_string_range_t range = f_string_range_initialize; + f_string_range_t range = f_string_range_t_initialize; f_number_unsigned_t number = 0; bool is_negative = F_false; @@ -5035,7 +5035,7 @@ extern "C" { return F_status_set_error(F_failure); } - f_string_range_t range = f_string_range_initialize; + f_string_range_t range = f_string_range_t_initialize; range.start = data_make->path.stack.array[0].used + 1; range.stop = range.start + (path.used - range.start) - 1; diff --git a/level_3/firewall/c/firewall.c b/level_3/firewall/c/firewall.c index 547e4f6..9309ba3 100644 --- a/level_3/firewall/c/firewall.c +++ b/level_3/firewall/c/firewall.c @@ -59,9 +59,9 @@ extern "C" { f_status_t status = F_none; { - f_console_parameters_t parameters = { data->parameters, firewall_total_parameters }; f_console_parameter_id_t ids[3] = { firewall_parameter_no_color, firewall_parameter_light, firewall_parameter_dark }; - f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameters_t parameters = { data->parameters, firewall_total_parameters }; status = fll_program_parameter_process(arguments, parameters, choices, F_true, &data->remaining, &data->context); @@ -140,7 +140,7 @@ extern "C" { if (found_command) { firewall_local_data_t local = firewall_local_data_t_initialize; firewall_reserved_chains_t reserved = firewall_reserved_chains_t_initialize; - f_string_range_t input = f_string_range_initialize; + f_string_range_t input = f_string_range_t_initialize; if (command == firewall_parameter_command_show) { // Warning: these are hardcoded print commands (I am not certain how I am going to implement external 'show' rules as the default-firewall setting file is the wrong place to put this) diff --git a/level_3/firewall/c/private-firewall.c b/level_3/firewall/c/private-firewall.c index 606001a..0421803 100644 --- a/level_3/firewall/c/private-firewall.c +++ b/level_3/firewall/c/private-firewall.c @@ -645,7 +645,7 @@ f_return_status firewall_perform_commands(const firewall_local_data_t local, con } else { { - f_string_range_t input = f_string_range_initialize; + f_string_range_t input = f_string_range_t_initialize; input.stop = local_buffer.used - 1; @@ -860,7 +860,7 @@ f_return_status firewall_create_custom_chains(firewall_reserved_chains_t *reserv f_array_length_t j = 0; f_string_length_t length = 0; - f_string_range_t range = f_string_range_initialize; + f_string_range_t range = f_string_range_t_initialize; f_string_dynamics_t arguments = f_string_dynamics_t_initialize; f_string_dynamic_t fixed_string = f_string_dynamic_t_initialize; @@ -1399,7 +1399,7 @@ f_return_status firewall_buffer_rules(const f_string_t filename, const bool opti return status; } else { - f_string_range_t input = f_string_range_initialize; + f_string_range_t input = f_string_range_t_initialize; input.stop = local->buffer.used - 1; diff --git a/level_3/fss_basic_list_read/c/fss_basic_list_read.c b/level_3/fss_basic_list_read/c/fss_basic_list_read.c index 923b894..2998733 100644 --- a/level_3/fss_basic_list_read/c/fss_basic_list_read.c +++ b/level_3/fss_basic_list_read/c/fss_basic_list_read.c @@ -126,9 +126,9 @@ extern "C" { f_status_t status = F_none; { - f_console_parameters_t parameters = { data->parameters, fss_basic_list_read_total_parameters }; f_console_parameter_id_t ids[3] = { fss_basic_list_read_parameter_no_color, fss_basic_list_read_parameter_light, fss_basic_list_read_parameter_dark }; - f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameters_t parameters = { data->parameters, fss_basic_list_read_total_parameters }; status = fll_program_parameter_process(arguments, parameters, choices, F_true, &data->remaining, &data->context); @@ -328,7 +328,7 @@ extern "C" { } } - status = f_file_read_until(file, &data->buffer, data->quantity.total); + status = f_file_read_until(file, data->quantity.total, &data->buffer); f_file_close(&file.id); diff --git a/level_3/fss_basic_list_read/c/private-fss_basic_list_read.c b/level_3/fss_basic_list_read/c/private-fss_basic_list_read.c index 51fd6a8..b204a47 100644 --- a/level_3/fss_basic_list_read/c/private-fss_basic_list_read.c +++ b/level_3/fss_basic_list_read/c/private-fss_basic_list_read.c @@ -120,7 +120,7 @@ extern "C" { else { position_depth = data.parameters[fss_basic_list_read_parameter_depth].additional.array[i]; - const f_string_range_t range = f_macro_string_range_initialize(strlen(arguments.argv[position_depth])); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(arguments.argv[position_depth])); status = fl_conversion_string_to_number_unsigned(arguments.argv[position_depth], &depths->array[i].depth, range); if (F_status_is_error(status)) { @@ -141,7 +141,7 @@ extern "C" { depths->array[i].index_at = data.parameters[fss_basic_list_read_parameter_at].additional.array[position_at]; - const f_string_range_t range = f_macro_string_range_initialize(strlen(arguments.argv[depths->array[i].index_at])); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(arguments.argv[depths->array[i].index_at])); status = fl_conversion_string_to_number_unsigned(arguments.argv[depths->array[i].index_at], &depths->array[i].value_at, range); if (F_status_is_error(status)) { @@ -244,7 +244,7 @@ extern "C" { f_status_t status = F_none; { - f_string_range_t input = f_string_range_initialize; + f_string_range_t input = f_string_range_t_initialize; input.start = 0; input.stop = data->buffer.used - 1; @@ -300,7 +300,7 @@ extern "C" { if (data->parameters[fss_basic_list_read_parameter_select].result == f_console_result_additional) { const f_string_length_t index = data->parameters[fss_basic_list_read_parameter_select].additional.array[data->parameters[fss_basic_list_read_parameter_select].additional.used - 1]; - const f_string_range_t range = f_macro_string_range_initialize(strlen(arguments.argv[index])); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(arguments.argv[index])); status = fl_conversion_string_to_number_unsigned(arguments.argv[index], &select, range); if (F_status_is_error(status)) { @@ -318,7 +318,7 @@ extern "C" { if (data->parameters[fss_basic_list_read_parameter_line].result == f_console_result_additional) { const f_string_length_t index = data->parameters[fss_basic_list_read_parameter_line].additional.array[data->parameters[fss_basic_list_read_parameter_line].additional.used - 1]; - const f_string_range_t range = f_macro_string_range_initialize(strlen(arguments.argv[index])); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(arguments.argv[index])); status = fl_conversion_string_to_number_unsigned(arguments.argv[index], &line, range); if (F_status_is_error(status)) { diff --git a/level_3/fss_basic_list_write/c/fss_basic_list_write.c b/level_3/fss_basic_list_write/c/fss_basic_list_write.c index 455d2b3..aff4524 100644 --- a/level_3/fss_basic_list_write/c/fss_basic_list_write.c +++ b/level_3/fss_basic_list_write/c/fss_basic_list_write.c @@ -32,9 +32,9 @@ extern "C" { f_status_t status = F_none; { - f_console_parameters_t parameters = { data->parameters, fss_basic_list_write_total_parameters }; f_console_parameter_id_t ids[3] = { fss_basic_list_write_parameter_no_color, fss_basic_list_write_parameter_light, fss_basic_list_write_parameter_dark }; - f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameters_t parameters = { data->parameters, fss_basic_list_write_total_parameters }; status = fll_program_parameter_process(arguments, parameters, choices, F_true, &data->remaining, &data->context); if (F_status_is_error(status)) { @@ -56,7 +56,7 @@ extern "C" { bool object = (data->parameters[fss_basic_list_write_parameter_object].result == f_console_result_found); f_string_dynamic_t buffer = f_string_dynamic_t_initialize; - f_string_range_t range = f_string_range_initialize; + f_string_range_t range = f_string_range_t_initialize; if (data->process_pipe) { f_file_t file = f_file_t_initialize; diff --git a/level_3/fss_basic_read/c/fss_basic_read.c b/level_3/fss_basic_read/c/fss_basic_read.c index efa2e10..8a545ae 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.c +++ b/level_3/fss_basic_read/c/fss_basic_read.c @@ -126,9 +126,9 @@ extern "C" { f_status_t status = F_none; { - f_console_parameters_t parameters = { data->parameters, fss_basic_read_total_parameters }; f_console_parameter_id_t ids[3] = { fss_basic_read_parameter_no_color, fss_basic_read_parameter_light, fss_basic_read_parameter_dark }; - f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameters_t parameters = { data->parameters, fss_basic_read_total_parameters }; status = fll_program_parameter_process(arguments, parameters, choices, F_true, &data->remaining, &data->context); @@ -330,7 +330,7 @@ extern "C" { } } - status = f_file_read_until(file, &data->buffer, data->quantity.total); + status = f_file_read_until(file, data->quantity.total, &data->buffer); f_file_close(&file.id); diff --git a/level_3/fss_basic_read/c/private-fss_basic_read.c b/level_3/fss_basic_read/c/private-fss_basic_read.c index 53e1cf0..09199a9 100644 --- a/level_3/fss_basic_read/c/private-fss_basic_read.c +++ b/level_3/fss_basic_read/c/private-fss_basic_read.c @@ -120,7 +120,7 @@ extern "C" { else { position_depth = data.parameters[fss_basic_read_parameter_depth].additional.array[i]; - const f_string_range_t range = f_macro_string_range_initialize(strlen(arguments.argv[position_depth])); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(arguments.argv[position_depth])); status = fl_conversion_string_to_number_unsigned(arguments.argv[position_depth], &depths->array[i].depth, range); if (F_status_is_error(status)) { @@ -141,7 +141,7 @@ extern "C" { depths->array[i].index_at = data.parameters[fss_basic_read_parameter_at].additional.array[position_at]; - const f_string_range_t range = f_macro_string_range_initialize(strlen(arguments.argv[depths->array[i].index_at])); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(arguments.argv[depths->array[i].index_at])); status = fl_conversion_string_to_number_unsigned(arguments.argv[depths->array[i].index_at], &depths->array[i].value_at, range); if (F_status_is_error(status)) { @@ -244,7 +244,7 @@ extern "C" { f_status_t status = F_none; { - f_string_range_t input = f_string_range_initialize; + f_string_range_t input = f_string_range_t_initialize; input.start = 0; input.stop = data->buffer.used - 1; @@ -300,7 +300,7 @@ extern "C" { if (data->parameters[fss_basic_read_parameter_select].result == f_console_result_additional) { const f_string_length_t index = data->parameters[fss_basic_read_parameter_select].additional.array[data->parameters[fss_basic_read_parameter_select].additional.used - 1]; - const f_string_range_t range = f_macro_string_range_initialize(strlen(arguments.argv[index])); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(arguments.argv[index])); status = fl_conversion_string_to_number_unsigned(arguments.argv[index], &select, range); if (F_status_is_error(status)) { @@ -318,7 +318,7 @@ extern "C" { if (data->parameters[fss_basic_read_parameter_line].result == f_console_result_additional) { const f_string_length_t index = data->parameters[fss_basic_read_parameter_line].additional.array[data->parameters[fss_basic_read_parameter_line].additional.used - 1]; - const f_string_range_t range = f_macro_string_range_initialize(strlen(arguments.argv[index])); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(arguments.argv[index])); status = fl_conversion_string_to_number_unsigned(arguments.argv[index], &line, range); if (F_status_is_error(status)) { diff --git a/level_3/fss_basic_write/c/fss_basic_write.c b/level_3/fss_basic_write/c/fss_basic_write.c index 5236978..bec6350 100644 --- a/level_3/fss_basic_write/c/fss_basic_write.c +++ b/level_3/fss_basic_write/c/fss_basic_write.c @@ -32,9 +32,9 @@ extern "C" { f_status_t status = F_none; { - f_console_parameters_t parameters = { data->parameters, fss_basic_write_total_parameters }; f_console_parameter_id_t ids[3] = { fss_basic_write_parameter_no_color, fss_basic_write_parameter_light, fss_basic_write_parameter_dark }; - f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameters_t parameters = { data->parameters, fss_basic_write_total_parameters }; status = fll_program_parameter_process(arguments, parameters, choices, F_true, &data->remaining, &data->context); if (F_status_is_error(status)) { @@ -56,7 +56,7 @@ extern "C" { bool object = (data->parameters[fss_basic_write_parameter_object].result == f_console_result_found); f_string_dynamic_t buffer = f_string_dynamic_t_initialize; - f_string_range_t range = f_string_range_initialize; + f_string_range_t range = f_string_range_t_initialize; if (data->process_pipe) { f_file_t file = f_file_t_initialize; diff --git a/level_3/fss_extended_list_read/c/fss_extended_list_read.c b/level_3/fss_extended_list_read/c/fss_extended_list_read.c index f4028f3..573e8d4 100644 --- a/level_3/fss_extended_list_read/c/fss_extended_list_read.c +++ b/level_3/fss_extended_list_read/c/fss_extended_list_read.c @@ -126,9 +126,9 @@ extern "C" { f_status_t status = F_none; { - f_console_parameters_t parameters = { data->parameters, fss_extended_list_read_total_parameters }; f_console_parameter_id_t ids[3] = { fss_extended_list_read_parameter_no_color, fss_extended_list_read_parameter_light, fss_extended_list_read_parameter_dark }; - f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameters_t parameters = { data->parameters, fss_extended_list_read_total_parameters }; status = fll_program_parameter_process(arguments, parameters, choices, F_true, &data->remaining, &data->context); @@ -312,7 +312,7 @@ extern "C" { } } - status = f_file_read_until(file, &data->buffer, data->quantity.total); + status = f_file_read_until(file, data->quantity.total, &data->buffer); f_file_close(&file.id); diff --git a/level_3/fss_extended_list_read/c/private-fss_extended_list_read.c b/level_3/fss_extended_list_read/c/private-fss_extended_list_read.c index 3d7858c..ecf026a 100644 --- a/level_3/fss_extended_list_read/c/private-fss_extended_list_read.c +++ b/level_3/fss_extended_list_read/c/private-fss_extended_list_read.c @@ -120,7 +120,7 @@ extern "C" { else { position_depth = data.parameters[fss_extended_list_read_parameter_depth].additional.array[i]; - const f_string_range_t range = f_macro_string_range_initialize(strlen(arguments.argv[position_depth])); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(arguments.argv[position_depth])); status = fl_conversion_string_to_number_unsigned(arguments.argv[position_depth], &depths->array[i].depth, range); if (F_status_is_error(status)) { @@ -141,7 +141,7 @@ extern "C" { depths->array[i].index_at = data.parameters[fss_extended_list_read_parameter_at].additional.array[position_at]; - const f_string_range_t range = f_macro_string_range_initialize(strlen(arguments.argv[depths->array[i].index_at])); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(arguments.argv[depths->array[i].index_at])); status = fl_conversion_string_to_number_unsigned(arguments.argv[depths->array[i].index_at], &depths->array[i].value_at, range); if (F_status_is_error(status)) { @@ -244,7 +244,7 @@ extern "C" { f_status_t status = F_none; { - f_string_range_t input = f_string_range_initialize; + f_string_range_t input = f_string_range_t_initialize; input.start = 0; input.stop = data->buffer.used - 1; @@ -310,7 +310,7 @@ extern "C" { if (data->parameters[fss_extended_list_read_parameter_select].result == f_console_result_additional) { const f_string_length_t index = data->parameters[fss_extended_list_read_parameter_select].additional.array[data->parameters[fss_extended_list_read_parameter_select].additional.used - 1]; - const f_string_range_t range = f_macro_string_range_initialize(strlen(arguments.argv[index])); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(arguments.argv[index])); status = fl_conversion_string_to_number_unsigned(arguments.argv[index], &select, range); if (F_status_is_error(status)) { @@ -329,7 +329,7 @@ extern "C" { if (data->parameters[fss_extended_list_read_parameter_line].result == f_console_result_additional) { const f_string_length_t index = data->parameters[fss_extended_list_read_parameter_line].additional.array[data->parameters[fss_extended_list_read_parameter_line].additional.used - 1]; - const f_string_range_t range = f_macro_string_range_initialize(strlen(arguments.argv[index])); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(arguments.argv[index])); f_number_unsigned_t number = 0; @@ -360,7 +360,7 @@ extern "C" { if (depth_setting.index_name > 0) { memset(names, 0, sizeof(bool) * items->used); - f_string_range_t value_range = f_string_range_initialize; + f_string_range_t value_range = f_string_range_t_initialize; value_range.stop = depth_setting.value_name.used - 1; if (data->parameters[fss_extended_list_read_parameter_trim].result == f_console_result_found) { diff --git a/level_3/fss_extended_read/c/fss_extended_read.c b/level_3/fss_extended_read/c/fss_extended_read.c index bcba24f..7878e2c 100644 --- a/level_3/fss_extended_read/c/fss_extended_read.c +++ b/level_3/fss_extended_read/c/fss_extended_read.c @@ -126,9 +126,9 @@ extern "C" { f_status_t status = F_none; { - f_console_parameters_t parameters = { data->parameters, fss_extended_read_total_parameters }; f_console_parameter_id_t ids[3] = { fss_extended_read_parameter_no_color, fss_extended_read_parameter_light, fss_extended_read_parameter_dark }; - f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameters_t parameters = { data->parameters, fss_extended_read_total_parameters }; status = fll_program_parameter_process(arguments, parameters, choices, F_true, &data->remaining, &data->context); @@ -329,7 +329,7 @@ extern "C" { } } - status = f_file_read_until(file, &data->buffer, data->quantity.total); + status = f_file_read_until(file, data->quantity.total, &data->buffer); f_file_close(&file.id); diff --git a/level_3/fss_extended_read/c/private-fss_extended_read.c b/level_3/fss_extended_read/c/private-fss_extended_read.c index cdc4e3d..66fe3cc 100644 --- a/level_3/fss_extended_read/c/private-fss_extended_read.c +++ b/level_3/fss_extended_read/c/private-fss_extended_read.c @@ -120,7 +120,7 @@ extern "C" { else { position_depth = data.parameters[fss_extended_read_parameter_depth].additional.array[i]; - const f_string_range_t range = f_macro_string_range_initialize(strlen(arguments.argv[position_depth])); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(arguments.argv[position_depth])); status = fl_conversion_string_to_number_unsigned(arguments.argv[position_depth], &depths->array[i].depth, range); if (F_status_is_error(status)) { @@ -141,7 +141,7 @@ extern "C" { depths->array[i].index_at = data.parameters[fss_extended_read_parameter_at].additional.array[position_at]; - const f_string_range_t range = f_macro_string_range_initialize(strlen(arguments.argv[depths->array[i].index_at])); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(arguments.argv[depths->array[i].index_at])); status = fl_conversion_string_to_number_unsigned(arguments.argv[depths->array[i].index_at], &depths->array[i].value_at, range); if (F_status_is_error(status)) { @@ -244,7 +244,7 @@ extern "C" { f_status_t status = F_none; { - f_string_range_t input = f_string_range_initialize; + f_string_range_t input = f_string_range_t_initialize; input.start = 0; input.stop = data->buffer.used - 1; @@ -300,7 +300,7 @@ extern "C" { if (data->parameters[fss_extended_read_parameter_select].result == f_console_result_additional) { const f_string_length_t index = data->parameters[fss_extended_read_parameter_select].additional.array[data->parameters[fss_extended_read_parameter_select].additional.used - 1]; - const f_string_range_t range = f_macro_string_range_initialize(strlen(arguments.argv[index])); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(arguments.argv[index])); status = fl_conversion_string_to_number_unsigned(arguments.argv[index], &select, range); if (F_status_is_error(status)) { @@ -313,7 +313,7 @@ extern "C" { if (data->parameters[fss_extended_read_parameter_line].result == f_console_result_additional) { const f_string_length_t index = data->parameters[fss_extended_read_parameter_line].additional.array[data->parameters[fss_extended_read_parameter_line].additional.used - 1]; - const f_string_range_t range = f_macro_string_range_initialize(strlen(arguments.argv[index])); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(arguments.argv[index])); status = fl_conversion_string_to_number_unsigned(arguments.argv[index], &line, range); if (F_status_is_error(status)) { diff --git a/level_3/fss_extended_write/c/fss_extended_write.c b/level_3/fss_extended_write/c/fss_extended_write.c index 76049b9..9413f9b 100644 --- a/level_3/fss_extended_write/c/fss_extended_write.c +++ b/level_3/fss_extended_write/c/fss_extended_write.c @@ -32,9 +32,9 @@ extern "C" { f_status_t status = F_none; { - f_console_parameters_t parameters = { data->parameters, fss_extended_write_total_parameters }; f_console_parameter_id_t ids[3] = { fss_extended_write_parameter_no_color, fss_extended_write_parameter_light, fss_extended_write_parameter_dark }; - f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameters_t parameters = { data->parameters, fss_extended_write_total_parameters }; status = fll_program_parameter_process(arguments, parameters, choices, F_true, &data->remaining, &data->context); if (F_status_is_error(status)) { @@ -56,7 +56,7 @@ extern "C" { bool object = (data->parameters[fss_extended_write_parameter_object].result == f_console_result_found); f_string_dynamic_t buffer = f_string_dynamic_t_initialize; - f_string_range_t range = f_string_range_initialize; + f_string_range_t range = f_string_range_t_initialize; if (data->process_pipe) { f_file_t file = f_file_t_initialize; diff --git a/level_3/fss_status_code/c/fss_status_code.c b/level_3/fss_status_code/c/fss_status_code.c index d27ca51..1f764c9 100644 --- a/level_3/fss_status_code/c/fss_status_code.c +++ b/level_3/fss_status_code/c/fss_status_code.c @@ -33,9 +33,9 @@ extern "C" { f_status_t status = F_none; { - f_console_parameters_t parameters = { data->parameters, fss_status_code_total_parameters }; f_console_parameter_id_t ids[3] = { fss_status_code_parameter_no_color, fss_status_code_parameter_light, fss_status_code_parameter_dark }; - f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameters_t parameters = { data->parameters, fss_status_code_total_parameters }; status = fll_program_parameter_process(arguments, parameters, choices, F_true, &data->remaining, &data->context); diff --git a/level_3/fss_status_code/c/private-fss_status_code.c b/level_3/fss_status_code/c/private-fss_status_code.c index 3471e87..d82d659 100644 --- a/level_3/fss_status_code/c/private-fss_status_code.c +++ b/level_3/fss_status_code/c/private-fss_status_code.c @@ -48,7 +48,7 @@ extern "C" { f_status_t status = F_none; { - const f_string_range_t range = f_macro_string_range_initialize(strlen(value)); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(value)); f_number_unsigned_t number = 0; @@ -133,7 +133,7 @@ extern "C" { #ifndef _di_fss_status_code_convert_number_ f_return_status fss_status_code_convert_number(const fss_status_code_data_t data, const f_string_t value, f_number_unsigned_t *number) { - const f_string_range_t range = f_macro_string_range_initialize(strlen(value)); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(value)); f_status_t status = fl_conversion_string_to_number_unsigned(value, number, range); diff --git a/level_3/iki_read/c/iki_read.c b/level_3/iki_read/c/iki_read.c index e8e652c..4d16762 100644 --- a/level_3/iki_read/c/iki_read.c +++ b/level_3/iki_read/c/iki_read.c @@ -32,7 +32,7 @@ extern "C" { printf("%c", f_string_eol[0]); - fll_program_print_help_option(context, iki_read_short_substitute, iki_read_long_substitute, f_console_symbol_short_enable, f_console_symbol_long_enable,"Substitute the entire variable for the given name and content value with the given string."); + fll_program_print_help_option(context, iki_read_short_substitute, iki_read_long_substitute, f_console_symbol_short_enable, f_console_symbol_long_enable, "Substitute the entire variable for the given name and content value with the given string."); fll_program_print_help_usage(context, iki_read_name, "filename(s)"); @@ -89,9 +89,9 @@ extern "C" { f_status_t status = F_none; { - f_console_parameters_t parameters = { data->parameters, iki_read_total_parameters }; f_console_parameter_id_t ids[3] = { iki_read_parameter_no_color, iki_read_parameter_light, iki_read_parameter_dark }; - f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameters_t parameters = { data->parameters, iki_read_total_parameters }; status = fll_program_parameter_process(arguments, parameters, choices, F_true, &data->remaining, &data->context); if (F_status_is_error(status)) { @@ -156,7 +156,7 @@ extern "C" { } else if (data->parameters[iki_read_parameter_at].result == f_console_result_additional) { const f_string_length_t index = data->parameters[iki_read_parameter_at].additional.array[data->parameters[iki_read_parameter_at].additional.used - 1]; - const f_string_range_t range = f_macro_string_range_initialize(strlen(arguments.argv[index])); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(arguments.argv[index])); f_number_unsigned_t number = 0; @@ -195,7 +195,7 @@ extern "C" { } else if (data->parameters[iki_read_parameter_line].result == f_console_result_additional) { const f_string_length_t index = data->parameters[iki_read_parameter_line].additional.array[data->parameters[iki_read_parameter_line].additional.used - 1]; - const f_string_range_t range = f_macro_string_range_initialize(strlen(arguments.argv[index])); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(arguments.argv[index])); f_number_unsigned_t number = 0; @@ -369,7 +369,7 @@ extern "C" { continue; } - status = f_file_read_until(file, &data->buffer, total); + status = f_file_read_until(file, total, &data->buffer); f_file_close(&file.id); @@ -396,7 +396,7 @@ extern "C" { } } - // ensure a newline is always put at the end of the program execution, unless in quite mode. + // ensure a newline is always put at the end of the program execution, unless in quiet mode. if (data->verbosity != iki_read_verbosity_quiet) { if (F_status_is_error(status) || data->mode == 0) { fprintf(f_type_error, "%c", f_string_eol[0]); diff --git a/level_3/iki_read/c/iki_read.h b/level_3/iki_read/c/iki_read.h index 3d4d408..0d451f6 100644 --- a/level_3/iki_read/c/iki_read.h +++ b/level_3/iki_read/c/iki_read.h @@ -5,11 +5,12 @@ * API Version: 0.5 * Licenses: lgplv2.1 * - * This is the FSS Basic Read program + * This is the IKI Read program. + * * This program utilizes the Featureless Linux Library. * This program processes files or other input in fss format and stores the results in the iki_read_data_t. * - * This processes in accordance to the FSS-0000 Basic specification. + * This processes in accordance to the IKI specification. */ #ifndef _iki_read_h diff --git a/level_3/iki_read/c/private-iki_read.c b/level_3/iki_read/c/private-iki_read.c index 5286586..301bb4d 100644 --- a/level_3/iki_read/c/private-iki_read.c +++ b/level_3/iki_read/c/private-iki_read.c @@ -331,7 +331,7 @@ extern "C" { f_iki_content_t content = f_iki_content_t_initialize; if (data->parameters[iki_read_parameter_whole].result == f_console_result_found) { - f_string_range_t buffer_range = f_macro_string_range_initialize(data->buffer.used); + f_string_range_t buffer_range = f_macro_string_range_t_initialize(data->buffer.used); status = iki_read_process_at(arguments, file_name, data, &buffer_range); @@ -358,7 +358,7 @@ extern "C" { status = iki_read_process_buffer_total(arguments, file_name, data, &variable, &vocabulary, &content); } else { - f_string_range_t buffer_range = f_macro_string_range_initialize(data->buffer.used); + f_string_range_t buffer_range = f_macro_string_range_t_initialize(data->buffer.used); status = iki_read_process_at(arguments, file_name, data, &buffer_range); @@ -536,8 +536,8 @@ extern "C" { } f_string_dynamics_t names = f_string_dynamics_t_initialize; - f_string_range_t name_range = f_string_range_initialize; - f_string_range_t substitution_range = f_string_range_initialize; + f_string_range_t name_range = f_string_range_t_initialize; + f_string_range_t substitution_range = f_string_range_t_initialize; bool name_missed = F_true; @@ -670,7 +670,7 @@ extern "C" { #ifndef _di_iki_read_process_buffer_total_ f_return_status iki_read_process_buffer_total(const f_console_arguments_t arguments, const f_string_t file_name, iki_read_data_t *data, f_iki_variable_t *variable, f_iki_vocabulary_t *vocabulary, f_iki_content_t *content) { f_status_t status = F_none; - f_string_range_t range = f_macro_string_range_initialize(data->buffer.used); + f_string_range_t range = f_macro_string_range_t_initialize(data->buffer.used); status = iki_read_process_at(arguments, file_name, data, &range); @@ -787,7 +787,7 @@ extern "C" { f_status_t status = F_none; f_string_length_t i = 0; - f_string_range_t range = f_string_range_initialize; + f_string_range_t range = f_string_range_t_initialize; range.start = 0; diff --git a/level_3/init/c/init.c b/level_3/init/c/init.c index bd547b5..c97abc4 100644 --- a/level_3/init/c/init.c +++ b/level_3/init/c/init.c @@ -56,9 +56,9 @@ extern "C" { unsigned short do_socket_port = F_false; { - f_console_parameters_t parameters = { data->parameters, init_total_parameters }; f_console_parameter_id_t ids[3] = { init_parameter_no_color, init_parameter_light, init_parameter_dark }; - f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameters_t parameters = { data->parameters, init_total_parameters }; status = fll_program_parameter_process(arguments, parameters, choices, F_true, &data->remaining, &data->context); diff --git a/level_3/init/c/private-init.c b/level_3/init/c/private-init.c index df24d72..315f2ef 100644 --- a/level_3/init/c/private-init.c +++ b/level_3/init/c/private-init.c @@ -41,7 +41,7 @@ f_macro_file_t_reset_position(quantity, file) fflush(stdout); - status = f_file_read_until(file, buffer, quantity); + status = f_file_read_until(file, quantity, buffer); f_file_close(&file.id); @@ -66,7 +66,7 @@ return F_status_set_error(status); } else { - f_string_range_t input = f_string_range_initialize; + f_string_range_t input = f_string_range_t_initialize; input.stop = buffer->used - 1; @@ -483,7 +483,7 @@ f_return_status init_process_main_rule(const init_data_t data, f_string_dynamic_t *buffer, init_data_t *settings) { f_status_t status = F_none; f_string_dynamic_t buffer = f_string_dynamic_t_initialize; - f_string_range_t range = f_string_range_initialize; + f_string_range_t range = f_string_range_t_initialize; f_fss_objects_t objects = f_fss_objects_t_initialize; f_fss_contents_t contents = f_fss_contents_t_initialize; f_string_length_t position = 0; diff --git a/level_3/status_code/c/private-status_code.c b/level_3/status_code/c/private-status_code.c index 252e150..a70ce9e 100644 --- a/level_3/status_code/c/private-status_code.c +++ b/level_3/status_code/c/private-status_code.c @@ -48,7 +48,7 @@ extern "C" { f_status_t status = F_none; { - const f_string_range_t range = f_macro_string_range_initialize(strlen(value)); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(value)); f_number_unsigned_t number = 0; @@ -127,7 +127,7 @@ extern "C" { #ifndef _di_status_code_convert_number_ f_return_status status_code_convert_number(const status_code_data_t data, const f_string_t value, f_number_unsigned_t *number) { - const f_string_range_t range = f_macro_string_range_initialize(strlen(value)); + const f_string_range_t range = f_macro_string_range_t_initialize(strlen(value)); f_status_t status = fl_conversion_string_to_number_unsigned(value, number, range); diff --git a/level_3/status_code/c/status_code.c b/level_3/status_code/c/status_code.c index e70e1ff..f9033d5 100644 --- a/level_3/status_code/c/status_code.c +++ b/level_3/status_code/c/status_code.c @@ -33,9 +33,9 @@ extern "C" { f_status_t status = F_none; { - f_console_parameters_t parameters = { data->parameters, status_code_total_parameters }; f_console_parameter_id_t ids[3] = { status_code_parameter_no_color, status_code_parameter_light, status_code_parameter_dark }; - f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameter_ids_t choices = { ids, 3 }; + const f_console_parameters_t parameters = { data->parameters, status_code_total_parameters }; status = fll_program_parameter_process(arguments, parameters, choices, F_true, &data->remaining, &data->context); -- 1.8.3.1