From: Kevin Day Date: Mon, 3 May 2021 02:07:21 +0000 (-0500) Subject: Cleanup: Sloppy use of "main" inside of "main()", oops. X-Git-Tag: 0.5.4~64 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=b7fc039259adee5cf250e05bb6cf6d14ea98f9ae;p=fll Cleanup: Sloppy use of "main" inside of "main()", oops. I cannot believe I let this one slip through (and so did the compilers). When I refactored "data" to be "main" this included the refactor in the function called "main". This is dangerous at worst and at best bad practice. Given that "data" is no longer to be used in the main(), just rename the uses of "main" back to "data" for the variable name only (not the typedef structure name). --- diff --git a/level_3/byte_dump/c/main.c b/level_3/byte_dump/c/main.c index b6dc21c..d399fda 100644 --- a/level_3/byte_dump/c/main.c +++ b/level_3/byte_dump/c/main.c @@ -1,14 +1,15 @@ #include "byte_dump.h" int main(const int argc, const f_string_t *argv) { + const f_console_arguments_t arguments = { argc, argv }; - byte_dump_main_t main = byte_dump_main_t_initialize; + byte_dump_main_t data = byte_dump_main_t_initialize; if (f_pipe_input_exists()) { - main.process_pipe = F_true; + data.process_pipe = F_true; } - const f_status_t status = byte_dump_main(arguments, &main); + const f_status_t status = byte_dump_main(arguments, &data); // flush output pipes before closing. fflush(f_type_output); diff --git a/level_3/control/c/main.c b/level_3/control/c/main.c index 9095f46..63db5c8 100644 --- a/level_3/control/c/main.c +++ b/level_3/control/c/main.c @@ -1,14 +1,15 @@ #include "control.h" int main(const int argc, const f_string_t *argv) { + const f_console_arguments_t arguments = { argc, argv }; - control_main_t main = control_data_initialize; + control_main_t data = control_data_initialize; if (f_pipe_input_exists()) { - main.process_pipe = F_true; + data.process_pipe = F_true; } - const f_status_t status = control_main(arguments, &main); + const f_status_t status = control_main(arguments, &data); // flush output pipes before closing. fflush(f_type_output); diff --git a/level_3/controller/c/main.c b/level_3/controller/c/main.c index a9cb379..1f00632 100644 --- a/level_3/controller/c/main.c +++ b/level_3/controller/c/main.c @@ -1,39 +1,40 @@ #include "controller.h" int main(const int argc, const f_string_t *argv) { + const f_console_arguments_t arguments = { argc, argv }; - controller_main_t main = controller_main_t_initialize; + controller_main_t data = controller_main_t_initialize; f_status_t status = F_none; if (f_pipe_input_exists()) { - main.process_pipe = F_true; + data.process_pipe = F_true; } - main.pid = getpid(); + data.pid = getpid(); - f_signal_set_empty(&main.signal.set); - f_signal_set_add(F_signal_abort, &main.signal.set); - f_signal_set_add(F_signal_hangup, &main.signal.set); - f_signal_set_add(F_signal_interrupt, &main.signal.set); - f_signal_set_add(F_signal_quit, &main.signal.set); - f_signal_set_add(F_signal_termination, &main.signal.set); - f_signal_mask(SIG_BLOCK, &main.signal.set, 0); + f_signal_set_empty(&data.signal.set); + f_signal_set_add(F_signal_abort, &data.signal.set); + f_signal_set_add(F_signal_hangup, &data.signal.set); + f_signal_set_add(F_signal_interrupt, &data.signal.set); + f_signal_set_add(F_signal_quit, &data.signal.set); + f_signal_set_add(F_signal_termination, &data.signal.set); + f_signal_mask(SIG_BLOCK, &data.signal.set, 0); - status = f_signal_open(&main.signal); + status = f_signal_open(&data.signal); // if there is an error opening a signal descriptor, then do not handle signals. if (F_status_is_error(status)) { - f_signal_mask(SIG_UNBLOCK, &main.signal.set, 0); - f_signal_close(&main.signal); + f_signal_mask(SIG_UNBLOCK, &data.signal.set, 0); + f_signal_close(&data.signal); } // @fixme: bad design in POSIX where there is no get umask without setting it. - main.umask = umask(0); + data.umask = umask(0); // restore umask. - umask(main.umask); + umask(data.umask); - status = controller_main(arguments, &main); + status = controller_main(arguments, &data); // flush output pipes before closing. fflush(f_type_output); @@ -44,10 +45,10 @@ int main(const int argc, const f_string_t *argv) { close(f_type_descriptor_input); close(f_type_descriptor_error); - f_signal_close(&main.signal); + f_signal_close(&data.signal); if (status == F_child) { - exit(main.child); + exit(data.child); } if (F_status_is_error(status)) { diff --git a/level_3/fake/c/main.c b/level_3/fake/c/main.c index b11290c..098bf6a 100644 --- a/level_3/fake/c/main.c +++ b/level_3/fake/c/main.c @@ -15,36 +15,37 @@ * @see exit() */ int main(const int argc, const f_string_t *argv) { + const f_console_arguments_t arguments = { argc, argv }; - fake_main_t main = fake_main_t_initialize; + fake_main_t data = fake_main_t_initialize; f_status_t status = F_none; - f_signal_set_empty(&main.signal.set); - f_signal_set_add(F_signal_abort, &main.signal.set); - f_signal_set_add(F_signal_hangup, &main.signal.set); - f_signal_set_add(F_signal_interrupt, &main.signal.set); - f_signal_set_add(F_signal_quit, &main.signal.set); - f_signal_set_add(F_signal_termination, &main.signal.set); + f_signal_set_empty(&data.signal.set); + f_signal_set_add(F_signal_abort, &data.signal.set); + f_signal_set_add(F_signal_hangup, &data.signal.set); + f_signal_set_add(F_signal_interrupt, &data.signal.set); + f_signal_set_add(F_signal_quit, &data.signal.set); + f_signal_set_add(F_signal_termination, &data.signal.set); - status = f_signal_mask(SIG_BLOCK, &main.signal.set, 0); + status = f_signal_mask(SIG_BLOCK, &data.signal.set, 0); if (F_status_is_error_not(status)) { - status = f_signal_open(&main.signal); + status = f_signal_open(&data.signal); // if there is an error opening a signal descriptor, then do not handle signals. if (F_status_is_error(status)) { - f_signal_mask(SIG_UNBLOCK, &main.signal.set, 0); - f_signal_close(&main.signal); + f_signal_mask(SIG_UNBLOCK, &data.signal.set, 0); + f_signal_close(&data.signal); } } // @fixme: bad design in POSIX where there is no get umask without setting it. - main.umask = umask(0); + data.umask = umask(0); // restore umask. - umask(main.umask); + umask(data.umask); - status = fake_main(arguments, &main); + status = fake_main(arguments, &data); // flush output pipes before closing. fflush(f_type_output); @@ -55,10 +56,10 @@ int main(const int argc, const f_string_t *argv) { close(f_type_descriptor_input); close(f_type_descriptor_error); - f_signal_close(&main.signal); + f_signal_close(&data.signal); if (status == F_child) { - exit(main.child); + exit(data.child); } if (F_status_is_error(status)) { diff --git a/level_3/firewall/c/main.c b/level_3/firewall/c/main.c index b0bd369..6b3f60b 100644 --- a/level_3/firewall/c/main.c +++ b/level_3/firewall/c/main.c @@ -1,14 +1,15 @@ #include "firewall.h" int main(const int argc, const f_string_t *argv) { + const f_console_arguments_t arguments = { argc, argv }; - firewall_main_t main = firewall_main_t_initialize; + firewall_main_t data = firewall_main_t_initialize; if (f_pipe_input_exists()) { - main.process_pipe = F_true; + data.process_pipe = F_true; } - if (F_status_is_error(firewall_main(arguments, &main))) { + if (F_status_is_error(firewall_main(arguments, &data))) { 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 9881dcf..c519638 100644 --- a/level_3/fss_basic_list_read/c/main.c +++ b/level_3/fss_basic_list_read/c/main.c @@ -1,14 +1,15 @@ #include "fss_basic_list_read.h" int main(const int argc, const f_string_t *argv) { + const f_console_arguments_t arguments = { argc, argv }; - fss_basic_list_read_main_t main = fss_basic_list_read_main_t_initialize; + fss_basic_list_read_main_t data = fss_basic_list_read_main_t_initialize; if (f_pipe_input_exists()) { - main.process_pipe = F_true; + data.process_pipe = F_true; } - const f_status_t status = fss_basic_list_read_main(arguments, &main); + const f_status_t status = fss_basic_list_read_main(arguments, &data); // flush output pipes before closing. fflush(f_type_output); diff --git a/level_3/fss_basic_list_write/c/main.c b/level_3/fss_basic_list_write/c/main.c index b4e82b4..48f6234 100644 --- a/level_3/fss_basic_list_write/c/main.c +++ b/level_3/fss_basic_list_write/c/main.c @@ -1,14 +1,15 @@ #include "fss_basic_list_write.h" int main(const int argc, const f_string_t *argv) { + const f_console_arguments_t arguments = { argc, argv }; - fss_basic_list_write_main_t main = fss_basic_list_write_main_t_initialize; + fss_basic_list_write_main_t data = fss_basic_list_write_main_t_initialize; if (f_pipe_input_exists()) { - main.process_pipe = F_true; + data.process_pipe = F_true; } - const f_status_t status = fss_basic_list_write_main(arguments, &main); + const f_status_t status = fss_basic_list_write_main(arguments, &data); // flush output pipes before closing. fflush(f_type_output); diff --git a/level_3/fss_basic_read/c/main.c b/level_3/fss_basic_read/c/main.c index efe4f0c..844654a 100644 --- a/level_3/fss_basic_read/c/main.c +++ b/level_3/fss_basic_read/c/main.c @@ -3,13 +3,13 @@ int main(const int argc, const f_string_t *argv) { f_console_arguments_t arguments = { argc, argv }; - fss_basic_read_main_t main = fss_basic_read_main_t_initialize; + fss_basic_read_main_t data = fss_basic_read_main_t_initialize; if (f_pipe_input_exists()) { - main.process_pipe = F_true; + data.process_pipe = F_true; } - const f_status_t status = fss_basic_read_main(&arguments, &main); + const f_status_t status = fss_basic_read_main(&arguments, &data); // flush output pipes before closing. fflush(f_type_output); diff --git a/level_3/fss_basic_write/c/main.c b/level_3/fss_basic_write/c/main.c index ef09cb4..32526c1 100644 --- a/level_3/fss_basic_write/c/main.c +++ b/level_3/fss_basic_write/c/main.c @@ -1,14 +1,15 @@ #include "fss_basic_write.h" int main(const int argc, const f_string_t *argv) { + const f_console_arguments_t arguments = { argc, argv }; - fss_basic_write_main_t main = fss_basic_write_main_t_initialize; + fss_basic_write_main_t data = fss_basic_write_main_t_initialize; if (f_pipe_input_exists()) { - main.process_pipe = F_true; + data.process_pipe = F_true; } - const f_status_t status = fss_basic_write_main(arguments, &main); + const f_status_t status = fss_basic_write_main(arguments, &data); // flush output pipes before closing. fflush(f_type_output); diff --git a/level_3/fss_embedded_list_read/c/main.c b/level_3/fss_embedded_list_read/c/main.c index 850895b..0497df5 100644 --- a/level_3/fss_embedded_list_read/c/main.c +++ b/level_3/fss_embedded_list_read/c/main.c @@ -1,14 +1,15 @@ #include "fss_embedded_list_read.h" int main(const int argc, const f_string_t *argv) { + const f_console_arguments_t arguments = { argc, argv }; - fss_embedded_list_read_main_t main = fss_embedded_list_read_main_t_initialize; + fss_embedded_list_read_main_t data = fss_embedded_list_read_main_t_initialize; if (f_pipe_input_exists()) { - main.process_pipe = F_true; + data.process_pipe = F_true; } - const f_status_t status = fss_embedded_list_read_main(arguments, &main); + const f_status_t status = fss_embedded_list_read_main(arguments, &data); // flush output pipes before closing. fflush(f_type_output); diff --git a/level_3/fss_embedded_list_write/c/main.c b/level_3/fss_embedded_list_write/c/main.c index c236863..d7f0a30 100644 --- a/level_3/fss_embedded_list_write/c/main.c +++ b/level_3/fss_embedded_list_write/c/main.c @@ -1,14 +1,15 @@ #include "fss_embedded_list_write.h" int main(const int argc, const f_string_t *argv) { + const f_console_arguments_t arguments = { argc, argv }; - fss_embedded_list_write_main_t main = fss_embedded_list_write_main_t_initialize; + fss_embedded_list_write_main_t data = fss_embedded_list_write_main_t_initialize; if (f_pipe_input_exists()) { - main.process_pipe = F_true; + data.process_pipe = F_true; } - const f_status_t status = fss_embedded_list_write_main(arguments, &main); + const f_status_t status = fss_embedded_list_write_main(arguments, &data); // flush output pipes before closing. fflush(f_type_output); diff --git a/level_3/fss_extended_list_read/c/main.c b/level_3/fss_extended_list_read/c/main.c index e9f1b60..18e726a 100644 --- a/level_3/fss_extended_list_read/c/main.c +++ b/level_3/fss_extended_list_read/c/main.c @@ -1,14 +1,15 @@ #include "fss_extended_list_read.h" int main(const int argc, const f_string_t *argv) { + const f_console_arguments_t arguments = { argc, argv }; - fss_extended_list_read_main_t main = fss_extended_list_read_main_t_initialize; + fss_extended_list_read_main_t data = fss_extended_list_read_main_t_initialize; if (f_pipe_input_exists()) { - main.process_pipe = F_true; + data.process_pipe = F_true; } - const f_status_t status = fss_extended_list_read_main(arguments, &main); + const f_status_t status = fss_extended_list_read_main(arguments, &data); // flush output pipes before closing. fflush(f_type_output); diff --git a/level_3/fss_extended_list_write/c/main.c b/level_3/fss_extended_list_write/c/main.c index 435f88a..de2a36e 100644 --- a/level_3/fss_extended_list_write/c/main.c +++ b/level_3/fss_extended_list_write/c/main.c @@ -1,14 +1,15 @@ #include "fss_extended_list_write.h" int main(const int argc, const f_string_t *argv) { + const f_console_arguments_t arguments = { argc, argv }; - fss_extended_list_write_main_t main = fss_extended_list_write_main_t_initialize; + fss_extended_list_write_main_t data = fss_extended_list_write_main_t_initialize; if (f_pipe_input_exists()) { - main.process_pipe = F_true; + data.process_pipe = F_true; } - const f_status_t status = fss_extended_list_write_main(arguments, &main); + const f_status_t status = fss_extended_list_write_main(arguments, &data); // flush output pipes before closing. fflush(f_type_output); diff --git a/level_3/fss_extended_read/c/main.c b/level_3/fss_extended_read/c/main.c index dbef786..aae3a3a 100644 --- a/level_3/fss_extended_read/c/main.c +++ b/level_3/fss_extended_read/c/main.c @@ -1,14 +1,15 @@ #include "fss_extended_read.h" int main(const int argc, const f_string_t *argv) { + const f_console_arguments_t arguments = { argc, argv }; - fss_extended_read_main_t main = fss_extended_read_main_t_initialize; + fss_extended_read_main_t data = fss_extended_read_main_t_initialize; if (f_pipe_input_exists()) { - main.process_pipe = F_true; + data.process_pipe = F_true; } - const f_status_t status = fss_extended_read_main(arguments, &main); + const f_status_t status = fss_extended_read_main(arguments, &data); // flush output pipes before closing. fflush(f_type_output); diff --git a/level_3/fss_extended_write/c/main.c b/level_3/fss_extended_write/c/main.c index bfbeb9a..1756734 100644 --- a/level_3/fss_extended_write/c/main.c +++ b/level_3/fss_extended_write/c/main.c @@ -1,14 +1,15 @@ #include "fss_extended_write.h" int main(const int argc, const f_string_t *argv) { + const f_console_arguments_t arguments = { argc, argv }; - fss_extended_write_main_t main = fss_extended_write_main_t_initialize; + fss_extended_write_main_t data = fss_extended_write_main_t_initialize; if (f_pipe_input_exists()) { - main.process_pipe = F_true; + data.process_pipe = F_true; } - const f_status_t status = fss_extended_write_main(arguments, &main); + const f_status_t status = fss_extended_write_main(arguments, &data); // flush output pipes before closing. fflush(f_type_output); diff --git a/level_3/fss_status_code/c/main.c b/level_3/fss_status_code/c/main.c index 760d7e6..5dfa153 100644 --- a/level_3/fss_status_code/c/main.c +++ b/level_3/fss_status_code/c/main.c @@ -1,14 +1,15 @@ #include "fss_status_code.h" int main(const int argc, const f_string_t *argv) { + const f_console_arguments_t arguments = { argc, argv }; - fss_status_code_main_t main = fss_status_code_main_t_initialize; + fss_status_code_main_t data = fss_status_code_main_t_initialize; if (f_pipe_input_exists()) { - main.process_pipe = F_true; + data.process_pipe = F_true; } - const f_status_t status = fss_status_code_main(arguments, &main); + const f_status_t status = fss_status_code_main(arguments, &data); // flush output pipes before closing. fflush(f_type_output); diff --git a/level_3/iki_read/c/main.c b/level_3/iki_read/c/main.c index bd2fa82..72105f4 100644 --- a/level_3/iki_read/c/main.c +++ b/level_3/iki_read/c/main.c @@ -1,14 +1,15 @@ #include "iki_read.h" int main(const int argc, const f_string_t *argv) { + const f_console_arguments_t arguments = { argc, argv }; - iki_read_main_t main = iki_read_main_t_initialize; + iki_read_main_t data = iki_read_main_t_initialize; if (f_pipe_input_exists()) { - main.process_pipe = F_true; + data.process_pipe = F_true; } - const f_status_t status = iki_read_main(arguments, &main); + const f_status_t status = iki_read_main(arguments, &data); // flush output pipes before closing. fflush(f_type_output); diff --git a/level_3/iki_write/c/main.c b/level_3/iki_write/c/main.c index 7fa07c5..f2de7d4 100644 --- a/level_3/iki_write/c/main.c +++ b/level_3/iki_write/c/main.c @@ -1,14 +1,15 @@ #include "iki_write.h" int main(const int argc, const f_string_t *argv) { + const f_console_arguments_t arguments = { argc, argv }; - iki_write_main_t main = iki_write_main_t_initialize; + iki_write_main_t data = iki_write_main_t_initialize; if (f_pipe_input_exists()) { - main.process_pipe = F_true; + data.process_pipe = F_true; } - const f_status_t status = iki_write_main(arguments, &main); + const f_status_t status = iki_write_main(arguments, &data); // flush output pipes before closing. fflush(f_type_output); diff --git a/level_3/status_code/c/main.c b/level_3/status_code/c/main.c index 7ece9e0..7727663 100644 --- a/level_3/status_code/c/main.c +++ b/level_3/status_code/c/main.c @@ -1,14 +1,15 @@ #include "status_code.h" int main(const int argc, const f_string_t *argv) { + const f_console_arguments_t arguments = { argc, argv }; - status_code_main_t main = status_code_main_t_initialize; + status_code_main_t data = status_code_main_t_initialize; if (f_pipe_input_exists()) { - main.process_pipe = F_true; + data.process_pipe = F_true; } - const f_status_t status = status_code_main(arguments, &main); + const f_status_t status = status_code_main(arguments, &data); // flush output pipes before closing. fflush(f_type_output);