diff options
Diffstat (limited to '')
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | inc/minishell.h | 1 | ||||
| -rw-r--r-- | src/ft_history.c | 27 | ||||
| -rw-r--r-- | src/main.c | 8 | 
4 files changed, 31 insertions, 7 deletions
@@ -63,7 +63,7 @@ fclean:			clean xclean  re:				fclean all  build:			${OBJS} -	${CC} ${CFLAGS} ${DEBUG} ${FSANITIZE} ${LIB_DIR} ${LIB} -o a.out ${OBJS} +	${CC} ${CFLAGS} ${DEBUG} ${FSANITIZE} ${LIB_DIR} ${LIB} -o minishell ${OBJS}  default: all diff --git a/inc/minishell.h b/inc/minishell.h index e3fb5b6..f2b9a94 100644 --- a/inc/minishell.h +++ b/inc/minishell.h @@ -12,5 +12,6 @@ uint8_t ft_exit(char **com);  int ft_error(const char *com, int errno);  int ft_exec(char **app);  int ft_history(char *arg); +char *ft_get_last_line(void);  #endif diff --git a/src/ft_history.c b/src/ft_history.c index 6a82a16..10f683a 100644 --- a/src/ft_history.c +++ b/src/ft_history.c @@ -17,18 +17,37 @@  #include <stdio.h>  #include <fcntl.h>  #include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> + +char +*ft_get_last_line(void) +{ +	// char *buff; +	int fd; +	struct stat info; + +	if ((fd = open("joe-sh_history", O_CREAT | O_RDWR, 0644)) == -1) +		return (NULL); +	fstat(fd, &info); +	return ("qweqwe"); +}  int  ft_history(char *arg)  { -	char c; +	char *buff;  	int fd; -	int r; +	struct stat info; +	if (!*arg) +		return (0);  	if ((fd = open("joe-sh_history", O_CREAT | O_RDWR, 0644)) == -1)  		return (1); -	while ((r = read(fd, &c, 1)) != EOF) -		puts(&c); +	fstat(fd, &info); +	if (!(buff = (char*)malloc(info.st_size * sizeof(char)))) +		return (0); +	read(fd, buff, info.st_size);  	ft_putendl_fd(arg, fd);  	close(fd);  	return (0); @@ -24,7 +24,6 @@ int  	char c;  	char *arg;  	uint8_t i; -	int ret;  	i = 0;  	arg = NULL; @@ -44,11 +43,16 @@ int  			if (c == '\n')  				break ;  			arg[i] = c; +			if (!ft_strncmp("", arg, 4)) +			{ +				arg = ft_get_last_line(); +				break ; +			}  			i++;  		}  		arg[i] = '\0';  		ft_history(arg); -		ret = ft_process_arg(arg); +		ft_process_arg(arg);  	}  	free(arg);  	arg = NULL;  | 
