--- /dev/null
+/* FLL - Level 3
+ * Project: FSS
+ * Version: 0.3.x
+ * Licenses: lgplv2.1
+ * Programmers: Kevin Day
+ */
+#include <level_3/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_error_code_print_version_
+ f_return_status error_code_print_version(const error_code_data data){
+ printf("%s\n", error_code_version);
+
+ return f_none;
+ }
+#endif // _error_code_print_version_
+
+#ifndef _di_error_code_print_help_
+ f_return_status error_code_print_help(const error_code_data data){
+ printf("\n");
+ fl_print_color(f_standard_output, data.context.title, data.context.reset, " %s", error_code_name_long);
+
+ printf("\n");
+ fl_print_color(f_standard_output, data.context.notable, data.context.reset, " Version %s", 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, 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_error_code_print_help_
+
+#ifndef _di_error_code_main_
+ f_return_status error_code_main(const f_array_length argc, const f_string argv[], 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, error_code_total_parameters, &data->remaining);
+
+ // load colors when not told to show no colors
+ if (data->parameters[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[error_code_parameter_light].result == f_console_result_found);
+ } else {
+ fprintf(f_standard_error, "Critical Error: unable to allocate memory\n");
+ 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);
+ }
+
+ error_code_delete_data(data);
+ return status;
+ }
+
+ // execute parameter results
+ if (data->parameters[error_code_parameter_help].result == f_console_result_found){
+ error_code_print_help(*data);
+ } else if (data->parameters[error_code_parameter_version].result == f_console_result_found){
+ 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 (fl_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;
+ }
+
+ error_code_delete_data(data);
+ return status;
+ }
+#endif // _di_error_code_main_
+
+#ifndef _di_error_code_delete_data_
+ f_return_status error_code_delete_data(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_error_code_delete_data_
+
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
--- /dev/null
+/* 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 _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>
+
+#ifdef __cplusplus
+extern "C"{
+#endif
+
+#ifndef _di_error_code_version_
+ #define error_code_major_version "0"
+ #define error_code_minor_version "3"
+ #define error_code_micro_version "0"
+ #define error_code_version error_code_major_version "." error_code_minor_version "." error_code_micro_version
+#endif // _di_error_code_version_
+
+#ifndef _di_error_code_name_
+ #define error_code_name "error_code"
+ #define error_code_name_long "Error Code"
+#endif // _di_error_code_name_
+
+#ifndef _di_error_code_defines_
+ enum {
+ error_code_parameter_help,
+ error_code_parameter_light,
+ error_code_parameter_no_color,
+ error_code_parameter_version,
+ };
+
+ #define f_console_parameter_initialize_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 error_code_total_parameters 4
+#endif // _di_error_code_defines_
+
+#ifndef _di_error_code_data_
+ typedef struct {
+ f_console_parameter parameters[error_code_total_parameters];
+
+ f_string_lengths remaining;
+ f_bool process_pipe;
+
+ fll_color_context context;
+ } error_code_data;
+
+ #define error_code_data_initialize \
+ { \
+ f_console_parameter_initialize_error_code, \
+ f_string_lengths_initialize, \
+ f_false, \
+ fll_color_context_initialize, \
+ }
+#endif // _di_error_code_data_
+
+#ifndef _di_error_code_print_version_
+ extern f_return_status error_code_print_version(const error_code_data data);
+#endif // _di_error_code_print_version_
+
+#ifndef _di_error_code_print_help_
+ extern f_return_status error_code_print_help(const error_code_data data);
+#endif // _di_error_code_print_help_
+
+#ifndef _di_error_code_main_
+ extern f_return_status error_code_main(const f_array_length argc, const f_string argv[], error_code_data *data);
+#endif // _di_error_code_main_
+
+#ifndef _di_error_code_delete_data_
+ extern f_return_status error_code_delete_data(error_code_data *data);
+#endif // _di_error_code_delete_data_
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _error_code_h