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.
* - 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_
#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_
/**
}
#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);
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 {
}
}
- 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
* 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:
* @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.
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