コード例 #1
0
ファイル: tabkey_ls.c プロジェクト: vcourtin/42.sh
int		add_tab_to_buff(char **buff, int j, char *comp, char *word)
{
	struct stat		stats;
	char			*total_path;
	char			*path;

	*buff = add_str_to_tab(*buff, &(comp[ft_strlen(word)]), j);
	path = ft_get_end(*buff, ' ');
	total_path = ft_strjoin(getcwd(NULL, 1024), "/");
	total_path = ft_strjoin(total_path, path);
	stat(total_path, &stats);
	if ((stats.st_mode & S_IFDIR) != 0)
	{
		j++;
		*buff = add_to_tab(*buff, '/', ft_strlen(*buff));
	}
	j = j + (ft_strlen(comp) - ft_strlen(word));
	return (j);
}
コード例 #2
0
ファイル: add_to_history.c プロジェクト: ftwftw0/minishell
int	add_to_history(char *buff, t_history *history)
{
	if (!history || !buff)
		return (-1);
	if (history->history[history->size] != NULL)
	{
		free(history->history[history->size]);
		history->history[history->size] = NULL;
	}
	if (buff[0] && ft_strlen(buff) > 0 &&
		(history->size == 0 ||
		ft_strcmp(buff, history->history[history->size - 1])))
	{
		history->history[history->size] = NULL;
		add_str_to_tab(&(history->history), buff);
		history->current = history->size++;
		ft_putendl_fd(buff, history->fd);
	}
	history->current = history->size;
	return (0);
}