some more refactor and todo

This commit is contained in:
Quinten Mennen 2025-03-05 21:42:59 +01:00
parent f6c2754882
commit af4e215242
3 changed files with 15 additions and 11 deletions

View File

@ -25,7 +25,6 @@ char **parser_get_arguments(t_list *list, t_minishell *msh);
int parser_validate_command(t_command *command);
int parser_count_arguments(t_list *list);
char *parser_concatenate(t_minishell *msh, char *str1, char *str2);
char *parser_process_token(t_minishell *msh, char **args, t_list *prev
, t_list *t_head);
char *parser_process_token(t_minishell *msh, t_list *prev, t_list *t_head);
#endif

View File

@ -11,8 +11,9 @@
/* ************************************************************************** */
#include "minishell.h"
#include "typedef.h"
static int parser_should_concact(t_minishell *msh, int argi, t_list *tkns)
static int parser_should_concact(t_minishell *msh, int argi, t_list *cur, t_list *prev)
{
t_token *c_tkn;
t_token *p_tkn;
@ -20,19 +21,20 @@ static int parser_should_concact(t_minishell *msh, int argi, t_list *tkns)
if (argi < 1)
return (0);
p_tkn = token_from_list(token_list_index(tkns, argi - 1));
c_tkn = token_from_list(token_list_index(tkns, argi));
p_tkn = token_from_list(prev);
c_tkn = token_from_list(cur);
lexer_char = 0;
if (!p_tkn || !c_tkn || c_tkn->position <= 0)
return (0);
lexer_char = msh->lexer->input[c_tkn->position - 1];
// if current & previous token is word and inbetween is no space, concat
// Determine exact separation position
return (c_tkn->type < 3 && p_tkn->type < 3 && !ft_isspace(lexer_char));
}
char **parser_get_arguments(t_list *list, t_minishell *msh)
{
t_list *current;
t_list *prev;
char *str;
char **args;
int argc;
@ -46,13 +48,14 @@ char **parser_get_arguments(t_list *list, t_minishell *msh)
{
if (token_from_list(current)->type < 3)
{
str = parser_process_token(msh, args, token_list_index(list, i - 1), current);
if (parser_should_concact(msh, i, list))
str = parser_process_token(msh, token_list_index(list, i - 1), current);
if (parser_should_concact(msh, i, current, prev))
args[i - 1] = parser_concatenate(msh, args[i - 1], str);
else if (str)
args[i++] = str;
argc--;
}
prev = current;
current = current->next;
}
args[i] = 0;

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/05 21:12:15 by qmennen #+# #+# */
/* Updated: 2025/03/05 21:14:09 by qmennen ### ########.fr */
/* Updated: 2025/03/05 21:42:44 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -36,15 +36,17 @@ static int parser_should_expand(t_list *value)
return (0);
}
char *parser_process_token(t_minishell *msh, char **args, t_list *prev
, t_list *t_head)
//TODO: Make an exception for this `echo hey""you "" test`. here echo actually interprets "" as an extra space. Just check if its empty and surrounded by spaces or sth. Can't be asked rn
char *parser_process_token(t_minishell *msh, t_list *prev, t_list *t_head)
{
char *str;
t_token *token;
t_token *p_token;
if (!t_head)
return (NULL);
token = (t_token *)t_head->content;
p_token = (t_token *)prev->content;
str = NULL;
if (ft_strcmp(token->value, "") == 0)
return (NULL);