maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
main.c File Reference
#include "tokens.h"
#include "execute.h"
#include "shell.h"
#include "pipe.h"
#include "signals.h"
#include "exit_status.h"
#include "builtins.h"
Include dependency graph for main.c:

Go to the source code of this file.

Functions

void main_loop (t_ms_data *data, t_loop_data *loop_data)
 
int main (int argc, char **argv, char **envp)
 
void process_command (t_ms_data *data, t_loop_data *loop_data, t_token *tokens_head)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv,
char **  envp 
)

Definition at line 71 of file main.c.

72{
73 t_ms_data data;
74 t_loop_data loop_data;
75
77 init_ms_data(&data, argv, envp);
78 initialise(argc, argv);
79 main_loop(&data, &loop_data);
80 free_ms_data(&data);
82 return (0);
83}
void main_loop(t_ms_data *data, t_loop_data *loop_data)
Definition main.c:43
void initialise(int argc, char **argv)
Definition initialise.c:36
void print_maxishell(void)
Definition prompt.c:56
void init_ms_data(t_ms_data *data, char **argv, char **envp)
Definition initialise.c:20
void clear_history_file(void)
void free_ms_data(t_ms_data *data)
Definition clean.c:51

References clear_history_file(), free_ms_data(), init_ms_data(), initialise(), main_loop(), and print_maxishell().

Here is the call graph for this function:

◆ main_loop()

void main_loop ( t_ms_data data,
t_loop_data loop_data 
)

Definition at line 43 of file main.c.

44{
45 t_token *tokens_start;
46
47 while (1)
48 {
51 loop_data->input = readline("🌴 maxishell> ");
52 if (loop_data->input && loop_data->input[0] == '\0')
53 continue ;
54 if (!loop_data->input || !ft_strncmp(loop_data->input, "exit", 4))
55 {
56 data->args = ft_split(loop_data->input, ' ');
57 builtin_exit(data);
58 }
59 make_history(loop_data->input);
60 loop_data->trimmed_input = trim_input(loop_data->input);
61 if (input_error_checks(loop_data))
62 continue ;
63 loop_data->tokens = tokenise(loop_data->trimmed_input);
64 tokens_start = loop_data->tokens;
65 loop_data->tree = parse_tokens(&loop_data->tokens, data);
66 process_command(data, loop_data, tokens_start);
67 }
69}
int builtin_exit(t_ms_data *data)
Definition exit.c:61
int ft_strncmp(const char *s1, const char *s2, size_t n)
Definition ft_strncmp.c:24
char ** ft_split(char const *s, char c)
Definition ft_split.c:95
void process_command(t_ms_data *data, t_loop_data *loop_data, t_token *tokens_head)
Definition main.c:24
void set_signals_interactive(t_ms_data *data)
Definition signals.c:43
void set_signals_noninteractive(void)
Definition signals.c:66
char * trimmed_input
Definition tokens.h:61
t_token * tokens
Definition tokens.h:62
char * input
Definition tokens.h:60
t_ast * tree
Definition tokens.h:63
char ** args
Definition shell.h:23
t_ast * parse_tokens(t_token **tokens, t_ms_data *data)
Definition AST_utils.c:23
t_token * tokenise(char *str)
Definition tokeniser.c:22
int input_error_checks(t_loop_data *loop_data)
void make_history(char *line)
Definition aux.c:15
char * trim_input(char *str)

References s_ms_data::args, builtin_exit(), clear_history_file(), ft_split(), ft_strncmp(), s_loop_data::input, input_error_checks(), make_history(), parse_tokens(), process_command(), set_signals_interactive(), set_signals_noninteractive(), tokenise(), s_loop_data::tokens, s_loop_data::tree, trim_input(), and s_loop_data::trimmed_input.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_command()

void process_command ( t_ms_data data,
t_loop_data loop_data,
t_token tokens_head 
)

Definition at line 24 of file main.c.

26{
27 int status;
28
29 if (!data || !loop_data || !tokens_head || !loop_data->tree)
30 return ;
31 status = execute_ast(loop_data->tree, data);
32 data->exit_status = status;
34 if (status == WAIT_NEXT_COMMAND)
35 {
36 loop_cleanup(loop_data, tokens_head);
37 return ;
38 }
39 handle_io_fd(data);
40 loop_cleanup(loop_data, tokens_head);
41}
int execute_ast(t_ast *node, t_ms_data *data)
execute Abstract Syntax Tree
Definition execute.c:38
void handle_io_fd(t_ms_data *data)
close temporary input/output file descriptors and reset them to -1
Definition utils_0.c:39
void set_shell_var_handler(t_ms_data *data)
Definition exit_status.c:53
#define WAIT_NEXT_COMMAND
Definition pipe.h:19
int exit_status
Definition shell.h:30
void loop_cleanup(t_loop_data *loop_data, t_token *tokens_head)
Definition clean.c:67

References execute_ast(), s_ms_data::exit_status, handle_io_fd(), loop_cleanup(), set_shell_var_handler(), s_loop_data::tree, and WAIT_NEXT_COMMAND.

Referenced by main_loop().

Here is the call graph for this function:
Here is the caller graph for this function: