summaryrefslogtreecommitdiffstats
path: root/src/c_init.c
diff options
context:
space:
mode:
authorsalad <fmoenne-@student.le-101.fr>2020-11-03 00:03:48 +0100
committersalad <fmoenne-@student.le-101.fr>2020-11-03 00:03:48 +0100
commitb18fbce9a7e33f7e54949ae8de32fd7fc42e6ad1 (patch)
tree859e4d58e05622ef7a402e50ddd2ec913a51ef5d /src/c_init.c
parentstrplen (diff)
download42-minishell-b18fbce9a7e33f7e54949ae8de32fd7fc42e6ad1.tar.gz
42-minishell-b18fbce9a7e33f7e54949ae8de32fd7fc42e6ad1.tar.bz2
42-minishell-b18fbce9a7e33f7e54949ae8de32fd7fc42e6ad1.tar.xz
42-minishell-b18fbce9a7e33f7e54949ae8de32fd7fc42e6ad1.tar.zst
42-minishell-b18fbce9a7e33f7e54949ae8de32fd7fc42e6ad1.zip
this is it \(2009\) \: a Micheal Jackson Biopic
Diffstat (limited to 'src/c_init.c')
-rw-r--r--src/c_init.c50
1 files changed, 10 insertions, 40 deletions
diff --git a/src/c_init.c b/src/c_init.c
index 53af0a3..1023ced 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -14,6 +14,7 @@
#include <stdlib.h>
#include <libft.h>
#include <signal.h>
+#include <string.h>
#include <term.h>
#include "c_init.h"
@@ -23,30 +24,6 @@
#include "s_struct.h"
#include "m_prompt.h"
-unsigned int
- c_plen(char *prompt)
-{
- unsigned int i;
- unsigned int size;
-
- i = 0;
- size = 0;
- while (prompt[i] != '\0')
- {
- if (ft_isalpha(prompt[i]))
- {
- i++;
- size++;
- }
- else
- {
-
- i++;
- }
- }
- return (size);
-}
-
short
c_set_term_raw(char mode)
{
@@ -76,7 +53,7 @@ static void
{
*line = c_insert_char(*line, buf[0], tcaps);
tcaps->cpos++;
- if ((((tcaps->cpos) + ft_strlen(msh->ps[tcaps->psx])) %
+ if ((((tcaps->cpos) + tcaps->plen) %
tcaps->ws.ws_col) == 0)
{
write(1, "\n\r", 2);
@@ -88,21 +65,18 @@ static void
static short
c_read_cap(char *buf, char *line, t_caps *tcaps, t_msh *msh)
{
- unsigned int plen;
-
- plen = ft_strlen(msh->ps[tcaps->psx]);
if (((*((unsigned int *)buf)) == LEFT_K) ||
((*((unsigned int *)buf)) == CTRL_B))
- return (c_key_left(plen, tcaps));
+ return (c_key_left(tcaps->plen, tcaps));
else if (((*((unsigned int *)buf)) == RIGHT_K) ||
((*((unsigned int *)buf)) == CTRL_F))
- return (c_key_right(ft_strlen(line), plen, tcaps));
+ return (c_key_right(ft_strlen(line), tcaps->plen, tcaps));
else if (((*((unsigned int *)buf)) == HOME_K) ||
((*((unsigned int *)buf)) == CTRL_A))
- return (c_home_key(plen, tcaps));
+ return (c_home_key(tcaps->plen, tcaps));
else if (((*((unsigned int *)buf)) == END_K) ||
((*((unsigned int *)buf)) == CTRL_E))
- return (c_end_key(ft_strlen(line), plen, tcaps));
+ 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)
@@ -128,8 +102,8 @@ static char
c_add_char(&line, buf, tcaps, msh);
else if ((*((unsigned int *)buf)) == DEL_K)
{
- c_back_slash(&line, ft_strlen(msh->ps[tcaps->psx]), tcaps);
- if ((((tcaps->cpos) + ft_strlen(msh->ps[tcaps->psx])) %
+ c_back_slash(&line, tcaps->plen, tcaps);
+ if ((((tcaps->cpos) + tcaps->plen) %
tcaps->ws.ws_col) == 0)
{
return (NULL);
@@ -152,17 +126,13 @@ short
c_init_line(psx, &tcaps);
tputs(tgetstr("cr", NULL), 1, ft_putchar);
m_prompt_psx(psx, msh);
- ft_printf("%u", c_plen(msh->ps[0]));
ft_bzero(nread, 5);
+ tcaps.plen = m_plen(msh->ps[psx - 1]);
+ tcaps.plen += (psx != 1);
if (!(c_get_win_size(&tcaps.ws)))
return (-1);
while (!(ft_strchr(nread, '\n')))
{
- if (msh->ret == 130)
- {
- *line = ft_strdup("\0");
- return (1);
- }
ft_bzero(nread, 5);
if (!(read(fd, nread, 4)))
return (0);