From: Kevin Day Date: Sun, 17 Nov 2019 07:48:34 +0000 (-0600) Subject: Feature: implement pipe support in byte_dump X-Git-Tag: 0.5.0~374 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=c48da08db558f26b1e06570afdf8f0185b601c48;p=fll Feature: implement pipe support in byte_dump --- diff --git a/level_3/byte_dump/c/byte_dump.c b/level_3/byte_dump/c/byte_dump.c index 5bdc724..bcb019b 100644 --- a/level_3/byte_dump/c/byte_dump.c +++ b/level_3/byte_dump/c/byte_dump.c @@ -249,7 +249,37 @@ extern "C" { } if (data->process_pipe) { - // TODO: how should this be done? + f_file file = f_file_initialize; + + file.address = f_pipe; + + printf("%c", f_string_eol); + fl_color_print(f_standard_output, data->context.title, data->context.reset, "Piped Byte Dump: (in "); + + if (data->mode == byte_dump_mode_hexidecimal) { + fl_color_print(f_standard_output, data->context.title, data->context.reset, "Hexidecimal"); + } + else if (data->mode == byte_dump_mode_duodecimal) { + fl_color_print(f_standard_output, data->context.title, data->context.reset, "Duodecimal"); + } + else if (data->mode == byte_dump_mode_octal) { + fl_color_print(f_standard_output, data->context.title, data->context.reset, "Octal"); + } + else if (data->mode == byte_dump_mode_binary) { + fl_color_print(f_standard_output, data->context.title, data->context.reset, "Binary"); + } + else if (data->mode == byte_dump_mode_decimal) { + fl_color_print(f_standard_output, data->context.title, data->context.reset, "Decimal"); + } + + fl_color_print_line(f_standard_output, data->context.title, data->context.reset, ")"); + + status = byte_dump_file(*data, "-", file); + + if (f_status_is_error(status)) { + byte_dump_delete_data(data); + return status; + } } if (data->remaining.used > 0) { @@ -264,7 +294,7 @@ extern "C" { missing_files = status; } - byte_dump_print_file_error(data->context, status, "f_file_exists", arguments.argv[data->remaining.array[counter]]); + byte_dump_print_file_error(data->context, "f_file_exists", arguments.argv[data->remaining.array[counter]], f_status_set_fine(status)); } } // for @@ -281,7 +311,7 @@ extern "C" { status = f_file_open(&file, arguments.argv[data->remaining.array[counter]]); if (f_status_is_error(status)) { - byte_dump_print_file_error(data->context, status, "f_file_open", arguments.argv[data->remaining.array[counter]]); + byte_dump_print_file_error(data->context, "f_file_open", arguments.argv[data->remaining.array[counter]], f_status_set_fine(status)); byte_dump_delete_data(data); return status; } diff --git a/level_3/byte_dump/c/byte_dump.h b/level_3/byte_dump/c/byte_dump.h index db2ab96..227d30d 100644 --- a/level_3/byte_dump/c/byte_dump.h +++ b/level_3/byte_dump/c/byte_dump.h @@ -23,6 +23,7 @@ // fll-0 includes #include #include +#include #include #include #include diff --git a/level_3/byte_dump/c/private-byte_dump.c b/level_3/byte_dump/c/private-byte_dump.c index c78b1df..d22834e 100644 --- a/level_3/byte_dump/c/private-byte_dump.c +++ b/level_3/byte_dump/c/private-byte_dump.c @@ -788,17 +788,15 @@ extern "C" { #endif // _di_byte_dump_file_ #ifndef _di_byte_dump_print_file_error_ - void byte_dump_print_file_error(const fl_color_context context, const f_status status, const f_string function, const f_string file_name) { - f_status error = f_status_set_fine(status); - - if (error == f_false) { + void byte_dump_print_file_error(const fl_color_context context, const f_string function, const f_string file_name, const f_status status) { + if (status == f_false) { 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, "'."); return; } - if (error == f_invalid_parameter) { + if (status == f_invalid_parameter) { 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.notable, context.reset, "%s", function); fl_color_print(f_standard_error, context.error, context.reset, "() for the file '"); @@ -807,42 +805,42 @@ extern "C" { return; } - if (error == f_invalid_name) { + if (status == f_invalid_name) { fl_color_print(f_standard_error, context.error, context.reset, "ERROR: Invalid filename '"); fl_color_print(f_standard_error, context.notable, context.reset, "%s", file_name); fl_color_print_line(f_standard_error, context.error, context.reset, "'."); return; } - if (error == f_out_of_memory) { + if (status == f_out_of_memory) { fl_color_print(f_standard_error, context.error, context.reset, "CRITICAL ERROR: Unable to allocate memory, while trying to access 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, "'."); return; } - if (error == f_overflow) { + if (status == f_overflow) { fl_color_print(f_standard_error, context.error, context.reset, "ERROR: Overflow while trying to access 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, "'."); return; } - if (error == f_invalid_directory) { + if (status == f_invalid_directory) { fl_color_print(f_standard_error, context.error, context.reset, "ERROR: Invalid directory while trying to access 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, "'."); return; } - if (error == f_access_denied) { + if (status == f_access_denied) { fl_color_print(f_standard_error, context.error, context.reset, "ERROR: Access denied while trying to access 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, "'."); return; } - if (error == f_loop) { + if (status == f_loop) { fl_color_print(f_standard_error, context.error, context.reset, "ERROR: Loop while trying to access 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, "'."); @@ -850,7 +848,7 @@ extern "C" { } fl_color_print(f_standard_error, context.error, context.reset, "UNKNOWN ERROR: ("); - fl_color_print(f_standard_error, context.notable, context.reset, "%d", 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 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, "'."); diff --git a/level_3/byte_dump/c/private-byte_dump.h b/level_3/byte_dump/c/private-byte_dump.h index d0aff3c..6b1c98e 100644 --- a/level_3/byte_dump/c/private-byte_dump.h +++ b/level_3/byte_dump/c/private-byte_dump.h @@ -147,13 +147,15 @@ extern "C" { * The name of the function that failed. * @param file_name * The name of the file related to the error. + * @param status + * The status code representing the error. * * @param * f_true if error has been printed. * f_false if error has not been printed. */ #ifndef _di_byte_dump_print_file_error_ - extern void byte_dump_print_file_error(const fl_color_context context, const f_status status, const f_string function, const f_string file_name); + extern void byte_dump_print_file_error(const fl_color_context context, const f_string function, const f_string file_name, const f_status status); #endif // _di_byte_dump_print_file_error_ #ifdef __cplusplus