better parsing if
This commit is contained in:
commit
63ed4b64f4
37 changed files with 597 additions and 98 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
|
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
|
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
|
||||||
#* Updated: 2017/03/05 15:36:45 by wescande ### ########.fr *#
|
# Updated: 2017/03/10 17:40:02 by gwojda ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -44,9 +44,12 @@ 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_binary.c\
|
completion/c_binary.c\
|
||||||
completion/c_clear.c\
|
completion/c_clear.c\
|
||||||
completion/c_files.c\
|
completion/c_files.c\
|
||||||
|
completion/c_glob_matching.c\
|
||||||
completion/c_init.c\
|
completion/c_init.c\
|
||||||
completion/c_matching.c\
|
completion/c_matching.c\
|
||||||
completion/c_misc.c\
|
completion/c_misc.c\
|
||||||
|
|
@ -55,6 +58,7 @@ 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_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\
|
||||||
|
|
@ -245,6 +249,7 @@ line-editing/home_end.c\
|
||||||
line-editing/init_history.c\
|
line-editing/init_history.c\
|
||||||
line-editing/init_line.c\
|
line-editing/init_line.c\
|
||||||
line-editing/init_termcaps.c\
|
line-editing/init_termcaps.c\
|
||||||
|
line-editing/lib_line_editing/ft_nb_line.c\
|
||||||
line-editing/lib_line_editing/tool_line.c\
|
line-editing/lib_line_editing/tool_line.c\
|
||||||
line-editing/lib_line_editing/tool_line_2.c\
|
line-editing/lib_line_editing/tool_line_2.c\
|
||||||
line-editing/lib_line_editing/toolz.c\
|
line-editing/lib_line_editing/toolz.c\
|
||||||
|
|
@ -297,7 +302,7 @@ NB = $(words $(SRC_BASE))
|
||||||
INDEX = 0
|
INDEX = 0
|
||||||
|
|
||||||
all :
|
all :
|
||||||
@make -j $(NAME)
|
@make $(NAME)
|
||||||
|
|
||||||
$(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS)
|
$(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS)
|
||||||
@$(CC) $(OBJS) -o $(NAME) \
|
@$(CC) $(OBJS) -o $(NAME) \
|
||||||
|
|
|
||||||
|
|
@ -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/02/17 11:10:48 by gwojda ### ########.fr */
|
/* Updated: 2017/03/10 17:38:50 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
# define COMPLETION_H
|
# define COMPLETION_H
|
||||||
|
|
||||||
# include "minishell.h"
|
# include "minishell.h"
|
||||||
|
#define RETARDED_BEHAVIOR 0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Autocompletion list for the valid candidates from the parser.
|
** Autocompletion list for the valid candidates from the parser.
|
||||||
|
|
@ -55,6 +56,10 @@ typedef struct s_clst
|
||||||
** c_pline : Number of item per line when printing.
|
** c_pline : Number of item per line when printing.
|
||||||
** c_line : Number of line required to move to terminal up.
|
** c_line : Number of line required to move to terminal up.
|
||||||
** win_x : Size of the window in length.
|
** win_x : Size of the window in length.
|
||||||
|
** win_y : Size of the window in height.
|
||||||
|
** m_size : Max size of the list in pagination.
|
||||||
|
** pos_x : Position of the element relative to the terminal in list mode (X).
|
||||||
|
** pos_y : Position of the element relative to the terminal in list mode (Y).
|
||||||
** key : The keypressed lastly.
|
** key : The keypressed lastly.
|
||||||
** isfolder : If the match is a folder. boolean.
|
** isfolder : If the match is a folder. boolean.
|
||||||
** lst : List of the item corresponding to the completion.
|
** lst : List of the item corresponding to the completion.
|
||||||
|
|
@ -63,9 +68,9 @@ typedef struct s_clst
|
||||||
**
|
**
|
||||||
** Exemple: [ ls / ; cd (tab) ; pwd ]
|
** Exemple: [ ls / ; cd (tab) ; pwd ]
|
||||||
**
|
**
|
||||||
** (int)cutpoint
|
** (int)cutpoint
|
||||||
** |
|
** |
|
||||||
** |
|
** |
|
||||||
** Become: [ls / ;] [ ] [cd ] [ ; pwd]
|
** Become: [ls / ;] [ ] [cd ] [ ; pwd]
|
||||||
** | | | |
|
** | | | |
|
||||||
** | | | |
|
** | | | |
|
||||||
|
|
@ -90,8 +95,13 @@ typedef struct s_comp
|
||||||
int c_pline;
|
int c_pline;
|
||||||
int c_line;
|
int c_line;
|
||||||
int win_x;
|
int win_x;
|
||||||
|
int win_y;
|
||||||
|
int m_size;
|
||||||
|
int pos_x;
|
||||||
|
int pos_y;
|
||||||
int key;
|
int key;
|
||||||
int isfolder;
|
int isfolder;
|
||||||
|
int isrematch;
|
||||||
t_clst *lst;
|
t_clst *lst;
|
||||||
} t_comp;
|
} t_comp;
|
||||||
|
|
||||||
|
|
@ -132,12 +142,14 @@ int c_rematch(t_comp *c, long int keypress);
|
||||||
** c_term_mv_down : Make space for the list.
|
** c_term_mv_down : Make space for the list.
|
||||||
** c_term_mv_back : Reset the cursor position.
|
** c_term_mv_back : Reset the cursor position.
|
||||||
** c_term_clear : Delete the list from the terminal.
|
** c_term_clear : Delete the list from the terminal.
|
||||||
|
** c_term_resize : Refresh win_x and win_y.
|
||||||
** 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);
|
||||||
void c_printer(t_comp *c);
|
void c_printer(t_comp *c);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -151,12 +163,20 @@ void c_printer(t_comp *c);
|
||||||
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_spacing_clear(t_comp *c);
|
||||||
|
int ft_sstrlen(char **s);
|
||||||
|
char *ft_sstrtostr(char **s, char *sep);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** ajout rapide gwojda pour compiler :
|
** j'ajoute a la va vite^^
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int ft_sstrlen(char **s);
|
int c_glob_matching(void);
|
||||||
char *ft_sstrtostr(char **s, char *sep);
|
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);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* exec.h :+: :+: :+: */
|
/* exec.h :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/10 17:39:42 by ariard ### ########.fr */
|
/* Updated: 2017/03/10 18:09:53 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/09 11:55:17 by gwojda ### ########.fr */
|
/* Updated: 2017/03/10 17:40:40 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -129,6 +129,8 @@ int ft_put(int nb);
|
||||||
void ft_check_line(void);
|
void ft_check_line(void);
|
||||||
void ft_clear_window(void);
|
void ft_clear_window(void);
|
||||||
void free_history_list(t_list_history *head);
|
void free_history_list(t_list_history *head);
|
||||||
|
int ft_nb_of_line(char *str, size_t pos);
|
||||||
|
int ft_get_size_prev(char *str, size_t pos);
|
||||||
|
|
||||||
char *ft_read_stdin(void);
|
char *ft_read_stdin(void);
|
||||||
void ft_end(void);
|
void ft_end(void);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
|
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/10 15:38:44 by jhalford ### ########.fr */
|
/* Updated: 2017/03/10 16:57:46 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
52
42sh/src/completion/c_abs_path.c
Normal file
52
42sh/src/completion/c_abs_path.c
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* c_abs_path.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/09 16:54:59 by gwojda #+# #+# */
|
||||||
|
/* Updated: 2017/03/09 17:34:43 by gwojda ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "completion.h"
|
||||||
|
|
||||||
|
static int c_exclusion_folder(t_comp *c)
|
||||||
|
{
|
||||||
|
DIR *rep;
|
||||||
|
char *tmp;
|
||||||
|
char *tmp2;
|
||||||
|
|
||||||
|
tmp = ft_strjoin(c->cpath, c->match);
|
||||||
|
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;
|
||||||
|
|
||||||
|
c->cpath = ft_strndup(current_word, ft_strrchr(c->rcmd, '/') - current_word + 1);
|
||||||
|
if (current_word[0] == '~')
|
||||||
|
{
|
||||||
|
tmp = c->cpath;
|
||||||
|
c->cpath = ft_str3join(getenv("PWD"), "/", c->cpath + 2);
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
|
!c->match ? c->match = ft_strdupi_w(ft_strrchr(c->rcmd, '/') + 1) : 0;
|
||||||
|
c_parser(c, c->cpath, c->match);
|
||||||
|
c_exclusion_folder(c);
|
||||||
|
}
|
||||||
105
42sh/src/completion/c_arrow.c
Normal file
105
42sh/src/completion/c_arrow.c
Normal file
|
|
@ -0,0 +1,105 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* c_arrow.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/10 09:04:42 by alao #+# #+# */
|
||||||
|
/* Updated: 2017/03/10 12:44:05 by alao ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "completion.h"
|
||||||
|
|
||||||
|
static void c_arrow_right(t_comp *c)
|
||||||
|
{
|
||||||
|
t_clst *ptr;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
ptr = c->lst;
|
||||||
|
i = 0;
|
||||||
|
while (!ptr->cursor)
|
||||||
|
ptr = ptr->next;
|
||||||
|
ptr->cursor = 0;
|
||||||
|
while (i < c->c_line)
|
||||||
|
{
|
||||||
|
ptr = ptr->next;
|
||||||
|
if (ptr == c->lst)
|
||||||
|
i += c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (c->pos_x == (c->c_pline - 1))
|
||||||
|
{
|
||||||
|
i = c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line));
|
||||||
|
while (i < c->c_line)
|
||||||
|
{
|
||||||
|
ptr = ptr->next;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ptr->cursor = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void c_arrow_left(t_comp *c)
|
||||||
|
{
|
||||||
|
t_clst *ptr;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
ptr = c->lst;
|
||||||
|
i = 0;
|
||||||
|
while (!ptr->cursor)
|
||||||
|
ptr = ptr->next;
|
||||||
|
ptr->cursor = 0;
|
||||||
|
while (i < c->c_line)
|
||||||
|
{
|
||||||
|
ptr = ptr->prev;
|
||||||
|
if (ptr == c->lst)
|
||||||
|
i += c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
/* if (c->pos_x == 1)
|
||||||
|
{
|
||||||
|
i = c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line));
|
||||||
|
while (i < c->c_line)
|
||||||
|
{
|
||||||
|
ptr = ptr->prev;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
ptr->cursor = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void c_arrow_down(t_comp *c)
|
||||||
|
{
|
||||||
|
t_clst *ptr;
|
||||||
|
|
||||||
|
ptr = c->lst;
|
||||||
|
while (!ptr->cursor)
|
||||||
|
ptr = ptr->next;
|
||||||
|
ptr->cursor = 0;
|
||||||
|
ptr->next->cursor = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void c_arrow_up(t_comp *c)
|
||||||
|
{
|
||||||
|
t_clst *ptr;
|
||||||
|
|
||||||
|
ptr = c->lst;
|
||||||
|
while (!ptr->cursor)
|
||||||
|
ptr = ptr->next;
|
||||||
|
ptr->cursor = 0;
|
||||||
|
ptr->prev->cursor = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void c_arrow(t_comp *c, long int keypress)
|
||||||
|
{
|
||||||
|
if (keypress == 4283163)
|
||||||
|
c_arrow_up(c);
|
||||||
|
if (keypress == 4348699)
|
||||||
|
c_arrow_down(c);
|
||||||
|
if (keypress == 4479771)
|
||||||
|
c_arrow_left(c);
|
||||||
|
if (keypress == 4414235)
|
||||||
|
c_arrow_right(c);
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* 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/16 21:03:18 by alao ### ########.fr */
|
/* Updated: 2017/02/27 13:17:27 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -29,7 +29,8 @@ int c_seek_binary(t_data *s, t_comp *c)
|
||||||
if (!(tmp = ft_strdup(ft_getenv(s->env, "PATH"))))
|
if (!(tmp = ft_strdup(ft_getenv(s->env, "PATH"))))
|
||||||
return (-1);
|
return (-1);
|
||||||
paths = ft_strsplit(tmp, ':');
|
paths = ft_strsplit(tmp, ':');
|
||||||
c->match = ft_strdup(c->rcmd);
|
if (c->match == NULL)
|
||||||
|
c->match = ft_strdup(c->rcmd);
|
||||||
while (paths[i])
|
while (paths[i])
|
||||||
c_parser(c, paths[i++], c->rcmd);
|
c_parser(c, paths[i++], c->rcmd);
|
||||||
tmp ? ft_memdel((void *)&tmp) : (0);
|
tmp ? ft_memdel((void *)&tmp) : (0);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* 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/16 22:03:41 by alao ### ########.fr */
|
/* Updated: 2017/02/17 14:57:09 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -21,6 +21,8 @@ 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)
|
||||||
|
return (0);
|
||||||
c_lst = c->lst;
|
c_lst = c->lst;
|
||||||
c->lst->prev ? (c->lst = c->lst->prev) : (0);
|
c->lst->prev ? (c->lst = c->lst->prev) : (0);
|
||||||
c_lst->prev->next = NULL;
|
c_lst->prev->next = NULL;
|
||||||
|
|
@ -48,6 +50,8 @@ int c_clear(t_data *s)
|
||||||
{
|
{
|
||||||
t_comp *ptr;
|
t_comp *ptr;
|
||||||
|
|
||||||
|
if (s->comp == NULL)
|
||||||
|
return (0);
|
||||||
ptr = s->comp;
|
ptr = s->comp;
|
||||||
ptr->rcmd ? ft_memdel((void *)&ptr->rcmd) : (0);
|
ptr->rcmd ? ft_memdel((void *)&ptr->rcmd) : (0);
|
||||||
ptr->match ? ft_memdel((void *)&ptr->match) : (0);
|
ptr->match ? ft_memdel((void *)&ptr->match) : (0);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* 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/02/16 22:14:51 by alao ### ########.fr */
|
/* Updated: 2017/03/10 17:38:37 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -27,15 +27,22 @@ static int c_exclusion_folder(t_comp *c)
|
||||||
char *tmp2;
|
char *tmp2;
|
||||||
|
|
||||||
tmp = ft_strjoin(c->cpath, c->match);
|
tmp = ft_strjoin(c->cpath, c->match);
|
||||||
|
tmp2 = NULL;
|
||||||
if ((rep = opendir(tmp)) && (!closedir(rep)))
|
if ((rep = opendir(tmp)) && (!closedir(rep)))
|
||||||
{
|
{
|
||||||
|
tmp ? ft_memdel((void *)&tmp) : (0);
|
||||||
|
if (c->rcmd[ft_strlen(c->rcmd) - 1] == '/')
|
||||||
|
{
|
||||||
|
c_clear(data_singleton());
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
tmp2 = ft_strjoin(c->match, "/");
|
tmp2 = ft_strjoin(c->match, "/");
|
||||||
c_updater(c, tmp2);
|
c_updater(c, tmp2);
|
||||||
tmp ? ft_memdel((void *)&tmp) : (0);
|
|
||||||
tmp2 ? ft_memdel((void *)&tmp2) : (0);
|
tmp2 ? ft_memdel((void *)&tmp2) : (0);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
tmp ? ft_memdel((void *)&tmp) : (0);
|
tmp ? ft_memdel((void *)&tmp) : (0);
|
||||||
|
tmp ? ft_memdel((void *)&tmp) : (0);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
|
@ -63,7 +70,9 @@ static char *c_slicer(t_comp *c)
|
||||||
i--;
|
i--;
|
||||||
tmp[i] == '/' ? i++ : (0);
|
tmp[i] == '/' ? i++ : (0);
|
||||||
rt = (i == (int)ft_strlen(tmp) - 1) ? NULL : ft_strsub(tmp, 0, i);
|
rt = (i == (int)ft_strlen(tmp) - 1) ? NULL : ft_strsub(tmp, 0, i);
|
||||||
if (i <= (int)ft_strlen(tmp) - i + 1)
|
if (c_chevron(c))
|
||||||
|
c->match = ft_strdup("");
|
||||||
|
else
|
||||||
c->match = ft_strsub(tmp, i, ft_strlen(tmp) - i);
|
c->match = ft_strsub(tmp, i, ft_strlen(tmp) - i);
|
||||||
tmp ? ft_memdel((void *)&tmp) : (0);
|
tmp ? ft_memdel((void *)&tmp) : (0);
|
||||||
return (rt);
|
return (rt);
|
||||||
|
|
@ -78,6 +87,11 @@ int c_seek_files(t_data *s, t_comp *c)
|
||||||
char *path;
|
char *path;
|
||||||
|
|
||||||
(void)s;
|
(void)s;
|
||||||
|
if (c->rcmd[0] == '.')
|
||||||
|
{
|
||||||
|
c->cpath = ft_strdup("./");
|
||||||
|
c->match = ft_strdup(".");
|
||||||
|
}
|
||||||
if (c->cpath == NULL)
|
if (c->cpath == NULL)
|
||||||
{
|
{
|
||||||
path = c_slicer(c);
|
path = c_slicer(c);
|
||||||
|
|
@ -85,7 +99,12 @@ int c_seek_files(t_data *s, t_comp *c)
|
||||||
path ? ft_memdel((void *)&path) : (0);
|
path ? ft_memdel((void *)&path) : (0);
|
||||||
}
|
}
|
||||||
c_parser(c, c->cpath, c->match);
|
c_parser(c, c->cpath, c->match);
|
||||||
if (c->lst == NULL)
|
if (c->lst == NULL && c->isrematch == 0)
|
||||||
c_exclusion_folder(c);
|
c_exclusion_folder(c);
|
||||||
|
else if ((c->lst && (c->lst == c->lst->next)) && c->isrematch == 0)
|
||||||
|
{
|
||||||
|
if (c->match && ft_strequ(c->match, c->lst->name))
|
||||||
|
c_exclusion_folder(c);
|
||||||
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
72
42sh/src/completion/c_glob_matching.c
Normal file
72
42sh/src/completion/c_glob_matching.c
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* c_glob_matching.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/08 17:20:01 by gwojda #+# #+# */
|
||||||
|
/* Updated: 2017/03/10 17:43:15 by gwojda ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
static void c_replace_globbing(char **glob, size_t start)
|
||||||
|
{
|
||||||
|
char *ref_next;
|
||||||
|
char *ref_mid;
|
||||||
|
char *ref_prev;
|
||||||
|
char *str;
|
||||||
|
size_t pos;
|
||||||
|
|
||||||
|
str = data_singleton()->line.input;
|
||||||
|
pos = data_singleton()->line.pos;
|
||||||
|
while (str[pos] && str[pos] != ' ')
|
||||||
|
++pos;
|
||||||
|
while (str[pos] && str[pos] == ' ')
|
||||||
|
++pos;
|
||||||
|
ref_prev = ft_strndup(str, start);
|
||||||
|
ref_mid = ft_sstrtostr(glob, " ");
|
||||||
|
ref_next = ft_strdup(str + pos);
|
||||||
|
data_singleton()->line.input = ft_str3join(ref_prev, ref_mid, ref_next);
|
||||||
|
free(ref_prev);
|
||||||
|
free(ref_mid);
|
||||||
|
free(ref_next);
|
||||||
|
free(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
int c_glob_matching(void)
|
||||||
|
{
|
||||||
|
char *current_word;
|
||||||
|
char **ss_glob;
|
||||||
|
unsigned char *glob_echap;
|
||||||
|
char *str;
|
||||||
|
size_t pos;
|
||||||
|
|
||||||
|
str = data_singleton()->line.input;
|
||||||
|
pos = data_singleton()->line.pos;
|
||||||
|
if (!str)
|
||||||
|
return (0);
|
||||||
|
if (pos && str[pos] == ' ')
|
||||||
|
--pos;
|
||||||
|
while (pos && str[pos] != ' ')
|
||||||
|
--pos;
|
||||||
|
if (str[pos] == ' ')
|
||||||
|
++pos;
|
||||||
|
current_word = ft_strdupi_w(str + pos);
|
||||||
|
if (current_word[0] == '$')
|
||||||
|
{
|
||||||
|
free(current_word);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
glob_echap = (unsigned char *)ft_strnew(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);
|
||||||
|
free(current_word);
|
||||||
|
if (!*ss_glob || !**ss_glob || !ft_strncmp(str + pos, *ss_glob, ft_strlen(*ss_glob)))
|
||||||
|
return (0);
|
||||||
|
c_replace_globbing(ss_glob, pos);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* 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/02/16 22:08:25 by alao ### ########.fr */
|
/* Updated: 2017/03/10 12:43:57 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -55,9 +55,17 @@ static void c_init_base(t_comp *c)
|
||||||
|
|
||||||
ioctl(0, TIOCGWINSZ, &win);
|
ioctl(0, TIOCGWINSZ, &win);
|
||||||
c->win_x = win.ws_col;
|
c->win_x = win.ws_col;
|
||||||
|
c->win_y = win.ws_row;
|
||||||
|
c->m_size = data_singleton()->line.prompt_size;
|
||||||
|
c->m_size += ft_strlen(data_singleton()->line.input);
|
||||||
|
c->m_size = (c->m_size / c->win_y);
|
||||||
|
c->m_size = c->win_y - c->m_size - 1;
|
||||||
|
c->pos_x = 1;
|
||||||
|
c->pos_y = 1;
|
||||||
c->cutpoint = 0;
|
c->cutpoint = 0;
|
||||||
c->between = NULL;
|
c->between = NULL;
|
||||||
c->isfolder = 0;
|
c->isfolder = 0;
|
||||||
|
c->isrematch = 0;
|
||||||
c->match = NULL;
|
c->match = NULL;
|
||||||
c->cpath = NULL;
|
c->cpath = NULL;
|
||||||
c->lst = NULL;
|
c->lst = NULL;
|
||||||
|
|
@ -70,9 +78,8 @@ static void c_init_base(t_comp *c)
|
||||||
** structure data and call for the c_matching() function.
|
** structure data and call for the c_matching() function.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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)))))
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,32 @@
|
||||||
/* 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/02/16 21:57:47 by alao ### ########.fr */
|
/* Updated: 2017/03/10 17:20:20 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
** chevron y es-tu ???
|
||||||
|
*/
|
||||||
|
|
||||||
|
int c_chevron(t_comp *c)
|
||||||
|
{
|
||||||
|
size_t pos;
|
||||||
|
|
||||||
|
pos = c->ircmd;
|
||||||
|
while (pos)
|
||||||
|
{
|
||||||
|
if (c->rcmd[pos] == '<' || c->rcmd[pos] == '>')
|
||||||
|
return (1);
|
||||||
|
--pos;
|
||||||
|
}
|
||||||
|
if (c->rcmd[pos] == '<' || c->rcmd[pos] == '>')
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Start the parsing for the autocompletion.
|
** Start the parsing for the autocompletion.
|
||||||
** Check the first char of the c->rcmd for a . or /. to see if it's a local
|
** Check the first char of the c->rcmd for a . or /. to see if it's a local
|
||||||
|
|
@ -25,19 +45,32 @@
|
||||||
** Else 0 is returned.
|
** Else 0 is returned.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static char *c_current_words(t_comp *c)
|
||||||
|
{
|
||||||
|
int pos;
|
||||||
|
|
||||||
|
pos = c->ircmd;
|
||||||
|
while (pos && c->rcmd[pos] != ' ')
|
||||||
|
--pos;
|
||||||
|
if (c->rcmd[pos] == ' ')
|
||||||
|
++pos;
|
||||||
|
return (c->rcmd + pos);
|
||||||
|
}
|
||||||
|
|
||||||
int c_matching(t_data *s, t_comp *c)
|
int c_matching(t_data *s, t_comp *c)
|
||||||
{
|
{
|
||||||
if (c->rcmd[0] == '.' || c->rcmd[0] == '/')
|
char *current_word;
|
||||||
{
|
|
||||||
c->rcmd[0] == '.' ? c->cpath = path_solver(c, "./", NULL) : 0;
|
current_word = c_current_words(c);
|
||||||
c->rcmd[0] == '/' ? c->cpath = path_solver(c, "/", NULL) : 0;
|
if (ft_strchr(c->rcmd, '/'))
|
||||||
c_parser(c, c->cpath, c->match);
|
c_seek_abs_path(c, current_word);
|
||||||
}
|
else if (ft_strchr(c->rcmd, '$'))
|
||||||
else if (!(ft_strchr(c->rcmd, ' ')))
|
c_seek_env(c, current_word);
|
||||||
|
else if (c->rcmd[0] != '.' && !(ft_strchr(c->rcmd, ' ')) && !c_chevron(c))
|
||||||
c_seek_binary(s, c);
|
c_seek_binary(s, c);
|
||||||
else
|
else
|
||||||
c_seek_files(s, c);
|
c_seek_files(s, c);
|
||||||
if (s->comp && c->lst)
|
if (s->comp && s->comp->lst)
|
||||||
{
|
{
|
||||||
c_sizing(c);
|
c_sizing(c);
|
||||||
return (1);
|
return (1);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* 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/02/16 22:00:38 by alao ### ########.fr */
|
/* Updated: 2017/03/10 09:05:23 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -114,5 +114,11 @@ 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
|
||||||
|
|| keypress == 4479771 || keypress == 4414235)
|
||||||
|
{
|
||||||
|
c_arrow(c, keypress);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
return ((c_rematch(c, keypress)) ? (0) : (1));
|
return ((c_rematch(c, keypress)) ? (0) : (1));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* 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/02/16 22:00:49 by alao ### ########.fr */
|
/* Updated: 2017/03/09 16:47:31 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
** Add the matching element to the list
|
** Add the matching element to the list
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void c_add_to_lst(t_comp *c, t_clst *node)
|
void c_add_to_lst(t_comp *c, t_clst *node)
|
||||||
{
|
{
|
||||||
if (c->lst == NULL)
|
if (c->lst == NULL)
|
||||||
{
|
{
|
||||||
|
|
@ -49,8 +49,6 @@ static int c_storing(t_comp *c, char *value, unsigned char type)
|
||||||
return (0);
|
return (0);
|
||||||
if (c->match && ft_strnequ(c->match, value, ft_strlen(c->match)) != 1)
|
if (c->match && ft_strnequ(c->match, value, ft_strlen(c->match)) != 1)
|
||||||
return (0);
|
return (0);
|
||||||
if (c->match && ft_strequ(c->match, value))
|
|
||||||
return (0);
|
|
||||||
if (!(tmp = (t_clst *)malloc(sizeof(t_clst))))
|
if (!(tmp = (t_clst *)malloc(sizeof(t_clst))))
|
||||||
return (-1);
|
return (-1);
|
||||||
tmp->name = ft_strdup(value);
|
tmp->name = ft_strdup(value);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* 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/02/16 22:11:48 by alao ### ########.fr */
|
/* Updated: 2017/03/10 16:09:46 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -72,6 +72,48 @@ static int c_printer_line(t_comp *c, t_clst *lst, int loop, int i)
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Controlling the offset value for the rolling list if the space in the
|
||||||
|
** terminal is too small to display the whole list.
|
||||||
|
**
|
||||||
|
** Controlled value are:
|
||||||
|
** - x : the column of the element currently selected.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static t_clst *c_rolling(t_comp *c)
|
||||||
|
{
|
||||||
|
t_clst *ptr;
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int id;
|
||||||
|
|
||||||
|
ptr = c->lst;
|
||||||
|
while (!ptr->cursor)
|
||||||
|
ptr = ptr->next;
|
||||||
|
|
||||||
|
x = 1;
|
||||||
|
while ((x * c->c_line) < ptr->id)
|
||||||
|
x++;
|
||||||
|
id = ((x == 1) ? ptr->id : (ptr->id - ((x - 1) * c->c_line)));
|
||||||
|
y = 1;
|
||||||
|
while ((y * (c->m_size - 1)) < id)
|
||||||
|
y++;
|
||||||
|
c->pos_x = id;
|
||||||
|
c->pos_y = y;
|
||||||
|
if (y > 1)
|
||||||
|
{
|
||||||
|
x = (y - 1) * (c->m_size - 1);
|
||||||
|
ptr = c->lst;
|
||||||
|
while (x)
|
||||||
|
{
|
||||||
|
ptr = ptr->next;
|
||||||
|
x--;
|
||||||
|
}
|
||||||
|
return (ptr);
|
||||||
|
}
|
||||||
|
return (c->lst);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Control the number of time it cycle for LINE
|
** Control the number of time it cycle for LINE
|
||||||
*/
|
*/
|
||||||
|
|
@ -80,14 +122,24 @@ void c_printer(t_comp *c)
|
||||||
{
|
{
|
||||||
t_clst *ptr;
|
t_clst *ptr;
|
||||||
int loop;
|
int loop;
|
||||||
|
int max_line;
|
||||||
|
int offset;
|
||||||
|
|
||||||
ptr = c->lst;
|
|
||||||
loop = c->c_line;
|
loop = c->c_line;
|
||||||
while (loop)
|
|
||||||
|
max_line = c->c_line - (c->m_size - 1);
|
||||||
|
ptr = c_rolling(c);
|
||||||
|
if ((c->pos_y * (c->m_size - 1)) > c->c_line)
|
||||||
|
max_line = (c->c_line % (c->m_size - 1));
|
||||||
|
else
|
||||||
|
max_line = c->m_size - 1;
|
||||||
|
offset = (c->m_size - 1) - max_line;
|
||||||
|
while (loop && max_line)
|
||||||
{
|
{
|
||||||
c_printer_line(c, ptr, c->c_pline, 1);
|
c_printer_line(c, ptr, c->c_pline, 1);
|
||||||
loop > 1 ? ft_putstr(tgetstr("do", NULL)) : (0);
|
loop > 1 ? ft_putstr(tgetstr("do", NULL)) : (0);
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
loop--;
|
loop--;
|
||||||
|
max_line--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* 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/02/16 22:03:42 by alao ### ########.fr */
|
/* Updated: 2017/03/10 17:27:06 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -50,22 +50,17 @@ int c_rematch(t_comp *c, long int keypress)
|
||||||
{
|
{
|
||||||
if (ft_isascii(keypress))
|
if (ft_isascii(keypress))
|
||||||
{
|
{
|
||||||
|
c->isrematch = 1;
|
||||||
c_term_clear(c);
|
c_term_clear(c);
|
||||||
c_refresh_match(c, keypress);
|
c_refresh_match(c, keypress);
|
||||||
c_clear_lst(c);
|
c_clear_lst(c);
|
||||||
c_matching(data_singleton(), c);
|
c_matching(data_singleton(), c);
|
||||||
if (c->lst == NULL)
|
if (c->lst == NULL)
|
||||||
{
|
|
||||||
c_clear(data_singleton());
|
c_clear(data_singleton());
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
else if (c->lst == c->lst->next)
|
else if (c->lst == c->lst->next)
|
||||||
return (1);
|
return (1);
|
||||||
else
|
ft_print(keypress);
|
||||||
{
|
return(1);
|
||||||
ft_print(keypress);
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
55
42sh/src/completion/c_seek_env.c
Normal file
55
42sh/src/completion/c_seek_env.c
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* c_seek_env.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/09 15:50:24 by gwojda #+# #+# */
|
||||||
|
/* Updated: 2017/03/10 17:33:37 by gwojda ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
static int c_storing(t_comp *c, char *value)
|
||||||
|
{
|
||||||
|
t_clst *tmp;
|
||||||
|
|
||||||
|
if (!(tmp = (t_clst *)malloc(sizeof(t_clst))))
|
||||||
|
return (-1);
|
||||||
|
tmp->name = value;
|
||||||
|
tmp->len = ft_strlen(tmp->name);
|
||||||
|
tmp->type = 10;
|
||||||
|
tmp->cursor = 0;
|
||||||
|
c_add_to_lst(c, tmp);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void c_maj_rcmd(t_comp *c, char *current_word)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
tmp = c->rcmd;
|
||||||
|
c->rcmd = ft_strdupi_w(current_word);
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
int c_seek_env(t_comp *c, char *current_word)
|
||||||
|
{
|
||||||
|
char *match;
|
||||||
|
char **env;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
env = data_singleton()->env;
|
||||||
|
match = ft_strdupi_w(current_word + 1);
|
||||||
|
c_maj_rcmd(c, current_word);
|
||||||
|
while (env[i])
|
||||||
|
{
|
||||||
|
if (!ft_strncmp(match, env[i], ft_strlen(match)))
|
||||||
|
c_storing(c, ft_strndup(env[i], ft_strchr(env[i], '=') - env[i]));
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* 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/02/16 22:01:47 by alao ### ########.fr */
|
/* Updated: 2017/03/10 08:45:52 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -56,7 +56,7 @@ int c_sizing(t_comp *c)
|
||||||
c->c_line = 0;
|
c->c_line = 0;
|
||||||
while ((c->c_line * c->c_pline) < c->c_sy)
|
while ((c->c_line * c->c_pline) < c->c_sy)
|
||||||
c->c_line++;
|
c->c_line++;
|
||||||
if (c->win_x < c->c_sx)
|
if ((c->win_x < c->c_sx))
|
||||||
{
|
{
|
||||||
c->c_pline = 0;
|
c->c_pline = 0;
|
||||||
c->c_line = 0;
|
c->c_line = 0;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* 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/02/16 22:01:37 by alao ### ########.fr */
|
/* Updated: 2017/03/10 16:07:36 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -43,9 +43,14 @@ void c_term_mv_back(t_comp *c)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int lcmd;
|
int lcmd;
|
||||||
|
int value;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i != (c->c_line))
|
if (c->c_sy > c->win_y)
|
||||||
|
value = c->m_size;
|
||||||
|
else
|
||||||
|
value = c->c_line;
|
||||||
|
while (i != value)
|
||||||
{
|
{
|
||||||
ft_putstr(tgetstr("up", NULL));
|
ft_putstr(tgetstr("up", NULL));
|
||||||
i++;
|
i++;
|
||||||
|
|
@ -69,18 +74,46 @@ void c_term_mv_back(t_comp *c)
|
||||||
void c_term_mv_down(t_comp *c)
|
void c_term_mv_down(t_comp *c)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
int value;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < c->c_line)
|
if (c->c_sy > c->win_y)
|
||||||
|
value = c->m_size;
|
||||||
|
else
|
||||||
|
value = c->c_line;
|
||||||
|
while (i < value)
|
||||||
{
|
{
|
||||||
ft_putstr(tgetstr("do", NULL));
|
ft_putstr(tgetstr("do", NULL));
|
||||||
ft_putstr(tgetstr("cd", NULL));
|
ft_putstr(tgetstr("cd", NULL));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i != (c->c_line - 1))
|
if (c->c_sy > c->win_y)
|
||||||
|
value = c->m_size - 1;
|
||||||
|
else
|
||||||
|
value = c->c_line - 1;
|
||||||
|
while (i != value)
|
||||||
{
|
{
|
||||||
ft_putstr(tgetstr("up", NULL));
|
ft_putstr(tgetstr("up", NULL));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** If the terminal has changed in size, the function will refresh these values
|
||||||
|
** and clear the previous print list.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int c_term_resize(t_comp *c)
|
||||||
|
{
|
||||||
|
struct winsize win;
|
||||||
|
|
||||||
|
ioctl(0, TIOCGWINSZ, &win);
|
||||||
|
if ((win.ws_col == c->win_x) && (win.ws_row == c->win_y))
|
||||||
|
return (0);
|
||||||
|
c->win_x = win.ws_col;
|
||||||
|
c->win_y = win.ws_row;
|
||||||
|
c_sizing(c);
|
||||||
|
c_term_clear(c);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* 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/02/16 22:01:18 by alao ### ########.fr */
|
/* Updated: 2017/03/10 17:20:04 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -38,18 +38,16 @@ static void c_next_item(t_comp *c)
|
||||||
|
|
||||||
static int c_dispatcher(t_data *s)
|
static int c_dispatcher(t_data *s)
|
||||||
{
|
{
|
||||||
if (s->comp && s->comp->lst == NULL && s->comp->isfolder)
|
|
||||||
{
|
|
||||||
c_clear(s);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
if (s->comp && s->comp->lst == NULL)
|
if (s->comp && s->comp->lst == NULL)
|
||||||
{
|
{
|
||||||
c_clear(s);
|
c_clear(s);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
else if (s->comp && s->comp->lst == s->comp->lst->next)
|
else if (s->comp && s->comp->lst == s->comp->lst->next)
|
||||||
return (c_updater(s->comp, s->comp->lst->name));
|
{
|
||||||
|
c_updater(s->comp, s->comp->lst->name);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
else if (s->comp && s->comp->lst != s->comp->lst->next)
|
else if (s->comp && s->comp->lst != s->comp->lst->next)
|
||||||
{
|
{
|
||||||
c_term_mv_down(s->comp);
|
c_term_mv_down(s->comp);
|
||||||
|
|
@ -83,6 +81,8 @@ int completion(long int keypress)
|
||||||
t_data *s;
|
t_data *s;
|
||||||
|
|
||||||
s = data_singleton();
|
s = data_singleton();
|
||||||
|
if (c_glob_matching())
|
||||||
|
return (1);
|
||||||
if (s->comp == NULL)
|
if (s->comp == NULL)
|
||||||
{
|
{
|
||||||
if (s->line.pos == 0)
|
if (s->line.pos == 0)
|
||||||
|
|
@ -96,6 +96,7 @@ int completion(long int keypress)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
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
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 15:47:30 by wescande #+# #+# */
|
/* Created: 2017/03/07 15:47:30 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/10 15:36:02 by jhalford ### ########.fr */
|
/* Updated: 2017/03/10 16:58:57 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -29,8 +29,6 @@ int exec_leaf(t_btree **ast)
|
||||||
{
|
{
|
||||||
if (JOB_IS_FG(job->attrs))
|
if (JOB_IS_FG(job->attrs))
|
||||||
put_job_in_foreground(job, 0);
|
put_job_in_foreground(job, 0);
|
||||||
/* else */
|
|
||||||
/* put_job_in_background(job, 0); */
|
|
||||||
job->pgid = 0;
|
job->pgid = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */
|
/* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/10 13:48:19 by jhalford ### ########.fr */
|
/* Updated: 2017/03/10 16:49:14 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -20,15 +20,13 @@ int exec_reset(void)
|
||||||
/* exec->fd_save[0] = 1;//fcntl(STDIN, F_DUPFD_CLOEXEC); */
|
/* exec->fd_save[0] = 1;//fcntl(STDIN, F_DUPFD_CLOEXEC); */
|
||||||
/* exec->fd_save[1] = 1;//fcntl(STDOUT, F_DUPFD_CLOEXEC); */
|
/* exec->fd_save[1] = 1;//fcntl(STDOUT, F_DUPFD_CLOEXEC); */
|
||||||
/* exec->fd_save[2] = 1;//fcntl(STDERR, F_DUPFD_CLOEXEC); */
|
/* exec->fd_save[2] = 1;//fcntl(STDERR, F_DUPFD_CLOEXEC); */
|
||||||
DG("check 0");
|
|
||||||
if ((exec->fd_save[0] = fcntl(STDIN, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF)
|
if ((exec->fd_save[0] = fcntl(STDIN, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF)
|
||||||
ft_dprintf(2, "{red}%s: internal fcntl STDIN error errno=%i %s{eoc}\n", SHELL_NAME, errno);
|
ft_dprintf(2, "{red}%s: internal fcntl STDIN error errno=%i %s{eoc}\n", SHELL_NAME, errno);
|
||||||
DG("check 1");
|
|
||||||
if ((exec->fd_save[1] = fcntl(STDOUT, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF)
|
if ((exec->fd_save[1] = fcntl(STDOUT, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF)
|
||||||
ft_dprintf(2, "{red}%s: internal fcntl STDOUT error errno=%i %s{eoc}\n", SHELL_NAME, errno);
|
ft_dprintf(2, "{red}%s: internal fcntl STDOUT error errno=%i %s{eoc}\n", SHELL_NAME, errno);
|
||||||
if ((exec->fd_save[2] = fcntl(STDERR, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF)
|
if ((exec->fd_save[2] = fcntl(STDERR, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF)
|
||||||
ft_dprintf(2, "{red}%s: internal fcntl STDERR error errno=%i %s{eoc}\n", SHELL_NAME, errno);
|
ft_dprintf(2, "{red}%s: internal fcntl STDERR error errno=%i %s{eoc}\n", SHELL_NAME, errno);
|
||||||
DG("saved [%i:%i:%i]", exec->fd_save[0], exec->fd_save[1], exec->fd_save[2]);
|
/* DG("saved [%i:%i:%i]", exec->fd_save[0], exec->fd_save[1], exec->fd_save[2]); */
|
||||||
exec->op_stack = NULL;
|
exec->op_stack = NULL;
|
||||||
exec->fdin = STDIN;
|
exec->fdin = STDIN;
|
||||||
exec->attrs = 0;
|
exec->attrs = 0;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 17:26:53 by wescande #+# #+# */
|
/* Created: 2017/03/07 17:26:53 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/08 15:07:47 by wescande ### ########.fr */
|
/* Updated: 2017/03/10 17:08:46 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
|
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/10 15:21:02 by jhalford ### ########.fr */
|
/* Updated: 2017/03/10 16:50:33 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 17:20:53 by wescande #+# #+# */
|
/* Created: 2017/03/07 17:20:53 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/10 14:28:06 by ariard ### ########.fr */
|
/* Updated: 2017/03/10 17:09:14 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
|
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/10 14:32:05 by ariard ### ########.fr */
|
/* Updated: 2017/03/10 17:09:04 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */
|
/* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/09 14:28:39 by jhalford ### ########.fr */
|
/* Updated: 2017/03/10 16:51:47 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -23,8 +23,7 @@ int process_setgroup(t_process *p, pid_t pid)
|
||||||
if (!SH_HAS_JOBC(data->opts))
|
if (!SH_HAS_JOBC(data->opts))
|
||||||
return (0);
|
return (0);
|
||||||
j = &data->exec.job;
|
j = &data->exec.job;
|
||||||
if (!j->pgid)
|
/* DG("setpgid(%i, %i)", pid, j->pgid); */
|
||||||
j->pgid = pid ? pid : getpid();
|
|
||||||
setpgid(pid, j->pgid);
|
setpgid(pid, j->pgid);
|
||||||
if (pid == 0 && JOB_IS_FG(j->attrs))
|
if (pid == 0 && JOB_IS_FG(j->attrs))
|
||||||
tcsetpgrp(STDIN, j->pgid);
|
tcsetpgrp(STDIN, j->pgid);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/08 14:30:07 by jhalford #+# #+# */
|
/* Created: 2017/01/08 14:30:07 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/21 20:09:24 by jhalford ### ########.fr */
|
/* Updated: 2017/03/10 16:27:01 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */
|
/* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/10 15:36:33 by jhalford ### ########.fr */
|
/* Updated: 2017/03/10 16:45:11 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -27,15 +27,12 @@ int job_addprocess(t_process *p)
|
||||||
job->pgid = p->pid;
|
job->pgid = p->pid;
|
||||||
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
|
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
|
||||||
}
|
}
|
||||||
DG("check 0");
|
|
||||||
job = jobc->first_job->content;
|
job = jobc->first_job->content;
|
||||||
ft_lsteadd(&job->first_process, ft_lstnew(p, sizeof(*p)));
|
ft_lsteadd(&job->first_process, ft_lstnew(p, sizeof(*p)));
|
||||||
DG("[BG:%i]", JOB_IS_BG(job->attrs));
|
/* DG("[BG:%i]", JOB_IS_BG(job->attrs)); */
|
||||||
if (JOB_IS_BG(job->attrs) && IS_PIPEEND(*p))
|
if (JOB_IS_BG(job->attrs) && IS_PIPEEND(*p))
|
||||||
{
|
{
|
||||||
DG("check 2");
|
|
||||||
job_notify_new(job);
|
job_notify_new(job);
|
||||||
}
|
}
|
||||||
DG("check 3");
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */
|
/* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/10 15:38:56 by jhalford ### ########.fr */
|
/* Updated: 2017/03/10 16:45:32 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */
|
/* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/10 15:40:32 by jhalford ### ########.fr */
|
/* Updated: 2017/03/10 16:48:38 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -19,11 +19,14 @@ int job_wait(int id)
|
||||||
t_jobc *jobc;
|
t_jobc *jobc;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
DG("job wait [%i]", id);
|
|
||||||
jobc = &data_singleton()->jobc;
|
jobc = &data_singleton()->jobc;
|
||||||
j = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content;
|
j = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content;
|
||||||
|
DG("job wait id=[%i], pgid=[%i]", id, j->pgid);
|
||||||
do
|
do
|
||||||
|
{
|
||||||
pid = waitpid(-j->pgid, &status, WUNTRACED);
|
pid = waitpid(-j->pgid, &status, WUNTRACED);
|
||||||
|
DG("pid=[%d]", pid);
|
||||||
|
}
|
||||||
while (pid > 1 && !mark_process_status(pid, status)
|
while (pid > 1 && !mark_process_status(pid, status)
|
||||||
&& !job_is_stopped(id)
|
&& !job_is_stopped(id)
|
||||||
&& !job_is_completed(id));
|
&& !job_is_completed(id));
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/09 13:05:55 by jhalford #+# #+# */
|
/* Created: 2017/01/09 13:05:55 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/08 20:08:26 by jhalford ### ########.fr */
|
/* Updated: 2017/03/10 16:27:33 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */
|
/* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/10 15:16:49 by jhalford ### ########.fr */
|
/* Updated: 2017/03/10 16:27:05 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,36 +6,55 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/03 14:15:55 by gwojda #+# #+# */
|
/* Created: 2017/02/03 14:15:55 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/16 14:22:44 by gwojda ### ########.fr */
|
/* Updated: 2017/03/09 15:20:18 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
int ft_completion(int ret)
|
static size_t ft_strleni_w(char *str, size_t pos, char c)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
len = 0;
|
||||||
|
if (!STR)
|
||||||
|
return (0);
|
||||||
|
while (str[pos] && str[pos] != c)
|
||||||
|
{
|
||||||
|
++len;
|
||||||
|
++pos;
|
||||||
|
}
|
||||||
|
return (len);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_completion(int ret)
|
||||||
{
|
{
|
||||||
size_t tmp;
|
size_t tmp;
|
||||||
size_t pos_tmp;
|
size_t pos_tmp;
|
||||||
int beg_len;
|
size_t right;
|
||||||
char boolean;
|
char boolean;
|
||||||
|
|
||||||
boolean = 0;
|
boolean = 0;
|
||||||
beg_len = ft_strlen(data_singleton()->line.input);
|
pos_tmp = POS;
|
||||||
|
right = ft_strleni_w(STR, POS, '\n');
|
||||||
if (((ret != TOUCHE_TAB && ret != 10)
|
if (((ret != TOUCHE_TAB && ret != 10)
|
||||||
|| (ret == 10)) && !(data_singleton()->comp))
|
|| (ret == 10)) && !(data_singleton()->comp))
|
||||||
return (0);
|
return (0);
|
||||||
tmp = POS;
|
|
||||||
pos_tmp = POS;
|
|
||||||
if (data_singleton()->comp || ret == TOUCHE_TAB)
|
if (data_singleton()->comp || ret == TOUCHE_TAB)
|
||||||
boolean = completion(ret);
|
boolean = completion(ret);
|
||||||
if (boolean || ret == 10)
|
if (boolean || ret == 10)
|
||||||
{
|
{
|
||||||
|
if (pos_tmp)
|
||||||
|
--pos_tmp;
|
||||||
|
else
|
||||||
|
ft_puttermcaps("nd");
|
||||||
|
ft_get_beggin_with_curs(STR, &pos_tmp);
|
||||||
|
tmp = pos_tmp;
|
||||||
ft_puttermcaps("cd");
|
ft_puttermcaps("cd");
|
||||||
ft_current_str(STR, tmp);
|
ft_current_str(STR, tmp);
|
||||||
ft_get_next_str(STR, &tmp);
|
ft_get_next_str(STR, &tmp);
|
||||||
ft_putnc('\b', tmp -
|
ft_putnc('\b', right);
|
||||||
(pos_tmp + ft_strlen(data_singleton()->line.input) - beg_len));
|
POS = ft_strleni_w(STR, pos_tmp, '\n') - right;
|
||||||
POS = pos_tmp + ft_strlen(data_singleton()->line.input) - beg_len;
|
|
||||||
}
|
}
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
25
42sh/src/line-editing/lib_line_editing/ft_nb_line.c
Normal file
25
42sh/src/line-editing/lib_line_editing/ft_nb_line.c
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_nb_line.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/08 17:11:57 by gwojda #+# #+# */
|
||||||
|
/* Updated: 2017/03/08 17:43:14 by gwojda ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
int ft_nb_of_line(char *str, size_t pos)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
|
||||||
|
len = 1;
|
||||||
|
if (pos && str[pos] == '\n')
|
||||||
|
--pos;
|
||||||
|
len += data_singleton()->line.prompt_size;
|
||||||
|
len += ft_get_size_prev(str, pos);
|
||||||
|
return (len / ft_size_term());
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/08 12:35:11 by gwojda #+# #+# */
|
/* Created: 2017/01/08 12:35:11 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/08 23:38:50 by ariard ### ########.fr */
|
/* Updated: 2017/03/10 17:43:59 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -49,7 +49,7 @@ int ft_nb_last_line(char *str, size_t pos)
|
||||||
--pos;
|
--pos;
|
||||||
len += data_singleton()->line.prompt_size;
|
len += data_singleton()->line.prompt_size;
|
||||||
len += ft_get_size_prev(str, pos);
|
len += ft_get_size_prev(str, pos);
|
||||||
return ((len) ? len % ft_size_term() : -1);
|
return (len % ft_size_term());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_check_end_of_line(char *str, size_t pos)
|
void ft_check_end_of_line(char *str, size_t pos)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue