]> Kevux Git Server - fll/commitdiff
Progress: further work in Featureless Make, implement cleanup operation
authorKevin Day <thekevinday@gmail.com>
Mon, 11 May 2020 01:16:59 +0000 (20:16 -0500)
committerKevin Day <thekevinday@gmail.com>
Mon, 11 May 2020 01:16:59 +0000 (20:16 -0500)
level_3/fake/c/fake.c
level_3/fake/c/fake.h
level_3/fake/c/private-build.c
level_3/fake/c/private-clean.c
level_3/fake/c/private-clean.h
level_3/fake/c/private-fake.c
level_3/fake/c/private-fake.h
level_3/fake/data/build/dependencies
level_3/fake/data/build/settings

index 5dc796129c2f03653ce3110bef3a93cb0170d334..db67b5a36e5df3be86bbe9e5b759d122c6165fd2 100644 (file)
@@ -262,31 +262,49 @@ extern "C" {
           status = fake_build_operate(*data);
 
           if (f_status_is_error(status)) {
-            fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: the operation '");
-            fl_color_print(f_standard_error, data->context.notable, data->context.reset, "%s", fake_other_operation_clean);
-            fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "' failed.");
+            if (data->verbosity != fake_verbosity_quiet) {
+              fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: the operation '");
+              fl_color_print(f_standard_error, data->context.notable, data->context.reset, "%s", fake_other_operation_build);
+              fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "' failed.");
+            }
+
             break;
           }
         }
         else if (operations[i] == fake_operation_clean) {
-          fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: the operation '");
-          fl_color_print(f_standard_error, data->context.notable, data->context.reset, "%s", fake_other_operation_clean);
-          fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "' is not yet implemented.");
+          status = fake_clean_operate(*data);
+
+          if (f_status_is_error(status)) {
+            if (data->verbosity != fake_verbosity_quiet) {
+              fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: the operation '");
+              fl_color_print(f_standard_error, data->context.notable, data->context.reset, "%s", fake_other_operation_clean);
+              fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "' failed.");
+            }
+
+            break;
+          }
         }
         else if (operations[i] == fake_operation_make) {
-          fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: the operation '");
-          fl_color_print(f_standard_error, data->context.notable, data->context.reset, "%s", fake_other_operation_make);
-          fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "' is not yet implemented.");
+          if (data->verbosity != fake_verbosity_quiet) {
+            fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: the operation '");
+            fl_color_print(f_standard_error, data->context.notable, data->context.reset, "%s", fake_other_operation_make);
+            fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "' is not yet implemented.");
+          }
         }
         else if (operations[i] == fake_operation_skeleton) {
-          fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: the operation '");
-          fl_color_print(f_standard_error, data->context.notable, data->context.reset, "%s", fake_other_operation_skeleton);
-          fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "' is not yet implemented.");
+          if (data->verbosity != fake_verbosity_quiet) {
+            fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: the operation '");
+            fl_color_print(f_standard_error, data->context.notable, data->context.reset, "%s", fake_other_operation_skeleton);
+            fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "' is not yet implemented.");
+          }
         }
       } // for
     }
     else {
-      fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: you failed to specify an operation.");
+      if (data->verbosity != fake_verbosity_quiet) {
+        fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: you failed to specify an operation.");
+      }
+
       status = f_status_set_error(f_invalid_parameter);
     }
 
index f4e35adcb5dd4f9db8d605a6399b7a145fb19c4f..901db04e4e35cf58fcfdf64701a4081361612aab 100644 (file)
 #include <unistd.h>
 
 // fll-0 includes
-#include <level_0/console.h>
-#include <level_0/file.h>
 #include <level_0/status.h>
 #include <level_0/string.h>
 #include <level_0/type.h>
+#include <level_0/console.h>
+#include <level_0/directory.h>
+#include <level_0/file.h>
 
 // fll-1 includes
 #include <level_1/color.h>
 
 // fll-2 includes
 #include <level_2/execute.h>
