working on esc character in token
This commit is contained in:
parent
26625dd1b1
commit
45bc317f97
24 changed files with 224 additions and 102 deletions
|
|
@ -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/24 21:22:58 by wescande ### ########.fr */
|
/* Updated: 2017/01/27 19:13:15 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -22,14 +22,23 @@ typedef struct s_ld
|
||||||
struct s_ld *prev;
|
struct s_ld *prev;
|
||||||
} t_ld;
|
} t_ld;
|
||||||
|
|
||||||
char **glob(const char *str, char **env);
|
typedef struct s_glob
|
||||||
t_ld *expand_brace(const char *pat);
|
{
|
||||||
|
const char *pat;
|
||||||
|
const char *esc;
|
||||||
|
t_ld *match;
|
||||||
|
t_ld *m_pat;
|
||||||
|
} t_glob;
|
||||||
|
|
||||||
|
char **glob(const char *str, const char *esc, char **env);
|
||||||
|
void expand_brace(t_glob *tglob);
|
||||||
void glob_print(t_list *token, t_data *data);
|
void glob_print(t_list *token, t_data *data);
|
||||||
int match_pattern(const char *pat, char *str,
|
int match_pattern(t_glob *tglob, char *str, char *full_word);
|
||||||
char *full_word, t_ld **match);
|
void dir_research(t_glob *tglob, char *path);
|
||||||
void dir_research(const char *pat, char *path, t_ld **match);
|
void dir_research_recursive(t_glob *tglob, char *p);
|
||||||
void dir_research_recursive(const char *pat, char *p, t_ld **match);
|
int is_directory(const char *path);
|
||||||
bool is_directory(const char *path);
|
|
||||||
|
int is_char_esc(const char *esc, const char *ini_str, const char *str_pos);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** 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/12 14:57:41 by jhalford ### ########.fr */
|
/* Updated: 2017/01/27 15:52:11 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -63,6 +63,7 @@ struct s_token
|
||||||
{
|
{
|
||||||
t_type type;
|
t_type type;
|
||||||
char *data;
|
char *data;
|
||||||
|
char *esc;
|
||||||
int size;
|
int size;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -75,7 +76,7 @@ extern int (*g_lexer[])(t_list **alst, char *str);
|
||||||
t_token *token_init();
|
t_token *token_init();
|
||||||
int ft_tokenize(t_list **alst, char *str, t_lexstate state);
|
int ft_tokenize(t_list **alst, char *str, t_lexstate state);
|
||||||
int ft_post_tokenize(t_list **alst, char *str);
|
int ft_post_tokenize(t_list **alst, char *str);
|
||||||
int token_append(t_token *token, char c);
|
int token_append(t_token *token, char c, short int esc);
|
||||||
void token_free(void *data, size_t size);
|
void token_free(void *data, size_t size);
|
||||||
int token_cmp_type(t_token *token, t_type *ref);
|
int token_cmp_type(t_token *token, t_type *ref);
|
||||||
void token_print(t_list *lst);
|
void token_print(t_list *lst);
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,13 @@
|
||||||
/* 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/24 21:16:42 by wescande ### ########.fr */
|
/* Updated: 2017/01/27 18:32:54 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "glob.h"
|
#include "glob.h"
|
||||||
|
|
||||||
bool is_directory(const char *path)
|
int is_directory(const char *path)
|
||||||
{
|
{
|
||||||
struct stat path_stat;
|
struct stat path_stat;
|
||||||
|
|
||||||
|
|
@ -20,7 +20,7 @@ bool is_directory(const char *path)
|
||||||
return (S_ISDIR(path_stat.st_mode));
|
return (S_ISDIR(path_stat.st_mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
void dir_research(const char *pat, char *p, t_ld **match)
|
void dir_research(t_glob *gl, char *p)
|
||||||
{
|
{
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *in;
|
struct dirent *in;
|
||||||
|
|
@ -38,8 +38,8 @@ void dir_research(const char *pat, char *p, t_ld **match)
|
||||||
path_tmp = ft_strjoin(p, in->d_name);
|
path_tmp = ft_strjoin(p, in->d_name);
|
||||||
else
|
else
|
||||||
path_tmp = ft_strjoinf(ft_strjoin(p, "/"), in->d_name, 1);
|
path_tmp = ft_strjoinf(ft_strjoin(p, "/"), in->d_name, 1);
|
||||||
if (match_pattern(pat, in->d_name, path_tmp, match))
|
if (match_pattern(gl, in->d_name, path_tmp))
|
||||||
ft_ld_pushfront(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);
|
||||||
}
|
}
|
||||||
|
|
@ -47,7 +47,7 @@ void dir_research(const char *pat, char *p, t_ld **match)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dir_research_recursive(const char *pat, char *p, t_ld **match)
|
void dir_research_recursive(t_glob *gl, char *p)
|
||||||
{
|
{
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *in;
|
struct dirent *in;
|
||||||
|
|
@ -66,9 +66,9 @@ void dir_research_recursive(const char *pat, char *p, t_ld **match)
|
||||||
else
|
else
|
||||||
path_tmp = ft_strjoinf(ft_strjoin(p, "/"), in->d_name, 1);
|
path_tmp = ft_strjoinf(ft_strjoin(p, "/"), in->d_name, 1);
|
||||||
if (is_directory(path_tmp))
|
if (is_directory(path_tmp))
|
||||||
dir_research_recursive(pat, path_tmp, match);
|
dir_research_recursive(gl, path_tmp);
|
||||||
if (match_pattern(pat, in->d_name, path_tmp, match))
|
if (match_pattern(gl, in->d_name, path_tmp))
|
||||||
ft_ld_pushfront(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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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/24 19:15:35 by wescande ### ########.fr */
|
/* Updated: 2017/01/27 20:12:12 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -20,7 +20,43 @@
|
||||||
** -char *pat -> pattern string to be looking for expand
|
** -char *pat -> pattern string to be looking for expand
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int search_brace(t_ld **wk, char *str, int index)
|
static char **generate_tab(const char *pat, const char *esc, int dup)
|
||||||
|
{
|
||||||
|
char **my_tab;
|
||||||
|
|
||||||
|
if (!(my_tab = (char **)malloc(sizeof(char*) * 3)))
|
||||||
|
return (NULL);
|
||||||
|
if (dup)
|
||||||
|
{
|
||||||
|
my_tab[0] = ft_strdup(pat);
|
||||||
|
my_tab[1] = ft_strdup(esc);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
my_tab[0] = (char *)pat;
|
||||||
|
my_tab[1] = (char *)esc;
|
||||||
|
}
|
||||||
|
my_tab[2] = NULL;
|
||||||
|
return (my_tab);
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *calc_expand_esc(const char *esc,
|
||||||
|
int nb_start, int nb_middle, int nb_end)
|
||||||
|
{
|
||||||
|
char *new_esc;
|
||||||
|
int index;
|
||||||
|
|
||||||
|
new_esc = ft_memalloc(sizeof(char) * (nb_start + nb_middle + nb_end) / 8);
|
||||||
|
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.
|
||||||
|
return (new_esc);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int search_brace(t_ld **wk, char *str, char *esc, int index)
|
||||||
{
|
{
|
||||||
char *start;
|
char *start;
|
||||||
char *s1;
|
char *s1;
|
||||||
|
|
@ -29,17 +65,17 @@ static int search_brace(t_ld **wk, char *str, int index)
|
||||||
start = NULL;
|
start = NULL;
|
||||||
while (*str)
|
while (*str)
|
||||||
{
|
{
|
||||||
if (*str == '{')
|
start = *str == '{' ? str : start;
|
||||||
start = str;
|
if (*str == '}' && start)
|
||||||
else if (*str == '}' && start)
|
|
||||||
{
|
{
|
||||||
s1 = ft_strsub(start, 1, str - start - 1);
|
s1 = ft_strsub(start, 1, str - start - 1);
|
||||||
split = ft_strsplit(s1, ',');
|
split = ft_strsplit(s1, ',');
|
||||||
ft_strdel(&s1);
|
ft_strdel(&s1);
|
||||||
s1 = ft_strsub((*wk)->content, 0, start - (char *)(*wk)->content);
|
s1 = ft_strsub((*wk)->content, 0, start - (char *)(*wk)->content);
|
||||||
while (split[++index])
|
while (split[++index])
|
||||||
ft_ld_pushfront(wk, ft_strjoinf(ft_strjoin(s1, split[index]),
|
ft_ld_pushfront(wk, generate_tab(ft_strjoinf(ft_strjoin(s1,
|
||||||
str + 1, 1));
|
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_strdel(&s1);
|
||||||
ft_tabdel(&split);
|
ft_tabdel(&split);
|
||||||
return (1);
|
return (1);
|
||||||
|
|
@ -49,29 +85,27 @@ static int search_brace(t_ld **wk, char *str, int index)
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_ld *expand_brace(const char *pat)
|
void expand_brace(t_glob *gl)
|
||||||
{
|
{
|
||||||
t_ld *ret;
|
|
||||||
t_ld *tmp;
|
t_ld *tmp;
|
||||||
int do_it;
|
int do_it;
|
||||||
|
|
||||||
ret = NULL;
|
ft_ld_pushfront(&gl->m_pat, generate_tab("", "", 1));
|
||||||
ft_ld_pushfront(&ret, ft_strdup(""));
|
ft_ld_pushfront(&gl->m_pat, generate_tab(gl->pat, gl->esc, 1));
|
||||||
ft_ld_pushfront(&ret, ft_strdup(pat));
|
|
||||||
do_it = 1;
|
do_it = 1;
|
||||||
while (do_it)
|
while (do_it)
|
||||||
{
|
{
|
||||||
do_it = 0;
|
do_it = 0;
|
||||||
while (ret->next)
|
while (gl->m_pat->next)
|
||||||
{
|
{
|
||||||
if ((tmp = ret) && search_brace(&ret, ret->content, -1))
|
if ((tmp = gl->m_pat) && search_brace(&gl->m_pat,
|
||||||
|
((char **)gl->m_pat->content)[0],((char **)gl->m_pat->content)[1], -1))
|
||||||
{
|
{
|
||||||
ft_ld_del(&tmp, &ft_strdel);
|
ft_ld_del(&tmp, &ft_tabdel);
|
||||||
do_it = 1;
|
do_it = 1;
|
||||||
}
|
}
|
||||||
ret = ret->next;
|
gl->m_pat = gl->m_pat->next;
|
||||||
}
|
}
|
||||||
ret = ft_ld_front(ret);
|
gl->m_pat = ft_ld_front(gl->m_pat);
|
||||||
}
|
}
|
||||||
return (ret);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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/26 17:18:20 by wescande ### ########.fr */
|
/* Updated: 2017/01/27 19:05:38 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -21,13 +21,13 @@
|
||||||
** to just expanse in local directory and not in path
|
** to just expanse in local directory and not in path
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void path_research(const char *pat, char **path, t_ld **match)
|
static void path_research(t_glob *tglob, char **path)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = -1;
|
i = -1;
|
||||||
while (path[++i])
|
while (path[++i])
|
||||||
dir_research(pat, path[i], match);
|
dir_research(tglob, path[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char **treat_glob(t_ld **match)
|
static char **treat_glob(t_ld **match)
|
||||||
|
|
@ -42,30 +42,54 @@ static char **treat_glob(t_ld **match)
|
||||||
return (gl);
|
return (gl);
|
||||||
}
|
}
|
||||||
|
|
||||||
char **glob(const char *pat, char **env)
|
static void add_simple_pat(t_glob *gl)
|
||||||
{
|
{
|
||||||
t_ld *match;
|
char *str;
|
||||||
char **path;
|
int start;
|
||||||
t_ld *mul_pat;
|
|
||||||
|
|
||||||
match = NULL;
|
str = ((char **)gl->m_pat->content)[0];
|
||||||
mul_pat = expand_brace(pat);
|
start = 0;
|
||||||
while (mul_pat->next)
|
while (*str)
|
||||||
{
|
{
|
||||||
if (!(((char *)mul_pat->content)[0] == '/'
|
if (!is_char_esc(((char **)gl->m_pat->content)[1],
|
||||||
|| (((char *)mul_pat->content)[0] == '.'
|
((char **)gl->m_pat->content)[0], str))
|
||||||
&& ((char *)mul_pat->content)[1] == '/'))
|
{
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
|
||||||
|
char **glob(const char *pat, const char *esc, char **env)
|
||||||
|
{
|
||||||
|
t_glob tglob;
|
||||||
|
char **path;
|
||||||
|
|
||||||
|
tglob = (t_glob){pat, esc, NULL, NULL};
|
||||||
|
expand_brace(&tglob, tglob.pat);
|
||||||
|
while (tglob.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"), ':')))
|
&& env && (path = ft_strsplit(ft_getenv(env, "PATH"), ':')))
|
||||||
{
|
{
|
||||||
path_research(mul_pat->content, path, &match);
|
path_research(&tglob, path);
|
||||||
ft_tabdel(&path);
|
ft_tabdel(&path);
|
||||||
}
|
}
|
||||||
if (((char *)mul_pat->content)[0] != '/')
|
if (((char **)tglob.m_pat->content)[0][0] != '/')
|
||||||
dir_research(mul_pat->content, ".", &match);
|
dir_research(&tglob, ".");
|
||||||
else
|
else
|
||||||
dir_research(mul_pat->content + 1, "/", &match);
|
dir_research(&tglob, "/");
|
||||||
mul_pat = mul_pat->next;
|
tglob.m_pat = tglob.m_pat->next;
|
||||||
}
|
}
|
||||||
ft_ld_clear(&mul_pat, &ft_strdel);
|
ft_ld_clear(&tglob.m_pat, &ft_strdel);
|
||||||
return (treat_glob(&match));
|
return (treat_glob(&tglob.match));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/05 16:09:40 by wescande #+# #+# */
|
/* Created: 2017/01/05 16:09:40 by wescande #+# #+# */
|
||||||
/* Updated: 2017/01/26 17:14:32 by wescande ### ########.fr */
|
/* Updated: 2017/01/27 18:29:32 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -26,6 +26,20 @@ 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)
|
void glob_print(t_list *lst, t_data *data)
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
@ -40,7 +54,8 @@ void glob_print(t_list *lst, t_data *data)
|
||||||
type = token->type;
|
type = token->type;
|
||||||
while (type >> (i++ + 2))
|
while (type >> (i++ + 2))
|
||||||
;
|
;
|
||||||
glob_ret = glob(token->data, data->env);
|
glob_ret = glob(token->data, token->esc, data->env);
|
||||||
|
print_esc(token);
|
||||||
DG("%02i '%s'", i, token->data);
|
DG("%02i '%s'", i, token->data);
|
||||||
ft_tabprint_fd(glob_ret, 3);
|
ft_tabprint_fd(glob_ret, 3);
|
||||||
lst = lst->next;
|
lst = lst->next;
|
||||||
|
|
|
||||||
23
42sh/src/glob/is_char_esc.c
Normal file
23
42sh/src/glob/is_char_esc.c
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* is_char_esc.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/01/27 18:19:55 by wescande #+# #+# */
|
||||||
|
/* Updated: 2017/01/27 18:23:22 by wescande ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "glob.h"
|
||||||
|
|
||||||
|
int is_char_esc(const char *esc, const char *ini_str, const char *str_pos)
|
||||||
|
{
|
||||||
|
int pos;
|
||||||
|
|
||||||
|
pos = str_pos - ini_str;
|
||||||
|
if ((esc[pos / 8] >> pos % 8) & 1)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */
|
/* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/11 16:11:02 by jhalford ### ########.fr */
|
/* Updated: 2017/01/27 15:43:46 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 11:56:49 by jhalford #+# #+# */
|
/* Created: 2016/12/03 11:56:49 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/03 12:35:13 by jhalford ### ########.fr */
|
/* Updated: 2017/01/27 15:52:46 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,6 +18,6 @@ int lexer_backslash(t_list **alst, char *str)
|
||||||
|
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
token->type = TK_WORD;
|
token->type = TK_WORD;
|
||||||
token_append(token, str[1]);
|
token_append(token, str[1], 1);
|
||||||
return (ft_tokenize(alst, str + 2, WORD));
|
return (ft_tokenize(alst, str + 2, WORD));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 18:36:21 by jhalford #+# #+# */
|
/* Created: 2016/11/28 18:36:21 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/11 16:10:53 by jhalford ### ########.fr */
|
/* Updated: 2017/01/27 15:53:10 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -28,7 +28,7 @@ int lexer_default(t_list **alst, char *str)
|
||||||
else
|
else
|
||||||
state = WORD;
|
state = WORD;
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
token_append(token, *str);
|
token_append(token, *str, 0);
|
||||||
token->type = TK_N_WORD;
|
token->type = TK_N_WORD;
|
||||||
return (ft_tokenize(alst, str + 1, state));
|
return (ft_tokenize(alst, str + 1, state));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 18:36:58 by jhalford #+# #+# */
|
/* Created: 2016/11/28 18:36:58 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/10 15:15:24 by jhalford ### ########.fr */
|
/* Updated: 2017/01/27 15:53:31 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -23,9 +23,9 @@ int lexer_dquote(t_list **alst, char *str)
|
||||||
return (ft_tokenize(alst, str + 1, DEFAULT));
|
return (ft_tokenize(alst, str + 1, DEFAULT));
|
||||||
if (*str == '\\')
|
if (*str == '\\')
|
||||||
{
|
{
|
||||||
token_append(token, *(str + 1));
|
token_append(token, *(str + 1), 1);
|
||||||
return (lexer_dquote(alst, str + 1));
|
return (lexer_dquote(alst, str + 1));
|
||||||
}
|
}
|
||||||
token_append(token, *str);
|
token_append(token, *str, 1);
|
||||||
return (lexer_dquote(alst, str));
|
return (lexer_dquote(alst, str));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 12:06:35 by jhalford #+# #+# */
|
/* Created: 2016/12/03 12:06:35 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/10 14:48:49 by jhalford ### ########.fr */
|
/* Updated: 2017/01/27 15:54:53 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,17 +17,17 @@ int lexer_great(t_list **alst, char *str)
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
token_append(token, str[0]);
|
token_append(token, str[0], 0);
|
||||||
if (*(str + 1) == '&')
|
if (*(str + 1) == '&')
|
||||||
{
|
{
|
||||||
token->type = TK_GREATAND;
|
token->type = TK_GREATAND;
|
||||||
token_append(token, str[1]);
|
token_append(token, str[1], 0);
|
||||||
return (lexer_greatand(alst, str + 2));
|
return (lexer_greatand(alst, str + 2));
|
||||||
}
|
}
|
||||||
else if (*(str + 1) == '>')
|
else if (*(str + 1) == '>')
|
||||||
{
|
{
|
||||||
token->type = TK_DGREAT;
|
token->type = TK_DGREAT;
|
||||||
token_append(token, str[1]);
|
token_append(token, str[1], 0);
|
||||||
return (ft_tokenize(&(*alst)->next, str + 2, DEFAULT));
|
return (ft_tokenize(&(*alst)->next, str + 2, DEFAULT));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 11:56:58 by jhalford #+# #+# */
|
/* Created: 2016/12/03 11:56:58 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/03 11:57:09 by jhalford ### ########.fr */
|
/* Updated: 2017/01/27 15:55:04 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -20,12 +20,12 @@ int lexer_greatand(t_list **alst, char *str)
|
||||||
token->type = TK_GREATAND;
|
token->type = TK_GREATAND;
|
||||||
if (ft_isdigit(*str))
|
if (ft_isdigit(*str))
|
||||||
{
|
{
|
||||||
token_append(token, *str);
|
token_append(token, *str, 0);
|
||||||
return (lexer_greatand(alst, str + 1));
|
return (lexer_greatand(alst, str + 1));
|
||||||
}
|
}
|
||||||
else if (*str == '-')
|
else if (*str == '-')
|
||||||
{
|
{
|
||||||
token_append(token, *str);
|
token_append(token, *str, 0);
|
||||||
return (ft_tokenize(&(*alst)->next, str + 1, DEFAULT));
|
return (ft_tokenize(&(*alst)->next, str + 1, DEFAULT));
|
||||||
}
|
}
|
||||||
return (ft_tokenize(alst, str, DEFAULT));
|
return (ft_tokenize(alst, str, DEFAULT));
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 12:06:53 by jhalford #+# #+# */
|
/* Created: 2016/12/03 12:06:53 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/10 14:27:51 by jhalford ### ########.fr */
|
/* Updated: 2017/01/27 15:55:16 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,17 +17,17 @@ int lexer_less(t_list **alst, char *str)
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
token_append(token, str[0]);
|
token_append(token, str[0], 0);
|
||||||
if (*(str + 1) == '&')
|
if (*(str + 1) == '&')
|
||||||
{
|
{
|
||||||
token->type = TK_LESSAND;
|
token->type = TK_LESSAND;
|
||||||
token_append(token, str[1]);
|
token_append(token, str[1], 0);
|
||||||
return (lexer_lessand(alst, str + 2));
|
return (lexer_lessand(alst, str + 2));
|
||||||
}
|
}
|
||||||
else if (*(str + 1) == '<')
|
else if (*(str + 1) == '<')
|
||||||
{
|
{
|
||||||
token->type = TK_DLESS;
|
token->type = TK_DLESS;
|
||||||
token_append(token, str[1]);
|
token_append(token, str[1], 0);
|
||||||
return (ft_tokenize(&(*alst)->next, str + 2, DEFAULT));
|
return (ft_tokenize(&(*alst)->next, str + 2, DEFAULT));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 11:58:51 by jhalford #+# #+# */
|
/* Created: 2016/12/03 11:58:51 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/03 11:58:52 by jhalford ### ########.fr */
|
/* Updated: 2017/01/27 15:55:27 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -20,12 +20,12 @@ int lexer_lessand(t_list **alst, char *str)
|
||||||
token->type = TK_LESSAND;
|
token->type = TK_LESSAND;
|
||||||
if (ft_isdigit(*str))
|
if (ft_isdigit(*str))
|
||||||
{
|
{
|
||||||
token_append(token, *str);
|
token_append(token, *str, 0);
|
||||||
return (lexer_lessand(alst, str + 1));
|
return (lexer_lessand(alst, str + 1));
|
||||||
}
|
}
|
||||||
else if (*str == '-')
|
else if (*str == '-')
|
||||||
{
|
{
|
||||||
token_append(token, *str);
|
token_append(token, *str, 0);
|
||||||
return (ft_tokenize(&(*alst)->next, str + 1, DEFAULT));
|
return (ft_tokenize(&(*alst)->next, str + 1, DEFAULT));
|
||||||
}
|
}
|
||||||
return (ft_tokenize(alst, str, DEFAULT));
|
return (ft_tokenize(alst, str, DEFAULT));
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 12:06:45 by jhalford #+# #+# */
|
/* Created: 2016/12/03 12:06:45 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/10 14:29:46 by jhalford ### ########.fr */
|
/* Updated: 2017/01/27 15:52:58 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -27,7 +27,7 @@ int lexer_number(t_list **alst, char *str)
|
||||||
return (ft_tokenize(alst, str, LESS));
|
return (ft_tokenize(alst, str, LESS));
|
||||||
else if (ft_isdigit(*str))
|
else if (ft_isdigit(*str))
|
||||||
{
|
{
|
||||||
token_append(token, *str);
|
token_append(token, *str, 0);
|
||||||
return (lexer_number(alst, str + 1));
|
return (lexer_number(alst, str + 1));
|
||||||
}
|
}
|
||||||
return (ft_tokenize(alst, str, DEFAULT));
|
return (ft_tokenize(alst, str, DEFAULT));
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 12:07:08 by jhalford #+# #+# */
|
/* Created: 2016/12/03 12:07:08 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/10 15:13:06 by jhalford ### ########.fr */
|
/* Updated: 2017/01/27 15:52:21 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -21,6 +21,6 @@ int lexer_quote(t_list **alst, char *str)
|
||||||
str++;
|
str++;
|
||||||
if (*str == '\'')
|
if (*str == '\'')
|
||||||
return (ft_tokenize(alst, str + 1, WORD));
|
return (ft_tokenize(alst, str + 1, WORD));
|
||||||
token_append(token, *str);
|
token_append(token, *str, 1);
|
||||||
return (lexer_quote(alst, str));
|
return (lexer_quote(alst, str));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/10 14:54:57 by jhalford #+# #+# */
|
/* Created: 2017/01/10 14:54:57 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/10 16:36:15 by jhalford ### ########.fr */
|
/* Updated: 2017/01/27 15:55:54 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@ int lexer_var(t_list **alst, char *str)
|
||||||
token->type = TK_N_WORD;
|
token->type = TK_N_WORD;
|
||||||
str++;
|
str++;
|
||||||
if (!ft_strchr(token->data, '$'))
|
if (!ft_strchr(token->data, '$'))
|
||||||
token_append(token, '$');
|
token_append(token, '$', 0);
|
||||||
if (!*str)
|
if (!*str)
|
||||||
{
|
{
|
||||||
token_expand_var(token);
|
token_expand_var(token);
|
||||||
|
|
@ -32,6 +32,6 @@ int lexer_var(t_list **alst, char *str)
|
||||||
token_expand_var(token);
|
token_expand_var(token);
|
||||||
return (ft_tokenize(alst, str, state));
|
return (ft_tokenize(alst, str, state));
|
||||||
}
|
}
|
||||||
token_append(token, *str);
|
token_append(token, *str, 0);
|
||||||
return (lexer_var(alst, str));
|
return (lexer_var(alst, str));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */
|
/* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/11 15:38:03 by jhalford ### ########.fr */
|
/* Updated: 2017/01/27 15:56:02 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -25,6 +25,6 @@ int lexer_word(t_list **alst, char *str)
|
||||||
return (ft_tokenize(&(*alst)->next, str, GREAT));
|
return (ft_tokenize(&(*alst)->next, str, GREAT));
|
||||||
else if (*str == '<')
|
else if (*str == '<')
|
||||||
return (ft_tokenize(&(*alst)->next, str, LESS));
|
return (ft_tokenize(&(*alst)->next, str, LESS));
|
||||||
token_append(token, *str);
|
token_append(token, *str, 0);
|
||||||
return (ft_tokenize(alst, str + 1, WORD));
|
return (ft_tokenize(alst, str + 1, WORD));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,19 +6,26 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/11 17:18:42 by jhalford #+# #+# */
|
/* Created: 2016/11/11 17:18:42 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/11 17:47:15 by jhalford ### ########.fr */
|
/* Updated: 2017/01/27 20:08:12 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "lexer.h"
|
#include "lexer.h"
|
||||||
|
|
||||||
int token_append(t_token *token, char c)
|
int token_append(t_token *token, char c, short int esc)
|
||||||
{
|
{
|
||||||
if ((int)ft_strlen(token->data) >= token->size)
|
int len;
|
||||||
|
|
||||||
|
len = ft_strlen(token->data);
|
||||||
|
if (len >= token->size)
|
||||||
{
|
{
|
||||||
token->data = (char *)ft_realloc(token->data, token->size + 10);
|
token->size += 8;
|
||||||
token->size += 10;
|
token->data = (char *)ft_realloc(token->data, token->size + 1);
|
||||||
|
token->esc = (char *)ft_realloc(token->esc, token->size / 8);
|
||||||
|
token->esc[token->size / 8 - 1] = 0;
|
||||||
}
|
}
|
||||||
ft_strcat(token->data, (char[2]){c, '\0'});
|
ft_strcat(token->data, (char[2]){c, '\0'});
|
||||||
|
if (esc)
|
||||||
|
token->esc[len / 8] |= 1 << len % 8;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/10 14:57:53 by jhalford #+# #+# */
|
/* Created: 2017/01/10 14:57:53 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/10 16:37:33 by jhalford ### ########.fr */
|
/* Updated: 2017/01/27 15:56:40 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -24,5 +24,5 @@ void token_expand_var(t_token *token)
|
||||||
*dollar = 0;
|
*dollar = 0;
|
||||||
if (val)
|
if (val)
|
||||||
while (*val)
|
while (*val)
|
||||||
token_append(token, *val++);
|
token_append(token, *val++, 1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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/12 13:18:46 by jhalford ### ########.fr */
|
/* Updated: 2017/01/27 15:35:37 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -19,6 +19,9 @@ void token_free(void *data, size_t size)
|
||||||
(void)size;
|
(void)size;
|
||||||
token = data;
|
token = data;
|
||||||
if (!(token->type & TK_NON_FREEABLE))
|
if (!(token->type & TK_NON_FREEABLE))
|
||||||
|
{
|
||||||
ft_strdel(&token->data);
|
ft_strdel(&token->data);
|
||||||
|
ft_strdel(&token->esc);
|
||||||
|
}
|
||||||
free(token);
|
free(token);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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/11 15:45:10 by jhalford ### ########.fr */
|
/* Updated: 2017/01/27 15:35:04 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,7 +18,8 @@ t_token *token_init(void)
|
||||||
|
|
||||||
token = (t_token *)malloc(sizeof(t_token));
|
token = (t_token *)malloc(sizeof(t_token));
|
||||||
token->type = 0;
|
token->type = 0;
|
||||||
token->size = 10;
|
token->size = 8;
|
||||||
token->data = ft_strnew(token->size);
|
token->data = ft_strnew(token->size + 1);
|
||||||
|
token->esc = ft_strnew(token->size / 8);
|
||||||
return (token);
|
return (token);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 14:39:01 by jhalford #+# #+# */
|
/* Created: 2016/11/28 14:39:01 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/12 14:48:33 by jhalford ### ########.fr */
|
/* Updated: 2017/01/27 16:08:16 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,6 +17,7 @@ void token_print(t_list *lst)
|
||||||
t_token *token;
|
t_token *token;
|
||||||
int i;
|
int i;
|
||||||
t_type type;
|
t_type type;
|
||||||
|
int index;
|
||||||
|
|
||||||
while (lst)
|
while (lst)
|
||||||
{
|
{
|
||||||
|
|
@ -26,6 +27,10 @@ void token_print(t_list *lst)
|
||||||
while (type >> (i++ + 2))
|
while (type >> (i++ + 2))
|
||||||
;
|
;
|
||||||
DG("%02i '%s'", i, token->data);
|
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;
|
lst = lst->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue