From 4f5c65b9a25455a9e4e3ae9c22a55fc58cb90f9d Mon Sep 17 00:00:00 2001 From: wescande Date: Sat, 28 Jan 2017 01:19:03 +0100 Subject: [PATCH] =?UTF-8?q?finalisation=20du=20lexer=20avec=20les=20char?= =?UTF-8?q?=20echapp=C3=A9=20->=201=20unsigned=20char=20pour=208=20char=20?= =?UTF-8?q?du=20token=20(1=20bit=20pour=201=20char).=20Module=20glob=20en?= =?UTF-8?q?=20place=20en=20tenant=20compte=20des=20echapp=C3=A9.=20fonctio?= =?UTF-8?q?n=20is=5Fchar=5Fesc=20en=20place=20pour=20une=20utilisation=20p?= =?UTF-8?q?lus=20globale?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 42sh/Makefile | 4 +- 42sh/includes/glob.h | 30 ++++++--- 42sh/includes/lexer.h | 10 +-- 42sh/src/glob/dir_glob.c | 13 ++-- 42sh/src/glob/expand_brace.c | 113 +++++++++++++++++++++++----------- 42sh/src/glob/glob.c | 88 +++++++++++++++++--------- 42sh/src/glob/glob_print.c | 17 +---- 42sh/src/glob/is_char_esc.c | 7 ++- 42sh/src/glob/match_pattern.c | 72 +++++++++++----------- 42sh/src/lexer/token_append.c | 6 +- 42sh/src/lexer/token_free.c | 4 +- 42sh/src/lexer/token_init.c | 4 +- 42sh/src/lexer/token_print.c | 5 +- 13 files changed, 218 insertions(+), 155 deletions(-) diff --git a/42sh/Makefile b/42sh/Makefile index 9bfbaf2d..fe295d2b 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -59,6 +59,7 @@ glob/dir_glob.c\ glob/expand_brace.c\ glob/glob.c\ glob/glob_print.c\ +glob/is_char_esc.c\ glob/lib_perso/ft_ld_back.c\ glob/lib_perso/ft_ld_clear.c\ glob/lib_perso/ft_ld_del.c\ @@ -188,7 +189,8 @@ parser/parse_word.c SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE)) OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o)) -all : $(NAME) +all : + @make -j $(NAME) $(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS) @$(CC) $(FLAGS) $(D_FLAGS) \ diff --git a/42sh/includes/glob.h b/42sh/includes/glob.h index 943ab15a..dd568f8f 100644 --- a/42sh/includes/glob.h +++ b/42sh/includes/glob.h @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/04 16:31:18 by wescande #+# #+# */ -/* Updated: 2017/01/27 19:13:15 by wescande ### ########.fr */ +/* Updated: 2017/01/28 00:14:11 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,9 @@ # include "minishell.h" +# define CH(x) ((char **)(x)->content) +# define UCH(x) ((unsigned char **)(x)->content) + typedef struct s_ld { void *content; @@ -24,21 +27,30 @@ typedef struct s_ld typedef struct s_glob { - const char *pat; - const char *esc; - t_ld *match; - t_ld *m_pat; + const char *pat; + const unsigned char *esc; + t_ld *match; + t_ld *m_pat; } t_glob; -char **glob(const char *str, const char *esc, char **env); +typedef struct s_expand +{ + t_ld **wk; + char *str; + unsigned char *esc; + char **split; + char *s1; +} t_expand; + +char **glob(const char *str, const unsigned char *esc, char **env); void expand_brace(t_glob *tglob); void glob_print(t_list *token, t_data *data); int match_pattern(t_glob *tglob, char *str, char *full_word); -void dir_research(t_glob *tglob, char *path); -void dir_research_recursive(t_glob *tglob, char *p); +void dir_research(t_glob *tglob, char *p, const char *pat); +void dir_research_recursive(t_glob *tglob, char *p, const char *pat); int is_directory(const char *path); -int is_char_esc(const char *esc, const char *ini_str, const char *str_pos); +int is_char_esc(const unsigned char *esc, const char *ini_str, const char *str_pos); /* ** LIST D: diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index e1dcf24f..9913c091 100644 --- a/42sh/includes/lexer.h +++ b/42sh/includes/lexer.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */ -/* Updated: 2017/01/27 15:52:11 by wescande ### ########.fr */ +/* Updated: 2017/01/27 21:47:44 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -61,10 +61,10 @@ enum e_lexstate struct s_token { - t_type type; - char *data; - char *esc; - int size; + t_type type; + char *data; + unsigned char *esc; + int size; }; typedef struct s_data t_data; diff --git a/42sh/src/glob/dir_glob.c b/42sh/src/glob/dir_glob.c index 804c9465..92b90348 100644 --- a/42sh/src/glob/dir_glob.c +++ b/42sh/src/glob/dir_glob.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/04 16:29:54 by wescande #+# #+# */ -/* Updated: 2017/01/27 18:32:54 by wescande ### ########.fr */ +/* Updated: 2017/01/27 23:48:18 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ int is_directory(const char *path) return (S_ISDIR(path_stat.st_mode)); } -void dir_research(t_glob *gl, char *p) +void dir_research(t_glob *gl, char *p, const char *pat) { DIR *dir; struct dirent *in; @@ -38,6 +38,7 @@ void dir_research(t_glob *gl, char *p) path_tmp = ft_strjoin(p, in->d_name); else path_tmp = ft_strjoinf(ft_strjoin(p, "/"), in->d_name, 1); + gl->pat = pat; if (match_pattern(gl, in->d_name, path_tmp)) ft_ld_pushfront(&gl->match, ft_strdup(path_tmp + 2 * (path_tmp[0] == '.' && path_tmp[1] == '/'))); @@ -47,13 +48,13 @@ void dir_research(t_glob *gl, char *p) } } -void dir_research_recursive(t_glob *gl, char *p) +void dir_research_recursive(t_glob *gl, char *p, const char *pat) { DIR *dir; struct dirent *in; char *path_tmp; - if (ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.') + if ((ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.') && is_directory(p)) { if (!(dir = opendir(p))) return ; @@ -65,8 +66,8 @@ void dir_research_recursive(t_glob *gl, char *p) path_tmp = ft_strjoin(p, in->d_name); else path_tmp = ft_strjoinf(ft_strjoin(p, "/"), in->d_name, 1); - if (is_directory(path_tmp)) - dir_research_recursive(gl, path_tmp); + dir_research_recursive(gl, path_tmp, pat); + gl->pat = pat; if (match_pattern(gl, in->d_name, path_tmp)) ft_ld_pushfront(&gl->match, ft_strdup(path_tmp + 2 * (path_tmp[0] == '.' && path_tmp[1] == '/'))); diff --git a/42sh/src/glob/expand_brace.c b/42sh/src/glob/expand_brace.c index 8db42a27..78211f16 100644 --- a/42sh/src/glob/expand_brace.c +++ b/42sh/src/glob/expand_brace.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/12 19:00:29 by wescande #+# #+# */ -/* Updated: 2017/01/27 20:12:12 by wescande ### ########.fr */ +/* Updated: 2017/01/28 01:13:26 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,16 +20,17 @@ ** -char *pat -> pattern string to be looking for expand */ -static char **generate_tab(const char *pat, const char *esc, int dup) +static char **gen_tab(const char *pat, + const unsigned char *esc, int dup) { char **my_tab; - if (!(my_tab = (char **)malloc(sizeof(char*) * 3))) + if (!(my_tab = (char **)malloc(sizeof(char *) * 3))) return (NULL); if (dup) { my_tab[0] = ft_strdup(pat); - my_tab[1] = ft_strdup(esc); + my_tab[1] = ft_strdup((const char *)esc); } else { @@ -40,66 +41,104 @@ static char **generate_tab(const char *pat, const char *esc, int dup) return (my_tab); } -static char *calc_expand_esc(const char *esc, - int nb_start, int nb_middle, int nb_end) +static unsigned char *calc_expand_esc(const unsigned char *esc, + int nb_start, int nb_middle, int *nb_end) { - char *new_esc; - int index; + unsigned char *new_esc; + int index; + int pos; - new_esc = ft_memalloc(sizeof(char) * (nb_start + nb_middle + nb_end) / 8); + if (!(new_esc = ft_memalloc(sizeof(char) * + ((nb_start + nb_middle + nb_end[1]) / 8) + 1))) + return (NULL); index = -1; while (++index < nb_start) - new_esc[index / 8] |= (esc[index / 8] >> index % 8) & 1 << index % 8; - //copy the nb_start first bit of esc. - //append nb_middle bit at status 0 - //append nb_end last bit from end of esc. + new_esc[index / 8] |= + ((esc[index / 8] >> (7 - index % 8)) & 1) << (7 - index % 8); + pos = -1; + while (++pos < nb_middle) + { + new_esc[index / 8] |= 1 << (7 - index % 8); + ++index; + } + pos = nb_end[0]; + while (++pos <= nb_end[0] + nb_end[1]) + { + new_esc[index / 8] |= + ((esc[pos / 8] >> (7 - pos % 8)) & 1) << (7 - index % 8); + ++index; + } return (new_esc); } -static int search_brace(t_ld **wk, char *str, char *esc, int index) +static void iter_on_each(t_expand *me) +{ + int i; + char **my_new; + char *first; + unsigned char *second; + t_ld *wk_tmp; + + i = -1; + wk_tmp = *me->wk; + while (me->split[++i]) + { + first = ft_strjoinf(ft_strjoin(me->s1, me->split[i]), me->str + 1, 1); + second = calc_expand_esc(me->esc, + ft_strlen(me->s1), + ft_strlen(me->split[i]), + (int[2]){me->str - CH(*me->wk)[0], ft_strlen(me->str + 1)}); + my_new = gen_tab(first, second, 0); + ft_ld_pushfront(&wk_tmp, my_new); + } + me->wk = &wk_tmp; +} + +static int search_brace(t_expand *me) { char *start; - char *s1; - char **split; start = NULL; - while (*str) + while (*me->str) { - start = *str == '{' ? str : start; - if (*str == '}' && start) + start = *me->str == '{' && !is_char_esc(me->esc, + CH(*me->wk)[0], me->str) ? me->str : start; + if (*me->str == '}' && start + && !is_char_esc(me->esc, CH(*me->wk)[0], me->str)) { - s1 = ft_strsub(start, 1, str - start - 1); - split = ft_strsplit(s1, ','); - ft_strdel(&s1); - s1 = ft_strsub((*wk)->content, 0, start - (char *)(*wk)->content); - while (split[++index]) - ft_ld_pushfront(wk, generate_tab(ft_strjoinf(ft_strjoin(s1, - split[index]), str + 1, 1), calc_expand_esc(esc, - ft_strlen(s1), ft_strlen(split[index]), ft_strlen(str +1)), 0)); - ft_strdel(&s1); - ft_tabdel(&split); + me->s1 = ft_strsub(start, 1, me->str - start - 1); + me->split = ft_strsplit(me->s1, ','); + ft_strdel(&me->s1); + me->s1 = ft_strsub(CH(*me->wk)[0], 0, start - CH(*me->wk)[0]); + iter_on_each(me); + ft_strdel(&me->s1); + ft_tabdel(&me->split); return (1); } - ++str; + ++me->str; } return (0); } -void expand_brace(t_glob *gl) +void expand_brace(t_glob *gl) { - t_ld *tmp; - int do_it; + t_ld *tmp; + int do_it; + t_expand me; - ft_ld_pushfront(&gl->m_pat, generate_tab("", "", 1)); - ft_ld_pushfront(&gl->m_pat, generate_tab(gl->pat, gl->esc, 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)); + me = (t_expand){NULL, NULL, NULL, NULL, NULL}; do_it = 1; while (do_it) { do_it = 0; while (gl->m_pat->next) { - if ((tmp = gl->m_pat) && search_brace(&gl->m_pat, - ((char **)gl->m_pat->content)[0],((char **)gl->m_pat->content)[1], -1)) + me.wk = &gl->m_pat; + me.esc = UCH(gl->m_pat)[1]; + me.str = CH(gl->m_pat)[0]; + if ((tmp = gl->m_pat) && search_brace(&me)) { ft_ld_del(&tmp, &ft_tabdel); do_it = 1; diff --git a/42sh/src/glob/glob.c b/42sh/src/glob/glob.c index de095b22..d09d531d 100644 --- a/42sh/src/glob/glob.c +++ b/42sh/src/glob/glob.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/04 16:29:54 by wescande #+# #+# */ -/* Updated: 2017/01/27 19:05:38 by wescande ### ########.fr */ +/* Updated: 2017/01/28 01:17:04 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,13 +21,13 @@ ** to just expanse in local directory and not in path */ -static void path_research(t_glob *tglob, char **path) +static void path_research(t_glob *gl, char **path) { int i; i = -1; while (path[++i]) - dir_research(tglob, path[i]); + dir_research(gl, path[i], gl->pat); } static char **treat_glob(t_ld **match) @@ -47,49 +47,77 @@ static void add_simple_pat(t_glob *gl) char *str; int start; - str = ((char **)gl->m_pat->content)[0]; + str = (char *)gl->pat; start = 0; while (*str) { - if (!is_char_esc(((char **)gl->m_pat->content)[1], - ((char **)gl->m_pat->content)[0], 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 ; + if (*str == '[') + start = 1; + else if (*str == ']' && start == 1) + return ; + else if (*str == '*' || *str == '?') + return ; } ++str; } - ft_ld_pushfront(&gl->match, ((char **)gl->m_pat->content)[0]); + ft_ld_pushfront(&gl->match, ft_strdup(gl->pat)); } -char **glob(const char *pat, const char *esc, char **env) +static void printme_me(const char *pat, const unsigned char *esc) { - t_glob tglob; + char *str; + int index; + int len; + + str = (char *)pat; + while (*str) + { + ft_dprintf(3, is_char_esc(esc, pat, str) ? "\\%c" : "%c", *str); + ++str; + } + ft_dprintf(3, "\n"); + len = ft_strlen(pat); + index = -1; + while (++index < len) + ft_dprintf(3, ((esc[index / 8] >> (7 - index % 8)) & 1) ? " 1" : "0"); + ft_dprintf(3, "\n"); + index = 0; + while (index < len) + { + ft_dprintf(3, "%08b", esc[index / 8]); + index += 8; + } + ft_dprintf(3, "\n"); +} + +char **glob(const char *pat, const unsigned char *esc, char **env) +{ + t_glob gl; char **path; - tglob = (t_glob){pat, esc, NULL, NULL}; - expand_brace(&tglob, tglob.pat); - while (tglob.m_pat->next) + gl = (t_glob){pat, esc, NULL, NULL}; + expand_brace(&gl); + while (gl.m_pat->next) { - add_simple_pat(&tglob); - if (!(((char **)tglob.m_pat->content)[0][0] == '/' - || (((char **)tglob.m_pat->content)[0][0] == '.' - && ((char **)tglob.m_pat->content)[0][1] == '/')) - && env && (path = ft_strsplit(ft_getenv(env, "PATH"), ':'))) + gl.pat = ((char **)gl.m_pat->content)[0]; + gl.esc = ((unsigned char **)gl.m_pat->content)[1]; + printme_me(gl.pat, gl.esc); + add_simple_pat(&gl); + if (!(gl.pat[0] == '/' || (gl.pat[0] == '.' && gl.pat[1] == '/')) + && env && (path = ft_strsplit(ft_getenv(env, "PATH"), ':'))) { - path_research(&tglob, path); + path_research(&gl, path); ft_tabdel(&path); } - if (((char **)tglob.m_pat->content)[0][0] != '/') - dir_research(&tglob, "."); + gl.pat = ((char **)gl.m_pat->content)[0]; + if (gl.pat[0] != '/') + dir_research(&gl, ".", gl.pat); else - dir_research(&tglob, "/"); - tglob.m_pat = tglob.m_pat->next; + dir_research(&gl, "/", gl.pat + 1); + gl.m_pat = gl.m_pat->next; } - ft_ld_clear(&tglob.m_pat, &ft_strdel); - return (treat_glob(&tglob.match)); + ft_ld_clear(&gl.m_pat, &ft_tabdel); + return (treat_glob(&gl.match)); } diff --git a/42sh/src/glob/glob_print.c b/42sh/src/glob/glob_print.c index ce0cd349..46fcdd8d 100644 --- a/42sh/src/glob/glob_print.c +++ b/42sh/src/glob/glob_print.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/05 16:09:40 by wescande #+# #+# */ -/* Updated: 2017/01/27 18:29:32 by wescande ### ########.fr */ +/* Updated: 2017/01/27 21:57:24 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,20 +26,6 @@ void ft_tabprint_fd(char **mytab, int fd) } } -void print_esc(t_token *token) -{ - char *str = token->data; - while (*str) - { - if (is_char_esc(token->esc, token->data, str)) - ft_dprintf(3, "\\%c", *str); - else - ft_dprintf(3, "%c", *str); - ++str; - } - ft_dprintf(3, "\n"); -} - void glob_print(t_list *lst, t_data *data) { t_token *token; @@ -55,7 +41,6 @@ void glob_print(t_list *lst, t_data *data) while (type >> (i++ + 2)) ; glob_ret = glob(token->data, token->esc, data->env); - print_esc(token); DG("%02i '%s'", i, token->data); ft_tabprint_fd(glob_ret, 3); lst = lst->next; diff --git a/42sh/src/glob/is_char_esc.c b/42sh/src/glob/is_char_esc.c index ba85450c..5c06a546 100644 --- a/42sh/src/glob/is_char_esc.c +++ b/42sh/src/glob/is_char_esc.c @@ -6,18 +6,19 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/27 18:19:55 by wescande #+# #+# */ -/* Updated: 2017/01/27 18:23:22 by wescande ### ########.fr */ +/* Updated: 2017/01/27 23:45:51 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "glob.h" -int is_char_esc(const char *esc, const char *ini_str, const char *str_pos) +int is_char_esc(const unsigned char *esc, + const char *ini_str, const char *str_pos) { int pos; pos = str_pos - ini_str; - if ((esc[pos / 8] >> pos % 8) & 1) + if ((esc[pos / 8] >> (7 - pos % 8)) & 1) return (1); return (0); } diff --git a/42sh/src/glob/match_pattern.c b/42sh/src/glob/match_pattern.c index 5e95b55b..8707c3c4 100644 --- a/42sh/src/glob/match_pattern.c +++ b/42sh/src/glob/match_pattern.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/24 17:30:23 by wescande #+# #+# */ -/* Updated: 2017/01/24 20:58:47 by wescande ### ########.fr */ +/* Updated: 2017/01/27 23:45:39 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,35 +31,34 @@ static int match_bracket_char(char **cmp, const char *pat, char c, int neg) *cmp += 2; } else if (!neg && **cmp == c) - { return (1); - } else if (neg && **cmp == c) - { return (0); - } return (-1); } -static int match_bracket(const char **pat, char c) +static int match_bracket(t_glob *gl, char c) { char *cmp; int neg; int ret; - cmp = (char *)*pat + 1; - while (**pat != ']') + cmp = (char *)gl->pat + 1; + while (*gl->pat != ']' + || is_char_esc(gl->esc, ((char **)gl->m_pat->content)[0], gl->pat)) { - if (!**pat) + if (!*gl->pat) return (0); - ++*pat; + ++gl->pat; } neg = 0; - if ((*cmp == '^' || *cmp == '!') && ++neg) + if ((*cmp == '^' || *cmp == '!') + && !is_char_esc(gl->esc, ((char **)gl->m_pat->content)[0], cmp) + && ++neg) ++cmp; - while (cmp < *pat) + while (cmp < gl->pat) { - ret = match_bracket_char(&cmp, *pat, c, neg); + ret = match_bracket_char(&cmp, gl->pat, c, neg); if (ret != -1) return (ret); ++cmp; @@ -67,19 +66,19 @@ static int match_bracket(const char **pat, char c) return (neg); } -static int match_star(const char *pat, char *str, - char *full_word, t_ld **match) +static int match_star(t_glob *gl, char *str, char *full_word) { char *fix; - if (pat[1] == '*') - dir_research_recursive(pat, full_word, match); - if (!pat[1]) + if (gl->pat[1] == '*' && + !is_char_esc(gl->esc, ((char **)gl->m_pat->content)[0], gl->pat + 1)) + dir_research_recursive(gl, full_word, gl->pat + 1); + if (!*++gl->pat) return (1); fix = str + ft_strlen(str); while (fix > str) { - if (match_pattern(pat + 1, fix, full_word, match)) + if (match_pattern(gl, fix, full_word)) return (1); --fix; } @@ -94,32 +93,31 @@ const char *manage_pat(const char *pat, char *str) return (pat); } -int match_pattern(const char *pat, char *str, - char *full_word, t_ld **match) +int match_pattern(t_glob *gl, char *str, char *full_word) { - pat = manage_pat(pat, str); - while (*pat) + gl->pat = manage_pat(gl->pat, str); + while (*gl->pat) { - if (*pat == '?') + if (is_char_esc(gl->esc, ((char **)gl->m_pat->content)[0], gl->pat)) + { + if (*str != *gl->pat) + return (0); + } + else if (*gl->pat == '?') str++; - else if (*pat == '[') + else if (*gl->pat == '[') { - if (!match_bracket(&pat, *str)) + if (!match_bracket(gl, *str)) return (0); } - else if (*pat == '*') - return (match_star(pat, str, full_word, match)); - else if (*pat == '\\') - { - if (!*++pat || *str != *pat) - return (0); - } - else if (*pat == '/' && !*str && is_directory(full_word)) - dir_research((pat + 1), full_word, match); - else if (*pat != *str) + else if (*gl->pat == '*') + return (match_star(gl, str, full_word)); + else if (*gl->pat == '/' && !*str && is_directory(full_word)) + dir_research(gl, full_word, gl->pat + 1); + else if (*gl->pat != *str) return (0); ++str; - ++pat; + ++gl->pat; } return (*str ? 0 : 1); } diff --git a/42sh/src/lexer/token_append.c b/42sh/src/lexer/token_append.c index 649f0901..fc9845fd 100644 --- a/42sh/src/lexer/token_append.c +++ b/42sh/src/lexer/token_append.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/11 17:18:42 by jhalford #+# #+# */ -/* Updated: 2017/01/27 20:08:12 by wescande ### ########.fr */ +/* Updated: 2017/01/27 21:54:32 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,11 +21,11 @@ int token_append(t_token *token, char c, short int esc) { token->size += 8; token->data = (char *)ft_realloc(token->data, token->size + 1); - token->esc = (char *)ft_realloc(token->esc, token->size / 8); + token->esc = (unsigned char *)ft_realloc((char *)token->esc, token->size / 8 + 1); token->esc[token->size / 8 - 1] = 0; } ft_strcat(token->data, (char[2]){c, '\0'}); if (esc) - token->esc[len / 8] |= 1 << len % 8; + token->esc[len / 8] |= 1 << (7 - len % 8); return (0); } diff --git a/42sh/src/lexer/token_free.c b/42sh/src/lexer/token_free.c index fc42c83a..466d4407 100644 --- a/42sh/src/lexer/token_free.c +++ b/42sh/src/lexer/token_free.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:07:30 by jhalford #+# #+# */ -/* Updated: 2017/01/27 15:35:37 by wescande ### ########.fr */ +/* Updated: 2017/01/27 21:54:05 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ void token_free(void *data, size_t size) if (!(token->type & TK_NON_FREEABLE)) { ft_strdel(&token->data); - ft_strdel(&token->esc); + ft_memdel((void **)&token->esc); } free(token); } diff --git a/42sh/src/lexer/token_init.c b/42sh/src/lexer/token_init.c index 8d113343..009f27dd 100644 --- a/42sh/src/lexer/token_init.c +++ b/42sh/src/lexer/token_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 15:30:25 by jhalford #+# #+# */ -/* Updated: 2017/01/27 15:35:04 by wescande ### ########.fr */ +/* Updated: 2017/01/27 21:54:53 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,6 @@ t_token *token_init(void) token->type = 0; token->size = 8; token->data = ft_strnew(token->size + 1); - token->esc = ft_strnew(token->size / 8); + token->esc = (unsigned char *)ft_strnew(token->size / 8 + 1); return (token); } diff --git a/42sh/src/lexer/token_print.c b/42sh/src/lexer/token_print.c index 3edd1759..343fe5bc 100644 --- a/42sh/src/lexer/token_print.c +++ b/42sh/src/lexer/token_print.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:39:01 by jhalford #+# #+# */ -/* Updated: 2017/01/27 16:08:16 by wescande ### ########.fr */ +/* Updated: 2017/01/27 21:57:05 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,9 +28,6 @@ void token_print(t_list *lst) ; DG("%02i '%s'", i, token->data); index = -1; - while (++index < token->size / 8) - ft_dprintf(3, "|%b vs %x vs %c| ", token->esc[index], token->esc[index], token->esc[index]); - ft_dprintf(3, "\n"); lst = lst->next; } }