+#include <level_2/directory.h>
 #include <level_2/fss.h>
 #include <level_2/fss_extended.h>
 #include <level_2/program.h>
@@ -245,6 +247,8 @@ extern "C" {
 #endif // _di_fake_build_language_
 
 #ifndef _di_fake_defines_
+  #define fake_directory_max_recursion 2048
+
   enum {
     fake_operation_build = 1,
     fake_operation_clean,
index 7f92034ff5b69b6895e9fc1c193ace16ebc00dc4..6bc3166674deb63a81d4711ff190535ce1d15de6 100644 (file)
@@ -48,7 +48,7 @@ extern "C" {
       }
 
       if (f_status_is_error(status)) {
-        fake_print_error_file(data.context, data.verbosity, f_status_set_fine(status), name_function, path.string, "file", f_true);
+        fake_print_error_file(data.context, data.verbosity, f_status_set_fine(status), name_function, path.string, f_true, f_true);
 
         f_macro_string_dynamic_delete_simple(buffer);
         f_macro_string_dynamic_delete_simple(path);
index a85ade620574d9e0913f2743b95c83cf7a10bf80..61e17ba2eb4d267b1f086d9bb96f841ee4d91923 100644 (file)
@@ -6,6 +6,46 @@
 extern "C" {
 #endif
 
+#ifndef _di_fake_clean_operate_
+  f_return_status fake_clean_operate(const fake_data data) {
+    f_status status = f_none;
+
+    if (data.verbosity != fake_verbosity_quiet) {
+      printf("%c", f_string_eol);
+      fl_color_print(f_standard_output, data.context.important, data.context.reset, "Deleting all files within build directory '");
+      fl_color_print(f_standard_output, data.context.notable, data.context.reset, "%s", data.path_build.string);
+      fl_color_print_line(f_standard_output, data.context.important, data.context.reset, "'.");
+    }
+
+    if (data.verbosity == fake_verbosity_verbose) {
+      status = f_directory_remove_custom(data.path_build.string, fake_directory_max_recursion, f_true, fake_clean_remove_recursively_verbosely);
+    }
+    else {
+      status = f_directory_remove(data.path_build.string, fake_directory_max_recursion, f_true);
+    }
+
+    if (f_status_is_error(status)) {
+      fake_print_error(data.context, data.verbosity, f_status_set_fine(status), "f_directory_remove", f_true);
+      return status;
+    }
+
+    return f_none;
+  }
+#endif // _di_fake_clean_operate_
+
+#if !defined(_di_fake_clean_operate_)
+  int fake_clean_remove_recursively_verbosely(const char *path, const struct stat *file_stat, int type, struct FTW *entity) {
+    if (entity->level == 0) return 0;
+
+    int result = remove(path);
+
+    if (result == 0) {
+      printf("Removed '%s'.%c", path, f_string_eol);
+    }
+
+    return result;
+  }
+#endif // !defined(_di_fake_clean_operate_)
 
 #ifdef __cplusplus
 } // extern "C"
index 01e125cc057cbb3cc19d6b6abbcaca470b60d1e8..df83f07c1aebcdab4c9bceaf068c3b2ef9f412c9 100644 (file)
 extern "C" {
 #endif
 
+/**
+ * Execute the clean operation.
+ *
+ * @param data
+ *   The program data.
+ *
+ * @return
+ *   f_none on success.
+ *   Status codes (with error bit) are returned on any problem.
+ */
+#ifndef _di_fake_clean_operate_
+  extern f_return_status fake_clean_operate(const fake_data data) f_gcc_attribute_visibility_internal;
+#endif // _di_fake_clean_operate_
+
+
+/**
+ * A special function intended to be used directly by nftw().
+ *
+ * This is intended to be used by the specified function as a function pointer and therefore follows the required structure.
+ *
+ * This is essentially a wrapper to remove().
+ *
+ * @param path
+ *   The file path.
+ * @param file_stat
+ *   The file stat.
+ * @param type
+ *   The file type.
+ * @param entity
+ *   The FTW entity.
+ *
+ * @return
+ *   0 on success.
+ *   -1 on failure.
+ *   Check errno for details.
+ *
+ * @see f_directory_remove()
+ * @see nftw()
+ * @see remove()
+ */
+#if !defined(_di_fake_clean_operate_)
+  extern int fake_clean_remove_recursively_verbosely(const char *path, const struct stat *file_stat, int type, struct FTW *entity) f_gcc_attribute_visibility_internal;
+#endif // !defined(_di_fake_clean_operate_)
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
index b7a4d54bc9ed4684b386280055172674beddc4c3..5ad664ef62a01f1b396f1183c023cac6e648dc57 100644 (file)
@@ -194,22 +194,16 @@ extern "C" {
 #endif // _di_fake_print_error_
 
 #ifndef _di_fake_print_error_file_
-  f_return_status fake_print_error_file(const fl_color_context context, const uint8_t verbosity, const f_status status, const f_string function, const f_string file_name, const f_string file_or_directory, const bool fallback) {
+  f_return_status fake_print_error_file(const fl_color_context context, const uint8_t verbosity, const f_status status, const f_string function, const f_string name, const bool is_file, const bool fallback) {
+    f_string file_or_directory = 0;
 
-    if (status == f_file_not_found) {
-      if (verbosity != fake_verbosity_quiet) {
-        fl_color_print(f_standard_error, context.error, context.reset, "ERROR: failed to find file '");
-        fl_color_print(f_standard_error, context.notable, context.reset, "%s", file_name);
-        fl_color_print_line(f_standard_error, context.error, context.reset, "'.");
-      }
+    if (is_file) file_or_directory = "file";
+    else file_or_directory = "directory";
 
-      return f_none;
-    }
-
-    if (status == f_directory_not_found) {
+    if (status == f_file_not_found) {
       if (verbosity != fake_verbosity_quiet) {
-        fl_color_print(f_standard_error, context.error, context.reset, "ERROR: failed to find directory '");
-        fl_color_print(f_standard_error, context.notable, context.reset, "%s", file_name);
+        fl_color_print(f_standard_error, context.error, context.reset, "ERROR: failed to find %s '", file_or_directory);
+        fl_color_print(f_standard_error, context.notable, context.reset, "%s", name);
         fl_color_print_line(f_standard_error, context.error, context.reset, "'.");
       }
 
@@ -218,10 +212,10 @@ extern "C" {
 
     if (status == f_invalid_parameter) {
       if (verbosity != fake_verbosity_quiet) {
-        fl_color_print(f_standard_error, context.error, context.reset, "INTERNAL ERROR: Invalid parameter when calling ", function, file_name);
+        fl_color_print(f_standard_error, context.error, context.reset, "INTERNAL ERROR: Invalid parameter when calling ", function, name);
         fl_color_print(f_standard_error, context.notable, context.reset, "%s", function);
         fl_color_print(f_standard_error, context.error, context.reset, "() for the %s '", file_or_directory);
-        fl_color_print(f_standard_error, context.notable, context.reset, "%s", file_name);
+        fl_color_print(f_standard_error, context.notable, context.reset, "%s", name);
         fl_color_print_line(f_standard_error, context.error, context.reset, "'.");
       }
 
@@ -231,7 +225,7 @@ extern "C" {
     if (status == f_invalid_name) {
       if (verbosity != fake_verbosity_quiet) {
         fl_color_print(f_standard_error, context.error, context.reset, "ERROR: Invalid %s name '", file_or_directory);
-        fl_color_print(f_standard_error, context.notable, context.reset, "%s", file_name);
+        fl_color_print(f_standard_error, context.notable, context.reset, "%s", name);
         fl_color_print_line(f_standard_error, context.error, context.reset, "'.");
       }
 
@@ -241,7 +235,7 @@ extern "C" {
     if (status == f_out_of_memory) {
       if (verbosity != fake_verbosity_quiet) {
         fl_color_print(f_standard_error, context.error, context.reset, "CRITICAL ERROR: Unable to allocate memory, while trying to access %s '", file_or_directory);
-        fl_color_print(f_standard_error, context.notable, context.reset, "%s", file_name);
+        fl_color_print(f_standard_error, context.notable, context.reset, "%s", name);
         fl_color_print_line(f_standard_error, context.error, context.reset, "'.");
       }
 
@@ -251,7 +245,7 @@ extern "C" {
     if (status == f_number_overflow) {
       if (verbosity != fake_verbosity_quiet) {
         fl_color_print(f_standard_error, context.error, context.reset, "ERROR: Overflow while trying to access %s '", file_or_directory);
-        fl_color_print(f_standard_error, context.notable, context.reset, "%s", file_name);
+        fl_color_print(f_standard_error, context.notable, context.reset, "%s", name);
         fl_color_print_line(f_standard_error, context.error, context.reset, "'.");
       }
 
@@ -261,7 +255,7 @@ extern "C" {
     if (status == f_invalid_directory) {
       if (verbosity != fake_verbosity_quiet) {
         fl_color_print(f_standard_error, context.error, context.reset, "ERROR: Invalid directory while trying to access %s '", file_or_directory);
-        fl_color_print(f_standard_error, context.notable, context.reset, "%s", file_name);
+        fl_color_print(f_standard_error, context.notable, context.reset, "%s", name);
         fl_color_print_line(f_standard_error, context.error, context.reset, "'.");
       }
 
@@ -271,7 +265,7 @@ extern "C" {
     if (status == f_access_denied) {
       if (verbosity != fake_verbosity_quiet) {
         fl_color_print(f_standard_error, context.error, context.reset, "ERROR: Access denied while trying to access %s '", file_or_directory);
-        fl_color_print(f_standard_error, context.notable, context.reset, "%s", file_name);
+        fl_color_print(f_standard_error, context.notable, context.reset, "%s", name);
         fl_color_print_line(f_standard_error, context.error, context.reset, "'.");
       }
 
@@ -281,18 +275,52 @@ extern "C" {
     if (status == f_loop) {
       if (verbosity != fake_verbosity_quiet) {
         fl_color_print(f_standard_error, context.error, context.reset, "ERROR: Loop while trying to access %s '", file_or_directory);
-        fl_color_print(f_standard_error, context.notable, context.reset, "%s", file_name);
+        fl_color_print(f_standard_error, context.notable, context.reset, "%s", name);
         fl_color_print_line(f_standard_error, context.error, context.reset, "'.");
       }
 
       return f_none;
     }
 
+    if (is_file) {
+    }
+    else {
+      if (status == f_directory_not_found) {
+        if (verbosity != fake_verbosity_quiet) {
+          fl_color_print(f_standard_error, context.error, context.reset, "ERROR: failed to find %s '", file_or_directory);
+          fl_color_print(f_standard_error, context.notable, context.reset, "%s", name);
+          fl_color_print_line(f_standard_error, context.error, context.reset, "'.");
+        }
+
+        return f_none;
+      }
+
+      if (status == f_no_data) {
+        if (verbosity != fake_verbosity_quiet) {
+          fl_color_print(f_standard_error, context.error, context.reset, "ERROR: could not find %s '", file_or_directory);
+          fl_color_print(f_standard_error, context.notable, context.reset, "%s", name);
+          fl_color_print_line(f_standard_error, context.error, context.reset, "'.");
+        }
+
+        return f_none;
+      }
+
+      if (status == f_failure) {
+        if (verbosity != fake_verbosity_quiet) {
+          fl_color_print(f_standard_error, context.error, context.reset, "ERROR: failed to read the %s '", file_or_directory);
+          fl_color_print(f_standard_error, context.notable, context.reset, "%s", name);
+          fl_color_print_line(f_standard_error, context.error, context.reset, "'.");
+        }
+
+        return f_none;
+      }
+    }
+
     if (fake_print_error(context, verbosity, status, function, f_false) == f_unknown && fallback && verbosity != fake_verbosity_quiet) {
       fl_color_print(f_standard_error, context.error, context.reset, "UNKNOWN ERROR: (");
       fl_color_print(f_standard_error, context.notable, context.reset, "%d", status);
       fl_color_print(f_standard_error, context.error, context.reset, ") occurred for %s '", file_or_directory);
-      fl_color_print(f_standard_error, context.notable, context.reset, "%s", file_name);
+      fl_color_print(f_standard_error, context.notable, context.reset, "%s", name);
       fl_color_print_line(f_standard_error, context.error, context.reset, "'.");
     }
 
@@ -573,7 +601,7 @@ extern "C" {
 
           if (f_status_is_error(status)) {
             if (f_status_set_fine(status) != f_directory_not_found || parameters_required[i]) {
-              fake_print_error_file(data->context, data->verbosity, f_status_set_fine(status), "f_file_stat", parameter_values[i]->string, "directory", f_true);
+              fake_print_error_file(data->context, data->verbosity, f_status_set_fine(status), "f_file_stat", parameter_values[i]->string, f_false, f_true);
               return status;
             }
           }
index c88d08b207516f35ce98f88474a436f3b4408780..2e9092ea5eb85e2ebb5a1df2e683a41a518774cf 100644 (file)
@@ -59,10 +59,10 @@ extern "C" {
  *   The error status code to report on.
  * @param function
  *   The function call that returned the error.
- * @param file_name
+ * @param name
  *   The name of the file or directory.
- * @param file_or_directory
- *   A string that should be either 'file' or 'directory' used when printing the message.
+ * @param is_file
+ *   Set to TRUE if this is a file and FALSE if this is a directory.
  * @param fallback
  *   Set to f_true to print the fallback error message for unknown errors.
  *
@@ -71,7 +71,7 @@ extern "C" {
  *   f_unknown is returned if the status code has no print message.
  */
 #ifndef _di_fake_print_error_file_
-  extern f_return_status fake_print_error_file(const fl_color_context context, const uint8_t verbosity, const f_status status, const f_string function, const f_string file_name, const f_string file_or_directory, const bool fallback) f_gcc_attribute_visibility_internal;
+  extern f_return_status fake_print_error_file(const fl_color_context context, const uint8_t verbosity, const f_status status, const f_string function, const f_string name, const bool is_file, const bool fallback) f_gcc_attribute_visibility_internal;
 #endif // _di_fake_print_error_file_
 
 /**
index 7794fe9d448a20c91aa97142ff6edb5e750cbe6b..c7ca115364341d42891639bf3aea1729428e09a5 100644 (file)
@@ -11,6 +11,7 @@ f_print
 f_utf
 fl_color
 fl_console
+fl_directory
 fl_file
 fl_fss
 fl_string
index 55bef6b33ea57ee8c6bc2c8253dca773a0e58196..1312632485eaf3c391029b03dfdf2dc102b8fe50 100644 (file)
@@ -13,7 +13,7 @@ version_micro 0
 build_compiler gcc
 build_linker ar
 build_libraries -lc
-build_libraries_fll -lfll_execute -lfll_fss -lfll_program -lfl_utf -lfl_string -lfl_file -lfl_fss -lfl_console -lfl_color -lf_utf -lf_print -lf_file -lf_conversion -lf_console -lf_memory
+build_libraries_fll -lfll_program -lfll_fss -lfll_execute -lfl_utf -lfl_string -lfl_file -lfl_fss -lfl_directory -lfl_console -lfl_color -lf_utf -lf_print -lf_file -lf_conversion -lf_console -lf_memory
 build_libraries_fll-level -lfll_2 -lfll_1 -lfll_0
 build_libraries_fll-monolithic -lfll
 build_sources_library fake.c private-fake.c private-clean.c private-build.c private-make.c private-skeleton.c