Merge branch 'master' of https://github.com/jzck/42sh
"norme + correction syntax error"
This commit is contained in:
commit
30cddb4983
14 changed files with 57 additions and 30 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/02/18 11:13:04 by alao #+# #+# */
|
||||
/* Updated: 2017/03/16 09:14:30 by alao ### ########.fr */
|
||||
/* Updated: 2017/03/17 17:23:34 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/17 12:17:52 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/17 17:24:03 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/10 11:37:43 by alao #+# #+# */
|
||||
/* Updated: 2017/03/16 08:27:50 by alao ### ########.fr */
|
||||
/* Updated: 2017/03/17 16:46:20 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/09 11:21:16 by alao #+# #+# */
|
||||
/* Updated: 2017/03/16 08:30:52 by alao ### ########.fr */
|
||||
/* Updated: 2017/03/17 16:51:46 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/16 22:17:10 by alao #+# #+# */
|
||||
/* Updated: 2017/03/16 08:08:19 by alao ### ########.fr */
|
||||
/* Updated: 2017/03/17 16:51:53 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/03 13:10:38 by alao #+# #+# */
|
||||
/* Updated: 2017/03/16 08:48:05 by alao ### ########.fr */
|
||||
/* Updated: 2017/03/17 16:48:49 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/11 10:44:40 by alao #+# #+# */
|
||||
/* Updated: 2017/03/16 09:02:14 by alao ### ########.fr */
|
||||
/* Updated: 2017/03/17 17:07:20 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -34,6 +34,22 @@ void c_term_clear(t_comp *c)
|
|||
}
|
||||
}
|
||||
|
||||
static size_t c_virtual_position(t_comp *c)
|
||||
{
|
||||
char *str;
|
||||
size_t pos;
|
||||
size_t virtual_pos;
|
||||
|
||||
pos = c->ircmd;
|
||||
virtual_pos = pos;
|
||||
str = data_singleton()->line.input;
|
||||
while (pos && str[pos] != '\n')
|
||||
--pos;
|
||||
if (str[pos] == '\n')
|
||||
++pos;
|
||||
return (virtual_pos - pos);
|
||||
}
|
||||
|
||||
/*
|
||||
** Move the terminal up by the number of line needed and move it back up to
|
||||
** the original position.
|
||||
|
|
@ -58,7 +74,7 @@ void c_term_mv_back(t_comp *c)
|
|||
ft_putstr(tgetstr("cr", NULL));
|
||||
i = 0;
|
||||
lcmd = 0;
|
||||
c->rcmd ? lcmd += c->ircmd + c->prompt + 1 : 0;
|
||||
c->rcmd ? lcmd += c_virtual_position(c) + c->prompt + 1 : 0;
|
||||
while (i < lcmd)
|
||||
{
|
||||
ft_putstr(tgetstr("nd", NULL));
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/02 15:22:19 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/17 12:09:42 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/17 16:05:47 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -39,8 +39,7 @@ int ft_history_down(char **str, size_t *pos)
|
|||
head = head->next;
|
||||
if (!head->str)
|
||||
*str = NULL;
|
||||
else
|
||||
if (!(*str = ft_strdup(head->str)))
|
||||
else if (!(*str = ft_strdup(head->str)))
|
||||
return (-1);
|
||||
if (*str)
|
||||
ft_current_str(*str, *pos);
|
||||
|
|
@ -64,8 +63,7 @@ int ft_history_up(char **str, size_t *pos)
|
|||
head = head->prev;
|
||||
if (!head->str)
|
||||
*str = NULL;
|
||||
else
|
||||
if (!(*str = ft_strdup(head->str)))
|
||||
else if (!(*str = ft_strdup(head->str)))
|
||||
return (-1);
|
||||
if (*str)
|
||||
ft_current_str(*str, *pos);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/26 10:43:16 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/17 12:12:19 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/17 16:06:09 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/03 14:15:55 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/17 12:13:41 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/17 17:22:02 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ int ft_completion(int ret, char **str, size_t *pos)
|
|||
ft_current_str(*str, tmp);
|
||||
ft_get_next_str(*str, &tmp);
|
||||
ft_putnc('\b', right);
|
||||
*pos = ft_strleni_w(*str, pos_tmp, '\n') - right;
|
||||
*pos = pos_tmp + ft_strleni_w(*str, pos_tmp, '\n') - right;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/17 15:11:10 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/17 15:54:45 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -81,6 +81,7 @@ int ft_read_stdin(char **input)
|
|||
{
|
||||
if (read_stdin(&ret, &j) < 0)
|
||||
return (-1);
|
||||
DG("key value hex = %x", ret);
|
||||
if (ft_completion(ret, str, pos))
|
||||
continue ;
|
||||
while (g_key[j].value && g_key[j].value != ret)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 17:34:23 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/17 14:35:12 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/17 16:01:44 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -26,6 +26,12 @@ static int ft_str_is_print(char *str)
|
|||
return (1);
|
||||
}
|
||||
|
||||
static void corrupt_history(int corrupt, char *home)
|
||||
{
|
||||
if (corrupt)
|
||||
ft_dprintf(2, "42sh: corrupt history file %s/.zsh_history\n", home);
|
||||
}
|
||||
|
||||
void ft_init_history(void)
|
||||
{
|
||||
int fd;
|
||||
|
|
@ -45,10 +51,11 @@ void ft_init_history(void)
|
|||
if (ft_str_is_print(str) && *str)
|
||||
ft_push_back_history(&data_singleton()->line.list_beg,
|
||||
ft_create_history_list(str));
|
||||
else if (!corrupt)
|
||||
ft_dprintf(2, "42sh: corrupt history file %s/.zsh_history", home);
|
||||
else
|
||||
corrupt = CORRUPT;
|
||||
free(str);
|
||||
}
|
||||
corrupt_history(corrupt, home);
|
||||
free(path);
|
||||
free(str);
|
||||
close(fd);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/17 14:56:35 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/17 16:10:40 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,11 +16,12 @@ int readline(int has_prompt, char **input)
|
|||
{
|
||||
int ret;
|
||||
|
||||
if (!has_prompt)
|
||||
data_singleton()->line.prompt_size = 1;
|
||||
if (!SH_IS_INTERACTIVE(data_singleton()->opts))
|
||||
return ((ret = get_next_line(STDIN, input)) >= 0 ? !ret : ret);
|
||||
readline_init(has_prompt);
|
||||
ret = ft_read_stdin(input);
|
||||
DG("ret = %s", input);
|
||||
if (ret < 0)
|
||||
return (ret);
|
||||
if (data_singleton()->line.input)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/16 23:25:46 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/17 17:41:33 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -27,9 +27,13 @@ int data_init(int ac, char **av)
|
|||
data->local_var = NULL;
|
||||
builtin_setenv(NULL, (char *[]){"local", "IFS", "\n ", 0}, NULL);
|
||||
set_exitstatus(0, 1);
|
||||
shlvl = ft_itoa(ft_atoi(ft_getenv(data->env, "SHLVL")) + 1);
|
||||
shlvl = ft_getenv(data->env, "SHLVL");
|
||||
if (shlvl)
|
||||
{
|
||||
shlvl = ft_itoa(ft_atoi(shlvl) + 1);
|
||||
builtin_setenv(NULL, (char *[]){"setenv", "SHLVL", shlvl, 0}, NULL);
|
||||
ft_strdel(&shlvl);
|
||||
}
|
||||
data->comp = NULL;
|
||||
data->opts = 0;
|
||||
exec_reset();
|
||||
|
|
|
|||
Loading…
Reference in a new issue