🔨」 fix: Fixed prompt and env

This commit is contained in:
2024-07-09 16:24:25 +02:00
parent 947ccc16e7
commit 3857261476
4 changed files with 33 additions and 21 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/19 13:48:05 by adjoly #+# #+# */ /* Created: 2024/05/19 13:48:05 by adjoly #+# #+# */
/* Updated: 2024/05/27 18:59:56 by adjoly ### ########.fr */ /* Updated: 2024/07/09 14:35:40 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -29,13 +29,13 @@ char *get_hostname(void);
* *
* @return (char *) the pwd * @return (char *) the pwd
*/ */
char *get_pwd(t_env env); char *get_pwd(t_env *env);
/** /**
* @brief return the full prompt * @brief return the full prompt
* *
* @prompt (char *) the prompt * @prompt (char *) the prompt
*/ */
char *get_prompt(t_env env); char *get_prompt(t_env *env);
#endif #endif

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */ /* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */ /* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
/* Updated: 2024/07/09 14:40:50 by mmoussou ### ########.fr */ /* Updated: 2024/07/09 16:08:08 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -34,17 +34,19 @@ bool run_checks(char *rl)
return (false); return (false);
} }
/*int main(int ac, char **av, char **env) int main(int ac, char **av, char **env)
{ {
char *rl; char *rl;
char *prompt; char *prompt;
t_env env_l; t_env *env_l;
t_list *cmd_list; t_list *cmd_list;
t_list *piped; t_list *piped;
(void)ac; (void)ac;
rl = NULL;
get_program_name(av[0]); get_program_name(av[0]);
if (env_init(env, &env_l)) env_l = env_init(env);
if (!env_l)
return (EXIT_FAILURE); return (EXIT_FAILURE);
signal(SIGINT, &sig_c); signal(SIGINT, &sig_c);
while (1) while (1)
@ -53,24 +55,34 @@ bool run_checks(char *rl)
rl = readline(prompt); rl = readline(prompt);
free(prompt); free(prompt);
if (!rl) if (!rl)
exit(727); break ;
if (!*rl)
{
continue ;
}
if (run_checks(rl)) if (run_checks(rl))
continue ; continue ;
piped = tokenizer(rl); piped = tokenizer(rl);
if (check_argv(piped)) if (check_argv(piped))
continue ; continue ;
add_history(rl); add_history(rl);
cmd_list = get_cmd_list(piped, &env_l); cmd_list = get_cmd_list(piped, env_l);
ft_lstclear(&piped, &free_token); ft_lstclear(&piped, &free_token);
format_quotes(cmd_list); format_quotes(cmd_list);
exec_split_cmd(cmd_list, &env_l); exec_split_cmd(cmd_list, env_l);
ft_lstclear(&cmd_list, &free_cmd); ft_lstclear(&cmd_list, &free_cmd);
free(rl); free(rl);
} }
return (0); free(rl);
}*/ rl_clear_history();
//ft_lstclear(&piped, &free_token);
//ft_lstclear(&cmd_list, &free_cmd);
ft_envclear(&env_l, free);
return (727);
}
int main(int ac, char **av, char **e) /*int main(int ac, char **av, char **e)
{ {
t_env *env; t_env *env;
@ -79,4 +91,4 @@ int main(int ac, char **av, char **e)
env = env_init(e); env = env_init(e);
ft_envprint(env); ft_envprint(env);
ft_envclear(&env, free); ft_envclear(&env, free);
} }*/

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/30 13:25:42 by adjoly #+# #+# */ /* Created: 2024/04/30 13:25:42 by adjoly #+# #+# */
/* Updated: 2024/07/04 17:14:30 by adjoly ### ########.fr */ /* Updated: 2024/07/09 14:35:13 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,11 +14,11 @@
#include "prompt.h" #include "prompt.h"
#include "env.h" #include "env.h"
char *get_prompt(t_env env) char *get_prompt(t_env *env)
{ {
char *prompt; char *prompt;
prompt = env_get_value("USER", &env); prompt = env_get_value("USER", env);
if (!prompt) if (!prompt)
prompt = ft_strdup("nixos"); prompt = ft_strdup("nixos");
prompt = ft_strjoin_free_s1(prompt, "@"); prompt = ft_strjoin_free_s1(prompt, "@");

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 14:42:00 by adjoly #+# #+# */ /* Created: 2024/05/02 14:42:00 by adjoly #+# #+# */
/* Updated: 2024/07/04 17:14:14 by adjoly ### ########.fr */ /* Updated: 2024/07/09 14:36:05 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,16 +14,16 @@
#include "libft.h" #include "libft.h"
#include "env.h" #include "env.h"
char *get_pwd(t_env env) char *get_pwd(t_env *env)
{ {
char *pwd; char *pwd;
char *home; char *home;
char *tmp; char *tmp;
pwd = env_get_value("PWD", &env); pwd = env_get_value("PWD", env);
if (!pwd) if (!pwd)
return (NULL); return (NULL);
home = env_get_value("HOME", &env); home = env_get_value("HOME", env);
if (!home) if (!home)
return (NULL); return (NULL);
if (!ft_strncmp(pwd, home, ft_strlen(home) - 1)) if (!ft_strncmp(pwd, home, ft_strlen(home) - 1))