Merge branch 'master' of https://github.com/jzck/42sh
This commit is contained in:
commit
4ba59d089b
4 changed files with 19 additions and 19 deletions
|
|
@ -57,7 +57,7 @@ int builtin_export(
|
|||
else
|
||||
equal = ft_getenv(data_singleton()->local_var, *av);
|
||||
equal ? equal++ : equal;
|
||||
builtin_setenv("internal", (char*[]){"global", *av, equal}, NULL);
|
||||
builtin_setenv("internal", (char*[]){"export", *av, equal}, NULL);
|
||||
builtin_unsetenv("internal", (char*[]){"local", *av, NULL}, NULL);
|
||||
av++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "minishell.h"
|
||||
|
||||
#define SETERR_0 "setenv: invalid variable name"
|
||||
#define SETERR_0 "%s: %s: invalid variable name"
|
||||
|
||||
static int assign_var(char *const av[], char ***env)
|
||||
{
|
||||
|
|
@ -59,7 +59,7 @@ int builtin_setenv(const char *path,
|
|||
ret = word_is_assignment((char *[]){av[1], (esc + 1)});
|
||||
ft_strdel(&esc);
|
||||
if (!ret && ft_strcmp(av[1], "?"))
|
||||
return (SH_ERR(SETERR_0));
|
||||
return (SH_ERR(SETERR_0, av[0], av[1]));
|
||||
assign_var(av, env);
|
||||
}
|
||||
return (envp ? builtin_return_status(0, 0) : 0);
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/25 11:39:47 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/18 15:04:16 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/22 12:09:59 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
static int ft_history_parsing_4(char *str, int *i)
|
||||
static int history_parsing_nb_and_previous(char *str, int *i)
|
||||
{
|
||||
int tmp;
|
||||
|
||||
|
|
@ -34,11 +34,11 @@ static int ft_history_parsing_4(char *str, int *i)
|
|||
return (0);
|
||||
}
|
||||
|
||||
static int ft_history_parsing_3(char *str, int *i)
|
||||
static int history_parsing_nb_and_name(char *str, int *i)
|
||||
{
|
||||
int tmp;
|
||||
|
||||
if (ft_history_parsing_4(str, i))
|
||||
if (history_parsing_nb_and_previous(str, i))
|
||||
return (1);
|
||||
else if (ft_isdigit(str[(*i) + 1]) && (size_t)ft_atoi(str + (*i) + 1) <
|
||||
ft_hist_len())
|
||||
|
|
@ -60,18 +60,20 @@ static int ft_history_parsing_3(char *str, int *i)
|
|||
return (1);
|
||||
}
|
||||
|
||||
static int ft_history_parsing_2(int has_prompt, char **input)
|
||||
static int rematch_history_parsing(int has_prompt, char **input)
|
||||
{
|
||||
int ret;
|
||||
|
||||
data_singleton()->line.pos = 0;
|
||||
has_prompt ? ft_prompt() : ft_putstr("> ");
|
||||
if (ft_read_stdin(input) < 0)
|
||||
if ((ret = ft_read_stdin(input)) < 0)
|
||||
return (-1);
|
||||
if (data_singleton()->line.input)
|
||||
ft_current_str(data_singleton()->line.input,
|
||||
data_singleton()->line.pos);
|
||||
ft_putchar('\n');
|
||||
ft_history_parsing(has_prompt, input);
|
||||
return (0);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int ft_history_parsing(int has_prompt, char **input)
|
||||
|
|
@ -88,14 +90,14 @@ int ft_history_parsing(int has_prompt, char **input)
|
|||
if (data_singleton()->line.input[i] == '!')
|
||||
{
|
||||
boolean = 1;
|
||||
if (!ft_history_parsing_3(data_singleton()->line.input, &i))
|
||||
if (!history_parsing_nb_and_name(data_singleton()->line.input, &i))
|
||||
boolean = 0;
|
||||
else
|
||||
break ;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
if (boolean && ft_history_parsing_2(has_prompt, input))
|
||||
return (-1);
|
||||
if (boolean)
|
||||
return (rematch_history_parsing(has_prompt, input));
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/25 20:04:16 by gwojda #+# #+# */
|
||||
/* Updated: 2017/01/26 11:33:22 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/22 11:56:47 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -52,13 +52,11 @@ void ft_realloc_str_history_3(char **str, size_t pos, char *s)
|
|||
if (new_str3)
|
||||
{
|
||||
new_str2 = ft_strjoin(new_str, new_str3);
|
||||
free(new_str);
|
||||
new_str3 = ft_strjoin(new_str2, (*str) + pos + ft_strlen(s) + 2);
|
||||
free(new_str2);
|
||||
}
|
||||
else
|
||||
new_str3 = ft_strjoin(new_str, (*str) + pos + ft_strlen(s) + 2);
|
||||
free(s);
|
||||
free(*str);
|
||||
free(new_str);
|
||||
ft_strdel(str);
|
||||
*str = new_str3;
|
||||
free(s);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue