42sh/src/io_backend/io_backend.c

36 lines
611 B
C
Raw Normal View History

2026-01-08 14:40:37 +01:00
#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)
{
2026-01-10 19:57:36 +01:00
case IOB_MODE_STDIN:
2026-01-08 14:40:37 +01:00
input = stdin;
return 0;
2026-01-10 19:57:36 +01:00
case IOB_MODE_SCRIPT:
2026-01-08 14:40:37 +01:00
if (context.args == NULL)
return -2;
input = fopen(context.args, "r");
if (input == NULL)
return -4;
2026-01-10 19:57:36 +01:00
return 0;
2026-01-08 14:40:37 +01:00
2026-01-10 19:57:36 +01:00
case IOB_MODE_CMD:
2026-01-08 14:40:37 +01:00
if (context.args != NULL)
return -2;
else
return 0;
default:
return -1;
}
}