]> Kevux Git Server - fll/commitdiff
Update: Simplify and centralize reporting for FSS read errors.
authorKevin Day <Kevin@kevux.org>
Wed, 4 Sep 2024 01:17:50 +0000 (20:17 -0500)
committerKevin Day <Kevin@kevux.org>
Wed, 4 Sep 2024 01:17:50 +0000 (20:17 -0500)
Use a single function to handle the common cases.

This is an improvement upon commit a9b37a3f8fd99e45feff22779e8d375314cbb925.

level_3/fss_read/c/basic/fss_read.c
level_3/fss_read/c/basic_list/fss_read.c
level_3/fss_read/c/embedded_list/fss_read.c
level_3/fss_read/c/extended/fss_read.c
level_3/fss_read/c/extended_list/fss_read.c
level_3/fss_read/c/main/print/error.c
level_3/fss_read/c/main/print/error.h
level_3/fss_read/c/payload/fss_read.c

index 46ee25162d0c265ba1d4d51f5a08b35cc776c7e2..5c183f1b5f488aafebd22b4500bf498f4559c709 100644 (file)
@@ -24,31 +24,7 @@ extern "C" {
     fll_fss_basic_read(main->setting.buffer, &main->setting.range, &main->setting.objects, &main->setting.contents, &main->setting.quotes_object, &main->setting.delimits_object, &main->setting.delimits_content, &main->setting.state);
 
     if (F_status_is_error(main->setting.state.status)) {
-      if (F_status_set_fine(main->setting.state.status) == F_interrupt) return;
-
-      // Handle knownable errors with more user-friendly messages.
-      switch (F_status_set_fine(main->setting.state.status)) {
-        case F_end_not_eos:
-        case F_end_not_group_eos:
-        case F_end_not_group_stop:
-        case F_end_not_nest_eos:
-        case F_end_not_nest_stop:
-        case F_end_not_stop:
-          fss_read_print_error_fss_end_early(&main->program.error, fss_read_file_identify(main->setting.range.start, main->setting.files));
-
-          break;
-
-        default:
-          fll_error_file_print(
-            &main->program.error,
-            F_status_set_fine(main->setting.state.status),
-            macro_fss_read_f(fll_fss_basic_read),
-            fll_error_file_flag_fallback_e,
-            fss_read_file_identify(main->setting.range.start, main->setting.files),
-            f_file_operation_process_s,
-            fll_error_file_type_file_e
-          );
-      }
+      fss_read_print_error_fss_read(&main->program.error, macro_fss_read_f(fll_fss_basic_read));
 
       return;
     }
index 4146b914c6029333847496d7dc64040cd651c01a..c00338ff0399ca6695b0d0f4e4470ba57c8dbcc2 100644 (file)
@@ -24,31 +24,7 @@ extern "C" {
     fll_fss_basic_list_read(main->setting.buffer, &main->setting.range, &main->setting.objects, &main->setting.contents, &main->setting.delimits_object, &main->setting.delimits_content, &main->setting.comments, &main->setting.state);
 
     if (F_status_is_error(main->setting.state.status)) {
-      if (F_status_set_fine(main->setting.state.status) == F_interrupt) return;
-
-      // Handle knownable errors with more user-friendly messages.
-      switch (F_status_set_fine(main->setting.state.status)) {
-        case F_end_not_eos:
-        case F_end_not_group_eos:
-        case F_end_not_group_stop:
-        case F_end_not_nest_eos:
-        case F_end_not_nest_stop:
-        case F_end_not_stop:
-          fss_read_print_error_fss_end_early(&main->program.error, fss_read_file_identify(main->setting.range.start, main->setting.files));
-
-          break;
-
-        default:
-          fll_error_file_print(
-            &main->program.error,
-            F_status_set_fine(main->setting.state.status),
-            macro_fss_read_f(fll_fss_basic_list_read),
-            fll_error_file_flag_fallback_e,
-            fss_read_file_identify(main->setting.range.start, main->setting.files),
-            f_file_operation_process_s,
-            fll_error_file_type_file_e
-          );
-      }
+      fss_read_print_error_fss_read(&main->program.error, macro_fss_read_f(fll_fss_basic_list_read));
 
       return;
     }
index 32da9f2e7148addc3f5f552e5c1d749ff127812c..bcbf9fa1be61acdbb8387efcfe2e5b13450b7154 100644 (file)
@@ -33,31 +33,7 @@ extern "C" {
     }
 
     if (F_status_is_error(main->setting.state.status)) {
-      if (F_status_set_fine(main->setting.state.status) == F_interrupt) return;
-
-      // Handle knownable errors with more user-friendly messages.
-      switch (F_status_set_fine(main->setting.state.status)) {
-        case F_end_not_eos:
-        case F_end_not_group_eos:
-        case F_end_not_group_stop:
-        case F_end_not_nest_eos:
-        case F_end_not_nest_stop:
-        case F_end_not_stop:
-          fss_read_print_error_fss_end_early(&main->program.error, fss_read_file_identify(main->setting.range.start, main->setting.files));
-
-          break;
-
-        default:
-          fll_error_file_print(
-            &main->program.error,
-            F_status_set_fine(main->setting.state.status),
-            macro_fss_read_f(fll_fss_embedded_list_read),
-            fll_error_file_flag_fallback_e,
-            fss_read_file_identify(main->setting.range.start, main->setting.files),
-            f_file_operation_process_s,
-            fll_error_file_type_file_e
-          );
-      }
+      fss_read_print_error_fss_read(&main->program.error, macro_fss_read_f(fll_fss_embedded_list_read));
 
       return;
     }
index 3313c3aa4d09688f557235f466f6a6876338e6fe..bead09655e90e367eebfa2b65aa668ea0f3ef3c7 100644 (file)
@@ -24,31 +24,7 @@ extern "C" {
     fll_fss_extended_read(main->setting.buffer, &main->setting.range, &main->setting.objects, &main->setting.contents, &main->setting.quotes_object, &main->setting.quotes_content, &main->setting.delimits_object, &main->setting.delimits_content, &main->setting.state);
 
     if (F_status_is_error(main->setting.state.status)) {
-      if (F_status_set_fine(main->setting.state.status) == F_interrupt) return;
-
-      // Handle knownable errors with more user-friendly messages.
-      switch (F_status_set_fine(main->setting.state.status)) {
-        case F_end_not_eos:
-        case F_end_not_group_eos:
-        case F_end_not_group_stop:
-        case F_end_not_nest_eos:
-        case F_end_not_nest_stop:
-        case F_end_not_stop:
-          fss_read_print_error_fss_end_early(&main->program.error, fss_read_file_identify(main->setting.range.start, main->setting.files));
-
-          break;
-
-        default:
-          fll_error_file_print(
-            &main->program.error,
-            F_status_set_fine(main->setting.state.status),
-            macro_fss_read_f(fll_fss_extended_read),
-            fll_error_file_flag_fallback_e,
-            fss_read_file_identify(main->setting.range.start, main->setting.files),
-            f_file_operation_process_s,
-            fll_error_file_type_file_e
-          );
-      }
+      fss_read_print_error_fss_read(&main->program.error, macro_fss_read_f(fll_fss_extended_read));
 
       return;
     }
index 07dd060170b19c85a627bebee2293c3fe834ecc8..affe47b8213db94a915f6144e8ba3d64f745f4a8 100644 (file)
@@ -24,31 +24,7 @@ extern "C" {
     fll_fss_extended_list_read(main->setting.buffer, &main->setting.range, &main->setting.objects, &main->setting.closes, &main->setting.contents, &main->setting.delimits_object, &main->setting.delimits_content, &main->setting.comments, &main->setting.state);
 
     if (F_status_is_error(main->setting.state.status)) {
-      if (F_status_set_fine(main->setting.state.status) == F_interrupt) return;
-
-      // Handle knownable errors with more user-friendly messages.
-      switch (F_status_set_fine(main->setting.state.status)) {
-        case F_end_not_eos:
-        case F_end_not_group_eos:
-        case F_end_not_group_stop:
-        case F_end_not_nest_eos:
-        case F_end_not_nest_stop:
-        case F_end_not_stop:
-          fss_read_print_error_fss_end_early(&main->program.error, fss_read_file_identify(main->setting.range.start, main->setting.files));
-
-          break;
-
-        default:
-          fll_error_file_print(
-            &main->program.error,
-            F_status_set_fine(main->setting.state.status),
-            macro_fss_read_f(fll_fss_extended_list_read),
-            fll_error_file_flag_fallback_e,
-            fss_read_file_identify(main->setting.range.start, main->setting.files),
-            f_file_operation_process_s,
-            fll_error_file_type_file_e
-          );
-      }
+      fss_read_print_error_fss_read(&main->program.error, macro_fss_read_f(fll_fss_extended_list_read));
 
       return;
     }
index 44cd97304b43959b4eb5fd56740cd9898e08a6de..3fccd9ce647151e8979d9ed2ac1c3529b053e402 100644 (file)
@@ -46,6 +46,39 @@ extern "C" {
   }
 #endif // _di_fss_read_print_error_fss_end_early_
 
+#ifndef _di_fss_read_print_error_fss_read_
+  f_status_t fss_read_print_error_fss_read(fl_print_t * const print, const f_string_t function) {
+
+    if (!print || !print->custom) return F_status_set_error(F_output_not);
+    if (print->verbosity == f_console_verbosity_quiet_e) return F_output_not;
+
+    fss_read_main_t * const main = (fss_read_main_t *) print->custom;
+
+    switch (F_status_set_fine(main->setting.state.status)) {
+      case F_interrupt:
+        return F_output_not;
+
+      case F_end_not_eos:
+      case F_end_not_group_eos:
+      case F_end_not_group_stop:
+      case F_end_not_nest_eos:
+      case F_end_not_nest_stop:
+      case F_end_not_stop:
+        return fss_read_print_error_fss_end_early(&main->program.error, fss_read_file_identify(main->setting.range.start, main->setting.files));
+    }
+
+    return fll_error_file_print(
+      &main->program.error,
+      F_status_set_fine(main->setting.state.status),
+      function,
+      fll_error_file_flag_fallback_e,
+      fss_read_file_identify(main->setting.range.start, main->setting.files),
+      f_file_operation_process_s,
+      fll_error_file_type_file_e
+    );
+  }
+#endif // _di_fss_read_print_error_fss_read_
+
 #ifndef _di_fss_read_print_error_parameter_requires_message_
   f_status_t fss_read_print_error_parameter_requires_message(fl_print_t * const print, const f_string_static_t symbol, const f_string_static_t name, const f_string_static_t message) {
 
index f29707cfbed828fffd8641ad9d1bfe0cb3d7fb58..2eeb64c754e92a37a95c3be3088375425d4f8e73 100644 (file)
@@ -93,6 +93,34 @@ extern "C" {
 #endif // _di_fss_read_print_error_fss_end_early_
 
 /**
+ * Print FSS read error messages, handling known errors.
+ *
+ * This is intended to be called to handle errors from the various FSS read functions, such as fll_fss_basic_read().
+ *
+ * @param print
+ *   The output structure to print to.
+ *
+ *   The print.custom is expected to be of type fss_read_main_t.
+ *
+ *   This does not alter print.custom.setting.state.status.
+ * @param function
+ *   (optional) The name of the function where the error happened.
+ *
+ *   Set to NULL to disable.
+ *
+ * @return
+ *   F_okay on success.
+ *   F_output_not on success, but no printing is performed.
+ *
+ *   F_output_not (with error bit) if a parameter is NULL.
+ *
+ * @see fll_error_file_print()
+ */
+#ifndef _di_fss_read_print_error_fss_read_
+  extern f_status_t fss_read_print_error_fss_read(fl_print_t * const print, const f_string_t function);
+#endif // _di_fss_read_print_error_fss_read_
+
+/**
  * Print an error message about the parameter requires something that is explained by the message parameter.
  *
  * @param print
index 0b461acb8d2fb08b638fd7280368fd7cb572bc62..2b2aec5ea16ea83caba1fdac236726f50f197f47 100644 (file)
@@ -42,78 +42,72 @@ extern "C" {
     fll_fss_payload_read(main->setting.buffer, &main->setting.range, &main->setting.objects, &main->setting.contents, &main->setting.delimits_object, &main->setting.delimits_content, &main->setting.comments, &main->setting.state);
 
     if (F_status_is_error(main->setting.state.status)) {
-      if (F_status_set_fine(main->setting.state.status) == F_interrupt) return;
+      switch (F_status_set_fine(main->setting.state.status)) {
+        case F_okay_stop:
+        case F_okay_eos:
+          if (main->setting.flag & fss_read_main_flag_payload_error_d) {
+            fss_read_payload_print_problem_payload_missing(&main->program.error);
 
-      if (main->setting.state.status == F_status_set_error(F_okay_stop) || main->setting.state.status == F_status_set_error(F_okay_eos)) {
-        if (main->setting.flag & fss_read_main_flag_payload_error_d) {
-          fss_read_payload_print_problem_payload_missing(&main->program.error);
-
-          return;
-        }
-
-        if (main->setting.flag & (fss_read_main_flag_payload_error_d | fss_read_main_flag_payload_warn_d)) {
-          if (main->program.warning.verbosity > f_console_verbosity_normal_e) {
-            fss_read_payload_print_problem_payload_missing(&main->program.warning);
+            break;
           }
 
-          main->setting.state.status = F_okay;
-        }
-        else if (main->setting.flag & fss_read_main_flag_payload_create_d) {
-          main->setting.state.status = f_string_dynamic_append_assure(f_string_eol_s, &main->setting.buffer);
+          if (main->setting.flag & (fss_read_main_flag_payload_error_d | fss_read_main_flag_payload_warn_d)) {
+            if (main->program.warning.verbosity > f_console_verbosity_normal_e) {
+              fss_read_payload_print_problem_payload_missing(&main->program.warning);
+            }
 
-          if (F_status_is_error(main->setting.state.status)) {
-            fss_read_print_error(&main->program.error, macro_fss_read_f(f_string_dynamic_append_assure));
+            main->setting.state.status = F_okay;
           }
-          else {
-            main->setting.state.status = f_memory_array_increase(main->setting.state.step_small, sizeof(f_range_t), (void **) &main->setting.objects.array, &main->setting.objects.used, &main->setting.objects.size);
-
-            if (F_status_is_error_not(main->setting.state.status)) {
-              main->setting.state.status = f_memory_array_increase(main->setting.state.step_small, sizeof(f_ranges_t), (void **) &main->setting.contents.array, &main->setting.contents.used, &main->setting.contents.size);
-            }
+          else if (main->setting.flag & fss_read_main_flag_payload_create_d) {
+            main->setting.state.status = f_string_dynamic_append_assure(f_string_eol_s, &main->setting.buffer);
 
             if (F_status_is_error(main->setting.state.status)) {
-              fss_read_print_error(&main->program.error, macro_fss_read_f(f_memory_array_increase));
+              fss_read_print_error(&main->program.error, macro_fss_read_f(f_string_dynamic_append_assure));
             }
             else {
-              main->setting.objects.array[main->setting.objects.used].start = main->setting.buffer.used;
-
-              main->setting.state.status = f_string_dynamic_append(f_fss_payload_s, &main->setting.buffer);
-
-              if (F_status_is_error_not(main->setting.state.status)) {
-                main->setting.state.status = f_string_dynamic_append(f_fss_payload_list_open_s, &main->setting.buffer);
-              }
+              main->setting.state.status = f_memory_array_increase(main->setting.state.step_small, sizeof(f_range_t), (void **) &main->setting.objects.array, &main->setting.objects.used, &main->setting.objects.size);
 
               if (F_status_is_error_not(main->setting.state.status)) {
-                main->setting.state.status = f_string_dynamic_append(f_fss_payload_list_open_end_s, &main->setting.buffer);
+                main->setting.state.status = f_memory_array_increase(main->setting.state.step_small, sizeof(f_ranges_t), (void **) &main->setting.contents.array, &main->setting.contents.used, &main->setting.contents.size);
               }
 
               if (F_status_is_error(main->setting.state.status)) {
-                fss_read_print_error(&main->program.error, macro_fss_read_f(f_string_dynamic_append));
+                fss_read_print_error(&main->program.error, macro_fss_read_f(f_memory_array_increase));
               }
               else {
-                main->setting.objects.array[main->setting.objects.used].stop = main->setting.objects.array[main->setting.objects.used].start + f_fss_payload_s.used - 1;
-                main->setting.contents.array[main->setting.contents.used++].used = 0;
-                ++main->setting.objects.used;
+                main->setting.objects.array[main->setting.objects.used].start = main->setting.buffer.used;
+
+                main->setting.state.status = f_string_dynamic_append(f_fss_payload_s, &main->setting.buffer);
+
+                if (F_status_is_error_not(main->setting.state.status)) {
+                  main->setting.state.status = f_string_dynamic_append(f_fss_payload_list_open_s, &main->setting.buffer);
+                }
+
+                if (F_status_is_error_not(main->setting.state.status)) {
+                  main->setting.state.status = f_string_dynamic_append(f_fss_payload_list_open_end_s, &main->setting.buffer);
+                }
+
+                if (F_status_is_error(main->setting.state.status)) {
+                  fss_read_print_error(&main->program.error, macro_fss_read_f(f_string_dynamic_append));
+                }
+                else {
+                  main->setting.objects.array[main->setting.objects.used].stop = main->setting.objects.array[main->setting.objects.used].start + f_fss_payload_s.used - 1;
+                  main->setting.contents.array[main->setting.contents.used++].used = 0;
+                  ++main->setting.objects.used;
 
-                main->setting.state.status = F_okay;
+                  main->setting.state.status = F_okay;
+                }
               }
             }
           }
+
+          break;
+
+        default:
+          fss_read_print_error_fss_read(&main->program.error, macro_fss_read_f(fll_fss_payload_read));
         }
-      }
-      else {
-        fll_error_file_print(
-          &main->program.error,
-          F_status_set_fine(main->setting.state.status),
-          macro_fss_read_f(fll_fss_payload_read),
-          fll_error_file_flag_fallback_e,
-          fss_read_file_identify(main->setting.range.start, main->setting.files),
-          f_file_operation_process_s,
-          fll_error_file_type_file_e
-        );
 
         return;
-      }
     }
 
     if (main->setting.state.status == F_data_not_stop || main->setting.state.status == F_data_not_eos) {