Merge branch 'master' into sadjigui

This commit is contained in:
PrStein 2022-04-18 02:57:32 +02:00
commit 84eb4c9b2c
4 changed files with 14 additions and 30 deletions

View File

@ -6,35 +6,12 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/21 18:30:26 by sadjigui #+# #+# */ /* Created: 2022/03/21 18:30:26 by sadjigui #+# #+# */
/* Updated: 2022/04/15 02:44:25 by apommier ### ########.fr */ /* Updated: 2022/04/17 10:05:05 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "../../includes/minishell.h" #include "../../includes/minishell.h"
void ft_ls(char *input)
{
int i;
DIR *dir;
struct dirent *sd;
i = ft_strlen("ls");
while (input[i] && input[i] != ' ')
i++;
dir = opendir(".");
if (dir == NULL)
{
printf("stop\n");
return ;
}
while ((sd=readdir(dir)) != NULL)
{
printf(" >> %s\n", sd->d_name);
}
closedir(dir);
}
void del_one(t_s_cmd *cmd) void del_one(t_s_cmd *cmd)
{ {
int i; int i;
@ -76,6 +53,7 @@ void add_one(t_s_cmd *cmd)
i = find_it(cmd->big_cmd->env, "PWD"); i = find_it(cmd->big_cmd->env, "PWD");
str = getcwd(p, sizeof(p)); str = getcwd(p, sizeof(p));
free(cmd->big_cmd->env[i]);
cmd->big_cmd->env[i] = ft_strjoin("PWD=", p); cmd->big_cmd->env[i] = ft_strjoin("PWD=", p);
} }
@ -90,6 +68,7 @@ void change_path(t_s_cmd *cmd)
{ {
pwd = find_it(cmd->big_cmd->env, "PWD"); pwd = find_it(cmd->big_cmd->env, "PWD");
old = find_it(cmd->big_cmd->env, "OLDPWD"); old = find_it(cmd->big_cmd->env, "OLDPWD");
free(cmd->big_cmd->env[old]);
cmd->big_cmd->env[old] = ft_strjoin("OLD", cmd->big_cmd->env[pwd]); cmd->big_cmd->env[old] = ft_strjoin("OLD", cmd->big_cmd->env[pwd]);
// old = 0; // old = 0;
// while (tab[old]) // while (tab[old])

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/06 13:27:11 by apommier #+# #+# */ /* Created: 2022/03/06 13:27:11 by apommier #+# #+# */
/* Updated: 2022/04/17 02:13:41 by apommier ### ########.fr */ /* Updated: 2022/04/17 19:26:30 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,7 +26,7 @@ void sig_quit(int num)
{ {
num = 0; num = 0;
ft_putstr_fd("\b \b\b \b", 1); ft_putstr_fd("\b \b\b \b", 1);
//printf("quit num= %d\n", num); printf("quit num= %d\n", num);
//exit(0); //exit(0);
} }
@ -62,7 +62,10 @@ void print_prompt(char **path)
{ {
input = readline("\033[1;31m~$ \033[0m"); input = readline("\033[1;31m~$ \033[0m");
if (!input) if (!input)
{
free_double(path);
exit_shell(cmd, 0); exit_shell(cmd, 0);
}
add_history(input); add_history(input);
/*if (!ft_strcmp("exit", input) && input) /*if (!ft_strcmp("exit", input) && input)
{ {
@ -81,8 +84,8 @@ void print_prompt(char **path)
err_var = cmd->err_var; err_var = cmd->err_var;
path = ft_dup_double(cmd->env); path = ft_dup_double(cmd->env);
//cmd = 0;
free_cmd(cmd); free_cmd(cmd);
cmd = 0;
} }
else else
ft_putstr_fd("Minishell: error while parsing command\n", 2); ft_putstr_fd("Minishell: error while parsing command\n", 2);
@ -109,7 +112,7 @@ int main(int ac, char **av, char **path)
} }
printf("---MINISHELL START---\n"); printf("---MINISHELL START---\n");
signal(SIGINT, crtl_c); signal(SIGINT, crtl_c);
signal(SIGQUIT, sig_quit);
print_prompt(env); print_prompt(env);
return (0); return (0);
} }

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/09 12:33:30 by apommier #+# #+# */ /* Created: 2022/03/09 12:33:30 by apommier #+# #+# */
/* Updated: 2022/04/17 02:11:56 by apommier ### ########.fr */ /* Updated: 2022/04/17 11:05:04 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,6 +19,8 @@ void exit_shell(t_cmd *cmd, int ret)
i = 0; i = 0;
//if (cmd) //if (cmd)
// free_double(cmd->env); // free_double(cmd->env);
if (!cmd)
exit(ret);
if (cmd->tmpin != -1) if (cmd->tmpin != -1)
{ {
dup2(cmd->tmpin, 0); dup2(cmd->tmpin, 0);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/09 15:18:58 by apommier #+# #+# */ /* Created: 2022/03/09 15:18:58 by apommier #+# #+# */
/* Updated: 2022/04/16 11:03:41 by apommier ### ########.fr */ /* Updated: 2022/04/17 10:25:03 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */