mise a la norme edition de ligne - heredoc mal géré

This commit is contained in:
gwojda 2017-02-04 16:29:28 +01:00
parent 08710f9e6b
commit 288acbb378
19 changed files with 279 additions and 245 deletions

View file

@ -6,7 +6,7 @@
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# 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 #
# #
# **************************************************************************** #

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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_BSLASH (1 << 5)
# define STR data_singleton()->line.input
# define POS data_singleton()->line.pos
# define HIST 1
# define ERROR_CNTL_R 1
@ -88,7 +91,6 @@ typedef struct s_line
{
char *input;
char *copy_tmp;
char *input_tmp;
size_t pos;
int prompt_size;
int list_size;

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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[] =
{
{IS_QUOTES ,SIZE_PROMPT_QUOTES ,PROMPT_QUOTES},
{IS_BQUOTES ,SIZE_PROMPT_BQUOTES ,PROMPT_BQUOTES},
{IS_DQUOTES ,SIZE_PROMPT_DQUOTES ,PROMPT_DQUOTES},
{IS_ACCOLADE ,SIZE_PROMPT_ACCOLADE ,PROMPT_ACCOLADE},
{IS_BRACKET ,SIZE_PROMPT_BRACKET ,PROMPT_BRACKET},
{IS_BSLASH ,SIZE_PROMPT_BSLASH ,PROMPT_BSLASH},
{0 ,0 ,0},
{IS_QUOTES, SIZE_PROMPT_QUOTES, PROMPT_QUOTES},
{IS_BQUOTES, SIZE_PROMPT_BQUOTES, PROMPT_BQUOTES},
{IS_DQUOTES, SIZE_PROMPT_DQUOTES, PROMPT_DQUOTES},
{IS_ACCOLADE, SIZE_PROMPT_ACCOLADE, PROMPT_ACCOLADE},
{IS_BRACKET, SIZE_PROMPT_BRACKET, PROMPT_BRACKET},
{IS_BSLASH, SIZE_PROMPT_BSLASH, PROMPT_BSLASH},
{0, 0, 0},
};
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)
{
int i;
char stats[] = {'\'', '`', '\"', '{', '(', '\\', '\0'};
char *stats;
i = 0;
stats = "\'`\"{(\\";
while (stats[i] && stats[i] != c)
++i;
if (!stats[i])

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */
@ -45,17 +45,14 @@ void ft_v(void)
size_t *pos;
tmp = data_singleton()->line.copy_tmp;
str = &data_singleton()->line.input;
pos = &data_singleton()->line.pos;
i = 0;
str = &STR;
pos = &POS;
i = -1;
tmp_pos = *pos;
if (!*str || !tmp)
return ;
while (tmp[i])
{
while (tmp[++i])
*str = ft_realloc_imput(*str, tmp[i], *pos + i);
++i;
}
if (*pos)
{
--(*pos);
@ -75,8 +72,8 @@ void ft_x(void)
size_t *pos;
tmp = &data_singleton()->line.copy_tmp;
str = &data_singleton()->line.input;
pos = &data_singleton()->line.pos;
str = &STR;
pos = &POS;
if (!*str)
return ;
if (*tmp)
@ -98,8 +95,8 @@ void ft_c(void)
size_t *pos;
tmp = data_singleton()->line.copy_tmp;
str = &data_singleton()->line.input;
pos = &data_singleton()->line.pos;
str = &STR;
pos = &POS;
if (tmp)
ft_strdel(&tmp);
tmp = ft_strdupi_space((*str) + (*pos));

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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_CTRL_C , &ft_control_c },
{TOUCHE_CTRL_D , &ft_control_d },
{TOUCHE_CTRL_R , &ft_history_parsing },
{TOUCHE_CTRL_R , &ft_surch_in_history },
{TOUCHE_SUPPR , &ft_suppr },
{TOUCHE_HOME , &ft_home },
{TOUCHE_END , &ft_end },
@ -37,18 +37,23 @@ t_key g_key[] =
{0 , 0 },
};
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 j;
if (data_singleton()->line.input)
{
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);
}
ft_is_str();
if (data_singleton()->comp)
c_clear(data_singleton());
while (42)
@ -65,9 +70,8 @@ char *ft_read_stdin(void)
else if (ft_isprint(ret))
ft_print(ret);
else if (ret == 10)
return (data_singleton()->line.input);
return (STR);
else if (ft_isascii(ret) == 0)
ft_read_it(ret, &data_singleton()->line.pos,
&data_singleton()->line.input);
ft_read_it(ret, &POS, &STR);
}
}

View file

@ -6,23 +6,17 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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"
void ft_found_prev_word(void)
static void ft_init_prev_word(size_t *pos, char *str)
{
int i;
char *str;
size_t *pos;
str = data_singleton()->line.input;
pos = &data_singleton()->line.pos;
i = 0;
if (!*pos)
return ;
if (str[*pos - 1] != '\n' && !(str[*pos] == '\n' || str[*pos] == ' '))
{
ft_puttermcaps("le");
@ -34,19 +28,10 @@ void ft_found_prev_word(void)
++i;
}
(*pos) = (i && str[*pos - i] == '\n') ? *pos - i + 1 : *pos - i;
i = 0;
if (*pos >= 1 && str[*pos - 1] == '\n')
{
ft_puttermcaps("cd");
if (*pos >= 2)
(*pos) -= 2;
ft_get_beggin(str, pos);
ft_current_str(str, *pos);
ft_get_next_str(str, pos);
++(*pos);
}
else
{
}
static void ft_found_prev_word_2(int i, char *str, size_t *pos)
{
if (*pos && !(str[*pos] == '\n' || str[*pos] == ' '))
{
ft_puttermcaps("le");
@ -68,27 +53,41 @@ void ft_found_prev_word(void)
++(*pos);
}
(*pos) -= i;
}
}
void ft_found_next_word(void)
void ft_found_prev_word(void)
{
int i;
char *str;
size_t *pos;
str = data_singleton()->line.input;
pos = &data_singleton()->line.pos;
i = 0;
if (!str)
str = STR;
pos = &POS;
if (!*pos || !str)
return ;
while (str[i + *pos] && str[i + *pos] == ' ')
ft_init_prev_word(pos, str);
if (*pos >= 1 && str[*pos - 1] == '\n')
{
ft_putchar(str[i + *pos]);
++i;
ft_puttermcaps("cd");
if (*pos >= 2)
(*pos) -= 2;
ft_get_beggin(str, pos);
ft_current_str(str, *pos);
ft_get_next_str(str, pos);
++(*pos);
}
if (str[*pos] == '\n')
{
else
ft_found_prev_word_2(i, str, pos);
}
static void ft_found_next_word_2(void)
{
char *str;
size_t *pos;
str = STR;
pos = &POS;
if (*pos)
{
--(*pos);
@ -102,7 +101,26 @@ void ft_found_next_word(void)
if (!str[*pos])
--(*pos);
ft_get_beggin_with_curs(str, pos);
}
void ft_found_next_word(void)
{
int i;
char *str;
size_t *pos;
i = 0;
str = STR;
pos = &POS;
if (!str)
return ;
while (str[i + *pos] && str[i + *pos] == ' ')
{
ft_putchar(str[i + *pos]);
++i;
}
if (str[*pos] == '\n')
ft_found_next_word_2();
else
{
while (str[i + *pos] && str[i + *pos] != '\n' && str[i + *pos] != ' ')

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
size_t *pos;
str = data_singleton()->line.input;
pos = &data_singleton()->line.pos;
str = STR;
pos = &POS;
if (!str)
return ;
if (*pos)
@ -45,8 +45,8 @@ void ft_home(void)
char *str;
size_t *pos;
str = data_singleton()->line.input;
pos = &data_singleton()->line.pos;
str = STR;
pos = &POS;
if (!str)
return ;
if (*pos)
@ -69,45 +69,40 @@ void ft_home(void)
void ft_move_right(void)
{
size_t tmp;
char *str;
size_t *pos;
str = data_singleton()->line.input;
pos = &data_singleton()->line.pos;
if (ft_strlen(str) <= *pos)
pos = &POS;
if (ft_strlen(STR) <= *pos)
return ;
if (str[*pos] == '\n')
if (STR[*pos] == '\n')
{
if (*pos)
{
tmp = *pos - 1;
ft_get_beggin_with_curs(str, &tmp);
ft_get_beggin_with_curs(STR, &tmp);
}
ft_puttermcaps("cd");
++(*pos);
ft_current_str(str, *pos);
ft_get_next_str(str, pos);
if (!str[*pos])
--(*pos);
ft_get_beggin_with_curs(str, pos);
ft_current_str(STR, *pos);
ft_get_next_str(STR, pos);
(*pos) = (!STR[*pos]) ? *pos - 1 : *pos;
ft_get_beggin_with_curs(STR, pos);
}
else
{
ft_putchar(str[*pos]);
ft_putchar(STR[*pos]);
++(*pos);
}
}
void ft_move_left(void)
{
char *str;
size_t *pos;
str = data_singleton()->line.input;
pos = &data_singleton()->line.pos;
pos = &POS;
if (!*pos)
return ;
if (str[*pos - 1] == '\n')
if (STR[*pos - 1] == '\n')
{
if (*pos - 1 == 0)
{
@ -117,9 +112,9 @@ void ft_move_left(void)
}
ft_puttermcaps("cd");
(*pos) -= 2;
ft_get_beggin(str, pos);
ft_current_str(str, *pos);
ft_get_next_str(str, pos);
ft_get_beggin(STR, pos);
ft_current_str(STR, *pos);
ft_get_next_str(STR, pos);
++(*pos);
}
else

View file

@ -6,23 +6,17 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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"
void ft_history_down(void)
static void ft_clear_before_history(char **str)
{
t_list_history *head;
char **str;
size_t *pos;
str = &data_singleton()->line.input;
pos = &data_singleton()->line.pos;
head = data_singleton()->line.list_cur;
if (!head)
return ;
pos = &POS;
if (*str)
{
if (*pos)
@ -34,6 +28,20 @@ void ft_history_down(void)
*pos = 0;
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)
head = head->next;
if (!head->str)
@ -55,22 +63,12 @@ void ft_history_up(void)
char **str;
size_t *pos;
str = &data_singleton()->line.input;
pos = &data_singleton()->line.pos;
str = &STR;
pos = &POS;
head = data_singleton()->line.list_cur;
if (!head)
return ;
if (*str)
{
if (*pos)
{
--(*pos);
ft_get_beggin_with_curs(*str, pos);
}
ft_puttermcaps("cd");
*pos = 0;
ft_strdel(str);
}
ft_clear_before_history(str);
if (head->prev)
head = head->prev;
if (!head->str)

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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)
{
int tmp;
if (!ft_strncmp("!!", str + *i, 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)
{
int tmp;
if (ft_history_parsing_4(str, i))
return (1);
else if (str[*i + 1] == '-' && ft_isdigit(str[*i + 2]))

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
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_putstr("\033[22;36m");
ret = ft_currend_dir();

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */
@ -58,14 +58,14 @@ void ft_read_it(int input, size_t *pos, char **str)
pos_tmp = *pos;
if (input == TOUCHE_DELETE || input < 0 || input == 892427035 ||
input == 126 || input == 993090331 || input == 925981467 ||
input == 21298 || input == 892427035 || input == 8270395 ||
input == 942758683 || input == 993090331 || input == 18489 || input == 17977)
input == 21298 || input == 892427035 || input == 8270395 || input ==
942758683 || input == 993090331 || input == 18489 || input == 17977)
return ;
ft_read_it_2(input, t);
ft_read_it_3(str, t, pos, &j);
*pos = pos_tmp;
ft_current_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);
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */
@ -76,22 +76,22 @@ int ft_readline(void)
ft_save_stats_term();
if (tcsetattr(0, TCSANOW, ft_stats_term_termcaps()) == -1)
return (-1);
if (data_singleton()->line.input)
ft_strdel(&data_singleton()->line.input);
if (STR)
ft_strdel(&STR);
data_singleton()->line.list_cur = data_singleton()->line.list_beg;
data_singleton()->line.pos = 0;
POS = 0;
ft_prompt();
data_singleton()->line.input = ft_read_stdin();
STR = ft_read_stdin();
ft_check_line();
ft_putchar('\n');
ft_check_heredoc(&data_singleton()->line.input);
ft_check_heredoc(&STR);
ft_history_parsing();
if (data_singleton()->line.input && (!data_singleton()->line.list_beg ||
ft_strcmp(data_singleton()->line.list_beg->prev->str, data_singleton()->line.input)))
if (STR && (!data_singleton()->line.list_beg ||
ft_strcmp(data_singleton()->line.list_beg->prev->str, STR)))
{
ft_push_back_history(&data_singleton()->line.list_beg,
ft_create_history_list(data_singleton()->line.input));
ft_add_in_history_file(data_singleton()->line.input);
ft_create_history_list(STR));
ft_add_in_history_file(STR);
}
if (tcsetattr(0, TCSANOW, ft_save_stats_term()) == -1)
return (-1);

View file

@ -6,13 +6,13 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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"
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)
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");
}
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);
++(*srch_pos);
*str = ft_strget_history(*str_srch);
}
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;
int ret;
size_t srch_pos;
char **str;
size_t *pos;
str = &data_singleton()->line.input;
pos = &data_singleton()->line.pos;
srch_pos = 0;
str_srch = NULL;
if (*str)
ft_strdel(str);
if (STR)
ft_strdel(&STR);
while (42)
{
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);
}
ft_give_new_prompt(str_srch, srch_pos);
ret = 0;
read(0, &ret, sizeof(int));
if (ft_isprint(ret))
ft_surch_and_realloc(str, &str_srch, ret, &srch_pos);
else if (ret == 127)
{
if (srch_pos)
ft_surch_and_realloc(&STR, &str_srch, ret, &srch_pos);
else if (ret == 127 && srch_pos)
{
--srch_pos;
str_srch = ft_remove_imput(str_srch, srch_pos);
ft_puttermcaps("le");
}
}
else
else if (ret != 127)
break ;
}
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);
ft_modify_str(str_srch, srch_pos);
}

View file

@ -6,17 +6,19 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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"
static void ft_clear_window()
static void ft_clear_window(void)
{
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();
if (soon_pid != 0)
wait(NULL);
@ -24,25 +26,10 @@ static void ft_clear_window()
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;
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)
{
ret = 0;
@ -54,9 +41,36 @@ void ft_printall(void)
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("cd");
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)
--(*pos);
ft_get_beggin(str, pos);
@ -69,17 +83,6 @@ void ft_printall(void)
*pos = pos_tmp;
}
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");
}
}
void ft_get_beggin_with_curs(char *str, size_t *pos)
{
while ((*pos) && str[(*pos)] != '\n')

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */
@ -16,7 +16,8 @@ void ft_add_in_history_file(char *str)
{
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)
return ;
write(fd, str, ft_strlen(str));

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
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");
}
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */