]> Kevux Git Server - fll/commitdiff
Feature: implement pipe support in byte_dump
authorKevin Day <thekevinday@gmail.com>
Sun, 17 Nov 2019 07:48:34 +0000 (01:48 -0600)
committerKevin Day <thekevinday@gmail.com>
Sun, 17 Nov 2019 07:48:34 +0000 (01:48 -0600)
level_3/byte_dump/c/byte_dump.c
level_3/byte_dump/c/byte_dump.h
level_3/byte_dump/c/private-byte_dump.c
level_3/byte_dump/c/private-byte_dump.h

index 5bdc72459e9f6b5d70083cff6c2b25d26c0e6103..bcb019b3d7e3765de1553a9290f0973f527ee036 100644 (file)
@@ -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;
           }
index db2ab96fa1dc6deaf86c3f4be446aa01a97ecbe8..227d30d4001582d584cc2aa6fc9139d7fe30b2cc 100644 (file)
@@ -23,6 +23,7 @@
 // fll-0 includes
 #include <level_0/console.h>
 #include <level_0/conversion.h>
+#include <level_0/file.h>
 #include <level_0/pipe.h>
 #include <level_0/print.h>
 #include <level_0/status.h>
index c78b1df34845e5c7a9543ee4849e05549f7dc199..d22834e5b7140e27771486a6845e36618c07db18 100644 (file)
@@ -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, "'.");
index d0aff3ce8433d86aa6dd76ffdb8770a6868ad33f..6b1c98e64ad5c28bd783cd5d5b25f5267b2e5221 100644 (file)
@@ -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