feat: IOB structures and iob_init()

This commit is contained in:
Gu://em_ 2026-01-08 14:40:37 +01:00
parent 269f50a367
commit 92c0b5ba96
2 changed files with 80 additions and 0 deletions

View file

@ -0,0 +1,34 @@
#include "io_backend.h"
#include <stdio.h>
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;
}
}