summaryrefslogtreecommitdiffstats
path: root/src/c_init.c
diff options
context:
space:
mode:
authorsalad <fmoenne-@student.le-101.fr>2020-08-31 18:05:00 +0200
committersalad <fmoenne-@student.le-101.fr>2020-08-31 18:05:00 +0200
commit2ae54586f6dd2381e15b54fd510c7303e7ce366e (patch)
treeccffabdd60160902c1e0b543ba260db0b3da83df /src/c_init.c
parentstart normng (diff)
download42-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 ?
Diffstat (limited to 'src/c_init.c')
-rw-r--r--src/c_init.c41
1 files changed, 26 insertions, 15 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;