示例#1
0
void		ft_lecture_liste(t_liste **lst_f, char *argument, int *option)
{
	DIR				*fd;
	struct dirent	*lreaddir;
	t_liste			*tmplst;

	lreaddir = NULL;
	if ((fd = openornot(argument, option, lst_f, lreaddir)) == NULL)
		return ;
	ft_ajout_liste_dossier(lst_f, argument);
	tmplst = ft_pointe_fin_lst(lst_f);
	while ((lreaddir = readdir(fd)) != NULL)
		renvoie(lst_f, option, lreaddir, argument);
	closedir(fd);
	if (option[4] == 1)
		ft_trie_liste_temp(tmplst, option[3]);
	else
		tmplst = ft_trie_liste(tmplst, option[3]);
	if (option[2] == 1)
		tmplst = tmplst->next;
	while (tmplst && tmplst->type != 9)
	{
		if (tmplst->type == 'd' && !(ft_strcmp(tmplst->nom, ".") == 0
				|| ft_strcmp(tmplst->nom, "..") == 0))
			ft_lecture_liste(lst_f, ft_path(argument, tmplst->nom), option);
		tmplst = tmplst->next;
	}
}
示例#2
0
文件: ft_path.c 项目: amineau/lem-in
int		ft_path(t_matrice *m, int id, int cnt)
{
	int	x;

	if (id != 1)
	{
		x = 0;
		while (++x < m->length)
		{
			if (m->matrice[id][x] && cnt < m->length)
			{
				ft_set_matrice(m->matrice, x, id, 0);
				m->tmp[cnt] = x;
				if ((cnt = ft_path(m, x, ++cnt)) > 0)
					m->tmp[--cnt] = 0;
				ft_set_matrice(m->matrice, x, id, 1);
			}
		}
	}
	if (id == 1 && cnt < m->min)
	{
		m->min = cnt;
		ft_memdel((void**)&(m->path_min));
		m->path_min = ft_tabcpy(m->tmp, m->length);
	}
	return (cnt);
}
示例#3
0
int		ft_cd(t_info *info)
{
	char	*home;
	char	*oldpwd;

	info->w = 0;
	info->error = 0;
	if (info->av[1] && info->av[2])
	{
		ft_putstr_fd("cd: too many arguments\n", 2);
		return (-1);
	}
	home = ft_strdup(get_element(info, "HOME", 2));
	oldpwd = ft_strdup(get_element(info, "OLDPWD", 3));
	if (info->error <= 2 && info->av[1] && ft_strcmp(info->av[1], "-") == 0)
		ft_rep_av(info, home, oldpwd, 1);
	if (info->error <= 1 && info->av[1] && info->av[1][0] == '~')
		ft_rep_av(info, home, oldpwd, 2);
	if (info->av && !info->av[1])
		ft_cd_plus(info, home);
	if (info->av && info->av[1])
		ft_path(info);
	free(oldpwd);
	free(home);
	return (-1);
}
示例#4
0
void	ft_exec(char *cmd, char **opt, t_env *var)
{
	char	*tmp;
	char	**conv;
	pid_t	proc;

	if (ft_isfile(cmd))
		tmp = ft_strdup(cmd);
	else
		tmp = ft_path(cmd, var);
	if (!tmp)
	{
		ft_error_cmd(cmd);
		return ;
	}
	proc = fork();
	if (proc == 0)
	{
		conv = ft_conv_env(var);
		execve(tmp, opt, conv);
		ft_free_tab(conv);
	}
	wait(NULL);
	free(tmp);
}
示例#5
0
static void	renvoie(t_liste **lst_f, int *opt, struct dirent *lrd, char *arg)
{
	struct stat	*llstat;

	llstat = (struct stat*)malloc(sizeof(struct stat));
	if (opt[0] == 1 || opt[4] == 1 || opt[5] == 1)
		lstat(ft_path(arg, lrd->d_name), llstat);
	if (opt[1] == 1 || lrd->d_name[0] != '.')
		ft_lstaddend(lst_f, ft_ajt_lst(lrd, llstat, opt, arg));
}
示例#6
0
文件: ft_go.c 项目: mguesner/projet42
void	ft_go(char ***env)
{
	char	*tmp;
	char	**path;
	t_list	*arg;
	t_tree	*tree;

	if (!(tmp = ft_getenv("PATH", *env)))
		path = ft_path();
	else
		path = ft_strsplit(tmp, ':');
	if ((arg = ft_parser(g_e.buff))
			&& (tree = ft_make_tree(arg)))
	{
		ft_exec(tree, path, env);
		ft_del_tree(tree);
	}
	ft_tabdel(path);
	free(path);
}
示例#7
0
文件: ft_exec.c 项目: YanisSOTO/42sh
void	ft_launch_exec(char *command, char ***env, int *execve_flag)
{
	char	**path;
	char	**cmd_arg;

	if (ft_strsrch(command, '|') != -1)
		exec_pipe(env, command, execve_flag);
	else
	{
		cmd_arg = get_clean_arg(command, *env);
		if (((path = ft_path(env, cmd_arg[0])) == NULL)
				&& ft_strcmp(command, "exit") != 0)
			ft_putendl("Set a good path or you will take expensive.");
		if ((ft_rd(command, env, execve_flag) == 1)
				&& (builtin(env, cmd_arg) == 0))
		{
			ft_execute_cmd(path, cmd_arg, *env, execve_flag);
			if (path)
				ft_tabfree(path);
		}
	}
}