71 lines
1.7 KiB
C
Raw Normal View History

2024-04-25 11:46:41 +02:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
2024-04-27 17:39:26 +02:00
/* Updated: 2024/04/27 17:34:52 by adjoly ### ########.fr */
2024-04-25 11:46:41 +02:00
/* */
/* ************************************************************************** */
#include <readline/readline.h>
#include <stdio.h>
2024-04-27 17:39:26 +02:00
#include <stdlib.h>
2024-04-25 11:46:41 +02:00
#include "libft.h"
t_boolean is_str(char *src, char *dst)
{
2024-04-27 17:39:26 +02:00
while (*src && *dst && *src == *dst)
{
src++;
dst++;
}
2024-04-25 11:46:41 +02:00
if (*src)
return (FALSE);
return (TRUE);
}
2024-04-27 17:39:26 +02:00
void get_prompt(void)
{
char *pwd;
char *home;
char *user;
char *host;
pwd = getenv("PWD");
home = getenv("HOME");
host = getenv("HOST");
user = getenv("USER");
if (!ft_strncmp(pwd, home, ft_strlen(home)))
{
ft_printf("%s@%s:~%s> ", user, host, pwd + ft_strlen(home));
return ;
}
ft_printf("%s@%s:%s> ", user, host, pwd);
}
2024-04-25 11:46:41 +02:00
int main(int ac, char **av, char **env)
{
char *test;
char **lll;
(void)ac;
(void)av;
(void)env;
while (1)
{
2024-04-27 17:39:26 +02:00
get_prompt();
test = readline(NULL);
2024-04-25 11:46:41 +02:00
lll = ft_split(test, ' ');
2024-04-27 17:39:26 +02:00
if (!*lll)
continue;
if (is_str(test, "exit"))
break;
2024-04-25 11:46:41 +02:00
}
2024-04-27 17:39:26 +02:00
ft_freearr((void **)lll);
2024-04-25 11:46:41 +02:00
return (0);
}