moving some files around
This commit is contained in:
parent
97069cac62
commit
56b5e7c0a5
@ -20,6 +20,7 @@
|
|||||||
# include "environment.h"
|
# include "environment.h"
|
||||||
# include "prompt.h"
|
# include "prompt.h"
|
||||||
# include "tokenizer.h"
|
# include "tokenizer.h"
|
||||||
|
# include "token.h"
|
||||||
# include "builtin.h"
|
# include "builtin.h"
|
||||||
# include "executor.h"
|
# include "executor.h"
|
||||||
# include "parser.h"
|
# include "parser.h"
|
||||||
|
|||||||
@ -23,5 +23,6 @@ void parser_create_command(t_minishell *msh,
|
|||||||
t_command *cmd, t_list **l_tkn);
|
t_command *cmd, t_list **l_tkn);
|
||||||
char **parser_get_arguments(t_list *list, t_minishell *msh);
|
char **parser_get_arguments(t_list *list, t_minishell *msh);
|
||||||
int parser_validate_command(t_command *command);
|
int parser_validate_command(t_command *command);
|
||||||
|
int parser_count_arguments(t_list *list);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
20
inc/token.h
Normal file
20
inc/token.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* token.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/03/05 13:11:41 by qmennen #+# #+# */
|
||||||
|
/* Updated: 2025/03/05 13:11:58 by qmennen ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef TOKEN_H
|
||||||
|
# define TOKEN_H
|
||||||
|
|
||||||
|
# include "minishell.h"
|
||||||
|
|
||||||
|
t_token *token_from_list(t_list *list);
|
||||||
|
|
||||||
|
#endif
|
||||||
36
src/parser/parser_count_arguments.c
Normal file
36
src/parser/parser_count_arguments.c
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* parser_count_arguments.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/03/05 13:09:30 by qmennen #+# #+# */
|
||||||
|
/* Updated: 2025/03/05 13:09:47 by qmennen ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
int parser_count_arguments(t_list *list)
|
||||||
|
{
|
||||||
|
int cmds;
|
||||||
|
t_list *current;
|
||||||
|
t_list *prev;
|
||||||
|
t_token *token;
|
||||||
|
|
||||||
|
cmds = 0;
|
||||||
|
current = list;
|
||||||
|
prev = NULL;
|
||||||
|
while (current)
|
||||||
|
{
|
||||||
|
token = ((t_token *)current->content);
|
||||||
|
if (token->type < 3 && (!prev || ((t_token *)prev->content)->type < 3))
|
||||||
|
cmds++;
|
||||||
|
prev = current;
|
||||||
|
current = current->next;
|
||||||
|
}
|
||||||
|
return (cmds);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -15,27 +15,6 @@
|
|||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
static int count_cmds(t_list *list)
|
|
||||||
{
|
|
||||||
int cmds;
|
|
||||||
t_list *current;
|
|
||||||
t_list *prev;
|
|
||||||
t_token *token;
|
|
||||||
|
|
||||||
cmds = 0;
|
|
||||||
current = list;
|
|
||||||
prev = NULL;
|
|
||||||
while (current)
|
|
||||||
{
|
|
||||||
token = ((t_token *)current->content);
|
|
||||||
if (token->type < 3 && (!prev || ((t_token *)prev->content)->type < 3))
|
|
||||||
cmds++;
|
|
||||||
prev = current;
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
return (cmds);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int parser_should_expand(t_list *value)
|
static int parser_should_expand(t_list *value)
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
@ -91,14 +70,14 @@ char **parser_get_arguments(t_list *list, t_minishell *msh)
|
|||||||
char *str;
|
char *str;
|
||||||
char *cat;
|
char *cat;
|
||||||
|
|
||||||
argc = count_cmds(list);
|
argc = parser_count_arguments(list);
|
||||||
args = malloc_safe(msh, (argc + 1) * sizeof(char *));
|
args = malloc_safe(msh, (argc + 1) * sizeof(char *));
|
||||||
current = list;
|
current = list;
|
||||||
i = 0;
|
i = 0;
|
||||||
prev = NULL;
|
prev = NULL;
|
||||||
while (argc > 0 && current)
|
while (argc > 0 && current)
|
||||||
{
|
{
|
||||||
if (((t_token *)current->content)->type < 3 && (!prev || ((t_token *)prev->content)->type < 3))
|
if (token_from_list(current)->type < 3 && (!prev || ((t_token *)prev->content)->type < 3))
|
||||||
{
|
{
|
||||||
str = parser_process_token(msh, args, prev, current);
|
str = parser_process_token(msh, args, prev, current);
|
||||||
if (i > 0 && prev && ft_strcmp(((t_token *)prev->content)->value, "") == 0)
|
if (i > 0 && prev && ft_strcmp(((t_token *)prev->content)->value, "") == 0)
|
||||||
|
|||||||
18
src/token/token_from_list.c
Normal file
18
src/token/token_from_list.c
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* token_from_list.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/03/05 13:10:47 by qmennen #+# #+# */
|
||||||
|
/* Updated: 2025/03/05 13:11:17 by qmennen ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
t_token *token_from_list(t_list *list)
|
||||||
|
{
|
||||||
|
return ((t_token *)list->content);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user