Exemplo n.º 1
0
static void		sh_context(t_info *info, t_info *context)
{
	context->line = ft_strdup(info->line);
	context->args = ft_tabdup(info->args);
	context->env = ft_tabdup(info->env);
	context->status = info->status;
	context->sig = info->sig;
	context->cursdir = ft_strdup(info->cursdir);
	ft_strcpy(context->path, info->path);
}
Exemplo n.º 2
0
static void		ft_realloc_alias(char *value, char ***tab)
{
	char		**cmd;
	char		**tmp;
	int			len;
	int			i;
	int			j;

	tmp = ft_tabdup(*tab);
	ft_tabdel(tab);
	cmd = ft_strsplit_space(value);
	i = ft_tablen(tmp) - 1;
	j = ft_tablen(cmd);
	len = i + j;
	*tab = (char **)malloc(sizeof(char *) * (len + 1));
	(*tab)[len] = NULL;
	while (--len >= 0)
	{
		if (i > 0)
			(*tab)[len] = ft_strdup(tmp[i--]);
		else
			(*tab)[len] = ft_strdup(cmd[--j]);
	}
	ft_tabdel(&cmd);
	ft_tabdel(&tmp);
}
Exemplo n.º 3
0
void			ft_env(char **command, t_env *e)
{
	t_opt		opt;
	char		**tmp;
	int			i;

	ft_memset(&opt, 0, sizeof(opt));
	e->ret = 0;
	if ((opt.env = ft_tabdup(e->env)) == NULL)
		return (ft_error("malloc failed", &opt, e));
	if (!command[1])
		ft_puttab(opt.env);
	else
	{
		if ((i = check(command, &opt)) < 0)
			return (ft_error(NULL, &opt, e));
		if (command[i])
		{
			tmp = e->env;
			e->env = opt.env;
			check_and_exec(&command[i], e);
			e->env = tmp;
		}
		else
			ft_puttab(opt.env);
	}
	free_opt(&opt);
}
Exemplo n.º 4
0
static int		add_dir(char ***path_tab, char *path)
{
	char	**new_tab;
	int		size;

	size = ft_tablen(*path_tab);
	new_tab = ft_tabdup(*path_tab, size + 1);
	new_tab[size] = ft_strdup_to_char(path, '/');
	del_tab(*path_tab);
	*path_tab = new_tab;
	size = 0;
	while (path[size] && path[size] != '/')
		++size;
	return (size);
}
Exemplo n.º 5
0
static int	check_i_opt(t_shell *sh, char **arg, char **env_cpy)
{
	char	*cmd;
	char	**tab_cpy;

	if (arg[0][0] == '-' && arg[0][1] == 'i' && !arg[0][2] && arg[1])
	{
		arg++;
		cmd = join_tab(arg);
		tab_cpy = ft_tabdup(env_cpy);
		ft_free_tab(tab_cpy);
		tab_cpy = NULL;
		exec_env(sh, cmd, tab_cpy);
		free(cmd);
		return (0);
	}
	else
		return (1);
}
Exemplo n.º 6
0
int				main(int argc, char **argv, char **environ)
{
	int		i;
	char	**envi;
	t_env	*env;
	char	*line;

	i = -1;
	line = ft_strdup("");
	envi = ft_tabdup(environ);
	signal(SIGINT, SIG_IGN);
	env = NULL;
	while (envi[++i] != 0)
		env = env_in_list(envi[i], env);
	free_tab(envi);
	if (argc == 1 && argv[0])
		no_more_lines(line, env);
	free_list(&env);
	return (0);
}
Exemplo n.º 7
0
int				main(int ac, char **av, char **envp)
{
	char	**cmd;
	int		i;
	int		exit;

	av[ac] = 0;
	i = 0;
	g_envtmp = NULL;
	g_env = ft_tabdup(envp);
	set_signals(0);
	while (i < 2)
	{
		g_pid = 0;
		ft_putstr("$> ");
		cmd = ft_get_cmd();
		exit = do_cmd(cmd, &i);
		ft_freetab(&cmd);
	}
	ft_freetab(&g_env);
	return (exit);
}
Exemplo n.º 8
0
t_ftsh	*intialize_sh(int argc, char **argv, char **envp)
{
	t_ftsh	*sh;

	sh = NULL;
	sh = ft_memalloc(sizeof(t_ftsh));
	if (sh)
	{
		sh->prompt = ft_strdup(PROMPT);
		if (!(sh->prompt))
			return (NULL);
		sh->env_dup = ft_tabdup(envp);
		increment_shlvl(&(sh->env_dup));
		sh->line = NULL;
		change_env_pwd(&(sh->env_dup));
		if (sh->env_dup)
			sh->path_dir = extract_path_directories(sh->env_dup);
		sh->argc = argc;
		sh->argv = argv;
	}
	else
		return (NULL);
	return (sh);
}