diff options
| author | joe <rbousset@42lyon.fr> | 2020-12-01 16:12:02 +0100 | 
|---|---|---|
| committer | joe <rbousset@42lyon.fr> | 2020-12-01 16:12:02 +0100 | 
| commit | 214eae8a55bde34ca412084bebdb378a696152cc (patch) | |
| tree | 70404f68b1b86035fe4835d8cf2da61dcefc5eba /src | |
| parent | Not quite done (diff) | |
| download | 42-minishell-214eae8a55bde34ca412084bebdb378a696152cc.tar.gz 42-minishell-214eae8a55bde34ca412084bebdb378a696152cc.tar.bz2 42-minishell-214eae8a55bde34ca412084bebdb378a696152cc.tar.xz 42-minishell-214eae8a55bde34ca412084bebdb378a696152cc.tar.zst 42-minishell-214eae8a55bde34ca412084bebdb378a696152cc.zip | |
Bav
Diffstat (limited to '')
| -rw-r--r-- | src/c_init.c | 9 | ||||
| -rw-r--r-- | src/c_keys_next.c | 45 | ||||
| -rw-r--r-- | src/c_keys_next.h | 2 | ||||
| -rw-r--r-- | src/e_pipes_next.c | 33 | ||||
| -rw-r--r-- | src/m_minishell.c | 10 | 
5 files changed, 46 insertions, 53 deletions
| diff --git a/src/c_init.c b/src/c_init.c index 1ab6743..965af3f 100644 --- a/src/c_init.c +++ b/src/c_init.c @@ -89,9 +89,6 @@ static short  		return (c_end_key(ft_strlen(line), tcaps->plen, tcaps));  	else if ((*((unsigned int *)buf)) == CTRL_L)  		return (c_ctrl_l(line, tcaps, msh)); -	else if (((*((unsigned int *)buf)) == UP_K) || -			((*((unsigned int *)buf)) == CTRL_P)) -			return (c_key_up(tcaps, msh));  	else if ((*((unsigned int *)buf)) == CTRL_D &&  			line[0] == '\0')  	{ @@ -120,6 +117,12 @@ static char  			return (NULL);  	if (ft_isprint(buf[0]))  		c_add_char(&line, buf, tcaps, msh); +	else if (((*((unsigned int *)buf)) == UP_K) || +			((*((unsigned int *)buf)) == CTRL_P)) +	{ +		c_key_up(&line, tcaps, msh); +		c_redraw_line(line, tcaps, msh); +	}  	else if ((*((unsigned int *)buf)) == DEL_K)  	{  		c_back_slash(&line, tcaps->plen, tcaps); diff --git a/src/c_keys_next.c b/src/c_keys_next.c index 99f01b9..629d9f8 100644 --- a/src/c_keys_next.c +++ b/src/c_keys_next.c @@ -15,31 +15,32 @@  #include <term.h>  #include "c_init.h" +#include "c_keys.h"  #include "d_define.h"  #include "s_struct.h" -short	c_key_up(t_caps *tcaps, t_msh *msh) +short	c_key_up(char *line[], t_caps *tcaps, t_msh *msh)  { -	/* static char		*ptr;                                        */ -	/* static t_bool	set = TRUE;                                  */ -    /*                                                               */ -	/* if (set == TRUE)                                              */ -	/* {                                                             */ -	/*     ptr = msh->curr_hist_ptr + ft_strlen(msh->curr_hist_ptr); */ -	/*     set = FALSE;                                              */ -	/* }                                                             */ -	/* while (ptr - msh->curr_hist_ptr != 0 && *ptr != '\n')         */ -	/* {                                                             */ -	/*     ft_printf("{%c}\n", *ptr);                                */ -	/*     ptr--;                                                    */ -	/* }                                                             */ -	/* ptr += 1;                                                     */ -	/* ft_dprintf(1, "[%s]\n", ptr);                                 */ -	(void)msh; -	(void)tcaps; -	ft_dprintf(0, "qwe"); -	/* tcaps->cpos = 0; */ -	/* tcaps->lpos = 0; */ -	/* tputs(tgetstr("nd", NULL), 1, ft_putchar); */ +	char			tmp[ARG_MAX]; +	static char		*ptr; +	static t_bool	set = TRUE; + +	if (set == TRUE) +	{ +		ptr = msh->curr_hist_ptr + ft_strlen(msh->curr_hist_ptr); +		set = FALSE; +	} +	ptr -= 2; +	while (ptr - msh->curr_hist_ptr != 0 && *ptr != '\n') +	{ +		ptr--; +	} +	ptr += 1; +	c_home_key(tcaps->plen, tcaps); +	ft_substr_s(tmp, ptr, 0, ft_strclen(ptr, '\n')); +	ft_memdel((void*)&(*line)); +	tputs(tgetstr("ce", NULL), 1, ft_putchar); +	*line = ft_strdup(tmp); +	tcaps->cpos = ft_strlen(*line);  	return (1);  } diff --git a/src/c_keys_next.h b/src/c_keys_next.h index fc76ecf..53e3f23 100644 --- a/src/c_keys_next.h +++ b/src/c_keys_next.h @@ -16,6 +16,6 @@  #include "c_init.h"  #include "s_struct.h" -short	c_key_up(t_caps *tcaps, t_msh *msh); +short	c_key_up(char *line[], t_caps *tcaps, t_msh *msh);  #endif diff --git a/src/e_pipes_next.c b/src/e_pipes_next.c index 93eb42e..a129f2e 100644 --- a/src/e_pipes_next.c +++ b/src/e_pipes_next.c @@ -40,30 +40,19 @@ static void	e_fullpath_not_found(t_com *ptr, t_msh *msh)  static void	e_exec_child(const char fullpath[], t_com *ptr, t_msh *msh)  { -	char	buff[7]; -	int		fd; - -	if ((fd = open(fullpath, O_RDONLY)) != -1) -	{ -		if (read(fd, buff, 7) != -1) -			if (ft_strncmp(buff, "\177ELF\002\001\001", 7) != 0 -				&& ft_strncmp(buff, "#!", 2) != 0) -			{ -				close(fd); -				e_extern_read_script(fullpath, ptr, msh, TRUE); -				return ; -			} -		close(fd); -	}  	if (execve(fullpath, ptr->argv, msh->envp) == -1)  	{ -		f_exec(fullpath, ptr->bin); -		u_eof_fd(msh->fd); -		s_com_destroy(&msh->com); -		s_lpipes_clear(&msh->pipes); -		s_line_clear(&msh->curr); -		s_destroy(msh); -		exit(errno); +		if (errno != ENOEXEC) +		{ +			f_exec(fullpath, ptr->bin); +			u_eof_fd(msh->fd); +			s_com_destroy(&msh->com); +			s_lpipes_clear(&msh->pipes); +			s_line_clear(&msh->curr); +			s_destroy(msh); +			exit(errno); +		} +		e_extern_read_script(fullpath, ptr, msh, FALSE);  	}  } diff --git a/src/m_minishell.c b/src/m_minishell.c index 6cd1f61..e5ec69e 100644 --- a/src/m_minishell.c +++ b/src/m_minishell.c @@ -32,11 +32,11 @@ int	main(int argc, char *const argv[], char *const envp[])  		ft_dprintf(STDERR_FILENO, "%s\n", strerror(errno));  		return (M_RET_ALLOC);  	} -	if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO)) -	{ -		ft_dprintf(STDERR_FILENO, "minishell: innapropriate ioctl device.\n"); -		exit(1); -	} +	/* if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO)) */ +	/* { */ +	/*     ft_dprintf(STDERR_FILENO, "minishell: innapropriate ioctl device.\n"); */ +	/*     exit(1); */ +	/* } */  	ret = m_argv(argc, argv, msh);  	s_destroy(msh);  	return (ret); | 
