From c7a96b14e8c66ffcd364f50a2e77254a18a34d9e Mon Sep 17 00:00:00 2001 From: 0x221E Date: Sun, 18 Jan 2026 22:39:32 +0100 Subject: [PATCH] Refactor: command_create_f_to_o() and command_get_profile() --- src/command.c | 44 +++++++++++++++++++++++--------------------- src/command.h | 8 ++++++++ 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/command.c b/src/command.c index f5e78eb..d70bbfc 100644 --- a/src/command.c +++ b/src/command.c @@ -18,25 +18,8 @@ Command command_create_f_to_o(CommandOptions* co) size_t len_args = 6; - size_t flag_count = 0; - - StringView* dep_flags_buf = NULL; - - switch(co->bp) - { - case B_DEBUG: - len_args += co->c->debug_compiler_flags_c; - flag_count = co->c->debug_compiler_flags_c; - dep_flags_buf = co->c->debug_compiler_flags; - break; - case B_PROD: - len_args += co->c->prod_compiler_flags_c; - flag_count = co->c->prod_compiler_flags_c; - dep_flags_buf = co->c->prod_compiler_flags; - break; - default: - DIE("No configuration was selected!"); - } + ProfileResult pr = command_get_profile(co); + len_args += pr.compiler_flags_count; const char** args_buf = (const char**)arena_alloc(co->a, sizeof(const char*) * len_args); args_buf[0] = co->app.buf; @@ -49,9 +32,9 @@ Command command_create_f_to_o(CommandOptions* co) args_buf[4] = f_o.buf; args_buf[5] = "-MMD"; - for (size_t i = 0; i < flag_count; i++) + for (size_t i = 0; i < pr.compiler_flags_count; i++) { - args_buf[i + 5] = dep_flags_buf[i].buf; + args_buf[i + 5] = pr.compiler_flags_buf[i].buf; } args_buf[len_args] = NULL; @@ -61,6 +44,25 @@ Command command_create_f_to_o(CommandOptions* co) return (Command){.a = co->a, .app = co->app, .args = args_buf}; } +ProfileResult command_get_profile(CommandOptions* co) +{ + ProfileResult pr; + switch(co->bp) + { + case B_DEBUG: + pr.compiler_flags_count = co->c->debug_compiler_flags_c; + pr.compiler_flags_buf = co->c->debug_compiler_flags; + break; + case B_PROD: + pr.compiler_flags_count = co->c->prod_compiler_flags_c; + pr.compiler_flags_buf = co->c->prod_compiler_flags; + break; + default: + DIE("No configuration was selected!"); + } + return pr; +} + // TODO: Add input sanitization to cmd->app and cmd->args int command_run(Command* cmd) { diff --git a/src/command.h b/src/command.h index 73afd35..5e43d05 100644 --- a/src/command.h +++ b/src/command.h @@ -18,6 +18,12 @@ struct CommandOptions StringView* files; }; +struct ProfileResult +{ + size_t compiler_flags_count; + StringView* compiler_flags_buf; +}; + struct Command { Arena* a; @@ -28,8 +34,10 @@ struct Command typedef struct Argument Argument; typedef struct Command Command; typedef struct CommandOptions CommandOptions; +typedef struct ProfileResult ProfileResult; Command command_create_f_to_o(CommandOptions* co); +ProfileResult command_get_profile(CommandOptions* co); int command_run(Command* cmd);