」 feat: Prompt finished

This commit is contained in:
2024-05-02 15:50:58 +02:00
parent 272061eafc
commit bbadc3e663
71 changed files with 83 additions and 86 deletions

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/26 09:38:51 by mmoussou #+# #+# */
/* Updated: 2024/04/30 12:39:03 by adjoly ### ########.fr */
/* Updated: 2024/05/02 15:31:38 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,5 +22,8 @@
# include "libft.h"
char set_env(char **env, const char *name, char *content);
char *get_hostname(void);
char *get_prompt(void);
char *get_pwd(void);
#endif

BIN
libft/libft.a Normal file

Binary file not shown.

BIN
libft/src/char/ft_isalnum.o Normal file

Binary file not shown.

BIN
libft/src/char/ft_isalpha.o Normal file

Binary file not shown.

BIN
libft/src/char/ft_isascii.o Normal file

Binary file not shown.

BIN
libft/src/char/ft_isdigit.o Normal file

Binary file not shown.

BIN
libft/src/char/ft_isprint.o Normal file

Binary file not shown.

BIN
libft/src/int/ft_abs.o Normal file

Binary file not shown.

BIN
libft/src/int/ft_max.o Normal file

Binary file not shown.

BIN
libft/src/int/ft_min.o Normal file

Binary file not shown.

BIN
libft/src/io/ft_printf.o Normal file

Binary file not shown.

BIN
libft/src/io/ft_printf_fd.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
libft/src/io/ft_putnbr_fd.o Normal file

Binary file not shown.

BIN
libft/src/io/ft_putstr_fd.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
libft/src/mem/ft_bzero.o Normal file

Binary file not shown.

BIN
libft/src/mem/ft_calloc.o Normal file

Binary file not shown.

BIN
libft/src/mem/ft_free.o Normal file

Binary file not shown.

BIN
libft/src/mem/ft_memchr.o Normal file

Binary file not shown.

BIN
libft/src/mem/ft_memcmp.o Normal file

Binary file not shown.

BIN
libft/src/mem/ft_memcpy.o Normal file

Binary file not shown.

BIN
libft/src/mem/ft_memmove.o Normal file

Binary file not shown.

BIN
libft/src/mem/ft_memset.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
libft/src/str/ft_split.o Normal file

Binary file not shown.

BIN
libft/src/str/ft_strchr.o Normal file

Binary file not shown.

BIN
libft/src/str/ft_strcmp.o Normal file

Binary file not shown.

BIN
libft/src/str/ft_strdup.o Normal file

Binary file not shown.

BIN
libft/src/str/ft_striteri.o Normal file

Binary file not shown.

BIN
libft/src/str/ft_strjoin.o Normal file

Binary file not shown.

BIN
libft/src/str/ft_strlcat.o Normal file

Binary file not shown.

BIN
libft/src/str/ft_strlcpy.o Normal file

Binary file not shown.

BIN
libft/src/str/ft_strlen.o Normal file

Binary file not shown.

BIN
libft/src/str/ft_strmapi.o Normal file

Binary file not shown.

BIN
libft/src/str/ft_strncmp.o Normal file

Binary file not shown.

BIN
libft/src/str/ft_strnstr.o Normal file

Binary file not shown.

BIN
libft/src/str/ft_strrchr.o Normal file

Binary file not shown.

BIN
libft/src/str/ft_strtrim.o Normal file

Binary file not shown.

BIN
libft/src/str/ft_substr.o Normal file

Binary file not shown.

BIN
libft/src/str/ft_tolower.o Normal file

Binary file not shown.

BIN
libft/src/str/ft_toupper.o Normal file

Binary file not shown.

BIN
minishell Executable file

Binary file not shown.

BIN
obj/src/env_cmd.o Normal file

Binary file not shown.

BIN
obj/src/main.o Normal file

Binary file not shown.

Binary file not shown.

BIN
obj/src/prompt/get_prompt.o Normal file

Binary file not shown.

BIN
obj/src/prompt/get_pwd.o Normal file

Binary file not shown.

View File

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
/* Updated: 2024/04/30 12:40:35 by adjoly ### ########.fr */
/* Updated: 2024/05/02 15:47:34 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -30,61 +30,19 @@ bool is_str(char *src, char *dst)
return (true);
}
/*char *get_hostname(void)
{
char *hostname;
char *tmp;
int host_file;
//host_file = open();
tmp = hostname;
while (*tmp)
tmp++;
return
}*/
char *get_prompt(void)
{
char **prompt;
char *ret = NULL;
char *home;
char **tmp;
prompt = malloc(1000);
prompt[0] = getenv("USER");
prompt[1] = "@";
//prompt[2] = get_hostname();
home = getenv("HOME");
prompt[3] = getenv("PWD");
prompt[4] = ">";
//ret = ft_calloc(1000, sizeof(char));
if (!ft_strncmp(prompt[3], home, ft_strlen(home)))
prompt[3] += ft_strlen(home);
tmp = prompt;
while (*tmp)
{
ft_strlcat(ret, *tmp, ft_strlen(ret) + ft_strlen(*tmp) + 1);
tmp++;
}
free(prompt);
return (ret);
}
int main(int ac, char **av, char **env)
{
char *test;
char **lll;
char *ret = NULL;
char *prompt;
(void)ac;
(void)av;
(void)env;
while (1)
{
ret = get_prompt();
test = readline(ret);
free(ret);
prompt = get_prompt();
test = readline(prompt);
add_history(test);
lll = ft_split(test, ' ');
if (!*lll)
@ -92,6 +50,6 @@ int main(int ac, char **av, char **env)
if (is_str(test, "exit"))
break;
}
//ft_freearr((void **)lll);
//ft_free("a", &lll);
return (0);
}

