merge de extend_glob. Ajout de la barre de progression dans le makefile
This commit is contained in:
commit
3c8c143143
16 changed files with 113 additions and 136 deletions
|
|
@ -17,7 +17,7 @@ FLAGS = -Wall -Wextra -Werror
|
||||||
D_FLAGS = -g
|
D_FLAGS = -g
|
||||||
|
|
||||||
LEN_NAME = `printf "%s" $(NAME) |wc -c`
|
LEN_NAME = `printf "%s" $(NAME) |wc -c`
|
||||||
DELTA = $$(echo "$$(tput cols)-24-$(LEN_NAME)"|bc)
|
DELTA = $$(echo "$$(tput cols)-37-$(LEN_NAME)"|bc)
|
||||||
|
|
||||||
LIBFT_DIR = libft/
|
LIBFT_DIR = libft/
|
||||||
LIBFT_LIB = $(LIBFT_DIR)libft.a
|
LIBFT_LIB = $(LIBFT_DIR)libft.a
|
||||||
|
|
@ -62,7 +62,6 @@ exec/set_exitstatus.c\
|
||||||
glob/dir_glob.c\
|
glob/dir_glob.c\
|
||||||
glob/expand_brace.c\
|
glob/expand_brace.c\
|
||||||
glob/glob.c\
|
glob/glob.c\
|
||||||
glob/glob_print.c\
|
|
||||||
glob/is_char_esc.c\
|
glob/is_char_esc.c\
|
||||||
glob/lib_perso/ft_ld_back.c\
|
glob/lib_perso/ft_ld_back.c\
|
||||||
glob/lib_perso/ft_ld_clear.c\
|
glob/lib_perso/ft_ld_clear.c\
|
||||||
|
|
@ -189,6 +188,8 @@ parser/parse_word.c
|
||||||
|
|
||||||
SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE))
|
SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE))
|
||||||
OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o))
|
OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o))
|
||||||
|
NB = $(words $(SRC_BASE))
|
||||||
|
INDEX = 0
|
||||||
|
|
||||||
all :
|
all :
|
||||||
@make -j $(NAME)
|
@make -j $(NAME)
|
||||||
|
|
@ -210,10 +211,15 @@ $(OBJ_DIR) :
|
||||||
@mkdir -p $(dir $(OBJS))
|
@mkdir -p $(dir $(OBJS))
|
||||||
|
|
||||||
$(OBJ_DIR)%.o : $(SRC_DIR)%.c | $(OBJ_DIR)
|
$(OBJ_DIR)%.o : $(SRC_DIR)%.c | $(OBJ_DIR)
|
||||||
|
@$(eval DONE=$(shell echo $$(($(INDEX)*20/$(NB)))))
|
||||||
|
@$(eval PERCENT=$(shell echo $$(($(INDEX)*100/$(NB)))))
|
||||||
|
@$(eval COLOR=$(shell echo $$(($(PERCENT)%35+196))))
|
||||||
|
@$(eval TO_DO=$(shell echo $$((20-$(INDEX)*20/$(NB)))))
|
||||||
|
@printf "\r\033[38;5;11m⌛ MAKE %s : %2d%% \033[48;5;%dm%*s\033[0m%*s\033[48;5;255m \033[0m \033[38;5;11m %*s\033[0m\033[K" $(NAME) $(PERCENT) $(COLOR) $(DONE) "" $(TO_DO) "" $(DELTA) "$@"
|
||||||
@$(CC) $(FLAGS) -MMD -c $< -o $@\
|
@$(CC) $(FLAGS) -MMD -c $< -o $@\
|
||||||
-I $(INC_DIR)\
|
-I $(INC_DIR)\
|
||||||
-I $(LIBFT_INC)
|
-I $(LIBFT_INC)
|
||||||
@printf "\r\033[38;5;11m⌛ MAKE %s plz wait : %*s\033[0m\033[K" $(NAME) $(DELTA) "$@"
|
@$(eval INDEX=$(shell echo $$(($(INDEX)+1))))
|
||||||
|
|
||||||
clean: cleanlib
|
clean: cleanlib
|
||||||
@rm -rf $(OBJ_DIR)
|
@rm -rf $(OBJ_DIR)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/04 16:31:18 by wescande #+# #+# */
|
/* Created: 2017/01/04 16:31:18 by wescande #+# #+# */
|
||||||
/* Updated: 2017/01/30 12:12:23 by wescande ### ########.fr */
|
/* Updated: 2017/01/31 17:54:19 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -42,15 +42,15 @@ typedef struct s_expand
|
||||||
char *s1;
|
char *s1;
|
||||||
} t_expand;
|
} t_expand;
|
||||||
|
|
||||||
char **glob(const char *str, const unsigned char *esc, char **env);
|
/*
|
||||||
void expand_brace(t_glob *tglob);
|
** interface of glob.
|
||||||
void glob_print(t_list *token, t_data *data);
|
*/
|
||||||
int match_pattern(t_glob *tglob, char *str, char *full_word);
|
char **glob(const char *str, const unsigned char *esc);
|
||||||
void dir_research(t_glob *tglob, char *p, const char *pat);
|
|
||||||
void dir_research_recursive(t_glob *tglob, char *p, const char *pat);
|
|
||||||
/*
|
/*
|
||||||
** return TRUE if path file is a directory.
|
** return TRUE if path file is a directory.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int is_directory(const char *path);
|
int is_directory(const char *path);
|
||||||
/*
|
/*
|
||||||
** return TRUE if char at str_pos in ini_str is escape.
|
** return TRUE if char at str_pos in ini_str is escape.
|
||||||
|
|
@ -58,6 +58,13 @@ int is_directory(const char *path);
|
||||||
int is_char_esc(const unsigned char *esc,
|
int is_char_esc(const unsigned char *esc,
|
||||||
const char *ini_str, const char *str_pos);
|
const char *ini_str, const char *str_pos);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Internal function.
|
||||||
|
*/
|
||||||
|
void expand_brace(t_glob *tglob);
|
||||||
|
int match_pattern(t_glob *tglob, char *str, char *full_word);
|
||||||
|
int dir_research(t_glob *tglob, char *p, const char *pat);
|
||||||
|
int dir_research_recursive(t_glob *tglob, char *p, const char *pat);
|
||||||
/*
|
/*
|
||||||
** LIST D:
|
** LIST D:
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
|
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/30 13:07:23 by wescande ### ########.fr */
|
/* Updated: 2017/01/31 18:35:34 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
|
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/11 17:06:17 by jhalford ### ########.fr */
|
/* Updated: 2017/01/31 19:17:25 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
# include "minishell.h"
|
# include "minishell.h"
|
||||||
|
|
||||||
typedef struct s_parser t_parser;
|
typedef struct s_parser t_parser;
|
||||||
|
typedef struct s_ld t_ld;
|
||||||
typedef struct s_astnode t_astnode;
|
typedef struct s_astnode t_astnode;
|
||||||
typedef struct s_redir t_redir;
|
typedef struct s_redir t_redir;
|
||||||
typedef union u_astdata t_astdata;
|
typedef union u_astdata t_astdata;
|
||||||
|
|
@ -44,6 +45,7 @@ struct s_redir
|
||||||
union u_astdata
|
union u_astdata
|
||||||
{
|
{
|
||||||
t_redir redir;
|
t_redir redir;
|
||||||
|
t_ld *token;
|
||||||
char **sstr;
|
char **sstr;
|
||||||
char *str;
|
char *str;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */
|
/* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/11 17:50:03 by jhalford ### ########.fr */
|
/* Updated: 2017/01/31 19:15:28 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -19,9 +19,11 @@ void ast_free(void *data, size_t content_size)
|
||||||
(void)content_size;
|
(void)content_size;
|
||||||
node = data;
|
node = data;
|
||||||
if (node->type == TK_COMMAND)
|
if (node->type == TK_COMMAND)
|
||||||
|
ft_ld_clear(&node->data.token, &ft_tabdel);
|
||||||
|
else if (node->type == TK_SUBSHELL)
|
||||||
{
|
{
|
||||||
if (node->data.sstr)
|
ft_sstrfree(node->data.sstr);
|
||||||
ft_sstrfree(node->data.sstr);
|
node->data.sstr = NULL;
|
||||||
}
|
}
|
||||||
else if (node->type == TK_LESS || node->type == TK_GREAT || node->type == TK_DGREAT)
|
else if (node->type == TK_LESS || node->type == TK_GREAT || node->type == TK_DGREAT)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,53 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/12 13:14:35 by jhalford ### ########.fr */
|
/* Updated: 2017/01/31 19:12:23 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "exec.h"
|
#include "exec.h"
|
||||||
|
|
||||||
int exec_command(t_btree **ast)
|
static char **return_array_expand(t_ld *ld)
|
||||||
|
{
|
||||||
|
char **my_tab;
|
||||||
|
int index;
|
||||||
|
char **expand;
|
||||||
|
char **content;
|
||||||
|
|
||||||
|
my_tab = NULL;
|
||||||
|
while (ld)
|
||||||
|
{
|
||||||
|
content = ld->content;
|
||||||
|
DG("EXPANSION DE :");
|
||||||
|
DG("%s", content[0]);
|
||||||
|
expand = glob(content[0], (unsigned char *)content[1]);
|
||||||
|
DG();
|
||||||
|
index = -1;
|
||||||
|
while (expand[++index])
|
||||||
|
my_tab = ft_sstradd(my_tab, expand[index]);
|
||||||
|
ft_tabdel(&expand);
|
||||||
|
ld = ld->next;
|
||||||
|
}
|
||||||
|
return (my_tab);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ft_tabprint_fd(char **mytab, int fd)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
DG("Affichage des parametres envoyes apres le glob");
|
||||||
|
if (!mytab || !*mytab)
|
||||||
|
return ;
|
||||||
|
i = 0;
|
||||||
|
while (mytab[i])
|
||||||
|
{
|
||||||
|
ft_putendl_fd(mytab[i], fd);
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int exec_command(t_btree **ast)
|
||||||
{
|
{
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
t_process *p;
|
t_process *p;
|
||||||
|
|
@ -21,7 +61,8 @@ int exec_command(t_btree **ast)
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
p = &data_singleton()->exec.process;
|
p = &data_singleton()->exec.process;
|
||||||
job = &data_singleton()->exec.job;
|
job = &data_singleton()->exec.job;
|
||||||
p->av = ft_sstrdup(node->data.sstr);
|
p->av = return_array_expand(node->data.token);
|
||||||
|
ft_tabprint_fd(p->av, 4);
|
||||||
process_setexec(node->type, p);
|
process_setexec(node->type, p);
|
||||||
if (!(launch_process(p)))
|
if (!(launch_process(p)))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/30 12:07:16 by wescande #+# #+# */
|
/* Created: 2017/01/30 12:07:16 by wescande #+# #+# */
|
||||||
/* Updated: 2017/01/30 12:07:19 by wescande ### ########.fr */
|
/* Updated: 2017/01/31 18:00:16 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -20,16 +20,16 @@ int is_directory(const char *path)
|
||||||
return (S_ISDIR(path_stat.st_mode));
|
return (S_ISDIR(path_stat.st_mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
void dir_research(t_glob *gl, char *p, const char *pat)
|
int dir_research(t_glob *gl, char *p, const char *pat)
|
||||||
{
|
{
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *in;
|
struct dirent *in;
|
||||||
char *path_tmp;
|
char *path_tmp;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.')
|
ret = 0;
|
||||||
{
|
if ((ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.')
|
||||||
if (!(dir = opendir(p)))
|
&& is_directory(p) && (dir = opendir(p)))
|
||||||
return ;
|
|
||||||
while ((in = readdir(dir)))
|
while ((in = readdir(dir)))
|
||||||
{
|
{
|
||||||
if (ft_strcmp(in->d_name, ".") && ft_strcmp(in->d_name, ".."))
|
if (ft_strcmp(in->d_name, ".") && ft_strcmp(in->d_name, ".."))
|
||||||
|
|
@ -39,25 +39,25 @@ void dir_research(t_glob *gl, char *p, const char *pat)
|
||||||
else
|
else
|
||||||
path_tmp = ft_strjoinf(ft_strjoin(p, "/"), in->d_name, 1);
|
path_tmp = ft_strjoinf(ft_strjoin(p, "/"), in->d_name, 1);
|
||||||
gl->pat = pat;
|
gl->pat = pat;
|
||||||
if (match_pattern(gl, in->d_name, path_tmp))
|
if (match_pattern(gl, in->d_name, path_tmp) && ++ret)
|
||||||
ft_ld_pushfront(&gl->match, ft_strdup(path_tmp + 2 *
|
ft_ld_pushfront(&gl->match, ft_strdup(path_tmp + 2 *
|
||||||
(path_tmp[0] == '.' && path_tmp[1] == '/')));
|
(path_tmp[0] == '.' && path_tmp[1] == '/')));
|
||||||
ft_strdel(&path_tmp);
|
ft_strdel(&path_tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dir_research_recursive(t_glob *gl, char *p, const char *pat)
|
int dir_research_recursive(t_glob *gl, char *p, const char *pat)
|
||||||
{
|
{
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *in;
|
struct dirent *in;
|
||||||
char *path_tmp;
|
char *path_tmp;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if ((ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.') && is_directory(p))
|
ret = 0;
|
||||||
{
|
if ((ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.')
|
||||||
if (!(dir = opendir(p)))
|
&& is_directory(p) && (dir = opendir(p)))
|
||||||
return ;
|
|
||||||
while ((in = readdir(dir)))
|
while ((in = readdir(dir)))
|
||||||
{
|
{
|
||||||
if (ft_strcmp(in->d_name, ".") && ft_strcmp(in->d_name, ".."))
|
if (ft_strcmp(in->d_name, ".") && ft_strcmp(in->d_name, ".."))
|
||||||
|
|
@ -68,11 +68,11 @@ void dir_research_recursive(t_glob *gl, char *p, const char *pat)
|
||||||
path_tmp = ft_strjoinf(ft_strjoin(p, "/"), in->d_name, 1);
|
path_tmp = ft_strjoinf(ft_strjoin(p, "/"), in->d_name, 1);
|
||||||
dir_research_recursive(gl, path_tmp, pat);
|
dir_research_recursive(gl, path_tmp, pat);
|
||||||
gl->pat = pat;
|
gl->pat = pat;
|
||||||
if (match_pattern(gl, in->d_name, path_tmp))
|
if (match_pattern(gl, in->d_name, path_tmp) && ++ret)
|
||||||
ft_ld_pushfront(&gl->match, ft_strdup(path_tmp + 2 *
|
ft_ld_pushfront(&gl->match, ft_strdup(path_tmp + 2 *
|
||||||
(path_tmp[0] == '.' && path_tmp[1] == '/')));
|
(path_tmp[0] == '.' && path_tmp[1] == '/')));
|
||||||
ft_strdel(&path_tmp);
|
ft_strdel(&path_tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/12 19:00:29 by wescande #+# #+# */
|
/* Created: 2017/01/12 19:00:29 by wescande #+# #+# */
|
||||||
/* Updated: 2017/01/28 01:13:26 by wescande ### ########.fr */
|
/* Updated: 2017/01/31 18:19:34 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -38,6 +38,7 @@ static char **gen_tab(const char *pat,
|
||||||
my_tab[1] = (char *)esc;
|
my_tab[1] = (char *)esc;
|
||||||
}
|
}
|
||||||
my_tab[2] = NULL;
|
my_tab[2] = NULL;
|
||||||
|
|
||||||
return (my_tab);
|
return (my_tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -126,6 +127,7 @@ void expand_brace(t_glob *gl)
|
||||||
int do_it;
|
int do_it;
|
||||||
t_expand me;
|
t_expand me;
|
||||||
|
|
||||||
|
|
||||||
ft_ld_pushfront(&gl->m_pat, gen_tab("", (const unsigned char *)"", 1));
|
ft_ld_pushfront(&gl->m_pat, gen_tab("", (const unsigned char *)"", 1));
|
||||||
ft_ld_pushfront(&gl->m_pat, gen_tab(gl->pat, gl->esc, 1));
|
ft_ld_pushfront(&gl->m_pat, gen_tab(gl->pat, gl->esc, 1));
|
||||||
me = (t_expand){NULL, NULL, NULL, NULL, NULL};
|
me = (t_expand){NULL, NULL, NULL, NULL, NULL};
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/04 16:29:54 by wescande #+# #+# */
|
/* Created: 2017/01/04 16:29:54 by wescande #+# #+# */
|
||||||
/* Updated: 2017/01/31 14:16:38 by jhalford ### ########.fr */
|
/* Updated: 2017/01/31 19:40:49 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -22,15 +22,6 @@
|
||||||
** to just expanse in local directory and not in path dir
|
** to just expanse in local directory and not in path dir
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void path_research(t_glob *gl, char **path)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = -1;
|
|
||||||
while (path[++i])
|
|
||||||
dir_research(gl, path[i], gl->pat);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char **treat_glob(t_ld **match)
|
static char **treat_glob(t_ld **match)
|
||||||
{
|
{
|
||||||
char **gl;
|
char **gl;
|
||||||
|
|
@ -43,33 +34,10 @@ static char **treat_glob(t_ld **match)
|
||||||
return (gl);
|
return (gl);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_simple_pat(t_glob *gl)
|
char **glob(const char *pat, const unsigned char *esc)
|
||||||
{
|
|
||||||
char *str;
|
|
||||||
int start;
|
|
||||||
|
|
||||||
str = (char *)gl->pat;
|
|
||||||
start = 0;
|
|
||||||
while (*str)
|
|
||||||
{
|
|
||||||
if (!is_char_esc(gl->esc, gl->pat, str))
|
|
||||||
{
|
|
||||||
if (*str == '[')
|
|
||||||
start = 1;
|
|
||||||
else if (*str == ']' && start == 1)
|
|
||||||
return ;
|
|
||||||
else if (*str == '*' || *str == '?')
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
++str;
|
|
||||||
}
|
|
||||||
ft_ld_pushfront(&gl->match, ft_strdup(gl->pat));
|
|
||||||
}
|
|
||||||
|
|
||||||
char **glob(const char *pat, const unsigned char *esc, char **env)
|
|
||||||
{
|
{
|
||||||
t_glob gl;
|
t_glob gl;
|
||||||
char **path;
|
int ret;
|
||||||
|
|
||||||
gl = (t_glob){pat, esc, NULL, NULL};
|
gl = (t_glob){pat, esc, NULL, NULL};
|
||||||
expand_brace(&gl);
|
expand_brace(&gl);
|
||||||
|
|
@ -77,18 +45,12 @@ char **glob(const char *pat, const unsigned char *esc, char **env)
|
||||||
{
|
{
|
||||||
gl.pat = ((char **)gl.m_pat->content)[0];
|
gl.pat = ((char **)gl.m_pat->content)[0];
|
||||||
gl.esc = ((unsigned char **)gl.m_pat->content)[1];
|
gl.esc = ((unsigned char **)gl.m_pat->content)[1];
|
||||||
add_simple_pat(&gl);
|
|
||||||
if (!(gl.pat[0] == '/' || (gl.pat[0] == '.' && gl.pat[1] == '/'))
|
|
||||||
&& env && (path = ft_strsplit(ft_getenv(env, "PATH"), ':')))
|
|
||||||
{
|
|
||||||
path_research(&gl, path);
|
|
||||||
ft_tabdel(&path);
|
|
||||||
}
|
|
||||||
gl.pat = ((char **)gl.m_pat->content)[0];
|
|
||||||
if (gl.pat[0] != '/')
|
if (gl.pat[0] != '/')
|
||||||
dir_research(&gl, ".", gl.pat);
|
ret = dir_research(&gl, ".", gl.pat);
|
||||||
else
|
else
|
||||||
dir_research(&gl, "/", gl.pat + 1);
|
ret = dir_research(&gl, "/", gl.pat + 1);
|
||||||
|
if (!ret)
|
||||||
|
ft_ld_pushfront(&gl.match, ft_strdup(gl.pat));
|
||||||
gl.m_pat = gl.m_pat->next;
|
gl.m_pat = gl.m_pat->next;
|
||||||
}
|
}
|
||||||
ft_ld_clear(&gl.m_pat, &ft_tabdel);
|
ft_ld_clear(&gl.m_pat, &ft_tabdel);
|
||||||
|
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* glob_print.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2017/01/05 16:09:40 by wescande #+# #+# */
|
|
||||||
/* Updated: 2017/01/31 13:52:43 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "glob.h"
|
|
||||||
|
|
||||||
void ft_tabprint_fd(char **mytab, int fd)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!mytab || !*mytab)
|
|
||||||
return ;
|
|
||||||
i = 0;
|
|
||||||
while (mytab[i])
|
|
||||||
{
|
|
||||||
ft_putendl_fd(mytab[i], fd);
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void glob_print(t_list *lst, t_data *data)
|
|
||||||
{
|
|
||||||
t_token *token;
|
|
||||||
int i;
|
|
||||||
t_type type;
|
|
||||||
char **glob_ret;
|
|
||||||
|
|
||||||
while (lst)
|
|
||||||
{
|
|
||||||
i = 1;
|
|
||||||
token = lst->content;
|
|
||||||
type = token->type;
|
|
||||||
while (type >> (i++ + 2))
|
|
||||||
;
|
|
||||||
glob_ret = glob(token->data, token->esc, data->env);
|
|
||||||
DG("%02i '%s'", i, token->data);
|
|
||||||
ft_tabprint_fd(glob_ret, 3);
|
|
||||||
lst = lst->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */
|
/* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/12 15:31:34 by jhalford ### ########.fr */
|
/* Updated: 2017/01/31 16:07:17 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 12:07:30 by jhalford #+# #+# */
|
/* Created: 2016/12/03 12:07:30 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/27 21:54:05 by wescande ### ########.fr */
|
/* Updated: 2017/01/31 18:36:40 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/10 15:30:25 by jhalford #+# #+# */
|
/* Created: 2016/11/10 15:30:25 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/27 21:54:53 by wescande ### ########.fr */
|
/* Updated: 2017/01/31 18:36:31 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/31 16:43:19 by jhalford ### ########.fr */
|
/* Updated: 2017/01/31 19:41:25 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -30,7 +30,6 @@ int shell_single_command(char *command)
|
||||||
return (1);
|
return (1);
|
||||||
DG("after post_tokenize");
|
DG("after post_tokenize");
|
||||||
token_print(token);
|
token_print(token);
|
||||||
glob_print(token, data_singleton());
|
|
||||||
if (ft_parse(&ast, &token))
|
if (ft_parse(&ast, &token))
|
||||||
return (1);
|
return (1);
|
||||||
btree_print(STDBUG, ast, &ft_putast);
|
btree_print(STDBUG, ast, &ft_putast);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/30 17:14:58 by jhalford #+# #+# */
|
/* Created: 2016/11/30 17:14:58 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/12 15:07:31 by jhalford ### ########.fr */
|
/* Updated: 2017/01/31 16:10:41 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -41,7 +41,7 @@ int ft_parse(t_btree **ast, t_list **start)
|
||||||
if (!*ast)
|
if (!*ast)
|
||||||
{
|
{
|
||||||
*ast = btree_create_node(&item, sizeof(item));
|
*ast = btree_create_node(&item, sizeof(item));
|
||||||
((t_astnode *)(*ast)->item)->data.sstr = NULL;
|
((t_astnode *)(*ast)->item)->data.token = NULL;
|
||||||
}
|
}
|
||||||
while (g_parser[i].type)
|
while (g_parser[i].type)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/11 17:24:55 by jhalford ### ########.fr */
|
/* Updated: 2017/01/31 19:17:58 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -16,12 +16,16 @@ int parse_word(t_btree **ast, t_list **start, t_list **lst)
|
||||||
{
|
{
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
char **my_tab;
|
||||||
|
|
||||||
(void)start;
|
(void)start;
|
||||||
|
my_tab = NULL;
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
node->type = TK_COMMAND;
|
node->type = TK_COMMAND;
|
||||||
node->data.sstr = ft_sstradd(node->data.sstr, token->data);
|
my_tab = ft_sstradd(my_tab, token->data);
|
||||||
|
my_tab = ft_sstradd(my_tab, (char *)token->esc);
|
||||||
|
ft_ld_pushback(&node->data.token, my_tab);
|
||||||
ft_parse(ast, &(*lst)->next);
|
ft_parse(ast, &(*lst)->next);
|
||||||
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
|
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue