Skip to content

Commit

Permalink
to solve parsing in tokenize
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin FEUILLADE--MONTIXI committed Aug 9, 2020
1 parent 60327d8 commit 75f2438
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 21 deletions.
Binary file modified minishell-tester-master/minishell
Binary file not shown.
Binary file modified minishell.dSYM/Contents/Resources/DWARF/minishell
Binary file not shown.
3 changes: 1 addition & 2 deletions srcs/launch_commands/command_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: qfeuilla <qfeuilla@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/02 16:21:03 by frthierr #+# #+# */
/* Updated: 2020/08/08 16:58:00 by qfeuilla ### ########.fr */
/* Updated: 2020/08/09 18:01:14 by qfeuilla ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -65,6 +65,5 @@ void exit_minishell(int action, t_list *token_list,
if (args_to_free)
free_argv(*args_to_free, INT_MAX);
}
system("leaks minishell");
exit(g_exit_status);
}
2 changes: 1 addition & 1 deletion srcs/parsing/prompt_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: qfeuilla <qfeuilla@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/02 14:48:38 by frthierr #+# #+# */
/* Updated: 2020/08/08 16:13:19 by qfeuilla ### ########.fr */
/* Updated: 2020/08/09 18:32:52 by qfeuilla ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
2 changes: 1 addition & 1 deletion srcs/parsing/token_len.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: qfeuilla <qfeuilla@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/25 14:27:21 by frthierr #+# #+# */
/* Updated: 2020/08/08 11:57:57 by qfeuilla ### ########.fr */
/* Updated: 2020/08/09 18:32:39 by qfeuilla ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
2 changes: 1 addition & 1 deletion srcs/parsing/tokenize.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: qfeuilla <qfeuilla@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/24 16:27:14 by frthierr #+# #+# */
/* Updated: 2020/08/08 11:57:59 by qfeuilla ### ########.fr */
/* Updated: 2020/08/09 18:34:34 by qfeuilla ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
2 changes: 1 addition & 1 deletion srcs/pipe/execute_pipes.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: qfeuilla <qfeuilla@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/15 10:16:23 by qfeuilla #+# #+# */
/* Updated: 2020/08/08 11:59:41 by qfeuilla ### ########.fr */
/* Updated: 2020/08/09 18:11:29 by qfeuilla ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
40 changes: 27 additions & 13 deletions srcs/token_expansion/expand_tokens.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,41 @@
/* By: qfeuilla <qfeuilla@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/30 11:57:50 by frthierr #+# #+# */
/* Updated: 2020/08/08 17:03:20 by qfeuilla ### ########.fr */
/* Updated: 2020/08/09 18:12:30 by qfeuilla ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"

char *add_bzero(char **final_token, int index)
{
(*final_token)[index] = '\0';
return (*final_token);
}

int is_quote_only(char *tk)
{
if (ft_strlen(tk) == 2 && (!ft_strncmp(tk, "\"\"", 3)
if ((ft_strlen(tk) == 2 && (!ft_strncmp(tk, "\"\"", 3)
|| !ft_strncmp(tk, "\'\'", 3)))
|| (tk[0] == '\"' && tk[ft_strlen(tk) - 1] == '\"' && ft_strlen(tk) >= 2))
return (1);
return (0);
}

char *return_token(char **tk, int check_quote)
{
if ((!(*tk) || !(*tk)[0]) && check_quote)
{
if (*tk)
free(*tk);
return (ft_strdup("\33\127"));
}
return (*tk);
}

char *expand_token_quote(char *tk, s_expand_tk_dt d)
{
int check_quote;

check_quote = 0;
if (is_quote_only(tk))
return (ft_strdup("\33\127"));
check_quote = 1;
if (!(d.final_token = init_expand(&d.qt, &d.ij, &d.pb, tk)))
return (NULL);
return (return_token(NULL, check_quote));
while (tk[d.ij.a])
{
tk[d.ij.a] == '\'' && d.qt.dq == -1 && (!d.pb || d.qt.q == 1)
Expand All @@ -43,16 +52,17 @@ char *expand_token_quote(char *tk, s_expand_tk_dt d)
{
d.tmp = d.final_token;
if (!(d.final_token = eev(tk, d.final_token, &d.ij.a, &d.ij.b)))
return (NULL);
return (return_token(NULL, check_quote));
if (elif_loop(&d.final_token, &d.tmp))
return (d.final_token);
return (return_token(&d.final_token, check_quote));
}
else
d.final_token[d.ij.b++] = tk[d.ij.a++];
else if (!(d.pb = 0))
else_loop(tk, &d.final_token, &d.ij, &d.qt);
}
return (add_bzero(&d.final_token, d.ij.b));
d.final_token[d.ij.b] = '\0';
return (return_token(&d.final_token, check_quote));
}

void *get_final_token(void *content)
Expand All @@ -64,7 +74,11 @@ void *get_final_token(void *content)
str = ((char*)content);
str = expand_token_quote(str, d);
if (!str || !str[0])
{
if (str)
free(str);
return (NULL);
}
return (str);
}

Expand Down
2 changes: 1 addition & 1 deletion srcs/token_expansion/get_env.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: qfeuilla <qfeuilla@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/29 16:49:23 by frthierr #+# #+# */
/* Updated: 2020/08/09 12:54:06 by qfeuilla ### ########.fr */
/* Updated: 2020/08/09 17:55:43 by qfeuilla ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
2 changes: 1 addition & 1 deletion srcs/utils/print_tokens.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: qfeuilla <qfeuilla@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/26 10:36:09 by franciszer #+# #+# */
/* Updated: 2020/08/08 11:58:19 by qfeuilla ### ########.fr */
/* Updated: 2020/08/09 18:34:19 by qfeuilla ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down

0 comments on commit 75f2438

Please sign in to comment.