diff --git a/42sh/libft/src/sstr/ft_sstrsort.c b/42sh/libft/src/sstr/ft_sstrsort.c index 180d4ea0..25cf4134 100644 --- a/42sh/libft/src/sstr/ft_sstrsort.c +++ b/42sh/libft/src/sstr/ft_sstrsort.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ft_sstrsort.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 18:03:37 by jhalford #+# #+# */ -/* Updated: 2016/11/23 14:46:54 by jhalford ### ########.fr */ +/* Updated: 2017/03/23 14:40:25 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/c_find_env.c b/42sh/src/completion/c_find_env.c index f93297ff..07be72e8 100644 --- a/42sh/src/completion/c_find_env.c +++ b/42sh/src/completion/c_find_env.c @@ -6,12 +6,13 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/09 15:50:24 by gwojda #+# #+# */ -/* Updated: 2017/03/22 12:29:40 by alao ### ########.fr */ +/* Updated: 2017/03/23 15:35:59 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "completion.h" +void c_lst_id(t_comp *c); /* ** Create a new list node and add it by calling c_add_to_lst. */ @@ -50,5 +51,6 @@ int c_seek_env(t_comp *c, char *current_word) c_addnode(c, ft_strndup(env[i], ft_strchr(env[i], '=') - env[i])); ++i; } + c_lst_id(c); return (0); } diff --git a/42sh/src/completion/c_parser.c b/42sh/src/completion/c_parser.c index 49721404..dc8d8ce7 100644 --- a/42sh/src/completion/c_parser.c +++ b/42sh/src/completion/c_parser.c @@ -6,33 +6,62 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:52:07 by alao #+# #+# */ -/* Updated: 2017/03/21 14:46:39 by gwojda ### ########.fr */ +/* Updated: 2017/03/23 15:34:53 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "completion.h" +void c_lst_id(t_comp *c) +{ + t_clst *lst; + int i; + + i = 1; + lst = c->lst; + if (!lst) + return ; + lst->cursor = 1; + if (!lst) + return ; + while (1) + { + lst->id = i; + lst = lst->next; + ++i; + if (lst == c->lst) + break ; + } +} /* ** Add the matching element to the list */ void c_add_to_lst(t_comp *c, t_clst *node) { + t_clst *lst; + + lst = c->lst; if (c->lst == NULL) { c->lst = node; node->next = node; node->prev = node; - node->cursor = 1; - node->id = 1; } else { - node->id = c->lst->prev->id + 1; - c->lst->prev->next = node; - node->prev = c->lst->prev; - node->next = c->lst; - c->lst->prev = node; + while (ft_strcmp(lst->name, node->name) < 0) + { + lst = lst->next; + if (lst == c->lst) + break ; + } + lst->prev->next = node; + node->prev = lst->prev; + node->next = lst; + lst->prev = node; + if (lst == c->lst && ft_strcmp(lst->name, node->name) > 0) + c->lst = node; } } @@ -77,5 +106,6 @@ int c_parser(t_comp *c, char *path, char *name) while ((dirc = readdir(rep))) c_storing(c, dirc->d_name, dirc->d_type); closedir(rep); + c_lst_id(c); return (0); }