wip builtins: env, exit

This commit is contained in:
LuckyLaszlo
2021-10-10 08:57:33 +02:00
parent a7e0066458
commit c0068a5ec7
9 changed files with 113 additions and 21 deletions

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/08 09:22:12 by lperrey #+# #+# */
/* Updated: 2021/10/08 19:09:12 by lperrey ### ########.fr */
/* Updated: 2021/10/10 08:54:17 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,9 +15,10 @@
static char *init_prompt_base(void);
static char *init_prompt(char *prompt_base);
int init(t_all *c)
int init(t_all *c, char *envp[])
{
ft_bzero(c, sizeof *c);
c->envp = envp;
c->prompt_base = init_prompt_base();
if (!c->prompt_base)
return (ft_reti_perror(0, "init_prompt_base() fail"));
@@ -36,12 +37,12 @@ static char *init_prompt_base(void)
if (!tmp)
tmp = getenv("LOGNAME");
if (!tmp)
tmp = "NoName";
tmp = "NoUser";
prompt_base = ft_strjoin(TERM_LIGHT_GREEN, tmp);
prompt_base = ft_strjoinfree_s1(prompt_base, "@");
tmp = getenv("NAME");
if (!tmp)
tmp = "NoHost";
tmp = "NoName";
prompt_base = ft_strjoinfree_s1(prompt_base, tmp);
prompt_base = ft_strjoinfree_s1(prompt_base, TERM_RESET":"TERM_LIGHT_BLUE);
return (prompt_base);
@@ -52,6 +53,6 @@ static char *init_prompt(char *prompt_base)
char *prompt;
prompt = ft_strjoinfree_s2(prompt_base, getcwd(NULL, 0));
prompt = ft_strjoinfree_s1(prompt, TERM_RESET PROMPT_EURO);
prompt = ft_strjoinfree_s1(prompt, TERM_RESET USER_PROMPT);
return (prompt);
}