From 6c319efd6faf2df5a429359a7de05c1ab97c3061 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Thu, 16 Jul 2020 23:05:43 -0500 Subject: [PATCH] Progress: featureless make. Begin adding the path stack functionality. --- level_3/fake/c/private-make.c | 40 ++++++++++++++++++++++++++++++++++++++++ level_3/fake/c/private-make.h | 22 ++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/level_3/fake/c/private-make.c b/level_3/fake/c/private-make.c index 1dc47cc..92b04c0 100644 --- a/level_3/fake/c/private-make.c +++ b/level_3/fake/c/private-make.c @@ -314,6 +314,28 @@ extern "C" { f_string_lengths list_stack = f_string_lengths_initialize; fake_make_data data_make = fake_make_data_initialize; + f_macro_string_dynamics_new(status, data_make.path.stack, f_memory_default_allocation_step); + if (F_status_is_error(status)) { + fake_print_error(data.context, data.verbosity, F_status_set_fine(status), "f_macro_string_dynamics_new", F_true); + return status; + } + + status = f_path_current(F_true, &data_make.path.stack.array[0]); + if (F_status_is_error(status)) { + fake_print_error(data.context, data.verbosity, F_status_set_fine(status), "f_path_current", F_true); + + fake_macro_make_data_delete_simple(data_make); + return status; + } + + status = f_directory_open(data_make.path.stack.array[0].string, F_false, &data_make.path.top); + if (F_status_is_error(status)) { + fake_print_error(data.context, data.verbosity, F_status_set_fine(status), "f_directory_open", F_true); + + fake_macro_make_data_delete_simple(data_make); + return status; + } + f_macro_mode_set_default_umask(mode, data.umask); data_make.fail = fake_make_operation_fail_type_exit; @@ -322,6 +344,24 @@ extern "C" { fake_make_operate_section(data, data_make.main, &data_make, &list_stack, &status); + if (data_make.path.current > 0) { + f_file_close(&data_make.path.current); + } + + { + f_status status_path = f_path_change_at(data_make.path.top); + if (F_status_is_error(status_path) && data.verbosity == fake_verbosity_verbose) { + fprintf(f_type_warning, "%c", f_string_eol[0]); + fl_color_print(f_type_warning, data.context.warning, data.context.reset, "WARNING: Failed change back to orignal path '"); + fl_color_print(f_type_warning, data.context.notable, data.context.reset, "%s", data_make.path.stack.array[0].string); + fl_color_print(f_type_warning, data.context.warning, data.context.reset, "', status code = "); + fl_color_print(f_type_warning, data.context.notable, data.context.reset, "%llu", F_status_set_fine(status_path)); + fl_color_print_line(f_type_warning, data.context.warning, data.context.reset, "."); + } + } + + f_file_close(&data_make.path.top); + f_macro_string_lengths_delete_simple(list_stack); fake_macro_make_data_delete_simple(data_make); diff --git a/level_3/fake/c/private-make.h b/level_3/fake/c/private-make.h index 6c0575c..b0a3330 100644 --- a/level_3/fake/c/private-make.h +++ b/level_3/fake/c/private-make.h @@ -242,13 +242,33 @@ extern "C" { f_macro_string_dynamics_delete_simple(parameter.work) #endif // _di_fake_make_parameter_ +#ifndef _di_fake_make_path_ + typedef struct { + int top; + int current; + + f_string_dynamics stack; + } fake_make_path; + + #define fake_make_path_initialize { \ + 0, \ + 0, \ + f_string_dynamics_initialize, \ + } + + #define fake_macro_make_path_delete_simple(path) \ + f_macro_string_dynamics_delete_simple(path.stack) +#endif // _di_fake_make_path_ + #ifndef _di_fake_make_data_ typedef struct { fake_build_setting setting_build; fake_make_setting setting_make; fake_environment environment; + fake_make_parameter parameter; + fake_make_path path; f_fss_nameds fakefile; f_string_dynamic buffer; @@ -263,6 +283,7 @@ extern "C" { fake_make_setting_initialize, \ fake_environment_initialize, \ fake_make_parameter_initialize, \ + fake_make_path_initialize, \ f_fss_nameds_initialize, \ f_string_dynamic_initialize, \ 0, \ @@ -274,6 +295,7 @@ extern "C" { fake_macro_make_setting_delete_simple(data.setting_make) \ fake_macro_environment_delete_simple(data.environment) \ fake_macro_make_parameter_delete_simple(data.parameter) \ + fake_macro_make_path_delete_simple(data.path) \ f_macro_fss_nameds_delete_simple(data.fakefile) \ f_macro_string_dynamic_delete_simple(data.buffer) #endif // _di_fake_make_data_ -- 1.8.3.1