36
src/prompt/get_hostname.c Normal file
View File

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_hostname.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 10:36:31 by adjoly #+# #+# */
/* Updated: 2024/05/02 13:42:24 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "fcntl.h"
#include "libft.h"
char *get_hostname(void)
{
char *hostname;
char *buf;
int host_file;
char *delimiter;
buf = ft_calloc(254, sizeof(char));
host_file = open("/etc/hostname", O_RDONLY);
read(host_file, buf, 254);
delimiter = ft_strchr(buf, '.');
if (!delimiter)
{
free(buf);
return (buf);
}
hostname = ft_calloc(delimiter - buf, sizeof(char));
ft_strlcpy(hostname, buf, delimiter - buf + 1);
free(buf);
return (hostname);
}

View File

@ -6,49 +6,22 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/30 13:25:42 by adjoly #+# #+# */
/* Updated: 2024/04/30 13:27:03 by adjoly ### ########.fr */
/* Updated: 2024/05/02 15:50:14 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
/*char *get_hostname(void)
{
char *hostname;
char *tmp;
int host_file;
//host_file = open();
tmp = hostname;
while (*tmp)
tmp++;
return
}*/
#include "libft.h"
#include "minishell.h"
char *get_prompt(void)
{
char **prompt;
char *ret = NULL;
char *home;
char **tmp;
char *prompt;
prompt = malloc(1000);
prompt[0] = getenv("USER");
prompt[1] = "@";
//prompt[2] = get_hostname();
home = getenv("HOME");
prompt[3] = getenv("PWD");
prompt[4] = ">";
//ret = ft_calloc(1000, sizeof(char));
if (!ft_strncmp(prompt[3], home, ft_strlen(home)))
prompt[3] += ft_strlen(home);
tmp = prompt;
while (*tmp)
{
ft_strlcat(ret, *tmp, ft_strlen(ret) + ft_strlen(*tmp) + 1);
tmp++;
}
free(prompt);
return (ret);
prompt = getenv("USER");
prompt = ft_strjoin(prompt, "@");
prompt = ft_strjoin_free(prompt, get_hostname());
prompt = ft_strjoin_free_s1(prompt, ":");
prompt = ft_strjoin_free(prompt, get_pwd());
prompt = ft_strjoin_free_s1(prompt, "$ ");
return (prompt);
}

27
src/prompt/get_pwd.c Normal file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_pwd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 14:42:00 by adjoly #+# #+# */
/* Updated: 2024/05/02 15:49:42 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
char *get_pwd(void)
{
char *pwd;
char *home;
pwd = getenv("PWD");
home = getenv("HOME");
if (!ft_strncmp(pwd, home, ft_strlen(home)))
pwd += ft_strlen(home);
pwd = ft_strjoin("~", pwd);
return (pwd);
}