]> Kevux Git Server - fll/commitdiff
Update: Change fl_directory_do() to make the action optional as well.
authorKevin Day <Kevin@kevux.org>
Sun, 27 Apr 2025 02:46:04 +0000 (21:46 -0500)
committerKevin Day <Kevin@kevux.org>
Sun, 27 Apr 2025 02:46:04 +0000 (21:46 -0500)
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.

level_0/f_directory/c/directory/common.h
level_1/fl_directory/c/directory.c
level_1/fl_directory/c/directory.h
level_1/fl_directory/c/private-directory.c

index 9b14ca4bdf5fe9683751867ca048e792f100928a..e3d5dd65885ee06a4222a48bea73797ac3930a2c 100644 (file)
@@ -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_
 
 /**
index d82ec37182988720c5c4b952c6aac6b93fd65f63..bb0ac9a84116357e0f1e6c3343798c7412108bc6 100644 (file)
@@ -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
 
index b10978a1aa6e862e9ebacc0166ec8f11b3ad5082..a83ed7a3cd934be86091a83d08f298e100f85ae6 100644 (file)
@@ -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.
index 86c2b5e30bee609c0550bb861b74554376a14884..7d2385fbb8fe7036e9f3368bbab5edcd7d80c8b1 100644 (file)
@@ -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