From 92c0b5ba962ebe888a0db94a8b3cad3c63dee1ff Mon Sep 17 00:00:00 2001 From: "Gu://em_" Date: Thu, 8 Jan 2026 14:40:37 +0100 Subject: [PATCH] feat: IOB structures and iob_init() --- src/io_backend/io_backend.c | 34 +++++++++++++++++++++++++++ src/io_backend/io_backend.h | 46 +++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/src/io_backend/io_backend.c b/src/io_backend/io_backend.c index e69de29..ee6b09b 100644 --- a/src/io_backend/io_backend.c +++ b/src/io_backend/io_backend.c @@ -0,0 +1,34 @@ +#include "io_backend.h" + +#include + +static struct iob_context context; +static FILE *input; + +int iob_init(struct iob_context *ctx) +{ + context = *ctx; + + switch (context.mode) + { + IOB_MODE_STDIN: + input = stdin; + return 0; + + IOB_MODE_SCRIPT: + if (context.args == NULL) + return -2; + input = fopen(context.args, "r"); + if (input == NULL) + return -4; + + IOB_MODE_CMD: + if (context.args != NULL) + return -2; + else + return 0; + + default: + return -1; + } +} diff --git a/src/io_backend/io_backend.h b/src/io_backend/io_backend.h index e69de29..34d85f3 100644 --- a/src/io_backend/io_backend.h +++ b/src/io_backend/io_backend.h @@ -0,0 +1,46 @@ +#ifndef IO_BACKEND_H +#define IO_BACKEND_H + +#include + +enum iob_mode { + IOB_MODE_NULL = 0, + IOB_MODE_STDIN, + IOB_MODE_SCRIPT, + IOB_MODE_CMD +}; + +/* @struct iob_context + * @var mode + * @var args contains + * the script name when mode is set to IOB_SCRIPT, + * the command to execute when mode is set to IOB_CMD, + */ +struct iob_context { + enum iob_mode mode; + char* args; +}; + +/* + * @brief Initializes the IO Backend module + * + * @param context contains the input mode and the args + * @return 0 on success, the corresponding error code otherwise + */ +int iob_init(struct iob_context *context); + +/* TODO + * + * + * + */ +void iob_close(); + +/*i TODO + * + * + * + */ +ssize_t stream_read(char** stream); + +#endif /* ! IO_BACKEND_H */