18 #define CTRL_KEYPRESS(k) ((k) & 0x1f)
22 #define IS_ATTY_PRINT(str) if (isatty(0)) my_putstr(str)
76 int (*builtin_function)(
mysh_t *mysh);
103void shell(
char **env);
411void my_exit(
mysh_t *mysh,
unsigned char status,
char const *message);
623char **
array_string(
char const *str,
char const *separator);
697int ctrl(
char c,
int *pos,
char *str,
char **str2);
707int backspace(
char c,
int *pos,
char *str,
char **str2);
The header file of the libmymemory.
int my_getline(char **line, FILE *stream)
Get the line from the stream.
Definition my_getline.c:115
int exec_alias(mysh_t *mysh)
The alias builtin.
Definition alias.c:142
void * free_str_and_tab(char *str, char **tab)
Free an string and his array.
Definition exit.c:20
char ** replace_alias_in_line(char **args, node_t **alias_list)
Replace the alias if it already exists.
Definition replace_alias.c:100
void analyse_pipes(mysh_t *mysh, char *line)
Analyse and execute the pipes.
Definition pipes.c:153
void check_42shrc(mysh_t *mysh)
Check if the 42shrc file exists in the home directory and create it if it doesn't.
Definition config_file.c:38
void is_git_repository(void)
Check if we are in a git repository and display the branch.
Definition git_repository.c:57
void add_variable(mysh_t *mysh, char *name, char *value)
Add a variable to the list.
Definition set.c:100
void shell(char **env)
The shell loop.
Definition shell.c:58
int execute_bash_file(mysh_t *mysh, int file, size_t size)
Execute a bash file.
Definition source.c:22
int exec_env(mysh_t *mysh)
The env builtin.
Definition env.c:22
char * check_command_exist(mysh_t *mysh, char *command)
Check if the command exists.
Definition command.c:97
void print_line(int signal)
Display the prompt when the SIGINT signal is received.
Definition signals.c:38
builtin_t * get_builtin_command(int index)
Get the builtin command.
Definition command.c:19
void replace_env_var(char **env, char *name, char *value)
Replace an environment variable.
Definition environnement.c:52
int exec_if(mysh_t *mysh)
The if builtin.
Definition if.c:134
void analyse_multi_commands(mysh_t *mysh, char *line)
Analyse and execute multiple commands.
Definition multiple_commands.c:20
int exec_set(mysh_t *mysh)
The set builtin.
Definition set.c:143
int check_tilde(mysh_t *mysh)
Transform the tilde in the command line by the home path.
Definition tilde.c:47
int exec_foreach(mysh_t *mysh)
The foreach builtin.
Definition foreach.c:115
void check_path(mysh_t *mysh)
Check if the PATH is set in the environment and set it if not.
Definition environnement.c:68
void set_command_in_history(mysh_t *mysh, char *line)
Set the command in the history.
Definition history_file.c:20
int ctrl(char c, int *pos, char *str, char **str2)
Handle the control key.
Definition ansi.c:147
int replace_variables(mysh_t *mysh)
Replace the variables in the command arguments.
Definition replace_variable.c:181
void my_exit(mysh_t *mysh, unsigned char status, char const *message)
Free the shell structure and exit the shell.
Definition exit.c:78
int exec_unalias(mysh_t *mysh)
The unalias builtin.
Definition unalias.c:35
void display_input_command(input_command_t *input_command)
Display the input command.
Definition input_command.c:226
int exec_else_if(mysh_t *mysh, char **line_content)
The else if builtin.
Definition if.c:107
int exec_source(mysh_t *mysh)
The source builtin.
Definition source.c:49
void select_redirections(mysh_t *mysh, input_command_t *input)
Analyse and execute the good redirection.
Definition redirections.c:58
void remove_comments(char *line)
Remove the comments from a line.
Definition scripting.c:19
int exec_help(mysh_t *mysh)
The help builtin.
Definition help.c:127
void print_exit(int signal)
Display "exit" when the a CRTL+D is received.
Definition signals.c:50
void status_handler(int status)
Display the signal returned by executing a command.
Definition signals.c:19
int exec_where(mysh_t *mysh)
The where builtin.
Definition where.c:80
char ** array_string(char const *str, char const *separator)
Transform a string into an array of words delimited by a string with inhibitors.
Definition array_string.c:133
int char_is_paranthesed(char *str, int index)
Check if a char is paranthesed.
Definition parsing.c:50
char ** array_separators(char const *str, char const *separator)
Transform a string into an array of words delimited by separators with inhibitors.
Definition array_separators.c:130
mysh_t * init_shell(char **env)
Initialize the shell structure.
Definition shell.c:30
input_command_t * get_input_command(char *command)
Get the input command.
Definition input_command.c:199
int exec_exit(mysh_t *mysh)
The exit builtin.
Definition exit.c:108
void check_tty(void)
Check if the shell is a tty and display the prompt if it is.
Definition shell.c:45
int exec_repeat(mysh_t *mysh)
The source builtin.
Definition repeat.c:19
int exec_end(mysh_t *mysh)
The end builtin.
Definition end.c:19
char * get_env_var(char **env, char *var)
Get an environment variable.
Definition environnement.c:36
int exec_echo(mysh_t *mysh)
The echo builtin.
Definition echo.c:19
char * get_variable_value(mysh_t *mysh, char *name)
Get the value of a variable.
Definition set.c:172
int missing_name(mysh_t *mysh, char **commands)
Display the error message when the name is missing.
Definition redirections.c:44
void set_title(void)
Set the title of the shell.
Definition title.c:18
int exec_history(mysh_t *mysh)
The history builtin.
Definition history.c:60
char * get_redirection_path(char *line)
Browse the command line to get the redirection path.
Definition redirections.c:19
char ** str_to_array_inhibitors(char *str)
Transform a string into an array of words with inhibitors.
Definition inhibitors.c:198
void exec_left_double_redirection(mysh_t *mysh, input_command_t *input)
Execute the left double redirection.
Definition left_redirections.c:79
int exec_about(mysh_t *mysh)
The about builtin.
Definition about.c:94
void analyse_backticks(mysh_t *mysh, char *line)
Analyse and execute backticks commands.
Definition backticks.c:134
int is_valid_variable(char *variable, char *builtin)
Check if the variable is valid.
Definition parsing.c:107
mysh_t * get_mysh(void)
Get the shell structure.
Definition shell.c:18
int exec_cd(mysh_t *mysh)
The cd builtin.
Definition cd.c:75
int exec_endif(mysh_t *mysh)
The endif builtin.
Definition endif.c:19
void exec_right_redirection(mysh_t *mysh, input_command_t *input)
Execute the right redirection.
Definition right_redirections.c:44
int exec_which(mysh_t *mysh)
The which builtin.
Definition which.c:84
int disable_buffer(void)
Disable the buffer.
Definition termios.c:40
int exec_else(mysh_t *mysh)
The else builtin.
Definition else.c:19
int exec_setenv(mysh_t *mysh)
The setenv builtin.
Definition setenv.c:86
void command(mysh_t *mysh, input_command_t *input)
Execute the command.
Definition command.c:149
int exec_unset(mysh_t *mysh)
The unset builtin.
Definition unset.c:36
void display_prompt(void)
Display the prompt.
Definition prompt.c:105
void exec_left_simple_redirection(mysh_t *mysh, input_command_t *input)
Execute the left simple redirection.
Definition left_redirections.c:109
char ** replace_history(char **args)
Replace '!' by history event.
Definition event.c:76
int read_file_in_stdin(char *file)
Read a file and execute the commands in it.
Definition scripting.c:81
int backspace(char c, int *pos, char *str, char **str2)
Handle the backspace key.
Definition ansi.c:173
char char_is_inhibited(char *str, int index)
Check if a character is inhibited.
Definition parsing.c:21
void free_input_list(mysh_t *mysh)
Free the input list.
Definition exit.c:34
void restore_termios(struct termios *saved_termios)
Restore terminal attributes.
Definition termios.c:30
int get_condition(char *str)
Get the condition result from a string.
Definition condition.c:91
int char_is_protected(char *str, int index)
Check if a char is protected.
Definition parsing.c:73
void analyse_parentheses(mysh_t *mysh, input_command_t *input)
Analyse the parentheses.
Definition parentheses.c:172
int exec_unsetenv(mysh_t *mysh)
The unsetenv builtin.
Definition unsetenv.c:56
int set_new_env_var(mysh_t *mysh, char *var, char *value)
Set a new environment variable.
Definition setenv.c:59
void save_termios(struct termios *saved_termios)
Save terminal attributes.
Definition termios.c:19
void create_history(mysh_t *mysh)
Create the history file.
Definition history_file.c:44
void analyse_operators(mysh_t *mysh, char *line)
Analyse the operators and execute the commands.
Definition operators.c:106
char * find_valid_str(char *str, char const *to_find)
Find a valid string in a string depending on inhibitors and parentheses.
Definition parsing.c:89
void move_cursor(int *pos, char *str, char **str2)
Move the cursor.
Definition ansi.c:120
void my_sort_alias(node_t **begin, int(*cmp)())
sort the alias list
Definition replace_alias.c:27
char ** globbing(char **args)
Analyse if arguments are globbing.
Definition globbing.c:42
int exec_command(mysh_t *mysh)
The exec command builtin.
Definition exec.c:73
void update_path_list(mysh_t *mysh)
Update the path list.
Definition environnement.c:79