mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 03:16:51 +01:00
「🔨」 fix: fixed being treated as a folder, and some exit codes
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/26 08:42:36 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/07/19 11:34:03 by mmoussou ### ########.fr */
|
||||
/* Updated: 2024/08/14 07:51:17 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/11 18:59:27 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/07/19 11:33:57 by mmoussou ### ########.fr */
|
||||
/* Updated: 2024/08/14 07:50:39 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -81,27 +81,28 @@ void add_to_env(char *name, char *content, t_env *env)
|
||||
ft_envadd_back(&env, ft_envnew(name, content));
|
||||
}
|
||||
|
||||
int check_export_input(char *input)
|
||||
int check_export_input(char *s)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if ((!ft_isalpha(input[i]) && input[i] != '_') || input[i] == '=')
|
||||
if ((!ft_isalpha(s[i]) && s[i] != '_') || s[i] == '=')
|
||||
{
|
||||
printf("minishell: export: '%s': not a valid identifier\n", input);
|
||||
ft_printf_fd(2, "minishell: export: '%s': not a valid identifier\n", s);
|
||||
return (get_exit_code(1));
|
||||
}
|
||||
i++;
|
||||
while (input[i] && input[i] != '=')
|
||||
while (s[i] && s[i] != '=')
|
||||
{
|
||||
if (!ft_isalnum(input[i]) && input[i] != '_')
|
||||
if (!ft_isalnum(s[i]) && s[i] != '_')
|
||||
{
|
||||
if (input[i] == '+' && input[i + 1] == '=')
|
||||
if (s[i] == '+' && s[i + 1] == '=')
|
||||
{
|
||||
i++;
|
||||
continue ;
|
||||
}
|
||||
printf("minishell: export: '%s': not a valid identifier\n", input);
|
||||
ft_printf_fd(2,
|
||||
"minishell: export: '%s': not a valid identifier\n", s);
|
||||
return (get_exit_code(1));
|
||||
}
|
||||
i++;
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/15 21:03:31 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/08/13 18:39:22 by mmoussou ### ########.fr */
|
||||
/* Updated: 2024/08/14 07:52:36 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -28,7 +28,7 @@ void exec_cmd(t_cmd *cmd, char **env, t_env *env_t)
|
||||
if (i == 6)
|
||||
ft_pwd();
|
||||
if (i == 4)
|
||||
ft_export(cmd->argv + 1, env_t, cmd->outfile);
|
||||
ft_export(cmd->argv + 1, env_t, STDOUT_FILENO);
|
||||
if (i == 3)
|
||||
ft_unset(&(cmd->argv)[1], env_t);
|
||||
if (i == 7)
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/01 14:55:06 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/08/13 19:16:03 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/08/14 07:45:57 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -31,10 +31,12 @@ int exec_fork_cmd(t_cmd *cmd, char **env, t_env *env_t, int pipe_fd[2])
|
||||
exec.status = switch_cmd_path(cmd, env_t);
|
||||
if (exec.status == -1 || !input || check_file(cmd->cmd, input))
|
||||
{
|
||||
if (exec.status == -1)
|
||||
get_exit_code(127);
|
||||
if (exec.status == -1)
|
||||
printf("minishell : command not found: %s\n", input);
|
||||
free(input);
|
||||
return (get_exit_code(127));
|
||||
return (-1);
|
||||
}
|
||||
free(input);
|
||||
fork_pid = fork();
|
||||
@ -64,10 +66,12 @@ int exec_single_cmd(t_cmd *cmd, char **env, t_env *env_t, int pipe_fd[2])
|
||||
exec.status = switch_cmd_path(cmd, env_t);
|
||||
if (exec.status == -1 || !input || check_file(cmd->cmd, input))
|
||||
{
|
||||
if (exec.status == -1)
|
||||
get_exit_code(127);
|
||||
if (exec.status == -1)
|
||||
printf("minishell : command not found: %s\n", input);
|
||||
free(input);
|
||||
return (get_exit_code(127));
|
||||
return (-1);
|
||||
}
|
||||
free(input);
|
||||
exec.status = exec_single_cmd_execution(cmd, env, env_t, exec);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/09 19:25:18 by adjoly #+# #+# */
|
||||
/* Updated: 2024/07/17 16:13:29 by mmoussou ### ########.fr */
|
||||
/* Updated: 2024/08/14 08:07:55 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -77,7 +77,7 @@ int switch_cmd_path(t_cmd *cmd, t_env *env)
|
||||
{
|
||||
char *path;
|
||||
|
||||
if (is_in_builtins(cmd->cmd))
|
||||
if (is_in_builtins(cmd->cmd) || !cmd->cmd || !cmd->cmd[0])
|
||||
return (0);
|
||||
if (cmd->cmd[0] == '.' && cmd->cmd[1] == '/')
|
||||
cmd->cmd = get_cmd_local_path(cmd->cmd, env);
|
||||
@ -100,16 +100,23 @@ int check_file(char *cmd, char *input)
|
||||
if (is_in_builtins(cmd))
|
||||
return (0);
|
||||
status = stat(cmd, &entry);
|
||||
if (status)
|
||||
if (status || !cmd || !*cmd)
|
||||
{
|
||||
get_exit_code(127);
|
||||
printf("minishell : command not found: %s\n", input);
|
||||
return (1);
|
||||
}
|
||||
if (!S_ISDIR(entry.st_mode) && !access(cmd, X_OK))
|
||||
return (0);
|
||||
if (S_ISDIR(entry.st_mode))
|
||||
{
|
||||
get_exit_code(126);
|
||||
printf("minishell : %s is a directory.\n", input);
|
||||
}
|
||||
else
|
||||
{
|
||||
get_exit_code(127);
|
||||
printf("minishell : command not found: %s\n", input);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user