-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix norm errors * Fix memory leaks * Fix crash when there's no limiter for heredoc
- Loading branch information
1 parent
d8d1bbf
commit 5f8d7c1
Showing
36 changed files
with
749 additions
and
884 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* messages.h :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: sehosaf <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/07/17 10:21:05 by sehosaf #+# #+# */ | ||
/* Updated: 2024/07/18 21:05:21 by sehosaf ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef MESSAGES_H | ||
# define MESSAGES_H | ||
|
||
# define PROMPT "\033[0;36mminishell\033[0m \033[0;32m> \033[0m" | ||
|
||
// ** Error messages ** | ||
# define ERR_GENERIC "\033[0;31mError: \033[0m" | ||
# define ERR_MALLOC "minishell: malloc failed" | ||
# define ERR_PERM "Permission denied" | ||
|
||
// ** Syntax error messages ** | ||
# define ERR_SNX_TOKEN "minishell: syntax error near unexpected token `" | ||
# define ERR_SNX_EOF "minishell: syntax error: unexpected end of file " | ||
|
||
// ** Built-in commands messages ** | ||
# define ERR_NO_HOME "minishell: cd: HOME not set " | ||
# define ERR_NO_CD "minishell: cd: can't cd to " | ||
# define ERR_RET_CWD "minishell: cd: error retrieving current directory " | ||
# define ERR_MANY_ARGS "minishell: exit: too many arguments " | ||
# define ERR_PWD "minishell: pwd: error " | ||
|
||
// ** Execution messages ** | ||
# define ERR_IS_DIR "minishell: is a directory: " | ||
# define ERR_FORK "minishell: fork failed " | ||
# define ERR_EXEC "minishell: execve failed " | ||
# define ERR_ENV "minishell: environment list is empty " | ||
# define ERR_INPUT_FILE "minishell: input file error: " | ||
# define ERR_OUTPUT_FILE "minishell: output file error: " | ||
# define ERR_PIPE "minishell: pipe error: " | ||
|
||
// ** Signals messages ** | ||
# define ERR_SIGINT "minishell: sigaction: SIGINT " | ||
# define ERR_SIGQUIT "minishell: sigaction: SIGQUIT " | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: dmoroz <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/06/11 20:37:44 by sehosaf #+# #+# */ | ||
/* Updated: 2024/07/10 15:51:34 by dmoroz ### ########.fr */ | ||
/* Updated: 2024/07/17 14:23:21 by sehosaf ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -29,6 +29,7 @@ | |
# include <stdbool.h> | ||
# include <limits.h> | ||
# include "libft.h" | ||
# include "messages.h" | ||
|
||
/* | ||
t_command struct represent command which has to be executed | ||
|
@@ -59,12 +60,12 @@ typedef enum e_connection | |
typedef struct s_command | ||
{ | ||
char **args; | ||
t_connection connection_type; | ||
t_connection conn_type; | ||
int is_heredoc; | ||
char *limiter; | ||
char *infile; | ||
char *outfile; | ||
int outfile_append_mode; | ||
int ap_mode; | ||
} t_command; | ||
|
||
typedef struct s_pipeline | ||
|
@@ -106,6 +107,4 @@ void free_pipeline(t_pipeline *p); | |
void interactive_signal_handlers(void); | ||
void non_interactive_signal_handlers(void); | ||
|
||
# define PROMPT "\033[0;36mminishell\033[0m \033[0;32m> \033[0m" | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* parser.h :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: sehosaf <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/07/17 09:26:08 by sehosaf #+# #+# */ | ||
/* Updated: 2024/07/18 17:19:48 by sehosaf ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef PARSER_H | ||
# define PARSER_H | ||
|
||
|
@@ -7,9 +19,11 @@ | |
char **split_line(char *line); | ||
void split_tokens_per_command(t_pipeline *start, char **tokens); | ||
t_pipeline *create_default_pipeline_node(void); | ||
void set_redirections(t_pipeline *node); | ||
int set_redirections(t_pipeline *node); | ||
void remove_cmd_arg(t_pipeline *node, int ind); | ||
void replace_vars(t_pipeline *node, t_shell *shell); | ||
void replace_wildcards(t_pipeline *node); | ||
char *get_var_name(char *dollar); | ||
char *get_var_value(const char *name, t_shell *shell); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: sehosaf <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/02/26 18:53:52 by dmoroz #+# #+# */ | ||
/* Updated: 2024/06/12 10:32:48 by sehosaf ### ########.fr */ | ||
/* Updated: 2024/07/17 20:42:46 by sehosaf ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -42,8 +42,8 @@ size_t ft_strlcat(char *dst, const char *src, size_t size); | |
char *ft_strchr(const char *s, int c); | ||
char *ft_strrchr(const char *s, int c); | ||
char *ft_strnstr(const char *str, const char *sub, size_t len); | ||
int ft_strcmp(const char *s1, const char *s2); | ||
int ft_strncmp(const char *s1, const char *s2, size_t n); | ||
int ft_strcmp(const char *s1, const char *s2); | ||
int ft_strncmp(const char *s1, const char *s2, size_t n); | ||
int ft_atoi(const char *str); | ||
size_t ft_strlcpy(char *dst, const char *src, size_t size); | ||
char *ft_substr(char const *s, unsigned int start, size_t len); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: sehosaf <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/06/10 20:37:41 by sehosaf #+# #+# */ | ||
/* Updated: 2024/06/19 21:03:35 by sehosaf ### ########.fr */ | ||
/* Updated: 2024/07/17 11:30:10 by sehosaf ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -31,7 +31,7 @@ int cmd_cd(t_shell *shell, char **args) | |
change_to = get_env_val(shell->env, "HOME"); | ||
if (change_to == NULL) | ||
{ | ||
ft_putendl_fd("minishell: cd: HOME not set", 2); | ||
ft_putendl_fd(ERR_NO_HOME, 2); | ||
return (EXIT_FAILURE); | ||
} | ||
} | ||
|
@@ -43,7 +43,7 @@ int cmd_cd(t_shell *shell, char **args) | |
old_pwd = getcwd(NULL, 0); | ||
if (chdir(change_to) != 0) | ||
{ | ||
ft_putstr_fd("minishell: cd: can't cd to ", 2); | ||
ft_putstr_fd(ERR_NO_CD, 2); | ||
ft_putendl_fd(change_to, 2); | ||
return (free(old_pwd), EXIT_FAILURE); | ||
} | ||
|
@@ -52,7 +52,7 @@ int cmd_cd(t_shell *shell, char **args) | |
|
||
static bool is_home_keyword(const char *arg) | ||
{ | ||
if (arg[0] == '~' && (arg[1] == '\0')) | ||
if (arg[0] == '~' && arg[1] == '\0') | ||
return (true); | ||
else if (ft_strcmp(arg, "--") == 0) | ||
return (true); | ||
|
@@ -70,7 +70,7 @@ static int update_pwd_env(t_shell *shell, char *old_pwd) | |
new_pwd = getcwd(NULL, 0); | ||
if (new_pwd == NULL) | ||
{ | ||
ft_putendl_fd("minishell: cd: error retrieving current directory", 2); | ||
ft_putendl_fd(ERR_RET_CWD, 2); | ||
return (free(old_pwd), EXIT_FAILURE); | ||
} | ||
if (set_env_var(shell->env, "OLDPWD", old_pwd) == EXIT_FAILURE) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: sehosaf <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/06/09 19:04:21 by sehosaf #+# #+# */ | ||
/* Updated: 2024/06/24 21:06:54 by sehosaf ### ########.fr */ | ||
/* Updated: 2024/07/17 11:32:13 by sehosaf ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -24,11 +24,11 @@ int cmd_exit(t_shell *shell, char **args, t_connection ct) | |
shell->exit_status = EXIT_SUCCESS; | ||
else if (args[2]) | ||
{ | ||
ft_putendl_fd("minishell: exit: too many arguments", STDERR_FILENO); | ||
ft_putendl_fd(ERR_MANY_ARGS, STDERR_FILENO); | ||
return (EXIT_FAILURE); | ||
} | ||
if (is_number(args[1])) | ||
shell->exit_status = ft_atol(args[1]); | ||
shell->exit_status = (signed int)ft_atol(args[1]); | ||
else if (args[1] && !is_number(args[1])) | ||
{ | ||
ft_putstr_fd("minishell: exit: ", STDERR_FILENO); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: sehosaf <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/06/02 14:08:08 by sehosaf #+# #+# */ | ||
/* Updated: 2024/06/19 20:53:20 by sehosaf ### ########.fr */ | ||
/* Updated: 2024/07/17 11:33:39 by sehosaf ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -22,7 +22,7 @@ int cmd_pwd(void) | |
|
||
if (getcwd(cwd, PATH_MAX) == NULL) | ||
{ | ||
ft_putendl_fd("minishell: pwd: error", STDERR_FILENO); | ||
ft_putendl_fd(ERR_PWD, STDERR_FILENO); | ||
return (EXIT_FAILURE); | ||
} | ||
return (ft_putendl_fd(cwd, STDOUT_FILENO), EXIT_SUCCESS); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: sehosaf <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/06/04 12:42:49 by sehosaf #+# #+# */ | ||
/* Updated: 2024/06/19 21:14:07 by sehosaf ### ########.fr */ | ||
/* Updated: 2024/07/17 11:35:00 by sehosaf ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -57,7 +57,7 @@ char **split_key_value(const char *str, char c) | |
|
||
result = (char **)malloc(sizeof(char *) * 3); | ||
if (!result) | ||
return (perror("malloc"), NULL); | ||
return (perror(ERR_MALLOC), NULL); | ||
index = ft_strchr(str, c); | ||
if (index) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: sehosaf <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/06/17 21:04:06 by sehosaf #+# #+# */ | ||
/* Updated: 2024/06/24 21:46:51 by sehosaf ### ########.fr */ | ||
/* Updated: 2024/07/17 12:32:00 by sehosaf ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -39,7 +39,7 @@ void execute(t_pipeline *pipeline, t_shell *shell) | |
while (cur != NULL) | ||
{ | ||
if (!async | ||
&& !should_execute(cur->cmd.connection_type, shell->exit_status)) | ||
&& !should_execute(cur->cmd.conn_type, shell->exit_status)) | ||
break ; | ||
cmds[i] = find_type(shell, pipeline, cur); | ||
if (!async) | ||
|
@@ -77,13 +77,13 @@ static pid_t absolute_path(t_shell *shell, t_pipeline *p, t_pipeline *cur) | |
|
||
if (stat(cur->cmd.args[0], &st) == -1) | ||
{ | ||
perror("minishell: "); | ||
perror(ERR_GENERIC); | ||
shell->exit_status = 127; | ||
return (EXIT_FAILURE); | ||
} | ||
if (S_ISDIR(st.st_mode)) | ||
{ | ||
ft_putendl_fd("minishell: is a directory", 2); | ||
ft_putendl_fd(ERR_IS_DIR, 2); | ||
shell->exit_status = 126; | ||
return (EXIT_FAILURE); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.