Norme for autocompletion module
This commit is contained in:
parent
8b8259b353
commit
c4df4b837b
20 changed files with 310 additions and 282 deletions
|
|
@ -44,21 +44,21 @@ builtin/builtin_setenv.c\
|
||||||
builtin/builtin_unset.c\
|
builtin/builtin_unset.c\
|
||||||
builtin/builtin_unsetenv.c\
|
builtin/builtin_unsetenv.c\
|
||||||
builtin/is_builtin.c\
|
builtin/is_builtin.c\
|
||||||
completion/c_abs_path.c\
|
|
||||||
completion/c_arrow.c\
|
completion/c_arrow.c\
|
||||||
completion/c_binary.c\
|
|
||||||
completion/c_clear.c\
|
completion/c_clear.c\
|
||||||
completion/c_files.c\
|
completion/c_find_abspath.c\
|
||||||
completion/c_glob_matching.c\
|
completion/c_find_binary.c\
|
||||||
|
completion/c_find_env.c\
|
||||||
|
completion/c_find_files.c\
|
||||||
completion/c_init.c\
|
completion/c_init.c\
|
||||||
completion/c_matching.c\
|
completion/c_match.c\
|
||||||
|
completion/c_match_glob.c\
|
||||||
|
completion/c_match_update.c\
|
||||||
completion/c_misc.c\
|
completion/c_misc.c\
|
||||||
completion/c_output.c\
|
completion/c_output.c\
|
||||||
completion/c_parser.c\
|
completion/c_parser.c\
|
||||||
completion/c_pathsolver.c\
|
completion/c_pathsolver.c\
|
||||||
completion/c_printer.c\
|
completion/c_printer.c\
|
||||||
completion/c_rematch.c\
|
|
||||||
completion/c_seek_env.c\
|
|
||||||
completion/c_sizing.c\
|
completion/c_sizing.c\
|
||||||
completion/c_terminal.c\
|
completion/c_terminal.c\
|
||||||
completion/completion.c\
|
completion/completion.c\
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/02/18 11:13:04 by alao #+# #+# */
|
/* Created: 2016/02/18 11:13:04 by alao #+# #+# */
|
||||||
/* Updated: 2017/03/15 18:46:45 by jhalford ### ########.fr */
|
/* Updated: 2017/03/16 09:14:30 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,7 +14,11 @@
|
||||||
# define COMPLETION_H
|
# define COMPLETION_H
|
||||||
|
|
||||||
# include "minishell.h"
|
# include "minishell.h"
|
||||||
# define RETARDED_BEHAVIOR 0
|
|
||||||
|
# define KP_U 4283163
|
||||||
|
# define KP_D 4348699
|
||||||
|
# define KP_L 4479771
|
||||||
|
# define KP_R 4414235
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Autocompletion list for the valid candidates from the parser.
|
** Autocompletion list for the valid candidates from the parser.
|
||||||
|
|
@ -27,16 +31,16 @@
|
||||||
** prev : Pointer to the previous item of the list.
|
** prev : Pointer to the previous item of the list.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct s_clst
|
typedef struct s_clst
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
char *name;
|
char *name;
|
||||||
int type;
|
int type;
|
||||||
int len;
|
int len;
|
||||||
int cursor;
|
int cursor;
|
||||||
struct s_clst *next;
|
struct s_clst *next;
|
||||||
struct s_clst *prev;
|
struct s_clst *prev;
|
||||||
} t_clst;
|
} t_clst;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Autocompletion structure composed as follow:
|
** Autocompletion structure composed as follow:
|
||||||
|
|
@ -77,65 +81,76 @@ typedef struct s_clst
|
||||||
** (char *)start (char *)between (char *)rcmd (char *)trail
|
** (char *)start (char *)between (char *)rcmd (char *)trail
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct s_comp
|
typedef struct s_comp
|
||||||
{
|
{
|
||||||
char *rcmd;
|
char *rcmd;
|
||||||
int ircmd;
|
int ircmd;
|
||||||
char *cpath;
|
char *cpath;
|
||||||
char *match;
|
char *match;
|
||||||
char *home;
|
char *home;
|
||||||
char *pwd;
|
char *pwd;
|
||||||
char *start;
|
char *start;
|
||||||
char *between;
|
char *between;
|
||||||
char *trail;
|
char *trail;
|
||||||
int cutpoint;
|
int cutpoint;
|
||||||
int prompt;
|
int prompt;
|
||||||
int c_sx;
|
int c_sx;
|
||||||
int c_sy;
|
int c_sy;
|
||||||
int c_pline;
|
int c_pline;
|
||||||
int c_line;
|
int c_line;
|
||||||
int win_x;
|
int win_x;
|
||||||
int win_y;
|
int win_y;
|
||||||
int m_size;
|
int m_size;
|
||||||
int pos_x;
|
int pos_x;
|
||||||
int pos_y;
|
int pos_y;
|
||||||
int key;
|
int key;
|
||||||
int isfolder;
|
int isfolder;
|
||||||
int isrematch;
|
int isrematch;
|
||||||
t_clst *lst;
|
t_clst *lst;
|
||||||
} t_comp;
|
} t_comp;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Main autocompletion engine:
|
** Main autocompletion engine:
|
||||||
** completion : Main function.
|
** completion : Main function.
|
||||||
** c_init : Initialization.
|
** c_init : Initialization.
|
||||||
** c_matching : Dispatcher for binary or local files.
|
** c_matching : Dispatcher for binary or local files.
|
||||||
|
** c_rematch : Restart on keypress.
|
||||||
|
** c_glob_matching : Call for globbing completion.
|
||||||
** c_seek_binary : Search binary using env PATH.
|
** c_seek_binary : Search binary using env PATH.
|
||||||
** c_seek_files : Solve path and search.
|
** c_seek_files : Solve path and search.
|
||||||
|
** c_seek_env : Search in env for $(var)
|
||||||
|
** c_seek_abs_path : Determiner for absolute path
|
||||||
** c_parser : Parser.
|
** c_parser : Parser.
|
||||||
|
** c_add_to_lst : Add new node to the list.
|
||||||
** c_sizing : Determine the size of the column/line.
|
** c_sizing : Determine the size of the column/line.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int completion(long int key);
|
int completion(long int key);
|
||||||
void c_init(t_data *s, long int input);
|
void c_init(t_data *s, long int input);
|
||||||
int c_matching(t_data *s, t_comp *c);
|
int c_matching(t_data *s, t_comp *c);
|
||||||
int c_seek_binary(t_data *s, t_comp *c);
|
int c_rematch(t_comp *c, long int keypress);
|
||||||
int c_seek_files(
|
int c_glob_matching(void);
|
||||||
t_data *s, t_comp *c, char *current_word);
|
int c_seek_binary(t_data *s, t_comp *c);
|
||||||
int c_parser(t_comp *c, char *path, char *name);
|
int c_seek_files(t_data *s, t_comp *c, char *current_word);
|
||||||
int c_sizing(t_comp *c);
|
int c_seek_env(t_comp *c, char *current_word);
|
||||||
|
void c_seek_abs_path(t_comp *c, char *current_word);
|
||||||
|
int c_parser(t_comp *c, char *path, char *name);
|
||||||
|
void c_add_to_lst(t_comp *c, t_clst *node);
|
||||||
|
int c_sizing(t_comp *c);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Output functions:
|
** Output functions:
|
||||||
**
|
**
|
||||||
|
** c_dispatcher : Choose between clear, print or update from to the list
|
||||||
** c_updater : Output the result to struct data.
|
** c_updater : Output the result to struct data.
|
||||||
** c_gtfo : Keypress handling.
|
** c_keypress : Keypress handling.
|
||||||
** c_rematch : Restart on keypress.
|
** c_arrow : Arrow support.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int c_updater(t_comp *c, char *select);
|
int c_dispatcher(t_data *s);
|
||||||
int c_gtfo(t_comp *c, long int keypress);
|
int c_updater(t_comp *c, char *select);
|
||||||
int c_rematch(t_comp *c, long int keypress);
|
int c_keypress(t_comp *c, long int key);
|
||||||
|
void c_arrow(t_comp *c, long int keypress);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Terminal functions:
|
** Terminal functions:
|
||||||
|
|
@ -147,11 +162,11 @@ int c_rematch(t_comp *c, long int keypress);
|
||||||
** c_printer : Printer of the list.
|
** c_printer : Printer of the list.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void c_term_mv_down(t_comp *c);
|
void c_term_mv_down(t_comp *c);
|
||||||
void c_term_mv_back(t_comp *c);
|
void c_term_mv_back(t_comp *c);
|
||||||
void c_term_clear(t_comp *c);
|
void c_term_clear(t_comp *c);
|
||||||
int c_term_resize(t_comp *c);
|
int c_term_resize(t_comp *c);
|
||||||
void c_printer(t_comp *c);
|
void c_printer(t_comp *c);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Support functions:
|
** Support functions:
|
||||||
|
|
@ -159,26 +174,16 @@ void c_printer(t_comp *c);
|
||||||
** c_clear : Memory clearing.
|
** c_clear : Memory clearing.
|
||||||
** c_clear_lst : List clearing.
|
** c_clear_lst : List clearing.
|
||||||
** path_solver : Solve abstract path to absolute.
|
** path_solver : Solve abstract path to absolute.
|
||||||
|
** c_exclusion_foldr : Check for match folder.
|
||||||
|
** ft_sstrlen : Return size of char **.
|
||||||
|
** ft_sstrtostr : Create char * from char ** with char *sep between.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int c_clear(t_data *s);
|
int c_clear(t_data *s);
|
||||||
int c_clear_lst(t_comp *c);
|
int c_clear_lst(t_comp *c);
|
||||||
char *path_solver(t_comp *c, char *cmd, char *cwd);
|
char *path_solver(t_comp *c, char *cmd, char *cwd);
|
||||||
int c_spacing_escape(t_clst *node, int x, int o);
|
int c_exclusion_folder(t_comp *c);
|
||||||
int c_spacing_clear(t_comp *c);
|
int ft_sstrlen(char **s);
|
||||||
int ft_sstrlen(char **s);
|
char *ft_sstrtostr(char **s, char *sep);
|
||||||
char *ft_sstrtostr(char **s, char *sep);
|
|
||||||
|
|
||||||
/*
|
|
||||||
** j'ajoute a la va vite^^
|
|
||||||
*/
|
|
||||||
|
|
||||||
int c_glob_matching(void);
|
|
||||||
void c_add_to_lst(t_comp *c, t_clst *node);
|
|
||||||
int c_seek_env(t_comp *c, char *current_word);
|
|
||||||
void c_seek_abs_path(t_comp *c, char *current_word);
|
|
||||||
void c_arrow(t_comp *c, long int keypress);
|
|
||||||
int c_chevron(t_comp *c);
|
|
||||||
int c_dispatcher(t_data *s);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -6,43 +6,51 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/10 09:04:42 by alao #+# #+# */
|
/* Created: 2017/03/10 09:04:42 by alao #+# #+# */
|
||||||
/* Updated: 2017/03/15 14:26:11 by alao ### ########.fr */
|
/* Updated: 2017/03/16 08:17:12 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "completion.h"
|
#include "completion.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
** Calculate the offset id value from the current one relative to the list size.
|
||||||
|
** lst_modulo is the number in element in the last column of the list that is
|
||||||
|
** not perfectly in the same size.
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int c_idsolver(t_comp *c, int ids, int ids_bk)
|
static int c_idsolver(t_comp *c, int ids, int ids_bk)
|
||||||
{
|
{
|
||||||
|
int lst_modulo;
|
||||||
|
|
||||||
|
lst_modulo = c->lst->prev->id % c->c_line;
|
||||||
|
if (lst_modulo == 0)
|
||||||
|
lst_modulo = c->c_line;
|
||||||
if (ids > c->lst->prev->id)
|
if (ids > c->lst->prev->id)
|
||||||
{
|
{
|
||||||
ids -= c->lst->prev->id;
|
ids -= c->lst->prev->id;
|
||||||
if (ids_bk < ((c->lst->prev->id - (c->lst->prev->id % c->c_line)) + 1))
|
if (ids_bk < ((c->lst->prev->id - lst_modulo) + 1))
|
||||||
ids = ids + (c->lst->prev->id % c->c_line);
|
ids = ids + lst_modulo;
|
||||||
else
|
else
|
||||||
ids = ids - (c->c_line - (c->lst->prev->id % c->c_line));
|
ids = ids - (c->c_line - lst_modulo);
|
||||||
}
|
}
|
||||||
else if (ids < c->lst->id)
|
else if (ids < c->lst->id)
|
||||||
{
|
{
|
||||||
if (ids_bk <= (c->lst->prev->id % c->c_line))
|
if (ids_bk <= lst_modulo)
|
||||||
ids = (c->lst->prev->id - (c->lst->prev->id % c->c_line)) + ids_bk;
|
ids = (c->lst->prev->id - lst_modulo) + ids_bk;
|
||||||
else
|
else
|
||||||
ids = c->lst->prev->id - (ids * -1) - (c->lst->prev->id % c->c_line);
|
ids = c->lst->prev->id - (ids * -1) - lst_modulo;
|
||||||
if (ids < c->lst->id)
|
if (ids < c->lst->id)
|
||||||
{
|
|
||||||
DG("Failsafe %d", ids);
|
|
||||||
ids = 1;
|
ids = 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return (ids);
|
return (ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
**
|
** Determine the movement in the list by retrieving the current id selected in
|
||||||
|
** the list and add/substract the value depending on the keypress (left/right).
|
||||||
|
** Call for c_idsolver() to adjust this value and cycle in the list to reassign
|
||||||
|
** the correct element to cursor position.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void c_arrow_multi(t_comp *c, long int keypress)
|
static void c_arrow_multi(t_comp *c, long int keypress)
|
||||||
|
|
@ -52,7 +60,6 @@ static void c_arrow_multi(t_comp *c, long int keypress)
|
||||||
int ids_bk;
|
int ids_bk;
|
||||||
|
|
||||||
ids = 0;
|
ids = 0;
|
||||||
|
|
||||||
ptr = c->lst;
|
ptr = c->lst;
|
||||||
while (!ptr->cursor)
|
while (!ptr->cursor)
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
|
|
@ -69,7 +76,10 @@ static void c_arrow_multi(t_comp *c, long int keypress)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
**
|
** Arrow support for moving inside the list of the completion.
|
||||||
|
** If the keypress is left/right, c_arrow_multi() is called. Else the list is
|
||||||
|
** just read until the cursor is found and the next/prev is reassigned as
|
||||||
|
** selected.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void c_arrow(t_comp *c, long int keypress)
|
void c_arrow(t_comp *c, long int keypress)
|
||||||
|
|
|
||||||
|
|
@ -6,20 +6,20 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/10 11:37:43 by alao #+# #+# */
|
/* Created: 2017/01/10 11:37:43 by alao #+# #+# */
|
||||||
/* Updated: 2017/02/17 14:57:09 by alao ### ########.fr */
|
/* Updated: 2017/03/16 08:27:50 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "completion.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Clear the list from the memory
|
** Clear the list from the memory
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int c_clear_lst(t_comp *c)
|
int c_clear_lst(t_comp *c)
|
||||||
{
|
{
|
||||||
t_clst *c_lst;
|
t_clst *c_lst;
|
||||||
t_clst *p_lst;
|
t_clst *p_lst;
|
||||||
|
|
||||||
if (c->lst == NULL)
|
if (c->lst == NULL)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
@ -46,9 +46,9 @@ int c_clear_lst(t_comp *c)
|
||||||
** function
|
** function
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int c_clear(t_data *s)
|
int c_clear(t_data *s)
|
||||||
{
|
{
|
||||||
t_comp *ptr;
|
t_comp *ptr;
|
||||||
|
|
||||||
if (s->comp == NULL)
|
if (s->comp == NULL)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
||||||
|
|
@ -1,45 +1,28 @@
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* c_abs_path.c :+: :+: :+: */
|
/* c_find_abspath.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/09 16:54:59 by gwojda #+# #+# */
|
/* Created: 2017/03/09 16:54:59 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/15 06:57:53 by alao ### ########.fr */
|
/* Updated: 2017/03/16 08:27:55 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "completion.h"
|
#include "completion.h"
|
||||||
|
|
||||||
static int c_exclusion_folder(t_comp *c)
|
/*
|
||||||
{
|
** Process the absolute path for the completion.
|
||||||
DIR *rep;
|
*/
|
||||||
char *tmp;
|
|
||||||
char *tmp2;
|
|
||||||
|
|
||||||
tmp = ft_strjoin(c->cpath, c->match);
|
void c_seek_abs_path(t_comp *c, char *current_word)
|
||||||
tmp2 = NULL;
|
|
||||||
if (tmp[ft_strlen(tmp) - 1] == '/')
|
|
||||||
return (0);
|
|
||||||
if ((rep = opendir(tmp)) && (!closedir(rep)))
|
|
||||||
{
|
|
||||||
tmp ? ft_memdel((void *)&tmp) : (0);
|
|
||||||
tmp2 = ft_strjoin(c->match, "/");
|
|
||||||
c_updater(c, tmp2);
|
|
||||||
tmp2 ? ft_memdel((void *)&tmp2) : (0);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
tmp ? ft_memdel((void *)&tmp) : (0);
|
|
||||||
tmp ? ft_memdel((void *)&tmp) : (0);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void c_seek_abs_path(t_comp *c, char *current_word)
|
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
int len;
|
||||||
|
|
||||||
c->cpath = ft_strndup(current_word, ft_strrchr(c->rcmd, '/') - current_word + 1);
|
len = ft_strrchr(c->rcmd, '/') - current_word + 1;
|
||||||
|
c->cpath = ft_strndup(current_word, len);
|
||||||
if (current_word[0] == '~')
|
if (current_word[0] == '~')
|
||||||
{
|
{
|
||||||
tmp = c->cpath;
|
tmp = c->cpath;
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* c_binary.c :+: :+: :+: */
|
/* c_find_binary.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/09 13:30:57 by alao #+# #+# */
|
/* Created: 2017/01/09 13:30:57 by alao #+# #+# */
|
||||||
/* Updated: 2017/02/27 13:17:27 by alao ### ########.fr */
|
/* Updated: 2017/03/16 08:28:03 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "completion.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Retrieve the path from the env and create a char ** from the PATH pattern.
|
** Retrieve the path from the env and create a char ** from the PATH pattern.
|
||||||
|
|
@ -18,11 +18,11 @@
|
||||||
** c_parser() function.
|
** c_parser() function.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int c_seek_binary(t_data *s, t_comp *c)
|
int c_seek_binary(t_data *s, t_comp *c)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
char **paths;
|
char **paths;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
|
|
@ -1,20 +1,24 @@
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* c_seek_env.c :+: :+: :+: */
|
/* c_find_env.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/09 15:50:24 by gwojda #+# #+# */
|
/* Created: 2017/03/09 15:50:24 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/15 11:50:15 by gwojda ### ########.fr */
|
/* Updated: 2017/03/16 08:28:19 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "completion.h"
|
||||||
|
|
||||||
static int c_storing(t_comp *c, char *value)
|
/*
|
||||||
|
** Create a new list node and add it by calling c_add_to_lst.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int c_addnode(t_comp *c, char *value)
|
||||||
{
|
{
|
||||||
t_clst *tmp;
|
t_clst *tmp;
|
||||||
|
|
||||||
if (!(tmp = (t_clst *)malloc(sizeof(t_clst))))
|
if (!(tmp = (t_clst *)malloc(sizeof(t_clst))))
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
@ -26,6 +30,10 @@ static int c_storing(t_comp *c, char *value)
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Search in the env for matching element and add them to the list if matched.
|
||||||
|
*/
|
||||||
|
|
||||||
int c_seek_env(t_comp *c, char *current_word)
|
int c_seek_env(t_comp *c, char *current_word)
|
||||||
{
|
{
|
||||||
char **env;
|
char **env;
|
||||||
|
|
@ -37,8 +45,8 @@ int c_seek_env(t_comp *c, char *current_word)
|
||||||
while (env[i])
|
while (env[i])
|
||||||
{
|
{
|
||||||
if (!ft_strncmp(c->match, env[i], ft_strlen(c->match)) &&
|
if (!ft_strncmp(c->match, env[i], ft_strlen(c->match)) &&
|
||||||
env[i][ft_strlen(c->match)] != '=')
|
env[i][ft_strlen(c->match)] != '=')
|
||||||
c_storing(c, ft_strndup(env[i], ft_strchr(env[i], '=') - env[i]));
|
c_addnode(c, ft_strndup(env[i], ft_strchr(env[i], '=') - env[i]));
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* c_files.c :+: :+: :+: */
|
/* c_find_files.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/09 13:31:21 by alao #+# #+# */
|
/* Created: 2017/01/09 13:31:21 by alao #+# #+# */
|
||||||
/* Updated: 2017/03/15 11:47:40 by gwojda ### ########.fr */
|
/* Updated: 2017/03/16 08:29:21 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "completion.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** If the parsing for local file fail. The function is called to check if the
|
** If the parsing for local file fail. The function is called to check if the
|
||||||
|
|
@ -20,11 +20,11 @@
|
||||||
** Returning 1 if success (trigger an update) or 0.
|
** Returning 1 if success (trigger an update) or 0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int c_exclusion_folder(t_comp *c)
|
int c_exclusion_folder(t_comp *c)
|
||||||
{
|
{
|
||||||
DIR *rep;
|
DIR *rep;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
char *tmp2;
|
char *tmp2;
|
||||||
|
|
||||||
tmp = ft_strjoin(c->cpath, c->match);
|
tmp = ft_strjoin(c->cpath, c->match);
|
||||||
tmp2 = NULL;
|
tmp2 = NULL;
|
||||||
|
|
@ -45,16 +45,17 @@ static int c_exclusion_folder(t_comp *c)
|
||||||
tmp ? ft_memdel((void *)&tmp) : (0);
|
tmp ? ft_memdel((void *)&tmp) : (0);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Clear the binary from c->rcmd ans save the result in c->match. Return the
|
** Clear the binary from c->rcmd ans save the result in c->match. Return the
|
||||||
** path part of it if exist or NULL.
|
** path part of it if exist or NULL.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static char *c_slicer(t_comp *c)
|
static char *c_slicer(t_comp *c)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
char *rt;
|
char *rt;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
|
|
@ -78,7 +79,7 @@ static char *c_slicer(t_comp *c)
|
||||||
** Files searching
|
** Files searching
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int c_seek_files(t_data *s, t_comp *c, char *current_word)
|
int c_seek_files(t_data *s, t_comp *c, char *current_word)
|
||||||
{
|
{
|
||||||
char *path;
|
char *path;
|
||||||
|
|
||||||
|
|
@ -6,22 +6,22 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/09 11:21:16 by alao #+# #+# */
|
/* Created: 2017/01/09 11:21:16 by alao #+# #+# */
|
||||||
/* Updated: 2017/03/10 12:43:57 by alao ### ########.fr */
|
/* Updated: 2017/03/16 08:30:52 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "completion.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Trim if there's many commands in a raw separed with a semi colon.
|
** Trim if there's many commands in a raw separed with a semi colon.
|
||||||
** The cutpoint is saved and also between char **.
|
** The cutpoint is saved and also between char **.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static char *c_trimmer(char *cmd, int st, int nd)
|
static char *c_trimmer(char *cmd, int st, int nd)
|
||||||
{
|
{
|
||||||
char *rt;
|
char *rt;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
rt = NULL;
|
rt = NULL;
|
||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
|
|
@ -49,9 +49,9 @@ static char *c_trimmer(char *cmd, int st, int nd)
|
||||||
** Norme function for c_init().
|
** Norme function for c_init().
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void c_init_base(t_comp *c)
|
static void c_init_base(t_comp *c)
|
||||||
{
|
{
|
||||||
struct winsize win;
|
struct winsize win;
|
||||||
|
|
||||||
ioctl(0, TIOCGWINSZ, &win);
|
ioctl(0, TIOCGWINSZ, &win);
|
||||||
c->win_x = win.ws_col;
|
c->win_x = win.ws_col;
|
||||||
|
|
@ -80,7 +80,7 @@ static void c_init_base(t_comp *c)
|
||||||
|
|
||||||
void c_init(t_data *s, long int input)
|
void c_init(t_data *s, long int input)
|
||||||
{
|
{
|
||||||
int len_trail;
|
int len_trail;
|
||||||
|
|
||||||
if (!(s->comp = (t_comp *)malloc((sizeof(t_comp)))))
|
if (!(s->comp = (t_comp *)malloc((sizeof(t_comp)))))
|
||||||
return ;
|
return ;
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,22 @@
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* c_matching.c :+: :+: :+: */
|
/* c_match.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/10/15 13:27:14 by alao #+# #+# */
|
/* Created: 2016/10/15 13:27:14 by alao #+# #+# */
|
||||||
/* Updated: 2017/03/14 17:22:10 by gwojda ### ########.fr */
|
/* Updated: 2017/03/16 09:12:40 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** chevron y es-tu ???
|
** Failsafe by checking if the nearby char are not a < or > for aggregation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int c_chevron(t_comp *c)
|
static int c_chevron(t_comp *c)
|
||||||
{
|
{
|
||||||
size_t pos;
|
size_t pos;
|
||||||
|
|
||||||
|
|
@ -33,16 +33,7 @@ int c_chevron(t_comp *c)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Start the parsing for the autocompletion.
|
** Seek the current word.
|
||||||
** Check the first char of the c->rcmd for a . or /. to see if it's a local
|
|
||||||
** path to search even if there's no space in the command.
|
|
||||||
** If a space is found in the command. The function will assume it's a binary
|
|
||||||
** completion that is needed. Else the c_seek_files() is called to search for
|
|
||||||
** local path along with the binary part separated.
|
|
||||||
** If any of the other part successfully created a list, the c_sizing is called
|
|
||||||
** and 1 is returned. The last condition also check is the structure still
|
|
||||||
** exist. It's only when the c_rematch() called it that it can be the case.
|
|
||||||
** Else 0 is returned.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static char *c_current_words(t_comp *c)
|
static char *c_current_words(t_comp *c)
|
||||||
|
|
@ -57,6 +48,10 @@ static char *c_current_words(t_comp *c)
|
||||||
return (c->rcmd + pos);
|
return (c->rcmd + pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Start the parsing for the autocompletion.
|
||||||
|
*/
|
||||||
|
|
||||||
int c_matching(t_data *s, t_comp *c)
|
int c_matching(t_data *s, t_comp *c)
|
||||||
{
|
{
|
||||||
char *current_word;
|
char *current_word;
|
||||||
|
|
@ -1,24 +1,28 @@
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* c_glob_matching.c :+: :+: :+: */
|
/* c_match_glob.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/08 17:20:01 by gwojda #+# #+# */
|
/* Created: 2017/03/08 17:20:01 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/14 14:00:30 by gwojda ### ########.fr */
|
/* Updated: 2017/03/16 08:39:09 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "completion.h"
|
||||||
|
|
||||||
static void c_replace_globbing(char **glob, size_t start)
|
/*
|
||||||
|
** Recreate the command from the globbing module responds.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void c_replace_globbing(char **glob, size_t start)
|
||||||
{
|
{
|
||||||
char *ref_next;
|
char *ref_next;
|
||||||
char *ref_mid;
|
char *ref_mid;
|
||||||
char *ref_prev;
|
char *ref_prev;
|
||||||
char *str;
|
char *str;
|
||||||
size_t pos;
|
size_t pos;
|
||||||
|
|
||||||
str = data_singleton()->line.input;
|
str = data_singleton()->line.input;
|
||||||
pos = data_singleton()->line.pos;
|
pos = data_singleton()->line.pos;
|
||||||
|
|
@ -36,7 +40,30 @@ static void c_replace_globbing(char **glob, size_t start)
|
||||||
free(str);
|
free(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
int c_glob_matching(void)
|
/*
|
||||||
|
** 42 norme. Readjust the position.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int c_glob_pos(char *str, size_t pos)
|
||||||
|
{
|
||||||
|
str = data_singleton()->line.input;
|
||||||
|
pos = data_singleton()->line.pos;
|
||||||
|
if (!str)
|
||||||
|
return (-1);
|
||||||
|
if (pos && str[pos] == ' ')
|
||||||
|
--pos;
|
||||||
|
while (pos && str[pos] != ' ')
|
||||||
|
--pos;
|
||||||
|
if (str[pos] == ' ')
|
||||||
|
++pos;
|
||||||
|
return (pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Match for globbing feature.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int c_glob_matching(void)
|
||||||
{
|
{
|
||||||
char *current_word;
|
char *current_word;
|
||||||
char **ss_glob;
|
char **ss_glob;
|
||||||
|
|
@ -45,15 +72,8 @@ int c_glob_matching(void)
|
||||||
size_t pos;
|
size_t pos;
|
||||||
|
|
||||||
str = data_singleton()->line.input;
|
str = data_singleton()->line.input;
|
||||||
pos = data_singleton()->line.pos;
|
if ((pos = c_glob_pos(NULL, 0)) == -1)
|
||||||
if (!str)
|
|
||||||
return (0);
|
return (0);
|
||||||
if (pos && str[pos] == ' ')
|
|
||||||
--pos;
|
|
||||||
while (pos && str[pos] != ' ')
|
|
||||||
--pos;
|
|
||||||
if (str[pos] == ' ')
|
|
||||||
++pos;
|
|
||||||
current_word = ft_strdupi_w(str + pos);
|
current_word = ft_strdupi_w(str + pos);
|
||||||
if (current_word[0] == '$')
|
if (current_word[0] == '$')
|
||||||
{
|
{
|
||||||
|
|
@ -64,7 +84,8 @@ int c_glob_matching(void)
|
||||||
ft_bzero(glob_echap, ft_strlen(str) >> 3);
|
ft_bzero(glob_echap, ft_strlen(str) >> 3);
|
||||||
ss_glob = glob(current_word, glob_echap, glob_echap, 1);
|
ss_glob = glob(current_word, glob_echap, glob_echap, 1);
|
||||||
free(current_word);
|
free(current_word);
|
||||||
if (!*ss_glob || !**ss_glob || !ft_strncmp(str + pos, *ss_glob, ft_strlen(*ss_glob)))
|
if (!*ss_glob || !**ss_glob ||
|
||||||
|
!ft_strncmp(str + pos, *ss_glob, ft_strlen(*ss_glob)))
|
||||||
return (0);
|
return (0);
|
||||||
c_replace_globbing(ss_glob, pos);
|
c_replace_globbing(ss_glob, pos);
|
||||||
return (1);
|
return (1);
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* c_rematch.c :+: :+: :+: */
|
/* c_match_update.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/15 12:03:30 by alao #+# #+# */
|
/* Created: 2017/02/15 12:03:30 by alao #+# #+# */
|
||||||
/* Updated: 2017/03/10 17:27:06 by gwojda ### ########.fr */
|
/* Updated: 2017/03/16 08:08:11 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "completion.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Recreate a c->match value by adding the new key pressed to it.
|
** Recreate a c->match value by adding the new key pressed to it.
|
||||||
|
|
@ -6,11 +6,11 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/16 22:17:10 by alao #+# #+# */
|
/* Created: 2017/02/16 22:17:10 by alao #+# #+# */
|
||||||
/* Updated: 2017/02/16 22:18:43 by alao ### ########.fr */
|
/* Updated: 2017/03/16 08:08:19 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "completion.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Support: Return the size of a char**.
|
** Support: Return the size of a char**.
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/03 13:10:38 by alao #+# #+# */
|
/* Created: 2017/02/03 13:10:38 by alao #+# #+# */
|
||||||
/* Updated: 2017/03/10 09:05:23 by alao ### ########.fr */
|
/* Updated: 2017/03/16 08:48:05 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "completion.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Update of the struct data.
|
** Update of the struct data.
|
||||||
|
|
@ -87,26 +87,31 @@ int c_updater(t_comp *c, char *select)
|
||||||
** return 0. Else it will return 1.
|
** return 0. Else it will return 1.
|
||||||
**
|
**
|
||||||
** Keypress values that cancel the module:
|
** Keypress values that cancel the module:
|
||||||
** 27: Escape
|
** 27 : Escape
|
||||||
** 127: Backspace
|
** 127 : Backspace
|
||||||
** 2117294875: Delete
|
** 2117294875 : Delete
|
||||||
**
|
**
|
||||||
** Keypress values that validate the choice:
|
** Keypress values that validate the choice:
|
||||||
** 10: Enter
|
** 10 : Enter
|
||||||
** 32: Space
|
** 32 : Space
|
||||||
|
** Keypress values for arrows
|
||||||
|
** 4283163 : Up
|
||||||
|
** 4348699 : Down
|
||||||
|
** 4479771 : Left
|
||||||
|
** 4414235 : Right
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int c_gtfo(t_comp *c, long int keypress)
|
int c_keypress(t_comp *c, long int key)
|
||||||
{
|
{
|
||||||
t_clst *ptr;
|
t_clst *ptr;
|
||||||
|
|
||||||
if (keypress == 27 || keypress == 127 || keypress == 2117294875)
|
if (key == 27 || key == 127 || key == 2117294875)
|
||||||
{
|
{
|
||||||
c_term_clear(c);
|
c_term_clear(c);
|
||||||
c_clear(data_singleton());
|
c_clear(data_singleton());
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
if (keypress == 10 || keypress == 32)
|
if (key == 10 || key == 32)
|
||||||
{
|
{
|
||||||
ptr = c->lst;
|
ptr = c->lst;
|
||||||
while (!ptr->cursor)
|
while (!ptr->cursor)
|
||||||
|
|
@ -114,11 +119,10 @@ int c_gtfo(t_comp *c, long int keypress)
|
||||||
c_updater(c, ptr->name);
|
c_updater(c, ptr->name);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
if (keypress == 4283163 || keypress == 4348699
|
if (key == KP_U || key == KP_D || key == KP_L || key == KP_R)
|
||||||
|| keypress == 4479771 || keypress == 4414235)
|
|
||||||
{
|
{
|
||||||
c_arrow(c, keypress);
|
c_arrow(c, key);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
return ((c_rematch(c, keypress)) ? (0) : (1));
|
return ((c_rematch(c, key)) ? (0) : (1));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/09 13:52:07 by alao #+# #+# */
|
/* Created: 2017/01/09 13:52:07 by alao #+# #+# */
|
||||||
/* Updated: 2017/03/15 06:53:34 by alao ### ########.fr */
|
/* Updated: 2017/03/16 08:49:22 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "completion.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Add the matching element to the list
|
** Add the matching element to the list
|
||||||
|
|
@ -18,7 +18,6 @@
|
||||||
|
|
||||||
void c_add_to_lst(t_comp *c, t_clst *node)
|
void c_add_to_lst(t_comp *c, t_clst *node)
|
||||||
{
|
{
|
||||||
DG("\tADD %s", node->name);
|
|
||||||
if (c->lst == NULL)
|
if (c->lst == NULL)
|
||||||
{
|
{
|
||||||
c->lst = node;
|
c->lst = node;
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/10/25 18:21:54 by alao #+# #+# */
|
/* Created: 2016/10/25 18:21:54 by alao #+# #+# */
|
||||||
/* Updated: 2017/02/16 22:17:53 by alao ### ########.fr */
|
/* Updated: 2017/03/16 08:50:38 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "completion.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Solve the tilde pattern in the path
|
** Solve the tilde pattern in the path
|
||||||
|
|
@ -18,10 +18,10 @@
|
||||||
|
|
||||||
static char *tilde(t_comp *c, char *cmd)
|
static char *tilde(t_comp *c, char *cmd)
|
||||||
{
|
{
|
||||||
char *t_home;
|
char *t_home;
|
||||||
char *t_sub;
|
char *t_sub;
|
||||||
char *rt;
|
char *rt;
|
||||||
int l_cmd;
|
int l_cmd;
|
||||||
|
|
||||||
t_home = NULL;
|
t_home = NULL;
|
||||||
t_sub = NULL;
|
t_sub = NULL;
|
||||||
|
|
@ -42,9 +42,9 @@ static char *tilde(t_comp *c, char *cmd)
|
||||||
|
|
||||||
static char *dots_purge(char **scwd, char **scmd, int i)
|
static char *dots_purge(char **scwd, char **scmd, int i)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
char *rt;
|
char *rt;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
rt = NULL;
|
rt = NULL;
|
||||||
|
|
@ -75,9 +75,9 @@ static char *dots_purge(char **scwd, char **scmd, int i)
|
||||||
|
|
||||||
static char *dots(char *cmd, char *cwd, int i)
|
static char *dots(char *cmd, char *cwd, int i)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
char **scmd;
|
char **scmd;
|
||||||
char **scwd;
|
char **scwd;
|
||||||
|
|
||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
if (!(ft_strcmp(cmd, ".")) || !(ft_strcmp(cmd, "./")))
|
if (!(ft_strcmp(cmd, ".")) || !(ft_strcmp(cmd, "./")))
|
||||||
|
|
@ -107,9 +107,9 @@ static char *dots(char *cmd, char *cwd, int i)
|
||||||
|
|
||||||
char *path_solver(t_comp *c, char *cmd, char *cwd)
|
char *path_solver(t_comp *c, char *cmd, char *cwd)
|
||||||
{
|
{
|
||||||
char *dir;
|
char *dir;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
char *ncmd;
|
char *ncmd;
|
||||||
|
|
||||||
dir = NULL;
|
dir = NULL;
|
||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/10 12:55:39 by alao #+# #+# */
|
/* Created: 2017/01/10 12:55:39 by alao #+# #+# */
|
||||||
/* Updated: 2017/03/15 14:30:37 by gwojda ### ########.fr */
|
/* Updated: 2017/03/16 09:01:22 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "completion.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Print the name with or without an underline and colored upon file type
|
** Print the name with or without an underline and colored upon file type
|
||||||
|
|
@ -21,9 +21,9 @@
|
||||||
** The rest of the placeholder is filled with space to align the list.
|
** The rest of the placeholder is filled with space to align the list.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void c_printer_node(t_clst *lst, int c_sx)
|
static void c_printer_node(t_clst *lst, int c_sx)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = lst->len;
|
i = lst->len;
|
||||||
lst->type == 4 ? ft_putstr_fd("\e[1;31m", 2) : (0);
|
lst->type == 4 ? ft_putstr_fd("\e[1;31m", 2) : (0);
|
||||||
|
|
@ -45,9 +45,9 @@ static void c_printer_node(t_clst *lst, int c_sx)
|
||||||
** trailing / for folder and a space in between.
|
** trailing / for folder and a space in between.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int c_printer_line(t_comp *c, t_clst *lst, int loop, int i)
|
static int c_printer_line(t_comp *c, t_clst *lst, int loop, int i)
|
||||||
{
|
{
|
||||||
t_clst *ptr;
|
t_clst *ptr;
|
||||||
|
|
||||||
ptr = lst->next;
|
ptr = lst->next;
|
||||||
c_printer_node(lst, c->c_sx);
|
c_printer_node(lst, c->c_sx);
|
||||||
|
|
@ -72,6 +72,25 @@ static int c_printer_line(t_comp *c, t_clst *lst, int loop, int i)
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Return the right pointer in the list from the offset value calculated below.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static t_clst *c_rolling_ptr(t_comp *c, int id)
|
||||||
|
{
|
||||||
|
t_clst *ptr;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = (id - 1) * (c->m_size - 1);
|
||||||
|
ptr = c->lst;
|
||||||
|
while (i)
|
||||||
|
{
|
||||||
|
ptr = ptr->next;
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
return (ptr);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Controlling the offset value for the rolling list if the space in the
|
** Controlling the offset value for the rolling list if the space in the
|
||||||
** terminal is too small to display the whole list.
|
** terminal is too small to display the whole list.
|
||||||
|
|
@ -90,7 +109,6 @@ static t_clst *c_rolling(t_comp *c)
|
||||||
ptr = c->lst;
|
ptr = c->lst;
|
||||||
while (!ptr->cursor)
|
while (!ptr->cursor)
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
|
|
||||||
x = 1;
|
x = 1;
|
||||||
while ((x * c->c_line) < ptr->id)
|
while ((x * c->c_line) < ptr->id)
|
||||||
x++;
|
x++;
|
||||||
|
|
@ -101,16 +119,7 @@ static t_clst *c_rolling(t_comp *c)
|
||||||
c->pos_x = id;
|
c->pos_x = id;
|
||||||
c->pos_y = y;
|
c->pos_y = y;
|
||||||
if (y > 1)
|
if (y > 1)
|
||||||
{
|
return (c_rolling_ptr(c, y));
|
||||||
x = (y - 1) * (c->m_size - 1);
|
|
||||||
ptr = c->lst;
|
|
||||||
while (x)
|
|
||||||
{
|
|
||||||
ptr = ptr->next;
|
|
||||||
x--;
|
|
||||||
}
|
|
||||||
return (ptr);
|
|
||||||
}
|
|
||||||
return (c->lst);
|
return (c->lst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,12 +127,11 @@ static t_clst *c_rolling(t_comp *c)
|
||||||
** Control the number of time it cycle for LINE
|
** Control the number of time it cycle for LINE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void c_printer(t_comp *c)
|
void c_printer(t_comp *c)
|
||||||
{
|
{
|
||||||
t_clst *ptr;
|
t_clst *ptr;
|
||||||
int loop;
|
int loop;
|
||||||
int max_line;
|
int max_line;
|
||||||
//int offset;
|
|
||||||
|
|
||||||
loop = c->c_line;
|
loop = c->c_line;
|
||||||
if (!c->c_line)
|
if (!c->c_line)
|
||||||
|
|
@ -134,7 +142,6 @@ void c_printer(t_comp *c)
|
||||||
max_line = (c->c_line % (c->m_size - 1));
|
max_line = (c->c_line % (c->m_size - 1));
|
||||||
else
|
else
|
||||||
max_line = c->m_size - 1;
|
max_line = c->m_size - 1;
|
||||||
// offset = (c->m_size - 1) - max_line;
|
|
||||||
while (loop && max_line)
|
while (loop && max_line)
|
||||||
{
|
{
|
||||||
c_printer_line(c, ptr, c->c_pline, 1);
|
c_printer_line(c, ptr, c->c_pline, 1);
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/10 08:50:26 by alao #+# #+# */
|
/* Created: 2017/01/10 08:50:26 by alao #+# #+# */
|
||||||
/* Updated: 2017/03/15 14:25:54 by gwojda ### ########.fr */
|
/* Updated: 2017/03/16 08:09:00 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "completion.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Get the max length from the list
|
** Get the max length from the list
|
||||||
|
|
|
||||||
|
|
@ -6,20 +6,20 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/10/11 10:44:40 by alao #+# #+# */
|
/* Created: 2016/10/11 10:44:40 by alao #+# #+# */
|
||||||
/* Updated: 2017/03/15 14:36:43 by gwojda ### ########.fr */
|
/* Updated: 2017/03/16 09:02:14 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "completion.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Clear the previous list from the screen and restore the same position.
|
** Clear the previous list from the screen and restore the same position.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void c_term_clear(t_comp *c)
|
void c_term_clear(t_comp *c)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int lcmd;
|
int lcmd;
|
||||||
|
|
||||||
ft_putstr(tgetstr("do", NULL));
|
ft_putstr(tgetstr("do", NULL));
|
||||||
ft_putstr(tgetstr("cd", NULL));
|
ft_putstr(tgetstr("cd", NULL));
|
||||||
|
|
@ -39,11 +39,11 @@ void c_term_clear(t_comp *c)
|
||||||
** the original position.
|
** the original position.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void c_term_mv_back(t_comp *c)
|
void c_term_mv_back(t_comp *c)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int lcmd;
|
int lcmd;
|
||||||
int value;
|
int value;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if (c->c_line > c->win_y)
|
if (c->c_line > c->win_y)
|
||||||
|
|
@ -71,10 +71,10 @@ void c_term_mv_back(t_comp *c)
|
||||||
** the first line under the prompt
|
** the first line under the prompt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void c_term_mv_down(t_comp *c)
|
void c_term_mv_down(t_comp *c)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int value;
|
int value;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if (c->c_line > c->win_y)
|
if (c->c_line > c->win_y)
|
||||||
|
|
@ -104,7 +104,7 @@ void c_term_mv_down(t_comp *c)
|
||||||
** and clear the previous print list.
|
** and clear the previous print list.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int c_term_resize(t_comp *c)
|
int c_term_resize(t_comp *c)
|
||||||
{
|
{
|
||||||
struct winsize win;
|
struct winsize win;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/09/20 14:50:33 by alao #+# #+# */
|
/* Created: 2016/09/20 14:50:33 by alao #+# #+# */
|
||||||
/* Updated: 2017/03/15 14:37:34 by gwojda ### ########.fr */
|
/* Updated: 2017/03/16 09:17:11 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "completion.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Function to select the next item in the list if it has already been created
|
** Function to select the next item in the list if it has already been created
|
||||||
|
|
@ -36,7 +36,7 @@ static void c_next_item(t_comp *c)
|
||||||
** of the cursor is restored.
|
** of the cursor is restored.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int c_dispatcher(t_data *s)
|
int c_dispatcher(t_data *s)
|
||||||
{
|
{
|
||||||
if (s->comp && s->comp->lst == NULL)
|
if (s->comp && s->comp->lst == NULL)
|
||||||
{
|
{
|
||||||
|
|
@ -85,10 +85,8 @@ int completion(long int keypress)
|
||||||
return (1);
|
return (1);
|
||||||
if (s->comp == NULL)
|
if (s->comp == NULL)
|
||||||
{
|
{
|
||||||
if (s->line.pos == 0)
|
if ((s->line.pos == 0) || (s->line.input[s->line.pos] != ' ' &&
|
||||||
return (0);
|
s->line.input[s->line.pos] != '\0'))
|
||||||
if (s->line.input[s->line.pos] != ' ' &&
|
|
||||||
s->line.input[s->line.pos] != '\0')
|
|
||||||
return (0);
|
return (0);
|
||||||
c_init(s, keypress);
|
c_init(s, keypress);
|
||||||
if (s->comp == NULL)
|
if (s->comp == NULL)
|
||||||
|
|
@ -99,11 +97,8 @@ int completion(long int keypress)
|
||||||
c_term_resize(s->comp);
|
c_term_resize(s->comp);
|
||||||
if (keypress == TOUCHE_TAB)
|
if (keypress == TOUCHE_TAB)
|
||||||
c_next_item(s->comp);
|
c_next_item(s->comp);
|
||||||
else
|
else if (c_keypress(s->comp, keypress))
|
||||||
{
|
return (1);
|
||||||
if (c_gtfo(s->comp, keypress))
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return (c_dispatcher(s));
|
return (c_dispatcher(s));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue