From 6c05c66f50719c9edaa36dea75669e03cd558ee4 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 4 Jan 2023 21:20:16 -0600 Subject: [PATCH] Feature: Support passing a fakefile Section name to the main program. This is intuitive and should have already been supported in the project to better transition from GNU Make into Featureless Make. The unknown parameter error is to no longer be thrown. Instead, when the make process in being followed, check to see if any Sections exist in the fakefile matching the main program Section parameters. Fail when this happens. If the Section exists in the fakefile then that Section is operated on. This, for example, now allows for doing something like "fake install" in the same way "make install" works. The "install" Section must exist in the fakefile for this to work. --- level_3/fake/c/common.h | 4 +- level_3/fake/c/fake.c | 8 --- level_3/fake/c/print.c | 2 + level_3/fake/c/private-make-operate.c | 114 +++++++++++++++++++++++++++++----- 4 files changed, 104 insertions(+), 24 deletions(-) diff --git a/level_3/fake/c/common.h b/level_3/fake/c/common.h index 89f0bc6..9ef8626 100644 --- a/level_3/fake/c/common.h +++ b/level_3/fake/c/common.h @@ -63,9 +63,9 @@ extern "C" { * The program help related data. */ #ifndef _di_fake_program_help_parameter_s_ - #define FAKE_program_help_parameters_s "operation" + #define FAKE_program_help_parameters_s "operation / section" - #define FAKE_program_help_parameters_s_length 9 + #define FAKE_program_help_parameters_s_length 19 extern const f_string_static_t fake_program_help_parameters_s; #endif // _di_fake_program_help_parameter_s_ diff --git a/level_3/fake/c/fake.c b/level_3/fake/c/fake.c index fee309a..d62322d 100644 --- a/level_3/fake/c/fake.c +++ b/level_3/fake/c/fake.c @@ -173,14 +173,6 @@ extern "C" { } else { operations[0] = fake_operation_make_e; - - if (!(main->pipe & fll_program_data_pipe_input_e) && main->parameters.remaining.used) { - status = F_status_set_error(F_parameter); - - if (main->error.verbosity > f_console_verbosity_quiet_e) { - fll_print_format("%r%[%QYou failed to specify a valid operation.%]%r", main->error.to, f_string_eol_s, main->error.context, main->error.prefix, main->error.context, f_string_eol_s); - } - } } if (F_status_is_error_not(status)) { diff --git a/level_3/fake/c/print.c b/level_3/fake/c/print.c index 8518b50..f12521d 100644 --- a/level_3/fake/c/print.c +++ b/level_3/fake/c/print.c @@ -70,6 +70,8 @@ extern "C" { fl_print_format(" When piping data to this program, the piped data is treated as if it were prepended to the %[%r%]", print.to, print.set->notable, fake_make_parameter_variable_fakefile_s, print.set->notable); fl_print_format(" or the %[%r%], depending on the operation.%r", print.to, print.set->notable, fake_make_parameter_variable_settings_s, print.set->notable, f_string_eol_s); + fl_print_format(" A section name from the fakefile that does not conflict with an operation name may be specified when performing the %[%r%] operation.%r%r", file.stream, context.set.notable, fake_other_operation_make_s, context.set.notable, f_string_eol_s, f_string_eol_s); + f_print_dynamic_raw(setting->line_last, print.to); f_file_stream_flush(output); diff --git a/level_3/fake/c/private-make-operate.c b/level_3/fake/c/private-make-operate.c index 63b45d8..8a3c592 100644 --- a/level_3/fake/c/private-make-operate.c +++ b/level_3/fake/c/private-make-operate.c @@ -128,27 +128,113 @@ extern "C" { data_make.error.verbosity = data->main->output.verbosity; - { - const int result = fake_make_operate_section(&data_make, data_make.id_main, §ion_stack, &status); + if (data->main->parameters.remaining.used) { + f_array_length_t i = 0; + f_array_length_t j = 0; + f_string_range_t range = f_string_range_t_initialize; + f_array_length_t index = 0; + + status = F_none; + + // Validate the remaining parameters. + for (i = 0; i < data->main->parameters.remaining.used; ++i) { + + index = data->main->parameters.remaining.array[i]; + + if (!data->main->parameters.arguments.array[index].used) { + status = F_status_set_error(F_parameter); + + break; + } + + range.start = 0; + range.stop = data->main->parameters.arguments.array[index].used - 1; + + for (j = 0; j < data_make.fakefile.used; ++j) { + if (fl_string_dynamic_partial_compare(data->main->parameters.arguments.array[index], data_make.buffer, range, data_make.fakefile.array[j].name) == F_equal_to) break; + } // for + + if (j == data_make.fakefile.used) { + status = F_status_set_error(F_parameter); + + break; + } + } // for + + if (F_status_is_error(status)) { + if (data->main->error.verbosity != f_console_verbosity_quiet_e) { + index = data->main->parameters.remaining.array[i]; + + flockfile(data->main->error.to.stream); + + fl_print_format("%r%[%QThe argument '%]", data->main->error.to.stream, f_string_eol_s, data->main->error.context, data->main->error.prefix, data->main->error.context); + fl_print_format("%[%Q%]", data->main->error.to.stream, data->main->error.notable, data->main->parameters.arguments.array[index], data->main->error.notable); + fl_print_format("%[' is not a valid section name.%]%r", data->main->error.to.stream, data->main->error.context, data->main->error.context, f_string_eol_s); + + funlockfile(data->main->error.to.stream); + } + } + else { + for (i = 0; i < data->main->parameters.remaining.used; ++i) { + + index = data->main->parameters.remaining.array[i]; + range.start = 0; + range.stop = data->main->parameters.arguments.array[index].used - 1; + + for (j = 0; j < data_make.fakefile.used; ++j) { + + if (fl_string_dynamic_partial_compare(data->main->parameters.arguments.array[index], data_make.buffer, range, data_make.fakefile.array[j].name) == F_equal_to) { + { + const int result = fake_make_operate_section(&data_make, j, §ion_stack, &status); + + if (status == F_child) { + data->main->child = result; + } + } + + if (status != F_child) { + const f_status_t status_path = f_path_change_at(data_make.path.top.id); + + if (F_status_is_error(status_path) && data->main->warning.verbosity >= f_console_verbosity_verbose_e) { + flockfile(data->main->warning.to.stream); + + fl_print_format("%r%[%QFailed change back to orignal path '%]", data->main->warning.to.stream, f_string_eol_s, data->main->warning.context, data->main->warning.prefix, data->main->warning.context); + fl_print_format("%[%Q%]", data->main->warning.to.stream, data->main->warning.notable, data_make.path.stack.array[0], data->main->warning.notable); + fl_print_format("%[', status code =%] ", data->main->warning.to.stream, data->main->warning.context, data->main->warning.context); + fl_print_format("%[%ui%]", data->main->warning.to.stream, data->main->warning.notable, F_status_set_fine(status_path), data->main->warning.notable); + fl_print_format("%['.%]%r", data->main->warning.to.stream, data->main->warning.context, data->main->warning.context, f_string_eol_s); - if (status == F_child) { - data->main->child = result; + funlockfile(data->main->warning.to.stream); + } + } + } + } // for + } // for } } + else { + { + const int result = fake_make_operate_section(&data_make, data_make.id_main, §ion_stack, &status); - if (status != F_child) { - const f_status_t status_path = f_path_change_at(data_make.path.top.id); + if (status == F_child) { + data->main->child = result; + } + } - if (F_status_is_error(status_path) && data->main->warning.verbosity >= f_console_verbosity_verbose_e) { - f_file_stream_lock(data->main->warning); + if (status != F_child) { + const f_status_t status_path = f_path_change_at(data_make.path.top.id); - fl_print_format("%r%[%QFailed change back to orignal path '%]", data->main->warning.to, f_string_eol_s, data->main->warning.context, data->main->warning.prefix, data->main->warning.context); - fl_print_format("%[%Q%]", data->main->warning.to, data->main->warning.notable, data_make.path.stack.array[0], data->main->warning.notable); - fl_print_format("%[', status code =%] ", data->main->warning.to, data->main->warning.context, data->main->warning.context); - fl_print_format("%[%ui%]", data->main->warning.to, data->main->warning.notable, F_status_set_fine(status_path), data->main->warning.notable); - fl_print_format("%['.%]%r", data->main->warning.to, data->main->warning.context, data->main->warning.context, f_string_eol_s); + if (F_status_is_error(status_path) && data->main->warning.verbosity >= f_console_verbosity_verbose_e) { + f_file_stream_lock(data->main->warning); - f_file_stream_unlock(data->main->warning); + fl_print_format("%r%[%QFailed change back to orignal path '%]", data->main->warning.to, f_string_eol_s, data->main->warning.context, data->main->warning.prefix, data->main->warning.context); + fl_print_format("%[%Q%]", data->main->warning.to, data->main->warning.notable, data_make.path.stack.array[0], data->main->warning.notable); + fl_print_format("%[', status code =%] ", data->main->warning.to, data->main->warning.context, data->main->warning.context); + fl_print_format("%[%ui%]", data->main->warning.to, data->main->warning.notable, F_status_set_fine(status_path), data->main->warning.notable); + fl_print_format("%['.%]%r", data->main->warning.to, data->main->warning.context, data->main->warning.context, f_string_eol_s); + + f_file_stream_unlock(data->main->warning); + } } } -- 1.8.3.1