59 lines
1.8 KiB
C
59 lines
1.8 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* main.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/04/23 14:33:45 by mcolonna #+# #+# */
|
|
/* Updated: 2024/05/31 13:46:33 by mcolonna ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "include.h"
|
|
|
|
t_memclass g_mc;
|
|
|
|
// Execute a command from a string.
|
|
static int do_command(char *const envp[], const char *str)
|
|
{
|
|
const t_memclass mc = mem_subclass(fatal_error, g_mc);
|
|
t_command command;
|
|
int r;
|
|
|
|
command = parse_command(mc, str);
|
|
if (command.error || command.empty)
|
|
return (command.error);
|
|
r = execute_command(mc, command, envp);
|
|
mem_freeall(mc);
|
|
return (r);
|
|
}
|
|
|
|
static void start(char *const envp[])
|
|
{
|
|
do_command(envp, "clear");
|
|
do_command(envp, "cat ./header");
|
|
do_command(envp, "echo");
|
|
}
|
|
|
|
int main(const int argc, const char *argv[], char *const envp[])
|
|
{
|
|
t_memclass mc;
|
|
const char *command_str;
|
|
int errorstatus;
|
|
|
|
(void)argc;
|
|
(void)argv;
|
|
g_mc = NULL;
|
|
g_mc = mem_newclass(fatal_error);
|
|
start(envp);
|
|
errorstatus = 0;
|
|
while (true)
|
|
{
|
|
mc = mem_subclass(fatal_error, g_mc);
|
|
command_str = ask_command(mc);
|
|
add_history(command_str);
|
|
do_command(envp, command_str);
|
|
}
|
|
return (errorstatus);
|
|
}
|