Exemple #1
0
int			ft_cd(char **path)
{
	char	tmp[500];

	if (path[0] && !path[1])
		ft_gohome();
	else if (ft_strcmp(path[1], "-L") == 0 || ft_strcmp(path[1], "-P") == 0)
		return (ft_cd_option(path));
	else if (path[0] && path[1] && !path[2])
	{
		if (ft_cd_lien(path[1], path) == 1)
			return (1);
		else if (chdir(path[1]) == -1)
			check_existe(path[1], 0);
		else
		{
			if (getcwd(tmp, 500) == NULL)
				ft_erreur("Récuperation de PWD", 0);
			ft_stockage_env("OLDPWD", ft_cherche_env("$PWD")->valeur);
			ft_stockage_env("PWD", tmp);
		}
	}
	else
		check_existe(path[1], 1);
	free_tabtab(path);
	return (1);
}
Exemple #2
0
static void	freeall(t_data *d)
{
	if (d != NULL)
	{
		if (d->line != NULL)
			ft_memdel((void **)&d->line);
		if (ft_strlen(d->toexec) > 0)
		{
			if (d->toexec[0] == 101)
			{
				free(d->toexec);
				d->toexec = NULL;
			}
		}
		if (d->argv != NULL)
			ft_memdel((void **)&d->argv);
		if (d->cenv != NULL)
			free_tabtab(d->cenv);
		if (d->varenv != NULL)
			ft_memdel((void **)&d->varenv);
		if (d->valenv != NULL)
			ft_memdel((void **)&d->valenv);
		if (d->lst_line != NULL)
			lx_full_free(d);
		if (d != NULL)
			ft_memdel((void **)&d);
	}
}
Exemple #3
0
void		build_cd(t_data *d)
{
	char	**av;

	if (!build_cd_check_for_env(d))
		return ;
	ft_replace('\t', ' ', d->toexec);
	av = ft_strsplit(d->toexec, ' ');
	if (av[1] != NULL && ft_strcmp(av[1], ".") != 0)
	{
		if (ft_strcmp(av[1], "-") == 0)
			cd_dash(d, av[1]);
		else
			build_cd2(d, av);
	}
	if (av[1] == NULL)
		cd_only(d, av[1]);
	free_tabtab(av);
}