runtime: command: add an arg to begin_processing() to indicate pipeline position

This commit is contained in:
2026-06-13 13:40:20 +01:00
parent de5058e045
commit 4c04ca6de8
6 changed files with 65 additions and 20 deletions
+19 -3
View File
@@ -57,6 +57,11 @@ static const fx_value *command_get_arg(
return &cmd->cmd_args[index];
}
static size_t command_get_arg_count(struct bshell_command_p *cmd)
{
return cmd->cmd_nr_args;
}
static fx_status get_command_type(
const fx_value *cmd_v,
const fx_property *prop,
@@ -236,14 +241,25 @@ const fx_value *bshell_command_get_arg(bshell_command *cmd, size_t index)
index);
}
enum bshell_status bshell_command_begin_processing(bshell_command *command)
size_t bshell_command_get_arg_count(const bshell_command *cmd)
{
FX_CLASS_DISPATCH_VIRTUAL_0(
FX_CLASS_DISPATCH_STATIC_0(
BSHELL_TYPE_COMMAND,
command_get_arg_count,
cmd);
}
enum bshell_status bshell_command_begin_processing(
bshell_command *command,
enum bshell_command_position position)
{
FX_CLASS_DISPATCH_VIRTUAL(
bshell_command,
BSHELL_TYPE_COMMAND,
BSHELL_ERR_NOT_SUPPORTED,
c_begin_processing,
command);
command,
position);
}
enum bshell_status bshell_command_process_record(
+3 -1
View File
@@ -43,7 +43,9 @@ static enum bshell_status get_callable_name(
return BSHELL_SUCCESS;
}
static enum bshell_status begin_processing(bshell_command *cmd)
static enum bshell_status begin_processing(
bshell_command *cmd,
enum bshell_command_position position)
{
return BSHELL_SUCCESS;
}
@@ -8,6 +8,13 @@
FX_DECLS_BEGIN;
enum bshell_command_position {
BSHELL_COMMAND_POSITION_SINGLE = 0,
BSHELL_COMMAND_POSITION_BEGINNING,
BSHELL_COMMAND_POSITION_MIDDLE,
BSHELL_COMMAND_POSITION_END,
};
struct bshell_runtime;
#define BSHELL_TYPE_COMMAND (bshell_command_get_type())
@@ -24,7 +31,9 @@ FX_TYPE_CLASS_DECLARATION_BEGIN(bshell_command)
*c_get_description)(const bshell_command *, fx_string *);
enum bshell_status (
*c_get_description_static)(const fx_type *, fx_string *);
enum bshell_status (*c_begin_processing)(bshell_command *);
enum bshell_status (*c_begin_processing)(
bshell_command *,
enum bshell_command_position);
enum bshell_status (*c_process_record)(
bshell_command *,
FX_TYPE_FWDREF(bshell_pipeline) * pipeline,
@@ -47,9 +56,11 @@ extern void bshell_command_set_args_reverse(
extern const fx_value *bshell_command_get_arg(
bshell_command *cmd,
size_t index);
extern size_t bshell_command_get_arg_count(const bshell_command *cmd);
extern enum bshell_status bshell_command_begin_processing(
bshell_command *command);
bshell_command *command,
enum bshell_command_position position);
extern enum bshell_status bshell_command_process_record(
bshell_command *command,
FX_TYPE_FWDREF(bshell_pipeline) * pipeline,
@@ -8,6 +8,8 @@ FX_DECLS_BEGIN;
struct bshell_runtime;
enum bshell_command_position;
#define BSHELL_TYPE_CMDCALL (bshell_cmdcall_get_type())
FX_DECLARE_TYPE(bshell_cmdcall);
@@ -29,7 +31,8 @@ extern enum bshell_status bshell_cmdcall_resolve(
extern enum bshell_status bshell_cmdcall_process_record(
bshell_cmdcall *cmdcall,
FX_TYPE_FWDREF(bshell_pipeline) * pipeline,
struct bshell_runtime *rt);
struct bshell_runtime *rt,
enum bshell_command_position position);
FX_DECLS_END;
+7 -12
View File
@@ -195,14 +195,15 @@ static enum bshell_status cmdcall_execute(struct bshell_cmdcall_p *cmdcall)
static enum bshell_status cmdcall_process_record(
struct bshell_cmdcall_p *cmdcall,
bshell_pipeline *pipeline,
struct bshell_runtime *rt)
struct bshell_runtime *rt,
enum bshell_command_position position)
{
if (!cmdcall->cmd_target) {
return BSHELL_ERR_NOT_SUPPORTED;
}
if (!cmdcall->cmd_initialised) {
bshell_command_begin_processing(cmdcall->cmd_target);
bshell_command_begin_processing(cmdcall->cmd_target, position);
cmdcall->cmd_initialised = true;
}
@@ -231,25 +232,19 @@ enum bshell_status bshell_cmdcall_resolve(
rt);
}
enum bshell_status bshell_cmdcall_execute(bshell_cmdcall *cmdcall)
{
FX_CLASS_DISPATCH_STATIC_0(
BSHELL_TYPE_CMDCALL,
cmdcall_execute,
cmdcall);
}
enum bshell_status bshell_cmdcall_process_record(
bshell_cmdcall *cmdcall,
bshell_pipeline *pipeline,
struct bshell_runtime *rt)
struct bshell_runtime *rt,
enum bshell_command_position position)
{
FX_CLASS_DISPATCH_STATIC(
BSHELL_TYPE_CMDCALL,
cmdcall_process_record,
cmdcall,
pipeline,
rt);
rt,
position);
}
FX_TYPE_CLASS_BEGIN(bshell_cmdcall)
+19 -1
View File
@@ -7,6 +7,7 @@
#include <fx/vector.h>
struct bshell_pipeline_p {
bool p_input_values_provided;
bshell_pipeline *p_self;
fx_array *p_in, *p_out;
FX_VECTOR_DECLARE(bshell_cmdcall *, p_cmds);
@@ -72,6 +73,7 @@ static enum bshell_status pipeline_add_input_value(
fx_value value,
bool enumerate)
{
pipeline->p_input_values_provided = true;
return write_value(pipeline, pipeline->p_in, value, enumerate);
}
@@ -118,10 +120,26 @@ static enum bshell_status pipeline_pump_record(
size_t i = 0;
for (i = 0; i < pipeline->p_cmds.count;) {
enum bshell_command_position position;
if (pipeline->p_cmds.count == 1) {
position = pipeline->p_input_values_provided
? BSHELL_COMMAND_POSITION_END
: BSHELL_COMMAND_POSITION_SINGLE;
} else if (i == 0) {
position = pipeline->p_input_values_provided
? BSHELL_COMMAND_POSITION_END
: BSHELL_COMMAND_POSITION_BEGINNING;
} else if (i == pipeline->p_cmds.count - 1) {
position = BSHELL_COMMAND_POSITION_END;
} else {
position = BSHELL_COMMAND_POSITION_MIDDLE;
}
status = bshell_cmdcall_process_record(
pipeline->p_cmds.items[i],
pipeline->p_self,
rt);
rt,
position);
if (status != BSHELL_SUCCESS) {
break;