From: Kevin Day Date: Sun, 27 Apr 2025 02:46:04 +0000 (-0500) Subject: Update: Change fl_directory_do() to make the action optional as well. X-Git-Tag: 0.7.1~8 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=eeab96706d4dcb4701cb5ec03fc76f0617d2da82;p=fll Update: Change fl_directory_do() to make the action optional as well. The action flag for `fl_directory_do()` should also be optional. Adjust the code so that recursion still happens even if the action flag is not set. This better allows for cases where the before is to be used but the action itself is not needed. This happens to be the case with Featureless Make. Add additional helper flags. Improve documentation comments. Add a warning about setting the top string to a string that is changed during recursion. --- diff --git a/level_0/f_directory/c/directory/common.h b/level_0/f_directory/c/directory/common.h index 9b14ca4..e3d5dd6 100644 --- a/level_0/f_directory/c/directory/common.h +++ b/level_0/f_directory/c/directory/common.h @@ -132,14 +132,15 @@ extern "C" { * - white_out: File is a special type called "white out", which is supported in Linux but is not generally used by most file systems. * * The helper flags: - * - before_after: Helper flag representing both before and after flags. - * - clean_list: Helper flag represeting both clean and list flags. - * - except_directory: Helper flag representing all type flags except for directory. - * - mask_basic: Helper flag representing the basic flags. - * - mask_type: Helper flag representing the action flags. - * - list_after: Helper flag representing both path and after flags. - * - list_before: Helper flag representing both path and before flags. - * - list_path: Helper flag representing both path and list flags. + * - before_action_after: Helper flag representing both before, action, and after flags. + * - before_after: Helper flag representing both before and after flags. + * - clean_list: Helper flag represeting both clean and list flags. + * - except_directory: Helper flag representing all type flags except for directory. + * - mask_basic: Helper flag representing the basic flags. + * - mask_type: Helper flag representing the action flags. + * - list_after: Helper flag representing both path and after flags. + * - list_before: Helper flag representing both path and before flags. + * - list_path: Helper flag representing both path and list flags. */ #ifndef _di_f_directory_recurse_do_flag_d_ @@ -165,14 +166,15 @@ extern "C" { #define f_directory_recurse_do_flag_white_out_d 0x8000 // The helper flags. - #define f_directory_recurse_do_flag_before_after_d 0x6 - #define f_directory_recurse_do_flag_clean_list_d 0x28 - #define f_directory_recurse_do_flag_except_directory_d 0xfd80 - #define f_directory_recurse_do_flag_mask_basic_d 0x7f - #define f_directory_recurse_do_flag_mask_type_d 0xff80 - #define f_directory_recurse_do_flag_path_after_d 0x42 - #define f_directory_recurse_do_flag_path_before_d 0x44 - #define f_directory_recurse_do_flag_path_list_d 0x60 + #define f_directory_recurse_do_flag_before_action_after_d 0x7 + #define f_directory_recurse_do_flag_before_after_d 0x6 + #define f_directory_recurse_do_flag_clean_list_d 0x28 + #define f_directory_recurse_do_flag_except_directory_d 0xfd80 + #define f_directory_recurse_do_flag_mask_basic_d 0x7f + #define f_directory_recurse_do_flag_mask_type_d 0xff80 + #define f_directory_recurse_do_flag_path_after_d 0x42 + #define f_directory_recurse_do_flag_path_before_d 0x44 + #define f_directory_recurse_do_flag_path_list_d 0x60 #endif // _di_f_directory_recurse_do_flag_d_ /** diff --git a/level_1/fl_directory/c/directory.c b/level_1/fl_directory/c/directory.c index d82ec37..bb0ac9a 100644 --- a/level_1/fl_directory/c/directory.c +++ b/level_1/fl_directory/c/directory.c @@ -76,6 +76,13 @@ extern "C" { } #endif // _di_level_1_parameter_checking_ + // Do nothing if nothing is asked to be done. + if (!(recurse->flag & f_directory_recurse_do_flag_before_action_after_d)) { + recurse->state.status = F_okay; + + return; + } + if (path.used) { recurse->state.status = f_string_dynamic_append_assure_nulless(path, &recurse->path); @@ -94,7 +101,9 @@ extern "C" { recurse->state.status = f_directory_exists(recurse->path); - recurse->state.status = recurse->state.status == F_false ? F_status_set_error(F_directory_not) : F_okay; + recurse->state.status = (recurse->state.status == F_false) + ? F_status_set_error(F_directory_not) + : F_okay; } } else { @@ -156,17 +165,19 @@ extern "C" { } } - recurse->state.status = F_okay; + if (flag_actions[action] != f_directory_recurse_do_flag_action_d || recurse->flag & f_directory_recurse_do_flag_action_d) { + recurse->state.status = F_okay; - recurse->action(recurse, path, flag_actions[action] | f_directory_recurse_do_flag_directory_d); + recurse->action(recurse, path, flag_actions[action] | f_directory_recurse_do_flag_directory_d); - if (F_status_is_error(recurse->state.status)) { - private_inline_fl_directory_do_handle(recurse, path, flag_actions[action] | f_directory_recurse_do_flag_directory_d); - if (F_status_is_error(recurse->state.status)) break; - } + if (F_status_is_error(recurse->state.status)) { + private_inline_fl_directory_do_handle(recurse, path, flag_actions[action] | f_directory_recurse_do_flag_directory_d); + if (F_status_is_error(recurse->state.status)) break; + } - // There is nothing to continue onto, so all of these result in a break out of the loop. - if (recurse->state.status == F_break || recurse->state.status == F_done || recurse->state.status == F_continue || F_status_set_fine(recurse->state.status) == F_interrupt) break; + // There is nothing to continue onto, so all of these result in a break out of the loop. + if (recurse->state.status == F_break || recurse->state.status == F_done || recurse->state.status == F_continue || F_status_set_fine(recurse->state.status) == F_interrupt) break; + } } } // for diff --git a/level_1/fl_directory/c/directory.h b/level_1/fl_directory/c/directory.h index b10978a..a83ed7a 100644 --- a/level_1/fl_directory/c/directory.h +++ b/level_1/fl_directory/c/directory.h @@ -106,6 +106,10 @@ extern "C" { * The directory recurse happens before the action. * The action happens before the after. * + * The before only happens if recurse.flag has f_directory_recurse_do_flag_before_d. + * The action only happens if recurse.flag has f_directory_recurse_do_flag_action_d. + * The after only happens if recurse.flag has f_directory_recurse_do_flag_after_d. + * * The action() and handle() should check if the recurse is NULL (and any other appropraite NULL checks). * * General behavior flow: @@ -128,6 +132,9 @@ extern "C" { * @param path * The directory file path. * + * This value gets pointed to by recurse.path_top. + * There is potential for problems if the memory pointed to by this string is altered as part of the recursion processing. + * * Must be NULL terminated. * @param recurse * The directory recurse data. diff --git a/level_1/fl_directory/c/private-directory.c b/level_1/fl_directory/c/private-directory.c index 86c2b5e..7d2385f 100644 --- a/level_1/fl_directory/c/private-directory.c +++ b/level_1/fl_directory/c/private-directory.c @@ -141,25 +141,27 @@ extern "C" { if (F_status_is_error(recurse->state.status)) break; } - // This loop is not considered a loop for breaking and continuing. - if (recurse->state.status == F_break || recurse->state.status == F_done || recurse->state.status == F_continue || F_status_set_fine(recurse->state.status) == F_interrupt) break; - // Reset the path after operating on child directories. recurse->path.used = used_directory; recurse->path.string[recurse->path.used] = 0; + + // This loop is not considered a loop for breaking and continuing. + if (recurse->state.status == F_break || recurse->state.status == F_done || recurse->state.status == F_continue || F_status_set_fine(recurse->state.status) == F_interrupt) break; } - recurse->state.status = F_okay; + if (flag_actions[action] != f_directory_recurse_do_flag_action_d || recurse->flag & f_directory_recurse_do_flag_action_d) { + recurse->state.status = F_okay; - recurse->action(recurse, name, flag_actions[action] | flag); + recurse->action(recurse, name, flag_actions[action] | flag); - if (F_status_is_error(recurse->state.status)) { - private_inline_fl_directory_do_handle(recurse, name, flag_actions[action] | flag); - if (F_status_is_error(recurse->state.status)) break; - } + if (F_status_is_error(recurse->state.status)) { + private_inline_fl_directory_do_handle(recurse, name, flag_actions[action] | flag); + if (F_status_is_error(recurse->state.status)) break; + } - // This loop is not considered a loop for breaking and continuing. - if (recurse->state.status == F_break || recurse->state.status == F_done || recurse->state.status == F_continue || F_status_set_fine(recurse->state.status) == F_interrupt) break; + // This loop is not considered a loop for breaking and continuing. + if (recurse->state.status == F_break || recurse->state.status == F_done || recurse->state.status == F_continue || F_status_set_fine(recurse->state.status) == F_interrupt) break; + } } } // for