Esempio n. 1
0
int					tt(int argc, char **argv, char **env)
{
	int			ret;
	char		**temp;
	int			cpt;
	char		*tp;

	cpt = 0;
	ret = 0;
	temp = argv;
	if (argc == 0)
		return (0);
	while (temp && temp[cpt] && temp[cpt][0])
	{
		if (temp[cpt][0] == '~' && ft_found(env, "HOME=", 0))
		{
			if (ft_found(env, "HOME=", 0) && (tp = ft_strjoin(ft_found(env,
							"HOME=", 1), temp[cpt] + 1)))
				temp[cpt] = ft_fr(tp, temp[cpt], 1);
		}
		else if (temp[cpt][0] == '~')
			return (ft_printff("cd : unable to found HOME\n", NULL, 0));
		cpt++;
	}
	return ((ft_knew_cmd(argv, env, argc)
	!= -10) ? 1 : (ft_ttaux(argc, argv, env)));
}
Esempio n. 2
0
int					ft_ttaux(int argc, char **argv, char **env)
{
	char		**path;
	char		*name;
	t_s			s;

	s.j = 0;
	name = argv[0];
	s.i = 0;
	if (!ft_found(env, "PATH=", 1))
		(SB(name, argv, env) == -1) ? ft_printff(P1, NULL, 0) : 0;
	else
	{
		path = ft_strsplit(ft_found(env, "PATH=", 1), ':');
		while ((s.ind = ft_sub_syscall(name, argv, env) == -1) && path[s.i])
		{
			s.j = access(name, F_OK) && s.ind == -1 ? s.j++ : s.j;
			name = ft_fr(ft_strjoin(path[s.i], "/"), name, s.i);
			name = ft_fr(ft_strjoin(name, argv[0]), name, 1);
			s.i++;
		}
		if (!path[s.i] && ft_printff("sh1:", GG(argv[0], s.j), 0))
			ft_putendl(argv[0]);
		ft_free_tab(path);
		s.i ? free(name) : (void)s.i;
	}
	return (argc - argc);
}
Esempio n. 3
0
File: ft_cd.c Progetto: kedric/42
t_gen			*ft_cd(char *path, t_gen *env)
{
	int	ih;
	int	ip;

	ih = ft_found("HOME", env);
	ip = ft_found("PWD", env);
	if (!path || ft_strcmp(path, "~") == 0)
	{
		if (ft_strncmp(env->env[ih], "HOME", 4) == 0)
		{
			env = ft_setenv("OLDPWD", env->env[ip] + 4, 1, env);
			chdir((env->env[ih] + 5));
			env = ft_setenv("PWD", (env->env[ih] + 5), 1, env);
		}
		return (env);
	}
	if (ft_strncmp(path, "..", 2) != 0 || ft_strcmp(env->env[ip], "PWD=/") != 0)
		env = ft_docd(path, env, ih, ip);
	return (env);
}
Esempio n. 4
0
int					ft_tmp_env(char ***args, int *argc, char ***temp,
		char **envp)
{
	char	*lvl;

	if (!ft_strcmp((*args)[1], "-i"))
	{
		if ((*argc) == 2)
			return (3);
		(*temp) = ft_set_env(NULL);
		(*args)++;
		(*argc)--;
		return (1);
	}
	else
		(*temp) = ft_set_env(envp);
	if ((lvl = ft_found(*temp, "SHLVL=", 1)))
		lvl = ft_strcpy(lvl, ft_itoa(ft_atoi(lvl) - 1));
	return (0);
}
Esempio n. 5
0
File: ft_cd.c Progetto: kedric/42
static t_gen	*ft_docd(char *path, t_gen *env, int ih, int ip)
{
	char		*s;
	char		*tmp;

	tmp = ft_dellast(env->env[ih] + 5);
	if (path[0] == '~' && path[1] == '/')
		s = ft_red(path + 2, env->env[ih] + 5);
	else if (path[0] == '~')
		s = ft_red(path + 1, tmp);
	else if (path[0] == '/')
		s = ft_red(path + 1, NULL);
	else if (ft_strcmp(path, "-") == 0)
		s = ft_strdup(&(env->env[ft_found("OLDPWD", env)][7]));
	else
		s = ft_red(path, env->env[ip] + 5);
	ft_checkaccess(s, env, ip);
	free(s);
	free(tmp);
	return (env);
}