From: Kevin Day Date: Sun, 11 Mar 2012 05:41:46 +0000 (-0600) Subject: Add Project: error_code X-Git-Tag: 0.3.0~86 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=7219a1ac70164be999cf3273f9e03cf492131180;p=fll Add Project: error_code This is a cli front end for the error code to string translation. This only translates standard error codes. --- diff --git a/level_3/error_code/c/error_code.c b/level_3/error_code/c/error_code.c new file mode 100644 index 0000000..7345cbb --- /dev/null +++ b/level_3/error_code/c/error_code.c @@ -0,0 +1,172 @@ +/* FLL - Level 3 + * Project: FSS + * Version: 0.3.x + * Licenses: lgplv2.1 + * Programmers: Kevin Day + */ +#include + +#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 diff --git a/level_3/error_code/c/error_code.h b/level_3/error_code/c/error_code.h new file mode 100644 index 0000000..454f983 --- /dev/null +++ b/level_3/error_code/c/error_code.h @@ -0,0 +1,107 @@ +/* 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 +#include +#include + +// fll-0 includes +#include +#include +#include +#include +#include + +// fll-1 includes +#include +#include +#include +#include + +// fll-2 includes +#include + +#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 diff --git a/level_3/error_code/c/main.c b/level_3/error_code/c/main.c new file mode 100644 index 0000000..7050959 --- /dev/null +++ b/level_3/error_code/c/main.c @@ -0,0 +1,13 @@ +#include + +int main(const f_array_length argc, const f_string argv[]){ + error_code_data data = error_code_data_initialize; + + /* + if (f_pipe_exists()){ + data.process_pipe = f_true; + } + */ + + return error_code_main(argc, argv, &data); +} diff --git a/level_3/error_code/data/build/settings b/level_3/error_code/data/build/settings new file mode 100644 index 0000000..7ca25d0 --- /dev/null +++ b/level_3/error_code/data/build/settings @@ -0,0 +1,21 @@ +# fss-0000 + +project_name 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 +build_sources_library error_code.c +build_sources_program main.c +build_sources_headers error_code.h +build_shared yes + +flags_all -z now +flags_shared +flags_static +flags_library -fPIC +flags_program -fPIE -lerror_code