|
42sh 1.0.0
Create a shell in C
|
The file containing the prototypes of the myshell functions. More...
Go to the source code of this file.
Data Structures | |
| struct | alias_s |
| struct | variable_s |
| struct | input_command_s |
| struct | mysh_s |
| struct | builtin_s |
Macros | |
| #define | MYSHELL_H_ |
| #define | CTRL_KEYPRESS(k) ((k) & 0x1f) |
| #define | CTRL_D 4 |
| #define | CTRL_C 3 |
| #define | IS_ATTY_PRINT(str) if (isatty(0)) my_putstr(str) |
Typedefs | |
| typedef struct alias_s | alias_t |
| typedef struct variable_s | variable_t |
| typedef struct input_command_s | input_command_t |
| typedef struct mysh_s | mysh_t |
| typedef struct builtin_s | builtin_t |
Functions | |
| mysh_t * | get_mysh (void) |
| Get the shell structure. | |
| mysh_t * | init_shell (char **env) |
| Initialize the shell structure. | |
| void | shell (char **env) |
| The shell loop. | |
| int | set_new_env_var (mysh_t *mysh, char *var, char *value) |
| Set a new environment variable. | |
| char * | get_env_var (char **env, char *var) |
| Get an environment variable. | |
| void | replace_env_var (char **env, char *name, char *value) |
| Replace an environment variable. | |
| void | check_path (mysh_t *mysh) |
| Check if the PATH is set in the environment and set it if not. | |
| void | update_path_list (mysh_t *mysh) |
| Update the path list. | |
| void | check_tty (void) |
| Check if the shell is a tty and display the prompt if it is. | |
| void | set_title (void) |
| Set the title of the shell. | |
| void | display_prompt (void) |
| Display the prompt. | |
| void | is_git_repository (void) |
| Check if we are in a git repository and display the branch. | |
| char * | check_command_exist (mysh_t *mysh, char *command) |
| Check if the command exists. | |
| void | command (mysh_t *mysh, input_command_t *input) |
| Execute the command. | |
| builtin_t * | get_builtin_command (int index) |
| Get the builtin command. | |
| int | exec_about (mysh_t *mysh) |
| The about builtin. | |
| int | exec_alias (mysh_t *mysh) |
| The alias builtin. | |
| int | exec_cd (mysh_t *mysh) |
| The cd builtin. | |
| int | exec_command (mysh_t *mysh) |
| The exec command builtin. | |
| int | exec_echo (mysh_t *mysh) |
| The echo builtin. | |
| int | exec_else (mysh_t *mysh) |
| The else builtin. | |
| int | exec_else_if (mysh_t *mysh, char **line_content) |
| The else if builtin. | |
| int | exec_end (mysh_t *mysh) |
| The end builtin. | |
| int | exec_endif (mysh_t *mysh) |
| The endif builtin. | |
| int | exec_env (mysh_t *mysh) |
| The env builtin. | |
| int | exec_exit (mysh_t *mysh) |
| The exit builtin. | |
| int | exec_foreach (mysh_t *mysh) |
| The foreach builtin. | |
| int | exec_help (mysh_t *mysh) |
| The help builtin. | |
| int | exec_history (mysh_t *mysh) |
| The history builtin. | |
| int | exec_if (mysh_t *mysh) |
| The if builtin. | |
| int | exec_repeat (mysh_t *mysh) |
| The source builtin. | |
| int | exec_set (mysh_t *mysh) |
| The set builtin. | |
| int | exec_setenv (mysh_t *mysh) |
| The setenv builtin. | |
| int | exec_source (mysh_t *mysh) |
| The source builtin. | |
| int | exec_unalias (mysh_t *mysh) |
| The unalias builtin. | |
| int | exec_unset (mysh_t *mysh) |
| The unset builtin. | |
| int | exec_unsetenv (mysh_t *mysh) |
| The unsetenv builtin. | |
| int | exec_where (mysh_t *mysh) |
| The where builtin. | |
| int | exec_which (mysh_t *mysh) |
| The which builtin. | |
| void * | free_str_and_tab (char *str, char **tab) |
| Free an string and his array. | |
| void | free_input_list (mysh_t *mysh) |
| Free the input list. | |
| void | my_exit (mysh_t *mysh, unsigned char status, char const *message) |
| Free the shell structure and exit the shell. | |
| void | status_handler (int status) |
| Display the signal returned by executing a command. | |
| void | print_line (int signal) |
| Display the prompt when the SIGINT signal is received. | |
| void | print_exit (int signal) |
| Display "exit" when the a CRTL+D is received. | |
| int | check_tilde (mysh_t *mysh) |
| Transform the tilde in the command line by the home path. | |
| char * | get_redirection_path (char *line) |
| Browse the command line to get the redirection path. | |
| int | missing_name (mysh_t *mysh, char **commands) |
| Display the error message when the name is missing. | |
| void | analyse_backticks (mysh_t *mysh, char *line) |
| Analyse and execute backticks commands. | |
| void | analyse_multi_commands (mysh_t *mysh, char *line) |
| Analyse and execute multiple commands. | |
| void | analyse_operators (mysh_t *mysh, char *line) |
| Analyse the operators and execute the commands. | |
| void | analyse_pipes (mysh_t *mysh, char *line) |
| Analyse and execute the pipes. | |
| void | exec_right_redirection (mysh_t *mysh, input_command_t *input) |
| Execute the right redirection. | |
| void | exec_left_double_redirection (mysh_t *mysh, input_command_t *input) |
| Execute the left double redirection. | |
| void | exec_left_simple_redirection (mysh_t *mysh, input_command_t *input) |
| Execute the left simple redirection. | |
| void | select_redirections (mysh_t *mysh, input_command_t *input) |
| Analyse and execute the good redirection. | |
| void | analyse_parentheses (mysh_t *mysh, input_command_t *input) |
| Analyse the parentheses. | |
| input_command_t * | get_input_command (char *command) |
| Get the input command. | |
| void | display_input_command (input_command_t *input_command) |
| Display the input command. | |
| char | char_is_inhibited (char *str, int index) |
| Check if a character is inhibited. | |
| int | char_is_paranthesed (char *str, int index) |
| Check if a char is paranthesed. | |
| int | char_is_protected (char *str, int index) |
| Check if a char is protected. | |
| char * | find_valid_str (char *str, char const *to_find) |
| Find a valid string in a string depending on inhibitors and parentheses. | |
| char ** | str_to_array_inhibitors (char *str) |
| Transform a string into an array of words with inhibitors. | |
| char ** | array_string (char const *str, char const *separator) |
| Transform a string into an array of words delimited by a string with inhibitors. | |
| char ** | array_separators (char const *str, char const *separator) |
| Transform a string into an array of words delimited by separators with inhibitors. | |
| char ** | globbing (char **args) |
| Analyse if arguments are globbing. | |
| int | my_getline (char **line, FILE *stream) |
| Get the line from the stream. | |
| void | save_termios (struct termios *saved_termios) |
| Save terminal attributes. | |
| void | restore_termios (struct termios *saved_termios) |
| Restore terminal attributes. | |
| int | disable_buffer (void) |
| Disable the buffer. | |
| void | move_cursor (int *pos, char *str, char **str2) |
| Move the cursor. | |
| int | ctrl (char c, int *pos, char *str, char **str2) |
| Handle the control key. | |
| int | backspace (char c, int *pos, char *str, char **str2) |
| Handle the backspace key. | |
| int | execute_bash_file (mysh_t *mysh, int file, size_t size) |
| Execute a bash file. | |
| void | check_42shrc (mysh_t *mysh) |
| Check if the 42shrc file exists in the home directory and create it if it doesn't. | |
| void | create_history (mysh_t *mysh) |
| Create the history file. | |
| void | set_command_in_history (mysh_t *mysh, char *line) |
| Set the command in the history. | |
| char ** | replace_history (char **args) |
| Replace '!' by history event. | |
| char ** | replace_alias_in_line (char **args, node_t **alias_list) |
| Replace the alias if it already exists. | |
| void | my_sort_alias (node_t **begin, int(*cmp)()) |
| sort the alias list | |
| int | is_valid_variable (char *variable, char *builtin) |
| Check if the variable is valid. | |
| void | add_variable (mysh_t *mysh, char *name, char *value) |
| Add a variable to the list. | |
| char * | get_variable_value (mysh_t *mysh, char *name) |
| Get the value of a variable. | |
| int | replace_variables (mysh_t *mysh) |
| Replace the variables in the command arguments. | |
| void | remove_comments (char *line) |
| Remove the comments from a line. | |
| int | read_file_in_stdin (char *file) |
| Read a file and execute the commands in it. | |
| int | get_condition (char *str) |
| Get the condition result from a string. | |
The file containing the prototypes of the myshell functions.
| void add_variable | ( | mysh_t * | mysh, |
| char * | name, | ||
| char * | value ) |
Add a variable to the list.
| mysh | The shell structure |
| name | The name of the variable |
| value | The value of the variable |
| void analyse_backticks | ( | mysh_t * | mysh, |
| char * | line ) |
Analyse and execute backticks commands.
| mysh | The shell structure |
| line | The command line |
| void analyse_multi_commands | ( | mysh_t * | mysh, |
| char * | line ) |
Analyse and execute multiple commands.
| mysh | The shell structure |
| line | The command line |
| void analyse_operators | ( | mysh_t * | mysh, |
| char * | line ) |
Analyse the operators and execute the commands.
| mysh | The shell structure |
| line | The command line |
| void analyse_parentheses | ( | mysh_t * | mysh, |
| input_command_t * | input ) |
Analyse the parentheses.
| mysh | The shell structure |
| input | The input command structure |
| void analyse_pipes | ( | mysh_t * | mysh, |
| char * | line ) |
Analyse and execute the pipes.
| mysh | The shell structure |
| line | The command line |
| char ** array_separators | ( | char const * | str, |
| char const * | separator ) |
Transform a string into an array of words delimited by separators with inhibitors.
| str | The string to transform |
| separator | The separator |
| char ** array_string | ( | char const * | str, |
| char const * | separator ) |
Transform a string into an array of words delimited by a string with inhibitors.
| str | The string to transform |
| separator | The separator |
| int backspace | ( | char | c, |
| int * | pos, | ||
| char * | str, | ||
| char ** | str2 ) |
Handle the backspace key.
| c | The character |
| pos | The position of the cursor |
| str | The string |
| str2 | The second string |
| char char_is_inhibited | ( | char * | str, |
| int | index ) |
Check if a character is inhibited.
| str | The string to check |
| index | The index of the character |
| int char_is_paranthesed | ( | char * | str, |
| int | index ) |
Check if a char is paranthesed.
| str | The string |
| index | The index |
| int char_is_protected | ( | char * | str, |
| int | index ) |
Check if a char is protected.
| str | The string |
| index | The index |
| void check_42shrc | ( | mysh_t * | mysh | ) |
Check if the 42shrc file exists in the home directory and create it if it doesn't.
| mysh | The shell structure |
| char * check_command_exist | ( | mysh_t * | mysh, |
| char * | command ) |
Check if the command exists.
| mysh | The shell structure |
| command | The command |
| void check_path | ( | mysh_t * | mysh | ) |
Check if the PATH is set in the environment and set it if not.
| mysh | The shell structure |
| int check_tilde | ( | mysh_t * | mysh | ) |
Transform the tilde in the command line by the home path.
| mysh | The shell structure |
| void check_tty | ( | void | ) |
Check if the shell is a tty and display the prompt if it is.
| void command | ( | mysh_t * | mysh, |
| input_command_t * | input ) |
Execute the command.
| mysh | The shell structure |
| input | The input command |
| void create_history | ( | mysh_t * | mysh | ) |
Create the history file.
| mysh | The shell structure |
| int ctrl | ( | char | c, |
| int * | pos, | ||
| char * | str, | ||
| char ** | str2 ) |
Handle the control key.
| c | The character |
| pos | The position of the cursor |
| str | The string |
| str2 | The second string |
| int disable_buffer | ( | void | ) |
Disable the buffer.
| void display_input_command | ( | input_command_t * | input_command | ) |
Display the input command.
| input_command | The input command |
| void display_prompt | ( | void | ) |
Display the prompt.
| int exec_about | ( | mysh_t * | mysh | ) |
The about builtin.
| mysh | The shell structure |
| int exec_alias | ( | mysh_t * | mysh | ) |
The alias builtin.
| mysh | The shell structure |
| int exec_cd | ( | mysh_t * | mysh | ) |
The cd builtin.
| mysh | The shell structure |
| int exec_command | ( | mysh_t * | mysh | ) |
The exec command builtin.
| mysh | The shell structure |
The exec command builtin.
| mysh | The shell structure |
| int exec_echo | ( | mysh_t * | mysh | ) |
The echo builtin.
| mysh | The shell structure |
| int exec_else | ( | mysh_t * | mysh | ) |
The else builtin.
| mysh | The shell structure |
| int exec_else_if | ( | mysh_t * | mysh, |
| char ** | line_content ) |
The else if builtin.
| mysh | The shell structure |
| line_content | The command arguments |
| int exec_end | ( | mysh_t * | mysh | ) |
The end builtin.
| mysh | The shell structure |
| int exec_endif | ( | mysh_t * | mysh | ) |
The endif builtin.
| mysh | The shell structure |
| int exec_env | ( | mysh_t * | mysh | ) |
The env builtin.
| mysh | The shell structure |
| int exec_exit | ( | mysh_t * | mysh | ) |
The exit builtin.
| mysh | The shell structure |
| int exec_foreach | ( | mysh_t * | mysh | ) |
The foreach builtin.
| mysh | The shell structure |
| int exec_help | ( | mysh_t * | mysh | ) |
The help builtin.
| mysh | The shell structure |
| int exec_history | ( | mysh_t * | mysh | ) |
The history builtin.
| mysh | The shell structure |
| int exec_if | ( | mysh_t * | mysh | ) |
The if builtin.
| mysh | The shell structure |
| void exec_left_double_redirection | ( | mysh_t * | mysh, |
| input_command_t * | input ) |
Execute the left double redirection.
| mysh | The shell structure |
| input | The input command |
| void exec_left_simple_redirection | ( | mysh_t * | mysh, |
| input_command_t * | input ) |
Execute the left simple redirection.
| mysh | The shell structure |
| input | The input command |
| int exec_repeat | ( | mysh_t * | mysh | ) |
The source builtin.
| mysh | The shell structure |
The source builtin.
| mysh | The shell structure |
| void exec_right_redirection | ( | mysh_t * | mysh, |
| input_command_t * | input ) |
Execute the right redirection.
| mysh | The shell structure |
| input | The input command |
| int exec_set | ( | mysh_t * | mysh | ) |
The set builtin.
| mysh | The shell structure |
| int exec_setenv | ( | mysh_t * | mysh | ) |
The setenv builtin.
| mysh | The shell structure |
| int exec_source | ( | mysh_t * | mysh | ) |
The source builtin.
| mysh | The shell structure |
| int exec_unalias | ( | mysh_t * | mysh | ) |
The unalias builtin.
| mysh | The shell structure |
| int exec_unset | ( | mysh_t * | mysh | ) |
The unset builtin.
| mysh | The shell structure |
| int exec_unsetenv | ( | mysh_t * | mysh | ) |
The unsetenv builtin.
| mysh | The shell structure |
| int exec_where | ( | mysh_t * | mysh | ) |
The where builtin.
| mysh | The shell structure |
| int exec_which | ( | mysh_t * | mysh | ) |
The which builtin.
| mysh | The shell structure |
| int execute_bash_file | ( | mysh_t * | mysh, |
| int | file, | ||
| size_t | size ) |
Execute a bash file.
| mysh | The shell structure |
| file | The file descriptor |
| size | The size of the file |
| char * find_valid_str | ( | char * | str, |
| char const * | to_find ) |
Find a valid string in a string depending on inhibitors and parentheses.
| str | The string to check |
| to_find | The string to find |
| void free_input_list | ( | mysh_t * | mysh | ) |
Free the input list.
| mysh | The shell structure |
| void * free_str_and_tab | ( | char * | str, |
| char ** | tab ) |
Free an string and his array.
| str | The string to free |
| tab | The array of the string to free |
| builtin_t * get_builtin_command | ( | int | index | ) |
Get the builtin command.
| index | The index of the command |
| int get_condition | ( | char * | str | ) |
Get the condition result from a string.
| str | The string to calculate |
| char * get_env_var | ( | char ** | env, |
| char * | var ) |
Get an environment variable.
| env | The environment |
| var | The variable to get |
| input_command_t * get_input_command | ( | char * | command | ) |
Get the input command.
| command | The command |
| mysh_t * get_mysh | ( | void | ) |
Get the shell structure.
| char * get_redirection_path | ( | char * | line | ) |
Browse the command line to get the redirection path.
| line | The command line |
| char * get_variable_value | ( | mysh_t * | mysh, |
| char * | name ) |
Get the value of a variable.
| mysh | The shell structure |
| name | The name of the variable |
| char ** globbing | ( | char ** | args | ) |
Analyse if arguments are globbing.
| args | The arguments |
Analyse if arguments are globbing.
| args | The command arguments |
| mysh_t * init_shell | ( | char ** | env | ) |
Initialize the shell structure.
| env | The environment variables |
| environ | The environment variables |
| void is_git_repository | ( | void | ) |
Check if we are in a git repository and display the branch.
| int is_valid_variable | ( | char * | variable, |
| char * | builtin ) |
Check if the variable is valid.
| variable | The variable |
| builtin | The builtin who called the function |
| int missing_name | ( | mysh_t * | mysh, |
| char ** | commands ) |
Display the error message when the name is missing.
| mysh | The shell structure |
| commands | The command line |
| void move_cursor | ( | int * | pos, |
| char * | str, | ||
| char ** | str2 ) |
Move the cursor.
| stream | The stream |
| pos | The position of the cursor |
| str | The string |
| str2 | The second string |
| void my_exit | ( | mysh_t * | mysh, |
| unsigned char | status, | ||
| char const * | message ) |
Free the shell structure and exit the shell.
| mysh | The shell structure |
| status | The exit status |
| message | The message to display |
| int my_getline | ( | char ** | line, |
| FILE * | stream ) |
Get the line from the stream.
| line | The line to store the command |
| stream | The stream |
| void my_sort_alias | ( | node_t ** | begin, |
| int(* | cmp )() ) |
sort the alias list
| begin | The alias list |
| cmp | The compare function |
| void print_exit | ( | int | signal | ) |
Display "exit" when the a CRTL+D is received.
| signal | The signal |
| void print_line | ( | int | signal | ) |
Display the prompt when the SIGINT signal is received.
| signal | The signal |
| int read_file_in_stdin | ( | char * | file | ) |
Read a file and execute the commands in it.
| file | The file path |
| void remove_comments | ( | char * | line | ) |
Remove the comments from a line.
| line | The line |
| char ** replace_alias_in_line | ( | char ** | args, |
| node_t ** | alias_list ) |
Replace the alias if it already exists.
| mysh | The shell structure |
| void replace_env_var | ( | char ** | env, |
| char * | name, | ||
| char * | value ) |
Replace an environment variable.
| env | The environment |
| name | The name of the variable |
| value | The new value |
| char ** replace_history | ( | char ** | args | ) |
Replace '!' by history event.
| args | The command arguments |
| int replace_variables | ( | mysh_t * | mysh | ) |
Replace the variables in the command arguments.
| mysh | The shell structure |
| void restore_termios | ( | struct termios * | saved_termios | ) |
Restore terminal attributes.
| saved_termios | The termios structure to restore the terminal attributes |
| void save_termios | ( | struct termios * | saved_termios | ) |
Save terminal attributes.
| saved_termios | The termios structure to save the terminal attributes |
| void select_redirections | ( | mysh_t * | mysh, |
| input_command_t * | input ) |
Analyse and execute the good redirection.
| mysh | The shell structure |
| input | The input command |
| void set_command_in_history | ( | mysh_t * | mysh, |
| char * | line ) |
Set the command in the history.
| mysh | The shell structure |
| line | The line to set in the history |
| int set_new_env_var | ( | mysh_t * | mysh, |
| char * | var, | ||
| char * | value ) |
Set a new environment variable.
| mysh | The shell structure |
| var | The variable name |
| value | The variable value |
| mysh | The shell structure |
| var | The variable name |
| value | The variable value |
| void set_title | ( | void | ) |
Set the title of the shell.
| void shell | ( | char ** | env | ) |
The shell loop.
| env | The environment variables |
| environ | The environment variables |
| void status_handler | ( | int | status | ) |
Display the signal returned by executing a command.
| signal | The signal |
| char ** str_to_array_inhibitors | ( | char * | str | ) |
Transform a string into an array of words with inhibitors.
| str | The string to transform |
| void update_path_list | ( | mysh_t * | mysh | ) |
Update the path list.
| mysh | The shell structure |