From fb6f69707616cd702d3af66792a411c5f8018636 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 8 Sep 2019 16:58:44 -0500 Subject: [PATCH] Cleanup: make main() programs design more consistent across level 3 projects --- level_3/firewall/c/firewall.h | 3 +++ level_3/firewall/c/main.c | 8 +++++++- level_3/fss_basic_list_read/c/main.c | 4 +++- level_3/fss_basic_list_write/c/main.c | 4 +++- level_3/fss_basic_read/c/main.c | 4 +++- level_3/fss_basic_write/c/main.c | 6 ++---- level_3/fss_extended_read/c/main.c | 4 +++- level_3/fss_extended_write/c/main.c | 4 +++- level_3/init/c/main.c | 12 +++++++++++- 9 files changed, 38 insertions(+), 11 deletions(-) diff --git a/level_3/firewall/c/firewall.h b/level_3/firewall/c/firewall.h index c3c0525..b7436ad 100644 --- a/level_3/firewall/c/firewall.h +++ b/level_3/firewall/c/firewall.h @@ -19,6 +19,7 @@ // fll-0 includes #include #include +#include #include #include #include @@ -278,6 +279,7 @@ extern "C" { f_string_dynamics chains; f_string_lengths remaining; + f_bool process_pipe; f_string_dynamics devices; fl_color_context context; @@ -288,6 +290,7 @@ extern "C" { f_console_parameter_initialize_firewall, \ f_string_dynamics_initialize, \ f_string_lengths_initialize, \ + f_false, \ f_string_dynamics_initialize, \ fl_color_context_initialize, \ } diff --git a/level_3/firewall/c/main.c b/level_3/firewall/c/main.c index 14a81a6..7eac475 100644 --- a/level_3/firewall/c/main.c +++ b/level_3/firewall/c/main.c @@ -5,7 +5,13 @@ int main(const int argc, const f_string *argv) { const f_console_arguments arguments = { argc, argv }; firewall_data data = firewall_data_initialize; - if (f_status_is_error(firewall_main(arguments, &data))) { + if (f_pipe_exists()) { + data.process_pipe = f_true; + } + + f_status status = firewall_main(arguments, &data); + + if (f_status_is_error(status)) { return 1; } diff --git a/level_3/fss_basic_list_read/c/main.c b/level_3/fss_basic_list_read/c/main.c index 9d493f5..5edc171 100644 --- a/level_3/fss_basic_list_read/c/main.c +++ b/level_3/fss_basic_list_read/c/main.c @@ -8,7 +8,9 @@ int main(const int argc, const f_string *argv) { data.process_pipe = f_true; } - if (f_status_is_error(fss_basic_list_read_main(arguments, &data))) { + f_status status = fss_basic_list_read_main(arguments, &data); + + if (f_status_is_error(status)) { return 1; } diff --git a/level_3/fss_basic_list_write/c/main.c b/level_3/fss_basic_list_write/c/main.c index e631ff8..2b06cb4 100644 --- a/level_3/fss_basic_list_write/c/main.c +++ b/level_3/fss_basic_list_write/c/main.c @@ -8,7 +8,9 @@ int main(const int argc, const f_string *argv) { data.process_pipe = f_true; } - if (f_status_is_error(fss_basic_list_write_main(arguments, &data))) { + f_status status = fss_basic_list_write_main(arguments, &data); + + if (f_status_is_error(status)) { return 1; } diff --git a/level_3/fss_basic_read/c/main.c b/level_3/fss_basic_read/c/main.c index 5815373..21a1b6f 100644 --- a/level_3/fss_basic_read/c/main.c +++ b/level_3/fss_basic_read/c/main.c @@ -8,7 +8,9 @@ int main(const int argc, const f_string *argv) { data.process_pipe = f_true; } - if (f_status_is_error(fss_basic_read_main(arguments, &data))) { + f_status status = fss_basic_read_main(arguments, &data); + + if (f_status_is_error(status)) { return 1; } diff --git a/level_3/fss_basic_write/c/main.c b/level_3/fss_basic_write/c/main.c index ed207cb..d2cc816 100644 --- a/level_3/fss_basic_write/c/main.c +++ b/level_3/fss_basic_write/c/main.c @@ -4,11 +4,9 @@ int main(const int argc, const f_string *argv) { const f_console_arguments arguments = { argc, argv }; fss_basic_write_data data = fss_basic_write_data_initialize; - if (f_pipe_exists()) { - data.process_pipe = f_true; - } + f_status status = fss_basic_write_main(arguments, &data); - if (f_status_is_error(fss_basic_write_main(arguments, &data))) { + if (f_status_is_error(status)) { return 1; } diff --git a/level_3/fss_extended_read/c/main.c b/level_3/fss_extended_read/c/main.c index 9afa9c8..bb92005 100644 --- a/level_3/fss_extended_read/c/main.c +++ b/level_3/fss_extended_read/c/main.c @@ -8,7 +8,9 @@ int main(const int argc, const f_string *argv) { data.process_pipe = f_true; } - if (f_status_is_error(fss_extended_read_main(arguments, &data))) { + f_status status = fss_extended_read_main(arguments, &data); + + if (f_status_is_error(status)) { return 1; } diff --git a/level_3/fss_extended_write/c/main.c b/level_3/fss_extended_write/c/main.c index d9cab58..5098d16 100644 --- a/level_3/fss_extended_write/c/main.c +++ b/level_3/fss_extended_write/c/main.c @@ -8,7 +8,9 @@ int main(const int argc, const f_string *argv) { data.process_pipe = f_true; } - if (f_status_is_error(fss_extended_write_main(arguments, &data))) { + f_status status = fss_extended_write_main(arguments, &data); + + if (f_status_is_error(status)) { return 1; } diff --git a/level_3/init/c/main.c b/level_3/init/c/main.c index 709b424..5b4257b 100644 --- a/level_3/init/c/main.c +++ b/level_3/init/c/main.c @@ -4,5 +4,15 @@ int main(const int argc, const f_string *argv) { const f_console_arguments arguments = { argc, argv }; init_argument data = init_argument_initialize; - return init_main(arguments, &data); + if (f_pipe_exists()) { + data.process_pipe = f_true; + } + + f_status status = init_main(arguments, &data); + + if (f_status_is_error(status)) { + return 1; + } + + return 0; } -- 1.8.3.1