mise a la norme edition de ligne - heredoc mal géré
This commit is contained in:
parent
08710f9e6b
commit
288acbb378
19 changed files with 279 additions and 245 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
|
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
|
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
|
||||||
# Updated: 2017/02/03 15:23:50 by gwojda ### ########.fr #
|
# Updated: 2017/02/04 12:47:31 by gwojda ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/03 16:36:20 by gwojda ### ########.fr */
|
/* Updated: 2017/02/04 14:50:04 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -73,6 +73,9 @@
|
||||||
# define IS_BRACKET (1 << 4)
|
# define IS_BRACKET (1 << 4)
|
||||||
# define IS_BSLASH (1 << 5)
|
# define IS_BSLASH (1 << 5)
|
||||||
|
|
||||||
|
# define STR data_singleton()->line.input
|
||||||
|
# define POS data_singleton()->line.pos
|
||||||
|
|
||||||
# define HIST 1
|
# define HIST 1
|
||||||
|
|
||||||
# define ERROR_CNTL_R 1
|
# define ERROR_CNTL_R 1
|
||||||
|
|
@ -88,7 +91,6 @@ typedef struct s_line
|
||||||
{
|
{
|
||||||
char *input;
|
char *input;
|
||||||
char *copy_tmp;
|
char *copy_tmp;
|
||||||
char *input_tmp;
|
|
||||||
size_t pos;
|
size_t pos;
|
||||||
int prompt_size;
|
int prompt_size;
|
||||||
int list_size;
|
int list_size;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/26 13:32:52 by gwojda #+# #+# */
|
/* Created: 2017/01/26 13:32:52 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/03 15:27:37 by gwojda ### ########.fr */
|
/* Updated: 2017/02/04 14:51:44 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,13 +14,13 @@
|
||||||
|
|
||||||
t_prompt_type g_prompt_tab[] =
|
t_prompt_type g_prompt_tab[] =
|
||||||
{
|
{
|
||||||
{IS_QUOTES ,SIZE_PROMPT_QUOTES ,PROMPT_QUOTES},
|
{IS_QUOTES, SIZE_PROMPT_QUOTES, PROMPT_QUOTES},
|
||||||
{IS_BQUOTES ,SIZE_PROMPT_BQUOTES ,PROMPT_BQUOTES},
|
{IS_BQUOTES, SIZE_PROMPT_BQUOTES, PROMPT_BQUOTES},
|
||||||
{IS_DQUOTES ,SIZE_PROMPT_DQUOTES ,PROMPT_DQUOTES},
|
{IS_DQUOTES, SIZE_PROMPT_DQUOTES, PROMPT_DQUOTES},
|
||||||
{IS_ACCOLADE ,SIZE_PROMPT_ACCOLADE ,PROMPT_ACCOLADE},
|
{IS_ACCOLADE, SIZE_PROMPT_ACCOLADE, PROMPT_ACCOLADE},
|
||||||
{IS_BRACKET ,SIZE_PROMPT_BRACKET ,PROMPT_BRACKET},
|
{IS_BRACKET, SIZE_PROMPT_BRACKET, PROMPT_BRACKET},
|
||||||
{IS_BSLASH ,SIZE_PROMPT_BSLASH ,PROMPT_BSLASH},
|
{IS_BSLASH, SIZE_PROMPT_BSLASH, PROMPT_BSLASH},
|
||||||
{0 ,0 ,0},
|
{0, 0, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
void ft_read_more(short c)
|
void ft_read_more(short c)
|
||||||
|
|
@ -50,9 +50,10 @@ void ft_read_more(short c)
|
||||||
void ft_check_this_char(char c, short *status)
|
void ft_check_this_char(char c, short *status)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char stats[] = {'\'', '`', '\"', '{', '(', '\\', '\0'};
|
char *stats;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
|
stats = "\'`\"{(\\";
|
||||||
while (stats[i] && stats[i] != c)
|
while (stats[i] && stats[i] != c)
|
||||||
++i;
|
++i;
|
||||||
if (!stats[i])
|
if (!stats[i])
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */
|
/* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/02 16:10:51 by gwojda ### ########.fr */
|
/* Updated: 2017/02/04 14:55:05 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -36,7 +36,7 @@ static char *ft_strdupi_space(char const *s)
|
||||||
return (str);
|
return (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_v(void)
|
void ft_v(void)
|
||||||
{
|
{
|
||||||
size_t tmp_pos;
|
size_t tmp_pos;
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -45,17 +45,14 @@ void ft_v(void)
|
||||||
size_t *pos;
|
size_t *pos;
|
||||||
|
|
||||||
tmp = data_singleton()->line.copy_tmp;
|
tmp = data_singleton()->line.copy_tmp;
|
||||||
str = &data_singleton()->line.input;
|
str = &STR;
|
||||||
pos = &data_singleton()->line.pos;
|
pos = &POS;
|
||||||
i = 0;
|
i = -1;
|
||||||
tmp_pos = *pos;
|
tmp_pos = *pos;
|
||||||
if (!*str || !tmp)
|
if (!*str || !tmp)
|
||||||
return ;
|
return ;
|
||||||
while (tmp[i])
|
while (tmp[++i])
|
||||||
{
|
|
||||||
*str = ft_realloc_imput(*str, tmp[i], *pos + i);
|
*str = ft_realloc_imput(*str, tmp[i], *pos + i);
|
||||||
++i;
|
|
||||||
}
|
|
||||||
if (*pos)
|
if (*pos)
|
||||||
{
|
{
|
||||||
--(*pos);
|
--(*pos);
|
||||||
|
|
@ -67,7 +64,7 @@ void ft_v(void)
|
||||||
(*pos) = tmp_pos;
|
(*pos) = tmp_pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_x(void)
|
void ft_x(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char **tmp;
|
char **tmp;
|
||||||
|
|
@ -75,8 +72,8 @@ void ft_x(void)
|
||||||
size_t *pos;
|
size_t *pos;
|
||||||
|
|
||||||
tmp = &data_singleton()->line.copy_tmp;
|
tmp = &data_singleton()->line.copy_tmp;
|
||||||
str = &data_singleton()->line.input;
|
str = &STR;
|
||||||
pos = &data_singleton()->line.pos;
|
pos = &POS;
|
||||||
if (!*str)
|
if (!*str)
|
||||||
return ;
|
return ;
|
||||||
if (*tmp)
|
if (*tmp)
|
||||||
|
|
@ -98,8 +95,8 @@ void ft_c(void)
|
||||||
size_t *pos;
|
size_t *pos;
|
||||||
|
|
||||||
tmp = data_singleton()->line.copy_tmp;
|
tmp = data_singleton()->line.copy_tmp;
|
||||||
str = &data_singleton()->line.input;
|
str = &STR;
|
||||||
pos = &data_singleton()->line.pos;
|
pos = &POS;
|
||||||
if (tmp)
|
if (tmp)
|
||||||
ft_strdel(&tmp);
|
ft_strdel(&tmp);
|
||||||
tmp = ft_strdupi_space((*str) + (*pos));
|
tmp = ft_strdupi_space((*str) + (*pos));
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */
|
/* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/03 18:00:09 by gwojda ### ########.fr */
|
/* Updated: 2017/02/04 15:39:49 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@ t_key g_key[] =
|
||||||
{TOUCHE_DELETE , &ft_del },
|
{TOUCHE_DELETE , &ft_del },
|
||||||
{TOUCHE_CTRL_C , &ft_control_c },
|
{TOUCHE_CTRL_C , &ft_control_c },
|
||||||
{TOUCHE_CTRL_D , &ft_control_d },
|
{TOUCHE_CTRL_D , &ft_control_d },
|
||||||
{TOUCHE_CTRL_R , &ft_history_parsing },
|
{TOUCHE_CTRL_R , &ft_surch_in_history },
|
||||||
{TOUCHE_SUPPR , &ft_suppr },
|
{TOUCHE_SUPPR , &ft_suppr },
|
||||||
{TOUCHE_HOME , &ft_home },
|
{TOUCHE_HOME , &ft_home },
|
||||||
{TOUCHE_END , &ft_end },
|
{TOUCHE_END , &ft_end },
|
||||||
|
|
@ -37,18 +37,23 @@ t_key g_key[] =
|
||||||
{0 , 0 },
|
{0 , 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
char *ft_read_stdin(void)
|
static void ft_is_str(void)
|
||||||
|
{
|
||||||
|
if (STR)
|
||||||
|
{
|
||||||
|
ft_current_str(STR, POS);
|
||||||
|
ft_get_next_str(STR, &POS);
|
||||||
|
if (STR[POS])
|
||||||
|
++(POS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_read_stdin(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
if (data_singleton()->line.input)
|
ft_is_str();
|
||||||
{
|
|
||||||
ft_current_str(data_singleton()->line.input, data_singleton()->line.pos);
|
|
||||||
ft_get_next_str(data_singleton()->line.input, &data_singleton()->line.pos);
|
|
||||||
if (data_singleton()->line.input[data_singleton()->line.pos])
|
|
||||||
++(data_singleton()->line.pos);
|
|
||||||
}
|
|
||||||
if (data_singleton()->comp)
|
if (data_singleton()->comp)
|
||||||
c_clear(data_singleton());
|
c_clear(data_singleton());
|
||||||
while (42)
|
while (42)
|
||||||
|
|
@ -65,9 +70,8 @@ char *ft_read_stdin(void)
|
||||||
else if (ft_isprint(ret))
|
else if (ft_isprint(ret))
|
||||||
ft_print(ret);
|
ft_print(ret);
|
||||||
else if (ret == 10)
|
else if (ret == 10)
|
||||||
return (data_singleton()->line.input);
|
return (STR);
|
||||||
else if (ft_isascii(ret) == 0)
|
else if (ft_isascii(ret) == 0)
|
||||||
ft_read_it(ret, &data_singleton()->line.pos,
|
ft_read_it(ret, &POS, &STR);
|
||||||
&data_singleton()->line.input);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,35 +6,67 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/19 16:42:54 by gwojda #+# #+# */
|
/* Created: 2016/12/19 16:42:54 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/03 12:08:45 by gwojda ### ########.fr */
|
/* Updated: 2017/02/04 15:17:19 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
void ft_found_prev_word(void)
|
static void ft_init_prev_word(size_t *pos, char *str)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *str;
|
|
||||||
size_t *pos;
|
|
||||||
|
|
||||||
str = data_singleton()->line.input;
|
|
||||||
pos = &data_singleton()->line.pos;
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if (!*pos)
|
|
||||||
return ;
|
|
||||||
if (str[*pos - 1] != '\n' && !(str[*pos] == '\n' || str[*pos] == ' '))
|
if (str[*pos - 1] != '\n' && !(str[*pos] == '\n' || str[*pos] == ' '))
|
||||||
{
|
{
|
||||||
ft_puttermcaps("le");
|
ft_puttermcaps("le");
|
||||||
--(*pos);
|
--(*pos);
|
||||||
}
|
}
|
||||||
while ((int)*pos - i - 1 > 0 && str[*pos - i - 1] == ' ')
|
while ((int)*pos - i - 1 > 0 && str[*pos - i - 1] == ' ')
|
||||||
{
|
{
|
||||||
ft_puttermcaps("le");
|
ft_puttermcaps("le");
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
(*pos) = (i && str[*pos - i] == '\n') ? *pos - i + 1 : *pos - i;
|
(*pos) = (i && str[*pos - i] == '\n') ? *pos - i + 1 : *pos - i;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ft_found_prev_word_2(int i, char *str, size_t *pos)
|
||||||
|
{
|
||||||
|
if (*pos && !(str[*pos] == '\n' || str[*pos] == ' '))
|
||||||
|
{
|
||||||
|
ft_puttermcaps("le");
|
||||||
|
--(*pos);
|
||||||
|
}
|
||||||
|
while (*pos - i && (str[*pos - i] == '\n' || str[*pos - i] == ' '))
|
||||||
|
{
|
||||||
|
ft_puttermcaps("le");
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
while (*pos - i && str[*pos - i] != '\n' && str[*pos - i] != ' ')
|
||||||
|
{
|
||||||
|
ft_puttermcaps("le");
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
if (str[*pos - i] == '\n' || str[*pos - i] == ' ')
|
||||||
|
{
|
||||||
|
ft_puttermcaps("nd");
|
||||||
|
++(*pos);
|
||||||
|
}
|
||||||
|
(*pos) -= i;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_found_prev_word(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char *str;
|
||||||
|
size_t *pos;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
|
str = STR;
|
||||||
|
pos = &POS;
|
||||||
|
if (!*pos || !str)
|
||||||
|
return ;
|
||||||
|
ft_init_prev_word(pos, str);
|
||||||
if (*pos >= 1 && str[*pos - 1] == '\n')
|
if (*pos >= 1 && str[*pos - 1] == '\n')
|
||||||
{
|
{
|
||||||
ft_puttermcaps("cd");
|
ft_puttermcaps("cd");
|
||||||
|
|
@ -46,40 +78,40 @@ void ft_found_prev_word(void)
|
||||||
++(*pos);
|
++(*pos);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
ft_found_prev_word_2(i, str, pos);
|
||||||
if (*pos && !(str[*pos] == '\n' || str[*pos] == ' '))
|
|
||||||
{
|
|
||||||
ft_puttermcaps("le");
|
|
||||||
--(*pos);
|
|
||||||
}
|
|
||||||
while (*pos - i && (str[*pos - i] == '\n' || str[*pos - i] == ' '))
|
|
||||||
{
|
|
||||||
ft_puttermcaps("le");
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
while (*pos - i && str[*pos - i] != '\n' && str[*pos - i] != ' ')
|
|
||||||
{
|
|
||||||
ft_puttermcaps("le");
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
if (str[*pos - i] == '\n' || str[*pos - i] == ' ')
|
|
||||||
{
|
|
||||||
ft_puttermcaps("nd");
|
|
||||||
++(*pos);
|
|
||||||
}
|
|
||||||
(*pos) -= i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_found_next_word(void)
|
static void ft_found_next_word_2(void)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
size_t *pos;
|
||||||
|
|
||||||
|
str = STR;
|
||||||
|
pos = &POS;
|
||||||
|
if (*pos)
|
||||||
|
{
|
||||||
|
--(*pos);
|
||||||
|
ft_get_beggin_with_curs(str, pos);
|
||||||
|
}
|
||||||
|
ft_puttermcaps("cd");
|
||||||
|
ft_get_next_str(str, pos);
|
||||||
|
(*pos) += (*pos) ? 2 : 1;
|
||||||
|
ft_current_str(str, *pos);
|
||||||
|
ft_get_next_str(str, pos);
|
||||||
|
if (!str[*pos])
|
||||||
|
--(*pos);
|
||||||
|
ft_get_beggin_with_curs(str, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_found_next_word(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *str;
|
char *str;
|
||||||
size_t *pos;
|
size_t *pos;
|
||||||
|
|
||||||
str = data_singleton()->line.input;
|
|
||||||
pos = &data_singleton()->line.pos;
|
|
||||||
i = 0;
|
i = 0;
|
||||||
|
str = STR;
|
||||||
|
pos = &POS;
|
||||||
if (!str)
|
if (!str)
|
||||||
return ;
|
return ;
|
||||||
while (str[i + *pos] && str[i + *pos] == ' ')
|
while (str[i + *pos] && str[i + *pos] == ' ')
|
||||||
|
|
@ -88,21 +120,7 @@ void ft_found_next_word(void)
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
if (str[*pos] == '\n')
|
if (str[*pos] == '\n')
|
||||||
{
|
ft_found_next_word_2();
|
||||||
if (*pos)
|
|
||||||
{
|
|
||||||
--(*pos);
|
|
||||||
ft_get_beggin_with_curs(str, pos);
|
|
||||||
}
|
|
||||||
ft_puttermcaps("cd");
|
|
||||||
ft_get_next_str(str, pos);
|
|
||||||
(*pos) += (*pos) ? 2 : 1;
|
|
||||||
ft_current_str(str, *pos);
|
|
||||||
ft_get_next_str(str, pos);
|
|
||||||
if (!str[*pos])
|
|
||||||
--(*pos);
|
|
||||||
ft_get_beggin_with_curs(str, pos);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
while (str[i + *pos] && str[i + *pos] != '\n' && str[i + *pos] != ' ')
|
while (str[i + *pos] && str[i + *pos] != '\n' && str[i + *pos] != ' ')
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/19 16:43:58 by gwojda #+# #+# */
|
/* Created: 2016/12/19 16:43:58 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/02 17:54:27 by gwojda ### ########.fr */
|
/* Updated: 2017/02/04 15:34:10 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -23,8 +23,8 @@ void ft_end(void)
|
||||||
char *str;
|
char *str;
|
||||||
size_t *pos;
|
size_t *pos;
|
||||||
|
|
||||||
str = data_singleton()->line.input;
|
str = STR;
|
||||||
pos = &data_singleton()->line.pos;
|
pos = &POS;
|
||||||
if (!str)
|
if (!str)
|
||||||
return ;
|
return ;
|
||||||
if (*pos)
|
if (*pos)
|
||||||
|
|
@ -45,8 +45,8 @@ void ft_home(void)
|
||||||
char *str;
|
char *str;
|
||||||
size_t *pos;
|
size_t *pos;
|
||||||
|
|
||||||
str = data_singleton()->line.input;
|
str = STR;
|
||||||
pos = &data_singleton()->line.pos;
|
pos = &POS;
|
||||||
if (!str)
|
if (!str)
|
||||||
return ;
|
return ;
|
||||||
if (*pos)
|
if (*pos)
|
||||||
|
|
@ -69,45 +69,40 @@ void ft_home(void)
|
||||||
void ft_move_right(void)
|
void ft_move_right(void)
|
||||||
{
|
{
|
||||||
size_t tmp;
|
size_t tmp;
|
||||||
char *str;
|
|
||||||
size_t *pos;
|
size_t *pos;
|
||||||
|
|
||||||
str = data_singleton()->line.input;
|
pos = &POS;
|
||||||
pos = &data_singleton()->line.pos;
|
if (ft_strlen(STR) <= *pos)
|
||||||
if (ft_strlen(str) <= *pos)
|
|
||||||
return ;
|
return ;
|
||||||
if (str[*pos] == '\n')
|
if (STR[*pos] == '\n')
|
||||||
{
|
{
|
||||||
if (*pos)
|
if (*pos)
|
||||||
{
|
{
|
||||||
tmp = *pos - 1;
|
tmp = *pos - 1;
|
||||||
ft_get_beggin_with_curs(str, &tmp);
|
ft_get_beggin_with_curs(STR, &tmp);
|
||||||
}
|
}
|
||||||
ft_puttermcaps("cd");
|
ft_puttermcaps("cd");
|
||||||
++(*pos);
|
++(*pos);
|
||||||
ft_current_str(str, *pos);
|
ft_current_str(STR, *pos);
|
||||||
ft_get_next_str(str, pos);
|
ft_get_next_str(STR, pos);
|
||||||
if (!str[*pos])
|
(*pos) = (!STR[*pos]) ? *pos - 1 : *pos;
|
||||||
--(*pos);
|
ft_get_beggin_with_curs(STR, pos);
|
||||||
ft_get_beggin_with_curs(str, pos);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ft_putchar(str[*pos]);
|
ft_putchar(STR[*pos]);
|
||||||
++(*pos);
|
++(*pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_move_left(void)
|
void ft_move_left(void)
|
||||||
{
|
{
|
||||||
char *str;
|
|
||||||
size_t *pos;
|
size_t *pos;
|
||||||
|
|
||||||
str = data_singleton()->line.input;
|
pos = &POS;
|
||||||
pos = &data_singleton()->line.pos;
|
|
||||||
if (!*pos)
|
if (!*pos)
|
||||||
return ;
|
return ;
|
||||||
if (str[*pos - 1] == '\n')
|
if (STR[*pos - 1] == '\n')
|
||||||
{
|
{
|
||||||
if (*pos - 1 == 0)
|
if (*pos - 1 == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -117,9 +112,9 @@ void ft_move_left(void)
|
||||||
}
|
}
|
||||||
ft_puttermcaps("cd");
|
ft_puttermcaps("cd");
|
||||||
(*pos) -= 2;
|
(*pos) -= 2;
|
||||||
ft_get_beggin(str, pos);
|
ft_get_beggin(STR, pos);
|
||||||
ft_current_str(str, *pos);
|
ft_current_str(STR, *pos);
|
||||||
ft_get_next_str(str, pos);
|
ft_get_next_str(STR, pos);
|
||||||
++(*pos);
|
++(*pos);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -6,23 +6,17 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/02 15:22:19 by gwojda #+# #+# */
|
/* Created: 2017/02/02 15:22:19 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/03 11:55:36 by gwojda ### ########.fr */
|
/* Updated: 2017/02/04 15:20:49 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
void ft_history_down(void)
|
static void ft_clear_before_history(char **str)
|
||||||
{
|
{
|
||||||
t_list_history *head;
|
|
||||||
char **str;
|
|
||||||
size_t *pos;
|
size_t *pos;
|
||||||
|
|
||||||
str = &data_singleton()->line.input;
|
pos = &POS;
|
||||||
pos = &data_singleton()->line.pos;
|
|
||||||
head = data_singleton()->line.list_cur;
|
|
||||||
if (!head)
|
|
||||||
return ;
|
|
||||||
if (*str)
|
if (*str)
|
||||||
{
|
{
|
||||||
if (*pos)
|
if (*pos)
|
||||||
|
|
@ -34,6 +28,20 @@ void ft_history_down(void)
|
||||||
*pos = 0;
|
*pos = 0;
|
||||||
ft_strdel(str);
|
ft_strdel(str);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_history_down(void)
|
||||||
|
{
|
||||||
|
t_list_history *head;
|
||||||
|
char **str;
|
||||||
|
size_t *pos;
|
||||||
|
|
||||||
|
str = &STR;
|
||||||
|
pos = &POS;
|
||||||
|
head = data_singleton()->line.list_cur;
|
||||||
|
if (!head)
|
||||||
|
return ;
|
||||||
|
ft_clear_before_history(str);
|
||||||
if (head->next)
|
if (head->next)
|
||||||
head = head->next;
|
head = head->next;
|
||||||
if (!head->str)
|
if (!head->str)
|
||||||
|
|
@ -55,22 +63,12 @@ void ft_history_up(void)
|
||||||
char **str;
|
char **str;
|
||||||
size_t *pos;
|
size_t *pos;
|
||||||
|
|
||||||
str = &data_singleton()->line.input;
|
str = &STR;
|
||||||
pos = &data_singleton()->line.pos;
|
pos = &POS;
|
||||||
head = data_singleton()->line.list_cur;
|
head = data_singleton()->line.list_cur;
|
||||||
if (!head)
|
if (!head)
|
||||||
return ;
|
return ;
|
||||||
if (*str)
|
ft_clear_before_history(str);
|
||||||
{
|
|
||||||
if (*pos)
|
|
||||||
{
|
|
||||||
--(*pos);
|
|
||||||
ft_get_beggin_with_curs(*str, pos);
|
|
||||||
}
|
|
||||||
ft_puttermcaps("cd");
|
|
||||||
*pos = 0;
|
|
||||||
ft_strdel(str);
|
|
||||||
}
|
|
||||||
if (head->prev)
|
if (head->prev)
|
||||||
head = head->prev;
|
head = head->prev;
|
||||||
if (!head->str)
|
if (!head->str)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/25 11:39:47 by gwojda #+# #+# */
|
/* Created: 2017/01/25 11:39:47 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/03 17:57:21 by gwojda ### ########.fr */
|
/* Updated: 2017/02/04 15:35:25 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
static int ft_history_parsing_4(char *str, int *i)
|
static int ft_history_parsing_4(char *str, int *i)
|
||||||
{
|
{
|
||||||
int tmp;
|
int tmp;
|
||||||
|
|
||||||
if (!ft_strncmp("!!", str + *i, 2))
|
if (!ft_strncmp("!!", str + *i, 2))
|
||||||
{
|
{
|
||||||
ft_realloc_str_history(&(data_singleton()->line.input), *i, 0, 2);
|
ft_realloc_str_history(&(data_singleton()->line.input), *i, 0, 2);
|
||||||
|
|
@ -35,6 +36,7 @@ static int ft_history_parsing_4(char *str, int *i)
|
||||||
static int ft_history_parsing_3(char *str, int *i)
|
static int ft_history_parsing_3(char *str, int *i)
|
||||||
{
|
{
|
||||||
int tmp;
|
int tmp;
|
||||||
|
|
||||||
if (ft_history_parsing_4(str, i))
|
if (ft_history_parsing_4(str, i))
|
||||||
return (1);
|
return (1);
|
||||||
else if (str[*i + 1] == '-' && ft_isdigit(str[*i + 2]))
|
else if (str[*i + 1] == '-' && ft_isdigit(str[*i + 2]))
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/09 13:21:40 by gwojda #+# #+# */
|
/* Created: 2017/01/09 13:21:40 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/02 15:07:08 by gwojda ### ########.fr */
|
/* Updated: 2017/02/04 15:36:25 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -38,9 +38,9 @@ static void ft_up_2(size_t *pos, char *str)
|
||||||
(*pos) -= i;
|
(*pos) -= i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_up(void)
|
void ft_up(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *str;
|
char *str;
|
||||||
size_t *pos;
|
size_t *pos;
|
||||||
|
|
||||||
|
|
@ -79,10 +79,10 @@ static void ft_down_2(size_t *pos, char *str)
|
||||||
ft_get_beggin_with_curs(str, pos);
|
ft_get_beggin_with_curs(str, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_down(void)
|
void ft_down(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int len;
|
int len;
|
||||||
char *str;
|
char *str;
|
||||||
size_t *pos;
|
size_t *pos;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */
|
/* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/03 15:52:53 by jhalford ### ########.fr */
|
/* Updated: 2017/02/04 14:56:51 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -55,9 +55,6 @@ void ft_prompt(void)
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
do_job_notification();
|
do_job_notification();
|
||||||
// yo gwojda enlève pas ca, je fait des notif de
|
|
||||||
// job control juste avant que tu mette ton prompt.
|
|
||||||
|
|
||||||
ft_get_date();
|
ft_get_date();
|
||||||
ft_putstr("\033[22;36m");
|
ft_putstr("\033[22;36m");
|
||||||
ret = ft_currend_dir();
|
ret = ft_currend_dir();
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/19 16:52:57 by gwojda #+# #+# */
|
/* Created: 2016/12/19 16:52:57 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/03 18:24:47 by gwojda ### ########.fr */
|
/* Updated: 2017/02/04 15:37:55 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -57,15 +57,15 @@ void ft_read_it(int input, size_t *pos, char **str)
|
||||||
j = 0;
|
j = 0;
|
||||||
pos_tmp = *pos;
|
pos_tmp = *pos;
|
||||||
if (input == TOUCHE_DELETE || input < 0 || input == 892427035 ||
|
if (input == TOUCHE_DELETE || input < 0 || input == 892427035 ||
|
||||||
input == 126 || input == 993090331 || input == 925981467 ||
|
input == 126 || input == 993090331 || input == 925981467 ||
|
||||||
input == 21298 || input == 892427035 || input == 8270395 ||
|
input == 21298 || input == 892427035 || input == 8270395 || input ==
|
||||||
input == 942758683 || input == 993090331 || input == 18489 || input == 17977)
|
942758683 || input == 993090331 || input == 18489 || input == 17977)
|
||||||
return ;
|
return ;
|
||||||
ft_read_it_2(input, t);
|
ft_read_it_2(input, t);
|
||||||
ft_read_it_3(str, t, pos, &j);
|
ft_read_it_3(str, t, pos, &j);
|
||||||
*pos = pos_tmp;
|
*pos = pos_tmp;
|
||||||
ft_current_str((*str), *pos);
|
ft_current_str((*str), *pos);
|
||||||
ft_get_next_str((*str), pos);
|
ft_get_next_str((*str), pos);
|
||||||
ft_putnc('\b', *pos - (pos_tmp + j) + 1);
|
ft_putnc('\b', *pos - (pos_tmp + j));
|
||||||
*pos = (pos_tmp + j);
|
*pos = (pos_tmp + j);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,13 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
|
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/03 18:36:18 by gwojda ### ########.fr */
|
/* Updated: 2017/02/04 16:19:36 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
void ft_init_line(void)
|
void ft_init_line(void)
|
||||||
{
|
{
|
||||||
data_singleton()->line.input = NULL;
|
data_singleton()->line.input = NULL;
|
||||||
data_singleton()->line.copy_tmp = NULL;
|
data_singleton()->line.copy_tmp = NULL;
|
||||||
|
|
@ -24,7 +24,7 @@ void ft_init_line(void)
|
||||||
data_singleton()->line.opt = 0;
|
data_singleton()->line.opt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_init_history(void)
|
void ft_init_history(void)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
char *str;
|
char *str;
|
||||||
|
|
@ -71,27 +71,27 @@ struct termios *ft_stats_term_termcaps(void)
|
||||||
return (term);
|
return (term);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_readline(void)
|
int ft_readline(void)
|
||||||
{
|
{
|
||||||
ft_save_stats_term();
|
ft_save_stats_term();
|
||||||
if (tcsetattr(0, TCSANOW, ft_stats_term_termcaps()) == -1)
|
if (tcsetattr(0, TCSANOW, ft_stats_term_termcaps()) == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
if (data_singleton()->line.input)
|
if (STR)
|
||||||
ft_strdel(&data_singleton()->line.input);
|
ft_strdel(&STR);
|
||||||
data_singleton()->line.list_cur = data_singleton()->line.list_beg;
|
data_singleton()->line.list_cur = data_singleton()->line.list_beg;
|
||||||
data_singleton()->line.pos = 0;
|
POS = 0;
|
||||||
ft_prompt();
|
ft_prompt();
|
||||||
data_singleton()->line.input = ft_read_stdin();
|
STR = ft_read_stdin();
|
||||||
ft_check_line();
|
ft_check_line();
|
||||||
ft_putchar('\n');
|
ft_putchar('\n');
|
||||||
ft_check_heredoc(&data_singleton()->line.input);
|
ft_check_heredoc(&STR);
|
||||||
ft_history_parsing();
|
ft_history_parsing();
|
||||||
if (data_singleton()->line.input && (!data_singleton()->line.list_beg ||
|
if (STR && (!data_singleton()->line.list_beg ||
|
||||||
ft_strcmp(data_singleton()->line.list_beg->prev->str, data_singleton()->line.input)))
|
ft_strcmp(data_singleton()->line.list_beg->prev->str, STR)))
|
||||||
{
|
{
|
||||||
ft_push_back_history(&data_singleton()->line.list_beg,
|
ft_push_back_history(&data_singleton()->line.list_beg,
|
||||||
ft_create_history_list(data_singleton()->line.input));
|
ft_create_history_list(STR));
|
||||||
ft_add_in_history_file(data_singleton()->line.input);
|
ft_add_in_history_file(STR);
|
||||||
}
|
}
|
||||||
if (tcsetattr(0, TCSANOW, ft_save_stats_term()) == -1)
|
if (tcsetattr(0, TCSANOW, ft_save_stats_term()) == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,13 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/26 10:43:16 by gwojda #+# #+# */
|
/* Created: 2017/01/26 10:43:16 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/02 15:16:42 by gwojda ### ########.fr */
|
/* Updated: 2017/02/04 15:50:26 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
void ft_clear_prompt(char *str, size_t *pos, size_t srch_pos)
|
static void ft_clear_prompt(char *str, size_t *pos, size_t srch_pos)
|
||||||
{
|
{
|
||||||
if (str)
|
if (str)
|
||||||
ft_get_beggin_with_curs(str, pos);
|
ft_get_beggin_with_curs(str, pos);
|
||||||
|
|
@ -25,63 +25,68 @@ void ft_clear_prompt(char *str, size_t *pos, size_t srch_pos)
|
||||||
ft_puttermcaps("cd");
|
ft_puttermcaps("cd");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_surch_and_realloc(char **str, char **str_srch, int ret, size_t *srch_pos)
|
static void ft_surch_and_realloc(char **str, char **str_srch,
|
||||||
|
int ret, size_t *srch_pos)
|
||||||
{
|
{
|
||||||
*str_srch = ft_realloc_imput(*str_srch, ret, *srch_pos);
|
*str_srch = ft_realloc_imput(*str_srch, ret, *srch_pos);
|
||||||
++(*srch_pos);
|
++(*srch_pos);
|
||||||
*str = ft_strget_history(*str_srch);
|
*str = ft_strget_history(*str_srch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_surch_in_history(void)
|
static void ft_give_new_prompt(char *str_srch, size_t srch_pos)
|
||||||
|
{
|
||||||
|
ft_clear_prompt(STR, &POS, srch_pos);
|
||||||
|
data_singleton()->line.prompt_size = 21;
|
||||||
|
if (str_srch)
|
||||||
|
ft_printf("\033[35m(reverse-i-search)`\033[32m%s\033[35m': \033[37m",
|
||||||
|
str_srch);
|
||||||
|
else
|
||||||
|
ft_putstr("\033[35m(reverse-i-search)`': \033[37m");
|
||||||
|
if (STR)
|
||||||
|
{
|
||||||
|
ft_current_str(STR, POS);
|
||||||
|
ft_get_next_str(STR, &POS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ft_modify_str(char *str_srch, size_t srch_pos)
|
||||||
|
{
|
||||||
|
ft_clear_prompt(STR, &POS, srch_pos);
|
||||||
|
ft_prompt();
|
||||||
|
if (STR)
|
||||||
|
{
|
||||||
|
STR = ft_strdup(STR);
|
||||||
|
ft_current_str(STR, POS);
|
||||||
|
ft_get_next_str(STR, &POS);
|
||||||
|
}
|
||||||
|
free(str_srch);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_surch_in_history(void)
|
||||||
{
|
{
|
||||||
char *str_srch;
|
char *str_srch;
|
||||||
int ret;
|
int ret;
|
||||||
size_t srch_pos;
|
size_t srch_pos;
|
||||||
char **str;
|
|
||||||
size_t *pos;
|
|
||||||
|
|
||||||
str = &data_singleton()->line.input;
|
|
||||||
pos = &data_singleton()->line.pos;
|
|
||||||
srch_pos = 0;
|
srch_pos = 0;
|
||||||
str_srch = NULL;
|
str_srch = NULL;
|
||||||
if (*str)
|
if (STR)
|
||||||
ft_strdel(str);
|
ft_strdel(&STR);
|
||||||
while (42)
|
while (42)
|
||||||
{
|
{
|
||||||
ft_clear_prompt(*str, pos, srch_pos);
|
ft_give_new_prompt(str_srch, srch_pos);
|
||||||
data_singleton()->line.prompt_size = 21;
|
|
||||||
if (str_srch)
|
|
||||||
ft_printf("\033[35m(reverse-i-search)`\033[32m%s\033[35m': \033[37m", str_srch);
|
|
||||||
else
|
|
||||||
ft_putstr("\033[35m(reverse-i-search)`': \033[37m");
|
|
||||||
if (*str)
|
|
||||||
{
|
|
||||||
ft_current_str(*str, *pos);
|
|
||||||
ft_get_next_str(*str, pos);
|
|
||||||
}
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
read(0, &ret, sizeof(int));
|
read(0, &ret, sizeof(int));
|
||||||
if (ft_isprint(ret))
|
if (ft_isprint(ret))
|
||||||
ft_surch_and_realloc(str, &str_srch, ret, &srch_pos);
|
ft_surch_and_realloc(&STR, &str_srch, ret, &srch_pos);
|
||||||
else if (ret == 127)
|
else if (ret == 127 && srch_pos)
|
||||||
{
|
{
|
||||||
if (srch_pos)
|
--srch_pos;
|
||||||
{
|
str_srch = ft_remove_imput(str_srch, srch_pos);
|
||||||
--srch_pos;
|
ft_puttermcaps("le");
|
||||||
str_srch = ft_remove_imput(str_srch, srch_pos);
|
|
||||||
ft_puttermcaps("le");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else if (ret != 127)
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
ft_clear_prompt(*str, pos, srch_pos);
|
ft_modify_str(str_srch, srch_pos);
|
||||||
ft_prompt();
|
|
||||||
if (*str)
|
|
||||||
{
|
|
||||||
*str = ft_strdup(*str);
|
|
||||||
ft_current_str(*str, *pos);
|
|
||||||
ft_get_next_str(*str, pos);
|
|
||||||
}
|
|
||||||
free(str_srch);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,17 +6,19 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/20 19:07:52 by gwojda #+# #+# */
|
/* Created: 2017/01/20 19:07:52 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/02 14:16:24 by gwojda ### ########.fr */
|
/* Updated: 2017/02/04 16:27:34 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
static void ft_clear_window()
|
static void ft_clear_window(void)
|
||||||
{
|
{
|
||||||
pid_t soon_pid;
|
pid_t soon_pid;
|
||||||
char *tab_str[2] = {(char *){"/usr/bin/clear"}, NULL};
|
char *tab_str[2];
|
||||||
|
|
||||||
|
tab_str[0] = "/usr/bin/clear";
|
||||||
|
tab_str[1] = NULL;
|
||||||
soon_pid = fork();
|
soon_pid = fork();
|
||||||
if (soon_pid != 0)
|
if (soon_pid != 0)
|
||||||
wait(NULL);
|
wait(NULL);
|
||||||
|
|
@ -24,25 +26,10 @@ static void ft_clear_window()
|
||||||
execve("/usr/bin/clear", tab_str, data_singleton()->env);
|
execve("/usr/bin/clear", tab_str, data_singleton()->env);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_printall(void)
|
static void ft_read_tmp(void)
|
||||||
{
|
{
|
||||||
size_t pos_tmp;
|
int ret;
|
||||||
int ret;
|
|
||||||
char *str;
|
|
||||||
size_t *pos;
|
|
||||||
|
|
||||||
str = data_singleton()->line.input;
|
|
||||||
pos = &data_singleton()->line.pos;
|
|
||||||
ret = 0;
|
|
||||||
if (read(0, &ret, sizeof(int)) == -1 || ret != 126 || !str)
|
|
||||||
return ;
|
|
||||||
ft_clear_window();
|
|
||||||
ft_prompt();
|
|
||||||
pos_tmp = *pos;
|
|
||||||
ft_putstr("\033[31m");
|
|
||||||
ft_puttermcaps("cd");
|
|
||||||
ft_puttermcaps("sc");
|
|
||||||
ft_putstr(str);
|
|
||||||
while (42)
|
while (42)
|
||||||
{
|
{
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
@ -54,9 +41,36 @@ void ft_printall(void)
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_change_affichage(void)
|
||||||
|
{
|
||||||
|
ft_putstr("\033[31m");
|
||||||
|
ft_puttermcaps("cd");
|
||||||
|
ft_puttermcaps("sc");
|
||||||
|
ft_putstr(STR);
|
||||||
|
ft_read_tmp();
|
||||||
ft_puttermcaps("rc");
|
ft_puttermcaps("rc");
|
||||||
ft_puttermcaps("cd");
|
ft_puttermcaps("cd");
|
||||||
ft_putstr("\033[37m");
|
ft_putstr("\033[37m");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_printall(void)
|
||||||
|
{
|
||||||
|
size_t pos_tmp;
|
||||||
|
char *str;
|
||||||
|
size_t *pos;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
str = STR;
|
||||||
|
pos = &POS;
|
||||||
|
ret = 0;
|
||||||
|
if (read(0, &ret, sizeof(int)) == -1 || ret != 126 || !str)
|
||||||
|
return ;
|
||||||
|
ft_clear_window();
|
||||||
|
ft_prompt();
|
||||||
|
pos_tmp = *pos;
|
||||||
|
ft_change_affichage();
|
||||||
if (*pos)
|
if (*pos)
|
||||||
--(*pos);
|
--(*pos);
|
||||||
ft_get_beggin(str, pos);
|
ft_get_beggin(str, pos);
|
||||||
|
|
@ -69,18 +83,7 @@ void ft_printall(void)
|
||||||
*pos = pos_tmp;
|
*pos = pos_tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_check_end_of_line(char *str, size_t pos)
|
void ft_get_beggin_with_curs(char *str, size_t *pos)
|
||||||
{
|
|
||||||
if (!str)
|
|
||||||
return ;
|
|
||||||
if (ft_nb_last_line(str, pos) == 0)
|
|
||||||
{
|
|
||||||
ft_putchar(' ');
|
|
||||||
ft_puttermcaps("le");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_get_beggin_with_curs(char *str, size_t *pos)
|
|
||||||
{
|
{
|
||||||
while ((*pos) && str[(*pos)] != '\n')
|
while ((*pos) && str[(*pos)] != '\n')
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/16 17:06:30 by gwojda #+# #+# */
|
/* Created: 2016/12/16 17:06:30 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/02 16:22:47 by gwojda ### ########.fr */
|
/* Updated: 2017/02/04 16:19:49 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -43,7 +43,7 @@ char *ft_strndup(char const *s, int n)
|
||||||
return (str);
|
return (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ft_strdupi(char const *s)
|
char *ft_strdupi(char const *s)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *str;
|
char *str;
|
||||||
|
|
|
||||||
|
|
@ -6,17 +6,18 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/07 11:00:28 by gwojda #+# #+# */
|
/* Created: 2017/01/07 11:00:28 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/02 16:04:55 by gwojda ### ########.fr */
|
/* Updated: 2017/02/04 16:20:11 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
void ft_add_in_history_file(char *str)
|
void ft_add_in_history_file(char *str)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = open(".42sh_history", O_CREAT | O_WRONLY | O_APPEND, S_IWUSR | S_IRUSR);
|
fd = open(".42sh_history",
|
||||||
|
O_CREAT | O_WRONLY | O_APPEND, S_IWUSR | S_IRUSR);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
return ;
|
return ;
|
||||||
write(fd, str, ft_strlen(str));
|
write(fd, str, ft_strlen(str));
|
||||||
|
|
@ -24,7 +25,7 @@ void ft_add_in_history_file(char *str)
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_nbr_len(int nbr)
|
int ft_nbr_len(int nbr)
|
||||||
{
|
{
|
||||||
if (nbr % 10 != nbr)
|
if (nbr % 10 != nbr)
|
||||||
return (ft_nbr_len(nbr / 10) + 1);
|
return (ft_nbr_len(nbr / 10) + 1);
|
||||||
|
|
@ -32,7 +33,7 @@ int ft_nbr_len(int nbr)
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_puttermcaps(char *str)
|
void ft_puttermcaps(char *str)
|
||||||
{
|
{
|
||||||
char *res;
|
char *res;
|
||||||
char *env;
|
char *env;
|
||||||
|
|
@ -43,7 +44,7 @@ void ft_puttermcaps(char *str)
|
||||||
tputs(res, 0, ft_put);
|
tputs(res, 0, ft_put);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_size_term(void)
|
int ft_size_term(void)
|
||||||
{
|
{
|
||||||
struct winsize w;
|
struct winsize w;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/08 12:35:11 by gwojda #+# #+# */
|
/* Created: 2017/01/08 12:35:11 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/01/24 11:19:34 by gwojda ### ########.fr */
|
/* Updated: 2017/02/04 16:26:55 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -43,3 +43,14 @@ int ft_nb_last_line(char *str, size_t pos)
|
||||||
len += ft_get_size_prev(str, pos);
|
len += ft_get_size_prev(str, pos);
|
||||||
return ((len) ? len % ft_size_term() : -1);
|
return ((len) ? len % ft_size_term() : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ft_check_end_of_line(char *str, size_t pos)
|
||||||
|
{
|
||||||
|
if (!str)
|
||||||
|
return ;
|
||||||
|
if (ft_nb_last_line(str, pos) == 0)
|
||||||
|
{
|
||||||
|
ft_putchar(' ');
|
||||||
|
ft_puttermcaps("le");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/10 11:36:39 by jhalford #+# #+# */
|
/* Created: 2017/01/10 11:36:39 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/03 15:25:13 by gwojda ### ########.fr */
|
/* Updated: 2017/02/04 10:55:39 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue