diff options
author | salad <fmoenne-@student.le-101.fr> | 2020-11-06 20:17:34 +0100 |
---|---|---|
committer | salad <fmoenne-@student.le-101.fr> | 2020-11-06 20:17:34 +0100 |
commit | 87a70e527eca58cad87c14fd2a8595b8bce85e25 (patch) | |
tree | 9bbb931a9bdd16d93f6546e1e7f254ba3c3db221 | |
parent | C-c arrows (diff) | |
download | 42-minishell-87a70e527eca58cad87c14fd2a8595b8bce85e25.tar.gz 42-minishell-87a70e527eca58cad87c14fd2a8595b8bce85e25.tar.bz2 42-minishell-87a70e527eca58cad87c14fd2a8595b8bce85e25.tar.xz 42-minishell-87a70e527eca58cad87c14fd2a8595b8bce85e25.tar.zst 42-minishell-87a70e527eca58cad87c14fd2a8595b8bce85e25.zip |
major changes to ctrlc + c, no norm for now
-rw-r--r-- | src/c_init.c | 13 | ||||
-rw-r--r-- | src/c_init.h | 2 | ||||
-rw-r--r-- | src/c_input.c | 21 | ||||
-rw-r--r-- | src/c_input.h | 1 | ||||
-rw-r--r-- | src/c_keys.c | 11 | ||||
-rw-r--r-- | src/c_keys.h | 1 | ||||
-rw-r--r-- | src/m_minishell.c | 5 |
7 files changed, 44 insertions, 10 deletions
diff --git a/src/c_init.c b/src/c_init.c index d80b9ea..314baad 100644 --- a/src/c_init.c +++ b/src/c_init.c @@ -24,6 +24,8 @@ #include "s_struct.h" #include "m_prompt.h" +t_msh *c_get_struct(int mode, t_msh *msh); + short c_set_term_raw(char mode) { @@ -79,11 +81,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)) == CTRL_C) - { - msh->ret = 130; - return (1); - } else return (0); } @@ -110,6 +107,10 @@ static char } c_redraw_line(line, tcaps, msh); } + else if ((*((unsigned int *)buf)) == CTRL_C) + { + return (c_ctrl_c(&line, buf, msh)); + } else { c_read_cap(buf, line, tcaps, msh); @@ -128,7 +129,7 @@ short m_prompt_psx(psx, msh); ft_bzero(nread, 4); tcaps.plen = (unsigned int)m_plen(msh->ps[psx - 1]); - tcaps.plen += (psx != 1); + c_get_struct(1, msh); if (!(c_get_win_size(&tcaps.ws))) return (-1); while (!(ft_strchr(nread, '\n'))) diff --git a/src/c_init.h b/src/c_init.h index ac380dd..f563df2 100644 --- a/src/c_init.h +++ b/src/c_init.h @@ -21,7 +21,7 @@ # define LEFT_K 0x445b1b # define RIGHT_K 0x435b1b # define HOME_K 0x485b1b -# define END_K 0x7e345b1b +# define END_K 0x465b1b # define DEL_K 0x7f # define RET_K 0x0d diff --git a/src/c_input.c b/src/c_input.c index 8f15449..5e7e937 100644 --- a/src/c_input.c +++ b/src/c_input.c @@ -23,15 +23,32 @@ #include "m_prompt.h" #include "m_loop.h" +t_msh + *c_get_struct(int mode, t_msh *msh) +{ + static t_msh *mstruct = NULL; + + if (mode) + { + mstruct = msh; + } + return (mstruct); +} void c_signal_int(int signo) { + t_msh *msh; + + msh = NULL; signal(SIGINT, c_signal_int); (void)signo; + msh = c_get_struct(0, msh); + msh->ret = 130; + write(1, "qwe", 3); ioctl(1, TIOCSTI, "\002"); } -void signal_ign(int signo) +void c_signal_ign(int signo) { signal(SIGINT, c_signal_int); (void)signo; @@ -50,7 +67,7 @@ short return (-1); c_set_term_raw(1); signal(SIGINT, c_signal_int); - signal(SIGQUIT, signal_ign); + signal(SIGQUIT, c_signal_ign); tcaps->cpos = 0; tcaps->lpos = 0; tcaps->nlines = 1; diff --git a/src/c_input.h b/src/c_input.h index 7ba697f..f2ccba8 100644 --- a/src/c_input.h +++ b/src/c_input.h @@ -14,7 +14,6 @@ # define C_INPUT_H short c_back_slash(char **line, unsigned int plen, t_caps *tcaps); -short c_ctrl_c(char *line, t_caps *tcaps, t_msh *msh); unsigned int c_get_line_num(char *line, unsigned int cpos, unsigned int plen, t_caps *tcaps); short c_init_line(char psx, t_caps *tcaps); diff --git a/src/c_keys.c b/src/c_keys.c index 6d472c4..8c06a85 100644 --- a/src/c_keys.c +++ b/src/c_keys.c @@ -12,6 +12,7 @@ #include <term.h> #include <libft.h> +#include <unistd.h> #include "c_init.h" #include "c_utils.h" @@ -26,6 +27,16 @@ short return (1); } +char + *c_ctrl_c(char **line, char *buf, t_msh *msh) +{ + msh->ret = 130; + buf[0] = '\n'; + write(1, "\n", 1); + ft_memdel((void**)line); + return (ft_strdup("\0")); +} + short c_home_key(unsigned int plen, t_caps *tcaps) { diff --git a/src/c_keys.h b/src/c_keys.h index d64a908..6b48431 100644 --- a/src/c_keys.h +++ b/src/c_keys.h @@ -18,5 +18,6 @@ short c_key_left(unsigned int plen, t_caps *tcaps); short c_home_key(unsigned int plen, t_caps *tcaps); short c_end_key(unsigned short size, unsigned int plen, t_caps *tcaps); short c_ctrl_l(char *line, t_caps *tcaps, t_msh *msh); +char *c_ctrl_c(char **line, char *buf, t_msh *msh); #endif diff --git a/src/m_minishell.c b/src/m_minishell.c index 987cfc0..a3226fe 100644 --- a/src/m_minishell.c +++ b/src/m_minishell.c @@ -32,6 +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(2, "minishell: innapropriate ioctl device."); + exit(1); + } ret = m_argv(argc, argv, msh); s_destroy(msh); return (ret); |