118 lines
2.3 KiB
C
118 lines
2.3 KiB
C
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <cmdln/struct.h>
|
|
#include <cmdln/new.h>
|
|
#include <cmdln/free.h>
|
|
|
|
#include <booleans/new.h>
|
|
#include <booleans/free.h>
|
|
|
|
/*#include <color_factory/new.h>*/
|
|
/*#include <color_factory/free.h>*/
|
|
|
|
#include <environment/new.h>
|
|
#include <environment/declare_builtins.h>
|
|
#include <environment/free.h>
|
|
|
|
#include <handle_init_file.h>
|
|
|
|
#include <handle_string.h>
|
|
#include <handle_file.h>
|
|
#include <handle_interactive.h>
|
|
|
|
int main(int argc, char* const* argv)
|
|
{
|
|
ENTER;
|
|
|
|
struct cmdln_flags* flags = new_cmdln_flags(argc, argv);
|
|
|
|
struct booleans* booleans = new_booleans();
|
|
|
|
struct environment* environment = new_environment(
|
|
/* fallback: */ NULL);
|
|
|
|
environment_declare_builtins(
|
|
/* this: */ environment,
|
|
/* booleans: */ booleans);
|
|
|
|
if (flags->read_init_file)
|
|
{
|
|
handle_init_file(&environment, booleans, flags->custom_init_path);
|
|
}
|
|
|
|
switch (flags->input_kind)
|
|
{
|
|
case ik_string:
|
|
{
|
|
handle_string(
|
|
/* environment, may by modified/replaced: */ &environment,
|
|
/* booleans: */ booleans,
|
|
/* input string: */ flags->input_string,
|
|
/* echo? */ flags->echo,
|
|
/* colors?: */ flags->print_with_colors);
|
|
|
|
break;
|
|
}
|
|
|
|
case ik_file:
|
|
{
|
|
handle_file(
|
|
/* environment, may by modified/replaced: */ &environment,
|
|
/* booleans: */ booleans,
|
|
/* input file: */ flags->input_file,
|
|
/* echo? */ flags->echo,
|
|
/* colors?: */ flags->print_with_colors);
|
|
|
|
break;
|
|
}
|
|
|
|
case ik_interactive:
|
|
{
|
|
if (!isatty(1))
|
|
{
|
|
TODO;
|
|
exit(1);
|
|
}
|
|
|
|
handle_interactive(
|
|
/* environment, may by modified/replaced: */ &environment,
|
|
/* booleans: */ booleans);
|
|
|
|
break;
|
|
}
|
|
|
|
default:
|
|
{
|
|
TODO;
|
|
break;
|
|
}
|
|
}
|
|
|
|
free_environment(environment);
|
|
|
|
free_booleans(booleans);
|
|
|
|
free_cmdln_flags(flags);
|
|
|
|
EXIT;
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|