diff options
author | salad <fmoenne-@student.le-101.fr> | 2020-08-31 18:05:00 +0200 |
---|---|---|
committer | salad <fmoenne-@student.le-101.fr> | 2020-08-31 18:05:00 +0200 |
commit | 2ae54586f6dd2381e15b54fd510c7303e7ce366e (patch) | |
tree | ccffabdd60160902c1e0b543ba260db0b3da83df | |
parent | start normng (diff) | |
download | 42-minishell-2ae54586f6dd2381e15b54fd510c7303e7ce366e.tar.gz 42-minishell-2ae54586f6dd2381e15b54fd510c7303e7ce366e.tar.bz2 42-minishell-2ae54586f6dd2381e15b54fd510c7303e7ce366e.tar.xz 42-minishell-2ae54586f6dd2381e15b54fd510c7303e7ce366e.tar.zst 42-minishell-2ae54586f6dd2381e15b54fd510c7303e7ce366e.zip |
it all failed ?
-rw-r--r-- | src/c_init.c | 41 | ||||
-rw-r--r-- | src/m_loop.c | 1 | ||||
-rw-r--r-- | src/p_lcom_next.c | 10 |
3 files changed, 29 insertions, 23 deletions
diff --git a/src/c_init.c b/src/c_init.c index 63e9e07..ee4d0a7 100644 --- a/src/c_init.c +++ b/src/c_init.c @@ -36,7 +36,7 @@ void c_process_key(t_caps *tcaps) { char nread[64] = {0}; int bread; - while ((bread = read(STDIN_FILENO, nread, sizeof(nread)) != 1)) { + while ((bread = read(STDIN_FILENO, nread, 3) != 1)) { if (bread == -1) { printf("error on read"); @@ -47,7 +47,7 @@ void c_process_key(t_caps *tcaps) { if (*nread == 'q') exit(0); else if ((strncmp(nread, "l", 1) == 0) || - strncmp(nread, tcaps->kl, strlen(tcaps->kl)) == 0) + strncmp(nread, tcaps->kr, 3) == 0) { tputs(tgoto(tcaps->nd, 1, 1), 1, putchar); } @@ -77,21 +77,32 @@ int16_t c_init_tcaps(void) term = getenv("TERM"); if (!tgetent(bp, term)) return (-1); - tcaps.cl = tgetstr("cl", &term); - tcaps.ks = tgetstr("ks", &term); - tcaps.kl = tgetstr("kl", &term); - tcaps.ke = tgetstr("kr", &term); - tcaps.kr = tgetstr("kr", &term); - tcaps.pc = tgetstr("pc", &term); - tcaps.bc = tgetstr("bc", &term); - tcaps.up = tgetstr("up", &term); - tcaps.nd = tgetstr("nd", &term); - tcaps.le = tgetstr("le", &term); - tcaps.DO = tgetstr("do", &term); + if (!(tcaps.cl = tgetstr("cl", &term))) + return (-1); + if (!(tcaps.ks = tgetstr("ks", &term))) + return (-1); + if (!(tcaps.kl = tgetstr("kl", &term))) + return (-1); + if (!(tcaps.ke = tgetstr("kr", &term))) + return (-1); + if (!(tcaps.kr = tgetstr("kr", &term))) + return (-1); + if (!(tcaps.pc = tgetstr("pc", &term))) + return (-1); + if (!(tcaps.bc = tgetstr("bc", &term))) + return (-1); + if (!(tcaps.up = tgetstr("up", &term))) + return (-1); + if (!(tcaps.nd = tgetstr("nd", &term))) + return (-1); + if (!(tcaps.le = tgetstr("le", &term))) + return (-1); + if (!(tcaps.DO = tgetstr("do", &term))) + return (-1); tcgetattr(STDIN_FILENO, &tcaps.tios); - printf("%d\n", KEY_LEFT); - tputs(tgoto(tcaps.ks, 1, 1), 1, putchar); + printf("%d\n [%s]", KEY_LEFT, tcaps.ks); + write(1, tcaps.ks, 1); tcaps.tios.c_lflag &= ~(ECHO | ICANON); tcaps.tios.c_cc[VMIN] = 0; tcaps.tios.c_cc[VTIME] = 1; diff --git a/src/m_loop.c b/src/m_loop.c index 9df2fce..39d8452 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -39,6 +39,7 @@ uint8_t int8_t gnl; gnl = 1; + c_init_tcaps(); while (gnl > 0) { if (fd == STDIN_FILENO) diff --git a/src/p_lcom_next.c b/src/p_lcom_next.c index 5e5b69d..19e3287 100644 --- a/src/p_lcom_next.c +++ b/src/p_lcom_next.c @@ -67,13 +67,11 @@ static char j = 0; if (reg == TRUE) - { while (words[j] && j < i) { p_register_word(words[j], msh); j++; } - } j = 0; while (words[i + j] != NULL) j++; @@ -94,7 +92,6 @@ static char } rewords[i - k] = 0; ft_delwords(words); - i++; return (rewords); } @@ -115,11 +112,8 @@ char ptr = words[i]; while (*ptr != '\0' && *ptr != '=') ptr++; - if (*ptr == '=') - { - reg = TRUE; - isvar = TRUE; - } + reg = (*ptr == '=') ? TRUE : FALSE; + isvar = (*ptr == '=') ? TRUE : FALSE; if (*ptr == '\0' || words[i][0] == '=' || ft_isdigit(words[i][0]) == TRUE) { |