]> Kevux Git Server - fll/commitdiff
Add Package: fss_error_code
authorKevin Day <kevin@kevux.org>
Sun, 11 Mar 2012 05:48:07 +0000 (23:48 -0600)
committerKevin Day <kevin@kevux.org>
Sun, 11 Mar 2012 05:48:07 +0000 (23:48 -0600)
This is the handles translating fss-specific error codes to strings.

level_3/fss_error_code/c/fss_error_code.c [new file with mode: 0644]
level_3/fss_error_code/c/fss_error_code.h [new file with mode: 0644]
level_3/fss_error_code/c/main.c [new file with mode: 0644]
level_3/fss_error_code/data/build/settings [new file with mode: 0644]

diff --git a/level_3/fss_error_code/c/fss_error_code.c b/level_3/fss_error_code/c/fss_error_code.c
new file mode 100644 (file)
index 0000000..f8b5d0a
--- /dev/null
@@ -0,0 +1,172 @@
+/* FLL - Level 3
+ * Project:       FSS
+ * Version:       0.3.x
+ * Licenses:      lgplv2.1
+ * Programmers:   Kevin Day
+ */
+#include <level_3/fss_error_code.h>
+
+#ifdef __cplusplus
+extern "C"{
+#endif
+
+// version printed may be used by scripts, so this will only print the version number and a newline, no extra information or colors
+#ifndef _di_fss_error_code_print_version_
+  f_return_status fss_error_code_print_version(const fss_error_code_data data){
+    printf("%s\n", fss_error_code_version);
+
+    return f_none;
+  }
+#endif // _fss_error_code_print_version_
+
+#ifndef _di_fss_error_code_print_help_
+  f_return_status fss_error_code_print_help(const fss_error_code_data data){
+    printf("\n");
+    fl_print_color(f_standard_output, data.context.title, data.context.reset, " %s", fss_error_code_name_long);
+
+    printf("\n");
+    fl_print_color(f_standard_output, data.context.notable, data.context.reset, "  Version %s", fss_error_code_version);
+
+
+    printf("\n\n");
+    fl_print_color(f_standard_output, data.context.important, data.context.reset, " Available Options: ");
+
+    printf("\n  %s", f_console_symbol_short_enable);
+    fl_print_color(f_standard_output, data.context.standout, data.context.reset, f_console_standard_short_help);
+
+    printf(", %s", f_console_symbol_long_enable);
+    fl_print_color(f_standard_output, data.context.standout, data.context.reset, f_console_standard_long_help);
+    printf("      Print this help message");
+
+    printf("\n  %s", f_console_symbol_short_disable);
+    fl_print_color(f_standard_output, data.context.standout, data.context.reset, f_console_standard_short_light);
+
+    printf(", %s", f_console_symbol_long_disable);
+    fl_print_color(f_standard_output, data.context.standout, data.context.reset, f_console_standard_long_light);
+    printf("     Output using colors that show up better on light backgrounds");
+
+    printf("\n  %s", f_console_symbol_short_disable);
+    fl_print_color(f_standard_output, data.context.standout, data.context.reset, f_console_standard_short_no_color);
+
+    printf(", %s", f_console_symbol_long_disable);
+    fl_print_color(f_standard_output, data.context.standout, data.context.reset, f_console_standard_long_no_color);
+    printf("  Do not output in color");
+
+    printf("\n  %s", f_console_symbol_short_enable);
+    fl_print_color(f_standard_output, data.context.standout, data.context.reset, f_console_standard_short_version);
+
+    printf(", %s", f_console_symbol_long_enable);
+    fl_print_color(f_standard_output, data.context.standout, data.context.reset, f_console_standard_long_version);
+    printf("   Print only the version number");
+
+
+    printf("\n\n");
+    fl_print_color(f_standard_output, data.context.important, data.context.reset, " Usage: ");
+
+    printf("\n  ");
+    fl_print_color(f_standard_output, data.context.standout, data.context.reset, fss_error_code_name);
+
+    printf("  ");
+    fl_print_color(f_standard_output, data.context.notable, data.context.reset, "[");
+
+    printf(" options ");
+    fl_print_color(f_standard_output, data.context.notable, data.context.reset, "]");
+
+    printf("  ");
+    fl_print_color(f_standard_output, data.context.notable, data.context.reset, "<");
+
+    printf(" error code(s) ");
+    fl_print_color(f_standard_output, data.context.notable, data.context.reset, ">");
+
+
+    printf("\n\n");
+
+    return f_none;
+  }
+#endif // _di_fss_error_code_print_help_
+
+#ifndef _di_fss_error_code_main_
+  f_return_status fss_error_code_main(const f_array_length argc, const f_string argv[], fss_error_code_data *data){
+    f_status status            = f_status_initialize;
+    f_status allocation_status = f_status_initialize;
+
+    status = fl_process_parameters(argc, argv, data->parameters, fss_error_code_total_parameters, &data->remaining);
+
+    // load colors when not told to show no colors
+    if (data->parameters[fss_error_code_parameter_no_color].result == f_console_result_none){
+      fll_new_color_context(allocation_status, data->context);
+
+      if (allocation_status == f_none){
+        fll_colors_load_context(&data->context, data->parameters[fss_error_code_parameter_light].result == f_console_result_found);
+      } else {
+        fprintf(f_standard_error, "Critical Error: unable to allocate memory\n");
+        fss_error_code_delete_data(data);
+        return allocation_status;
+      }
+    }
+
+    if (status != f_none){
+      if (status == f_no_data){
+        fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: One of the parameters you passed requires an additional parameter that you did not pass.");
+        // TODO: there is a way to identify which parameter is incorrect
+        //       to do this, one must look for any "has_additional" and then see if the "additional" location is set to 0
+        //       nothing can be 0 as that represents the program name, unless argv[] is improperly created
+      } else if (f_macro_test_for_allocation_errors(status)){
+        fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory.");
+      } else if (status == f_invalid_parameter){
+        fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters().");
+      } else {
+        fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters().", status);
+      }
+
+      fss_error_code_delete_data(data);
+      return status;
+    }
+
+    // execute parameter results
+    if (data->parameters[fss_error_code_parameter_help].result == f_console_result_found){
+      fss_error_code_print_help(*data);
+    } else if (data->parameters[fss_error_code_parameter_version].result == f_console_result_found){
+      fss_error_code_print_version(*data);
+    } else if (data->remaining.used > 0 || data->process_pipe){
+      f_array_length counter = f_array_length_initialize;
+
+      if (data->process_pipe) {
+        // TODO: how should this be done?
+      }
+
+      if (data->remaining.used > 0){
+        for (; counter < data->remaining.used; counter++){
+          f_status code   = (f_status) atoll(argv[data->remaining.array[counter]]);
+          f_string string = f_null;
+
+          if (fll_fss_errors_to_string(code, &string) == f_none){
+            printf("%s\n", string);
+          }
+        } // for
+      }
+    } else {
+      fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: you failed to specify an error code.");
+      status = f_invalid_parameter;
+    }
+
+    fss_error_code_delete_data(data);
+    return status;
+  }
+#endif // _di_fss_error_code_main_
+
+#ifndef _di_fss_error_code_delete_data_
+  f_return_status fss_error_code_delete_data(fss_error_code_data *data){
+    f_status status = f_status_initialize;
+
+    f_delete_string_lengths(status, data->remaining);
+    fll_delete_color_context(status, data->context);
+
+    return f_none;
+  }
+#endif // _di_fss_error_code_delete_data_
+
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_3/fss_error_code/c/fss_error_code.h b/level_3/fss_error_code/c/fss_error_code.h
new file mode 100644 (file)
index 0000000..5ab002f
--- /dev/null
@@ -0,0 +1,108 @@
+/* FLL - Level 3
+ * Project:       FSS
+ * Version:       0.3.x
+ * Licenses:      lgplv2.1
+ * Programmers:   Kevin Day
+ * Documentation:
+ *
+ * This program provides error code to string translation.
+ */
+#ifndef _fss_error_code_h
+
+// libc includes
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+// fll-0 includes
+#include <level_0/types.h>
+#include <level_0/strings.h>
+#include <level_0/console.h>
+#include <level_0/output.h>
+#include <level_0/pipe.h>
+
+// fll-1 includes
+#include <level_1/colors.h>
+#include <level_1/console.h>
+#include <level_1/strings.h>
+#include <level_1/errors.h>
+
+// fll-2 includes
+#include <level_2/colors.h>
+#include <level_2/fss_errors.h>
+
+#ifdef __cplusplus
+extern "C"{
+#endif
+
+#ifndef _di_fss_error_code_version_
+  #define fss_error_code_major_version "0"
+  #define fss_error_code_minor_version "3"
+  #define fss_error_code_micro_version "0"
+  #define fss_error_code_version fss_error_code_major_version "." fss_error_code_minor_version "." fss_error_code_micro_version
+#endif // _di_fss_error_code_version_
+
+#ifndef _di_fss_error_code_name_
+  #define fss_error_code_name "fss_error_code"
+  #define fss_error_code_name_long "FSS Error Code"
+#endif // _di_fss_error_code_name_
+
+#ifndef _di_fss_error_code_defines_
+  enum {
+    fss_error_code_parameter_help,
+    fss_error_code_parameter_light,
+    fss_error_code_parameter_no_color,
+    fss_error_code_parameter_version,
+  };
+
+  #define f_console_parameter_initialize_fss_error_code \
+    { \
+      f_console_parameter_initialize(f_console_standard_short_help, f_console_standard_long_help, 0, 0, f_false, f_console_type_normal, 0), \
+      f_console_parameter_initialize(f_console_standard_short_light, f_console_standard_long_light, 0, 0, f_false, f_console_type_inverse, 0), \
+      f_console_parameter_initialize(f_console_standard_short_no_color, f_console_standard_long_no_color, 0, 0, f_false, f_console_type_inverse, 0), \
+      f_console_parameter_initialize(f_console_standard_short_version, f_console_standard_long_version, 0, 0, f_false, f_console_type_normal, 0), \
+    }
+
+  #define fss_error_code_total_parameters 4
+#endif // _di_fss_error_code_defines_
+
+#ifndef _di_fss_error_code_data_
+  typedef struct {
+    f_console_parameter parameters[fss_error_code_total_parameters];
+
+    f_string_lengths remaining;
+    f_bool           process_pipe;
+
+    fll_color_context context;
+  } fss_error_code_data;
+
+  #define fss_error_code_data_initialize \
+    { \
+      f_console_parameter_initialize_fss_error_code, \
+      f_string_lengths_initialize, \
+      f_false, \
+      fll_color_context_initialize, \
+    }
+#endif // _di_fss_error_code_data_
+
+#ifndef _di_fss_error_code_print_version_
+  extern f_return_status fss_error_code_print_version(const fss_error_code_data data);
+#endif // _di_fss_error_code_print_version_
+
+#ifndef _di_fss_error_code_print_help_
+  extern f_return_status fss_error_code_print_help(const fss_error_code_data data);
+#endif // _di_fss_error_code_print_help_
+
+#ifndef _di_fss_error_code_main_
+  extern f_return_status fss_error_code_main(const f_array_length argc, const f_string argv[], fss_error_code_data *data);
+#endif // _di_fss_error_code_main_
+
+#ifndef _di_fss_error_code_delete_data_
+  extern f_return_status fss_error_code_delete_data(fss_error_code_data *data);
+#endif // _di_fss_error_code_delete_data_
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _fss_error_code_h
diff --git a/level_3/fss_error_code/c/main.c b/level_3/fss_error_code/c/main.c
new file mode 100644 (file)
index 0000000..fdd3ada
--- /dev/null
@@ -0,0 +1,13 @@
+#include <level_3/fss_error_code.h>
+
+int main(const f_array_length argc, const f_string argv[]){
+  fss_error_code_data data = fss_error_code_data_initialize;
+
+  /*
+  if (f_pipe_exists()){
+    data.process_pipe = f_true;
+  }
+  */
+
+  return fss_error_code_main(argc, argv, &data);
+}
diff --git a/level_3/fss_error_code/data/build/settings b/level_3/fss_error_code/data/build/settings
new file mode 100644 (file)
index 0000000..6e88903
--- /dev/null
@@ -0,0 +1,21 @@
+# fss-0000
+
+project_name fss_error_code
+project_level 3
+
+version_major 0
+version_minor 3
+version_micro 0
+
+build_compiler gcc
+build_libraries -lc -lf_memory -lf_console -lfl_console -lf_conversion -lf_pipe -lf_output -lfl_colors -lfll_colors -lfl_errors -lfl_fss -lfll_fss
+build_sources_library fss_error_code.c
+build_sources_program main.c
+build_sources_headers fss_error_code.h
+build_shared yes
+
+flags_all -z now
+flags_shared
+flags_static
+flags_library -fPIC
+flags_program -fPIE -lfss_error_code