2026-01-12 22:27:26 +01:00
|
|
|
// All the includes
|
2026-01-12 19:30:11 +00:00
|
|
|
#include <stdio.h>
|
2026-01-12 22:27:26 +01:00
|
|
|
#include <stdlib.h>
|
2026-01-12 19:30:11 +00:00
|
|
|
|
2026-01-12 22:27:26 +01:00
|
|
|
#include "execution/execution.h"
|
|
|
|
|
#include "io_backend/io_backend.h"
|
|
|
|
|
#include "parser/parser.h"
|
2026-01-12 19:30:11 +00:00
|
|
|
#include "utils/args/args.h"
|
|
|
|
|
|
2026-01-12 22:27:26 +01:00
|
|
|
enum return_codes
|
|
|
|
|
{
|
|
|
|
|
SUCCESS = 0,
|
|
|
|
|
ERR_IO_BACKEND = 2,
|
|
|
|
|
ERR_MALLOC = 3
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-07 17:38:54 +01:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
2026-01-12 22:27:26 +01:00
|
|
|
// Create the options struct (with argument handler)
|
2026-01-12 19:30:11 +00:00
|
|
|
struct args_options options;
|
|
|
|
|
int r = args_handler(argc, argv, &options);
|
|
|
|
|
if (r != 0)
|
|
|
|
|
{
|
|
|
|
|
print_usage(stderr, argv[0]);
|
2026-01-12 22:27:26 +01:00
|
|
|
return ERR_IO_BACKEND;
|
2026-01-12 19:30:11 +00:00
|
|
|
}
|
2026-01-12 22:27:26 +01:00
|
|
|
// args_print(&options);
|
|
|
|
|
|
|
|
|
|
// Create the IO-Backend context struct
|
|
|
|
|
struct iob_context *io_context = malloc(sizeof(struct iob_context));
|
|
|
|
|
if (io_context == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Error: Memory allocation failed for IO Backend context\n");
|
|
|
|
|
return ERR_MALLOC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convert args_options to iob_context
|
|
|
|
|
r = iob_config_from_args(&options, io_context);
|
|
|
|
|
if (r != 0)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Error: Failed to configure IO Backend from arguments\n");
|
|
|
|
|
free(io_context);
|
|
|
|
|
return ERR_IO_BACKEND;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Init IO Backend (with the context struct)
|
|
|
|
|
r = iob_init(io_context);
|
|
|
|
|
if (r != 0)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Error: IO Backend initialization failed with code %d\n", r);
|
|
|
|
|
free(io_context);
|
|
|
|
|
return ERR_IO_BACKEND;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(io_context);
|
|
|
|
|
|
|
|
|
|
// Call the parser to get the AST
|
|
|
|
|
struct ast *command_ast = get_ast(); // We'll pass the options later
|
|
|
|
|
|
2026-01-21 19:57:44 +01:00
|
|
|
if (options.pretty_print)
|
|
|
|
|
{
|
|
|
|
|
ast_print_dot(command_ast);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-12 22:27:26 +01:00
|
|
|
// Call the executor with the AST
|
|
|
|
|
r = execution(command_ast);
|
2026-01-12 19:30:11 +00:00
|
|
|
|
2026-01-12 22:27:26 +01:00
|
|
|
// Return the execution return code (last command executed)
|
|
|
|
|
return r;
|
2026-01-07 17:38:54 +01:00
|
|
|
}
|