148 lines
3.2 KiB
C
148 lines
3.2 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 <ostream/file/new.h>
|
|
#include <ostream/free.h>
|
|
|
|
#include <wcostream/ostream/new.h>
|
|
#include <wcostream/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>*/
|
|
|
|
#include <repl/main.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->init_path);
|
|
}
|
|
|
|
struct ostream* b_stdout = new_file_ostream(
|
|
/* file descriptor: */ 1);
|
|
|
|
struct wcostream* wc_stdout = new_ostream_wcostream(
|
|
/* binary stream: */ b_stdout);
|
|
|
|
switch (flags->input_kind)
|
|
{
|
|
case ik_string:
|
|
{
|
|
handle_string(
|
|
/* environment, may by modified/replaced: */ &environment,
|
|
/* booleans: */ booleans,
|
|
/* input string: */ flags->input_string,
|
|
/* echo statements? */ flags->echo,
|
|
/* colors?: */ flags->print_with_colors,
|
|
/* wide-character output stream: */ wc_stdout);
|
|
|
|
break;
|
|
}
|
|
|
|
case ik_file:
|
|
{
|
|
handle_file(
|
|
/* environment, may by modified/replaced: */ &environment,
|
|
/* booleans: */ booleans,
|
|
/* input file: */ flags->input_file,
|
|
/* echo statements? */ flags->echo,
|
|
/* colors?: */ flags->print_with_colors,
|
|
/* wide-character output stream: */ wc_stdout);
|
|
|
|
break;
|
|
}
|
|
|
|
case ik_interactive:
|
|
{
|
|
repl_main();
|
|
|
|
TODO;
|
|
#if 0
|
|
#ifdef RELEASE_BUILD
|
|
if (!isatty(1))
|
|
{
|
|
TODO;
|
|
exit(1);
|
|
}
|
|
#endif
|
|
|
|
handle_interactive(
|
|
/* environment, may by modified/replaced: */ &environment,
|
|
/* booleans: */ booleans,
|
|
/* wide-character output stream: */ wc_stdout
|
|
#ifndef RELEASE_BUILD
|
|
, /* test interactive using input file: */
|
|
flags->test_interactive_using_input_file
|
|
#endif
|
|
);
|
|
#endif
|
|
|
|
break;
|
|
}
|
|
|
|
default:
|
|
{
|
|
TODO;
|
|
break;
|
|
}
|
|
}
|
|
|
|
free_wcostream(wc_stdout);
|
|
|
|
free_ostream(b_stdout);
|
|
|
|
free_environment(environment);
|
|
|
|
free_booleans(booleans);
|
|
|
|
free_cmdln_flags(flags);
|
|
|
|
EXIT;
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|