maxishell
Implementation of a shell for Linux-like systems
|
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
#include <limits.h>
#include <unistd.h>
#include <stdarg.h>
#include <signal.h>
#include <stdbool.h>
#include <math.h>
Go to the source code of this file.
Macros | |
#define | BUFFER_SIZE 32 |
#define | TRUE 1 |
#define | FALSE 0 |
#define | STDIN 0 |
#define | STDOUT 1 |
#define | STDERR 2 |
#define | RESET "\033[0m" |
#define | BLK "\033[0;30m" |
#define | RED "\033[0;31m" |
#define | GRN "\033[0;32m" |
#define | YEL "\033[0;33m" |
#define | BLU "\033[0;34m" |
#define | MAG "\033[0;35m" |
#define | CYA "\033[0;36m" |
#define | WHI "\033[0;37m" |
#define | B_BLK "\033[1;30m" |
#define | B_RED "\033[1;31m" |
#define | B_GRN "\033[1;32m" |
#define | B_YEL "\033[1;33m" |
#define | B_BLU "\033[1;34m" |
#define | B_MAG "\033[1;35m" |
#define | B_CYA "\033[1;36m" |
#define | B_WHI "\033[1;37m" |
Functions | |
int | ft_abs (int n) |
int | ft_isalpha (int c) |
int | ft_isdigit (int c) |
int | ft_isalnum (int c) |
int | ft_isascii (int c) |
int | ft_isprint (int c) |
int | ft_toupper (int c) |
int | ft_tolower (int c) |
int | ft_print_int (int n) |
int | ft_print_char (int c) |
int | ft_print_percent (void) |
int | ft_print_str (char *str) |
int | list_len_char (char a[]) |
int | list_len_str (char *a[]) |
int | ft_atoi (const char *str) |
int | ft_is_num (const char *n) |
int | ft_ptr_len (uintptr_t num) |
int | ft_len_2d_arr (char **array) |
int | ft_is_double (const char *n) |
int | isnum_from_str (const char *str) |
int | ft_printf (const char *format,...) |
int | find_max_in_list (int a[], int size) |
int | ft_print_ptr (unsigned long long ptr) |
int | ft_print_unsigned_dec (unsigned int n) |
int | list_repeat_check_int (int a[], int size) |
int | ft_count_bits (unsigned char current_char) |
int | ft_strcmp (const char *s1, const char *s2) |
int | list_repeat_check_str (char *a[], int size) |
int | ft_strncmp (const char *s1, const char *s2, size_t n) |
int | ft_memcmp (const void *s1, const void *s2, size_t n) |
int | ft_print_unsigned_hex (unsigned int num, const char format) |
char * | ft_itoa (int n) |
char * | ft_strdup (const char *s) |
char * | ft_get_next_line (int fd) |
char * | ft_strchr (const char *s, int c) |
char * | ft_strcat (char *dest, char *src) |
char * | ft_strrchr (const char *s, int c) |
char ** | ft_split (char const *s, char c) |
char * | ft_strndup (const char *s, size_t n) |
char * | ft_strjoin_free (char *s1, char *s2) |
char * | ft_strcpy (char *dest, const char *src) |
char * | ft_strjoin (char const *s1, char const *s2) |
char * | ft_strtrim (char const *s1, char const *set) |
char * | ft_remove_quotes (char *str, char quote_type) |
char * | ft_strstr (const char *big, const char *little) |
char * | ft_strcat_const (const char *dest, const char *src) |
char * | ft_strmapi (char const *s, char(*f)(unsigned int, char)) |
char * | ft_substr (char const *s, unsigned int start, size_t len) |
char ** | ft_realloc_array (char **array, int old_size, int new_size) |
char * | ft_strnstr (const char *haystack, const char *needle, size_t len) |
void | ft_put_ptr (uintptr_t num) |
void | ft_free_2d_arr (char **arr) |
void | ft_bzero (void *s, size_t n) |
void | ft_putnbr_fd (int n, int fd) |
void | ft_putchar_fd (char c, int fd) |
void | ft_putstr_fd (char *s, int fd) |
void | ft_putendl_fd (char *s, int fd) |
void * | ft_memset (void *s, int c, size_t n) |
void * | ft_calloc (size_t count, size_t size) |
void | ft_print_2d_arr (char **arr, char *name) |
void * | ft_memchr (const void *s, int c, size_t n) |
void * | ft_memcpy (void *dest, const void *src, size_t n) |
void * | ft_memmove (void *dest, const void *src, size_t n) |
void | ft_striteri (char *s, void(*f)(unsigned int, char *)) |
size_t | ft_strlen (const char *s) |
size_t | ft_strlcpy (char *dest, const char *src, size_t size) |
size_t | ft_strlcat (char *dest, const char *src, size_t size) |
double | ft_atof (const char *str) |
long | ft_atol (const char *nptr) |
const char * | ft_exclude_delimiters (const char *str, char *delims) |
int find_max_in_list | ( | int | a[], |
int | size | ||
) |
Definition at line 15 of file find_max_in_list.c.
int ft_abs | ( | int | n | ) |
double ft_atof | ( | const char * | str | ) |
Definition at line 15 of file ft_atof.c.
int ft_atoi | ( | const char * | str | ) |
long ft_atol | ( | const char * | nptr | ) |
Definition at line 15 of file ft_atol.c.
void ft_bzero | ( | void * | s, |
size_t | n | ||
) |
Definition at line 21 of file ft_bzero.c.
void * ft_calloc | ( | size_t | count, |
size_t | size | ||
) |
Definition at line 23 of file ft_calloc.c.
References ft_memset().
int ft_count_bits | ( | unsigned char | current_char | ) |
Definition at line 13 of file ft_count_bits.c.
const char * ft_exclude_delimiters | ( | const char * | str, |
char * | delims | ||
) |
Definition at line 15 of file ft_exclude_delimiters.c.
References ft_strchr().
Referenced by valid_operator().
void ft_free_2d_arr | ( | char ** | arr | ) |
Definition at line 15 of file ft_free_2d_arr.c.
char * ft_get_next_line | ( | int | fd | ) |
int ft_is_double | ( | const char * | n | ) |
Definition at line 15 of file ft_is_double.c.
References FALSE, ft_isdigit(), and TRUE.
int ft_is_num | ( | const char * | n | ) |
Definition at line 15 of file ft_is_num.c.
References FALSE, ft_isdigit(), and TRUE.
int ft_isalnum | ( | int | c | ) |
Definition at line 15 of file ft_isalnum.c.
References ft_isalpha(), and ft_isdigit().
Referenced by ev_loop(), and handle_local_vars().
int ft_isalpha | ( | int | c | ) |
Definition at line 13 of file ft_isalpha.c.
Referenced by ft_isalnum().
int ft_isascii | ( | int | c | ) |
Definition at line 13 of file ft_isascii.c.
int ft_isdigit | ( | int | c | ) |
Definition at line 13 of file ft_isdigit.c.
Referenced by ft_is_double(), ft_is_num(), ft_isalnum(), ft_isnumber(), tmp_adj(), and token_adj().
int ft_isprint | ( | int | c | ) |
Definition at line 13 of file ft_isprint.c.
char * ft_itoa | ( | int | n | ) |
Definition at line 40 of file ft_itoa.c.
References count_digits(), and ft_strdup().
Referenced by builtin_env(), ft_print_int(), set_shell_var_handler(), and shell_variable_update().
int ft_len_2d_arr | ( | char ** | array | ) |
Definition at line 15 of file ft_len_2d_arr.c.
Referenced by split_loc_vars().
void * ft_memchr | ( | const void * | s, |
int | c, | ||
size_t | n | ||
) |
Definition at line 29 of file ft_memchr.c.
int ft_memcmp | ( | const void * | s1, |
const void * | s2, | ||
size_t | n | ||
) |
Definition at line 23 of file ft_memcmp.c.
void * ft_memcpy | ( | void * | dest, |
const void * | src, | ||
size_t | n | ||
) |
Definition at line 22 of file ft_memcpy.c.
Referenced by ft_memmove(), and strndup().
void * ft_memmove | ( | void * | dest, |
const void * | src, | ||
size_t | n | ||
) |
Definition at line 24 of file ft_memmove.c.
References ft_memcpy().
void * ft_memset | ( | void * | s, |
int | c, | ||
size_t | n | ||
) |
Definition at line 28 of file ft_memset.c.
Referenced by ft_calloc(), and signal_handler().
void ft_print_2d_arr | ( | char ** | arr, |
char * | name | ||
) |
Definition at line 15 of file ft_print_2d_arr.c.
References ft_printf(), ft_strlen(), GRN, and RESET.
Referenced by final_quote_removal().
int ft_print_char | ( | int | c | ) |
Definition at line 15 of file ft_print_char.c.
References ft_putchar_fd().
Referenced by ft_formatssssss(), and ft_printf().
int ft_print_int | ( | int | n | ) |
Definition at line 15 of file ft_print_int.c.
References ft_itoa(), and ft_print_str().
Referenced by ft_formatssssss().
int ft_print_percent | ( | void | ) |
Definition at line 15 of file ft_print_percent.c.
References ft_putchar_fd().
Referenced by ft_formatssssss().
int ft_print_ptr | ( | unsigned long long | ptr | ) |
Definition at line 44 of file ft_print_ptr.c.
References ft_ptr_len(), and ft_put_ptr().
Referenced by ft_formatssssss().
int ft_print_str | ( | char * | str | ) |
Definition at line 15 of file ft_print_str.c.
References ft_putchar_fd(), and ft_putstr_fd().
Referenced by ft_formatssssss(), ft_print_int(), and ft_print_unsigned_dec().
int ft_print_unsigned_dec | ( | unsigned int | n | ) |
Definition at line 47 of file ft_print_unsigned_dec.c.
References ft_print_str(), and ft_uitoa().
Referenced by ft_formatssssss().
int ft_print_unsigned_hex | ( | unsigned int | num, |
const char | format | ||
) |
Definition at line 49 of file ft_print_unsigned_hex.c.
References ft_hex_len(), ft_put_hex(), and ft_putchar_fd().
Referenced by ft_formatssssss().
int ft_printf | ( | const char * | format, |
... | |||
) |
Definition at line 37 of file ft_printf.c.
References ft_formatssssss(), and ft_print_char().
Referenced by append_word_if_valid(), env_tests(), ft_print_2d_arr(), initialise(), input_error_checks(), main(), new_process(), pipe_tests(), print_ast_args(), print_ast_node(), print_env(), print_env_stack(), print_maxishell(), print_stack(), print_t_env(), print_tokens(), test_get_env(), test_init_env(), test_set_env(), and test_unset_env().
int ft_ptr_len | ( | uintptr_t | num | ) |
Definition at line 15 of file ft_print_ptr.c.
Referenced by ft_print_ptr().
void ft_put_ptr | ( | uintptr_t | num | ) |
Definition at line 28 of file ft_print_ptr.c.
References ft_put_ptr(), and ft_putchar_fd().
Referenced by ft_print_ptr(), and ft_put_ptr().
void ft_putchar_fd | ( | char | c, |
int | fd | ||
) |
Definition at line 20 of file ft_putchar_fd.c.
Referenced by builtin_echo(), ft_print_char(), ft_print_percent(), ft_print_str(), ft_print_unsigned_hex(), ft_put_hex(), ft_put_ptr(), ft_putendl_fd(), and ft_putnbr_fd().
void ft_putendl_fd | ( | char * | s, |
int | fd | ||
) |
Definition at line 21 of file ft_putendl_fd.c.
References ft_putchar_fd(), and ft_putstr_fd().
Referenced by builtin_exit(), builtin_export(), builtin_pwd(), ft_puterror(), and handle_exit().
void ft_putnbr_fd | ( | int | n, |
int | fd | ||
) |
Definition at line 20 of file ft_putnbr_fd.c.
References ft_putchar_fd(), ft_putnbr_fd(), and ft_putstr_fd().
Referenced by ft_putnbr_fd().
void ft_putstr_fd | ( | char * | s, |
int | fd | ||
) |
Definition at line 20 of file ft_putstr_fd.c.
References ft_strlen().
Referenced by builtin_echo(), builtin_env(), ft_print_str(), ft_putendl_fd(), ft_puterror(), ft_putnbr_fd(), handle_exec_errors(), and handle_get_shell_variable().
char ** ft_realloc_array | ( | char ** | array, |
int | old_size, | ||
int | new_size | ||
) |
Definition at line 15 of file ft_realloc_array.c.
Referenced by handle_split_allocation().
char * ft_remove_quotes | ( | char * | str, |
char | quote_type | ||
) |
Definition at line 15 of file ft_remove_quotes.c.
References ft_strdup(), ft_strlen(), and ft_strndup().
Referenced by handle_add_set_shell_variable(), and post_process_command_args().
char ** ft_split | ( | char const * | s, |
char | c | ||
) |
Definition at line 95 of file ft_split.c.
References count_words(), and split_into_words().
Referenced by builtin_pipe_test(), ft_find_path(), main_loop(), and process_and_reassemble().
char * ft_strcat | ( | char * | dest, |
char * | src | ||
) |
Definition at line 26 of file ft_strcat.c.
Referenced by assemble_result(), generate_prompt(), and token_adj().
char * ft_strcat_const | ( | const char * | dest, |
const char * | src | ||
) |
Definition at line 15 of file ft_strcat_const.c.
References ft_strlen().
Referenced by check_operators().
char * ft_strchr | ( | const char * | s, |
int | c | ||
) |
Definition at line 25 of file ft_strchr.c.
Referenced by add_env(), add_env_node(), add_shell_var_node(), ft_exclude_delimiters(), handle_add_set_shell_variable(), handle_local_vars(), handle_phrase(), and tokenise().
int ft_strcmp | ( | const char * | s1, |
const char * | s2 | ||
) |
Definition at line 24 of file ft_strcmp.c.
Referenced by builtin_echo(), builtin_env(), builtin_export(), execute(), exit_status_adj(), expand_env_and_loc_var(), get_env(), get_shell_variable(), open_file(), open_tmp_file(), print_env(), set_env(), set_shell_var(), str_start_adj(), test_get_env(), test_set_env(), test_unset_env(), unset_env(), and write_heredoc_lines().
char * ft_strcpy | ( | char * | dest, |
const char * | src | ||
) |
Definition at line 25 of file ft_strcpy.c.
Referenced by generate_prompt(), and token_adj().
char * ft_strdup | ( | const char * | s | ) |
Definition at line 23 of file ft_strdup.c.
References ft_strlcpy(), and ft_strlen().
Referenced by add_env_node(), add_new_env(), add_shell_var_node(), append_expanded_var(), child_process(), create_pipe_node(), create_redir_node(), expand_env_and_loc_var(), expand_variable(), finalize_token(), ft_find_path(), ft_itoa(), ft_remove_all_edge_quotes(), ft_remove_quotes(), get_env_variable(), get_exit_status(), list_to_array(), new_token(), process_argument(), redirect_here_doc(), set_command_args(), set_env(), set_shell_var(), split_loc_vars(), tmp_adj(), and token_adj().
void ft_striteri | ( | char * | s, |
void(*)(unsigned int, char *) | f | ||
) |
Definition at line 28 of file ft_striteri.c.
char * ft_strjoin | ( | char const * | s1, |
char const * | s2 | ||
) |
Definition at line 23 of file ft_strjoin.c.
References ft_strlen().
Referenced by append_literal(), builtin_cd(), builtin_export(), env_to_array(), ft_strjoin_free(), generate_prompt_string(), handle_numeric_error(), and relative_path_handle().
char * ft_strjoin_free | ( | char * | s1, |
char * | s2 | ||
) |
Definition at line 15 of file ft_strjoin_free.c.
References ft_strjoin().
Referenced by append_expanded_var(), ev_loop(), and expand_variable().
size_t ft_strlcat | ( | char * | dest, |
const char * | src, | ||
size_t | size | ||
) |
Definition at line 26 of file ft_strlcat.c.
References ft_strlen().
size_t ft_strlcpy | ( | char * | dest, |
const char * | src, | ||
size_t | size | ||
) |
Definition at line 25 of file ft_strlcpy.c.
Referenced by ft_strdup(), and ft_strndup().
size_t ft_strlen | ( | const char * | s | ) |
Definition at line 15 of file ft_strlen.c.
Referenced by final_quote_removal(), ft_print_2d_arr(), ft_putstr_fd(), ft_remove_all_edge_quotes(), ft_remove_quotes(), ft_strcat_const(), ft_strdup(), ft_strjoin(), ft_strlcat(), ft_strndup(), ft_strnstr(), ft_strstr(), ft_strtrim(), ft_substr(), generate_prompt(), generate_prompt_string(), handle_trailing_quote(), post_process_command_args(), print_tokens(), process_single_token(), token_adj(), and write_heredoc_lines().
char * ft_strmapi | ( | char const * | s, |
char(*)(unsigned int, char) | f | ||
) |
Definition at line 28 of file ft_strmapi.c.
int ft_strncmp | ( | const char * | s1, |
const char * | s2, | ||
size_t | n | ||
) |
Definition at line 24 of file ft_strncmp.c.
Referenced by child_process(), ft_find_path(), ft_strnstr(), ft_strstr(), generate_prompt_string(), list_repeat_check_str(), and main_loop().
char * ft_strndup | ( | const char * | s, |
size_t | n | ||
) |
Definition at line 23 of file ft_strndup.c.
References ft_strlcpy(), and ft_strlen().
Referenced by add_env_node(), append_word_if_valid(), final_quote_removal(), ft_add_segment(), ft_remove_all_edge_quotes(), and ft_remove_quotes().
char * ft_strnstr | ( | const char * | haystack, |
const char * | needle, | ||
size_t | len | ||
) |
Definition at line 25 of file ft_strnstr.c.
References ft_strlen(), and ft_strncmp().
char * ft_strrchr | ( | const char * | s, |
int | c | ||
) |
Definition at line 24 of file ft_strrchr.c.
char * ft_strstr | ( | const char * | big, |
const char * | little | ||
) |
Definition at line 24 of file ft_strstr.c.
References ft_strlen(), and ft_strncmp().
char * ft_strtrim | ( | char const * | s1, |
char const * | set | ||
) |
Definition at line 39 of file ft_strtrim.c.
References ft_char_in_set(), and ft_strlen().
Referenced by trim_input().
char * ft_substr | ( | char const * | s, |
unsigned int | start, | ||
size_t | len | ||
) |
Definition at line 27 of file ft_substr.c.
References ft_strlen().
Referenced by append_literal(), ev_loop(), expand_variable(), and post_process_command_args().
int ft_tolower | ( | int | c | ) |
Definition at line 15 of file ft_tolower.c.
int ft_toupper | ( | int | c | ) |
Definition at line 15 of file ft_toupper.c.
int isnum_from_str | ( | const char * | str | ) |
Definition at line 15 of file isnum_from_str.c.
int list_len_char | ( | char | a[] | ) |
Definition at line 13 of file list_len_char.c.
int list_len_str | ( | char * | a[] | ) |
Definition at line 15 of file list_len_str.c.
int list_repeat_check_int | ( | int | a[], |
int | size | ||
) |
Definition at line 15 of file list_repeat_check_int.c.
int list_repeat_check_str | ( | char * | a[], |
int | size | ||
) |
Definition at line 15 of file list_repeat_check_str.c.
References ft_strncmp().